4 # key (tab) string (tab) page numbers
6 # command, data command, [data] 11
7 # command, display command, [display] 11, 54, 63, 75
8 # command, model command, [model] 11
9 # command, quit command, [quit] 5, 16
11 # key (tab) string (tab) page numbers
19 BEGIN { FS = OFS = "\t" }
21 { line[NR] = $0; x[NR] = $2 "\t" $3; y[NR] = $1 }
23 # find a sequence that have the same prefix
24 # dump prefix, then each instance with spaces instead of prefix
26 for (i = 1; i <= NR; i = j+1) {
27 j = findrun(i) # returns last elem of run
35 function findrun(s, j, p, np) { # find y[s],y[s+1]... with same prefix
38 for (j = s+1; j <= NR; j++) {
39 if (y[j] == p) # same, so include
41 if (index(y[j], p) != 1) # no match
43 c = substr(y[j], np+1, 1)
44 if (c != " " && c != ",") # has to be whole word prefix
50 function prefix(s, n) { # find 1st word of s: same sort key, minus ,
54 return substr(s, 1, n-1)
59 function printrun(s, e, i) { # move [...] to end, "see" to front
60 s1 = 0; e1 = 0; p1 = 0; i1 = 0
61 for (i = s; i <= e; i++) {
62 if (x[i] ~ /{see/) { # see, see also
66 } else if (x[i] ~ /^\[/) { # prefix word is [...]
70 } else if (x[i] ~ /\[.*\]/) { # [...] somewhere else
74 } else { # none of the above
80 if (e-s+1 != s1 + p1 + i1 + e1) print "oh shit" >"/dev/stderr"
82 for (i = 0; i < s1; i++) # "see", one/line
85 printgroup(ix,iy,0,i1) # non [...] items
89 printgroup(ex,ey,0,e1) # prefix [...] items
92 # for (i = 0; i < p1; i++) # [prefix] ... items
95 printgroup(px,py,0,p1) # [prefix] ... items
100 function printgroup(x, y, s, e, i, j) {
102 if (split(f23[1], temp, " ") > 1) {
103 pfx = temp[1] " " temp[2] # 2-word prefix
104 for (i = s+1; i < e; i++) {
105 if (index(x[i], pfx) != 1)
107 c = substr(x[i], length(pfx)+1, 1)
108 if (c != " " && c != ",") # has to be whole word prefix
112 # print "got a run with", pfx
113 sub(/ /, "@", f23[1])
114 for (i = s; i < e; i++)
115 sub(/ /, "@", x[i]) # take @ out later
118 n = sub(/,?[ ~]+.*/, "", f23[1]) # zap rest of line
120 sub(/,$/, "", f23[1])
121 if (n > 0) { # some change, so not a single word
122 sub(/@/, " ", f23[1])
123 print y[s], f23[1] # print main entry
125 for (j = s; j < e; j++) {
127 sub(/^[^, ]+[, ]+/, " ", f23[1])
128 sub(/@/, " ", f23[1])
129 print y[s], f23[1], f23[2]