summaryrefslogtreecommitdiff
path: root/Porting/manicheck
blob: 9ba83606fc4a95d88eda6cae995748d4b1aa957a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/perl -ws

#
# manicheck - check files against the MANIFEST
#
# Without options prints out (possibly) two lines:
#
# extra: a b c
# missing: d
#
# With option -x prints out only the missing files (and without the "extra: ")
# With option -m prints out only the extra files (and without the "missing: ")
#

BEGIN {
  $SIG{__WARN__} = sub {
    help() if $_[0] =~ /"main::\w" used only once: possible typo at /;
  };
}

use strict;

sub help {
  die <<EOF;
$0: Usage: $0 [-x|-m|-l|-h]
-x show only the extra files
-m show only the missing files
-l show the files one per line instead of one line
-h show only this help
EOF
}

use vars qw($x $m $l $h);

help() if $h;

open(MANIFEST, "MANIFEST") or die "MANIFEST: $!";

my %mani;
my %mand = qw(. 1);
use File::Basename qw(dirname);

while (<MANIFEST>) {
  if (/^(\S+)\t+(.+)$/) {
    $mani{$1}++;
    my $d = dirname($1);
    while($d ne '.') {
	$mand{$d}++;
	$d = dirname($d);
    }
  } else {
    warn "MANIFEST:$.:$_";
  }
}

close(MANIFEST);

my %find;
use File::Find;
find(sub {
       my $n = $File::Find::name;
       $n =~ s:^\./::;
       $find{$n}++;
     }, '.' );

my @xtra;
my @miss;

for (sort keys %find) {
  push @xtra, $_ unless $mani{$_} || $mand{$_};
}

for (sort keys %mani) {
  push @miss, $_ unless $find{$_};
}

$" = "\n" if $l;

unshift @xtra, "extra:"   if @xtra;
unshift @miss, "missing:" if @miss;

print "@xtra\n", if @xtra && !$m;
print "@miss\n"  if @miss && !$x;

exit 0;