#!/bin/sh
#
# judge - submit a problem solution to the judges 
#
# Usage: judge [filename]

address=contest@juliet.cs.duke.edu

echo Duke Internet Programming Contest Judged-Run Submission Program 

if test $# -eq 1; then
	filename=$1
elif test $# -gt 1; then
	echo Please provide only one argument, the name of the program file.
	exit 1
else
	echo -n "Enter the name of the program file: "
	read filename
fi

if test ! -r $filename; then
	echo File \"$filename\" is not accessible.
	exit 1
fi

echo -n "Enter the problem number: "
read problem

if test -n "${IPCTEAM}"; then
	   team=$IPCTEAM
else
	   echo -n "Enter your team number: "
	   read team
fi

if test $team -le 0; then
	echo "Your team number must be the number assigned to you when"
	echo "you registered at the start of the contest."
	exit 1
fi

echo -n 'Enter the compiler name (cc, gcc, pc, scc): '
read compiler
if test $compiler != cc -a $compiler != gcc -a $compiler != pc \
	-a $compiler != scc; then
    echo Compiler $compiler is not allowed.
    exit 1
fi

echo ""
echo Program file \"$filename\", problem number $problem, team number $team.
echo Compiler $compiler.
echo -n 'Confirm submission (type "yes"): '
read confirm

# if your system doesn't generate UTC time with the "date -u" command,
# replace the `date -u` below with `TZ=GMT0 date` and see if that works.
# if not, then you are out of luck (send me e-mail).

if test "$confirm" = "yes"; then
    sed 's/^/IPC /' $filename | Mail -s \
 "judge92 problem $problem team $team compiler $compiler time `date -u`"\
     $address
    echo Program submitted.
else
	echo Program not submitted.
fi
