1998-03-19 05:17:49 +00:00
|
|
|
#! /usr/bin/env perl
|
|
|
|
|
2002-05-02 20:42:30 +00:00
|
|
|
# On Cygwin, we actually have to generate a temporary file when doing
|
|
|
|
# the inplace edit, or we'll get permission errors. Not sure who's
|
|
|
|
# bug this is, except that it isn't ours. To deal with this, we
|
|
|
|
# generate backups during the edit phase and remove them at the end.
|
|
|
|
#
|
1998-03-19 05:17:49 +00:00
|
|
|
use English;
|
2002-05-02 20:42:30 +00:00
|
|
|
$INPLACE_EDIT = '.bak';
|
1998-02-18 13:53:48 +00:00
|
|
|
|
|
|
|
# read the labels, then reverse the mappings
|
|
|
|
require "labels.pl";
|
|
|
|
|
|
|
|
%nodes = ();
|
1998-02-26 18:49:58 +00:00
|
|
|
my $key;
|
1998-02-18 16:10:22 +00:00
|
|
|
# sort so that we get a consistent assignment for nodes with multiple labels
|
|
|
|
foreach $label (sort keys %external_labels) {
|
2001-05-29 19:53:46 +00:00
|
|
|
#
|
|
|
|
# If the label can't be used as a filename on non-Unix platforms,
|
|
|
|
# skip it. Such labels may be used internally within the documentation,
|
|
|
|
# but will never be used for filename generation.
|
|
|
|
#
|
|
|
|
if ($label =~ /^([-.a-zA-Z0-9]+)$/) {
|
|
|
|
$key = $external_labels{$label};
|
|
|
|
$key =~ s|^/||;
|
|
|
|
$nodes{$key} = $label;
|
|
|
|
}
|
1998-02-18 13:53:48 +00:00
|
|
|
}
|
|
|
|
|
1998-03-27 05:24:53 +00:00
|
|
|
# This adds the "internal" labels added for indexing. These labels will not
|
|
|
|
# be used for file names.
|
|
|
|
require "intlabels.pl";
|
|
|
|
foreach $label (keys %internal_labels) {
|
|
|
|
$key = $internal_labels{$label};
|
|
|
|
$key =~ s|^/||;
|
|
|
|
if (defined($nodes{$key})) {
|
|
|
|
$nodes{$label} = $nodes{$key};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-02-18 13:53:48 +00:00
|
|
|
# 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
|
2001-06-23 04:35:09 +00:00
|
|
|
if (/(HREF|href)=[\"\']node\d+\.html[\#\"\']/) {
|
2000-04-03 04:19:14 +00:00
|
|
|
@parts = split(/(HREF|href)\=[\"\']/);
|
1998-02-18 13:53:48 +00:00
|
|
|
shift @parts;
|
|
|
|
for $node (@parts) {
|
2000-04-03 04:19:14 +00:00
|
|
|
$node =~ s/[\#\"\'].*$//g;
|
2002-10-18 02:05:47 +00:00
|
|
|
chomp($node);
|
1998-02-18 13:53:48 +00:00
|
|
|
if (defined($nodes{$node})) {
|
|
|
|
$label = $nodes{$node};
|
2000-04-03 04:19:14 +00:00
|
|
|
if (s/(HREF|href)=([\"\'])$node([\#\"\'])/href=$2$label.html$3/g) {
|
|
|
|
s/(HREF|href)=([\"\'])$label.html/href=$2$label.html/g;
|
1998-02-18 13:53:48 +00:00
|
|
|
$newnames{$node} = "$label.html";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
print;
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach $oldname (keys %newnames) {
|
1998-08-11 18:17:47 +00:00
|
|
|
rename($oldname, $newnames{$oldname});
|
1998-02-18 13:53:48 +00:00
|
|
|
}
|
2002-05-02 20:42:30 +00:00
|
|
|
|
|
|
|
foreach $filename (glob('*.bak')) {
|
|
|
|
unlink($filename);
|
|
|
|
}
|