#!/bin/sh
#
# clarify - submit a clarification request to the judges 
#
# Usage: clarify

address=contest@juliet.cs.duke.edu

tmp=/tmp/IPC$$
trap "rm -f $tmp; exit" 2 15

echo Duke Internet Programming Contest Clarification Submission Program 

if test $# -ne 0; then
	echo Arguments ignored.
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

if test -n "${EDITOR}"; then
    echo "Enter your question below, then exit the editor:" > $tmp
    echo Running ${EDITOR}...
    ${EDITOR} $tmp
else
    echo "Enter your question below; terminate with ^D:"
    cat > $tmp
fi

# make sure terminated with new line
echo "" >>$tmp

echo ""
echo Problem number $problem, team number $team.
echo -n 'Confirm clarification submission ["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" -o "$confirm" = ""; then
    sed 's/^/IPC /' $tmp \
	| Mail -s "question93 problem $problem team $team `contestdate.sh`" \
	$address
    echo Clarification submitted.
else
    echo Clarification not submitted.
fi

rm -f $tmp
