#! /usr/bin/perl # $Id$ # Check all '^Patch\d+' lines and '^%patch' lines are matching. use strict; use warnings; @ARGV=<*.spec> if !@ARGV; my $rc=0; for $ARGV (@ARGV) { local *FILE; open FILE,$ARGV or die "open $ARGV: $!"; my $file=do { undef $/; ; } or die "read $ARGV: $!"; close FILE or die "close $ARGV: $!"; my @source =sort { $a<=>$b; } ($file=~/^\s*patch(\d+)\s*:/mig); my @apply =sort { $a<=>$b; } ($file=~/^\s*%patch(\d+)\b/mig); my @applyno=sort { $a<=>$b; } ($file=~/^#+\s*%patch(\d+)\b/mig); my %applyno=map(($_=>1),@applyno); while (@source || @apply) { my $source=$source[0]; $source=999999 if !defined $source; my $apply =$apply[0]; $apply=999999 if !defined $apply; if ($source eq $apply) { shift @apply; shift @source; } elsif ($apply < $source) { shift @apply; warn "$ARGV: excessive: ".'%'."patch$apply\n"; $rc=1; } elsif ($source < $apply) { shift @source; if (!$applyno{$source}) { warn "$ARGV: excessive: Patch$source\n"; $rc=1; } else { warn "$ARGV: (commented ".'%'."patch$source: Patch$source)\n"; } } else { die if $apply ne $source; shift @apply; shift @source; } } } exit $rc;