#! /bin/csh

# PREPDIR -- Convert a large distribution file into a directory containing
# the split file and a CHECKSUMS file.
#
# Usage:	prepdir file[.Z] [file[.Z] ...]

while ($1 != "")
	# Compress file if not already compressed.
	if ($1:e == "Z") then
	    set file = $1
	else
	    echo "compress $1"
	    compress -f $1
	    set file = $1.Z
	endif

	# Split the distribution file.
	set dir = $file:r
	mkdir $dir
	echo -n "${file}: "
	cat $file | (cd $dir; bsplit -v -p ${file}.)

	# Make the CHECKSUMS file.
	set olddir = $cwd; cd $dir

	echo ${file}: >> CHECKSUMS
	echo "compute the BSD checksums"
	echo "	------ BSD checksums ------" >> CHECKSUMS
	foreach i (*.Z.[0-9][0-9])
	    echo -n "	$i	" >> CHECKSUMS
	    sum $i >> CHECKSUMS
	end

	echo "compute the SYSV checksums"
	echo "	------ SYSV checksums ------" >> CHECKSUMS
	foreach i (*.Z.[0-9][0-9])
	    echo -n "	" >> CHECKSUMS
	    /usr/5bin/sum $i >> CHECKSUMS
	end
	echo "" >> CHECKSUMS

	cd $olddir

	# Advance to next argument.
	rm -f $file
	shift
end
