Added some code to peer into a data structure in Maemian/Schedule.pm. Also added the
[maemian] / nokia-lintian / collection / scripts
1 #!/usr/bin/perl -w
2 # scripts -- lintian collection script
3
4 # Copyright (C) 1998 Richard Braakman
5
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15
16 # You should have received a copy of the GNU General Public License
17 # along with this program.  If not, you can find it on the World Wide
18 # Web at http://www.gnu.org/copyleft/gpl.html, or write to the Free
19 # Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
20 # MA 02110-1301, USA.
21
22 use strict;
23
24 open(SCRIPTS, '>', "scripts") or fail("cannot open scripts output file: $!");
25 open(INDEX, '<', "index") or fail("cannot open index file: $!");
26
27 my $file;
28 my $magic;
29 my $scriptpath;
30
31 while (<INDEX>) {
32     next unless /^-/;   # skip non-files
33     chop;
34
35     # Extract the filename field from the tar-like file index.
36     # Note that the split is done with an explicit limit so that filenames
37     # with embedded spaces are handled correctly.
38     $file = (split(' ', $_, 6))[5];
39     $file =~ s/ link to .*//;    # cut off info about hard links
40     # This used to call fail() instead of next.  However, the check to
41     # see if all files in the index can be opened should be done elsewhere.
42     open(FILE, '<', "unpacked/$file") or next;
43     if (read(FILE, $magic, 2) and $magic eq '#!' and not eof(FILE)) {
44         $scriptpath = <FILE>;
45         chomp($scriptpath);
46         next if ($scriptpath =~ m/^\#!/); # skip lincity data files
47                                           # #!#!#!
48         my $copy_path = $scriptpath;
49         $scriptpath =~ s/^\s+//; # remove leading whitespace
50         $scriptpath =~ s/^\#.*//; # remove comments
51         if ($scriptpath eq '') {
52             print SCRIPTS "$copy_path $file\n";
53         } else {
54         # This used to have (\S+) rather than (\S*), but that went wrong
55         # with scripts that start with an empty #! line.
56             my $env = '';
57             if ($scriptpath =~ s,^/usr/bin/env\s+,,) {
58                 $env = 'env ';
59             }
60             $scriptpath =~ s/^(\S*).*/$1/s;
61             print SCRIPTS $env . "$scriptpath $file\n";
62         }
63     }
64     close(FILE);
65 }
66 close(INDEX);
67 close(SCRIPTS);
68
69 open(SCRIPTS, '>', "control-scripts")
70     or fail("cannot open control-scripts output file: $!");
71
72 opendir(CONTROL, "control")
73     or fail("cannot read control directory: $!");
74
75 for $file (readdir CONTROL) {
76     next unless -f "control/$file";
77     open(FILE, '<', "control/$file") or fail("cannot open control/$file: $!");
78     if (read(FILE, $magic, 2) and $magic eq '#!') {
79         $scriptpath = <FILE>;
80         $scriptpath =~ s/^\s*(\S*).*/$1/s;
81         print SCRIPTS "$scriptpath $file\n"
82     }
83     close(FILE);
84 }
85 closedir(CONTROL);
86 close(SCRIPTS);
87
88 exit 0;
89
90 # -----------------------------------
91
92 sub fail {
93     if ($_[0]) {
94         print STDERR "internal error: $_[0]\n";
95     } elsif ($!) {
96         print STDERR "internal error: $!\n";
97     } else {
98         print STDERR "internal error.\n";
99     }
100     exit 1;
101 }