new stdmodule file layout
[mala.git] / engine / engine.h
blob3cede9b277789e527d5983f30b51d1cb4bc37d25
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
31 b) are fast accessible with their symbolic index
33 #define MALA_COMMON_STRINGS \
34 { \
35 MALA_EXPAND (FALSE, "--FALSE"), \
36 MALA_EXPAND (TRUE, "--TRUE"), \
37 MALA_EXPAND (ZERO, "0"), \
38 MALA_EXPAND (NULL, "--NULL"), \
39 MALA_EXPAND (EXCLAMATIONMARK, "!"), \
40 MALA_EXPAND (ASSIGN, "="), \
41 MALA_EXPAND (BACKQUOTE, "`"), \
42 MALA_EXPAND (NOT, "--NOT"), \
43 MALA_EXPAND (LITERAL, "--LITERAL"), \
44 MALA_EXPAND (ENVSUBST, "--ENVSUBST"), \
45 MALA_EXPAND (SETENV, "--SETENV"), \
46 MALA_EXPAND (SECTION, "--SECTION"), \
47 MALA_EXPAND (HERE, "--HERE"), \
48 MALA_EXPAND (BEGIN, "--BEGIN"), \
49 MALA_EXPAND (END, "--END"), \
50 MALA_EXPAND (DEL, "--DEL"), \
51 MALA_EXPAND (DEFAULT_PARSER, "--DEFAULT-PARSER"), \
52 MALA_EXPAND (FLAG_LITERAL_EXPANSION, "--FLAG-LITERAL-EXPANSION"), \
53 MALA_EXPAND (FLAG_EXCLAM_EXPANSION, "--FLAG-EXCLAM-EXPANSION"), \
54 MALA_EXPAND (FLAG_NO_EXPANSION, "--FLAG-NO-EXPANSION"), \
55 MALA_EXPAND (FLAG_NUMSPLIT_EXPANSION, "--FLAG-NUMSPLIT-EXPANSION"), \
56 MALA_EXPAND (FLAG_CHAR_EXPANSION, "--FLAG-CHAR-EXPANSION"), \
57 MALA_EXPAND (FLAG_ASSIGN_EXPANSION, "--FLAG-ASSIGN-EXPANSION"), \
58 MALA_EXPAND (FLAG_SETENV_EXPANSION, "--FLAG-SETENV-EXPANSION"), \
59 MALA_EXPAND (FLAG_ENVVAR_EXPANSION, "--FLAG-ENVVAR-EXPANSION"), \
60 MALA_EXPAND (FLAG_UNDERSCORE_EXPANSION, "--FLAG-UNDERSCORE-EXPANSION"), \
61 MALA_EXPAND (FLAG_BRACKET_EXPANSION, "--FLAG-BRACKET-EXPANSION"), \
62 MALA_EXPAND (FLAG_ASSIGN_CONTRACTION, "--FLAG-ASSIGN-CONTRACTION"), \
63 MALA_EXPAND (ERROR_MISSING_ARGUMENT, "--ERROR-MISSING-ARGUMENT"), \
64 MALA_EXPAND (ERROR_MISSING_END, "--ERROR-MISSING-END"), \
65 MALA_EXPAND (ERROR_END_WITHOUT_BEGIN, "--ERROR-END-WITHOUT-BEGIN"), \
66 MALA_EXPAND (ERROR_BLOCK_NOT_ALLOWED, "--ERROR-BLOCK-NOT-ALLOWED"), \
67 MALA_EXPAND (ERROR_PARAMETER_SYNTAX, "--ERROR-PARAMETER-SYNTAX"), \
68 MALA_EXPAND (MAX, NULL) \
71 #define MALA_EXPAND(E,s) MALA_STRING_##E
72 enum mala_common_strings_enum MALA_COMMON_STRINGS;
73 #undef MALA_EXPAND
76 //#ifdef MALA_PRIVATE
77 struct mala_engine_struct
80 * every tokenized word is collected in 'words'
81 * actions can be bound to these words through the strings user variable
83 mala_stringbucket words;
84 mala_stringlist program;
85 mala_stringlist arguments;
87 MalaString common_string[MALA_STRING_MAX];
89 /*TODO static ringbuffer char ringbuffer *[10] */
91 //const char * argv_0;
93 int negated:1;
95 /* --BEGIN ... --END blocks are translated to --BLOCK-xxxxxxxx macros,
96 where xxxxxxxx is a monotonic incrementing counter, its value is stored here */
97 unsigned blockcnt;
99 int state;
101 //#endif
104 \f/**/
109 * Mala engine
111 MalaEngine
112 mala_engine_new ();
114 #if 0
115 MalaEngine
116 mala_engine_new_main (int (*initfunc) (MalaEngine),
117 int argc, char ** argv,
118 mala_actioninit * actions_init);
119 #endif
121 void
122 mala_engine_free (MalaEngine self);
125 mala_engine_actions_register (MalaEngine, MalaActionInit);
128 mala_engine_exception (MalaEngine self,
129 MalaStringListNode_ref pptr,
130 MalaStringListNode here,
131 MalaString message);
134 mala_engine_expand_define (MalaEngine self, const char * name, int argc, char **argv);
137 mala_engine_pushback_word (MalaEngine self, const char * word);
139 MalaStringList
140 mala_engine_getprogram (MalaEngine self);
142 mala_state
143 mala_engine_state_get (MalaEngine self);
145 void
146 mala_engine_clearstate (MalaEngine self);
149 mala_engine_negated (MalaEngine self);
151 void
152 mala_engine_clear_negated (MalaEngine self);
154 void
155 mala_engine_dumpprogram (MalaEngine self, const char * prefix, const char * suffix);
157 void
158 mala_engine_dumpargs (MalaEngine self, const char * prefix, const char * suffix);
160 MalaEngine
161 mala_engine_run (MalaEngine self);
164 mala_engine_eval (MalaEngine self, MalaStringListNode_ref pptr);
166 //int
167 //mala_engine_expansions (MalaEngine self, MalaStringListNode_ref pptr);
171 mala_engine_string_istrue (MalaEngine self, MalaString str);
174 mala_engine_check_expansionflag (MalaEngine self, int flag);
178 mala_engine_expand (MalaEngine self, MalaStringList list, MalaStringListNode_ref pptr);
181 mala_engine_literal_expansion (MalaEngine self,
182 MalaStringList list,
183 MalaStringListNode_ref pptr);
186 mala_engine_backquote_expansion (MalaEngine self,
187 MalaStringList list,
188 MalaStringListNode_ref pptr);
191 mala_engine_numsplit_expansion (MalaEngine self,
192 MalaStringList list,
193 MalaStringListNode_ref pptr);
196 mala_engine_exclam_expansion (MalaEngine self,
197 MalaStringList list,
198 MalaStringListNode_ref pptr);
201 mala_engine_no_expansion (MalaEngine self,
202 MalaStringList list,
203 MalaStringListNode_ref pptr);
206 mala_engine_assign_expansion (MalaEngine self,
207 MalaStringList list,
208 MalaStringListNode_ref pptr);
211 mala_engine_envvar_expansion (MalaEngine self,
212 MalaStringList list,
213 MalaStringListNode_ref pptr);
216 mala_engine_char_expansion (MalaEngine self,
217 MalaStringList list,
218 MalaStringListNode_ref pptr);
221 mala_engine_underscore_expansion (MalaEngine self,
222 MalaStringList list,
223 MalaStringListNode_ref pptr);
225 int mala_engine_setenv_expansion (MalaEngine self,
226 MalaStringList list,
227 MalaStringListNode_ref pptr);
229 int mala_engine_bracket_expansion (MalaEngine self,
230 MalaStringList list,
231 MalaStringListNode_ref pptr);
233 int mala_engine_assign_contraction (MalaEngine self,
234 MalaStringList list,
235 MalaStringListNode_ref pptr);
238 mala_engine_add_action_cstr (MalaEngine self, const char* cname, void* data,
239 MalaParserFunc parser, MalaDataFactory factory,
240 MalaAction parent);
243 mala_engine_add_action (MalaEngine self, MalaString name, void* data,
244 MalaParserFunc parser, MalaDataFactory factory,
245 MalaAction parent);
248 //TODO naming convention
249 MalaStringListNode
250 mala_engine_eval_arg_n (MalaEngine self, MalaStringListNode_ref pptr, unsigned n);
252 MalaStringListNode
253 mala_engine_get_arg_n (MalaEngine self, MalaStringListNode_ref pptr, unsigned n);
256 #if 0 /*TODO*/
258 MalaEngine
259 mala_engine_new_initfunc (int (*initfunc) (MalaEngine));
263 void
264 mala_engine_pushfront_program (MalaEngine self, int args, char ** argv);
268 mala_engine_erase_action (MalaEngine, const t_uchar * key);
271 mala_engine_eval (MalaEngine self, LList pptr);
274 mala_engine_deepeval (MalaEngine self, LList pptr);
276 MalaEngine
277 mala_engine_run (MalaEngine);
279 mala_engine_exception (MalaEngine, LList begin, LList end, const char *);
281 MalaAction
282 mala_engine_action_new (MalaEngine, t_uchar** name, void** data,
283 MalaParserFunc parser, MalaDataDestructor destructor);
286 MalaAction
287 mala_engine_getaction (MalaEngine, const t_uchar * name);
289 MalaAction
290 mala_engine_getprevaction (MalaEngine, const t_uchar * name);
292 #endif /*TODO*/
298 #endif /*MALA_ENGINE_H*/
300 // Local Variables:
301 // mode: C
302 // c-file-style: "gnu"
303 // End:
304 // arch-tag: 47d718f6-e397-400c-93a6-bc71f475c0c7
305 // end_of_file