3 # Copyright (C) 2001 Colin Watson
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, you can find it on the World Wide
17 # Web at http://www.gnu.org/copyleft/gpl.html, or write to the Free
18 # Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
21 # Invoke as ./manual_refs_update.pl manual_refs > manual_refs.new
22 # You need copies of all the relevant manuals installed in the standard
25 # Currently, this is only likely to work with the HTML output by
26 # DebianDoc-SGML. This seems to be OK for all the necessary manuals for now.
30 # Location of the manual directory on the local filesystem, and base URL for
31 # the eventual target of the reference.
34 'policy' => [ '/usr/share/doc/debian-policy/policy.html',
35 'http://www.debian.org/doc/debian-policy' ],
36 'devref' => [ '/usr/share/doc/developers-reference/' .
37 'developers-reference.html',
38 'http://www.debian.org/doc/packaging-manuals/' .
39 'developers-reference' ],
40 'menu' => [ '/usr/share/doc/menu/html',
41 'http://www.debian.org/doc/packaging-manuals/menu.html' ],
46 for my $manual (keys %manuals) {
47 my ($dir, $url) = @{$manuals{$manual}};
51 print STDERR "Manual '$manual' not installed; not updating.\n";
54 $refs{$manual} = [ "$manual $url/index.html" ];
57 opendir DIR, $dir or die "Couldn't open $dir: $!";
58 while (defined(my $file = readdir DIR)) {
59 next unless -f "$dir/$file";
62 open FILE, "< $dir/$file" or
63 die "Couldn't open $dir/$file: $!";
65 if (m/^Chapter (\d+)/ and not defined $chapter) {
67 push @{$chapter_refs[$chapter]}, "$manual-$1 $url/$file";
69 elsif (m/<a name="(.+?)">(\d.*?) /) {
70 if (defined $chapter) {
71 push @{$chapter_refs[$chapter]},
72 "$manual-$2 $url/$file#$1";
74 print STDERR "No 'Chapter' line in $dir/$file; ",
75 "ignoring this file.\n";
84 for my $chapter_ref (@chapter_refs) {
85 next unless defined $chapter_ref;
86 push @{$refs{$manual}}, @$chapter_ref;
90 # Replace all lines for manuals for which we have up-to-date information.
95 next unless m/^(\w+)/;
97 next if $seen{$manual};
98 if (exists $manuals{$manual} and exists $refs{$manual}) {
100 print join("\n", @{$refs{$manual}}), "\n";