#!/usr/local/bin/perl -w # # Change that path if your perl ain't in /usr/local/bin # # submit.pl # # simple perl script to handle submitting stuff via email to judges. # # not very pretty... # # Copyright (C) 2000-2006 Ben Breech # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # # # Ben Breech 1/17/00 # fiddled with 10/15/02 to put in java. # fiddled with 10/25/04 to put in some meta data into the email use strict; my ($judge, $mailer, $file, $prob, $team, $foo, $lang); my ($prefix, $prefix_meta, @stamp); # address of the person receiving submissions. Don't forget to put # a \ in front of the @ sign. Otherwise perl won't like it very much. $judge = "breech\@cis.udel.edu"; # mailer to use on this system. Put SUBJECT where the mailer expects # to see the subject heading (don't worry. SUBJECT will get replaced # later on) ADDR is where the mailer wants the address of the recepient. # here's some example mailers to use. # the following works on Solaris $mailer = "/bin/mailx -s SUBJECT ADDR"; # linux (redhat at least) # $mailer = "/bin/mail -s SUBJECT ADDR"; # digital UNIX # $mailer = "/usr/bin/mailx -s SUBJECT ADDR"; # this is a prefix that gets added to each line of the submitted file. # don't change this. the script the judges use looks for this # and will strip it out. # $prefix = "UD00 "; $prefix_meta = "METAUD00 "; if ($#ARGV > 0) { usage (); exit (1); } $file = file_name (); $prob = prob_num (); $lang = lang_num (); $team = team_num (); print "\n\n"; print "This is what you've given me: \n"; print "Team: $team\n"; print "Problem: $prob\n"; print "Language: $lang\n"; print "File: $file\n"; print "\n"; print "Last chance to back out.\n"; print "If you hit return here, I'll assume a `yes'\n"; print "Should I submit this (y/n) --> "; $foo = ; chomp $foo; if ($foo eq "" || $foo =~ /y.*/i) { my $sub = "UD00 problem $prob team $team language $lang"; my $line; $mailer =~ s/SUBJECT/\"$sub\"/; $mailer =~ s/ADDR/$judge/; open (FH, $file) or die "Can't open $file. Bye.\n"; open (MAIL, "|" . $mailer) or die "Can't open mailer program. Bye.\n"; # need the meta data to parse information. some mailers # refuse to allow the subject line to be set # (*cough* UD *cough*), so for them, the meta data # becomes the only way to tell. @stamp = localtime (time); print MAIL $prefix_meta, "Team: ", $team, "\n"; print MAIL $prefix_meta, "Lang: ", $lang, "\n"; print MAIL $prefix_meta, "prob: ", $prob, "\n"; print MAIL $prefix_meta, "Time: ", $stamp[2], ":", $stamp [1], ":", $stamp [0], "\n"; while (defined ($line = )) { print MAIL $prefix, $line; } close (FH); close (MAIL); print "$file submitted for judging.\n"; } else { print "$file NOT SUBMITTED.\n"; } exit (0); # # usage # # prints a (hopefully useful) usage message. # sub usage { print "Usage: $0 [filename]\n\n"; print " where filename is the name of the file to submit.\n"; print " if no filename is provided, you'll be asked.\n"; } # # team_num # # gets the team number, and does a quick check or two on it. # sub team_num { my $t; print "Team number: "; $t = ; chomp $t; if ($t !~ /^[0-9]+$/) { print "$t: Invalid team number. Bye\n"; exit (1); } return $t; } # # prob_num # # gets the problem number and does a quick check or two on it. sub prob_num { my $p; print "Problem number: "; $p = ; chomp $p; if ($p !~ /^[0-9]+$/) { print "$p: Invalid problem number. Bye\n"; exit (1); } return $p; } # # file_name # # gets the file name and does a quick check or two on it. # sub file_name { my $f; if ($#ARGV == 0) { $f = $ARGV [0]; } else { print "Name of the file to submit: "; $f = ; chomp $f; } if (! -r $f) { print "$f: No such file. Bye\n"; exit (2); } return $f; } # # lang_num # # gets the language number. Note that these must agree with the # judge's language numbers. # sub lang_num { my $lang; print "Choose the number of the language to run this program:\n"; print " 1) C\n"; print " 2) C++\n"; print " 3) Java\n"; print "Enter selection --> "; $lang = ; chomp $lang; if ($lang eq "") { $lang = 1; } if ($lang !~ /^[1-9]$/) { print "$lang is invalid. Bye.\n"; exit (2); } return $lang; }