::= sbc-options sbc-options
sbc-option ::= *
::= +
+ ::= ^
sbc-defn ::= opt-prefix = specifiers
::= [ ID ] = array-sbc
::= opt-prefix = sbc-special-form
syntax file. A plus sign (@samp{+}) is used to indicate that a
subcommand can appear more than once; if it is not present then that
subcommand can appear no more than once.
+A carat sign (@samp{^}) is used to indicate that a subcommand must appear
+at least once.
The subcommand name appears after the option characters.
}
subcommand_type;
+typedef enum
+ {
+ ARITY_ONCE_EXACTLY, /* must occur exactly once */
+ ARITY_ONCE_ONLY, /* zero or once */
+ ARITY_MANY /* 0, 1, ... , inf */
+ }subcommand_arity;
+
/* A single subcommand. */
typedef struct subcommand subcommand;
struct subcommand
subcommand *next; /* Next in the chain. */
char *name; /* Subcommand name. */
subcommand_type type; /* One of SBC_*. */
- int once; /* 1=Subcommand may appear only once. */
+ subcommand_arity arity; /* How many times should the subcommand occur*/
int narray; /* Index of next array element. */
const char *prefix; /* Prefix for variable and constant names. */
specifier *spec; /* Array of specifiers. */
static void
parse_subcommand (subcommand *sbc)
{
+ sbc->arity = ARITY_MANY;
+
if (match_token ('*'))
{
if (def)
def = sbc;
}
- sbc->once = match_token ('+');
+ if ( match_token('+'))
+ sbc->arity = ARITY_ONCE_ONLY ;
+ else if (match_token('^'))
+ sbc->arity = ARITY_ONCE_EXACTLY ;
+
force_id ();
sbc->name = xstrdup (tokstr);
dump (0, "lex_match ('=');");
dump (0, "p->sbc_%s++;", st_lower (sbc->name));
- if (sbc->once)
+ if (sbc->arity != ARITY_MANY)
{
dump (1, "if (p->sbc_%s > 1)", st_lower (sbc->name));
dump (1, "{");
outdent ();
}
}
+
+
/* Now deal with the /ALGORITHM subcommand implicit to all commands */
dump(1,"else if ( get_syntax() != COMPATIBLE && lex_match_id(\"ALGORITHM\"))");
dump(1,"{");
dump (-1, "}");
outdent ();
+
dump (1, "if (!lex_match ('/'))");
dump (0, "break;");
dump (0, "goto lossage;");
dump (-1, "}");
dump (0, nullstr);
+
+ outdent ();
+
+ {
+ /* Check that mandatory subcommands have been specified */
+ subcommand *sbc;
+
+ for (sbc = subcommands; sbc; sbc = sbc->next)
+ {
+
+ if ( sbc->arity == ARITY_ONCE_EXACTLY )
+ {
+ dump (0, "if ( 0 == p->sbc_%s)", st_lower (sbc->name));
+ dump (1, "{");
+ dump (0, "msg (SE, _(\"%s subcommand must be given.\"));",
+ sbc->name);
+ dump (0, "goto lossage;");
+ dump (-1, "}");
+ dump (0, nullstr);
+ }
+ }
+ }
+
dump (-1, "return 1;");
dump (0, nullstr);
dump (-1, "lossage:");
--- /dev/null
+#!/bin/sh
+
+# This program tests for a bug which crashed pspp when given certain
+# invalid input
+
+TEMPDIR=/tmp/pspp-tst-$$
+TESTFILE=$TEMPDIR/`basename $0`.sps
+
+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 program"
+cat > $TESTFILE <<EOF
+DATA LIST LIST /x *.
+BEGIN DATA.
+1
+2
+3
+END DATA.
+
+EXAMINE.
+ONEWAY.
+CROSSTABS.
+EOF
+if [ $? -ne 0 ] ; then no_result ; fi
+
+#This must fail
+activity="run program"
+$SUPERVISOR $here/../src/pspp $TESTFILE > /dev/null
+if [ $? -ne 1 ] ; then fail ; fi
+
+
+pass;