diff options
| author | Root THC | 2026-02-24 12:42:47 +0000 |
|---|---|---|
| committer | Root THC | 2026-02-24 12:42:47 +0000 |
| commit | c9cbeced5b3f2bdd7407e29c0811e65954132540 (patch) | |
| tree | aefc355416b561111819de159ccbd86c3004cf88 /other/burneye/src/conf/tmp/script.c | |
| parent | 073fe4bf9fca6bf40cef2886d75df832ef4b6fca (diff) | |
initial
Diffstat (limited to 'other/burneye/src/conf/tmp/script.c')
| -rw-r--r-- | other/burneye/src/conf/tmp/script.c | 154 |
1 files changed, 154 insertions, 0 deletions
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 @@ | |||
| 1 | /* fornax - distributed network | ||
| 2 | * | ||
| 3 | * by team teso | ||
| 4 | * | ||
| 5 | * scripting capabilities routines | ||
| 6 | */ | ||
| 7 | |||
| 8 | #include <stdio.h> | ||
| 9 | #include "branch.h" | ||
| 10 | #include "call.h" | ||
| 11 | #include "compiler.h" | ||
| 12 | #include "element.h" | ||
| 13 | #include "functions.h" | ||
| 14 | #include "script.h" | ||
| 15 | #include "symbol.h" | ||
| 16 | |||
| 17 | sym_elem ** gl_ns = NULL; | ||
| 18 | extern function gl_fnc[]; | ||
| 19 | |||
| 20 | |||
| 21 | /* static functions | ||
| 22 | */ | ||
| 23 | |||
| 24 | void scr_elem_exec (element **el); | ||
| 25 | static void scr_call (call *c); | ||
| 26 | static void scr_branch (branch * br); | ||
| 27 | |||
| 28 | |||
| 29 | /* scr_elem_exec | ||
| 30 | * | ||
| 31 | * execute the element list pointed to by `el' | ||
| 32 | * | ||
| 33 | * return in any case | ||
| 34 | */ | ||
| 35 | |||
| 36 | void | ||
| 37 | scr_elem_exec (element **el) | ||
| 38 | { | ||
| 39 | int el_ptr; | ||
| 40 | element * ec; | ||
| 41 | |||
| 42 | if (el == NULL || el[0] == NULL) | ||
| 43 | return; | ||
| 44 | |||
| 45 | for (el_ptr = 0 ; el[el_ptr] != NULL ; ++el_ptr) { | ||
| 46 | ec = el[el_ptr]; | ||
| 47 | |||
| 48 | switch (ec->type) { | ||
| 49 | case (ELEM_TYPE_CALL): | ||
| 50 | scr_call ((call *) ec->data); | ||
| 51 | break; | ||
| 52 | |||
| 53 | case (ELEM_TYPE_BRANCH): | ||
| 54 | scr_branch ((branch *) ec->data); | ||
| 55 | break; | ||
| 56 | |||
| 57 | /* in case it is a set element, just add the symbol element | ||
| 58 | * to the global namespace | ||
| 59 | */ | ||
| 60 | case (ELEM_TYPE_SET): | ||
| 61 | gl_ns = scr_ns_add (gl_ns, (sym_elem *) ec->data); | ||
| 62 | break; | ||
| 63 | |||
| 64 | /* should never happen | ||
| 65 | */ | ||
| 66 | default: | ||
| 67 | break; | ||
| 68 | } | ||
| 69 | } | ||
| 70 | |||
| 71 | return; | ||
| 72 | } | ||
| 73 | |||
| 74 | |||
| 75 | /* scr_call | ||
| 76 | * | ||
| 77 | * make a call, just like et did when he phoned home. well, not really, but | ||
| 78 | * quite similar | ||
| 79 | * | ||
| 80 | * return in any case | ||
| 81 | */ | ||
| 82 | |||
| 83 | static void | ||
| 84 | scr_call (call *c) | ||
| 85 | { | ||
| 86 | fnc_handler f_h; | ||
| 87 | |||
| 88 | /* nothing to execute today, baby | ||
| 89 | */ | ||
| 90 | if (c == NULL || c->name == NULL) | ||
| 91 | return; | ||
| 92 | |||
| 93 | f_h = fnc_find (gl_fnc, c->name); | ||
| 94 | |||
| 95 | /* no function found or nop -> return | ||
| 96 | */ | ||
| 97 | if (f_h == NULL) | ||
| 98 | return; | ||
| 99 | |||
| 100 | (void) f_h (c->parameters); | ||
| 101 | |||
| 102 | return; | ||
| 103 | } | ||
| 104 | |||
| 105 | |||
| 106 | static void | ||
| 107 | scr_branch (branch * br) | ||
| 108 | { | ||
| 109 | if (cond_verify (br->cond) == 1) { | ||
| 110 | scr_elem_exec (br->b_true); | ||
| 111 | } else { | ||
| 112 | scr_elem_exec (br->b_false); | ||
| 113 | } | ||
| 114 | |||
| 115 | return; | ||
| 116 | } | ||
| 117 | |||
| 118 | |||
| 119 | sym_elem ** | ||
| 120 | scr_ns_add (sym_elem **ns, sym_elem *elem) | ||
| 121 | { | ||
| 122 | return (sym_elem_add (ns, elem)); | ||
| 123 | } | ||
| 124 | |||
| 125 | |||
| 126 | int | ||
| 127 | scr_exec (char *script) | ||
| 128 | { | ||
| 129 | element ** scr; | ||
| 130 | |||
| 131 | scr = cp_compile (script, strlen (script)); | ||
| 132 | if (scr == NULL) | ||
| 133 | return (0); | ||
| 134 | |||
| 135 | scr_elem_exec (scr); | ||
| 136 | |||
| 137 | elem_list_free (scr); | ||
| 138 | |||
| 139 | return (1); | ||
| 140 | } | ||
| 141 | |||
| 142 | |||
| 143 | element ** | ||
| 144 | scr_compile (char *script) | ||
| 145 | { | ||
| 146 | element ** scr = NULL; | ||
| 147 | |||
| 148 | if (script != NULL) | ||
| 149 | scr = cp_compile (script, strlen (script)); | ||
| 150 | |||
| 151 | return (scr); | ||
| 152 | } | ||
| 153 | |||
| 154 | |||
