#!/usr/bin/perl
#
# Usage: shasum [ <filename> ... ]
#
# $Id: shasum,v 1.3 1997/12/10 21:21:13 mhw Exp $
#

use SHA 1.1;

@fileList = ();

for $fileName (@ARGV)
{
	if (-d $fileName)
	{
		open(FIND, "find \"$fileName\" -type f -print | sort |") || die($!);
		while (<FIND>)
		{
			chop;
			push @fileList, $_;
		}
		close(FIND) || die($!);
	}
	else
	{
		push @fileList, $fileName;
	}
}

$sha = new SHA;

for $fileName (@fileList)
{
	open(FILE, "<$fileName") || die("$fileName: $!");
	$sha->reset();
	# $sha->addfile(FILE);
	while (<FILE>)
	{
		$sha->add($_);
	}
	$digest = $sha->hexdigest();
	$digest =~ s/ //g;
	print "$digest  $fileName\n";
	close(FILE) || die($!);
}

#
# vi: ai ts=4
# vim: si
#
