diff options
author | Ondrej Zajicek <santiago@crfreenet.org> | 2013-07-25 22:33:57 +0200 |
---|---|---|
committer | Ondrej Zajicek <santiago@crfreenet.org> | 2013-07-25 22:33:57 +0200 |
commit | 1103b32e830fbf98d9b3e32c0425b9a589773bf8 (patch) | |
tree | 9d3577cf205e74002ea43e7754f3391cc1e4992d /conf/confbase.Y | |
parent | ac5745134847c044b21c311e5ab11d92d05bacc1 (diff) |
Allows to define constants of all filter types.
Diffstat (limited to 'conf/confbase.Y')
-rw-r--r-- | conf/confbase.Y | 31 |
1 files changed, 16 insertions, 15 deletions
diff --git a/conf/confbase.Y b/conf/confbase.Y index dcb0719f..c6678e77 100644 --- a/conf/confbase.Y +++ b/conf/confbase.Y @@ -103,28 +103,29 @@ conf_entries: CF_ADDTO(conf, ';') + /* Constant expressions */ +CF_ADDTO(conf, definition) +definition: + DEFINE SYM '=' term ';' { + struct f_val *val = cfg_alloc(sizeof(struct f_val)); + *val = f_eval($4, cfg_mem); + if (val->type == T_RETURN) cf_error("Runtime error"); + cf_define_symbol($2, SYM_CONSTANT | val->type, val); + } + ; + expr: NUM | '(' term ')' { $$ = f_eval_int($2); } - | SYM { if ($1->class != SYM_NUMBER) cf_error("Number expected"); else $$ = $1->aux; } + | SYM { + if ($1->class != (SYM_CONSTANT | T_INT)) cf_error("Number expected"); + $$ = SYM_VAL($1).i; } ; /* expr_u16: expr { check_u16($1); $$ = $1; }; */ -CF_ADDTO(conf, definition) -definition: - DEFINE SYM '=' expr ';' { - cf_define_symbol($2, SYM_NUMBER, NULL); - $2->aux = $4; - } - | DEFINE SYM '=' IPA ';' { - cf_define_symbol($2, SYM_IPA, cfg_alloc(sizeof(ip_addr))); - *(ip_addr *)$2->def = $4; - } - ; - /* Switches */ bool: @@ -141,8 +142,8 @@ bool: ipa: IPA | SYM { - if ($1->class != SYM_IPA) cf_error("IP address expected"); - $$ = *(ip_addr *)$1->def; + if ($1->class != (SYM_CONSTANT | T_IP)) cf_error("IP address expected"); + $$ = SYM_VAL($1).px.ip; } ; |