#!/usr/bin/perl
#
#   tce name [files]...
#
# Tar+Compress+uuEncode
#
# This runs tar on the files, compresses the archive, uuencodes the .Z  file,
# and  and  chops  the  result up into 50K chunks.  The files have names that
# start with the "name" arg and end with 01, 02, 03, ....  The result  should
# get anywhere in the email "system" undamaged.  To unpack it, you need to do
# the inverse operations:  Use sh to reconstruct the uuencoded archive,  feed
# that  to  uudecode to build the .Z file, uncompress to get the tar archive,
# and finally tar to extract the files. There's no program to do this, due to
# the hassle in determining where uudecode puts its output.
#
# See also tcb, a similar script which uses btoa, and aut which  unpacks  the
# stuff at the other end.
#
$name = shift || &usage;
$count = $limit = 50000;
open(data, "tar cf - @ARGV | compress | uuencode $name.tar.Z |")
	|| die "Can't run tar|compress|uuencode";
#
while (<data>) {
	&newfile if (($count += length) > $limit);
	print outfile;
}
exit $?;
#
sub newfile {
	$suffix = sprintf("%02d",++$filnum);
	open(outfile,">$name.$suffix")
		|| die "$$: Can't write to \"$name.$suffix\"";
	print outfile "Subject: $name.$suffix [tar+compress+uuencode]\n\n";
	$count = 0;
}
#
sub usage {
	die "Usage: $0 name [file]...";
}
