#!/bin/csh
# Usage: testprob team prob [version]
if ($#argv < 2 || $#argv > 3) then
	echo Usage: $0 "team prob [version]"
	exit(1)
endif

set team = $1
set prob = $2

set teamdir = `printprobdir`/subs/$team

if (! -d $teamdir) then
	echo $0: no subs directory for $team
	echo $0: $teamdir not found
	exit(1)
endif
cd $teamdir

if ($#argv == 3) then
	set version = $3
else
	set version = 1
	set nonomatch
	while (-e problem$prob$version.c || -e problem$prob$version.mod || -e problem$prob$version.p)
		@ version++
	end
	unset nonomatch
	@ version--
endif
set prog = problem$prob$version

make -f ../../../comp.Makefile $prog
limit cputime 2:00
set outfile = p$prob.$version.out
cat ../../input/$prob | ../../../src/dispatch $prog | egrep -v '^%' >$outfile
echo Contest `printcompname`\; program $prog
if (-f ../../check/check$prob) then
# A checking program is provided - use it
	../../check/check$prob <$outfile
else
# Otherwise, can just use straight diff
	echo "Judge <, $team >"
	diff ../../answers/$prob $outfile
endif
