Mercurial > cpython-lru_cache-weakref
annotate Doc/tools/node2label.pl @ 25838:8540887bcec6 2.2
Backport of 2.183:
Fix memory leak in add_subclass() found by NealN with valgrind.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Fri, 18 Oct 2002 13:42:21 +0000 |
| parents | fe4071beff41 |
| children | 3b323df945bb 7b7b96555842 |
| 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) { |
|
18002
45badfbfb00e
New solution to the "Someone stuck a colon in that filename!" problem:
Fred Drake <fdrake@acm.org>
parents:
12215
diff
changeset
|
13 # |
|
45badfbfb00e
New solution to the "Someone stuck a colon in that filename!" problem:
Fred Drake <fdrake@acm.org>
parents:
12215
diff
changeset
|
14 # 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
|
15 # 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
|
16 # 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
|
17 # |
|
45badfbfb00e
New solution to the "Someone stuck a colon in that filename!" problem:
Fred Drake <fdrake@acm.org>
parents:
12215
diff
changeset
|
18 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
|
19 $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
|
20 $key =~ s|^/||; |
|
45badfbfb00e
New solution to the "Someone stuck a colon in that filename!" problem:
Fred Drake <fdrake@acm.org>
parents:
12215
diff
changeset
|
21 $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
|
22 } |
|
7352
0d31c7d9697d
Patch HREFs in html files, replacing nodeXXX.html with label.html.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
23 } |
|
0d31c7d9697d
Patch HREFs in html files, replacing nodeXXX.html with label.html.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
24 |
|
7766
587d0178f8d3
Add support for mapping internal labels used from the index.
Fred Drake <fdrake@acm.org>
parents:
7721
diff
changeset
|
25 # 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
|
26 # 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
|
27 require "intlabels.pl"; |
|
587d0178f8d3
Add support for mapping internal labels used from the index.
Fred Drake <fdrake@acm.org>
parents:
7721
diff
changeset
|
28 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
|
29 $key = $internal_labels{$label}; |
|
587d0178f8d3
Add support for mapping internal labels used from the index.
Fred Drake <fdrake@acm.org>
parents:
7721
diff
changeset
|
30 $key =~ s|^/||; |
|
587d0178f8d3
Add support for mapping internal labels used from the index.
Fred Drake <fdrake@acm.org>
parents:
7721
diff
changeset
|
31 if (defined($nodes{$key})) { |
|
587d0178f8d3
Add support for mapping internal labels used from the index.
Fred Drake <fdrake@acm.org>
parents:
7721
diff
changeset
|
32 $nodes{$label} = $nodes{$key}; |
|
587d0178f8d3
Add support for mapping internal labels used from the index.
Fred Drake <fdrake@acm.org>
parents:
7721
diff
changeset
|
33 } |
|
587d0178f8d3
Add support for mapping internal labels used from the index.
Fred Drake <fdrake@acm.org>
parents:
7721
diff
changeset
|
34 } |
|
587d0178f8d3
Add support for mapping internal labels used from the index.
Fred Drake <fdrake@acm.org>
parents:
7721
diff
changeset
|
35 |
|
7352
0d31c7d9697d
Patch HREFs in html files, replacing nodeXXX.html with label.html.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
36 # 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
|
37 %newnames = (); |
|
0d31c7d9697d
Patch HREFs in html files, replacing nodeXXX.html with label.html.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
38 |
|
0d31c7d9697d
Patch HREFs in html files, replacing nodeXXX.html with label.html.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
39 while (<>) { |
|
0d31c7d9697d
Patch HREFs in html files, replacing nodeXXX.html with label.html.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
40 # 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
|
41 # 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
|
42 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
|
43 @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
|
44 shift @parts; |
|
0d31c7d9697d
Patch HREFs in html files, replacing nodeXXX.html with label.html.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
45 for $node (@parts) { |
|
12215
774817285b8c
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
10136
diff
changeset
|
46 $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
|
47 chop($node); |
|
0d31c7d9697d
Patch HREFs in html files, replacing nodeXXX.html with label.html.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
48 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
|
49 $label = $nodes{$node}; |
|
12215
774817285b8c
Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents:
10136
diff
changeset
|
50 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
|
51 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
|
52 $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
|
53 } |
|
0d31c7d9697d
Patch HREFs in html files, replacing nodeXXX.html with label.html.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
54 } |
|
0d31c7d9697d
Patch HREFs in html files, replacing nodeXXX.html with label.html.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
55 } |
|
0d31c7d9697d
Patch HREFs in html files, replacing nodeXXX.html with label.html.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
56 } |
|
0d31c7d9697d
Patch HREFs in html files, replacing nodeXXX.html with label.html.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
57 print; |
|
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 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
|
61 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
|
62 } |
