#!/afs/athena/contrib/perl/perl
open (FI,"/mit/mkgray/.zephyr.vars")||die "Couldn't get zephyr vars";

foreach $n (1..$#ARGV) {
	if ($ARGV[$n] eq "-s") {
		$sig = $ARGV[$n+1];
		$done = 1;
		}
	elsif (!($ARGV[$n-1] eq "-s")) {
		$tail = $tail." ".$ARGV[$n];
#		if($ARGV[$n] !~ /-/){$towho = $ARGV[$n];}
#		print("Current tail: $tail\n");
		}
	}
if (!$done) {
#	print("Looking for -zsig-$ARGV[0]-\n");
while (<FI>) {
        ($v, $e, @value) = split;
        $value = join (" ", @value);
#	print("Looking at :$v:  -$value-\n");
                if ($v eq "zsig-$ARGV[0]") {
                        $sig = $value;
#			print("!!!Setting sig!!!\n");
                        $done = 1;
                }
}
}
        if ($done) {
#               print ("Executing: zwrite -d $ARGV[0] -s $sig $tail");
		print("To: $ARGV[0]\t\tSig: $sig\n");
                system("zwrite $ARGV[0] -d -s \"$sig\" $tail");
}
        else{
#               print ("Executing: zwrite -d $ARGV[0] $tail");
                system("zwrite $ARGV[0] $tail");
}































