#!/usr/athena/bin/perl

$sigfile = "/mit/yoav/share/zephyr-sigs";
@sigs = ();
$sig_num = 0;
$shell = 0;
$lines = 0;

srand(time ^ $$);

if ($ARGV[0] eq "-shell") {
    $shell = 1;
}

open (SIGS,"<$sigfile");
while (<SIGS>){
    if ($_ !~ /^\#/) {
	if (length != 1) {
	    $lines++;
	    $sigs[$sig_num] = $sigs[$sig_num].$_;
	} else {
	    if (($lines > 1) && ($shell == 1)){
		$sigs[$sig_num] = "";
	    }
	    else {
		if ($lines > 0){
		    $sig_num++;
		}
	    }
	    $lines = 0;
	}
    }
}
if (($lines > 0) && ($shell == 1)){
    $sigs[$sig_num] = "";
    }
else {
    if ($lines >0) {
	$sig_num++;
    }
}
$lines = 0;
$new_sig = $sigs[(rand($sig_num))] ;

#if ($shell) {
#    $new_sig =~ s/([^\w\s])/\\$1/g ;
#}

print $new_sig;
