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.
23 #include "mala_types.h"
24 #include "stringbucket.h"
25 #include "stringlist.h"
28 enum mala_common_strings_enum
34 MALA_STRING_EXCLAMATIONMARK
,
36 MALA_STRING_BACKQUOTE
,
46 MALA_STRING_FLAG_LITERAL_EXPANSION
,
47 MALA_STRING_FLAG_EXCLAM_EXPANSION
,
48 MALA_STRING_FLAG_NO_EXPANSION
,
49 MALA_STRING_FLAG_NUMSPLIT_EXPANSION
,
50 MALA_STRING_FLAG_CHAR_EXPANSION
,
51 MALA_STRING_FLAG_ASSIGN_EXPANSION
,
52 MALA_STRING_FLAG_SETENV_EXPANSION
,
53 MALA_STRING_FLAG_ENVVAR_EXPANSION
,
54 MALA_STRING_FLAG_UNDERSCORE_EXPANSION
,
55 MALA_STRING_FLAG_BRACKET_EXPANSION
,
56 MALA_STRING_FLAG_ASSIGN_CONTRACTION
,
57 MALA_STRING_ERROR_MISSING_ARGUMENT
,
58 MALA_STRING_ERROR_MISSING_END
,
59 MALA_STRING_ERROR_END_WITHOUT_BEGIN
,
60 MALA_MAX_COMMON_STRING
69 struct mala_engine_struct
72 * every tokenized word is collected in 'words'
73 * actions can be bound to these words through the strings user variable
75 mala_stringbucket words
;
76 mala_stringlist program
;
77 mala_stringlist arguments
;
79 MalaString common_string
[MALA_MAX_COMMON_STRING
];
81 /*TODO static ringbuffer char ringbuffer *[10] */
83 //const char * argv_0;
87 /* --BEGIN ... --END blocks are translated to --BLOCK-xxxxxxxx macros,
88 where xxxxxxxx is a monotonic incrementing counter, its value is stored here */
108 mala_engine_new_main (int (*initfunc
) (MalaEngine
),
109 int argc
, char ** argv
,
110 mala_actioninit
* actions_init
);
114 mala_engine_free (MalaEngine self
);
117 mala_engine_actions_register (MalaEngine
, MalaActionInit
);
120 mala_engine_exception (MalaEngine self
,
121 MalaStringListNode_ref pptr
,
122 MalaStringListNode here
,
126 mala_engine_macro_define (MalaEngine self
, const char * name
, int argc
, char **argv
);
129 mala_engine_pushback_word (MalaEngine self
, const char * word
);
132 mala_engine_getprogram (MalaEngine self
);
135 mala_engine_state_get (MalaEngine self
);
138 mala_engine_clearstate (MalaEngine self
);
141 mala_engine_negated (MalaEngine self
);
144 mala_engine_clear_negated (MalaEngine self
);
147 mala_engine_dumpprogram (MalaEngine self
, const char * prefix
, const char * suffix
);
150 mala_engine_dumpargs (MalaEngine self
, const char * prefix
, const char * suffix
);
153 mala_engine_run (MalaEngine self
);
156 mala_engine_eval (MalaEngine self
, MalaStringListNode_ref pptr
);
159 //mala_engine_expansions (MalaEngine self, MalaStringListNode_ref pptr);
163 mala_engine_string_istrue (MalaEngine self
, MalaString str
);
166 mala_engine_check_expansionflag (MalaEngine self
, int flag
);
170 mala_engine_expand (MalaEngine self
, MalaStringList list
, MalaStringListNode_ref pptr
);
173 mala_engine_literal_expansion (MalaEngine self
,
175 MalaStringListNode_ref pptr
);
178 mala_engine_backquote_expansion (MalaEngine self
,
180 MalaStringListNode_ref pptr
);
183 mala_engine_numsplit_expansion (MalaEngine self
,
185 MalaStringListNode_ref pptr
);
188 mala_engine_exclam_expansion (MalaEngine self
,
190 MalaStringListNode_ref pptr
);
193 mala_engine_no_expansion (MalaEngine self
,
195 MalaStringListNode_ref pptr
);
198 mala_engine_assign_expansion (MalaEngine self
,
200 MalaStringListNode_ref pptr
);
203 mala_engine_envvar_expansion (MalaEngine self
,
205 MalaStringListNode_ref pptr
);
208 mala_engine_char_expansion (MalaEngine self
,
210 MalaStringListNode_ref pptr
);
213 mala_engine_underscore_expansion (MalaEngine self
,
215 MalaStringListNode_ref pptr
);
217 int mala_engine_setenv_expansion (MalaEngine self
,
219 MalaStringListNode_ref pptr
);
221 int mala_engine_bracket_expansion (MalaEngine self
,
223 MalaStringListNode_ref pptr
);
225 int mala_engine_assign_contraction (MalaEngine self
,
227 MalaStringListNode_ref pptr
);
230 mala_engine_add_action_cstr (MalaEngine self
, const char* cname
, void* data
,
231 MalaParserFunc parser
, MalaDataFactory factory
,
235 mala_engine_add_action (MalaEngine self
, MalaString name
, void* data
,
236 MalaParserFunc parser
, MalaDataFactory factory
,
240 mala_engine_try_eval_arg_n (MalaEngine self
, MalaStringListNode_ref pptr
, unsigned n
);
246 mala_engine_new_initfunc (int (*initfunc
) (MalaEngine
));
251 mala_engine_pushfront_program (MalaEngine self
, int args
, char ** argv
);
255 mala_engine_erase_action (MalaEngine
, const t_uchar
* key
);
258 mala_engine_eval (MalaEngine self
, LList pptr
);
261 mala_engine_deepeval (MalaEngine self
, LList pptr
);
264 mala_engine_run (MalaEngine
);
266 mala_engine_exception (MalaEngine
, LList begin
, LList end
, const char *);
269 mala_engine_action_new (MalaEngine
, t_uchar
** name
, void** data
,
270 MalaParserFunc parser
, MalaDataDestructor destructor
);
274 mala_engine_getaction (MalaEngine
, const t_uchar
* name
);
277 mala_engine_getprevaction (MalaEngine
, const t_uchar
* name
);
285 #endif /*MALA_ENGINE_H*/
289 // c-file-style: "gnu"
291 // arch-tag: 47d718f6-e397-400c-93a6-bc71f475c0c7