annotate Doc/tools/node2label.pl @ 38664:7619216bbc19 2.4

Bug #1502728: Correctly link against librt library on HP-UX. (backport from rev. 46743)
author Georg Brandl <georg@python.org>
date Thu, 08 Jun 2006 12:54:16 +0000
parents 4702921297d1
children
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
23366
3b323df945bb Work around limitation of Cygwin Perl: To avoid a permission denial, we need
Fred Drake <fdrake@acm.org>
parents: 18234
diff changeset
3 # On Cygwin, we actually have to generate a temporary file when doing
3b323df945bb Work around limitation of Cygwin Perl: To avoid a permission denial, we need
Fred Drake <fdrake@acm.org>
parents: 18234
diff changeset
4 # the inplace edit, or we'll get permission errors. Not sure who's
3b323df945bb Work around limitation of Cygwin Perl: To avoid a permission denial, we need
Fred Drake <fdrake@acm.org>
parents: 18234
diff changeset
5 # bug this is, except that it isn't ours. To deal with this, we
3b323df945bb Work around limitation of Cygwin Perl: To avoid a permission denial, we need
Fred Drake <fdrake@acm.org>
parents: 18234
diff changeset
6 # generate backups during the edit phase and remove them at the end.
3b323df945bb Work around limitation of Cygwin Perl: To avoid a permission denial, we need
Fred Drake <fdrake@acm.org>
parents: 18234
diff changeset
7 #
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
8 use English;
23366
3b323df945bb Work around limitation of Cygwin Perl: To avoid a permission denial, we need
Fred Drake <fdrake@acm.org>
parents: 18234
diff changeset
9 $INPLACE_EDIT = '.bak';
7352
0d31c7d9697d Patch HREFs in html files, replacing nodeXXX.html with label.html.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
10
0d31c7d9697d Patch HREFs in html files, replacing nodeXXX.html with label.html.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
11 # 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
12 require "labels.pl";
0d31c7d9697d Patch HREFs in html files, replacing nodeXXX.html with label.html.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
13
0d31c7d9697d Patch HREFs in html files, replacing nodeXXX.html with label.html.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
14 %nodes = ();
7491
7f28997b2c10 Adjusted to work with the newer version of LaTeX2HTML as well.
Fred Drake <fdrake@acm.org>
parents: 7366
diff changeset
15 my $key;
7366
717c3daca08e assure a consistent assignment for nodes with multiple labels
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 7355
diff changeset
16 # 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
17 foreach $label (sort keys %external_labels) {
18002
45badfbfb00e New solution to the "Someone stuck a colon in that filename!" problem:
Fred Drake <fdrake@acm.org>
parents: 12215
diff changeset
18 #
45badfbfb00e New solution to the "Someone stuck a colon in that filename!" problem:
Fred Drake <fdrake@acm.org>
parents: 12215
diff changeset
19 # If the label can't be used as a filename on non-Unix platforms,
45badfbfb00e New solution to the "Someone stuck a colon in that filename!" problem:
Fred Drake <fdrake@acm.org>
parents: 12215
diff changeset
20 # skip it. Such labels may be used internally within the documentation,
45badfbfb00e New solution to the "Someone stuck a colon in that filename!" problem:
Fred Drake <fdrake@acm.org>
parents: 12215
diff changeset
21 # but will never be used for filename generation.
45badfbfb00e New solution to the "Someone stuck a colon in that filename!" problem:
Fred Drake <fdrake@acm.org>
parents: 12215
diff changeset
22 #
45badfbfb00e New solution to the "Someone stuck a colon in that filename!" problem:
Fred Drake <fdrake@acm.org>
parents: 12215
diff changeset
23 if ($label =~ /^([-.a-zA-Z0-9]+)$/) {
45badfbfb00e New solution to the "Someone stuck a colon in that filename!" problem:
Fred Drake <fdrake@acm.org>
parents: 12215
diff changeset
24 $key = $external_labels{$label};
45badfbfb00e New solution to the "Someone stuck a colon in that filename!" problem:
Fred Drake <fdrake@acm.org>
parents: 12215
diff changeset
25 $key =~ s|^/||;
45badfbfb00e New solution to the "Someone stuck a colon in that filename!" problem:
Fred Drake <fdrake@acm.org>
parents: 12215
diff changeset
26 $nodes{$key} = $label;
45badfbfb00e New solution to the "Someone stuck a colon in that filename!" problem:
Fred Drake <fdrake@acm.org>
parents: 12215
diff changeset
27 }
7352
0d31c7d9697d Patch HREFs in html files, replacing nodeXXX.html with label.html.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
28 }
0d31c7d9697d Patch HREFs in html files, replacing nodeXXX.html with label.html.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
29
7766
587d0178f8d3 Add support for mapping internal labels used from the index.
Fred Drake <fdrake@acm.org>
parents: 7721
diff changeset
30 # 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
31 # 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
32 require "intlabels.pl";
587d0178f8d3 Add support for mapping internal labels used from the index.
Fred Drake <fdrake@acm.org>
parents: 7721
diff changeset
33 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
34 $key = $internal_labels{$label};
587d0178f8d3 Add support for mapping internal labels used from the index.
Fred Drake <fdrake@acm.org>
parents: 7721
diff changeset
35 $key =~ s|^/||;
587d0178f8d3 Add support for mapping internal labels used from the index.
Fred Drake <fdrake@acm.org>
parents: 7721
diff changeset
36 if (defined($nodes{$key})) {
587d0178f8d3 Add support for mapping internal labels used from the index.
Fred Drake <fdrake@acm.org>
parents: 7721
diff changeset
37 $nodes{$label} = $nodes{$key};
587d0178f8d3 Add support for mapping internal labels used from the index.
Fred Drake <fdrake@acm.org>
parents: 7721
diff changeset
38 }
587d0178f8d3 Add support for mapping internal labels used from the index.
Fred Drake <fdrake@acm.org>
parents: 7721
diff changeset
39 }
587d0178f8d3 Add support for mapping internal labels used from the index.
Fred Drake <fdrake@acm.org>
parents: 7721
diff changeset
40
7352
0d31c7d9697d Patch HREFs in html files, replacing nodeXXX.html with label.html.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
41 # 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
42 %newnames = ();
0d31c7d9697d Patch HREFs in html files, replacing nodeXXX.html with label.html.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
43
0d31c7d9697d Patch HREFs in html files, replacing nodeXXX.html with label.html.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
44 while (<>) {
0d31c7d9697d Patch HREFs in html files, replacing nodeXXX.html with label.html.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
45 # 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
46 # so look for lines with hrefs, then do s/// on nodes present
18234
fe4071beff41 Give the pattern used to pick out a source anchor a more specific pattern.
Fred Drake <fdrake@acm.org>
parents: 18002
diff changeset
47 if (/(HREF|href)=[\"\']node\d+\.html[\#\"\']/) {
12215
774817285b8c Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents: 10136
diff changeset
48 @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
49 shift @parts;
0d31c7d9697d Patch HREFs in html files, replacing nodeXXX.html with label.html.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
50 for $node (@parts) {
12215
774817285b8c Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents: 10136
diff changeset
51 $node =~ s/[\#\"\'].*$//g;
25835
4702921297d1 Try to fix the broken links caused by multiple \ref on the same line.
Neal Norwitz <nnorwitz@gmail.com>
parents: 23366
diff changeset
52 chomp($node);
7352
0d31c7d9697d Patch HREFs in html files, replacing nodeXXX.html with label.html.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
53 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
54 $label = $nodes{$node};
12215
774817285b8c Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents: 10136
diff changeset
55 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
56 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
57 $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
58 }
0d31c7d9697d Patch HREFs in html files, replacing nodeXXX.html with label.html.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
59 }
0d31c7d9697d Patch HREFs in html files, replacing nodeXXX.html with label.html.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
60 }
0d31c7d9697d Patch HREFs in html files, replacing nodeXXX.html with label.html.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
61 }
0d31c7d9697d Patch HREFs in html files, replacing nodeXXX.html with label.html.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
62 print;
0d31c7d9697d Patch HREFs in html files, replacing nodeXXX.html with label.html.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
63 }
0d31c7d9697d Patch HREFs in html files, replacing nodeXXX.html with label.html.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
64
0d31c7d9697d Patch HREFs in html files, replacing nodeXXX.html with label.html.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
65 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
66 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
67 }
23366
3b323df945bb Work around limitation of Cygwin Perl: To avoid a permission denial, we need
Fred Drake <fdrake@acm.org>
parents: 18234
diff changeset
68
3b323df945bb Work around limitation of Cygwin Perl: To avoid a permission denial, we need
Fred Drake <fdrake@acm.org>
parents: 18234
diff changeset
69 foreach $filename (glob('*.bak')) {
3b323df945bb Work around limitation of Cygwin Perl: To avoid a permission denial, we need
Fred Drake <fdrake@acm.org>
parents: 18234
diff changeset
70 unlink($filename);
3b323df945bb Work around limitation of Cygwin Perl: To avoid a permission denial, we need
Fred Drake <fdrake@acm.org>
parents: 18234
diff changeset
71 }