Added lots more modules from lintian. Maemian appears to work.
[maemian] / collection / file-info
1 #!/usr/bin/perl -w
2 # file-info -- maemian 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 use FileHandle;
25 use lib "$ENV{'MAEMIAN_ROOT'}/lib";
26 use Util;
27 use Maemian::Command qw(spawn reap);
28
29 ($#ARGV == 1) or fail("syntax: file-info <pkg> <type>");
30 my $pkg = shift;
31 my $type = shift;
32
33 -f "fields/source" or fail("file-info invoked in wrong directory");
34
35 unlink("file-info");
36 chdir("unpacked")
37     or fail("cannot chdir to unpacked directory: $!");
38
39 # We ignore failures from file because sometimes file returns a non-zero exit
40 # status when it can't parse a file.  So far, the resulting output still
41 # appears to be usable (although will contain "ERROR" strings, which Maemian
42 # doesn't care about), and the only problem was the exit status.
43 my %opts = ( pipe_in => FileHandle->new,
44              out => '../file-info',
45              fail => 'never' );
46 spawn(\%opts, ['xargs', '-0r', 'file', '--']);
47 $opts{pipe_in}->blocking(1);
48 open(INDEX, '<', "../index")
49     or fail("cannot open index file: $!");
50 while (<INDEX>) {
51     chomp;
52     $_ = (split(" ", $_, 6))[5];
53     s/ link to .*//;
54     s/ -> .*//;
55     s/(\G|[^\\](?:\\\\)*)\\(\d{3})/"$1" . chr(oct $2)/ge;
56     s/\\\\/\\/;
57     printf {$opts{pipe_in}} "%s\0", $_;
58 }
59 close(INDEX);
60
61 close $opts{pipe_in};
62 reap(\%opts);