home *** CD-ROM | disk | FTP | other *** search
- BEGIN {
- LIMIT="`"
- FS=LIMIT
- parts="@ABCDEFGHIJKLMNOPQRSTUVWXYZ"
- last_tag=" "
- part_no=0
- ind=""
- low_ind=""
- line=""
- entry=""
- entry_lim=4
- no_entry=0
- IND_FORMAT="l r"
- #{{{}}}
- # {{{ init lowercase field
- lowercase["A"]="a"; lowercase["B"]="b"; lowercase["C"]="c"
- lowercase["D"]="d"; lowercase["E"]="e"; lowercase["F"]="f"
- lowercase["G"]="g"; lowercase["H"]="h"; lowercase["I"]="i"
- lowercase["J"]="j"; lowercase["K"]="k"; lowercase["L"]="l"
- lowercase["M"]="m"; lowercase["N"]="n"; lowercase["O"]="o"
- lowercase["P"]="p"; lowercase["Q"]="q"; lowercase["R"]="r"
- lowercase["S"]="s"; lowercase["T"]="t"; lowercase["U"]="u"
- lowercase["V"]="v"; lowercase["W"]="w"; lowercase["X"]="x"
- lowercase["Y"]="y"; lowercase["Z"]="z"
- # }}}
- # {{{ print auto-gen tag
- printf(".\\%c generated automatically, containing the index data\n",34)
- # }}}
- # {{{ print header of table
- printf(".bp\n")
- printf(".nH 1 Index\n")
- printf(".LP\n")
- printf(".if \\n(gR .2C\n")
- printf("There are 3 types of indices:\n")
- printf(".TS\n")
- printf("center tab(" LIMIT ");\n")
- printf("l l.\n")
- printf(" \\fBline\\fP" LIMIT "marks a definition.\n")
- printf(" \\fIline\\fP" LIMIT "marks an example.\n")
- printf(" line" LIMIT "marks a normal reference.\n")
- printf(".TE\n")
- printf(".if \\n(gR .SM\n")
- printf(".TS\n")
- printf("center tab(" LIMIT ");\n")
- printf("%s.\n",IND_FORMAT)
- # }}}
- }
- {
- # {{{ handle index
- if (substr($1,1,1)==" ")
- in_index=substr($1,2)
- else
- in_index=$1
- # {{{ set low_in_index to tolower(in_index)
- low_in_index=""
- for (i=0; i<length(in_index);) if ((l=lowercase[c=substr(in_index,++i,1)])=="") { low_in_index=low_in_index c } else { low_in_index=low_in_index l }
- # }}}
- if (in_index!=ind) {
- if (low_ind==low_in_index) {
- # {{{ use upper case entry
- ind=low_in_index
- low_ind=low_in_index
- # }}}
- } else {
- # {{{ get tag
- tag=substr(low_in_index,1,1)
- part_no=0
- for (;part_no<=length(parts)&&tag!=substr(parts,part_no,1);part_no++);
- # }}}
- # {{{ maybe print old entry
- if (entry!="") {
- if (substr(ind,1,1)==".") printf("\&")
- if (substr(ind,1,1)=="=") printf("\&")
- printf("%s" LIMIT "%s\n",substr(ind,1,length(ind)-1),entry)
- }
- # }}}
- # {{{ maybe print header
- if (tag!=last_tag || entry=="") {
- printf("\n")
- if (part_no<=length(parts)) printf("\\fB%s\\fP:\n",tag)
- }
- # }}}
- # {{{ start new entry
- entry=""
- no_entry=0
- last_tag=tag
- ind=in_index
- low_ind=low_in_index
- line=""
- # }}}
- }
-
- }
- # }}}
- # {{{ handle line
- if ($2!=line) {
- # {{{ maybe gen whitespace between numbers
- if (no_entry!=entry_lim) {
- if (no_entry!=0) entry=entry " "
- no_entry++
- } else {
- entry=entry "\n" LIMIT
- no_entry=1
- }
- # }}}
- # {{{ get offset of number
- for (j=0;;)
- if (substr($2,j,1)==" ")
- j++
- else
- break
- for (;;)
- if (substr($2,j,1)=="0")
- j++
- else
- break
- # }}}
- # {{{ maybe change font
- if (substr($2,11,1)=="d")
- entry=entry "\\fB"
- else if (substr($2,11,1)=="x")
- entry=entry "\\fI"
- # }}}
- line_digit=substr($2,j,11-j)
- while (length(line_digit) && substr(line_digit,1,1)=="0")
- line_digit=substr(line_digit,2)
- entry=entry line_digit
- # {{{ maybe change font
- if (substr($2,11,1)!="i")
- entry=entry "\\fP"
- # }}}
- }
- # }}}
- line=$2
- }
- END {
- if (entry=="") {
- printf("\n")
- } else {
- # {{{ print last entry
- if (substr(ind,1,1)==".") printf("\&")
- if (substr(ind,1,1)=="=") printf("\&")
- printf("%s" LIMIT "%s\n",substr(ind,1,length(ind)-1),entry)
- # }}}
- }
- printf(".TE\n")
- printf(".if \\n(gR .LG\n")
- }
-