Filters, second try. This time they have their own directory.
This commit is contained in:
parent
b79f9215b9
commit
b9d70dc84e
7 changed files with 197 additions and 4 deletions
|
@ -1,10 +1,10 @@
|
|||
source=cf-parse.tab.c cf-lex.c f-util.c
|
||||
source=cf-parse.tab.c cf-lex.c
|
||||
root-rel=../
|
||||
|
||||
include ../Rules
|
||||
|
||||
conf-src=$(srcdir)/conf
|
||||
conf-fragments=$(conf-src)/confbase.Y @CONFS@ $(addsuffix /config.Y,$(static-dir-paths)) $(conf-src)/filter.Y
|
||||
conf-fragments=$(conf-src)/confbase.Y @CONFS@ $(addsuffix /config.Y,$(static-dir-paths))
|
||||
|
||||
ifdef DEBUG
|
||||
BISON_DEBUG=-t
|
||||
|
|
|
@ -16,7 +16,7 @@ CF_HDR
|
|||
#include "nest/protocol.h"
|
||||
#include "nest/iface.h"
|
||||
#include "nest/route.h"
|
||||
#include "conf/filter.h"
|
||||
#include "filter/filter.h"
|
||||
|
||||
CF_DECLS
|
||||
|
||||
|
|
5
filter/Makefile
Normal file
5
filter/Makefile
Normal file
|
@ -0,0 +1,5 @@
|
|||
source=f-util.c
|
||||
root-rel=../
|
||||
dir-name=filter
|
||||
|
||||
include ../Rules
|
100
filter/config.Y
Normal file
100
filter/config.Y
Normal file
|
@ -0,0 +1,100 @@
|
|||
/*
|
||||
* BIRD - filters
|
||||
*
|
||||
* Copyright 1998 Pavel Machek
|
||||
*
|
||||
* Can be freely distributed and used under the terms of the GNU GPL.
|
||||
*/
|
||||
|
||||
CF_HDR
|
||||
|
||||
#include "nest/bird.h"
|
||||
#include "filter/filter.h"
|
||||
#include "lib/resource.h"
|
||||
#include "lib/socket.h"
|
||||
#include "lib/timer.h"
|
||||
#include "nest/protocol.h"
|
||||
#include "nest/iface.h"
|
||||
#include "nest/route.h"
|
||||
|
||||
CF_DECLS
|
||||
|
||||
CF_KEYWORDS(FUNCTION, FILTER, PRINTDEBUG, INT, PRINT)
|
||||
|
||||
%type <x> expr
|
||||
|
||||
CF_GRAMMAR
|
||||
|
||||
config:
|
||||
program {
|
||||
printf( "Wow, we have full program\n" );
|
||||
return 0;
|
||||
}
|
||||
;
|
||||
|
||||
program: /* EMPTY */
|
||||
| program function
|
||||
;
|
||||
|
||||
CF_ADDTO(conf, function)
|
||||
function:
|
||||
FUNCTION SYM '(' ')' '{' expr '}' {
|
||||
extern struct f_instruction *last_func;
|
||||
if ($2->class != SYM_VOID) cf_error("Symbol already defined" );
|
||||
$2->class = SYM_FUNCTION;
|
||||
$2->aux = $6;
|
||||
last_func = $6;
|
||||
printf("Hmm, we've got one function here\n");
|
||||
}
|
||||
;
|
||||
|
||||
CF_ADDTO(conf, filter)
|
||||
filter:
|
||||
FILTER SYM '{' expr '}' {
|
||||
if ($2->class != SYM_VOID) cf_error("Symbol already defined" );
|
||||
$2->class = SYM_FILTER;
|
||||
$2->aux = $4;
|
||||
printf( "We have new filter defined (%s)\n", $2->name )
|
||||
}
|
||||
;
|
||||
|
||||
/* Programs */
|
||||
|
||||
expr: /* EMPTY */ { $$ = NULL; }
|
||||
| expr ';' expr {
|
||||
$$ = cfg_alloc(sizeof(struct f_instruction));
|
||||
printf( "We've got statement here\n" );
|
||||
$$->code = ',';
|
||||
$$->arg1 = $1;
|
||||
$$->arg2 = $3;
|
||||
}
|
||||
| INT SYM ';' {
|
||||
if ($2->class != SYM_VOID) cf_error("Symbol already defined, can not use as variable\n" );
|
||||
$2->class = SYM_VARIABLE_INT;
|
||||
printf( "New variable\n" );
|
||||
$$ = NULL;
|
||||
}
|
||||
| SYM '=' cexpr {
|
||||
$$ = cfg_alloc(sizeof(struct f_instruction));
|
||||
printf( "Ook, we'll set value\n" );
|
||||
if ($1->class != SYM_VARIABLE_INT)
|
||||
cf_error( "You may only set variables\n" );
|
||||
$$->code = '=';
|
||||
$$->arg1 = $1;
|
||||
$$->arg2 = $3;
|
||||
}
|
||||
| PRINT '(' SYM ')' {
|
||||
$$ = cfg_alloc(sizeof(struct f_instruction));
|
||||
printf( "Ook, we'll print something\n" );
|
||||
$$->code = 'p';
|
||||
$$->arg1 = $3;
|
||||
$$->arg2 = NULL;
|
||||
}
|
||||
| PRINTDEBUG {
|
||||
$$ = cfg_alloc(sizeof(struct f_instruction));
|
||||
$$->code = 'D';
|
||||
$$->arg1 = $$->arg2 = NULL;
|
||||
}
|
||||
;
|
||||
|
||||
CF_END
|
67
filter/f-util.c
Normal file
67
filter/f-util.c
Normal file
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
* Filters: utility functions
|
||||
*
|
||||
* Copyright 1998 Pavel Machek <pavel@ucw.cz>
|
||||
*
|
||||
* Can be freely distributed and used under the terms of the GNU GPL.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/signal.h>
|
||||
|
||||
#include "nest/bird.h"
|
||||
#include "lib/lists.h"
|
||||
#include "lib/resource.h"
|
||||
#include "lib/socket.h"
|
||||
#include "nest/route.h"
|
||||
#include "nest/protocol.h"
|
||||
#include "nest/iface.h"
|
||||
#include "conf/conf.h"
|
||||
#include "filter/filter.h"
|
||||
|
||||
struct f_instruction *last_func = NULL;
|
||||
|
||||
static void
|
||||
interpret(struct f_instruction *what)
|
||||
{
|
||||
struct symbol *sym;
|
||||
if (!what)
|
||||
return 0;
|
||||
switch(what->code) {
|
||||
case ',':
|
||||
interpret(what->arg1);
|
||||
interpret(what->arg2);
|
||||
break;
|
||||
case '=':
|
||||
sym = what->arg1;
|
||||
sym->aux = what->arg2;
|
||||
break;
|
||||
case 'p':
|
||||
sym = what->arg1;
|
||||
switch(sym->class) {
|
||||
case SYM_VARIABLE_INT:
|
||||
printf( "Printing: %d\n", sym->aux );
|
||||
break;
|
||||
default:
|
||||
printf( "Unknown type passed to print\n" );
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 'D':
|
||||
printf( "DEBUGGING PRINT\n" );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
filters_init(void)
|
||||
{
|
||||
if (!last_func)
|
||||
printf( "No function defined\n" );
|
||||
else {
|
||||
interpret(last_func);
|
||||
}
|
||||
}
|
||||
|
21
filter/filter.h
Normal file
21
filter/filter.h
Normal file
|
@ -0,0 +1,21 @@
|
|||
/*
|
||||
* BIRD Internet Routing Daemon -- Configuration File Handling
|
||||
*
|
||||
* (c) 1998 Martin Mares <mj@ucw.cz>
|
||||
*
|
||||
* Can be freely distributed and used under the terms of the GNU GPL.
|
||||
*/
|
||||
|
||||
#ifndef _BIRD_FILT_H_
|
||||
#define _BIRD_FILT_H_
|
||||
|
||||
#include "lib/resource.h"
|
||||
|
||||
/* Lexer */
|
||||
|
||||
struct f_instruction {
|
||||
int code;
|
||||
void *arg1, *arg2;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -19,7 +19,7 @@
|
|||
#include "nest/protocol.h"
|
||||
#include "nest/iface.h"
|
||||
#include "conf/conf.h"
|
||||
#include "conf/filter.h"
|
||||
#include "filter/filter.h"
|
||||
|
||||
#include "unix.h"
|
||||
#include "krt.h"
|
||||
|
|
Loading…
Reference in a new issue