#!/afs/net/tools/@sys/perl
#
# Vote counter program; for holding USENET-style votes
#

$VOTEDIR = "/afs/net/user/tytso/perl/vote/";

die "Usage: votecounter filename\n" unless @ARGV != 0;

$votefile = $ARGV[0]; shift;

open(LOCK, $VOTEDIR . $votefile) || die "Can't open $VOTEDIR$votefile";
flock(LOCK, 2);    #Grab an exclusive lock on the voter file

open(VOTE, ">>" . $VOTEDIR . $votefile) || 
	die "Can't open $VOTEDIR$votefile";
open(RAW, ">>" . $VOTEDIR . $votefile . ".raw") ||
	die "Can't open $VOTEDIR$votefile.raw";

while (<>) {
	last if /^$/;
	if (/^from: (.*)/i) {
		$fromuser = $1;
		print VOTE "$1\n";
	}
	print RAW;
}

while (<>) {
	print RAW;
}

print RAW "------------------------------ Vote Counter Boundary! -----\n;


