Clean up how transformations work.
[pspp] / src / language / command.h
index ba14c0bb4418880c603ab38cd9ca028197e25d22..ecd2a752659d663366c3788fe7c9f5d105a36dfe 100644 (file)
@@ -1,68 +1,72 @@
-/* PSPP - computes sample statistics.
-   Copyright (C) 1997-9, 2000 Free Software Foundation, Inc.
-   Written by Ben Pfaff <blp@gnu.org>.
+/* PSPP - a program for statistical analysis.
+   Copyright (C) 1997-9, 2000, 2006, 2010, 2013 Free Software Foundation, Inc.
 
-   This program is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public License as
-   published by the Free Software Foundation; either version 2 of the
-   License, or (at your option) any later version.
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation, either version 3 of the License, or
+   (at your option) any later version.
 
-   This program is distributed in the hope that it will be useful, but
-   WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   General Public License for more details.
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-   02110-1301, USA. */
+   along with this program.  If not, see <http://www.gnu.org/licenses/>. */
 
-#if !command_h
-#define command_h 1
+#ifndef COMMAND_H
+#define COMMAND_H 1
 
-/* Current program state. */
-enum
-  {
-    STATE_INIT,                        /* Initialization state. */
-    STATE_INPUT,               /* Input state. */
-    STATE_TRANS,               /* Transformation state. */
-    STATE_PROC,                        /* Procedure state. */
-    STATE_ERROR                        /* Invalid state transition. */
-  };
+#include <stdbool.h>
 
 /* Command return values. */
-enum
+enum cmd_result
   {
     /* Successful return values. */
-    CMD_SUCCESS = 0x1000,       /* Successfully parsed and executed. */
-    CMD_EOF,                    /* Requested exit. */
-
-    /* Various kinds of failures, in increasing order of severity. */
-    CMD_TRAILING_GARBAGE,      /* Followed by garbage. */
-    CMD_PART_SUCCESS,          /* Fully executed up to error. */
-    CMD_PART_SUCCESS_MAYBE,    /* May have been partially executed. */
-    CMD_FAILURE,                /* Not executed at all. */
-    CMD_CASCADING_FAILURE       /* Serious error: don't continue. */
+    CMD_SUCCESS = 1,            /* Successfully parsed and executed. */
+    CMD_EOF = 2,                /* End of input. */
+    CMD_FINISH = 3,             /* FINISH was executed. */
+
+    /* Various kinds of failures. */
+    CMD_FAILURE = -1,           /* Not executed at all. */
+    CMD_NOT_IMPLEMENTED = -2,   /* Command not implemented. */
+    CMD_CASCADING_FAILURE = -3  /* Serious error: don't continue. */
+  };
+
+bool cmd_result_is_success (enum cmd_result);
+bool cmd_result_is_failure (enum cmd_result);
+
+/* Command processing state. */
+enum cmd_state
+  {
+    CMD_STATE_INITIAL,          /* No active dataset yet defined. */
+    CMD_STATE_DATA,             /* Active dataset has been defined. */
+    CMD_STATE_INPUT_PROGRAM,    /* Inside INPUT PROGRAM. */
+    CMD_STATE_FILE_TYPE,        /* Inside FILE TYPE. */
+
+    /* Inside LOOP or DO IF... */
+    CMD_STATE_NESTED_DATA,      /* ...in CMD_STATE_DATA. */
+    CMD_STATE_NESTED_INPUT_PROGRAM, /* ...in CMD_STATE_INPUT_PROGRAM. */
   };
 
-extern int pgm_state;
+struct dataset;
+struct lexer;
+
+enum cmd_result cmd_parse_in_state (struct lexer *lexer, struct dataset *ds,
+                                   enum cmd_state);
+
+enum cmd_result cmd_parse (struct lexer *lexer, struct dataset *ds);
 
-char *pspp_completion_function (const char *text,   int state);
+struct command;
+const char *cmd_complete (const char *, const struct command **);
 
-int cmd_parse (void);
+struct dataset;
 
 /* Prototype all the command functions. */
-#define DEFCMD(NAME, T1, T2, T3, T4, FUNC)     \
-       int FUNC (void);
-#define SPCCMD(NAME, T1, T2, T3, T4, FUNC)     \
-       int FUNC (void);
-#define DBGCMD(NAME, T1, T2, T3, T4, FUNC)     \
-       int FUNC (void);
-#define UNIMPL(NAME, T1, T2, T3, T4, DESC)
+#define DEF_CMD(STATES, FLAGS, NAME, FUNCTION) int FUNCTION (struct lexer *, struct dataset *);
+#define UNIMPL_CMD(NAME, DESCRIPTION)
 #include "command.def"
-#undef DEFCMD
-#undef SPCCMD
-#undef UNIMPL
-#undef DBGCMD
+#undef DEF_CMD
+#undef UNIMPL_CMD
 
-#endif /* !command_h */
+#endif /* command.h */