+ }
+ }
+ }
+ /* not found, so return error */
+ return 1;
+}
+
+int getLong(const char* v,long *val,char**extra,int base) {
+ /* try to execute the parser */
+ /* NOTE that this may be a bit different from the original parser */
+ *extra=NULL;
+ *val=strtol(v,extra,base);
+ /* and error handling */
+ if (extra==NULL) {
+ return 0;
+ } else {
+ if (*extra==v) {
+ return -1; /* failed miserably */
+ } else {
+ if ((*extra)[0]==0) { return 0; }
+ return 1; /* got extra bytes */
+ }
+ }
+ /* not found, so return error */
+ return -2;
+}
+
+int getDouble(const char* v, double *val,char**extra) {
+ /* try to execute the parser */
+ /* NOTE that this may be a bit different from the original parser */
+ *extra=NULL;
+ *val=strtod(v,extra);
+ /* and error handling */
+ if (extra==NULL) {
+ return 0;
+ } else {
+ if (*extra==v) {
+ return -1; /* failed miserably */
+ } else {
+ if ((*extra)[0]==0) { return 0; }
+ return 1; /* got extra bytes */
+ }
+ }
+ /* not found, so return error */
+ return -2;
+}
+
+int addToArguments(parsedargs_t* pa, char*key, char*value, int cnt) {
+ /* resize the field */
+ keyvalue_t* t=realloc(pa->kv_args,(pa->kv_cnt+1)*sizeof(keyvalue_t));
+ if (!t) {
+ rrd_set_error("could not realloc memory");
+ return -1;
+ } else {
+ /* assign pointer */
+ pa->kv_args=t;
+ }
+ /* fill in data */
+ pa->kv_args[pa->kv_cnt].key=key;
+ pa->kv_args[pa->kv_cnt].value=value;
+ pa->kv_args[pa->kv_cnt].pos=cnt;
+ pa->kv_args[pa->kv_cnt].flag=0;
+ pa->kv_cnt++;
+ /* and return ok */
+ return 0;
+}
+
+char *poskeys[]={"pos0","pos1","pos2","pos3","pos4","pos5","pos6","pos7","pos8","pos9"};
+int parseArguments(const char* origarg, parsedargs_t* pa) {
+ initParsedArguments(pa);
+ /* now assign a copy */
+ pa->arg=strdup(origarg);
+ if (!pa->arg) { rrd_set_error("Could not allocate memory");return -1; }
+ pa->arg_orig=origarg;
+
+ /* first split arg into : */
+ char last=1;
+ char c;
+ int cnt=0;
+ int poscnt=0;
+ char* pos=pa->arg;
+ char* field=pos;
+ do {
+ c=*pos;
+ if (! field) { field=pos;cnt++;}
+ switch (c) {
+ /* if the char is a backslash, then this escapes the next one */
+ case '\\':
+ if (pos[1]) { pos++; }
+ break;
+ case 0:
+ case ':':
+ /* null and : separate the string */
+ *pos=0;
+ /* handle the case where we have got an = */
+ /* find equal sign */
+ char* equal=field;
+ for (equal=field;(*equal)&&(*equal!='=');equal++) { ; }
+ /* if we are on position 1 then check for position 0 to be [CV]?DEV */
+ int checkforkeyvalue=1;
+ /* nw define key to use */
+ char *key,*value;
+ if ((*equal=='=') && (checkforkeyvalue)) {
+ *equal=0;
+ key=field;
+ value=equal+1;
+ } else {
+ if ((poscnt>0)&&(strcmp(field,"STACK")==0)) {
+ key="stack";
+ value="1";
+ } else if ((poscnt>0)&&(strcmp(field,"strftime")==0)) {
+ key="strftime";
+ value="1";
+ } else {
+ if (poscnt>9) {
+ rrd_set_error("too many positional arguments");
+ freeParsedArguments(pa);
+ return -1;
+ }
+ key=poskeys[poscnt];
+ poscnt++;
+ value=field;
+ }
+ }
+ /* do some synonym translations */
+ if (strcmp(key,"label")==0) { key="legend"; }
+ if (strcmp(key,"colour")==0) { key="color"; }
+ if (strcmp(key,"colour2")==0) { key="color2"; }
+
+ /* add to fields */
+ if (addToArguments(pa,key,value,cnt)) {
+ freeParsedArguments(pa);
+ return -1;
+ }
+
+ /* and reset field */
+ field=NULL;
+ break;
+ default:
+ break;
+ }
+ /* assign last */
+ last=c;
+ /* and step to next one byte */
+ pos++;
+ } while (c);
+ /* and return OK */
+ return 0;
+}
+
+int parse_color( const char *const, struct gfx_color_t *);
+int parse_color( const char *const string, struct gfx_color_t *c)
+{
+ unsigned int r = 0, g = 0, b = 0, a = 0, i;
+
+ /* matches the following formats:
+ ** RGB
+ ** RGBA
+ ** RRGGBB
+ ** RRGGBBAA
+ */
+
+ i = 0;
+ while (string[i] && isxdigit((unsigned int) string[i]))
+ i++;
+ if (string[i] != '\0')
+ return 1; /* garbage follows hexdigits */
+ switch (i) {
+ case 3:
+ case 4:
+ sscanf(string, "%1x%1x%1x%1x", &r, &g, &b, &a);
+ r *= 0x11;
+ g *= 0x11;
+ b *= 0x11;
+ a *= 0x11;
+ if (i == 3)
+ a = 0xFF;
+ break;
+ case 6:
+ case 8:
+ sscanf(string, "%02x%02x%02x%02x", &r, &g, &b, &a);
+ if (i == 6)
+ a = 0xFF;
+ break;
+ default:
+ return 1; /* wrong number of digits */
+ }
+ /* I wonder how/why this works... */
+ *c=gfx_hex_to_col(r << 24 | g << 16 | b << 8 | a);
+ return 0;
+}
+
+/* this would allow for 240 different values */
+#define PARSE_FIELD1 (1L<<60)
+#define PARSE_FIELD2 (1L<<61)
+#define PARSE_FIELD3 (1L<<62)
+#define PARSE_FIELD4 (1L<<63)
+#define PARSE_POSITIONAL (1L<<59)
+#define PARSE_ONYAXIS (1L<<58)
+#define PARSE_VNAME (PARSE_FIELD1|(1L<< 0))
+#define PARSE_RRD (PARSE_FIELD1|(1L<< 1))
+#define PARSE_DS (PARSE_FIELD1|(1L<< 2))
+#define PARSE_CF (PARSE_FIELD1|(1L<< 3))
+#define PARSE_COLOR (PARSE_FIELD1|(1L<< 4))
+#define PARSE_COLOR2 (PARSE_FIELD1|(1L<< 5))
+#define PARSE_LEGEND (PARSE_FIELD1|(1L<< 6))
+#define PARSE_RPN (PARSE_FIELD1|(1L<< 7))
+#define PARSE_START (PARSE_FIELD1|(1L<< 8))
+#define PARSE_STEP (PARSE_FIELD1|(1L<< 9))
+#define PARSE_END (PARSE_FIELD1|(1L<<10))
+#define PARSE_STACK (PARSE_FIELD1|(1L<<11))
+#define PARSE_LINEWIDTH (PARSE_FIELD1|(1L<<12))
+#define PARSE_XAXIS (PARSE_FIELD1|(1L<<13))
+#define PARSE_YAXIS (PARSE_FIELD1|(1L<<14))
+#define PARSE_REDUCE (PARSE_FIELD1|(1L<<15))
+#define PARSE_DASHES (PARSE_FIELD1|(1L<<20))
+#define PARSE_HEIGHT (PARSE_FIELD1|(1L<<21))
+#define PARSE_FORMAT (PARSE_FIELD1|(1L<<22))
+#define PARSE_STRFTIME (PARSE_FIELD1|(1L<<23))
+#define PARSE_FRACTION (PARSE_FIELD1|(1L<<24))
+/* VNAME Special cases for generic parsing */
+#define PARSE_VNAMEDEF (PARSE_VNAME|(1L<<57))
+#define PARSE_VNAMEREF (PARSE_VNAME|(1L<<56))
+#define PARSE_VNAMEREFNUM (PARSE_VNAMEREF|(1L<<55))
+#define PARSE_VNAMEREFNUMNOPARSE (PARSE_FIELD1|(1L<<54))
+/* special positional cases */
+#define PARSE_VNAMERRDDSCF (PARSE_POSITIONAL|PARSE_VNAMEDEF|PARSE_RRD|PARSE_DS|PARSE_CF)
+#define PARSE_VNAMECOLORLEGEND (PARSE_POSITIONAL|PARSE_VNAMEREFNUM|PARSE_COLOR|PARSE_COLOR2|PARSE_LEGEND)
+#define PARSE_VNAMECOLORFRACTIONLEGEND (PARSE_VNAMECOLORLEGEND|PARSE_FRACTION)
+#define PARSE_VNAMERPN (PARSE_POSITIONAL|PARSE_VNAMEDEF|PARSE_RPN)
+#define PARSE_VNAMEREFPOS (PARSE_POSITIONAL|PARSE_VNAMEREF)
+
+graph_desc_t* newGraphDescription(image_desc_t *const,enum gf_en,parsedargs_t*,unsigned long);
+graph_desc_t* newGraphDescription(image_desc_t *const im,enum gf_en gf,parsedargs_t* pa,unsigned long bits) {
+ /* check that none of the othe bitfield marker is set */
+ if ((bits&PARSE_FIELD1)&&((bits&(PARSE_FIELD2|PARSE_FIELD3|PARSE_FIELD4)))) {
+ rrd_set_error("newGraphDescription: bad bitfield1 value %08x",bits);return NULL; }
+ /* the normal handler that adds to img */
+ if (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; }
+ gdp->debug=debug;
+ }
+
+ /* and the "flagged" parser implementation
+ *
+ * first the fields with legacy positional args
+ */
+#define bitscmp(v) ((bits&v)==v)
+ char* vname=NULL;
+ if (bitscmp(PARSE_VNAME)) { vname=getKeyValueArgument("vname",1,pa);
+ dprintfparsed("got vname: %s\n",vname);}
+ char *rrd=NULL;
+ if (bitscmp(PARSE_RRD)) { rrd=getKeyValueArgument("rrd",1,pa);
+ dprintfparsed("got rrd: %s\n",rrd);}
+ char *ds=NULL;
+ if (bitscmp(PARSE_DS)) { ds=getKeyValueArgument("ds",1,pa);
+ dprintfparsed("got ds: %s\n",ds);}
+ char *cf=NULL;
+ if (bitscmp(PARSE_CF)) { cf=getKeyValueArgument("cf",1,pa);
+ dprintfparsed("got cf: %s\n",cf);}
+ char *color=NULL;
+ if (bitscmp(PARSE_COLOR)) { color=getKeyValueArgument("color",1,pa);
+ dprintfparsed("got color: %s\n",color);}
+ char *color2=NULL;
+ if (bitscmp(PARSE_COLOR2)) { color2=getKeyValueArgument("color2",1,pa);
+ dprintfparsed("got color2: %s\n",color2);}
+ char *rpn=NULL;
+ if (bitscmp(PARSE_RPN)) { rpn=getKeyValueArgument("rpn",1,pa);
+ dprintfparsed("got rpn: %s\n",rpn);}
+ char *legend=NULL;
+ if (bitscmp(PARSE_LEGEND)) { legend=getKeyValueArgument("legend",1,pa);
+ dprintfparsed("got legend: %s\n",legend);}
+ char *fraction=NULL;
+ if (bitscmp(PARSE_FRACTION)) { fraction=getKeyValueArgument("fraction",1,pa);
+ dprintfparsed("got fraction: %s\n",fraction);}
+ /*
+ * here the ones without delayed assigns (which are for positional parsers)
+ */
+ if (bitscmp(PARSE_FORMAT)) {
+ char *format=getKeyValueArgument("format",1,pa);
+ if(format) {
+ strncpy(gdp->format,format,FMT_LEG_LEN);
+ dprintfparsed("got format: %s\n",format);
+ }
+ }
+ if (bitscmp(PARSE_STRFTIME)) {
+ char *strft=getKeyValueArgument("strftime",1,pa);
+ gdp->strftm=(strft)?1:0;
+ dprintfparsed("got strftime: %s\n",strft);
+ }
+ if (bitscmp(PARSE_STACK)) {
+ char *stack=getKeyValueArgument("stack",1,pa);
+ gdp->stack=(stack)?1:0;
+ dprintfparsed("got stack: %s\n",stack);
+ }
+ if (bitscmp(PARSE_REDUCE)) {
+ char *reduce=getKeyValueArgument("reduce",1,pa);
+ if (reduce) {
+ gdp->cf_reduce=cf_conv(reduce);
+ dprintfparsed("got reduce: %s (%i)\n",reduce,gdp->cf_reduce);
+ if (((int)gdp->cf_reduce)==-1) { rrd_set_error("bad reduce CF: %s",reduce); return NULL; }
+ }
+ }
+ if (bitscmp(PARSE_XAXIS)) {
+ long xaxis=0;
+ char *t,*x;
+ if ((t=getKeyValueArgument("xaxis",1,pa)) && ((getLong(t,&xaxis,&x,10))||(xaxis<1)||(xaxis>MAX_AXIS))) {
+ rrd_set_error("Bad xaxis value: %s",t); return NULL; }
+ dprintfparsed("got xaxis: %s (%li)\n",t,xaxis);
+ gdp->xaxisidx=xaxis;
+ }
+ if (bitscmp(PARSE_YAXIS)) {
+ long yaxis=0;
+ char *t,*x;
+ if ((t=getKeyValueArgument("yaxis",1,pa)) && ((getLong(t,&yaxis,&x,10))||(yaxis<1)||(yaxis>MAX_AXIS))) {
+ rrd_set_error("Bad yaxis value: %s",t); return NULL; }
+ dprintfparsed("got yaxis: %s (%li)\n",t,yaxis);
+ gdp->yaxisidx=yaxis;
+ }
+ if (bitscmp(PARSE_LINEWIDTH)) {
+ double linewidth=0;
+ char *t,*x;
+ if ((t=getKeyValueArgument("linewidth",1,pa))&&(*t!=0)) {
+ if ((getDouble(t,&linewidth,&x))||(linewidth<=0)) {
+ rrd_set_error("Bad line width: %s",t); return NULL;
+ }
+ dprintfparsed("got linewidth: %s (%g)\n",t,linewidth);
+ gdp->linewidth=linewidth;
+ }
+ }
+ if (bitscmp(PARSE_HEIGHT)) {
+ double height=0;
+ char *t,*x;
+ if ((t=getKeyValueArgument("height",1,pa))&&(*t!=0)) {
+ if (getDouble(t,&height,&x)) {
+ rrd_set_error("Bad height: %s",t); return NULL;
+ }
+ dprintfparsed("got height: %s (%g)\n",t,height);
+ gdp->gradheight=height;
+ }
+ }
+ if (bitscmp(PARSE_STEP)) {
+ long step=0;
+ char *t,*x;
+ if ((t=getKeyValueArgument("step",1,pa)) && ((getLong(t,&step,&x,10))||(step<1))) {
+ rrd_set_error("Bad step value: %s",t); return NULL; }
+ dprintfparsed("got step: %s (%li)\n",t,step);
+ gdp->step=step;
+ }
+ if ((bitscmp(PARSE_START)||bitscmp(PARSE_END))) {
+ /* these should get done together to use the start/end code correctly*/
+ char* parsetime_error;
+ /* first start */
+ char* start;
+ rrd_time_value_t start_tv;
+ start_tv.type = ABSOLUTE_TIME;
+ start_tv.offset = 0;
+ localtime_r(&gdp->start, &start_tv.tm);
+ if (bitscmp(PARSE_START)) {
+ start=getKeyValueArgument("start",1,pa);
+ if ((start)&&(parsetime_error = rrd_parsetime(start, &start_tv))) {
+ rrd_set_error("start time: %s", parsetime_error);return NULL; }
+ dprintfparsed("got start: %s\n",start);
+ }
+ /* now end */
+ char* end;
+ rrd_time_value_t end_tv;
+ end_tv.type = ABSOLUTE_TIME;
+ end_tv.offset = 0;
+ localtime_r(&gdp->end, &end_tv.tm);
+ if (bitscmp(PARSE_END)) {
+ end=getKeyValueArgument("end",1,pa);
+ if ((end)&&(parsetime_error = rrd_parsetime(end, &end_tv))) {
+ rrd_set_error("end time: %s", parsetime_error); return NULL; }
+ dprintfparsed("got end: %s\n",end);
+ }
+ /* and now put the pieces together (relative times like start=end-2days) */
+ time_t start_tmp = 0, end_tmp = 0;
+ if (rrd_proc_start_end(&start_tv, &end_tv, &start_tmp, &end_tmp) == -1) {
+ return NULL;
+ }
+ dprintfparsed("got start %s translated to: %lld\n",start,(long long int)start_tmp);
+ dprintfparsed("got end %s translated to: %lld\n",end,(long long int)end_tmp);
+
+ /* check some ranges */
+ if (start_tmp < 3600 * 24 * 365 * 10) {
+ rrd_set_error("the first entry to fetch should be "
+ "after 1980 (%ld)", start_tmp);
+ return NULL; }
+ if (end_tmp < start_tmp) {
+ rrd_set_error("start (%ld) should be less than end (%ld)",
+ start_tmp, end_tmp);
+ return NULL; }
+
+ /* and finally set it irrespectively of if it has been set or not
+ * it may have been a relative time and if you just set it partially
+ * then that is wrong...
+ */
+ gdp->start = start_tmp;
+ gdp->start_orig = start_tmp;
+ gdp->end = end_tmp;
+ gdp->end_orig = end_tmp;
+ }
+ if (bitscmp(PARSE_DASHES)) {
+ char* dashes=getKeyValueArgument("dashes",1,pa);
+ /* if we got dashes */
+ if (dashes) {
+ gdp->offset = 0;
+ /* count the , in dashes */
+ int cnt=0;for(char*t=dashes;(*t)&&(t=strchr(t,','));t++,cnt++) {;}
+ dprintfparsed("Got dashes argument: %s with %i comma\n",dashes,cnt);
+ /* now handle */
+ gdp->ndash = cnt+1;
+ gdp->p_dashes = (double *) malloc(sizeof(double)*(gdp->ndash+1));
+ /* now loop dashes */
+ for(int i=0;i<gdp->ndash;i++) {
+ char *x;
+ int f=getDouble(dashes,&gdp->p_dashes[i],&x);
+ if(f<0) {
+ rrd_set_error("Could not parse number: %s",dashes); return NULL;
+ }
+ /* we should have this most of the time */
+ dprintfparsed("Processed %s to %g at index %i\n",dashes,gdp->p_dashes[i],i);
+ if (f>0) {
+ if (*x!=',') {
+ rrd_set_error("expected a ',' at : %s",x); return NULL;}
+ dashes=x+1;
+ }
+ if ((f==0)&&(i!=gdp->ndash-1)) {
+ rrd_set_error("unexpected end at : %s",dashes); return NULL;}
+ }
+ }
+ char* dashoffset=getKeyValueArgument("dash-offset",1,pa);
+ if (dashoffset) {
+ char* x;
+ if (getDouble(dashes,&gdp->offset,&x)) {
+ rrd_set_error("Could not parse dash-offset: %s",dashoffset); return NULL; }
+ }
+ }
+
+ /* here now the positional(=legacy) parsers which are EXCLUSIVE - SO ELSE IF !!!
+ * we also only parse the extra here and assign just further down
+ * TODO maybe we can generalize this a bit more...
+ */
+ if (bitscmp(PARSE_VNAMERRDDSCF)) {
+ if ((!vname)||(!rrd)) {
+ /* get the first unused argument */
+ keyvalue_t* first=getFirstUnusedArgument(1,pa);
+ if (!first) { rrd_set_error("No argument for definition of vdef/rrd in %s",pa->arg_orig); return NULL; }
+ dprintfparsed("got positional vname and rrd: %s - %s\n",first->key,first->value);
+ if (!vname) {vname=first->key;}
+ if (!rrd) {rrd=first->value; }
+ }
+ /* and now look for datasource */
+ if (!ds) {
+ /* get the first unused argument */
+ keyvalue_t* first=getFirstUnusedArgument(1,pa);
+ if (!first) { rrd_set_error("No argument for definition of DS in %s",pa->arg_orig); return NULL; }
+ dprintfparsed("got positional ds: %s - \n",first->value);
+ ds=first->value;
+ }
+ /* and for CF */
+ if (!cf) {
+ /* get the first unused argument */
+ keyvalue_t* first=getFirstUnusedArgument(1,pa);
+ if (!first) { rrd_set_error("No argument for definition of CF in %s",pa->arg_orig); return NULL; }
+ dprintfparsed("got positional cf: %s - \n",first->value);
+ cf=first->value;
+ }
+ } else if (bitscmp(PARSE_VNAMECOLORLEGEND)) {
+ /* vname */
+ if (!vname) {
+ keyvalue_t* first=getFirstUnusedArgument(1,pa);
+ if (first) { vname=first->value;
+ } else { rrd_set_error("No positional VNAME"); return NULL; }
+ }
+ /* fraction added into the parsing mix for TICK */
+ if ((bitscmp(PARSE_VNAMECOLORFRACTIONLEGEND))&&(!fraction)) {
+ keyvalue_t* first=getFirstUnusedArgument(1,pa);
+ if (first) { fraction=first->value;
+ } else { rrd_set_error("No positional FRACTION"); return NULL; }
+ }
+ /* legend */
+ if (!legend) {
+ keyvalue_t* first=getFirstUnusedArgument(1,pa);
+ if (first) { legend=first->value;
+ dprintfparsed("got positional legend: %s - \n",first->value);
+ } else { rrd_set_error("No positional legend found"); return NULL; }
+ }
+ } else if (bitscmp(PARSE_VNAMERPN)) {
+ if ((!vname)||(!rpn)) {
+ /* get the first unused argument */
+ keyvalue_t* first=getFirstUnusedArgument(1,pa);
+ if (!first) { rrd_set_error("No argument for definition of vdef/rrd in %s",pa->arg_orig); return NULL; }
+ dprintfparsed("got positional vname and rpn: %s - %s\n",first->key,first->value);
+ if (!vname) {vname=first->key;}
+ if (!rpn) {rpn=first->value; }
+ }
+ } else if (bitscmp(PARSE_VNAMEREFPOS)) {
+ if ((!vname)) {
+ /* get the first unused argument */
+ keyvalue_t* first=getFirstUnusedArgument(1,pa);
+ if (!first) { rrd_set_error("No argument for definition of vdef/rrd in %s",pa->arg_orig); return NULL; }
+ dprintfparsed("got positional vname and rrd: %s - %s\n",first->key,first->value);
+ if (!vname) {vname=first->value;}
+ }
+ }
+
+ /* and set some of those late assignments to accomodate the legacy parser*/
+ /* first split vname into color */
+ if (vname) {
+ /* check for color */
+ char *h1=strchr(vname,'#');
+ char* h2=NULL;
+ if (h1) {
+ *h1=0;h1++;
+ dprintfparsed("got positional color: %s - \n",h1);
+ h2=strchr(h1,'#');
+ if (h2) {
+ *h2=0;h2++;
+ dprintfparsed("got positional color2: %s - \n",h2);
+ }
+ }
+ if (bitscmp(PARSE_COLOR) && (! color) && (h1)) { color=h1;}
+ if (bitscmp(PARSE_COLOR2) && (! color2) && (h2)) { color2=h2;}
+ }
+
+ /* check if we are reusing the vname */
+ if (vname) {
+ int idx=find_var(im, vname);
+ dprintfparsed("got positional index %i for %s - \n",idx,vname);
+
+ /* some handling */
+ if (bitscmp(PARSE_VNAMEDEF)) {
+ if (idx>=0) {
+ rrd_set_error("trying to reuse vname %s",vname); return NULL; }
+ } else if (bitscmp(PARSE_VNAMEREF)) {
+ if (idx>=0) {
+ gdp->vidx=idx;
+ } else if (bitscmp(PARSE_VNAMEREFNUM)) {
+ if (!bitscmp(PARSE_VNAMEREFNUMNOPARSE)) {
+ double val;
+ char *x;
+ int f=getDouble(vname,&val,&x);
+ if (f) {
+ rrd_set_error("error parsing number %s",vname); return NULL;
+ }
+ gdp->yrule=val;
+ } else {
+ rrd_set_error("vname %s not found",vname); return NULL;
+ }
+ } else {
+ gdp->vidx=-1;
+ }
+ }
+ }
+
+ /* and assign it */
+ if (vname) { strncpy(gdp->vname,vname,MAX_VNAME_LEN + 1); }
+ if (rrd) { strncpy(gdp->rrd,rrd,1024); }
+ if (ds) { strncpy(gdp->ds_nam,ds,DS_NAM_SIZE); }
+ if (cf) {
+ gdp->cf=cf_conv(cf);
+ if (((int)gdp->cf)==-1) {
+ rrd_set_error("bad CF: %s",cf); return NULL; }
+ } else { if (bitscmp(PARSE_CF)) {gdp->cf=-1;}}
+ if ((color)&&(parse_color(color,&(gdp->col)))) { return NULL; }
+ if ((color2)&&(parse_color(color2,&(gdp->col2)))) { return NULL; }
+ if (rpn) {gdp->rpn=rpn;}
+ if ((legend)&&(*legend!=0)) {
+ /* some spacing before we really start with the legend - needed for some reason */
+ char* t=gdp->legend;
+ *t=' ';t++;
+ *t=' ';t++;
+ /* and copy it into place */
+ strncpy(t,legend,FMT_LEG_LEN);
+ }
+ if (fraction) {
+ if (strcmp(fraction,"vname")==0) {
+ /* check that vname is really a DEF|CDEF */
+ if (im->gdes[gdp->vidx].gf != GF_DEF && im->gdes[gdp->vidx].gf != GF_CDEF) {
+ rrd_set_error("variable '%s' not DEF nor CDEF when using dynamic fractions", gdp->vname);
+ return NULL;
+ }
+ /* add as flag to use (c)?def */
+ gdp->cf=CF_LAST;
+ gdp->yrule=0.5;
+ } else {
+ /* parse number */
+ double val;
+ char *x;
+ int f=getDouble(fraction,&val,&x);
+ if (f) {
+ rrd_set_error("error parsing number %s",vname); return NULL;
+ }
+ gdp->yrule=val;
+ }
+ }
+ /* and return it */
+ return gdp;
+}