1 : #ifndef CONF_H
2 : #define CONF_H
3 :
4 : #include <vstr.h>
5 : #include "compiler.h"
6 :
7 : #define CONF_PARSE_ERR 0
8 : #define CONF_PARSE_FIN 1
9 :
10 : #define CONF_PARSE_STATE_BEG 0
11 : #define CONF_PARSE_STATE_WS 1
12 : #define CONF_PARSE_STATE_LIST_END_OR_WS 2
13 : #define CONF_PARSE_STATE_CHOOSE 3
14 : #define CONF_PARSE_STATE_QUOTE_D_BEG 4
15 : #define CONF_PARSE_STATE_QUOTE_S_BEG 5
16 : #define CONF_PARSE_STATE_UNQUOTE_BEG 6
17 : #define CONF_PARSE_STATE_QUOTE_D_END 7
18 : #define CONF_PARSE_STATE_QUOTE_DDD_END 8
19 : #define CONF_PARSE_STATE_QUOTE_S_END 9
20 : #define CONF_PARSE_STATE_QUOTE_SSS_END 10
21 : #define CONF_PARSE_STATE_UNQUOTE_D_END 11 /* unescaped quoted */
22 : #define CONF_PARSE_STATE_UNQUOTE_DDD_END 12
23 : #define CONF_PARSE_STATE_UNQUOTE_S_END 13
24 : #define CONF_PARSE_STATE_UNQUOTE_SSS_END 14
25 : #define CONF_PARSE_STATE_SYMBOL_END 15
26 : #define CONF_PARSE_STATE_END 16
27 :
28 : #define CONF_PARSE_STATE_QUOTE_X2XXX \
29 : (CONF_PARSE_STATE_QUOTE_DDD_END - CONF_PARSE_STATE_QUOTE_D_END)
30 : #define CONF_PARSE_STATE_QUOTE2UNQUOTE_END \
31 : (CONF_PARSE_STATE_UNQUOTE_D_END - CONF_PARSE_STATE_QUOTE_D_END)
32 :
33 : #define CONF_PARSE_LIST_DEPTH_SZ 64
34 :
35 : #define CONF_TOKEN_TYPE_ERR 0
36 : #define CONF_TOKEN_TYPE_CLIST 1
37 : #define CONF_TOKEN_TYPE_SLIST 2
38 : #define CONF_TOKEN_TYPE_QUOTE_D 3
39 : #define CONF_TOKEN_TYPE_QUOTE_ESC_D 4
40 : #define CONF_TOKEN_TYPE_QUOTE_DDD 5
41 : #define CONF_TOKEN_TYPE_QUOTE_ESC_DDD 6
42 : #define CONF_TOKEN_TYPE_QUOTE_S 7
43 : #define CONF_TOKEN_TYPE_QUOTE_ESC_S 8
44 : #define CONF_TOKEN_TYPE_QUOTE_SSS 9
45 : #define CONF_TOKEN_TYPE_QUOTE_ESC_SSS 10
46 : #define CONF_TOKEN_TYPE_SYMBOL 11
47 : #define CONF_TOKEN_TYPE_USER_BEG 12
48 :
49 : #define CONF_TOKEN_TYPE_2ESC \
50 : (CONF_TOKEN_TYPE_QUOTE_ESC_D - CONF_TOKEN_TYPE_QUOTE_D)
51 :
52 : #define CONF_SC_TYPE_RET_OK 0
53 : /* #define CONF_SC_TYPE_RET_ERR_TOO_MANY 1 */
54 : #define CONF_SC_TYPE_RET_ERR_NO_MATCH 2
55 : #define CONF_SC_TYPE_RET_ERR_NOT_EXIST 3
56 : #define CONF_SC_TYPE_RET_ERR_PARSE 4
57 :
58 : #define CONF_SC_PARSE_DEPTH_TOKEN_RET(c, t, d, ret) do { \
59 : if (!conf_token_list_num(t, d)) \
60 : return ret ; \
61 : conf_parse_token(c, t); \
62 : if (conf_token_at_depth(t) != (d)) \
63 : return ret ; \
64 : } while (0)
65 :
66 : #define CONF_SC_PARSE_TYPE_DEPTH_TOKEN_RET(c, t, d, T, ret) do { \
67 : CONF_SC_PARSE_DEPTH_TOKEN_RET(c, t, d, ret); \
68 : if (token->type != T) \
69 : return ret ; \
70 : } while (0)
71 :
72 : #define CONF_SC_PARSE_CLIST_DEPTH_TOKEN_RET(c, t, d, ret) \
73 : CONF_SC_PARSE_TYPE_DEPTH_TOKEN_RET(c, t, d, CONF_TOKEN_TYPE_CLIST, ret)
74 : #define CONF_SC_PARSE_SLIST_DEPTH_TOKEN_RET(c, t, d, ret) \
75 : CONF_SC_PARSE_TYPE_DEPTH_TOKEN_RET(c, t, d, CONF_TOKEN_TYPE_SLIST, ret)
76 :
77 : #define CONF_SC_PARSE_TOP_TOKEN_RET(c, t, ret) do { \
78 : unsigned int conf_sc__token_depth = (t)->depth_num; \
79 : CONF_SC_PARSE_DEPTH_TOKEN_RET(c, t, conf_sc__token_depth, ret); \
80 : } while (0)
81 : #define CONF_SC_PARSE_CLIST_TOP_TOKEN_RET(c, t, ret) do { \
82 : unsigned int conf_sc__token_depth = (t)->depth_num; \
83 : CONF_SC_PARSE_CLIST_DEPTH_TOKEN_RET(c, t, conf_sc__token_depth, ret); \
84 : } while (0)
85 : #define CONF_SC_PARSE_SLIST_TOP_TOKEN_RET(c, t, ret) do { \
86 : unsigned int conf_sc__token_depth = (t)->depth_num; \
87 : CONF_SC_PARSE_SLIST_DEPTH_TOKEN_RET(c, t, conf_sc__token_depth, ret); \
88 : } while (0)
89 :
90 : #define CONF_SC_TOGGLE_CLIST_VAR(x) do { \
91 : if (token->type == CONF_TOKEN_TYPE_CLIST) \
92 : { \
93 : (x) = 1; \
94 : CONF_SC_PARSE_TOP_TOKEN_RET(conf, token, 0); \
95 : } \
96 : else \
97 : (x) = 0; \
98 : } while (0)
99 :
100 : #define CONF_SC_MAKE_CLIST_MID(x, y) \
101 : while (conf_token_list_num(token, x)) \
102 : { \
103 : CONF_SC_PARSE_DEPTH_TOKEN_RET(conf, token, x, 0); \
104 : CONF_SC_TOGGLE_CLIST_VAR(y); \
105 : \
106 : if (0)
107 :
108 : #define CONF_SC_MAKE_CLIST_BEG(x, y) \
109 : unsigned int conf_sc__depth_ ## x = token->depth_num; \
110 : CONF_SC_MAKE_CLIST_MID(conf_sc__depth_ ## x, y)
111 :
112 : #define CONF_SC_MAKE_CLIST_END() \
113 : else \
114 : return (0); \
115 : } \
116 : do { } while (0)
117 :
118 :
119 : typedef struct Conf__uval_store
120 : {
121 : Vstr_ref *ref;
122 : unsigned int nxt;
123 : } Conf__uval_store;
124 :
125 : typedef struct Conf_parse
126 : {
127 : Vstr_sects *sects;
128 : Vstr_base *data;
129 : Vstr_base *tmp;
130 : unsigned int types_sz;
131 : unsigned int *types_ptr;
132 : unsigned int uvals_sz;
133 : unsigned int uvals_num;
134 : Conf__uval_store *uvals_ptr;
135 : unsigned int state;
136 : unsigned int depth;
137 : } Conf_parse;
138 :
139 : typedef struct Conf_token
140 : {
141 : union
142 : {
143 : const Vstr_sect_node *node;
144 : unsigned int list_num;
145 : unsigned int uval_num;
146 : } u;
147 :
148 : unsigned int type;
149 : unsigned int num;
150 : unsigned int depth_num;
151 : unsigned int depth_nums[CONF_PARSE_LIST_DEPTH_SZ + 1];
152 : } Conf_token;
153 : #define CONF_TOKEN_INIT {{NULL}, CONF_TOKEN_TYPE_ERR, 0, 0, {0}}
154 :
155 : extern Conf_parse *conf_parse_make(Vstr_conf *)
156 : VSTR__COMPILE_ATTR_MALLOC();
157 : extern void conf_parse_free(Conf_parse *);
158 :
159 : extern int conf_parse_lex(Conf_parse *, size_t, size_t);
160 :
161 : extern Conf_token *conf_token_make(void)
162 : VSTR__COMPILE_ATTR_MALLOC();
163 : extern void conf_token_free(Conf_token *);
164 :
165 : extern int conf_parse_token(const Conf_parse *, Conf_token *);
166 : extern int conf_parse_end_token(const Conf_parse *, Conf_token *, unsigned int);
167 : extern int conf_parse_num_token(const Conf_parse *, Conf_token *, unsigned int);
168 :
169 : extern unsigned int conf_token_at_depth(const Conf_token *);
170 :
171 : extern const char *conf_token_name(const Conf_token *);
172 : extern const Vstr_sect_node *conf_token_value(const Conf_token *);
173 :
174 : extern Vstr_ref *conf_token_get_user_value(const Conf_parse *,
175 : const Conf_token *, unsigned int *);
176 : extern int conf_token_set_user_value(Conf_parse *, Conf_token *,
177 : unsigned int, Vstr_ref *, unsigned int);
178 :
179 : extern int conf_token_cmp_val_eq(const Conf_parse *, const Conf_token *,
180 : const Vstr_base *, size_t, size_t);
181 : extern int conf_token_cmp_val_buf_eq(const Conf_parse *, const Conf_token *,
182 : const char *, size_t);
183 : extern int conf_token_cmp_val_cstr_eq(const Conf_parse *, const Conf_token *,
184 : const char *);
185 : extern int conf_token_cmp_val_beg_eq(const Conf_parse *, const Conf_token *,
186 : const Vstr_base *, size_t, size_t);
187 : extern int conf_token_cmp_case_val_eq(const Conf_parse *,
188 : const Conf_token *,
189 : const Vstr_base *, size_t, size_t);
190 : extern int conf_token_cmp_case_val_cstr_eq(const Conf_parse *,
191 : const Conf_token *,
192 : const char *);
193 : extern int conf_token_cmp_case_val_beg_eq(const Conf_parse *,
194 : const Conf_token *,
195 : const Vstr_base *, size_t, size_t);
196 : extern int conf_token_cmp_sym_eq(const Conf_parse *, const Conf_token *,
197 : const Vstr_base *, size_t, size_t);
198 : extern int conf_token_cmp_sym_buf_eq(const Conf_parse *, const Conf_token *,
199 : const char *, size_t);
200 : extern int conf_token_cmp_sym_cstr_eq(const Conf_parse *, const Conf_token *,
201 : const char *);
202 : extern int conf_token_cmp_case_sym_cstr_eq(const Conf_parse *,
203 : const Conf_token *,
204 : const char *);
205 :
206 : extern int conf_token_srch_val(const Conf_parse *, const Conf_token *,
207 : const Vstr_base *, size_t, size_t);
208 : extern int conf_token_srch_case_val(const Conf_parse *, const Conf_token *,
209 : const Vstr_base *, size_t, size_t);
210 :
211 : extern unsigned int conf_token_list_num(const Conf_token *, unsigned int);
212 :
213 : extern int conf_sc_token_parse_toggle(const Conf_parse *, Conf_token *, int *);
214 : extern int conf_sc_token_parse_uint(const Conf_parse *, Conf_token *,
215 : unsigned int *);
216 : extern int conf_sc_token_parse_ulong(const Conf_parse *, Conf_token *,
217 : unsigned long *);
218 : extern int conf_sc_token_parse_uintmax(const Conf_parse *, Conf_token *,
219 : uintmax_t *);
220 : extern int conf_sc_token_parse_eq(const Conf_parse *, Conf_token *,
221 : const Vstr_base *, size_t, size_t, int *);
222 : extern int conf_sc_token_parse_cstr_eq(const Conf_parse *, Conf_token *,
223 : const char *, int *);
224 : extern int conf_sc_token_app_vstr(const Conf_parse *, Conf_token *,
225 : Vstr_base *,
226 : const Vstr_base **, size_t *, size_t *);
227 : extern int conf_sc_token_sub_vstr(const Conf_parse *, Conf_token *,
228 : Vstr_base *, size_t, size_t);
229 : extern int conf_sc_conv_unesc(Vstr_base *, size_t, size_t, size_t *);
230 :
231 : extern void conf_parse_compress(Conf_parse *);
232 : extern void conf_parse_backtrace(Vstr_base *, const char *,
233 : const Conf_parse *, const Conf_token *);
234 :
235 : #if !defined(CONF_COMPILE_INLINE)
236 : # if COMPILE_DEBUG
237 : # define CONF_COMPILE_INLINE 0
238 : # else
239 : # define CONF_COMPILE_INLINE 1
240 : # endif
241 : #endif
242 :
243 : #if defined(VSTR_AUTOCONF_HAVE_INLINE) && CONF_COMPILE_INLINE
244 :
245 : #if COMPILE_DEBUG
246 : # define CONF__ASSERT ASSERT
247 : #else
248 : # define CONF__ASSERT(x)
249 : #endif
250 :
251 : #define CONF__FALSE 0
252 : #define CONF__TRUE 1
253 :
254 : extern inline int conf_parse_token(const Conf_parse *conf, Conf_token *token)
255 3669488 : {
256 1834757 : CONF__ASSERT(conf && conf->sects && token);
257 1834757 : CONF__ASSERT(!conf->depth); /* finished lex */
258 1834757 : CONF__ASSERT(conf->state == CONF_PARSE_STATE_END); /* finished lex */
259 1834757 : CONF__ASSERT(token->depth_num <= CONF_PARSE_LIST_DEPTH_SZ);
260 :
261 3669488 : token->depth_nums[0] = conf->sects->num;
262 :
263 3669488 : if (token->num >= conf->sects->num)
264 4844 : return (CONF__FALSE);
265 3664644 : ++token->num;
266 :
267 7505172 : while (token->depth_nums[token->depth_num] < token->num)
268 : {
269 87945 : CONF__ASSERT(token->depth_num);
270 87945 : CONF__ASSERT(token->depth_nums[token->depth_num] == (token->num - 1));
271 175884 : --token->depth_num;
272 : }
273 :
274 3664644 : token->type = conf->types_ptr[token->num - 1];
275 4917029 : if ((token->type >= CONF_TOKEN_TYPE_QUOTE_D) &&
276 : (token->type <= CONF_TOKEN_TYPE_SYMBOL))
277 2504797 : token->u.node = VSTR_SECTS_NUM(conf->sects, token->num);
278 1628016 : else if ((token->type == CONF_TOKEN_TYPE_CLIST) ||
279 : (token->type == CONF_TOKEN_TYPE_SLIST))
280 : {
281 936338 : token->u.list_num = VSTR_SECTS_NUM(conf->sects, token->num)->len;
282 936338 : token->depth_nums[++token->depth_num] = token->num + token->u.list_num;
283 : }
284 : else
285 223509 : token->u.uval_num = VSTR_SECTS_NUM(conf->sects, token->num)->pos;
286 :
287 3664644 : return (CONF__TRUE);
288 : }
289 :
290 : extern inline int conf_parse_end_token(const Conf_parse *conf,
291 : Conf_token *token,
292 : unsigned int depth)
293 218280 : {
294 218280 : if (depth > token->depth_num)
295 0 : return (CONF__FALSE);
296 :
297 218280 : if (token->depth_nums[depth] >= token->num)
298 : {
299 218280 : token->num = token->depth_nums[depth] - 1;
300 218280 : token->depth_num = depth;
301 : }
302 :
303 218280 : return (conf_parse_token(conf, token));
304 : }
305 :
306 : extern inline int conf_parse_num_token(const Conf_parse *conf,
307 : Conf_token *token,
308 : unsigned int num)
309 1698466 : {
310 849233 : CONF__ASSERT(num);
311 :
312 1698466 : if (token->num == num)
313 : { /* refresh info... */
314 1463614 : token->type = conf->types_ptr[token->num - 1];
315 :
316 1463614 : if ((token->type >= CONF_TOKEN_TYPE_QUOTE_D) &&
317 : (token->type <= CONF_TOKEN_TYPE_SYMBOL))
318 : { }
319 1461854 : else if ((token->type == CONF_TOKEN_TYPE_CLIST) ||
320 : (token->type == CONF_TOKEN_TYPE_SLIST))
321 0 : token->u.list_num = VSTR_SECTS_NUM(conf->sects, token->num)->len;
322 : else
323 1461854 : token->u.uval_num = VSTR_SECTS_NUM(conf->sects, token->num)->pos;
324 :
325 1463614 : return (CONF__TRUE);
326 : }
327 :
328 234852 : if (token->num > num)
329 : {
330 16 : Conf_token tmp = CONF_TOKEN_INIT;
331 :
332 16 : *token = tmp;
333 : }
334 :
335 603818 : while (token->num < num)
336 : {
337 251540 : if (!conf_parse_token(conf, token))
338 0 : return (CONF__FALSE);
339 :
340 251540 : if (token->depth_num && /* try to skip to end of current list */
341 : (token->depth_nums[token->depth_num] <= num) &&
342 : !conf_parse_end_token(conf, token, token->depth_num))
343 0 : return (CONF__FALSE);
344 : }
345 :
346 234852 : return (CONF__TRUE);
347 : }
348 :
349 : extern inline unsigned int conf_token_at_depth(const Conf_token *token)
350 1215234 : {
351 1215234 : unsigned int depth = 0;
352 :
353 607633 : CONF__ASSERT(token);
354 :
355 1215234 : depth = token->depth_num;
356 1215234 : if ((token->type == CONF_TOKEN_TYPE_CLIST) ||
357 : (token->type == CONF_TOKEN_TYPE_SLIST))
358 77260 : --depth;
359 :
360 1215234 : return (depth);
361 : }
362 :
363 : extern inline const Vstr_sect_node *conf_token_value(const Conf_token *token)
364 11745549 : {
365 5872991 : CONF__ASSERT(token);
366 :
367 11745549 : if ((token->type >= CONF_TOKEN_TYPE_QUOTE_D) &&
368 : (token->type <= CONF_TOKEN_TYPE_SYMBOL))
369 11743633 : return (token->u.node);
370 :
371 1916 : return (NULL);
372 : }
373 :
374 : extern inline Vstr_ref *conf_token_get_user_value(const Conf_parse *conf,
375 : const Conf_token *token,
376 : unsigned int *nxt)
377 996730 : {
378 : unsigned int dummy;
379 :
380 498365 : CONF__ASSERT(conf && token);
381 :
382 996730 : if (!nxt) nxt = &dummy;
383 996730 : *nxt = 0;
384 :
385 996730 : if (token->type <= CONF_TOKEN_TYPE_SYMBOL)
386 0 : return (NULL);
387 :
388 996730 : if (token->u.uval_num >= conf->uvals_sz)
389 0 : return (NULL);
390 :
391 498365 : CONF__ASSERT(conf->uvals_sz);
392 :
393 996730 : *nxt = conf->uvals_ptr[token->u.uval_num].nxt;
394 996730 : if (!conf->uvals_ptr[token->u.uval_num].ref)
395 0 : return (NULL);
396 :
397 996730 : return (vstr_ref_add(conf->uvals_ptr[token->u.uval_num].ref));
398 : }
399 :
400 : extern inline int conf_token_cmp_val_eq(const Conf_parse *conf,
401 : const Conf_token *token,
402 : const Vstr_base *s1,
403 : size_t pos, size_t len)
404 577748 : {
405 577748 : const Vstr_sect_node *val = conf_token_value(token);
406 :
407 288874 : CONF__ASSERT(conf && token && conf->data && s1);
408 :
409 577748 : if (!val) return (CONF__FALSE);
410 :
411 577748 : return (vstr_cmp_eq(conf->data, val->pos, val->len, s1, pos, len));
412 : }
413 :
414 : extern inline int conf_token_cmp_val_buf_eq(const Conf_parse *conf,
415 : const Conf_token *token,
416 : const char *buf, size_t len)
417 10942143 : {
418 10942143 : const Vstr_sect_node *val = conf_token_value(token);
419 :
420 5471281 : CONF__ASSERT(conf && token && conf->data && buf);
421 :
422 10942143 : if (!val) return (CONF__FALSE);
423 :
424 10942143 : return (vstr_cmp_buf_eq(conf->data, val->pos, val->len, buf, len));
425 : }
426 :
427 : extern inline int conf_token_cmp_val_cstr_eq(const Conf_parse *conf,
428 : const Conf_token *token,
429 : const char *cstr)
430 10942143 : {
431 10942143 : return (conf_token_cmp_val_buf_eq(conf, token, cstr, strlen(cstr)));
432 : }
433 :
434 : extern inline int conf_token_cmp_val_beg_eq(const Conf_parse *conf,
435 : const Conf_token *token,
436 : const Vstr_base *s1,
437 : size_t pos, size_t len)
438 0 : {
439 0 : const Vstr_sect_node *val = conf_token_value(token);
440 :
441 0 : CONF__ASSERT(conf && token && conf->data && s1);
442 :
443 0 : if (!val) return (CONF__FALSE);
444 :
445 0 : if (len > val->len)
446 0 : len = val->len;
447 :
448 0 : return (vstr_cmp_eq(conf->data, val->pos, val->len, s1, pos, len));
449 : }
450 :
451 : extern inline int conf_token_cmp_case_val_eq(const Conf_parse *conf,
452 : const Conf_token *token,
453 : const Vstr_base *s1,
454 : size_t pos, size_t len)
455 14520 : {
456 14520 : const Vstr_sect_node *val = conf_token_value(token);
457 :
458 7260 : CONF__ASSERT(conf && token && conf->data && s1);
459 :
460 14520 : if (!val) return (CONF__FALSE);
461 :
462 14520 : return (vstr_cmp_case_eq(conf->data, val->pos, val->len, s1, pos, len));
463 : }
464 :
465 : extern inline int conf_token_cmp_case_val_cstr_eq(const Conf_parse *conf,
466 : const Conf_token *token,
467 : const char *cstr)
468 0 : {
469 0 : const Vstr_sect_node *val = conf_token_value(token);
470 :
471 0 : CONF__ASSERT(conf && token && conf->data && cstr);
472 :
473 0 : if (!val) return (CONF__FALSE);
474 :
475 0 : return (vstr_cmp_case_cstr_eq(conf->data, val->pos, val->len, cstr));
476 : }
477 :
478 : extern inline int conf_token_cmp_case_val_beg_eq(const Conf_parse *conf,
479 : const Conf_token *token,
480 : const Vstr_base *s1,
481 : size_t pos, size_t len)
482 192 : {
483 192 : const Vstr_sect_node *val = conf_token_value(token);
484 :
485 96 : CONF__ASSERT(conf && token && conf->data && s1);
486 :
487 192 : if (!val) return (CONF__FALSE);
488 :
489 192 : if (len > val->len)
490 128 : len = val->len;
491 :
492 192 : return (vstr_cmp_case_eq(conf->data, val->pos, val->len, s1, pos, len));
493 : }
494 :
495 : extern inline int conf_token_cmp_sym_eq(const Conf_parse *conf,
496 : const Conf_token *token,
497 : const Vstr_base *s1,
498 : size_t pos, size_t len)
499 0 : {
500 0 : CONF__ASSERT(token);
501 :
502 0 : if (token->type == CONF_TOKEN_TYPE_SYMBOL)
503 0 : return (conf_token_cmp_val_eq(conf, token, s1, pos, len));
504 0 : return (CONF__FALSE);
505 : }
506 :
507 : extern inline int conf_token_cmp_sym_buf_eq(const Conf_parse *conf,
508 : const Conf_token *token,
509 : const char *buf, size_t len)
510 0 : {
511 0 : CONF__ASSERT(token);
512 :
513 0 : if (token->type == CONF_TOKEN_TYPE_SYMBOL)
514 0 : return (conf_token_cmp_val_buf_eq(conf, token, buf, len));
515 0 : return (CONF__FALSE);
516 : }
517 :
518 : extern inline int conf_token_cmp_sym_cstr_eq(const Conf_parse *conf,
519 : const Conf_token *token,
520 : const char *cstr)
521 11046503 : {
522 5523511 : CONF__ASSERT(token);
523 :
524 11046503 : if (token->type == CONF_TOKEN_TYPE_SYMBOL)
525 10921131 : return (conf_token_cmp_val_cstr_eq(conf, token, cstr));
526 125372 : return (CONF__FALSE);
527 : }
528 :
529 : extern inline int conf_token_cmp_case_sym_cstr_eq(const Conf_parse *conf,
530 : const Conf_token *token,
531 : const char *cstr)
532 0 : {
533 0 : CONF__ASSERT(token);
534 :
535 0 : if (token->type == CONF_TOKEN_TYPE_SYMBOL)
536 0 : return (conf_token_cmp_case_val_cstr_eq(conf, token, cstr));
537 0 : return (CONF__FALSE);
538 : }
539 :
540 : extern inline int conf_token_srch_val(const Conf_parse *conf,
541 : const Conf_token *token,
542 : const Vstr_base *s1,
543 : size_t pos, size_t len)
544 128 : {
545 128 : const Vstr_sect_node *val = conf_token_value(token);
546 :
547 64 : CONF__ASSERT(conf && token && conf->data && s1);
548 :
549 128 : if (!val) return (CONF__FALSE);
550 :
551 128 : return (vstr_srch_vstr_fwd(s1, pos, len, conf->data, val->pos, val->len));
552 : }
553 :
554 : extern inline int conf_token_srch_case_val(const Conf_parse *conf,
555 : const Conf_token *token,
556 : const Vstr_base *s1,
557 : size_t pos, size_t len)
558 256 : {
559 256 : const Vstr_sect_node *val = conf_token_value(token);
560 :
561 128 : CONF__ASSERT(conf && token && conf->data && s1);
562 :
563 256 : if (!val) return (CONF__FALSE);
564 :
565 256 : return (vstr_srch_case_vstr_fwd(s1, pos, len,
566 : conf->data, val->pos, val->len));
567 : }
568 :
569 : extern inline unsigned int conf_token_list_num(const Conf_token *token,
570 : unsigned int depth)
571 3025652 : {
572 1512861 : CONF__ASSERT(token);
573 :
574 3025652 : if (depth > token->depth_num)
575 362 : return (CONF__FALSE);
576 :
577 1512683 : CONF__ASSERT(token->depth_nums[depth] >= token->num);
578 :
579 3025290 : return (token->depth_nums[depth] - token->num);
580 : }
581 :
582 : extern inline int conf_sc_token_parse_toggle(const Conf_parse *conf,
583 : Conf_token *token, int *val)
584 3330 : {
585 3330 : unsigned int num = conf_token_list_num(token, token->depth_num);
586 3330 : int ern = CONF_SC_TYPE_RET_OK;
587 :
588 1665 : CONF__ASSERT(val);
589 :
590 3330 : if (!num)
591 : {
592 1016 : *val = !*val;
593 1016 : return (ern);
594 : }
595 :
596 2314 : conf_parse_token(conf, token);
597 : if (0) { }
598 3752 : else if (conf_token_cmp_val_cstr_eq(conf, token, "on") ||
599 : conf_token_cmp_val_cstr_eq(conf, token, "true") ||
600 : conf_token_cmp_val_cstr_eq(conf, token, "yes") ||
601 : conf_token_cmp_val_cstr_eq(conf, token, "ON") ||
602 : conf_token_cmp_val_cstr_eq(conf, token, "TRUE") ||
603 : conf_token_cmp_val_cstr_eq(conf, token, "YES") ||
604 : conf_token_cmp_val_cstr_eq(conf, token, "1"))
605 1438 : *val = CONF__TRUE;
606 1752 : else if (conf_token_cmp_val_cstr_eq(conf, token, "off") ||
607 : conf_token_cmp_val_cstr_eq(conf, token, "false") ||
608 : conf_token_cmp_val_cstr_eq(conf, token, "no") ||
609 : conf_token_cmp_val_cstr_eq(conf, token, "OFF") ||
610 : conf_token_cmp_val_cstr_eq(conf, token, "FALSE") ||
611 : conf_token_cmp_val_cstr_eq(conf, token, "NO") ||
612 : conf_token_cmp_val_cstr_eq(conf, token, "0"))
613 876 : *val = CONF__FALSE;
614 : else
615 0 : ern = CONF_SC_TYPE_RET_ERR_NO_MATCH;
616 :
617 2314 : return (ern);
618 : }
619 :
620 : extern inline int conf_sc_token_parse_eq(const Conf_parse *conf,
621 : Conf_token *token,
622 : const Vstr_base *s1,
623 : size_t pos, size_t len,
624 : int *matches)
625 577140 : {
626 577140 : unsigned int num = conf_token_list_num(token, token->depth_num);
627 :
628 288570 : CONF__ASSERT(matches);
629 :
630 577140 : if (!num)
631 0 : return (CONF_SC_TYPE_RET_ERR_PARSE);
632 :
633 577140 : conf_parse_token(conf, token);
634 :
635 577140 : *matches = conf_token_cmp_val_eq(conf, token, s1, pos, len);
636 :
637 577140 : return (CONF_SC_TYPE_RET_OK);
638 : }
639 :
640 : extern inline int conf_sc_token_parse_cstr_eq(const Conf_parse *conf,
641 : Conf_token *token,
642 : const char *s1, int *matches)
643 128 : {
644 128 : unsigned int num = conf_token_list_num(token, token->depth_num);
645 :
646 64 : CONF__ASSERT(matches);
647 :
648 128 : if (!num)
649 0 : return (CONF_SC_TYPE_RET_ERR_PARSE);
650 :
651 128 : conf_parse_token(conf, token);
652 :
653 128 : *matches = conf_token_cmp_val_cstr_eq(conf, token, s1);
654 :
655 128 : return (CONF_SC_TYPE_RET_OK);
656 : }
657 :
658 : #endif
659 :
660 : #endif
|