Fixed order of arguments for function call.

Enumeration types should work once CF_ENUM() is ready.

Created test.conf for testing of filters. (I'm currently thinking
about ./tests in root directory which will just fire all available
tests...)
This commit is contained in:
Pavel Machek 1999-11-11 13:55:39 +00:00
parent 4ed8718a19
commit 4515bdba4f
2 changed files with 90 additions and 27 deletions

View file

@ -8,7 +8,6 @@
FIXME (nonurgent): define keyword
FIXME: whole system of paths, path ~ string, path.prepend(), path.originate
FIXME: create community lists
FIXME: enumerational types
FIXME: write access to dynamic attributes.
*/
@ -41,9 +40,9 @@ CF_KEYWORDS(FUNCTION, PRINT, PRINTN, CONST,
%nonassoc THEN
%nonassoc ELSE
%type <x> term block cmds cmd function_body constant print_one print_list var_list var_listn any_dynamic enums
%type <x> term block cmds cmd function_body constant print_one print_list var_list var_listn any_dynamic
%type <f> filter filter_body
%type <i> type break_command pair enum_rts
%type <i> type break_command pair
%type <e> set_item set_items switch_body
%type <v> set_atom prefix prefix_s ipa
%type <s> decls declsn one_decl function_params
@ -103,8 +102,8 @@ decls: /* EMPTY */ { $$ = NULL; }
/* Declarations that have no ';' at the end. */
declsn: one_decl { $$ = $1; }
| declsn ';' one_decl {
$$ = $3;
$$->aux = (int) $1;
$$ = $1;
$$->aux = (int) $3;
}
;
@ -229,27 +228,6 @@ switch_body: /* EMPTY */ { $$ = NULL; }
}
;
enum_rts:
RTSDUMMY { $$ = 0; }
| RTSSTATIC { $$ = 1; }
| RTSINHERIT { $$ = 2; }
| RTSDEVICE { $$ = 3; }
| RTSSTATIC_DEVICE { $$ = 4; }
| RTSREDIRECT { $$ = 5; }
| RTSRIP { $$ = 6; }
| RTSRIP_EXT { $$ = 7; }
| RTSOSPF { $$ = 8; }
| RTSOSPF_EXT { $$ = 9; }
| RTSOSPF_IA { $$ = 10; }
| RTSOSPF_BOUNDARY { $$ = 11; }
| RTSBGP { $$ = 12; }
| RTSPIPE { $$ = 13; }
;
enums:
enum_rts { $$ = f_new_inst(); $$->code = 'c'; $$->a1.i = T_ENUM_RTS; $$->a2.i = $1; }
;
constant:
CONST '(' expr ')' { $$ = f_new_inst(); $$->code = 'c'; $$->a1.i = T_INT; $$->a2.i = $3; }
| NUM { $$ = f_new_inst(); $$->code = 'c'; $$->a1.i = T_INT; $$->a2.i = $1; }
@ -260,7 +238,6 @@ constant:
| ipa { NEW_F_VAL; $$ = f_new_inst(); $$->code = 'C'; $$->a1.p = val; *val = $1; }
| prefix_s {NEW_F_VAL; $$ = f_new_inst(); $$->code = 'C'; $$->a1.p = val; *val = $1; }
| '[' set_items ']' { printf( "We've got a set here..." ); $$ = f_new_inst(); $$->code = 'c'; $$->a1.i = T_SET; $$->a2.p = build_tree($2); printf( "ook\n" ); }
| enums { $$ = $1; }
;
any_dynamic:
@ -285,6 +262,13 @@ term:
| SYM {
$$ = f_new_inst();
switch ($1->class) {
case 0: /* This should better be an enum */
$$->code = 'c';
$$->a1.i = $1->aux;
if (($$->a1.i < T_ENUM_LO) || ($$->a1.i > T_ENUM_HI))
cf_error("You used symbol and it was not enum.\n");
$$->a2.i = (int) $1->aux2;
break;
case SYM_VARIABLE | T_INT:
case SYM_VARIABLE | T_PAIR:
case SYM_VARIABLE | T_PREFIX:
@ -296,6 +280,7 @@ term:
cf_error("Can not use this class of symbol (%s,%x) as variable.", $1->name, $1->class );
}
}
| RTA '.' FROM { $$ = f_new_inst(); $$->code = 'a'; $$->a1.i = T_IP; $$->a2.i = OFFSETOF(struct rta, from); }
| RTA '.' GW { $$ = f_new_inst(); $$->code = 'a'; $$->a1.i = T_IP; $$->a2.i = OFFSETOF(struct rta, gw); }

