.vimrc: +vim-fugitive
[nethome.git] / bin / checkspecpatch
1 #! /usr/bin/perl
2 # $Id$
3 # Check all '^Patch\d+' lines and '^%patch' lines are matching.
4
5 use strict;
6 use warnings;
7
8 @ARGV=<*.spec> if !@ARGV;
9
10 my $rc=0;
11 for $ARGV (@ARGV) {
12         local *FILE;
13         open FILE,$ARGV or die "open $ARGV: $!";
14         my $file=do { undef $/; <FILE>; } or die "read $ARGV: $!";
15         close FILE or die "close $ARGV: $!";
16
17         my @source =sort { $a<=>$b; } ($file=~/^\s*patch(\d+)\s*:/mig);
18         my @apply  =sort { $a<=>$b; } ($file=~/^\s*%patch(\d+)\b/mig);
19         my @applyno=sort { $a<=>$b; } ($file=~/^#+\s*%patch(\d+)\b/mig);
20         my %applyno=map(($_=>1),@applyno);
21         while (@source || @apply) {
22                 my $source=$source[0];
23                 $source=999999 if !defined $source;
24                 my $apply =$apply[0];
25                 $apply=999999 if !defined $apply;
26                 if ($source eq $apply) {
27                         shift @apply;
28                         shift @source;
29                 } elsif ($apply < $source) {
30                         shift @apply;
31                         warn "$ARGV: excessive: ".'%'."patch$apply\n";
32                         $rc=1;
33                 } elsif ($source < $apply) {
34                         shift @source;
35                         if (!$applyno{$source}) {
36                                 warn "$ARGV: excessive: Patch$source\n";
37                                 $rc=1;
38                         } else {
39                                 warn "$ARGV: (commented ".'%'."patch$source: Patch$source)\n";
40                         }
41                 } else {
42                         die if $apply ne $source;
43                         shift @apply;
44                         shift @source;
45                 }
46         }
47 }
48 exit $rc;