X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=bin%2Flib;h=ea516f17ede8cf3c42a6d6be7361d1eb2cf50e2f;hb=51e6d3494735a2f5ab576731d7c14ae535550573;hp=cb5e2150d2f9402a35d424a1cc2ebf44563f9884;hpb=ec0ab4919197e1fed514c677e5db2cd5d3ef2183;p=eval.git diff --git a/bin/lib b/bin/lib index cb5e215..ea516f1 100644 --- a/bin/lib +++ b/bin/lib @@ -1,5 +1,5 @@ # The Evaluator -- Shell Function Library -# (c) 2001--2004 Martin Mares +# (c) 2001--2007 Martin Mares # General settings shopt -s dotglob @@ -44,6 +44,11 @@ function fatal exit 1 } +function try-ln +{ + ln $1 $2 2>/dev/null || cp $1 $2 +} + # Sandbox subroutines function box-init @@ -99,16 +104,41 @@ EOF pend "OK" } -# Locating source file in SDIR, pass name in SRCN (without path) and extension in SRCEXT +# Locate source file. +# If no parameter is given, locate it in SDIR and return name as SRCN and extension as SRCEXT +# Or a file name can be given and then SDIR, SRCN and SRCEXT are set. +# Beware, SDIR and SRCN can contain spaces and other strange user-supplied characters. function locate-source { pstart "Finding source... " - SBASE=${1:-$PROBLEM} + local SBASE + if [ -n "$1" ] ; then + SDIR=`dirname "$1"` + local S=`basename "$1"` + SBASE=$(echo "$S" | sed 's/\.\([^.]\+\)//') + SRCEXT=$(echo "$S" | sed '/\./!d; s/.*\.\([^.]\+\)/\1/') + if [ -n "$SRCEXT" ] ; then + # Full name given, so just check the extension and existence + SRCN="$S" + [ -f "$SDIR/$SRCN" ] || die "Cannot find source file $SDIR/$SRCN" + SRCEXT_OK= + for a in $EXTENSIONS ; do + if [ $a == $SRCEXT ] ; then + pend $SDIR/$SRCN + echo "Explicitly set source file: $SDIR/$SRCN" + return 0 + fi + done + die "Unknown extension .$SRCEXT" + fi + else + SBASE=$PROBLEM + fi for a in $EXTENSIONS ; do - if [ -f $SDIR/$SBASE.$a ] ; then + if [ -f "$SDIR/$SBASE.$a" ] ; then [ -z "$SRCN" ] || die "Multiple source files found: $SDIR/$PROBLEM.$a and $SDIR/$SRCN. Please fix." - SRCN=$SBASE.$a + SRCN="$SBASE.$a" SRCEXT=$a fi done @@ -122,14 +152,15 @@ function locate-source function compile { pstart "Compiling... " - cp -a $SDIR/$SRCN $TDIR/$SRCN + # Beware, the original SRCN can be a strange user-supplied name + SRC=$PROBLEM.$SRCEXT + cp "$SDIR/$SRCN" $TDIR/$SRC if [ -n "$COMP_EXTRAS" ] ; then echo "Extras: $COMP_EXTRAS" for a in $COMP_EXTRAS ; do cp $PDIR/$a $TDIR/ ; done fi box-clean - for a in $SRCN $COMP_EXTRAS ; do cp $TDIR/$a $BOXDIR/ ; done - SRC=$SRCN + for a in $SRC $COMP_EXTRAS ; do cp $TDIR/$a $BOXDIR/ ; done EXE=$PROBLEM CCMD=COMP_$SRCEXT CCMD=`eval echo ${!CCMD}` @@ -196,12 +227,12 @@ function test-prolog OUT_TYPE=${OUT_TYPE:-$IO_TYPE} case $IN_TYPE in file) echo "Input file: $PROBLEM.in (from $PDIR/$TEST.in)" - ln $PDIR/$TEST.in $TDIR/$TEST.in + try-ln $PDIR/$TEST.in $TDIR/$TEST.in cp $PDIR/$TEST.in $BOXDIR/$PROBLEM.in - BOX_EXTRAS="$BOX_EXTRAS -i/dev/null" + [ $TASK_TYPE == interactive ] || BOX_EXTRAS="$BOX_EXTRAS -i/dev/null" ;; stdio) echo "Input file: (from $PDIR/$TEST.in)" - ln $PDIR/$TEST.in $TDIR/$TEST.in + try-ln $PDIR/$TEST.in $TDIR/$TEST.in cp $PDIR/$TEST.in $BOXDIR/.stdin BOX_EXTRAS="$BOX_EXTRAS -i.stdin" ;; @@ -212,7 +243,7 @@ function test-prolog esac case $OUT_TYPE in file) echo "Output file: $PROBLEM.out" - BOX_EXTRAS="$BOX_EXTRAS -o/dev/null" + [ $TASK_TYPE == interactive ] || BOX_EXTRAS="$BOX_EXTRAS -o/dev/null" ;; stdio) echo "Output file: " BOX_EXTRAS="$BOX_EXTRAS -o.stdout" @@ -272,7 +303,7 @@ function test-run-interactive echo "Interactive checker: $ICCMD" if ! $HDIR/bin/iwrapper $BOXCMD $BOXOPTS -- ./$PROBLEM @@ $ICCMD 2>$TMPDIR/exec.out ; then cat $TMPDIR/exec.out - MSG="`tail -1 $TMPDIR/exec.out`" + MSG="`head -1 $TMPDIR/exec.out`" test-result 0 "$MSG" fi cat $TMPDIR/exec.out @@ -300,19 +331,21 @@ function syntax-check function output-check { - [ -n "$OUTPUT_CHECK" ] || return 0 - pcont " " - [ -f $PDIR/$TEST.out ] && ln $PDIR/$TEST.out $TDIR/$TEST.ok - OCHECK=`eval echo $OUTPUT_CHECK` - echo "Output check command: $OCHECK" - if ! eval $OCHECK 2>$TMPDIR/exec.out ; then + MSG= + if [ -n "$OUTPUT_CHECK" -a "$OUT_TYPE" != none ] ; then + pcont " " + [ -f $PDIR/$TEST.out ] && ln $PDIR/$TEST.out $TDIR/$TEST.ok + OCHECK=`eval echo $OUTPUT_CHECK` + echo "Output check command: $OCHECK" + if ! eval $OCHECK 2>$TMPDIR/exec.out ; then + cat $TMPDIR/exec.out + MSG=`tail -1 $TMPDIR/exec.out` + if [ -z "$MSG" ] ; then MSG="Wrong answer." ; fi + test-result 0 "$MSG" + fi cat $TMPDIR/exec.out MSG=`tail -1 $TMPDIR/exec.out` - if [ -z "$MSG" ] ; then MSG="Wrong answer." ; fi - test-result 0 "$MSG" fi - cat $TMPDIR/exec.out - MSG=`tail -1 $TMPDIR/exec.out` if [ -z "$MSG" ] ; then MSG="OK" ; fi test-result $POINTS_PER_TEST "$MSG" } @@ -321,8 +354,8 @@ function output-check function public-setup { - HDIR=$MO_PUBLIC - PDIR=$MO_PUBLIC/problems/$PROBLEM + HDIR=$MO_ROOT + PDIR=$MO_ROOT/problems/$PROBLEM SDIR=. TDIR=~/.test TMPDIR=~/.test @@ -334,16 +367,22 @@ function public-setup BOXDIR=~/.box mkdir -p $BOXDIR rm -rf $BOXDIR/* - BOXCMD="$MO_PUBLIC/bin/box -c$BOXDIR" - exec >log - pend "OK (see 'log' for details)" + BOXCMD="$MO_ROOT/bin/box -c$BOXDIR" + exec >check-log + pend "OK (see 'check-log' for details)" } # Locate output of open data problem, test case TEST +# Beware, SDIR and SRCN can contain spaces and other strange user-supplied characters. function open-locate { [ -f $PDIR/$TEST.in ] || die "Unknown test $TEST" - SRCN=$SDIR/$PROBLEM$TEST.out + if [ -n "$1" ] ; then + SDIR=`dirname "$1"` + SRCN=`basename "$1"` + else + SRCN=$SDIR/$PROBLEM$TEST.out + fi [ -f $SRCN ] || fatal "Output file $SRCN not found" }