diff options
Diffstat (limited to 'index')
-rwxr-xr-x | index | 74 |
1 files changed, 0 insertions, 74 deletions
@@ -1,74 +0,0 @@ -#!/bin/rc -e - -# index -- add ids to headings and print index to stderr - -flagfmt=s -args='[file ...]' - -if(! ifs=() eval `{aux/getflags $*}){ - aux/usage - exit usage -} - -fn source{ - if(! ~ $#* 0) - cat $* - if not - cat -} - -source $* | awk ' - /<h[0-9]>.*<\/h[0-9]/ { - heading($0) - next - } - /<h[0-9]>/ { - open = 1 - s = $0 - next - } - open && /<\/h[0-9]>/ { - open = 0 - s = s "\n" $0 - heading(s) - next - } - open { s = s " " $0; next } - { print } - - function heading(s) { - i = s - sub("^.*<h[0-9]>", "", i) - sub("</h[0-9]>.*$", "", i) - i = toascii(i) - sub("^<h[0-9]", "& id=\"" i "\"", s) - print s - if (!ENVIRON["flags"]) { # if not silent mode - sub("^<h", "", s) - sub(" id=\"", " ", s) - sub("\">", " ", s) - sub("<\/h[0-9]>$", "", s) - print s > "/dev/stderr" - } - } - - function toascii(s) { - s = tolower(s) - gsub("[ÀÁÂÃÄÅàáâãäå]", "a", s) - gsub("[Ææ]", "ae", s) - gsub("[Çç]", "c", s) - gsub("[Ðð]", "dh", s) - gsub("[ÈÉÊËèéêë]", "e", s) - gsub("[ÌÍÎÏìíîï]", "i", s) - gsub("[Ññ]", "n", s) - gsub("[ÒÓÔÕÖØòóôõöø]", "o", s) - gsub("[ß]", "ss", s) - gsub("[Þþ]", "th", s) - gsub("[ÙÚÛÜùúûü]", "u", s) - gsub("[×]", "x", s) - gsub("[Ýýÿ]", "y", s) - gsub("[^-a-z_ ]", "", s) - gsub("[ ]+", "-", s) - return s - } -' |