#!/bin/perl5
# -*- perl -*-

chdir ".." unless -d "distrib";

print "reading manifests\n";
opendir(D, "manifest");
while ($f = readdir(D))
{
    next unless $f =~ /\.mft$/;
    open(M, "manifest/$f");
    while (<M>) {
	s/[\r\n]+$//;
	$saw{$_}++;
	$saw_in_crx{$_}++ if $f =~ /djcrx/;
    }
    close(M);
}
closedir(D);

for $f (sort keys %saw) {
    $count_files ++;
    if ($saw{$f} > ($saw_in_crx{$f} ? 2 : 1)) {
	push(@doubled, $f);
    }
}
$count_doubled = $#doubled + 1;

print "$count_files files, $count_doubled in more than one zip\n";
for $f (@doubled) {
    printf "%5d %s\n", $saw{$f}, $f;
}

print "\nRemaining files...\n";
open(F, "find * -type f -print | sort |");
open(O, "| distrib/nobins");
while (<F>) {
    s/[\r\n]+$//;
    next if $saw{$_};
    next if m@\.[do]$@;
    next if m@makefile.oh$@;
    next if m@^(zips|hostbin|distrib)/@;
    next if m@^tests/.*\.exe@;
    next if m@^src/libm/.*\.def@;
    next if m@^contrib/aspi@;
    print O "$_\n";
}

close F;
close O;
