#!/bin/sh
#
# submit - submit a problem solution to the judges 
#
# Usage: submit [filename]
# $Id: submit.sh,v 1.13 1993/11/10 18:42:23 khera Exp $

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
# now make sure it is numeric only
if expr match "$problem" "[0-9]*" >/dev/null ; then
	echo -n ""
else
	echo "The problem number must be a number"
	exit 1
fi

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

# note that these must agree with the judge program's list (in order!)
echo 'Choose the number of the language to run this program:'
echo '  1) C'
echo '  2) GNU C++'
echo '  3) Objective-C'
echo '  4) Pascal'
echo '  5) FORTRAN'
echo '  6) Scheme'
echo '  7) Haskell'
echo '  8) Literate Haskell'
echo '  9) Perl'
echo ' 10) Icon'
echo ' 11) Sun C++'
echo ' 12) Emacs Lisp'
echo ' 13) Standard ML'
echo ' 14) Matlab'
echo ' 15) Common Lisp'
echo ' 16) Ada'
echo -n 'Enter selection: '
read language

if test "$language" -le 0 -o "$language" -gt 16; then
    echo Language $language is not allowed.
    exit 1
fi

echo ""
echo Program file \"$filename\", problem number $problem, team number $team.
echo Language number $language.
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
    echo '' | cat $filename - | sed 's/^/IPC /' | Mail -s \
 "judge93 problem $problem team $team language $language time `contestdate.sh -u`"\
     $address
    echo Program submitted.
else
	echo Program not submitted.
fi
