From 07f59f5eb8c296b7306882185cbe932a2f286174 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Sun, 31 Jan 2021 12:51:28 +0000 Subject: Rename index to htindex (like htwrap) --- htindex | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100755 htindex (limited to 'htindex') diff --git a/htindex b/htindex new file mode 100755 index 0000000..accd0be --- /dev/null +++ b/htindex @@ -0,0 +1,74 @@ +#!/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]/ { + heading($0) + next + } + // { + 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("^.*", "", i) + sub(".*$", "", i) + i = toascii(i) + 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 + } +' -- cgit v1.2.3