Debian Codegraph @

helper/filter-debram-body

raw
1 #! /usr/bin/perl
2 use warnings;
3 use strict;
4 use integer;
5 use bytes;
6 use FindBin;
7 use lib $FindBin::RealBin;
8 use Def;
9
10 # This script searches certain fields of a Packages file for a pattern.
11 # If it finds the pattern, then it prints the corresponding line from a
12 # debram.txt body.
13
14 our %field = map { $_=>1 } qw(
15 Package
16 Source
17 Provides
18 Pre-Depends
19 Depends
20 Recommends
21 Description
22 );
23
24 our $usage = <<END;
25 usage: $0 [-hx] [Packages file] [pattern] [debram.txt body]
26 -h print this usage message
27 -x suppress empty rams
28 END
29
30 # Read command-line arguments and options.
31 my @opt;
32 my @arg;
33 {
34 my $stopopt = '';
35 for ( @ARGV ) {
36 if ( $stopopt ) { push @arg, $_ }
37 elsif ( $_ eq '-' ) { $stopopt = '1' }
38 else { push @{ /^-/ ? \@opt : \@arg }, $_ }
39 }
40 }
41 my %opt = map { my @o = split ''; shift @o; map {$_=>1} @o; } @opt;
42 if ( $opt{'?'} || $opt{h} || @arg != 3 ) { print $usage; exit 0; }
43 my( $fn_packages, $pat, $fn_body ) = @arg;
44
45 my $w0 = $Def::w_maint + $Def::w_pri;
46 my $w3 = $w0 - 3;
47
48 my %p;
49
50 # Scan the Packages file.
51 {
52 local $/ = '';
53 open P, '<', $fn_packages;
54 while (<P>) {
55 my( $name ) = /^Package: (\S+)/m
56 or die "$0: cannot determine the package name of\n$_\n";
57 for ( /^.*$/mg ) {
58 my( $key, $text ) = /^(\S+):(.*)$/ or next;
59 $field{$key} or next;
60 $p{$name} = 1 if $text =~ /$pat/;
61 }
62 }
63 close P;
64 }
65
66 # Filter the debram.txt body to stdout.
67 {
68 my $out = '';
69 my $doprint = '';
70 open D, '<', $fn_body;
71 while (<D>) {
72 if ( !/^\S/ ) {
73 $out .= $_;
74 print $out if $doprint || !$opt{x};
75 $out = '';
76 $doprint = '';
77 }
78 else {
79 my( $name ) = /^.{$w3} \267 (\S+)/;
80 if ( defined $name ) {
81 if ( $p{$name} ) {
82 $out .= $_ ;
83 $doprint = '1';
84 }
85 }
86 else {
87 $out .= $_;
88 }
89 }
90 }
91 close D;
92 print $out if $doprint || !$opt{x};
93 }
94
95 # Here are some interesting patterns to feed to the script:
96 # \b(?:perl(?:api)?\d*)\b
97 # \bpy|python
98 # ruby
99 # \b(?:lib)?(?:i|pl)?(?:tcl|tk)|expect|wish
100 # \b(?:lib(?:atk|bonobo\w*|cairo|gconf|gdk|gl|glade|glu|gnome\w*|gtk|ice|pango|qt|sdl|sm|x|xaw|xcursor|xext|xfixes|xft|xi|xinerama|xmu|xpm|xrandr|xrender|xt)|gconf|gdk|kdelibs|tcl|tk|x11|xfonts|xlibmesa|xlibs)\d*\b
101 # \b(?:lib(?:bonobo\w*|gconf|gnome\w*)|gconf)\d*\b
102 # libkde|kdelibs
103