#!/usr/bin/perl
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
#NAME
#  Zip - Wrapper around zip command
#
#SYNOPSIS
#  Zip [file]..
#
#DESCRIPTION
#  This script is mostly for using zip to compress big files.
#
#  What it does is make each named file into a zip file by removing its
#  suffix and packing it (and all other files with the same basename) into
#  a zip file.
#
#  So if the command
#    zip foo bar
#  will package all files "foo.*" into "foo.zip", and also package "bar.*"
#  into "bar.zip".
#
#OPTIONS
#  None yet.
#
#EXAMPLES
#
#FILES
#
#BUGS
#
#SEE ALSO
#
#AUTHOR
#  John Chambers <jc@trillian.mit.edu>
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #

$| = 1;
$exitstat = 0;
($P = $0) =~ s".*/"";
$V = $ENV{"V_$P"} || $ENV{"D_$P"} || 2;	# Verbose level.

for $path (@ARGV) {
	$base = $path;
	(($base,$suff) = ($base =~ m"^(.*)\.(.*)$"));
	if (-f "$base.zip") {
		print "--- $base.zip exists.\n";
		next;
	}
	print "Zip $base.zip ...\n";
	system "zip $base $base.*";
	if ($?) {
		print STDERR \"zip $base $base.*\" failed ($?)\n";
		$exitstat = $?;
	}
}

print "$P: Exit with status $exitstat.\n" if $V>1;
exit $exitstat;

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
