0c153becd74ddd4b8f06681f7f9d6afe176ee017
[pspp-builds.git] / src / language / command.h
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 1997-9, 2000, 2006 Free Software Foundation, Inc.
3
4    This program is free software: you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation, either version 3 of the License, or
7    (at your option) any later version.
8
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13
14    You should have received a copy of the GNU General Public License
15    along with this program.  If not, see <http://www.gnu.org/licenses/>. */
16
17 #ifndef COMMAND_H
18 #define COMMAND_H 1
19
20 #include <stdbool.h>
21
22 /* Command return values. */
23 enum cmd_result
24   {
25     /* Successful return values. */
26     CMD_SUCCESS = 1,            /* Successfully parsed and executed. */
27     CMD_EOF = 2,                /* End of input. */
28     CMD_FINISH = 3,             /* FINISH was executed. */
29
30     /* Range of successful return values available for use
31        by agreement between a command and the caller of
32        cmd_parse(). */
33     CMD_PRIVATE_FIRST = 4,
34     CMD_PRIVATE_LAST = 127,
35
36     /* Various kinds of failures. */
37     CMD_FAILURE = -1,           /* Not executed at all. */
38     CMD_NOT_IMPLEMENTED = -2,   /* Command not implemented. */
39     CMD_CASCADING_FAILURE = -3  /* Serious error: don't continue. */
40   };
41
42 bool cmd_result_is_success (enum cmd_result);
43 bool cmd_result_is_failure (enum cmd_result);
44
45 /* Command processing state. */
46 enum cmd_state
47   {
48     CMD_STATE_INITIAL,          /* No active file yet defined. */
49     CMD_STATE_DATA,             /* Active file has been defined. */
50     CMD_STATE_INPUT_PROGRAM,    /* Inside INPUT PROGRAM. */
51     CMD_STATE_FILE_TYPE         /* Inside FILE TYPE. */
52   };
53
54 struct dataset;
55 struct lexer;
56
57 enum cmd_result cmd_parse_in_state (struct lexer *lexer, struct dataset *ds,
58                                     enum cmd_state);
59
60 enum cmd_result cmd_parse (struct lexer *lexer, struct dataset *ds);
61
62 struct command;
63 const char *cmd_complete (const char *, const struct command **);
64
65 struct dataset;
66
67 /* Prototype all the command functions. */
68 #define DEF_CMD(STATES, FLAGS, NAME, FUNCTION) int FUNCTION (struct lexer *, struct dataset *);
69 #define UNIMPL_CMD(NAME, DESCRIPTION)
70 #include "command.def"
71 #undef DEF_CMD
72 #undef UNIMPL_CMD
73
74 #endif /* command.h */