--- /dev/null
+#! /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 $/; <FILE>; } 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=(shift @source)||"";
+ my $apply =(shift @apply)||"";
+ next if $source eq $apply;
+ if ($source ne "" && $apply < $source) {
+ unshift @source,$source;
+ warn "$ARGV: excessive: ".'%'."patch$apply\n";
+ $rc=1;
+ }
+ if ($apply ne "" && $source < $apply) {
+ unshift @apply,$apply;
+ if (!$applyno{$source}) {
+ warn "$ARGV: excessive: Patch$source\n";
+ $rc=1;
+ } else {
+ warn "$ARGV: (commented ".'%'."patch$source: Patch$source)\n";
+ }
+ }
+ }
+}
+exit $rc;