From: Martin Sperl Date: Tue, 24 Feb 2015 13:35:38 +0000 (+0000) Subject: fixed positional parser for def by allowing us to rerun the parser a second time X-Git-Tag: v1.5.0~11^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=beeb31409a94ccbf89e81dfcd49c1fc655228ba6;p=thirdparty%2Frrdtool-1.x.git fixed positional parser for def by allowing us to rerun the parser a second time but this time with the first positional key altered... --- diff --git a/src/rrd_graph.h b/src/rrd_graph.h index 12ea8b52..1429d086 100644 --- a/src/rrd_graph.h +++ b/src/rrd_graph.h @@ -85,7 +85,7 @@ enum vdef_op_en { , VDEF_LSLCORREL /* least squares line correlation coefficient */ , VDEF_PERCENTNAN /* Nth percentile ignoring NAN*/ }; -enum text_prop_en { +enum text_prop_en { TEXT_PROP_DEFAULT = 0, /* default settings */ TEXT_PROP_TITLE, /* properties for the title */ TEXT_PROP_AXIS, /* for the numbers next to the axis */ @@ -98,7 +98,7 @@ enum text_prop_en { enum legend_pos{ NORTH = 0, WEST, SOUTH, EAST }; enum legend_direction { TOP_DOWN = 0, BOTTOM_UP, BOTTOM_UP2 }; -enum gfx_if_en { IF_PNG = 0, IF_SVG, IF_EPS, IF_PDF, +enum gfx_if_en { IF_PNG = 0, IF_SVG, IF_EPS, IF_PDF, IF_XML=128, IF_CSV=129, IF_TSV=130, IF_SSV=131, IF_JSON=132, IF_XMLENUM=133, IF_JSONTIME=134 }; @@ -136,6 +136,7 @@ typedef struct parsedargs_t { keyvalue_t *kv_args; /* key value arguments */ } parsedargs_t; void initParsedArguments(parsedargs_t*); +void resetParsedArguments(parsedargs_t*); void freeParsedArguments(parsedargs_t*); int addToArguments(parsedargs_t*, char*, char*, char*, int); int parseArguments(const char*, parsedargs_t*); @@ -279,7 +280,7 @@ typedef struct image_desc_t { double second_axis_scale; /* relative to the first axis (0 to disable) */ double second_axis_shift; /* how much is it shifted vs the first axis */ char *second_axis_legend; /* label to put on the seond axis */ - char *second_axis_format; /* format for the numbers on the scond axis */ + char *second_axis_format; /* format for the numbers on the scond axis */ char *primary_axis_format; /* format for the numbers on the primary axis */ double ygridstep; /* user defined step for y grid */ int ylabfact; /* every how many y grid shall a label be written ? */ @@ -287,12 +288,12 @@ typedef struct image_desc_t { time_t start, end; /* what time does the graph cover */ unsigned long step; /* any preference for the default step ? */ rrd_value_t minval, maxval; /* extreme values in the data */ - int rigid; /* do not expand range even with + int rigid; /* do not expand range even with values outside */ ygrid_scale_t ygrid_scale; /* calculated y axis grid info */ int gridfit; /* adjust y-axis range etc so all grindlines falls in integer pixel values */ - char *imginfo; /* construct an 0: * gradient starts at top and goes down a fixed number of pixels (fire style) * height < 0: @@ -533,7 +534,7 @@ void gfx_add_rect_fadey( gfx_color_t color1, gfx_color_t color2, double height); - + /* close current path so it ends at the same point as it started */ diff --git a/src/rrd_graph_helper.c b/src/rrd_graph_helper.c index b76c6cf4..28e5ab24 100644 --- a/src/rrd_graph_helper.c +++ b/src/rrd_graph_helper.c @@ -37,6 +37,16 @@ void freeParsedArguments(parsedargs_t* pa) { initParsedArguments(pa); } +void resetParsedArguments(parsedargs_t* pa) { + if (pa->kv_args) { + for(int i=0;ikv_cnt;i++) { + if (pa->kv_args[i].flag!=255) { + pa->kv_args[i].flag=0; + } + } + } +} + void dumpKeyValue(char* pre,keyvalue_t* t) { if (t) { fprintf(stderr,"%s%i: '%s' = '%s' %i\n", @@ -364,6 +374,8 @@ int parse_color( const char *const string, struct gfx_color_t *c) #define PARSE_VNAMECOLORFRACTIONLEGEND (PARSE_VNAMECOLORLEGEND|PARSE_FRACTION) #define PARSE_VNAMERPN (PARSE_POSITIONAL|PARSE_VNAMEDEF|PARSE_RPN) #define PARSE_VNAMEREFPOS (PARSE_POSITIONAL|PARSE_VNAMEREF) +/* a retry parsing */ +#define PARSE_RETRY (1ULL<<54) GHashTable* gdef_map; @@ -400,17 +412,19 @@ static graph_desc_t* newGraphDescription(image_desc_t *const im,enum gf_en gf,pa if ((bits&PARSE_FIELD1)&&((bits&(PARSE_FIELD2|PARSE_FIELD3|PARSE_FIELD4)))) { rrd_set_error("newGraphDescription: bad bitfield1 value %08llx",bits);return NULL; } /* the normal handler that adds to img */ - if (gdes_alloc(im)) { return NULL; } + if ((!(bits & PARSE_RETRY)) && (gdes_alloc(im))) { return NULL; } /* set gdp */ graph_desc_t *gdp= &im->gdes[im->gdes_c - 1]; /* set some generic things */ gdp->gf=gf; - if (1) { + { char *t,*x; long debug=0; if ((t=getKeyValueArgument("debug",1,pa)) && ((getLong(t,&debug,&x,10)))) { - rrd_set_error("Bad debug value: %s",t); return NULL; } + rrd_set_error("Bad debug value: %s",t); + return NULL; + } gdp->debug=debug; } @@ -709,6 +723,13 @@ static graph_desc_t* newGraphDescription(image_desc_t *const im,enum gf_en gf,pa if (bitscmp(PARSE_COLOR2) && (! color2) && (h2)) { color2=h2;} } + /* clean up vname escaping on second tries */ + if (bits & PARSE_RETRY) { + if (vname && (*vname>128)) { + *vname-=128; + } + } + /* check if we are reusing the vname */ if (vname) { int idx=find_var(im, vname); @@ -878,7 +899,25 @@ int parse_def(enum gf_en gf,parsedargs_t*pa,image_desc_t *const im){ |PARSE_END |PARSE_REDUCE ); - if (!gdp) { return 1;} + /* retry in case of errors modifying the name*/ + if (!gdp) { + rrd_clear_error(); + /* restart from scratch */ + resetParsedArguments(pa); + /* but modify the first parameter */ + keyvalue_t *first= getFirstUnusedArgument(0,pa); + *(first->key)+=128; + /* now run it */ + gdp=newGraphDescription(im,gf,pa, + PARSE_VNAMERRDDSCF + |PARSE_START + |PARSE_STEP + |PARSE_END + |PARSE_REDUCE + |PARSE_RETRY + ); + if (!gdp) { return 1;} + } if (gdp->step == 0){ gdp->step = im->step; /* initialize with image wide step */ @@ -1180,7 +1219,7 @@ int parse_gprint(enum gf_en gf,parsedargs_t*pa,image_desc_t *const im) { if (first) { gdp->cf=cf_conv(first->value); if (((int)gdp->cf)==-1) { - rrd_set_error("bad CF: %s",first->value); return 1; } + rrd_set_error("bad CF for DEF/CDEF: %s",first->value); return 1; } } else { rrd_set_error("No positional CDEF"); return 1; } } break; @@ -1420,10 +1459,10 @@ void rrd_graph_script( /* now let us handle the field based on the first command or cmd=...*/ char*cmd=NULL; /* and try to get via cmd */ - char* t=getKeyValueArgument("cmd",1,&pa); + char* t=getKeyValueArgument("cmd",255,&pa); if (t) { cmd=t; - } else if ((t=getKeyValueArgument("pos0",1,&pa))) { + } else if ((t=getKeyValueArgument("pos0",255,&pa))) { cmd=t; } else { rrd_set_error("no command set in argument %s",pa.arg_orig);