Added some code to peer into a data structure in Maemian/Schedule.pm. Also added the
[maemian] / nokia-lintian / private / manual_refs_update.pl
1 #!/usr/bin/perl -w
2
3 # Copyright (C) 2001 Colin Watson
4 #
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.
9 #
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.
14 #
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,
19 # MA 02110-1301, USA.
20
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
23 # places locally.
24
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.
27
28 use strict;
29
30 # Location of the manual directory on the local filesystem, and base URL for
31 # the eventual target of the reference.
32
33 my %manuals = (
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' ],
42 );
43
44 my %refs;
45
46 for my $manual (keys %manuals) {
47     my ($dir, $url) = @{$manuals{$manual}};
48     my @chapter_refs;
49
50     unless (-d $dir) {
51         print STDERR "Manual '$manual' not installed; not updating.\n";
52         next;
53     }
54     $refs{$manual} = [ "$manual $url/index.html" ];
55
56     local *DIR;
57     opendir DIR, $dir or die "Couldn't open $dir: $!";
58     while (defined(my $file = readdir DIR)) {
59         next unless -f "$dir/$file";
60         my $chapter;
61         local *FILE;
62         open FILE, "< $dir/$file" or
63             die "Couldn't open $dir/$file: $!";
64         while (<FILE>) {
65             if (m/^Chapter (\d+)/ and not defined $chapter) {
66                 $chapter = $1;
67                 push @{$chapter_refs[$chapter]}, "$manual-$1 $url/$file";
68             }
69             elsif (m/<a name="(.+?)">(\d.*?) /) {
70                 if (defined $chapter) {
71                     push @{$chapter_refs[$chapter]},
72                          "$manual-$2 $url/$file#$1";
73                 } else {
74                     print STDERR "No 'Chapter' line in $dir/$file; ",
75                                  "ignoring this file.\n";
76                     next;
77                 }
78             }
79         }
80         close FILE;
81     }
82     closedir DIR;
83
84     for my $chapter_ref (@chapter_refs) {
85         next unless defined $chapter_ref;
86         push @{$refs{$manual}}, @$chapter_ref;
87     }
88 }
89
90 # Replace all lines for manuals for which we have up-to-date information.
91
92 my %seen;
93
94 while (<>) {
95     next unless m/^(\w+)/;
96     my $manual = $1;
97     next if $seen{$manual};
98     if (exists $manuals{$manual} and exists $refs{$manual}) {
99         $seen{$manual} = 1;
100         print join("\n", @{$refs{$manual}}), "\n";
101     } else {
102         print;
103     }
104 }