e38707ddbe74257018f09083b22d649a8409150a
[pspp-builds.git] / src / language / command.h
1 /* PSPP - computes sample statistics.
2    Copyright (C) 1997-9, 2000, 2006 Free Software Foundation, Inc.
3    Written by Ben Pfaff <blp@gnu.org>.
4
5    This program is free software; you can redistribute it and/or
6    modify it under the terms of the GNU General Public License as
7    published by the Free Software Foundation; either version 2 of the
8    License, or (at your option) any later version.
9
10    This program is distributed in the hope that it will be useful, but
11    WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    General Public License for more details.
14
15    You should have received a copy of the GNU General Public License
16    along with this program; if not, write to the Free Software
17    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18    02110-1301, USA. */
19
20 #ifndef COMMAND_H
21 #define COMMAND_H 1
22
23 #include <stdbool.h>
24
25 /* Command return values. */
26 enum cmd_result
27   {
28     /* Successful return values. */
29     CMD_SUCCESS = 1,            /* Successfully parsed and executed. */
30     CMD_EOF = 2,                /* End of input. */
31     CMD_FINISH = 3,             /* FINISH was executed. */
32
33     /* Range of successful return values available for use
34        by agreement between a command and the caller of
35        cmd_parse(). */
36     CMD_PRIVATE_FIRST = 4,      
37     CMD_PRIVATE_LAST = 127,      
38
39     /* Various kinds of failures. */
40     CMD_FAILURE = -1,           /* Not executed at all. */
41     CMD_NOT_IMPLEMENTED = -2,   /* Command not implemented. */
42     CMD_CASCADING_FAILURE = -3  /* Serious error: don't continue. */
43   };
44
45 bool cmd_result_is_success (enum cmd_result);
46 bool cmd_result_is_failure (enum cmd_result);
47
48 /* Command processing state. */
49 enum cmd_state
50   {
51     CMD_STATE_INITIAL,          /* No active file yet defined. */
52     CMD_STATE_DATA,             /* Active file has been defined. */
53     CMD_STATE_INPUT_PROGRAM,    /* Inside INPUT PROGRAM. */
54     CMD_STATE_FILE_TYPE         /* Inside FILE TYPE. */
55   };
56
57 struct dataset;
58 struct lexer; 
59
60 enum cmd_result cmd_parse (struct lexer *lexer, struct dataset *ds, enum cmd_state);
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 */