Thread: [Sysfence-commit] sysfence/parseopt confread.c,1.4,1.5 confread.h,1.2,1.3 parse.c,1.12,1.13
Status: Alpha
Brought to you by:
emes
|
From: Michal S. <em...@us...> - 2004-05-23 20:52:38
|
Update of /cvsroot/sysfence/sysfence/parseopt In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14456/parseopt Modified Files: confread.c confread.h parse.c Log Message: * general redesign: moving to new, extensible data structures stat values logging is temporarily disabled Index: confread.c =================================================================== RCS file: /cvsroot/sysfence/sysfence/parseopt/confread.c,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- confread.c 26 Feb 2004 14:10:14 -0000 1.4 +++ confread.c 23 May 2004 20:52:23 -0000 1.5 @@ -17,6 +17,7 @@ #include "../exit.h" #include "../xalloc.h" #include "lex.h" +#include "../datastruct.h" #include "../getstats.h" #include "../conditions.h" #include "parse.h" @@ -84,13 +85,13 @@ return res; } -ruleset ** read_config_files (int argc, char *argv[]) +sf_rule ** read_config_files (int argc, char *argv[]) { int i = 0, setsize = RULESETS, setpos = 0; - ruleset **set = (ruleset **) - xalloc (NULL, setsize * sizeof (ruleset *)); + sf_rule **set = (sf_rule **) + xalloc (NULL, setsize * sizeof (sf_rule *)); parserdata *rule; tokdata *stok, *tok; @@ -103,12 +104,12 @@ rule = get_ruleset (tok); if (rule == NULL) break; tok = rule->ptr; - *(set + setpos) = (ruleset *) rule->parsed; + *(set + setpos) = (sf_rule *) rule->parsed; setpos ++; if (setpos == setsize - 1) { /* if we're running out of buffer, resize it */ setsize += RULESETS; - set = (ruleset **) xalloc (set, setsize * sizeof (ruleset *)); + set = (sf_rule **) xalloc (set, setsize * sizeof (sf_rule *)); } } Index: confread.h =================================================================== RCS file: /cvsroot/sysfence/sysfence/parseopt/confread.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- confread.h 8 Feb 2004 17:40:16 -0000 1.2 +++ confread.h 23 May 2004 20:52:23 -0000 1.3 @@ -18,6 +18,6 @@ char * readfile (char *fname); tokdata * tokenized_conf (char *fname); -ruleset ** read_config_files (int argc, char *argv[]); +sf_rule ** read_config_files (int argc, char *argv[]); /* $Id$ */ Index: parse.c =================================================================== RCS file: /cvsroot/sysfence/sysfence/parseopt/parse.c,v retrieving revision 1.12 retrieving revision 1.13 diff -u -d -r1.12 -r1.13 --- parse.c 20 May 2004 15:57:09 -0000 1.12 +++ parse.c 23 May 2004 20:52:23 -0000 1.13 @@ -17,6 +17,7 @@ #include "lex.h" #include "../exit.h" #include "../xalloc.h" +#include "../datastruct.h" #include "../getstats.h" #include "../conditions.h" #include "parse.h" @@ -55,6 +56,7 @@ bail_out (EXIT_PARSE, buf); } +#if 0 void collect_stats (expression *ex, int *tab) { if (ex->type == ATOMIC) { @@ -64,6 +66,7 @@ collect_stats ((expression *) ex->arg2, tab); } } +#endif parserdata * get_logdata (tokdata *tok) { @@ -73,7 +76,7 @@ * */ parserdata *res; - logdata *log; /* helper */ + sf_logdata *log; /* helper */ if (tok->type != KW_LOG) return NULL; @@ -81,8 +84,8 @@ /* that's log data. initialize structures */ res = (parserdata *) xalloc (NULL, sizeof (parserdata)); - res->parsed = xalloc (NULL, sizeof ( logdata)); - log = (logdata *) res->parsed; + res->parsed = xalloc (NULL, sizeof (sf_logdata)); + log = (sf_logdata *) res->parsed; if (tok->type == KW_ONCE) { log->once = 1; tok ++; @@ -103,7 +106,7 @@ const char *thisfuncname = "get_rundata()"; #endif parserdata *res; - rundata *run; /* helper */ + sf_rundata *run; /* helper */ if (tok->type != KW_RUN) return NULL; @@ -111,8 +114,8 @@ /* that's run data. initialize structures */ res = (parserdata *) xalloc (NULL, sizeof (parserdata)); - res->parsed = xalloc (NULL, sizeof (rundata)); - run = (rundata *) res->parsed; + res->parsed = xalloc (NULL, sizeof (sf_rundata)); + run = (sf_rundata *) res->parsed; if (tok->type == KW_ONCE) { run->once = 1; tok ++; @@ -124,7 +127,7 @@ #else parse_error (tok); #endif - run->runcmd = tok->val; + run->command = tok->val; tok ++; res->ptr = tok; @@ -177,14 +180,14 @@ #ifdef DEBUG const char *thisfuncname = "expression_decompose()"; #endif - expression *resexp; + sf_expression *resexp; parserdata *right, *res; tokdata *tok = left->ptr; if ((tok->type == LO_OR) || (tok->type == LO_AND)) { /* this is compound expression */ res = (parserdata *) xalloc (NULL, sizeof (parserdata)); - resexp = (expression *) xalloc (NULL, sizeof (expression)); + resexp = (sf_expression *) xalloc (NULL, sizeof (sf_expression)); res->parsed = (void *) resexp; resexp->type = RELATION; /* set the expression we found before as first argument */ @@ -244,7 +247,7 @@ #ifdef DEBUG const char *thisfuncname = "get_atomic()"; #endif - atomic *at = (atomic *) xalloc (NULL, sizeof (atomic)); + sf_atomic *at = (sf_atomic *) xalloc (NULL, sizeof (sf_atomic)); tokdata *var = tok, *op = tok + 1, *val = tok + 2; @@ -255,39 +258,46 @@ switch (var->type) { case ID_LA1: - at->type = DOUBLE; + at->thresh.type = DOUBLE; at->op = op->type; - at->val_id = STA_LA1; + at->stat.label = ST_LOAD; + at->stat.arg[0].laminutes = 1; break; case ID_LA5: - at->type = DOUBLE; + at->thresh.type = DOUBLE; at->op = op->type; - at->val_id = STA_LA5; + at->stat.label = ST_LOAD; + at->stat.arg[0].laminutes = 5; break; case ID_LA15: - at->type = DOUBLE; + at->thresh.type = DOUBLE; at->op = op->type; - at->val_id = STA_LA15; + at->stat.label = ST_LOAD; + at->stat.arg[0].laminutes = 15; break; case ID_MFREE: - at->type = SIZE; + at->thresh.type = INTEGER; at->op = op->type; - at->val_id = STA_MFREE; + at->stat.label = ST_MEM; + at->stat.arg[0].resstat = VA_FREE; break; case ID_MUSED: - at->type = SIZE; + at->thresh.type = INTEGER; at->op = op->type; - at->val_id = STA_MUSED; + at->stat.label = ST_MEM; + at->stat.arg[0].resstat = VA_USED; break; case ID_SFREE: - at->type = SIZE; + at->thresh.type = INTEGER; at->op = op->type; - at->val_id = STA_SFREE; + at->stat.label = ST_SWAP; + at->stat.arg[0].resstat = VA_FREE; break; case ID_SUSED: - at->type = SIZE; + at->thresh.type = INTEGER; at->op = op->type; - at->val_id = STA_SUSED; + at->stat.label = ST_SWAP; + at->stat.arg[0].resstat = VA_USED; break; default: return NULL; @@ -313,8 +323,8 @@ /* check value type */ if (val->type == VA_INT) { /* this is integer. convert it to type required by label */ - if (at->type == SIZE) val->type = VA_SIZ; - else if (at->type == DOUBLE) { + if (at->thresh.type == INTEGER) val->type = VA_SIZ; + else if (at->thresh.type == DOUBLE) { /* long int 2 double */ val->type = VA_DBL; tmp = xalloc (NULL, sizeof (double)); @@ -324,8 +334,8 @@ } } - if (((at->type == SIZE) && (val->type != VA_SIZ)) || - ((at->type == DOUBLE) && (val->type != VA_DBL))) + if (((at->thresh.type == INTEGER) && (val->type != VA_SIZ)) || + ((at->thresh.type == DOUBLE) && (val->type != VA_DBL))) #ifdef DEBUG parse_error (val, thisfuncname, "type mismatch"); #else @@ -333,7 +343,7 @@ #endif /* copy threshold value */ - at->thresh = val->val; + at->thresh.ptr = val->val; res = (parserdata *) xalloc (NULL, sizeof (parserdata)); res->ptr = tok; @@ -344,11 +354,11 @@ parserdata * get_atomic_expression (tokdata *tok) { /* get atomic and encapsulate into expression with type = ATOMIC */ - parserdata *at = get_atomic (tok); - expression *ex; + parserdata *at = get_atomic (tok); + sf_expression *ex; if (at == NULL) return NULL; - ex = (expression *) xalloc (NULL, sizeof (expression)); + ex = (sf_expression *) xalloc (NULL, sizeof (sf_expression)); /* we'll use the same parserdata structure */ ex->type = ATOMIC; @@ -405,14 +415,14 @@ /* our result data */ parserdata *res = (parserdata *) xalloc (NULL, sizeof (parserdata)), *tmp, *run, *log; - ruleset *rlst; /* helper */ + sf_rule *rlst; /* helper */ /* the only way to return w/o error is to find end-of-file */ if (tok->type == END) return NULL; /* create ruleset structure */ - res->parsed = (ruleset *) xalloc (NULL, sizeof (ruleset)); - rlst = (ruleset *) res->parsed; + res->parsed = (sf_rule *) xalloc (NULL, sizeof (sf_rule)); + rlst = (sf_rule *) res->parsed; /* reset fields */ rlst->name = NULL; rlst->expr = NULL; @@ -420,8 +430,6 @@ rlst->log = NULL; rlst->hit = 0; rlst->prevhit = 0; - for (i = 0; i < STA_LAST; i++) - rlst->showstat[i] = 0; /* ruleset begins with IF */ if (tok->type != KW_IF) @@ -432,11 +440,17 @@ #endif else tok ++; - /* then we may find an optional rule name. */ + /* then we have rule name */ if (tok->type == VA_STR) { rlst->name = tok->val; - tok ++; + } else { +#ifdef DEBUG + parse_error (tok, thisfuncname, "no rule name"); +#else + parse_error (tok); +#endif } + tok ++; /* next should be expression in block */ tmp = get_block_expression (tok); @@ -448,7 +462,7 @@ #endif /* save expression and skip to next token */ - rlst->expr = (expression *) tmp->parsed; + rlst->expr = (sf_expression *) tmp->parsed; tok = tmp->ptr; run = get_rundata (tok); @@ -464,7 +478,7 @@ /* this is full ruleset now but we try to get next action data */ if (run != NULL) { /* save rundata && get logdata */ - rlst->run = (rundata *) run->parsed; + rlst->run = (sf_rundata *) run->parsed; log = get_logdata (run->ptr); /* if we have log sequence, save it. @@ -472,16 +486,16 @@ */ if (log != NULL) { tok = log->ptr; - rlst->log = (logdata *) log->parsed; + rlst->log = (sf_logdata *) log->parsed; } else tok = run->ptr; } else { - rlst->log = (logdata *) log->parsed; + rlst->log = (sf_logdata *) log->parsed; /* save logdata && get rundata */ run = get_rundata (log->ptr); if (run != NULL) { tok = run->ptr; - rlst->run = (rundata *) run->parsed; + rlst->run = (sf_rundata *) run->parsed; } else tok = log->ptr; } @@ -491,7 +505,7 @@ rlst->step = *((unsigned int *) tmp->parsed); /* search expression tree for used stats */ - collect_stats (rlst->expr, &(rlst->showstat[0])); +// collect_stats (rlst->expr, &(rlst->showstat[0])); /* ok, now we got full ruleset structure. * we need only to skip to next token. |