From aefd5ebc52b61eb33d20ea1a7a4b2c9769bf4d12 Mon Sep 17 00:00:00 2001 From: sam Date: Sat, 27 Sep 2003 12:05:59 +0000 Subject: [PATCH] * Changed the recursion into an iteration so that we don't use awk functions and it properly works with the Solaris implementation. git-svn-id: svn://svn.zoy.org/elk/trunk@207 55e467fa-43c5-0310-a8a2-de718669efc6 --- doc/util/mkindex.awk | 146 +++++++++++++++++++++---------------------- 1 file changed, 73 insertions(+), 73 deletions(-) diff --git a/doc/util/mkindex.awk b/doc/util/mkindex.awk index 29af972..08df045 100755 --- a/doc/util/mkindex.awk +++ b/doc/util/mkindex.awk @@ -29,79 +29,79 @@ { need_nl = 0; - do_line($0); + line = $0; + + while(line != "") { + + nxt = index(line, "@[") + + if(nxt == 0) { + printf "%s", line; + break; + } + + if(nxt > 1) { + if(substr(line, nxt - 1, 1) == "(") { + need_c = 1; + } + need_nl = 1; + printf "%s", substr(line, 1, nxt - 1); + line = substr(line, nxt); + continue; + } + + tmp = substr(line, 1, 3); + if(tmp == "@[.") { + macro = "Ix"; + } else + if(tmp == "@[.") { + macro = "Id"; + } else { + printf "error: invalid index %s\n", tmp > "/dev/stderr"; + exit 1; + } + + end = match(line, "[^\\\\]]"); + + if(end == 0) { + printf "error: unfinished @[\n" > "/dev/stderr"; + exit 1; + } + + inx = substr(line, 4, end - 3); + gsub("\\\\]", "]", inx); + arg = inx; + gsub("(\\\\f.|''|``|\\\\%)", "", arg); + + if(arg == "") { + printf "error: empty index\n" > "/dev/stderr"; + exit 1; + } + + if(need_c) { printf "\\c"; } + if(need_nl) { printf "\n"; } + + printf ".%s ", macro; + + line = substr(line, end + 2); + + if(sub("^=", "", arg)) { + printf "\"%s\"", arg; + if(line != "") { + printf "\n"; + need_nl = 0; + sub("^ ", "", line); + } + } else if (arg ~ /[|]/) { + q = arg; sub("[^|]*[|]", "", q); sub("[|].*", "", arg); + printf "\"%s, %s\"\n%s %s", q, arg, arg, q; + need_nl = 1; + } else { + printf "\"%s\"\n%s", arg, inx; + need_nl = 1; + } + } + printf "\n"; } -function do_line(line) { - nxt = index(line, "@[") - - if(nxt == 0) { - printf "%s", line; - return; - } - - if(nxt > 1) { - if(substr(line, nxt - 1, 1) == "(") { - need_c = 1; - } - need_nl = 1; - printf "%s", substr(line, 1, nxt - 1); - do_line(substr(line, nxt)); - return; - } - - tmp = substr(line, 1, 3); - if(tmp == "@[.") { - macro = "Ix"; - } else - if(tmp == "@[.") { - macro = "Id"; - } else { - printf "error: invalid index %s\n", tmp > "/dev/stderr"; - exit 1; - } - - end = match(line, "[^\\\\]]"); - - if(end == 0) { - printf "error: unfinished @[\n" > "/dev/stderr"; - exit 1; - } - - inx = substr(line, 4, end - 3); - gsub("\\\\]", "]", inx); - arg = inx; - gsub("(\\\\f.|''|``|\\\\%)", "", arg); - - if(arg == "") { - printf "error: empty index\n" > "/dev/stderr"; - exit 1; - } - - if(need_c) { printf "\\c"; } - if(need_nl) { printf "\n"; } - - printf ".%s ", macro; - - line = substr(line, end + 2); - - if(sub("^=", "", arg)) { - printf "\"%s\"", arg; - if(line != "") { - printf "\n"; - need_nl = 0; - sub("^ ", "", line); - } - } else if (arg ~ /[|]/) { - q = arg; sub("[^|]*[|]", "", q); sub("[|].*", "", arg); - printf "\"%s, %s\"\n%s %s", q, arg, arg, q; - need_nl = 1; - } else { - printf "\"%s\"\n%s", arg, inx; - need_nl = 1; - } - - do_line(line); -} -