removed failure state, reordered states, predicates will return --FALSE and --TRUE...
[mala.git] / engine / engine.h
blobab06f3d92353b406ac6462bfe3eaf97ae9a31744
1 /*
2 engine.h - MaLa core engine
4 Copyright (C) 2004, Christian Thaeter <chth@gmx.net>
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License version 2 as
8 published by the Free Software Foundation.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, contact me.
20 #ifndef MALA_ENGINE_H
21 #define MALA_ENGINE_H
23 #include "mala_types.h"
24 #include "stringbucket.h"
25 #include "stringlist.h"
26 //#include "action.h"
29 Build a table of common strings, this strings are
30 a) get never garbage collected (except at end)
31 b) are fast accessible with their symbolic index
33 note that "--WORLD" must be the first one
36 #define MALA_COMMON_STRINGS \
37 { \
38 MALA_COMMON_STRING (WORLD, "--WORLD"), \
39 MALA_COMMON_STRING (COMMANDLINE, "--COMMANDLINE"), \
40 MALA_COMMON_STRING (PROGRAM, "--PROGRAM"), \
41 MALA_COMMON_STRING (ARGUMENTS, "--ARGUMENTS"), \
42 MALA_COMMON_STRING (FALSE, "--FALSE"), \
43 MALA_COMMON_STRING (TRUE, "--TRUE"), \
44 MALA_COMMON_STRING (EMPTY, ""), \
45 MALA_COMMON_STRING (ZERO, "0"), \
46 MALA_COMMON_STRING (PASS, "--PASS"), \
47 MALA_COMMON_STRING (EXCLAMATIONMARK, "!"), \
48 MALA_COMMON_STRING (ASSIGN, "="), \
49 MALA_COMMON_STRING (BACKQUOTE, "`"), \
50 MALA_COMMON_STRING (NOT, "--NOT"), \
51 MALA_COMMON_STRING (LITERAL, "--LITERAL"), \
52 MALA_COMMON_STRING (ENVSUBST, "--ENVSUBST"), \
53 MALA_COMMON_STRING (SETENV, "--SETENV"), \
54 MALA_COMMON_STRING (SECTION, "--SECTION"), \
55 MALA_COMMON_STRING (BEFORE_HERE, "--BEFORE-HERE"), \
56 MALA_COMMON_STRING (BEGIN, "--BEGIN"), \
57 MALA_COMMON_STRING (END, "--END"), \
58 MALA_COMMON_STRING (DEL, "--DEL"), \
59 MALA_COMMON_STRING (DEFAULT_PARSER, "--DEFAULT-PARSER"), \
60 MALA_COMMON_STRING (PP_COMMANDLINE, "--PP-COMMANDLINE"), \
61 MALA_COMMON_STRING (PP_CONFIGFILE, "--PP-CONFIGFILE"), \
62 MALA_COMMON_STRING (PP_INTERACTIVE, "--PP-INTERACTIVE"), \
63 MALA_COMMON_STRING (FLAG_LITERAL_EXPANSION, "--FLAG-LITERAL-EXPANSION"), \
64 MALA_COMMON_STRING (FLAG_EXCLAM_EXPANSION, "--FLAG-EXCLAM-EXPANSION"), \
65 MALA_COMMON_STRING (FLAG_NO_EXPANSION, "--FLAG-NO-EXPANSION"), \
66 MALA_COMMON_STRING (FLAG_NUMSPLIT_EXPANSION, "--FLAG-NUMSPLIT-EXPANSION"), \
67 MALA_COMMON_STRING (FLAG_CHAR_EXPANSION, "--FLAG-CHAR-EXPANSION"), \
68 MALA_COMMON_STRING (FLAG_ASSIGN_EXPANSION, "--FLAG-ASSIGN-EXPANSION"), \
69 MALA_COMMON_STRING (FLAG_SETENV_EXPANSION, "--FLAG-SETENV-EXPANSION"), \
70 MALA_COMMON_STRING (FLAG_ENVVAR_EXPANSION, "--FLAG-ENVVAR-EXPANSION"), \
71 MALA_COMMON_STRING (FLAG_UNDERSCORE_EXPANSION, "--FLAG-UNDERSCORE-EXPANSION"), \
72 MALA_COMMON_STRING (FLAG_BRACKET_EXPANSION, "--FLAG-BRACKET-EXPANSION"), \
73 MALA_COMMON_STRING (FLAG_ASSIGN_CONTRACTION, "--FLAG-ASSIGN-CONTRACTION"), \
74 MALA_COMMON_STRING (ERROR, "--ERROR"), \
75 MALA_COMMON_STRING (ERROR_MISSING_ARGUMENT, "--ERROR-MISSING-ARGUMENT"), \
76 MALA_COMMON_STRING (ERROR_MISSING_END, "--ERROR-MISSING-END"), \
77 MALA_COMMON_STRING (ERROR_END_WITHOUT_BEGIN, "--ERROR-END-WITHOUT-BEGIN"), \
78 MALA_COMMON_STRING (ERROR_MACRO_SYNTAX, "--ERROR-MACRO-SYNTAX"), \
79 MALA_COMMON_STRING (ERROR_NESTING_LIMIT_EXCEED, "--ERROR-NESTING-LIMIT-EXCEED"), \
80 MALA_COMMON_STRING (ERROR_ACTION_NOT_DEFINED, "--ERROR-ACTION-NOT-DEFINED"), \
81 MALA_COMMON_STRING (MAX, "") \
85 #define MALA_COMMON_STRING(E,s) MALA_STRING_##E
86 enum mala_common_strings_enum MALA_COMMON_STRINGS;
87 #undef MALA_COMMON_STRING
89 typedef enum mala_common_strings_enum mala_common_string;
91 const char * mala_engine_states [MALA_STATE_TABLE_SIZEOF+1];
93 //#ifdef MALA_PRIVATE
94 struct mala_engine_struct
97 * every tokenized word is collected in 'words'
98 * actions can be bound to these words through the strings user variable
100 acogc_root gcroot;
102 acogc_factory gcfactory_buckets;
103 acogc_factory gcfactory_strings;
104 acogc_factory gcfactory_stringbucketnodes;
105 acogc_factory gcfactory_stringlists;
106 acogc_factory gcfactory_actions;
107 acogc_factory gcfactory_programs;
109 MalaStringBucket words;
111 //int negated:1;
113 mala_trace engine_trace;
115 /* --BEGIN ... --END blocks are translated to --BLOCK-xxxxxxxx macros,
116 where xxxxxxxx is a monotonic incrementing counter, its value is stored here */
117 unsigned blockcnt;
119 mala_state state;
121 MalaString common_string[MALA_STRING_MAX];
126 * Mala engine
128 void
129 mala_engine_init (MalaEngine self);
131 MalaEngine
132 mala_engine_new ();
134 #if 0
135 MalaEngine
136 mala_engine_new_main (int (*initfunc) (MalaEngine),
137 int argc, char ** argv,
138 mala_actioninit * actions_init);
139 #endif
141 void
142 mala_engine_erase (MalaEngine self);
144 void
145 mala_engine_free (MalaEngine self);
147 mala_state
148 mala_engine_actions_register (MalaEngine, MalaActionInit);
151 void
152 mala_engine_action_new_cstr (MalaEngine self,
153 const char* name,
154 MalaParserFunc parser,
155 void *data,
156 acogc_alloc_type data_alloc,
157 MalaAction parent);
160 void
161 mala_engine_run_cstr (MalaEngine self,
162 const char* cmd,
163 MalaStringList_ref result);
165 mala_state
166 mala_engine_state_get (MalaEngine self);
168 const char *
169 mala_engine_state_str (MalaEngine self);
171 void
172 mala_engine_clearstate (MalaEngine self);
174 MalaString
175 mala_engine_tmpname (MalaEngine self, const char* templ);
177 static inline MalaAction
178 mala_engine_action_get_cstr (MalaEngine engine, const char * cname)
180 MalaString s = mala_stringbucket_find (engine->words, cname);
181 return s ? s->action : NULL;
184 #endif /*MALA_ENGINE_H*/
186 // Local Variables:
187 // mode: C
188 // c-file-style: "gnu"
189 // End:
190 // arch-tag: 47d718f6-e397-400c-93a6-bc71f475c0c7
191 // end_of_file