Beginning of VFM cleanup.
[pspp-builds.git] / src / command.c
index d4c130aa64bce968c62d38f373d4304b243b8178..b12e46d0dfb9c7d815e7164b537b68832f8789f0 100644 (file)
    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
    02111-1307, USA. */
 
-/* AIX requires this to be the first thing in the file.  */
 #include <config.h>
-#if __GNUC__
-#define alloca __builtin_alloca
-#else
-#if HAVE_ALLOCA_H
-#include <alloca.h>
-#else
-#ifdef _AIX
-#pragma alloca
-#else
-#ifndef alloca                 /* predefined by HP cc +Olibcalls */
-char *alloca ();
-#endif
-#endif
-#endif
-#endif
-
 #include <assert.h>
+#include "command.h"
 #include <stdio.h>
 #include <stdlib.h>
 #include <ctype.h>
 #include <errno.h>
 #include "alloc.h"
-#include "command.h"
 #include "error.h"
 #include "getline.h"
 #include "lexer.h"
@@ -86,14 +69,6 @@ struct command
     struct command *next;      /* Next command with same word[0]. */
   };
 
-/* Prototype all the command functions. */
-#define DEFCMD(NAME, T1, T2, T3, T4, FUNC)     \
-       int FUNC (void);
-#define UNIMPL(NAME, T1, T2, T3, T4)
-#include "command.def"
-#undef DEFCMD
-#undef UNIMPL
-
 /* Define the command array. */
 #define DEFCMD(NAME, T1, T2, T3, T4, FUNC)             \
        {NAME, {T1, T2, T3, T4}, FUNC, {NULL, NULL, NULL}, NULL},
@@ -226,7 +201,8 @@ cmd_parse (void)
 
   /* If we're in a FILE TYPE structure, only certain commands can be
      allowed. */
-  if (pgm_state == STATE_INPUT && vfm_source == &file_type_source
+  if (pgm_state == STATE_INPUT
+      && case_source_is_class (vfm_source, &file_type_source_class)
       && !FILE_TYPE_okay (cp))
     return CMD_FAILURE;
 
@@ -274,7 +250,7 @@ cmd_parse (void)
     
     /* Perform the state transition if the command completed
        successfully (at least in part). */
-    if (result != 0)
+    if (result != CMD_FAILURE)
       {
        pgm_state = cp->transition[pgm_state];
 
@@ -576,7 +552,7 @@ cmd_n_of_cases (void)
   x = lex_integer ();
   lex_get ();
   if (!lex_match_id ("ESTIMATED"))
-    default_dict.N = x;
+    dict_set_case_limit (default_dict, x);
 
   return lex_end_of_command ();
 }
@@ -586,19 +562,28 @@ int
 cmd_execute (void)
 {
   lex_match_id ("EXECUTE");
-  procedure (NULL, NULL, NULL);
+  procedure (NULL, NULL, NULL, NULL);
   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"))
@@ -614,10 +599,10 @@ cmd_erase (void)
       return CMD_FAILURE;
     }
 
-  return lex_end_of_command ();
+  return CMD_SUCCESS;
 }
 
-#if unix
+#ifdef unix
 /* Spawn a shell process. */
 static int
 shell (void)
@@ -725,15 +710,11 @@ 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");
 
-#if unix
+#ifdef unix
   /* Figure out whether to invoke an interactive shell or to execute a
      single shell command. */
   if (lex_look_ahead () == '.')