#!/usr/local/bin/perl -w-- # -*- perl -*-
#
# $Id: mkuuindex,v 1.6 1994/10/18 14:53:06 ejb Exp $
# $Source: /home/ejb/scripts/RCS/mkuuindex,v $
# $Author: ejb $
#
# Generation validation index file from ls -lR output.  The format of each
# line is 
# dir##good/good/good##bad/bad/bad
# where good is a plain file and bad is a directory or link.
#

# This code, from the perl manual page, forces this to be run by perl from 
# perl, sh, or csh.  It must be first.
eval '(exit $?0)' && eval 'exec /usr/local/bin/perl -S $0 ${1+"$@"}'
& eval 'exec /usr/local/bin/perl -S $0 $argv:q'
    if 0;

$whoami = ($0 =~ m,([^/]*)$,) ? $1 : $0;

$database = "/usr/local/archives/indexes/uunet.uu.net.idx";

$in_progress = 0;
@good = @bad = ();
$curdir = "";

unlink("$database");
open(DATABASE, ">$database") || die "$whoami: can't create $database\n";
foreach $f (</usr/local/archives/indexes/uunet.uu.net.a?>)
{
    if (open(INDEX, "<$f"))
    {
	while (<INDEX>)
	{
	    chop;
	    if (m,^([^\s]*):$,)
	    {
		&finish;
		$curdir = $1;
		$curfile = "";
	    }
	    else
	    {
		$in_progress = 1;
		@fields = split;
		if (scalar(@fields) >= 8)
		{
		    $curfile = $fields[7];
		    $filetype = $fields[0];
		    $filetype =~ s/^(.).*/$1/;
		    
		    if ($filetype eq "-")
		    {
			push(@good, $curfile);
		    }
		    else
		    {
			push(@bad, $curfile);
		    }
		}
	    }
	}
	close(INDEX);
    }
}
&finish;
close(DATABASE);

chmod 0444, $database;

sub finish {
    if ($in_progress)
    {
	local($good, $bad);
	$in_progress = 0;
	$good = join('/', @good);
	$bad = join('/', @bad);
	print DATABASE "$curdir##$good##$bad\n";
	@good = @bad = ();
    }
}
