libsodium: Needed for Dnscrypto-proxy Release 1.3.0
[tomato.git] / release / src / router / config / expr.h
blobe96d03b5ab2f266962a113bbf0200807e40785d5
1 /*
2 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
3 * Released under the terms of the GNU GPL v2.0.
4 */
6 #ifndef EXPR_H
7 #define EXPR_H
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
13 #include <stdio.h>
14 #ifndef __cplusplus
15 #include <stdbool.h>
16 #endif
18 struct file {
19 struct file *next;
20 struct file *parent;
21 #ifdef CML1
22 struct statement *stmt;
23 struct statement *last_stmt;
24 #endif
25 char *name;
26 int lineno;
27 int flags;
30 #define FILE_BUSY 0x0001
31 #define FILE_SCANNED 0x0002
32 #define FILE_PRINTED 0x0004
34 typedef enum tristate {
35 no, mod, yes
36 } tristate;
38 enum expr_type {
39 E_NONE, E_OR, E_AND, E_NOT, E_EQUAL, E_UNEQUAL, E_CHOICE, E_SYMBOL
42 union expr_data {
43 struct expr *expr;
44 struct symbol *sym;
47 struct expr {
48 #ifdef CML1
49 int token;
50 #else
51 enum expr_type type;
52 #endif
53 union expr_data left, right;
56 #define E_TRI(ev) ((ev).tri)
57 #define E_EXPR(ev) ((ev).expr)
58 #define E_CALC(ev) (E_TRI(ev) = expr_calc_value(E_EXPR(ev)))
60 #define E_OR(dep1, dep2) (((dep1)>(dep2))?(dep1):(dep2))
61 #define E_AND(dep1, dep2) (((dep1)<(dep2))?(dep1):(dep2))
62 #define E_NOT(dep) (2-(dep))
64 struct expr_value {
65 struct expr *expr;
66 tristate tri;
69 #define S_VAL(sv) ((sv).value)
70 #define S_TRI(sv) ((sv).tri)
71 #define S_EQ(sv1, sv2) (S_VAL(sv1) == S_VAL(sv2) || !strcmp(S_VAL(sv1), S_VAL(sv2)))
73 struct symbol_value {
74 void *value;
75 tristate tri;
78 enum symbol_type {
79 S_UNKNOWN, S_BOOLEAN, S_TRISTATE, S_INT, S_HEX, S_STRING, S_OTHER
82 struct symbol {
83 struct symbol *next;
84 char *name;
85 char *help;
86 #ifdef CML1
87 int type;
88 #else
89 enum symbol_type type;
90 #endif
91 struct symbol_value curr, def;
92 tristate visible;
93 int flags;
94 struct property *prop;
95 struct expr *dep, *dep2;
96 struct menu *menu;
99 #define for_all_symbols(i, sym) for (i = 0; i < 257; i++) for (sym = symbol_hash[i]; sym; sym = sym->next) if (sym->type != S_OTHER)
101 #ifdef CML1
102 #define SYMBOL_UNKNOWN S_UNKNOWN
103 #define SYMBOL_BOOLEAN S_BOOLEAN
104 #define SYMBOL_TRISTATE S_TRISTATE
105 #define SYMBOL_INT S_INT
106 #define SYMBOL_HEX S_HEX
107 #define SYMBOL_STRING S_STRING
108 #define SYMBOL_OTHER S_OTHER
109 #endif
111 #define SYMBOL_YES 0x0001
112 #define SYMBOL_MOD 0x0002
113 #define SYMBOL_NO 0x0004
114 #define SYMBOL_CONST 0x0007
115 #define SYMBOL_CHECK 0x0008
116 #define SYMBOL_CHOICE 0x0010
117 #define SYMBOL_CHOICEVAL 0x0020
118 #define SYMBOL_PRINTED 0x0040
119 #define SYMBOL_VALID 0x0080
120 #define SYMBOL_OPTIONAL 0x0100
121 #define SYMBOL_WRITE 0x0200
122 #define SYMBOL_CHANGED 0x0400
123 #define SYMBOL_NEW 0x0800
124 #define SYMBOL_AUTO 0x1000
126 #define SYMBOL_MAXLENGTH 256
127 #define SYMBOL_HASHSIZE 257
128 #define SYMBOL_HASHMASK 0xff
130 enum prop_type {
131 P_UNKNOWN, P_PROMPT, P_COMMENT, P_MENU, P_ROOTMENU, P_DEFAULT, P_CHOICE
134 struct property {
135 struct property *next;
136 struct symbol *sym;
137 #ifdef CML1
138 int token;
139 #else
140 enum prop_type type;
141 #endif
142 const char *text;
143 struct symbol *def;
144 struct expr_value visible;
145 struct expr *dep;
146 struct expr *dep2;
147 struct menu *menu;
148 struct file *file;
149 int lineno;
150 #ifdef CML1
151 struct property *next_pos;
152 #endif
155 #define for_all_properties(sym, st, tok) \
156 for (st = sym->prop; st; st = st->next) \
157 if (st->type == (tok))
158 #define for_all_prompts(sym, st) for_all_properties(sym, st, P_PROMPT)
159 #define for_all_defaults(sym, st) for_all_properties(sym, st, P_DEFAULT)
160 #define for_all_choices(sym, st) for_all_properties(sym, st, P_CHOICE)
162 struct menu {
163 struct menu *next;
164 struct menu *parent;
165 struct menu *list;
166 struct symbol *sym;
167 struct property *prompt;
168 struct expr *dep;
169 //char *help;
170 struct file *file;
171 int lineno;
172 void *data;
175 #ifndef SWIG
177 extern struct file *file_list;
178 extern struct file *current_file;
179 struct file *lookup_file(const char *name);
181 extern struct symbol symbol_yes, symbol_no, symbol_mod;
182 extern struct symbol *modules_sym;
183 extern int cdebug;
184 extern int print_type;
185 struct expr *expr_alloc_symbol(struct symbol *sym);
186 #ifdef CML1
187 struct expr *expr_alloc_one(int token, struct expr *ce);
188 struct expr *expr_alloc_two(int token, struct expr *e1, struct expr *e2);
189 struct expr *expr_alloc_comp(int token, struct symbol *s1, struct symbol *s2);
190 #else
191 struct expr *expr_alloc_one(enum expr_type type, struct expr *ce);
192 struct expr *expr_alloc_two(enum expr_type type, struct expr *e1, struct expr *e2);
193 struct expr *expr_alloc_comp(enum expr_type type, struct symbol *s1, struct symbol *s2);
194 #endif
195 struct expr *expr_alloc_and(struct expr *e1, struct expr *e2);
196 struct expr *expr_copy(struct expr *org);
197 void expr_free(struct expr *e);
198 int expr_eq(struct expr *e1, struct expr *e2);
199 void expr_eliminate_eq(struct expr **ep1, struct expr **ep2);
200 tristate expr_calc_value(struct expr *e);
201 struct expr *expr_eliminate_yn(struct expr *e);
202 struct expr *expr_trans_bool(struct expr *e);
203 struct expr *expr_eliminate_dups(struct expr *e);
204 struct expr *expr_transform(struct expr *e);
205 int expr_contains_symbol(struct expr *dep, struct symbol *sym);
206 bool expr_depends_symbol(struct expr *dep, struct symbol *sym);
207 struct expr *expr_extract_eq_and(struct expr **ep1, struct expr **ep2);
208 struct expr *expr_extract_eq_or(struct expr **ep1, struct expr **ep2);
209 void expr_extract_eq(enum expr_type type, struct expr **ep, struct expr **ep1, struct expr **ep2);
210 struct expr *expr_trans_compare(struct expr *e, enum expr_type type, struct symbol *sym);
212 void expr_fprint(struct expr *e, FILE *out);
213 void print_expr(int mask, struct expr *e, int prevtoken);
215 #ifdef CML1
216 static inline int expr_is_yes(struct expr *e)
218 return !e || (e->token == WORD && e->left.sym == &symbol_yes);
221 static inline int expr_is_no(struct expr *e)
223 return e && (e->token == WORD && e->left.sym == &symbol_no);
225 #else
226 static inline int expr_is_yes(struct expr *e)
228 return !e || (e->type == E_SYMBOL && e->left.sym == &symbol_yes);
231 static inline int expr_is_no(struct expr *e)
233 return e && (e->type == E_SYMBOL && e->left.sym == &symbol_no);
235 #endif
236 #endif
238 #ifdef __cplusplus
240 #endif
242 #endif /* EXPR_H */