From: <al...@us...> - 2003-02-25 00:01:34
|
Update of /cvsroot/msyslog/msyslog-event/src/config In directory sc8-pr-cvs1:/tmp/cvs-serv16904/config Modified Files: config.y Log Message: change parser not to use multiple modules in blocks simplify it a bit while there some event work too (yeah, multiple changes shouldn't be committed together, d'oh) Index: config.y =================================================================== RCS file: /cvsroot/msyslog/msyslog-event/src/config/config.y,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- config.y 23 Feb 2003 22:19:23 -0000 1.1.1.1 +++ config.y 25 Feb 2003 00:01:31 -0000 1.2 @@ -31,35 +31,31 @@ #define BUILD_NUM_OP(x,y) ((2 << 24) | ((x & 0xff) << 16) | (y & 0xff)) #define BUILD_STR_OP(x,y) ((3 << 24) | ((x & 0xff) << 16) | (y & 0xff)) -char *name; /* save an option, filter or module block name */ +char *name; /* save an option, filter or module name */ extern char *yytext; extern int lineno; /* Elements are pushed, since there is no need of order here */ struct p_option *Options; -struct p_input_block *Input_Blocks; -struct p_filter_block *Filter_Blocks; -struct p_noninput_block *Noninput_Blocks; +struct p_input *Inputs; +struct p_filter *Filters; +struct p_ninput *Noninputs; struct p_path *Paths; %} %union { char *string; - struct p_args args; + struct p_args args; /* used for matched module */ struct { int filargc; /* filters count */ char *filargv[MAX_ARGVS]; /* filter names */ - int targc; /* true noninputs count */ - char *targv[MAX_ARGVS]; /* true noninputs names */ - int fargc; /* false noninputs count */ - char *fargv[MAX_ARGVS]; /* false noninputs names */ + int targc; /* true ninputs count */ + char *targv[MAX_ARGVS]; /* true ninputs names */ + int fargc; /* false ninputs count */ + char *fargv[MAX_ARGVS]; /* false ninputs names */ } path; - struct { - int mcount; - struct p_args modules[MAX_INPUTS_PER_BLOCK + 1]; - } modules; /* used for matched blocks */ struct p_stack stack; int integer; } @@ -79,9 +75,8 @@ %type <integer> comp strfield numfield %type <integer> priority facility integer_value -%type <path> path_second_part path_noninputs +%type <path> path_second_part path_ninputs %type <args> names -%type <modules> args %type <stack> expression evaluation %left OPOR OPAND @@ -97,9 +92,9 @@ ; line: option - | noninput_block - | input_block - | filter_block + | ninput + | input + | filter | path ; @@ -107,117 +102,67 @@ struct p_option *pob; if ((pob = (struct p_option *) - malloc(sizeof(struct p_option))) == NULL) { + calloc(1, sizeof(struct p_option))) == NULL) { /* do some error reporting */ } - if (Options == NULL) { - pob->next = NULL; - } else { - pob->next = Options; - } + + pob->next = Options; Options = pob; pob->name = $2; - pob->args.argc = $4.argc; - if (sizeof(pob->args.argv) < (($4.argc * sizeof(char *)) - 1)) { - /* do some error reporting */ - /* and free all stuff duped! */ - } - memcpy(pob->args.argv, $4.argv, pob->args.argc * sizeof(char *)); + memcpy(&pob->args, &$4, sizeof(pob->args)); pob->args.argv[pob->args.argc] = NULL; } ; -noninput_block: NONINPUT WORD ':' args { - struct p_noninput_block *nib; +ninput: NONINPUT WORD ':' ARGV { + struct p_ninput *nm; - if ((nib = (struct p_noninput_block *) - malloc(sizeof(struct p_noninput_block))) == NULL) { + if ((nm = (struct p_ninput *) + calloc(1, sizeof(struct p_ninput))) == NULL) { /* some error stuff */ } /* add this block */ - if (Noninput_Blocks == NULL) { - nib->next = NULL; - } else { - nib->next = Noninput_Blocks; - } - Noninput_Blocks = nib; - if (sizeof(nib->modules) < ($4.mcount * sizeof($4.modules[0]))) { - /* do some error reporting */ - /* and free all stuff duped! */ - } - memcpy(nib->modules, $4.modules, $4.mcount - * sizeof($4.modules[0])); - nib->name = $2; - nib->mcount = $4.mcount; + nm->next = Noninputs; + Noninputs = nm; + memcpy(&nm->module, &$4, sizeof(nm->module)); + nm->name = $2; } ; -input_block: INPUT WORD ':' args { - struct p_input_block *ib; +input: INPUT WORD ':' ARGV { + struct p_input *im; - if ((ib = (struct p_input_block *) - malloc(sizeof(struct p_input_block))) == NULL) { + if ((im = (struct p_input *) + calloc(1, sizeof(struct p_input))) == NULL) { /* some error stuff */ } /* add this block */ - if (Input_Blocks == NULL) { - ib->next = NULL; - } else { - ib->next = Input_Blocks; - } - Input_Blocks = ib; - if (sizeof(ib->modules) < ($4.mcount * sizeof($4.modules[0]))) { - /* do some error reporting */ - /* and free all stuff duped! */ - } - memcpy(ib->modules, $4.modules, $4.mcount - * sizeof($4.modules[0])); - ib->name = $2; - ib->mcount = $4.mcount; + im->next = Inputs; + Inputs = im; + memcpy(&im->module, &$4, sizeof(im->module)); + im->name = $2; } ; -args: args ARGV { - if (sizeof($$) < (sizeof($1) + sizeof($$.modules[0]))) { - /* do some error reporting */ - /* and free all stuff duped! */ - } - memcpy(&$$, &$1, sizeof($1)); - memcpy(&$$.modules[$$.mcount++], &$2, sizeof($2)); - } - | ARGV { - $$.mcount = 1; - if (sizeof($$.modules[0]) < sizeof($1)) { - /* do some error reporting */ - /* and free all stuff duped! */ - } - memcpy(&$$.modules[0], &$1, sizeof($1)); - } - ; - -filter_block: FILTER WORD ':' expression { - struct p_filter_block *fb; +filter: FILTER WORD ':' expression { + struct p_filter *fb; - if ((fb = (struct p_filter_block *) - malloc(sizeof(struct p_filter_block))) == NULL) { + if ((fb = (struct p_filter *) + calloc(1, sizeof(struct p_filter))) == NULL) { /* some error stuff */ } /* add this block */ - if (Filter_Blocks == NULL) { - fb->next = NULL; - } else { - fb->next = Filter_Blocks; - } - Filter_Blocks = fb; - fb->name = $2; + fb->next = Filters; + Filters = fb; /* size of stack */ memcpy(&fb->stack, &$4, sizeof(fb->stack)); + fb->name = $2; } ; @@ -393,7 +338,7 @@ | LOCAL7 { $$ = LOG_LOCAL7; } ; -path_noninputs: names ',' names { +path_ninputs: names ',' names { if ((sizeof($$.targv) < ($1.argc * sizeof(char *)) - 1) || (sizeof($$.fargv) < ($3.argc * sizeof(char *)) - 1)) { /* some error stuff */ @@ -414,7 +359,7 @@ } ; -path_second_part: names ':' path_noninputs { +path_second_part: names ':' path_ninputs { $$.filargc = $1.argc; memcpy(&$$.fargv, $3.filargv, sizeof($3.filargv)); $$.targc = $3.targc; @@ -422,7 +367,7 @@ $$.fargc = $3.fargc; memcpy(&$$.fargv, $3.fargv, sizeof($3.fargv)); } - | path_noninputs { + | path_ninputs { $$.targc = $1.targc; memcpy(&$$.targv, $1.targv, sizeof($1.targc)); $$.fargc = $1.fargc; @@ -432,13 +377,13 @@ path: PATH names ':' path_second_part { struct p_path *pb; - struct p_input_block *inp; - struct p_filter_block *filt; - struct p_noninput_block *ninp; + struct p_input *inp; + struct p_filter *filt; + struct p_ninput *ninp; int i; if ((pb = (struct p_path *) - malloc(sizeof(struct p_path))) == NULL) { + calloc(1, sizeof(struct p_path))) == NULL) { /* some error stuff */ } @@ -452,7 +397,7 @@ /* link inputs to this path */ for (i = 0; i < $2.argc; i++) { - for (inp = Input_Blocks; inp && inp->name + for (inp = Inputs; inp && inp->name && strcmp(inp->name, $2.argv[i]) != 0; inp = inp->next) ; @@ -468,7 +413,7 @@ /* link filters from this path */ for (i = 0; i < $4.filargc; i++) { - for (filt = Filter_Blocks; filt && filt->name + for (filt = Filters; filt && filt->name && strcmp(filt->name, $4.fargv[i]) != 0; filt = filt->next) ; @@ -482,9 +427,9 @@ } } - /* link true noninputs from this path */ + /* link true ninputs from this path */ for (i = 0; i < $4.targc; i++) { - for (ninp = Noninput_Blocks; ninp && ninp->name + for (ninp = Noninputs; ninp && ninp->name && strcmp(ninp->name, $4.targv[i]) != 0; ninp = ninp->next) ; @@ -497,9 +442,9 @@ return (-1); } } - /* link false noninputs from this path */ + /* link false ninputs from this path */ for (i = 0; i < $4.targc; i++) { - for (ninp = Noninput_Blocks; ninp && ninp->name + for (ninp = Noninputs; ninp && ninp->name && strcmp(ninp->name, $4.fargv[i]) != 0; ninp = ninp->next) ; @@ -533,14 +478,13 @@ int yyparse(void); int -process_config(struct p_option **pOptions, struct p_input_block **pInput_Blocks, - struct p_filter_block **pFilter_Blocks, - struct p_noninput_block **pNoninput_Blocks, struct p_path **pPaths, - FILE *Config) +process_config(struct p_option **pOptions, struct p_input **pInputs, + struct p_filter **pFilters, struct p_ninput **pNoninputs, + struct p_path **pPaths, FILE *Config) { - if (Config == NULL || pOptions == NULL || pInput_Blocks == NULL - || pFilter_Blocks == NULL || pNoninput_Blocks == NULL + if (Config == NULL || pOptions == NULL || pInputs == NULL + || pFilters == NULL || pNoninputs == NULL || pPaths == NULL) return (-1); @@ -552,9 +496,9 @@ } while (parse_error[0] == '\0' && !feof(Config)); *pOptions = Options; - *pInput_Blocks = Input_Blocks; - *pFilter_Blocks = Filter_Blocks; - *pNoninput_Blocks = Noninput_Blocks; + *pInputs = Inputs; + *pFilters = Filters; + *pNoninputs = Noninputs; *pPaths = Paths; return (1); |