annotate Doc/tools/node2label.pl @ 17322:bd110eadc19a legacy-trunk

One-liner critical fix from Jim Fulton: Eric's string-method crusade got the order backwards in a line (for .find()).
author Tim Peters <tim.peters@gmail.com>
date Thu, 05 Apr 2001 22:26:23 +0000
parents 774817285b8c
children 45badfbfb00e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7721
f093fcfd5625 Use "/usr/bin/env perl" for the #! line, and change the -i option to:
Fred Drake <fdrake@acm.org>
parents: 7491
diff changeset
1 #! /usr/bin/env perl
f093fcfd5625 Use "/usr/bin/env perl" for the #! line, and change the -i option to:
Fred Drake <fdrake@acm.org>
parents: 7491
diff changeset
2
f093fcfd5625 Use "/usr/bin/env perl" for the #! line, and change the -i option to:
Fred Drake <fdrake@acm.org>
parents: 7491
diff changeset
3 use English;
f093fcfd5625 Use "/usr/bin/env perl" for the #! line, and change the -i option to:
Fred Drake <fdrake@acm.org>
parents: 7491
diff changeset
4 $INPLACE_EDIT = '';
7352
0d31c7d9697d Patch HREFs in html files, replacing nodeXXX.html with label.html.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
5
0d31c7d9697d Patch HREFs in html files, replacing nodeXXX.html with label.html.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
6 # read the labels, then reverse the mappings
0d31c7d9697d Patch HREFs in html files, replacing nodeXXX.html with label.html.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
7 require "labels.pl";
0d31c7d9697d Patch HREFs in html files, replacing nodeXXX.html with label.html.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
8
0d31c7d9697d Patch HREFs in html files, replacing nodeXXX.html with label.html.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
9 %nodes = ();
7491
7f28997b2c10 Adjusted to work with the newer version of LaTeX2HTML as well.
Fred Drake <fdrake@acm.org>
parents: 7366
diff changeset
10 my $key;
7366
717c3daca08e assure a consistent assignment for nodes with multiple labels
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 7355
diff changeset
11 # sort so that we get a consistent assignment for nodes with multiple labels
717c3daca08e assure a consistent assignment for nodes with multiple labels
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 7355
diff changeset
12 foreach $label (sort keys %external_labels) {
7491
7f28997b2c10 Adjusted to work with the newer version of LaTeX2HTML as well.
Fred Drake <fdrake@acm.org>
parents: 7366
diff changeset
13 $key = $external_labels{$label};
7f28997b2c10 Adjusted to work with the newer version of LaTeX2HTML as well.
Fred Drake <fdrake@acm.org>
parents: 7366
diff changeset
14 $key =~ s|^/||;
7f28997b2c10 Adjusted to work with the newer version of LaTeX2HTML as well.
Fred Drake <fdrake@acm.org>
parents: 7366
diff changeset
15 $nodes{$key} = $label;
7352
0d31c7d9697d Patch HREFs in html files, replacing nodeXXX.html with label.html.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
16 }
0d31c7d9697d Patch HREFs in html files, replacing nodeXXX.html with label.html.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
17
7766
587d0178f8d3 Add support for mapping internal labels used from the index.
Fred Drake <fdrake@acm.org>
parents: 7721
diff changeset
18 # This adds the "internal" labels added for indexing. These labels will not
587d0178f8d3 Add support for mapping internal labels used from the index.
Fred Drake <fdrake@acm.org>
parents: 7721
diff changeset
19 # be used for file names.
587d0178f8d3 Add support for mapping internal labels used from the index.
Fred Drake <fdrake@acm.org>
parents: 7721
diff changeset
20 require "intlabels.pl";
587d0178f8d3 Add support for mapping internal labels used from the index.
Fred Drake <fdrake@acm.org>
parents: 7721
diff changeset
21 foreach $label (keys %internal_labels) {
587d0178f8d3 Add support for mapping internal labels used from the index.
Fred Drake <fdrake@acm.org>
parents: 7721
diff changeset
22 $key = $internal_labels{$label};
587d0178f8d3 Add support for mapping internal labels used from the index.
Fred Drake <fdrake@acm.org>
parents: 7721
diff changeset
23 $key =~ s|^/||;
587d0178f8d3 Add support for mapping internal labels used from the index.
Fred Drake <fdrake@acm.org>
parents: 7721
diff changeset
24 if (defined($nodes{$key})) {
587d0178f8d3 Add support for mapping internal labels used from the index.
Fred Drake <fdrake@acm.org>
parents: 7721
diff changeset
25 $nodes{$label} = $nodes{$key};
587d0178f8d3 Add support for mapping internal labels used from the index.
Fred Drake <fdrake@acm.org>
parents: 7721
diff changeset
26 }
587d0178f8d3 Add support for mapping internal labels used from the index.
Fred Drake <fdrake@acm.org>
parents: 7721
diff changeset
27 }
587d0178f8d3 Add support for mapping internal labels used from the index.
Fred Drake <fdrake@acm.org>
parents: 7721
diff changeset
28
7352
0d31c7d9697d Patch HREFs in html files, replacing nodeXXX.html with label.html.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
29 # collect labels that have been used
0d31c7d9697d Patch HREFs in html files, replacing nodeXXX.html with label.html.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
30 %newnames = ();
0d31c7d9697d Patch HREFs in html files, replacing nodeXXX.html with label.html.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
31
0d31c7d9697d Patch HREFs in html files, replacing nodeXXX.html with label.html.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
32 while (<>) {
0d31c7d9697d Patch HREFs in html files, replacing nodeXXX.html with label.html.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
33 # don't want to do one s/// per line per node
0d31c7d9697d Patch HREFs in html files, replacing nodeXXX.html with label.html.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
34 # so look for lines with hrefs, then do s/// on nodes present
12215
774817285b8c Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents: 10136
diff changeset
35 if (/(HREF|href)=[\"\']([^\#\"\']*)html[\#\"\']/) {
774817285b8c Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents: 10136
diff changeset
36 @parts = split(/(HREF|href)\=[\"\']/);
7352
0d31c7d9697d Patch HREFs in html files, replacing nodeXXX.html with label.html.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
37 shift @parts;
0d31c7d9697d Patch HREFs in html files, replacing nodeXXX.html with label.html.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
38 for $node (@parts) {
12215
774817285b8c Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents: 10136
diff changeset
39 $node =~ s/[\#\"\'].*$//g;
7352
0d31c7d9697d Patch HREFs in html files, replacing nodeXXX.html with label.html.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
40 chop($node);
0d31c7d9697d Patch HREFs in html files, replacing nodeXXX.html with label.html.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
41 if (defined($nodes{$node})) {
0d31c7d9697d Patch HREFs in html files, replacing nodeXXX.html with label.html.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
42 $label = $nodes{$node};
12215
774817285b8c Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents: 10136
diff changeset
43 if (s/(HREF|href)=([\"\'])$node([\#\"\'])/href=$2$label.html$3/g) {
774817285b8c Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents: 10136
diff changeset
44 s/(HREF|href)=([\"\'])$label.html/href=$2$label.html/g;
7352
0d31c7d9697d Patch HREFs in html files, replacing nodeXXX.html with label.html.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
45 $newnames{$node} = "$label.html";
0d31c7d9697d Patch HREFs in html files, replacing nodeXXX.html with label.html.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
46 }
0d31c7d9697d Patch HREFs in html files, replacing nodeXXX.html with label.html.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
47 }
0d31c7d9697d Patch HREFs in html files, replacing nodeXXX.html with label.html.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
48 }
0d31c7d9697d Patch HREFs in html files, replacing nodeXXX.html with label.html.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
49 }
0d31c7d9697d Patch HREFs in html files, replacing nodeXXX.html with label.html.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
50 print;
0d31c7d9697d Patch HREFs in html files, replacing nodeXXX.html with label.html.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
51 }
0d31c7d9697d Patch HREFs in html files, replacing nodeXXX.html with label.html.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
52
0d31c7d9697d Patch HREFs in html files, replacing nodeXXX.html with label.html.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
53 foreach $oldname (keys %newnames) {
8951
8acc72a81319 Use Perl's rename() function instead of system(); there's no need for two
Fred Drake <fdrake@acm.org>
parents: 7766
diff changeset
54 rename($oldname, $newnames{$oldname});
7352
0d31c7d9697d Patch HREFs in html files, replacing nodeXXX.html with label.html.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
55 }