]> mj.ucw.cz Git - moe.git/blobdiff - bin/lib
Implemented general mechanism for overriding variables for specific
[moe.git] / bin / lib
diff --git a/bin/lib b/bin/lib
index 792a546ca9c6f4f475b2dd553762e5c18ca7a92e..a84258cb162aeed79730d40d4701e361063350bf 100644 (file)
--- a/bin/lib
+++ b/bin/lib
@@ -1,5 +1,5 @@
 # The Evaluator -- Shell Function Library
-# (c) 2001--2007 Martin Mares <mj@ucw.cz>
+# (c) 2001--2008 Martin Mares <mj@ucw.cz>
 
 # General settings
 shopt -s dotglob
@@ -49,6 +49,21 @@ function try-ln
        ln $1 $2 2>/dev/null || cp $1 $2
 }
 
+# Given a <prefix>, override each variable <x> by <prefix>_<x>
+
+function override-vars
+{
+       local OR V OLDIFS
+       declare -a OR
+       OLDIFS="$IFS"
+       IFS=$'\n'
+       OR=($(set | sed "s/^$1_//;t;d")) || true
+       IFS="$OLDIFS"
+       for V in "${OR[@]}" ; do
+               eval "$V"
+       done
+}
+
 # Sandbox subroutines
 
 function box-init
@@ -152,6 +167,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
@@ -195,6 +211,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