-
Notifications
You must be signed in to change notification settings - Fork 790
Expand file tree
/
Copy pathmkidx
More file actions
executable file
·172 lines (159 loc) · 3.82 KB
/
mkidx
File metadata and controls
executable file
·172 lines (159 loc) · 3.82 KB
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#!/usr/local/bin/perl
# Index maker:
#
# Build an index table of all the anchors that have a name of the form:
# "<prefix>-<name>". In addition when a database is given with the '-db' option,
# information related to elements searched by names is added to the table.
# Table headers can be specified through the '-th' option.
#
# Arnaud Le Hors - lehors@w3.org
# $Id: mkidx,v 1.11 1997-12-11 00:13:20 ijacobs Exp $
if (($_ = $ARGV[0], /^-r/) && $ARGV[0]) {
shift;
$realpath = $ARGV[0];
shift;
} else {
$realpath = ();
}
$PROGNAME = substr($0, rindex($0, "/") + 1);
if (!$ARGV[1]) {
die "Usage: $PROGNAME indexfile idxdb1 idxdb2 ...\n";
}
$indexf = $ARGV[0];
shift;
if (!$realpath) {
$realpath = $indexf;
}
# compute relative path from 1 to 2
sub rpath {
@path1 = split("/", $_[0]);
@path2 = split("/", $_[1]);
pop(@path1);
while ($path1[0] eq $path2[0]) {
shift(@path1);
shift(@path2);
}
$root = "";
foreach $el (@path1) {
$root .= "../";
}
$path = join("/", @path2);
return "$root$path";
}
sub readdbfile {
$dbasef = $_[0];
if (!open(DBASE, $dbasef)) {
print STDERR "$PROGNAME Error: Cannot open dbfile: $dbasef\n";
return;
}
while (<DBASE>) {
chop;
($index, $url, $cmt) = split(/\|/, $_, 3);
# Remove entity markup first (e.g. $lt;)
$index =~ s/^&[^;]+;//;
# Sort on certain chars only.
$index =~ s/^[^a-zA-Z0-9\@:]*//;
# Case-insensitive
$index = lc($index);
# NB: must have a non-space characer
# between index and cmt for proper sortin.
$key = "$index $cmt";
if ($indexes{$key}) {
push(@{$indexes{$key}}, "$_");
} else {
@{$indexes{$key}} = ("$_");
# Write the subterms that are different
# class="tocline*" directs our patched html2ps to omit the bullet
close(DBASE);
}
### main
@indexes = ();
foreach $file (@ARGV) {
readdbfile($file);
}
for ($j = $i; $j <= $#subs; $j++) {
# print out index document
$buf = "";
@letters = ();
$curindex = ();
$curletter = ();
foreach $key (sort(keys %indexes)) {
$lastcmt = ();
$first = t;
foreach $item (@{$indexes{$key}}) {
$cmt = ();
if ($first) {
$first = ();
$pre = "";
} else {
$pre = ",\n";
($index, $url, $cmt) = split(/\|/, $item, 3);
if ($class eq 'index-def') {
$rurl = rpath($realpath, $url); # relative URL
}
if ($curletter ne ($letter = lc(substr($key, 0, 1)))) {
if ($curletter) {
$buf .= "</dl>\n";
}
$buf .= "\n<dl>";
$curletter = $letter;
$setanchor = t;
push(@letters, $letter);
} else {
$setanchor = ();
}
if ($curindex ne $index) {
if ($setanchor) {
$buf .= "\n <dt><a name=\"$letter\">$index</a>";
} else {
$buf .= "\n <dt>$index";
}
$n = 1;
$curindex = $index;
}
if ($url =~ /\#didx-/i) {
$class="index-def";
} else {
$class="index-inst";
}
if ($cmt ne "") {
# If there is an index subkey
if ($lastcmt ne $cmt) {
# If the subkey is not the same
# as the previous one, start
# a new subkey list.
$buf .= "\n <dd>$cmt";
$pre .= " <a href=\"$rurl\" class=\"$class\">";
$content = "1";
$post = "</a>";
$n = 2;
$lastcmt = $cmt;
} else {
# Add number to current subkey list.
$pre .= " <a href=\"$rurl\" class=\"$class\">";
$content = $n;
$post = "</a>";
$n++;
}
} else {
# Add number to current index line.
$pre .= " <a href=\"$rurl\" class=\"$class\">";
$content = $n;
$post = "</a>";
$n++;
}
if ($url =~ /\#didx-/) {
$content = "<em>$content</em>";
}
$buf .= "$pre$content$post";
}
$lvl--;
$buf .= "</dl>\n";
# Print out the full buffer
open(OUTPUT, "> $indexf");
print OUTPUT "<DIV class=\"noprint\"> ";
foreach $letter (@letters) {
print OUTPUT " <a href=\"#$letter\">" . uc($letter) . "</a> ";
close(OUTPUT);
print OUTPUT "</DIV>";
print OUTPUT $buf;