-
Notifications
You must be signed in to change notification settings - Fork 790
Expand file tree
/
Copy pathmkpanchdb
More file actions
executable file
·74 lines (66 loc) · 1.49 KB
/
mkpanchdb
File metadata and controls
executable file
·74 lines (66 loc) · 1.49 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
#!/usr/local/bin/perl
# Extract all the anchors that have a name of the form:
# $include src=<srcdir>/<name2>.srb
# and build a database for it.
#
# Arnaud Le Hors - lehors@w3.org
# $Id: mkpanchdb,v 1.1 1997-10-03 20:29:14 ian Exp $
$PROGNAME = substr($0, rindex($0, "/") + 1);
if (!$ARGV[0] || !$ARGV[1]) {
print "Usage: $PROGNAME srcdir prefix dbase src1 src2 ...\n";
exit 1;
} else {
$srcdir = $ARGV[0];
shift;
$prefix = $ARGV[0];
shift;
$dbasef = $ARGV[0];
shift;
}
# copy file in memory
sub readfile {
$buf = "";
if (!open(INPUT, $_[0])) {
print STDERR "$PROGNAME Error: Cannot open file: $_[0]\n";
return;
}
while (<INPUT>) {
$buf .= $_;
}
close(INPUT);
}
# store anchor
sub addanchor {
if ($anchors{$_[0]}) {
print STDERR "$PROGNAME Warning: duplicated index: \"$_[0]\" found both @\n";
print STDERR "\t $anchors{$_[0]}\n";
print STDERR "\tand $_[1]\n";
} else {
$anchors{$_[0]} = $_[1];
}
}
# look for index anchors
$pattern = "src=\"?$srcdir\/(.*?)\.srb\"?";
sub seekanchors {
$_ = $buf;
while (/$pattern/sio) {
addanchor($1, "$file#$prefix-$1");
$_ = $';
}
}
### main
# search for all the anchors
@anchors = ();
foreach $file (@ARGV) {
readfile($file);
seekanchors();
}
# print out database
if (!open(DBASE, "> $dbasef")) {
print STDERR "$PROGNAME Error: Cannot open dbfile: $dbasef\n";
} else {
foreach $key (sort(keys %anchors)) {
print DBASE "$key;$anchors{$key}\n";
}
close(DBASE);
}