Move placeholders into a new rhash magic type.
[p5sagit/p5-mst-13.2.git] / Porting / manicheck
CommitLineData
93209f39 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
15BEGIN {
16 $SIG{__WARN__} = sub {
17 help() if $_[0] =~ /"main::\w" used only once: possible typo at /;
18 };
19}
20
21use strict;
22
23sub help {
24 die <<EOF;
bd6c346e 25$0: Usage: $0 [-x|-m|-l|-h]
93209f39 26-x show only the extra files
27-m show only the missing files
bd6c346e 28-l show the files one per line instead of one line
93209f39 29-h show only this help
30EOF
31}
32
bd6c346e 33use vars qw($x $m $l $h);
93209f39 34
35help() if $h;
36
37open(MANIFEST, "MANIFEST") or die "MANIFEST: $!";
38
39my %mani;
6501254e 40my %mand = qw(. 1);
41use File::Basename qw(dirname);
93209f39 42
43while (<MANIFEST>) {
44 if (/^(\S+)\t+(.+)$/) {
45 $mani{$1}++;
6501254e 46 my $d = dirname($1);
47 while($d ne '.') {
48 $mand{$d}++;
49 $d = dirname($d);
50 }
93209f39 51 } else {
52 warn "MANIFEST:$.:$_";
53 }
54}
55
56close(MANIFEST);
57
58my %find;
59use File::Find;
60find(sub {
6501254e 61 my $n = $File::Find::name;
62 $n =~ s:^\./::;
63 $find{$n}++;
93209f39 64 }, '.' );
65
66my @xtra;
67my @miss;
68
69for (sort keys %find) {
6501254e 70 push @xtra, $_ unless $mani{$_} || $mand{$_};
93209f39 71}
72
73for (sort keys %mani) {
74 push @miss, $_ unless $find{$_};
75}
76
bd6c346e 77$" = "\n" if $l;
78
79unshift @xtra, "extra:" if @xtra;
80unshift @miss, "missing:" if @miss;
81
82print "@xtra\n", if @xtra && !$m;
83print "@miss\n" if @miss && !$x;
93209f39 84
85exit 0;
86