#! /usr/bin/perl

##  Generate a filename-only manifest from an INN tree.
##
##  This script generates a filename-only manifest from an INN tree, excluding
##  certain files according to built-in rules and a list at the end of this
##  file.  It is intended to be used to support make check-manifest from the
##  top level of the INN tree.

require 5.005;

use strict;
use warnings;

use File::Find qw(find);
use vars qw(@FILES %IGNORE @IGNORE);

# The following regex patterns match files to be ignored wherever they are in
# the tree.  This is intended to handle files that CVS, Subversion or Git
# ignores by default.
@IGNORE = (
    qr%(\A|/)\.cvsignore\Z%, qr%(\A|/)CVS(/|\Z)%,
    qr%(\A|/)\.svn(/|\Z)%,
    qr%(\A|/)\.vscode(/|\Z)%,
    qr%(\A|/)\.gitignore\Z%, qr%(\A|/)\.git(/|\Z)%,
    qr%(\A|/)\.git-blame-ignore-revs(/|\Z)%,
    qr/\.l?[ao]\Z/, qr%(\A|/)\.?\#%, qr%(\A|/)core\Z%,
    qr/\.(old|bak|orig|rej)$/, qr/~$/, qr%(\A|/)\.pure$%,
    qr%(\A|/)\.libs(/|\Z)%,
);

# Load file names and patterns from the DATA section.
sub load_exclusions {
    local $_;
    while (<DATA>) {
        next if /^\s*\#/;
        next if /^\s*$/;
        chomp;
        if (/\*/) {
            my $pattern = $_;
            $pattern =~ s%\*%[^/]*%g;
            $pattern =~ s/\./\\./g;
            push(@IGNORE, qr/^$pattern$/);
        } else {
            $IGNORE{$_} = 1;
        }
    }
}

# Build a list of all files in the tree that aren't ignored by the version
# control software or listed in ignore regexes.
sub find_files {
    return if $_ eq '.';
    my $name = $File::Find::name;
    $name =~ s%^./%%;
    if ($IGNORE{$name}) {
        $File::Find::prune = 1;
        return;
    }
    for my $pattern (@IGNORE) {
        return if $name =~ /$pattern/;
    }
    push(@FILES, $name);
}

load_exclusions;
find(\&find_files, '.');
print join("\n", (sort @FILES), '');

__DATA__

