From c9cbeced5b3f2bdd7407e29c0811e65954132540 Mon Sep 17 00:00:00 2001 From: Root THC Date: Tue, 24 Feb 2026 12:42:47 +0000 Subject: initial --- other/burneye/src/conf/tmp/script.c | 154 ++++++++++++++++++++++++++++++++++++ 1 file changed, 154 insertions(+) create mode 100644 other/burneye/src/conf/tmp/script.c (limited to 'other/burneye/src/conf/tmp/script.c') diff --git a/other/burneye/src/conf/tmp/script.c b/other/burneye/src/conf/tmp/script.c new file mode 100644 index 0000000..3fc7634 --- /dev/null +++ b/other/burneye/src/conf/tmp/script.c @@ -0,0 +1,154 @@ +/* fornax - distributed network + * + * by team teso + * + * scripting capabilities routines + */ + +#include +#include "branch.h" +#include "call.h" +#include "compiler.h" +#include "element.h" +#include "functions.h" +#include "script.h" +#include "symbol.h" + +sym_elem ** gl_ns = NULL; +extern function gl_fnc[]; + + +/* static functions + */ + +void scr_elem_exec (element **el); +static void scr_call (call *c); +static void scr_branch (branch * br); + + +/* scr_elem_exec + * + * execute the element list pointed to by `el' + * + * return in any case + */ + +void +scr_elem_exec (element **el) +{ + int el_ptr; + element * ec; + + if (el == NULL || el[0] == NULL) + return; + + for (el_ptr = 0 ; el[el_ptr] != NULL ; ++el_ptr) { + ec = el[el_ptr]; + + switch (ec->type) { + case (ELEM_TYPE_CALL): + scr_call ((call *) ec->data); + break; + + case (ELEM_TYPE_BRANCH): + scr_branch ((branch *) ec->data); + break; + + /* in case it is a set element, just add the symbol element + * to the global namespace + */ + case (ELEM_TYPE_SET): + gl_ns = scr_ns_add (gl_ns, (sym_elem *) ec->data); + break; + + /* should never happen + */ + default: + break; + } + } + + return; +} + + +/* scr_call + * + * make a call, just like et did when he phoned home. well, not really, but + * quite similar + * + * return in any case + */ + +static void +scr_call (call *c) +{ + fnc_handler f_h; + + /* nothing to execute today, baby + */ + if (c == NULL || c->name == NULL) + return; + + f_h = fnc_find (gl_fnc, c->name); + + /* no function found or nop -> return + */ + if (f_h == NULL) + return; + + (void) f_h (c->parameters); + + return; +} + + +static void +scr_branch (branch * br) +{ + if (cond_verify (br->cond) == 1) { + scr_elem_exec (br->b_true); + } else { + scr_elem_exec (br->b_false); + } + + return; +} + + +sym_elem ** +scr_ns_add (sym_elem **ns, sym_elem *elem) +{ + return (sym_elem_add (ns, elem)); +} + + +int +scr_exec (char *script) +{ + element ** scr; + + scr = cp_compile (script, strlen (script)); + if (scr == NULL) + return (0); + + scr_elem_exec (scr); + + elem_list_free (scr); + + return (1); +} + + +element ** +scr_compile (char *script) +{ + element ** scr = NULL; + + if (script != NULL) + scr = cp_compile (script, strlen (script)); + + return (scr); +} + + -- cgit v1.3