X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=bin%2Flib;h=f0476f2ec699acbdf8f77cc47feb4211a7822a89;hb=107b5e8dc73f0180e2b3f35f8ed031662bbc57fb;hp=792a546ca9c6f4f475b2dd553762e5c18ca7a92e;hpb=e63f74b3e9f5d95e624279e2dd18c993ab862792;p=moe.git diff --git a/bin/lib b/bin/lib index 792a546..f0476f2 100644 --- a/bin/lib +++ b/bin/lib @@ -1,5 +1,5 @@ # The Evaluator -- Shell Function Library -# (c) 2001--2007 Martin Mares +# (c) 2001--2008 Martin Mares # General settings shopt -s dotglob @@ -49,6 +49,27 @@ function try-ln ln $1 $2 2>/dev/null || cp $1 $2 } +# Expand occurrences of `$var' in a given variable + +function expand-var +{ + eval echo ${!1} +} + +# Given a , override each variable by _ + +function override-vars +{ + local OR V W + declare -a OR + # `${!${1}_@}' does not work, so we have to use eval + OR=($(eval echo '${!'$1'_@}')) + for V in "${OR[@]}" ; do + W=${V##$1_} + eval $W='"$'$V'"' + done +} + # Sandbox subroutines function box-init @@ -152,6 +173,7 @@ function locate-source function compile { pstart "Compiling... " + override-vars "EXT_$SRCEXT" # Beware, the original SRCN can be a strange user-supplied name SRC=$PROBLEM.$SRCEXT cp "$SDIR/$SRCN" $TDIR/$SRC @@ -162,9 +184,8 @@ function compile box-clean for a in $SRC $COMP_EXTRAS ; do cp $TDIR/$a $BOXDIR/ ; done EXE=$PROBLEM - CCMD=COMP_$SRCEXT - CCMD=`eval echo ${!CCMD}` - COMP_SANDBOX_OPTS=`eval echo $COMP_SANDBOX_OPTS` + CCMD=$(expand-var COMP) + COMP_SANDBOX_OPTS=$(expand-var COMP_SANDBOX_OPTS) echo "Compiler command: $CCMD" echo "Compiler sandbox options: $COMP_SANDBOX_OPTS" eval $COMP_SANDBOX_INIT @@ -195,6 +216,12 @@ function compile # Running of test program according to current task type (returns exit code and TEST_MSG) +function test-config +{ + [ -f $PDIR/$TEST.config ] && . $PDIR/$TEST.config + override-vars "TEST_$TEST" +} + function test-run { test-run-$TASK_TYPE @@ -312,7 +339,7 @@ function test-epilog if [ -n "$OUTPUT_FILTER" -a "$OUT_TYPE" != none -a -z "$EV_NOFILTER" ] ; then pcont " " - FILTER=`eval echo \"$OUTPUT_FILTER\"` + FILTER=$(expand-var OUTPUT_FILTER) echo "Output filter command: $FILTER" mv $TDIR/$TEST.out $TDIR/$TEST.raw if ! eval $FILTER 2>$TMPDIR/exec.out ; then @@ -331,7 +358,7 @@ function test-run-file { test-prolog pcont " " - BOXOPTS="`eval echo $TEST_SANDBOX_OPTS`$BOX_EXTRAS" + BOXOPTS=$(expand-var TEST_SANDBOX_OPTS) echo "Sandbox options: $BOXOPTS" if ! $BOXCMD $BOXOPTS -- ./$PROBLEM 2>$TMPDIR/exec.out ; then cat $TMPDIR/exec.out @@ -348,9 +375,9 @@ function test-run-interactive { test-prolog pcont " " - BOXOPTS="`eval echo $TEST_SANDBOX_OPTS`$BOX_EXTRAS" + BOXOPTS=$(expand-var TEST_SANDBOX_OPTS) echo "Sandbox options: $BOXOPTS" - ICCMD=`eval echo $IA_CHECK` + ICCMD=$(expand-var IA_CHECK) echo "Interactive checker: $ICCMD" if ! $HDIR/bin/iwrapper $BOXCMD $BOXOPTS -- ./$PROBLEM @@ $ICCMD 2>$TMPDIR/exec.out ; then cat $TMPDIR/exec.out @@ -376,7 +403,7 @@ function syntax-check [ -n "$SYNTAX_CHECK" ] || return 0 [ -z "$EV_NOCHECK" ] || return 0 pcont " " - SCHECK=`eval echo \"$SYNTAX_CHECK\"` + SCHECK=$(expand-var SYNTAX_CHECK) echo "Syntax check command: $SCHECK" if ! eval $SCHECK 2>$TMPDIR/exec.out ; then cat $TMPDIR/exec.out @@ -395,7 +422,7 @@ function output-check if [ -n "$OUTPUT_CHECK" -a "$OUT_TYPE" != none -a -z "$EV_NOCHECK" ] ; then pcont " " [ -f $PDIR/$TEST.out ] && ln $PDIR/$TEST.out $TDIR/$TEST.ok - OCHECK=`eval echo \"$OUTPUT_CHECK\"` + OCHECK=$(expand-var OUTPUT_CHECK) echo "Output check command: $OCHECK" if ! eval $OCHECK 2>$TMPDIR/exec.out ; then cat $TMPDIR/exec.out