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/condition.c | |
| parent | 073fe4bf9fca6bf40cef2886d75df832ef4b6fca (diff) | |
initial
Diffstat (limited to 'other/burneye/src/conf/tmp/condition.c')
| -rw-r--r-- | other/burneye/src/conf/tmp/condition.c | 157 |
1 files changed, 157 insertions, 0 deletions
diff --git a/other/burneye/src/conf/tmp/condition.c b/other/burneye/src/conf/tmp/condition.c new file mode 100644 index 0000000..368aa73 --- /dev/null +++ b/other/burneye/src/conf/tmp/condition.c | |||
| @@ -0,0 +1,157 @@ | |||
| 1 | /* fornax - distributed network | ||
| 2 | * | ||
| 3 | * by team teso | ||
| 4 | * | ||
| 5 | * scripting condition routines | ||
| 6 | */ | ||
| 7 | |||
| 8 | #include <stdlib.h> | ||
| 9 | #include <string.h> | ||
| 10 | #include "../../shared/common.h" | ||
| 11 | #include "condition.h" | ||
| 12 | #include "symbol.h" | ||
| 13 | |||
| 14 | extern sym_elem ** gl_ns; | ||
| 15 | |||
| 16 | |||
| 17 | int | ||
| 18 | cond_verify (condition *cnd) | ||
| 19 | { | ||
| 20 | /* condition is invalid and hence cannot be met | ||
| 21 | */ | ||
| 22 | if (cnd->cond1 == NULL && cnd->val1 == NULL) | ||
| 23 | return (0); | ||
| 24 | |||
| 25 | /* pair condition | ||
| 26 | */ | ||
| 27 | if (cnd->cond1 != NULL) { | ||
| 28 | int c1_ret, c2_ret; | ||
| 29 | |||
| 30 | c1_ret = cond_verify (cnd->cond1); | ||
| 31 | c2_ret = cond_verify (cnd->cond2); | ||
| 32 | |||
| 33 | if (cnd->logoper == LO_OR) { | ||
| 34 | return ((c1_ret == 1 || c2_ret == 1) ? 1 : 0); | ||
| 35 | } else if (cnd->logoper == LO_AND) { | ||
| 36 | return ((c1_ret == 1 && c2_ret == 1) ? 1 : 0); | ||
| 37 | } | ||
| 38 | |||
| 39 | /* shouldn't happen | ||
| 40 | */ | ||
| 41 | return (0); | ||
| 42 | } else { | ||
| 43 | int eq_val = 0; | ||
| 44 | char * val1_s; | ||
| 45 | char * val2_s; | ||
| 46 | |||
| 47 | /* normal equality test (broken-down-case) | ||
| 48 | * first substitute each side then compare according to the | ||
| 49 | * equality operator | ||
| 50 | */ | ||
| 51 | val1_s = (char *) sym_resolve (gl_ns, cnd->val1); | ||
| 52 | val2_s = sym_subst (gl_ns, cnd->val2); | ||
| 53 | |||
| 54 | switch (cnd->eqop) { | ||
| 55 | case (EQ_EQUAL): | ||
| 56 | eq_val = (strcasecmp (val1_s, val2_s) == 0) ? 1 : 0; | ||
| 57 | break; | ||
| 58 | case (EQ_NOTEQ): | ||
| 59 | eq_val = (strcasecmp (val1_s, val2_s) == 0) ? 0 : 1; | ||
| 60 | break; | ||
| 61 | /* to be implemented | ||
| 62 | */ | ||
| 63 | case (EQ_GREATEQ): | ||
| 64 | case (EQ_LOWEREQ): | ||
| 65 | break; | ||
| 66 | default: | ||
| 67 | break; | ||
| 68 | } | ||
| 69 | |||
| 70 | free (val2_s); | ||
| 71 | |||
| 72 | return (eq_val); | ||
| 73 | } | ||
| 74 | } | ||
| 75 | |||
| 76 | |||
| 77 | condition * | ||
| 78 | cond_create (void) | ||
| 79 | { | ||
| 80 | condition * new = xcalloc (1, sizeof (condition)); | ||
| 81 | |||
| 82 | return (new); | ||
| 83 | } | ||
| 84 | |||
| 85 | |||
| 86 | void | ||
| 87 | cond_free (condition *c) | ||
| 88 | { | ||
| 89 | if (c->val1 != NULL) | ||
| 90 | free (c->val1); | ||
| 91 | if (c->val2 != NULL) | ||
| 92 | free (c->val2); | ||
| 93 | if (c->cond1 != NULL) | ||
| 94 | cond_free (c->cond1); | ||
| 95 | if (c->cond2 != NULL) | ||
| 96 | cond_free (c->cond2); | ||
| 97 | free (c); | ||
| 98 | |||
| 99 | return; | ||
| 100 | } | ||
| 101 | |||
| 102 | |||
| 103 | condition * | ||
| 104 | cond_set_cond1 (condition *c, condition *c1) | ||
| 105 | { | ||
| 106 | c->cond1 = c1; | ||
| 107 | |||
| 108 | return (c); | ||
| 109 | } | ||
| 110 | |||
| 111 | |||
| 112 | condition * | ||
| 113 | cond_set_cond2 (condition *c, condition *c2) | ||
| 114 | { | ||
| 115 | c->cond2 = c2; | ||
| 116 | |||
| 117 | return (c); | ||
| 118 | } | ||
| 119 | |||
| 120 | |||
| 121 | condition * | ||
| 122 | cond_set_logoper (condition *c, int lo) | ||
| 123 | { | ||
| 124 | c->logoper = lo; | ||
| 125 | |||
| 126 | return (c); | ||
| 127 | } | ||
| 128 | |||
| 129 | |||
| 130 | condition * | ||
| 131 | cond_set_eqop (condition *c, int eo) | ||
| 132 | { | ||
| 133 | c->eqop = eo; | ||
| 134 | |||
| 135 | return (c); | ||
| 136 | } | ||
| 137 | |||
| 138 | |||
| 139 | condition * | ||
| 140 | cond_set_val1 (condition *c, char *val) | ||
| 141 | { | ||
| 142 | c->val1 = val; | ||
| 143 | |||
| 144 | return (c); | ||
| 145 | } | ||
| 146 | |||
| 147 | |||
| 148 | condition * | ||
| 149 | cond_set_val2 (condition *c, char *val) | ||
| 150 | { | ||
| 151 | c->val2 = val; | ||
| 152 | |||
| 153 | return (c); | ||
| 154 | } | ||
| 155 | |||
| 156 | |||
| 157 | |||
