Fred Drake | 2543769 | 1998-03-19 05:17:49 +0000 | [diff] [blame] | 1 | #! /usr/bin/env perl |
| 2 | |
| 3 | use English; |
| 4 | $INPLACE_EDIT = ''; |
Jeremy Hylton | daa2d5d | 1998-02-18 13:53:48 +0000 | [diff] [blame] | 5 | |
| 6 | # read the labels, then reverse the mappings |
| 7 | require "labels.pl"; |
| 8 | |
| 9 | %nodes = (); |
Fred Drake | e817930 | 1998-02-26 18:49:58 +0000 | [diff] [blame] | 10 | my $key; |
Jeremy Hylton | 9caa110 | 1998-02-18 16:10:22 +0000 | [diff] [blame] | 11 | # sort so that we get a consistent assignment for nodes with multiple labels |
| 12 | foreach $label (sort keys %external_labels) { |
Fred Drake | 9a37418 | 2001-05-29 19:53:46 +0000 | [diff] [blame] | 13 | # |
| 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 Hylton | daa2d5d | 1998-02-18 13:53:48 +0000 | [diff] [blame] | 23 | } |
| 24 | |
Fred Drake | 19e2ce5 | 1998-03-27 05:24:53 +0000 | [diff] [blame] | 25 | # This adds the "internal" labels added for indexing. These labels will not |
| 26 | # be used for file names. |
| 27 | require "intlabels.pl"; |
| 28 | foreach $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 Hylton | daa2d5d | 1998-02-18 13:53:48 +0000 | [diff] [blame] | 36 | # collect labels that have been used |
| 37 | %newnames = (); |
| 38 | |
| 39 | while (<>) { |
| 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 Drake | f015d9a | 2001-06-23 04:35:09 +0000 | [diff] [blame] | 42 | if (/(HREF|href)=[\"\']node\d+\.html[\#\"\']/) { |
Fred Drake | ba82878 | 2000-04-03 04:19:14 +0000 | [diff] [blame] | 43 | @parts = split(/(HREF|href)\=[\"\']/); |
Jeremy Hylton | daa2d5d | 1998-02-18 13:53:48 +0000 | [diff] [blame] | 44 | shift @parts; |
| 45 | for $node (@parts) { |
Fred Drake | ba82878 | 2000-04-03 04:19:14 +0000 | [diff] [blame] | 46 | $node =~ s/[\#\"\'].*$//g; |
Jeremy Hylton | daa2d5d | 1998-02-18 13:53:48 +0000 | [diff] [blame] | 47 | chop($node); |
| 48 | if (defined($nodes{$node})) { |
| 49 | $label = $nodes{$node}; |
Fred Drake | ba82878 | 2000-04-03 04:19:14 +0000 | [diff] [blame] | 50 | if (s/(HREF|href)=([\"\'])$node([\#\"\'])/href=$2$label.html$3/g) { |
| 51 | s/(HREF|href)=([\"\'])$label.html/href=$2$label.html/g; |
Jeremy Hylton | daa2d5d | 1998-02-18 13:53:48 +0000 | [diff] [blame] | 52 | $newnames{$node} = "$label.html"; |
| 53 | } |
| 54 | } |
| 55 | } |
| 56 | } |
| 57 | print; |
| 58 | } |
| 59 | |
| 60 | foreach $oldname (keys %newnames) { |
Fred Drake | af06a0b | 1998-08-11 18:17:47 +0000 | [diff] [blame] | 61 | rename($oldname, $newnames{$oldname}); |
Jeremy Hylton | daa2d5d | 1998-02-18 13:53:48 +0000 | [diff] [blame] | 62 | } |