-
Notifications
You must be signed in to change notification settings - Fork 790
Expand file tree
/
Copy pathmkidx
More file actions
executable file
·123 lines (115 loc) · 2.88 KB
/
mkidx
File metadata and controls
executable file
·123 lines (115 loc) · 2.88 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
#!/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.8 1997-09-08 13:52:57 ian Exp $
$PROGNAME = substr($0, rindex($0, "/") + 1);
if (!$ARGV[1]) {
print "Usage: $PROGNAME indexfile idxdb1 idxdb2 ...\n";
exit 1;
} else {
$indexf = $ARGV[0];
shift;
}
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);
$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 = ();
foreach $item (@{$indexes{$key}}) {
$cmt = ();
($index, $url, $cmt) = split(/\|/, $item, 3);
if ($class eq 'index-def') {
if (($curindex) && ($curindex ne $index)) {
$buf .= "</dl>\n";
}
if ($curletter ne ($letter = lc(substr($key, 0, 1)))) {
$curletter = $letter;
$buf .= "<h2><a name=\"$letter\">" .
uc($letter) . "</a></h2>\n";
push(@letters, $letter);
}
if ($curindex ne $index) {
$buf .= "\n<dl><dt>$index";
$n = 1;
$curindex = $index;
}
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 = "\n, <a href=\"$url\">";
$content = "1";
$post = "</a>";
$n = 2;
$lastcmt = $cmt;
} else {
# Add number to current subkey list.
$pre = "\n, <a href=\"$url\">";
$content = $n;
$post = "</a>";
$n++;
}
} else {
# Add number to current index line.
$pre = "\n, <a href=\"$url\">";
$content = $n;
$post = "</a>";
$n++;
}
$_ = $url;
if (/\#didx-/) {
$content = "<em>$content</em>";
}
$buf .= "$pre$content$post";
}
$lvl--;
$buf .= "</dl>\n";
# Print out the full buffer
open(OUTPUT, "> $indexf");
print OUTPUT "<P><H2> ";
foreach $letter (@letters) {
print OUTPUT " <a href=\"#$letter\">" . uc($letter) . "</a> ";
close(OUTPUT);
print OUTPUT "</H2>";
print OUTPUT $buf;