78
filter/test.conf Normal file
View file

@ -0,0 +1,78 @@
/*
* This is an example configuration file.
*/
# Yet another comment
router id 62.168.0.1;
define xyzzy = 120+10;
function callme ( int arg1; int arg2 )
int local1;
int local2;
int i;
{
print "Ok";
print "Function callme called arguments " arg1 " and " arg2;
i = arg2;
case arg1 {
2: print "dva"; print "jeste jednou dva";
3 .. 5: print "tri az pet";
else: print "neco jineho";
}
}
function startup ()
int i;
prefix px;
ip p;
{
print "Testing filter language:";
i = 4;
i = 1230 + i;
i = ( i + 0 );
print " arithmetics: 1234 = " i;
printn " if statements ";
if i = 4 then { print "*** FAIL: if 0"; quitbird; } else printn ".";
if 1234 = i then printn "."; else { print "*** FAIL: if 1 else"; }
if 1 <= 1 then printn "."; else { print "*** FAIL: test 3"; }
if 1234 < 1234 then { print "*** FAIL: test 4"; quitbird; } else print "ok";
print " data types; must be true: " 1.2.3.4 = 1.2.3.4 "," 1 ~ [1,2,3] "," 5 ~ [1..20] "," 2 ~ [ 1, 2, 3 ] "," 5 ~ [ 4 .. 7 ] "," 1.2.3.4 ~ [ 1.2.3.3..1.2.3.5 ] "," 1.2.3.4 ~ 1.2.3.4/8 "," 1.2.3.4/8 ~ 1.2.3.4/8 "," 1.2.3.4/8 ~ [ 1.2.3.4/8+ ] "," 1.2.3.4/16 ~ [ 1.2.3.4/8{ 15 , 16 } ] "," defined(1) "," defined(1.2.3.4);
print " data types: must be false: " 1 ~ [ 2, 3, 4 ] "," 5 ~ [ 2, 3, 4, 7..11 ] "," 1.2.3.4 ~ [ 1.2.3.3, 1.2.3.5 ] "," (1,2) > (2,2) "," (1,1) > (1,1) "," 1.2.3.4/8 ~ [ 1.2.3.4/8- ] "," 1.2.3.4/17 ~ [ 1.2.3.4/8{ 15 , 16 } ];
px = 1.2.3.4/18;
print "Testing prefixes: 1.2.3.4/18 = " px;
p = 127.1.2.3;
print "Testing mask : 127.0.0.0 = " p.mask(8);
print "Testing pairs: (1,2) = " (1,2);
#
print "What will this do? " [ 1, 2, 1, 1, 1, 3, 4, 1, 1, 1, 5 ];
print "Testing functions...";
# callme ( 1, 2 );
callme ( 2, 2 );
callme ( 2, 2 );
callme ( 3, 2 );
callme ( 4, 2 );
callme ( 7, 2 );
print "done";
quitbird;
# print "*** FAIL: this is unreachable";
}
filter testf
int j;
{
print "Heya, filtering route to " rta.net.ip " prefixlen " rta.net.len;
print "This route was from " rta.from;
j = 7;
j = 17;
if rta.rip_metric > 15 then
print "RIP Metric is more than infinity";
accept;
}