blob: 73a3809a1da8bc04fcf726c0bb6a54fdc956d1df [file] [log] [blame]
Fred Drake9acafa81998-02-18 14:52:24 +00001#!/depot/gnu/plat/bin/perl -i
Jeremy Hyltondaa2d5d1998-02-18 13:53:48 +00002
3# read the labels, then reverse the mappings
4require "labels.pl";
5
6%nodes = ();
Fred Drakee8179301998-02-26 18:49:58 +00007my $key;
Jeremy Hylton9caa1101998-02-18 16:10:22 +00008# sort so that we get a consistent assignment for nodes with multiple labels
9foreach $label (sort keys %external_labels) {
Fred Drakee8179301998-02-26 18:49:58 +000010 $key = $external_labels{$label};
11 $key =~ s|^/||;
12 $nodes{$key} = $label;
Jeremy Hyltondaa2d5d1998-02-18 13:53:48 +000013}
14
15# collect labels that have been used
16%newnames = ();
17
18while (<>) {
19 # don't want to do one s/// per line per node
20 # so look for lines with hrefs, then do s/// on nodes present
21 if (/HREF=\"([^\#\"]*)html[\#\"]/) {
22 @parts = split(/HREF\=\"/);
23 shift @parts;
24 for $node (@parts) {
25 $node =~ s/[\#\"].*$//g;
26 chop($node);
27 if (defined($nodes{$node})) {
28 $label = $nodes{$node};
29 if (s/HREF=\"$node([\#\"])/HREF=\"$label.html$1/g) {
30 s/HREF=\"$label.html#SECTION\d+/HREF=\"$label.html/g;
31 $newnames{$node} = "$label.html";
32 }
33 }
34 }
35 }
36 print;
37}
38
39foreach $oldname (keys %newnames) {
Fred Drake9acafa81998-02-18 14:52:24 +000040# or ln -s
41 system("mv $oldname $newnames{$oldname}");
Jeremy Hyltondaa2d5d1998-02-18 13:53:48 +000042}