# The following additional files should be ignored.  The file names are
# relative to the root of the tree.  Shell wildcards are supported.
BOOTSTRAP
LIST.*
Makefile.global
README.*
autom4te.cache
config.cache
config.log
config.status
config.status.lineno
configure.lineno
inn-*
libtool
snapshot.log
authprogs/auth_krb5
authprogs/ckpasswd
authprogs/domain
authprogs/ident
authprogs/radius
backends/actmerge
backends/actsync
backends/actsyncd
backends/archive
backends/batcher
backends/buffchan
backends/cvtbatch
backends/delayer
backends/innbind
backends/inndf
backends/innxbatch
backends/innxmit
backends/mod-active
backends/news2mail
backends/ninpaths
backends/nntpget
backends/nntpsend
backends/overchan
backends/send-ihave
backends/send-uucp
backends/sendinpaths
backends/sendxbatches
backends/shlock
backends/shrinkfile
contrib/analyze-traffic
contrib/archivegz
contrib/auth_pass
contrib/authmysql
contrib/backlogstat
contrib/cleannewsgroups
contrib/count_overview
contrib/expirectl
contrib/findreadgroups
contrib/fixhist
contrib/innconfcheck
contrib/makeexpctl
contrib/makestorconf
contrib/mkbuf
contrib/mlockfile
contrib/newsresp
contrib/nnrp.access2readers.conf
contrib/ovsqlite-dump
contrib/ovsqlite-undump
contrib/pullart
contrib/reset-cnfs
contrib/respool
contrib/stathist
contrib/thdexpire
contrib/tunefeed
control/controlbatch
control/controlchan
control/docheckgroups
control/gencancel
control/perl-nocem
control/pgpverify
doc/man/index.db
expire/convdate
expire/expire
expire/expireover
expire/expirerm
expire/fastrm
expire/grephistory
expire/makedbz
expire/makehistory
expire/prunehistory
frontends/bunbatch
frontends/c7unbatch
frontends/cnfsheadconf
frontends/cnfsstat
frontends/ctlinnd
frontends/decode
frontends/encode
frontends/feedone
frontends/getlist
frontends/gunbatch
frontends/inews
frontends/innconfval
frontends/mailpost
frontends/ovdb_init
frontends/ovdb_monitor
frontends/ovdb_server
frontends/ovdb_stat
frontends/pullnews
frontends/rnews
frontends/scanspool
frontends/sm
frontends/sys2nf
history/buildconfig
include/config.h
include/inn/paths.h
include/inn/portable-getaddrinfo.h
include/inn/portable-getnameinfo.h
include/inn/portable-macros.h
include/inn/portable-socket.h
include/inn/portable-stdbool.h
include/inn/system.h
include/inn/version.h
innd/innd
innd/tinyleaf
innfeed/imapfeed
innfeed/innfeed
innfeed/procbatch
nnrpd/nnrpd
perl/INN/Config.pm
perl/INN/Utils/Shlock.pm
samples/buffindexed.conf
samples/inn.conf
samples/innreport.conf
samples/newsfeeds
samples/nnrpd_access.pl
samples/nnrpd_auth.pl
scripts/inncheck
scripts/innmail
scripts/innreport
scripts/innshellvars
scripts/innshellvars.pl
scripts/innshellvars.tcl
scripts/innstat
scripts/innupgrade
scripts/innwatch
scripts/news.daily
scripts/rc.news
scripts/scanlogs
scripts/simpleftp
scripts/tally.control
scripts/writelog
site/INN.py
site/active.minimal
site/actsync.cfg
site/actsync.ign
site/buffindexed.conf
site/config
site/control.ctl
site/control.ctl.local
site/cycbuff.conf
site/distrib.pats
site/distributions
site/expire.ctl
site/filter_innd.pl
site/filter_innd.py
site/filter_nnrpd.pl
site/incoming.conf
site/inn-radius.conf
site/inn-secrets.conf
site/inn.conf
site/innfeed.conf
site/innreport.conf
site/innreport.css
site/innshellvars.local
site/innshellvars.pl.local
site/innshellvars.tcl.local
site/innwatch.ctl
site/localgroups
site/moderators
site/motd.innd
site/motd.nnrpd
site/news2mail.cf
site/newsfeeds
site/newsgroups.minimal
site/nnrpd.py
site/nnrpd.track
site/nnrpd_access.pl
site/nnrpd_access.py
site/nnrpd_auth.pl
site/nnrpd_auth.py
site/nnrpd_dynamic.py
site/nntpsend.ctl
site/nocem.ctl
site/ovdb.conf
site/ovsqlite.conf
site/passwd.nntp
site/readers.conf
site/send-uucp.cf
site/startup_innd.pl
site/storage.conf
site/subscriptions
site/update
storage/buffindexed/buffindexed_d
storage/buildconfig
storage/ovsqlite/ovsqlite-server
storage/ovsqlite/ovsqlite-util
storage/ovsqlite/sqlite-helper-gen
storage/tradindexed/tdx-util
support/fixconfig
support/fixscript
tests/runtests
tests/authprogs/ident.t
tests/clients/server-list
tests/docs/pod.t
tests/innd/artparse.t
tests/innd/chan.t
tests/lib/artnumber.t
tests/lib/asprintf.t
tests/lib/buffer.t
tests/lib/canlock.t
tests/lib/concat.t
tests/lib/conffile.t
tests/lib/confparse.t
tests/lib/daemon.t
tests/lib/date.t
tests/lib/dispatch.t
tests/lib/fdflag.t
tests/lib/getaddrinfo.t
tests/lib/getnameinfo.t
tests/lib/hash.t
tests/lib/hashtab.t
tests/lib/headers.t
tests/lib/hex.t
tests/lib/inet_aton.t
tests/lib/inet_ntoa.t
tests/lib/inet_ntop.t
tests/lib/innconf.t
tests/lib/list.t
tests/lib/md5.t
tests/lib/messageid.t
tests/lib/messages.t
tests/lib/mkstemp.t
tests/lib/network/addr-ipv4.t
tests/lib/network/addr-ipv6.t
tests/lib/network/client.t
tests/lib/network/server.t
tests/lib/pread.t
tests/lib/pwrite.t
tests/lib/qio.t
tests/lib/reallocarray.t
tests/lib/setenv.t
tests/lib/snprintf.t
tests/lib/strlcat.t
tests/lib/strlcpy.t
tests/lib/tst.t
tests/lib/uwildmat.t
tests/lib/vector.t
tests/lib/wire.t
tests/lib/xmalloc
tests/lib/xwrite.t
tests/nnrpd/auth-ext.t
tests/overview/api.t
tests/overview/buffindexed.t
tests/overview/tradindexed.t
tests/overview/xref.t
tests/perl/minimum-version.t
tests/util/innbind.t
