]> mj.ucw.cz Git - eval.git/commitdiff
Cleaned up handling of SDIR and SRCN.
authorMartin Mares <mj@ucw.cz>
Thu, 28 Jun 2007 17:21:07 +0000 (19:21 +0200)
committerMartin Mares <mj@ucw.cz>
Thu, 28 Jun 2007 17:21:07 +0000 (19:21 +0200)
File and directory names with spaces should work now.

bin/lib
public/check
public/submit

diff --git a/bin/lib b/bin/lib
index 0be042f80b88efde5fc5f39b3d3e9694bbf655d6..126e0fd2ee20e09b2119154ac02dda994a74e76e 100644 (file)
--- a/bin/lib
+++ b/bin/lib
@@ -107,20 +107,20 @@ EOF
 # 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... "
+       local SBASE
        if [ -n "$1" ] ; then
-               SRCBASE=$(echo $1 | sed 's/\.\([^.]\+\)//')
-               SRCEXT=$(echo $1 | sed 's/.*\.\([^.]\+\)/\1/')
+               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=$1
-                       if [ ${SRCN:0:1} == / ] ; then
-                               SRCN=${SRCN:1}
-                               SDIR=
-                       fi
+                       SRCN="$S"
                        [ -f "$SDIR/$SRCN" ] || die "Cannot find source file $SDIR/$SRCN"
                        SRCEXT_OK=
                        for a in $EXTENSIONS ; do
@@ -136,9 +136,9 @@ function locate-source
                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
@@ -154,7 +154,7 @@ function compile
        pstart "Compiling... "
        # Beware, the original SRCN can be a strange user-supplied name
        SRC=$PROBLEM.$SRCEXT
-       cp -a $SDIR/$SRCN $TDIR/$SRC
+       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
@@ -373,12 +373,14 @@ function public-setup
 }
 
 # 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"
        if [ -n "$1" ] ; then
-               SRCN=$1
+               SDIR=`dirname "$1"`
+               SRCN=`basename "$1"`
        else
                SRCN=$SDIR/$PROBLEM$TEST.out
        fi
index 152884d2aaf674806a742552a5c129c84910f407..a3bf810fc97571fc4b582d730b244974298ebfad 100755 (executable)
@@ -48,13 +48,13 @@ function test-verdict
 if [ $TASK_TYPE == open-data ] ; then
        [ -n "$TEST" ] || die "You need to specify test number for open data problems."
        pstart "Checking $TEST: "
-       open-locate $SRCFILE
-       ln $SRCN $TDIR/$TEST.out
+       open-locate "$SRCFILE"
+       ln "$SRCN" $TDIR/$TEST.out
        syntax-check
        test-result 1 OK
 else
        [ -z "$TEST" ] || die "Test number should be given only for open data problems."
-       locate-source $SRCFILE
+       locate-source "$SRCFILE"
        compile
        RC=0
        for TEST in $SAMPLE_TESTS ; do
index 119ffcf2d43c6c53150fa316d8e9189412c40fda..c642218e11d22e6299438cde36d54a3747aed4e6 100755 (executable)
@@ -51,15 +51,15 @@ if [ $TASK_TYPE == open-data ] ; then
        [ -n "$PART" ] || die "You need to specify test number for open data problems."
        TEST=$PART
        pstart "Test case $TEST: "
-       open-locate $SRCFILE
+       open-locate "$SRCFILE"
        (
-               ln $SRCN $TDIR/$TEST.out
+               ln "$SDIR/$SRCN" $TDIR/$TEST.out
                syntax-check
                test-result 1 OK
        ) || FAILED=1
 else
        [ -z "$PART" ] || die "Test number should be given only for open data problems."
-       locate-source $SRCFILE
+       locate-source "$SRCFILE"
        compile
        for TEST in $SAMPLE_TESTS ; do
                (
@@ -85,7 +85,7 @@ fi
 
 if [ -n "$REMOTE_SUBMIT" ] ; then
        pstart "Submitting to the server... "
-       $MO_ROOT/bin/remote-submit $PROBLEM $PART $SDIR/$SRCN
+       $MO_ROOT/bin/remote-submit $PROBLEM $PART "$SDIR/$SRCN"
        pend "OK"
        exit 0
 fi
@@ -94,10 +94,10 @@ pstart "Submitting... "
 mkdir -p ~/.submit
 if [ $TASK_TYPE == open-data ] ; then
        mkdir -p ~/.submit/$PROBLEM
-       cp $SRCN ~/.submit/$PROBLEM/$PART.out
+       cp "$SDIR/$SRCN" ~/.submit/$PROBLEM/$PART.out
 else
        rm -rf ~/.submit/$PROBLEM
        mkdir -p ~/.submit/$PROBLEM
-       cp $SRCN ~/.submit/$PROBLEM/
+       cp "$SDIR/$SRCN" ~/.submit/$PROBLEM/
 fi
 pend "OK"