Debian Codegraph @

helper/count-deps

raw
1 #! /usr/bin/perl
2 use warnings;
3 use strict;
4 use integer;
5 use FindBin;
6 use lib $FindBin::RealBin;
7 use Def;
8
9 # This script counts and ranks dependencies in one or more Packages
10 # files.
11
12 our $usage = <<END;
13 usage: $0 [-h] [Packages file]...
14 -h print this usage message
15 END
16
17 # Read command-line arguments and options.
18 my @opt;
19 my @arg;
20 {
21 my $stopopt = '';
22 for ( @ARGV ) {
23 if ( $stopopt ) { push @arg, $_ }
24 elsif ( $_ eq '-' ) { $stopopt = '1' }
25 else { push @{ /^-/ ? \@opt : \@arg }, $_ }
26 }
27 }
28 my %opt = map { my @o = split ''; shift @o; map {$_=>1} @o; } @opt;
29 if ( $opt{'?'} || $opt{h} ) { print $usage; exit 0; }
30
31 my %dep;
32
33 for my $fn ( @arg ) {
34 open P, '<', $fn;
35 while (<P>) {
36 my( $text ) = /^(?:Pre-Depends|Depends|Recommends):(.*)$/ or next;
37 $dep{$_}++ for map { length($_) ? $_ : () }
38 split /[\s,|]*\([^()]*\)[\s,|]*|[\s,|]+/, $text;
39 }
40 close P;
41 }
42
43 printf "%5d %s\n", $dep{$_}, $_ for sort {
44 $dep{$b} <=> $dep{$a} || $a cmp $b
45 } keys %dep;
46