20125d8cf8cb55b1f144d6b2d1b0f26070a7b76b
[p5sagit/p5-mst-13.2.git] / Porting / manicheck
1 #!/usr/bin/perl -ws
2
3 #
4 # manicheck - check files against the MANIFEST
5 #
6 # Without options prints out (possibly) two lines:
7 #
8 # extra: a b c
9 # missing: d
10 #
11 # With option -x prints out only the missing files (and without the "extra: ")
12 # With option -m prints out only the extra files (and without the "missing: ")
13 #
14
15 BEGIN {
16   $SIG{__WARN__} = sub {
17     help() if $_[0] =~ /"main::\w" used only once: possible typo at /;
18   };
19 }
20
21 use strict;
22
23 sub help {
24   die <<EOF;
25 $0: Usage: $0 [-x|-m|-h]
26 -x show only the extra files
27 -m show only the missing files
28 -h show only this help
29 EOF
30 }
31
32 use vars qw($x $m $h);
33
34 help() if $h;
35
36 open(MANIFEST, "MANIFEST") or die "MANIFEST: $!";
37
38 my %mani;
39
40 while (<MANIFEST>) {
41   if (/^(\S+)\t+(.+)$/) {
42     $mani{$1}++;
43   } else {
44     warn "MANIFEST:$.:$_";
45   }
46 }
47
48 close(MANIFEST);
49
50 my %find;
51 use File::Find;
52 find(sub {
53        if(-f $_) {
54          my $f = $File::Find::name;
55          $f =~ s:^\./::;
56          $find{$f}++;
57        }
58      }, '.' );
59
60 my @xtra;
61 my @miss;
62
63 for (sort keys %find) {
64   push @xtra, $_ unless $mani{$_};
65 }
66
67 for (sort keys %mani) {
68   push @miss, $_ unless $find{$_};
69 }
70
71 printf("%s@xtra\n", $x || $m ? "" : "extra: ")   if @xtra && !$m;
72 printf("%s@miss\n", $x || $m ? "" : "missing: ") if @miss && !$x;
73
74 exit 0;
75