This repository has been archived by the owner on Aug 27, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
subindex
executable file
·91 lines (79 loc) · 1.38 KB
/
subindex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/awk -f
#
# (c) K. Anton Feenstra 2001
#
# subindex v. 0.1 - 12 feb 2001
#
# reads tex index entries as generated by makeindex and
# combines identical words into sub-entries
#
BEGIN {
n=0;
}
/[{ ]Symbols[ }]/ {
if ( substr(1,1,$0)!="%" )
$0 = "% " $0;
}
/^[ \t]*\\see/ {
sub("^[ \t]*","");
pp = pp $0;
next;
}
{
sub(", \\\\see.*","",pp);
}
function dump() {
printf("%% %d %d %d %d |", mc, nc, mp, np);
for(i=1;i<=nc;i++) printf(" %s",c[i]);
printf(" |");
for(i=1;i<=np;i++) printf(" %s",p[i]);
printf(" |\n");
}
{
mc=0;
if ($1=="\\item") {
for(i=1; $(i)!="\\hfill" && i<=NF; i++) {
c[i]=$(i+1);
sub(",$","",c[i]);
if (i<=np && c[i]==p[i]) mc=i;
}
nc=i-2;
} else {
nc=0;
mc=0;
}
# if (mc) dump();
if (mc && mc<=nc) {
if (mc) {
key=c[1];
for(i=2; i<=mc; i++)
key=key" "c[i];
} else
key="";
if (key != pkey && mc<np)
printf(" \\item %s \\hfill \\nopagebreak\n", key);
pkey=key;
}
if (mp) m=mp; else m=mc;
skey=p[m+1];
for(i=m+2; i<=np; i++)
skey=skey" "p[i];
if (mc<np)
for(i=1; i<=mp || i<=mc; i++) {
sub("item "key" ", "subitem ", pp);
sub("item "key", "skey, "subitem "skey" $\\sim$", pp);
pp=" "pp;
}
np=nc;
mp=mc;
for(i=1;i<=np;i++)
p[i]=c[i];
}
{
if (NR>1) print pp;
pp=$0;
}
END {
print pp;
}
#last line