From: John Darrington Date: Mon, 5 Jan 2004 06:26:03 +0000 (+0000) Subject: Fixed a buglet in the ERASE command, added a test for it, and some documentation. X-Git-Tag: v0.4.0~393 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1dc8717737084b93af2cd212e84edbd2cce1046c;p=pspp-builds.git Fixed a buglet in the ERASE command, added a test for it, and some documentation. --- diff --git a/doc/pspp.texi b/doc/pspp.texi index 4c35bce7..1d647483 100644 --- a/doc/pspp.texi +++ b/doc/pspp.texi @@ -7863,6 +7863,7 @@ encountered in the input. * DISPLAY DOCUMENTS:: Display active file documents. * DISPLAY FILE LABEL:: Display the active file label. * DROP DOCUMENTS:: Remove documents from the active file. +* ERASE:: Erase a file. * EXECUTE:: Execute pending transformations. * FILE LABEL:: Set the active file's label. * FINISH:: Terminate the PSPP session. @@ -7934,7 +7935,7 @@ DISPLAY FILE LABEL. active file, if any. @xref{FILE LABEL}. -@node DROP DOCUMENTS, EXECUTE, DISPLAY FILE LABEL, Utilities +@node DROP DOCUMENTS, ERASE, DISPLAY FILE LABEL, Utilities @section DROP DOCUMENTS @vindex DROP DOCUMENTS @@ -7948,7 +7949,22 @@ New documents can be added with @cmd{DOCUMENT} (@pxref{DOCUMENT}). @cmd{DROP DOCUMENTS} changes only the active file. It does not modify any system files stored on disk. -@node EXECUTE, FILE LABEL, DROP DOCUMENTS, Utilities + +@node ERASE, EXECUTE, DROP DOCUMENTS, Utilities +@comment node-name, next, previous, up +@section ERASE +@vindex ERASE + +@display +ERASE FILE file_name. +@end display + +@cmd{ERASE FILE} deletes a file from the local filesystem. +file_name must be quoted. +This command cannot be used if the SAFER setting is active. + + +@node EXECUTE, FILE LABEL, ERASE, Utilities @section EXECUTE @vindex EXECUTE @@ -7998,6 +8014,7 @@ HOST. @cmd{HOST} suspends the current PSPP session and temporarily returns control to the operating system. +This command cannot be used if the SAFER setting is active. @node INCLUDE, QUIT, HOST, Utilities diff --git a/src/command.c b/src/command.c index 7e9bb774..2c62d2f2 100644 --- a/src/command.c +++ b/src/command.c @@ -565,15 +565,24 @@ cmd_execute (void) return lex_end_of_command (); } + +#define assert_not_safer() \ + do { \ + if (set_safer) \ + { \ + msg (SE, _("This command not allowed when the SAFER option is set.")); \ + return CMD_FAILURE; \ + } \ +} while(0) + + + /* Parses, performs the ERASE command. */ int cmd_erase (void) { - if (set_safer) - { - msg (SE, _("This command not allowed when the SAFER option is set.")); - return CMD_FAILURE; - } + + assert_not_safer(); lex_match_id ("ERASE"); if (!lex_force_match_id ("FILE")) @@ -589,7 +598,7 @@ cmd_erase (void) return CMD_FAILURE; } - return lex_end_of_command (); + return CMD_SUCCESS; } #if unix @@ -700,11 +709,7 @@ cmd_host (void) { int code; - if (set_safer) - { - msg (SE, _("This command not allowed when the SAFER option is set.")); - return CMD_FAILURE; - } + assert_not_safer(); lex_match_id ("HOST"); diff --git a/tests/Makefile.am b/tests/Makefile.am index 721520b7..b1746e97 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -8,6 +8,7 @@ TESTS = command/aggregate.sh \ command/count.sh \ command/compute.sh \ command/descriptives.sh \ + command/erase.sh \ command/file-label.sh \ command/filter.sh \ command/flip.sh \ diff --git a/tests/command/erase.sh b/tests/command/erase.sh new file mode 100755 index 00000000..d5f69102 --- /dev/null +++ b/tests/command/erase.sh @@ -0,0 +1,102 @@ +#!/bin/sh + +# This program tests the ERASE command. + +TEMPDIR=/tmp/pspp-tst-$$ + +here=`pwd`; + +# ensure that top_srcdir is absolute +cd $top_srcdir; top_srcdir=`pwd` + +export STAT_CONFIG_PATH=$top_srcdir/config + + +cleanup() +{ + rm -rf $TEMPDIR +} + + +fail() +{ + echo $activity + echo FAILED + cleanup; + exit 1; +} + + +no_result() +{ + echo $activity + echo NO RESULT; + cleanup; + exit 2; +} + +pass() +{ + cleanup; + exit 0; +} + +mkdir -p $TEMPDIR + +cd $TEMPDIR + +activity="create file" +cat > $TEMPDIR/foobar < $TEMPDIR/foo.sps < /dev/null +if [ $? -eq 0 ] ; then fail ; fi + + +activity="create program 2" +cat > $TEMPDIR/foo.sps <