#!/usr/bin/perl -w use strict; sub print_usage { print "Usage: rbd package [...]\nPrint reverse build-depends list of given package(s)\n"; exit; } print_usage unless(@ARGV); foreach (0..$#ARGV) { print_usage if($ARGV[$_]=~/^-/); } my @results; my $package; foreach () { open FILE, "<$_" or die "Cannot open cache $_: $!\n"; while () { if(/^Package:\s(.+)$/) { $package=$1; } if(/^Build-Depend(?:s|s-Indep):\s(.+)$/) { my $list=$1; foreach (0..$#ARGV) { push(@{$results[$_]}, $package) if($list=~/\b\Q$ARGV[$_]\E\b/); } } } close FILE or die $!; } foreach (0..$#ARGV) { print "$ARGV[$_]\nReverse Build-Depends:\n"; if($results[$_]) { my @sorted=sort(@{$results[$_]}); foreach my $package (@sorted) { print " $package\n"; } } }