Ejemplo n.º 1
0
static int parse_cvdef(enum gf_en gf,parsedargs_t*pa,image_desc_t *const im){
  /* get new graph that we fill */
  graph_desc_t *gdp=newGraphDescription(im,gf,pa,
					PARSE_VNAMERPN
					);
  if (!gdp) { return 1;}

  /* handle RPN parsing */
  if (gf==GF_CDEF) {
    /* parse rpn */
    if ((gdp->rpnp= rpn_parse((void *) im, gdp->rpn, &find_var_wrapper)) == NULL) {
      return 1; }
  } else { /* VDEF */
    /* parse vdef, as vdef_parse is a bit "stupid" right now we have to touch things here */
    /* so find first , */
    char*c=strchr(gdp->rpn,',');
    char vname[MAX_VNAME_LEN+1];
    if (! c) { rrd_set_error("Comma expected in VDEF definition %s",gdp->rpn); return 1;}
    /* found a comma, so copy the first part to ds_nam (re/abusing it) */
    *c=0; /* yes now it seems as if the string ended here */
    strncpy(vname,gdp->rpn,MAX_VNAME_LEN);
    *c=','; /* and now all is back to normal ... shudder */
    /* trying to find the vidx for that name */
    gdp->vidx = find_var(im, vname);
    if (gdp->vidx<0) { *c=',';
      rrd_set_error("Not a valid vname: %s in line %s", vname, gdp->rpn);
      return 1;}
    if (im->gdes[gdp->vidx].gf != GF_DEF && im->gdes[gdp->vidx].gf != GF_CDEF) {
      rrd_set_error("variable '%s' not DEF nor "
		    "CDEF in VDEF '%s'",vname, gdp->rpn);
      return 1;
    }
    /* and parsing the rpn */
    int r=vdef_parse(gdp, c+1);
    /* original code does not check here for some reason */
    if (r) { return 1; }
  }

  /* debugging output */
  dprintf("=================================\n");
  if (gf==GF_CDEF) {
    dprintf("CDEF  : %s\n",pa->arg_orig);
  } else {
    dprintf("VDEF  : %s\n",pa->arg_orig);
  }
  dprintf("VNAME : %s\n",gdp->vname);
  dprintf("RPN   : %s\n",gdp->rpn);
  dprintf("=================================\n");

  /* and return fine */
  return 0;
}
Ejemplo n.º 2
0
int
rrd_parse_cdef(char *line, unsigned int *eaten, graph_desc_t *gdp, image_desc_t *im) {
    dprintf("- parsing '%s'\n",&line[*eaten]);
    if (rrd_parse_vname(line,eaten,gdp,im)) return 1;
    if ((gdp->rpnp = rpn_parse(
	(void *)im,
	&line[*eaten],
	&find_var_wrapper)
    )==NULL) {
	rrd_set_error("invalid rpn expression in: %s",&line[*eaten]);
	return 1;
    };
    while (line[*eaten]!='\0'&&line[*eaten]!=':')
	(*eaten)++;
    return 0;
}