summaryrefslogtreecommitdiffstats
path: root/Doc/node2label.pl
blob: 1d643dbb49077efc9f4b6a58f7df655422012961 (plain)
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
#!/depot/gnu/plat/bin/perl -i

# read the labels, then reverse the mappings
require "labels.pl";

%nodes = ();
# sort so that we get a consistent assignment for nodes with multiple labels 
foreach $label (sort keys %external_labels) {
  $nodes{$external_labels{$label}} = $label;
}

# collect labels that have been used
%newnames = ();

while (<>) {
  # don't want to do one s/// per line per node
  # so look for lines with hrefs, then do s/// on nodes present
  if (/HREF=\"([^\#\"]*)html[\#\"]/) {
    @parts = split(/HREF\=\"/);
    shift @parts;
    for $node (@parts) {
      $node =~ s/[\#\"].*$//g;
      chop($node);
      if (defined($nodes{$node})) {
	$label = $nodes{$node};
	if (s/HREF=\"$node([\#\"])/HREF=\"$label.html$1/g) {
	  s/HREF=\"$label.html#SECTION\d+/HREF=\"$label.html/g;
	  $newnames{$node} = "$label.html";
	}
      }
    }
  }
  print;
}

foreach $oldname (keys %newnames) {
# or ln -s
  system("mv $oldname $newnames{$oldname}");
}