blob: 90f0c18933a5e4e0ce829a6741064f727c7e13e9 [file] [log] [blame]
Fred Drake25437691998-03-19 05:17:49 +00001#! /usr/bin/env perl
2
3use English;
4$INPLACE_EDIT = '';
Jeremy Hyltondaa2d5d1998-02-18 13:53:48 +00005
6# read the labels, then reverse the mappings
7require "labels.pl";
8
9%nodes = ();
Fred Drakee8179301998-02-26 18:49:58 +000010my $key;
Jeremy Hylton9caa1101998-02-18 16:10:22 +000011# sort so that we get a consistent assignment for nodes with multiple labels
12foreach $label (sort keys %external_labels) {
Fred Drake9a374182001-05-29 19:53:46 +000013 #
14 # If the label can't be used as a filename on non-Unix platforms,
15 # skip it. Such labels may be used internally within the documentation,
16 # but will never be used for filename generation.
17 #
18 if ($label =~ /^([-.a-zA-Z0-9]+)$/) {
19 $key = $external_labels{$label};
20 $key =~ s|^/||;
21 $nodes{$key} = $label;
22 }
Jeremy Hyltondaa2d5d1998-02-18 13:53:48 +000023}
24
Fred Drake19e2ce51998-03-27 05:24:53 +000025# This adds the "internal" labels added for indexing. These labels will not
26# be used for file names.
27require "intlabels.pl";
28foreach $label (keys %internal_labels) {
29 $key = $internal_labels{$label};
30 $key =~ s|^/||;
31 if (defined($nodes{$key})) {
32 $nodes{$label} = $nodes{$key};
33 }
34}
35
Jeremy Hyltondaa2d5d1998-02-18 13:53:48 +000036# collect labels that have been used
37%newnames = ();
38
39while (<>) {
40 # don't want to do one s/// per line per node
41 # so look for lines with hrefs, then do s/// on nodes present
Fred Drakef015d9a2001-06-23 04:35:09 +000042 if (/(HREF|href)=[\"\']node\d+\.html[\#\"\']/) {
Fred Drakeba828782000-04-03 04:19:14 +000043 @parts = split(/(HREF|href)\=[\"\']/);
Jeremy Hyltondaa2d5d1998-02-18 13:53:48 +000044 shift @parts;
45 for $node (@parts) {
Fred Drakeba828782000-04-03 04:19:14 +000046 $node =~ s/[\#\"\'].*$//g;
Jeremy Hyltondaa2d5d1998-02-18 13:53:48 +000047 chop($node);
48 if (defined($nodes{$node})) {
49 $label = $nodes{$node};
Fred Drakeba828782000-04-03 04:19:14 +000050 if (s/(HREF|href)=([\"\'])$node([\#\"\'])/href=$2$label.html$3/g) {
51 s/(HREF|href)=([\"\'])$label.html/href=$2$label.html/g;
Jeremy Hyltondaa2d5d1998-02-18 13:53:48 +000052 $newnames{$node} = "$label.html";
53 }
54 }
55 }
56 }
57 print;
58}
59
60foreach $oldname (keys %newnames) {
Fred Drakeaf06a0b1998-08-11 18:17:47 +000061 rename($oldname, $newnames{$oldname});
Jeremy Hyltondaa2d5d1998-02-18 13:53:48 +000062}