This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Upgrade to CPAN-1.88_53.
[perl5.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|-l|-h]
26 -x show only the extra files
27 -m show only the missing files
28 -l show the files one per line instead of one line
29 -h show only this help
30 EOF
31 }
32
33 use vars qw($x $m $l $h);
34
35 help() if $h;
36
37 open(MANIFEST, "MANIFEST") or die "MANIFEST: $!";
38
39 my %mani;
40 my %mand = qw(. 1);
41 use File::Basename qw(dirname);
42
43 while (<MANIFEST>) {
44   if (/^(\S+)\t+(.+)$/) {
45     $mani{$1}++;
46     my $d = dirname($1);
47     while($d ne '.') {
48         $mand{$d}++;
49         $d = dirname($d);
50     }
51   } else {
52     warn "MANIFEST:$.:$_";
53   }
54 }
55
56 close(MANIFEST);
57
58 my %find;
59 use File::Find;
60 find(sub {
61        my $n = $File::Find::name;
62        $n =~ s:^\./::;
63        $find{$n}++;
64      }, '.' );
65
66 my @xtra;
67 my @miss;
68
69 for (sort keys %find) {
70   push @xtra, $_ unless $mani{$_} || $mand{$_};
71 }
72
73 for (sort keys %mani) {
74   push @miss, $_ unless $find{$_};
75 }
76
77 $" = "\n" if $l;
78
79 unshift @xtra, "extra:"   if @xtra;
80 unshift @miss, "missing:" if @miss;
81
82 print "@xtra\n", if @xtra && !$m;
83 print "@miss\n"  if @miss && !$x;
84
85 exit 0;
86