Exemplo n.º 1
0
int parse_area(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_VNAMECOLORLEGEND
					|PARSE_STACK
                                        |PARSE_SKIPSCALE
					|PARSE_XAXIS
					|PARSE_YAXIS
					|PARSE_HEIGHT
					); 
  if (!gdp) { return 1;}

  /* debug output */
  dprintf("=================================\n");
  dprintf("AREA  : %s\n",pa->arg_orig);
  if (gdp->vidx<0) {
    dprintf("VAL   : %g\n",gdp->yrule);
  } else {
    dprintf("VNAME : %s (%li)\n",gdp->vname,gdp->vidx);
  }
  dprintf("COLOR : r=%g g=%g b=%g a=%g\n",
	  gdp->col.red,gdp->col.green,gdp->col.blue,gdp->col.alpha);
  dprintf("COLOR2: r=%g g=%g b=%g a=%g\n",
	  gdp->col2.red,gdp->col2.green,gdp->col2.blue,gdp->col2.alpha);
  dprintf("LEGEND: %s\n",gdp->legend);
  dprintf("STACK : %i\n",gdp->stack);
  dprintf("SKIPSCALE : %i\n",gdp->skipscale);
  dprintf("XAXIS : %i\n",gdp->xaxisidx);
  dprintf("YAXIS : %i\n",gdp->yaxisidx);
  dprintf("=================================\n");

  /* and return fine */
  return 0;
}
Exemplo n.º 2
0
static int parse_xport(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_VNAMECOLORLEGEND);
  if (!gdp) { return 1;}
  /* check for cdef */
  /* and check that it is a CDEF */
  switch (im->gdes[gdp->vidx].gf) {
  case GF_DEF:
  case GF_CDEF:
    dprintf("- vname is of type DEF or CDEF, OK\n");
    break;
  case GF_VDEF:
    rrd_set_error("Cannot shift a VDEF: '%s' in line '%s'\n",
		  im->gdes[gdp->vidx].vname, pa->arg_orig);
    return 1;
  default:
    rrd_set_error("Encountered unknown type variable '%s' in line '%s'",
		  im->gdes[gdp->vidx].vname, pa->arg_orig);
    return 1;
  }

  /* debug output */
  dprintf("=================================\n");
  dprintf("LINE  : %s\n",pa->arg_orig);
  dprintf("VNAME : %s (%li)\n",gdp->vname,gdp->vidx);
  dprintf("LEGEND: \"%s\"\n",gdp->legend);
  dprintf("=================================\n");

  return 0;
}
Exemplo n.º 3
0
int parse_def(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_VNAMERRDDSCF 
					|PARSE_START
					|PARSE_STEP
					|PARSE_END
					|PARSE_REDUCE
					); 
  if (gdp->step == 0){
      gdp->step = im->step; /* initialize with image wide step */
  }  
  if (!gdp) { return 1;}
  /* debugging output */
  dprintf("=================================\n");
  dprintf("DEF   : %s\n",pa->arg_orig);
  dprintf("VNAME : %s\n",gdp->vname);
  dprintf("RRD   : %s\n",gdp->rrd);
  dprintf("DS    : %s\n",gdp->ds_nam);
  dprintf("CF    : %i\n",gdp->cf);
  dprintf("START : (%lld)\n",(long long int)gdp->start);
  dprintf("STEP  : (%lld)\n",(long long int)gdp->step);
  dprintf("END   : (%lld)\n",(long long int)gdp->end);
  dprintf("REDUCE: (%i)\n",gdp->cf_reduce);
  dprintf("=================================\n");

  /* and return fine */
  return 0;
}  
Exemplo n.º 4
0
int parse_textalign(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,0); 
  if (!gdp) { return 1;}

  /* get align */
  char* align=getKeyValueArgument("align",1,pa);
  if (!align) align=getFirstUnusedArgument(1,pa)->value;
  if (!align) { rrd_set_error("No alignment given"); return 1; }

  /* parse align */
  if (strcmp(align, "left") == 0) {
    gdp->txtalign = TXA_LEFT;
  } else if (strcmp(align, "right") == 0) {
    gdp->txtalign = TXA_RIGHT;
  } else if (strcmp(align, "justified") == 0) {
    gdp->txtalign = TXA_JUSTIFIED;
  } else if (strcmp(align, "center") == 0) {
    gdp->txtalign = TXA_CENTER;
  } else {
    rrd_set_error("Unknown alignement type '%s'", align);
    return 1;
  }

  /* debug output */
  dprintf("=================================\n");
  dprintf("TEXTALIGN : %s\n",pa->arg_orig);
  dprintf("ALIGNMENT : %s (%u)\n",align,gdp->txtalign);  
  dprintf("=================================\n");
  /* and return */
  return 0;
}
Exemplo n.º 5
0
static int parse_stack(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_VNAMECOLORLEGEND
					|PARSE_XAXIS
					|PARSE_YAXIS
					);
  if (!gdp) { return 1;}

  gdp->stack=1;
  /* and try to get the one index before ourselves */
  long i;
  for (i=im->gdes_c-1;(gdp->gf==gf)&&(i>=0);i--) {
    dprintfparsed("trying to process entry %li with type %u\n",i,im->gdes[i].gf);
    switch (im->gdes[i].gf) {
    case GF_LINE:
    case GF_AREA:
      gdp->gf=im->gdes[i].gf;
      gdp->linewidth=im->gdes[i].linewidth;
      dprintfparsed("found matching LINE/AREA at %li with type %u\n",i,im->gdes[i].gf);
      break;
    default: break;
    }
  }
  /* error the unhandled */
  if (gdp->gf==gf) {
    rrd_set_error("No previous LINE or AREA found for %s",pa->arg_orig); return 1;}

  /* debug output */
  dprintf("=================================\n");
  dprintf("STACK : %s\n",pa->arg_orig);
  if (gdp->vidx<0) {
    dprintf("VAL   : %g\n",gdp->yrule);
  } else {
    dprintf("VNAME : %s (%li)\n",gdp->vname,gdp->vidx);
  }
  dprintf("COLOR : r=%g g=%g b=%g a=%g\n",
	  gdp->col.red,gdp->col.green,gdp->col.blue,gdp->col.alpha);
  dprintf("COLOR2: r=%g g=%g b=%g a=%g\n",
	  gdp->col2.red,gdp->col2.green,gdp->col2.blue,gdp->col2.alpha);
  dprintf("LEGEND: \"%s\"\n",gdp->legend);
  dprintf("STACK : %i\n",gdp->stack);
  dprintf("WIDTH : %g\n",gdp->linewidth);
  dprintf("XAXIS : %i\n",gdp->xaxisidx);
  dprintf("YAXIS : %i\n",gdp->yaxisidx);
  dprintf("DASHES: TODI\n");
  dprintf("=================================\n");

  /* shift the legend by 2 spaces for the "coloured-box"*/
  legend_shift(gdp->legend);

  /* and return fine */
  return 0;
}
Exemplo n.º 6
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;
}
Exemplo n.º 7
0
static int parse_hvrule(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_VNAMECOLORLEGEND
					|PARSE_VNAMEREFNUM
					|PARSE_XAXIS
					|PARSE_YAXIS
					|PARSE_DASHES
					);
  if (!gdp) { return 1;}

  /* debug output */
  dprintf("=================================\n");
  if (gf==GF_VRULE) {
    dprintf("VRULE : %s\n",pa->arg_orig);
  } else {
    dprintf("HRULE : %s\n",pa->arg_orig);
  }
  if (gdp->vidx<0) {
    if (gf==GF_VRULE) {
      dprintf("VAL   : %lld\n",(long long)gdp->xrule);
    } else {
      dprintf("VAL   : %g\n",gdp->yrule);
    }
  } else {
    dprintf("VNAME : %s (%li)\n",gdp->vname,gdp->vidx);
  }
  dprintf("COLOR : r=%g g=%g b=%g a=%g\n",
	  gdp->col.red,gdp->col.green,gdp->col.blue,gdp->col.alpha);
  dprintf("COLOR2: r=%g g=%g b=%g a=%g\n",
	  gdp->col2.red,gdp->col2.green,gdp->col2.blue,gdp->col2.alpha);
  dprintf("LEGEND: \"%s\"\n",gdp->legend);
  dprintf("DASHES: TODO\n");
  dprintf("XAXIS : %i\n",gdp->xaxisidx);
  dprintf("YAXIS : %i\n",gdp->yaxisidx);
  dprintf("=================================\n");

  /* shift the legend by 2 spaces for the "coloured-box"*/
  legend_shift(gdp->legend);

  /* check that vidx is of type VDEF */
  if (gdp->vidx != -1 && im->gdes[gdp->vidx].gf != GF_VDEF) {
    rrd_set_error("Using vname %s of wrong type in line %s\n",
		  gdp->vname,pa->arg_orig);
    return 1;
  }


  /* and return fine */
  return 0;
}
Exemplo n.º 8
0
static int parse_line(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_VNAMECOLORLEGEND
					|PARSE_STACK
                                        |PARSE_SKIPSCALE
					|PARSE_LINEWIDTH
					|PARSE_DASHES
					|PARSE_XAXIS
					|PARSE_YAXIS
					);
  if (!gdp) { return 1;}

  /* debug output */
  dprintf("=================================\n");
  dprintf("LINE  : %s\n",pa->arg_orig);
  if (gdp->vidx<0) {
    dprintf("VAL   : %g\n",gdp->yrule);
  } else {
    dprintf("VNAME : %s (%li)\n",gdp->vname,gdp->vidx);
  }
  dprintf("COLOR : r=%g g=%g b=%g a=%g\n",
	  gdp->col.red,gdp->col.green,gdp->col.blue,gdp->col.alpha);
  dprintf("COLOR2: r=%g g=%g b=%g a=%g\n",
	  gdp->col2.red,gdp->col2.green,gdp->col2.blue,gdp->col2.alpha);
  dprintf("LEGEND: \"%s\"\n",gdp->legend);
  dprintf("STACK : %i\n",gdp->stack);
  dprintf("SKIPSCALE : %i\n",gdp->skipscale);
  dprintf("WIDTH : %g\n",gdp->linewidth);
  dprintf("XAXIS : %i\n",gdp->xaxisidx);
  dprintf("YAXIS : %i\n",gdp->yaxisidx);
  if (gdp->ndash) {
    dprintf("DASHES: %i - %g",gdp->ndash,gdp->p_dashes[0]);
    for(int i=1;i<gdp->ndash;i++){dprintf(", %g",gdp->p_dashes[i]);}
    dprintf("\n");
  }
  dprintf("=================================\n");

  /* shift the legend by 2 spaces for the "coloured-box"*/
  legend_shift(gdp->legend);

  /* and return fine */
  return 0;
}
Exemplo n.º 9
0
int parse_comment(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_LEGEND
					); 
  if (!gdp) { return 1;}

  /* and if we have no legend, then use the first positional one */
  if (gdp->legend[0]==0) {
    keyvalue_t* first=getFirstUnusedArgument(1,pa);
    if (first) {
      strncpy(gdp->legend,first->value,FMT_LEG_LEN);      
    } else { rrd_set_error("No positional CF/FORMAT"); return 1; }    
  }
  /* debug output */
  dprintf("=================================\n");
  dprintf("COMMENT : %s\n",pa->arg_orig);
  dprintf("LEGEND  : %s\n",gdp->legend);
  /* and return */
  return 0;
}
Exemplo n.º 10
0
static int parse_tick(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_VNAMECOLORFRACTIONLEGEND
					);
  if (!gdp) { return 1;}
  /* debug output */
  dprintf("=================================\n");
  dprintf("TICK  : %s\n",pa->arg_orig);
  dprintf("VNAME : %s (%li)\n",gdp->vname,gdp->vidx);
  dprintf("COLOR : r=%g g=%g b=%g a=%g\n",
	  gdp->col.red,gdp->col.green,gdp->col.blue,gdp->col.alpha);
  if (gdp->cf==CF_LAST) {
    dprintf("FRAC  : %s\n",gdp->vname);
  } else {
    dprintf("FRAC  : %g\n",gdp->yrule);
  }
  dprintf("LEGEND: \"%s\"\n",gdp->legend);
  dprintf("XAXIS : %i\n",gdp->xaxisidx);
  dprintf("YAXIS : %i\n",gdp->yaxisidx);
  dprintf("=================================\n");
  /* and return */
  return 0;
}
Exemplo n.º 11
0
static int parse_def(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_VNAMERRDDSCF
					|PARSE_START
					|PARSE_STEP
					|PARSE_END
					|PARSE_REDUCE
					|PARSE_DAEMON
					);
  /* retry in case of errors modifying the name*/
  if (!gdp) {
	  /* restart from scratch */
	  resetParsedArguments(pa);
	  /* get the first parameter */
	  keyvalue_t *first= getFirstUnusedArgument(0,pa);
	  /* if it is any of the "original" positional args, then we terminate immediately */
	  for(int i=0;i<10;i++){
		  if (poskeys[i] == first->key) {
			  return -1;
		  }
	  }
	  /* otherwise we patch the key */
	  *(first->key)+=128;

	  /* and keep a copy of the error */
	  char original_error[4096];
	  strncpy(original_error,rrd_get_error(),sizeof(original_error) - 1);
	  /* and clear the error */
	  rrd_clear_error();

	  /* now run it */
	  gdp=newGraphDescription(im,gf,pa,
					PARSE_VNAMERRDDSCF
					|PARSE_START
					|PARSE_STEP
					|PARSE_END
					|PARSE_REDUCE
					|PARSE_DAEMON
				        |PARSE_RETRY
					);
	  /* on error, we restore the original error and return */
	  if (!gdp) {
		  rrd_set_error(original_error);
		  return 1;
	  }
  }

  if (gdp->step == 0){
      gdp->step = im->step; /* initialize with image wide step */
  }

  /* debugging output */
  dprintf("=================================\n");
  dprintf("DEF   : %s\n",pa->arg_orig);
  dprintf("VNAME : %s\n",gdp->vname);
  dprintf("RRD   : %s\n",gdp->rrd);
  dprintf("DS    : %s\n",gdp->ds_nam);
  dprintf("CF    : %i\n",gdp->cf);
  dprintf("START : (%lld)\n",(long long int)gdp->start);
  dprintf("STEP  : (%lld)\n",(long long int)gdp->step);
  dprintf("END   : (%lld)\n",(long long int)gdp->end);
  dprintf("REDUCE: (%i)\n",gdp->cf_reduce);
  dprintf("DAEMON: %s\n",gdp->daemon);
  dprintf("=================================\n");

  /* and return fine */
  return 0;
}
Exemplo n.º 12
0
static int parse_shift(enum gf_en gf,parsedargs_t* pa,image_desc_t *const im) {
  keyvalue_t *kv;
  /* get new graph that we fill */
  graph_desc_t *gdp=newGraphDescription(im,gf,pa,PARSE_VNAMEREFPOS);
  if (!gdp) { return 1;}
  /* and check that it is a CDEF */
  switch (im->gdes[gdp->vidx].gf) {
  case GF_DEF:
  case GF_CDEF:
    dprintf("- vname is of type DEF or CDEF, OK\n");
    break;
  case GF_VDEF:
    rrd_set_error("Cannot shift a VDEF: '%s' in line '%s'\n",
		  im->gdes[gdp->vidx].vname, pa->arg_orig);
    return 1;
  default:
    rrd_set_error("Encountered unknown type variable '%s' in line '%s'",
		  im->gdes[gdp->vidx].vname, pa->arg_orig);
    return 1;
  }

  /* now parse the "shift" */
  char* shift=getKeyValueArgument("shift",1,pa);
  if (!shift) {
    kv=getFirstUnusedArgument(1,pa);
    if (kv) shift=kv->value;
  }
  if (!shift) { rrd_set_error("No shift given"); return 1; }
  /* identify shift */
  gdp->shidx=find_var(im, shift);
  if (gdp->shidx>=0) {
    /* it is a def, so let us check its type*/
    switch (im->gdes[gdp->shidx].gf) {
    case GF_DEF:
    case GF_CDEF:
      rrd_set_error("Offset cannot be a (C)DEF: '%s' in line '%s'\n",
		    im->gdes[gdp->shidx].vname, pa->arg_orig);
      return 1;
    case GF_VDEF:
      dprintf("- vname is of type VDEF, OK\n");
      break;
    default:
            rrd_set_error
	      ("Encountered unknown type variable '%s' in line '%s'",
	       im->gdes[gdp->vidx].vname, pa->arg_orig);
            return 1;
    }
  } else {
    /* it is no def, so parse as number */
    long val;
    char *x;
    int f=getLong(shift,&val,&x,10);
    if (f) { rrd_set_error("error parsing number %s",shift); return 1; }
    gdp->shval = val;
    gdp->shidx = -1;
  }

  /* debug output */
  dprintf("=================================\n");
  dprintf("SHIFT   : %s\n",pa->arg_orig);
  dprintf("VNAME   : %s (%li)\n",im->gdes[gdp->vidx].vname,gdp->vidx);
  if (gdp->shidx>=0) {
    dprintf("SHIFTBY : %s (%i)\n",im->gdes[gdp->shidx].vname,gdp->shidx);
  } else {
    dprintf("SHIFTBY : %li\n",gdp->shval);
  }
  dprintf("=================================\n");
  /* and return */
  return 0;
}
Exemplo n.º 13
0
static int parse_gprint(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_VNAMEREF
					|PARSE_CF
					|PARSE_FORMAT
					|PARSE_STRFTIMEVFMT
					);
  if (!gdp) { return 1;}
   /* here we parse pos arguments locally */
  /* vname */
  if (gdp->vname[0]==0) {
    dprintfparsed("Processing positional vname\n");
    keyvalue_t* first=getFirstUnusedArgument(1,pa);
    if (first) {
      strncpy(gdp->vname,first->keyvalue,MAX_VNAME_LEN);
      gdp->vname[MAX_VNAME_LEN] = '\0';
      /* get type of reference */
      gdp->vidx=find_var(im, gdp->vname);
      if (gdp->vidx<0) {
	rrd_set_error("undefined vname %s",gdp->vname); return 1; }
    } else { rrd_set_error("No positional VNAME"); return 1; }
  }
  /* check type of ref in general */
  enum gf_en vnamegf=im->gdes[gdp->vidx].gf;
  dprintfparsed("Processing referenced type %i\n",vnamegf);
  switch (vnamegf) {
    /* deprecated */
  case GF_DEF:
  case GF_CDEF:
    dprintfparsed("Processing positional CF\n");
    /* look for CF if not given */
    if (((int)gdp->cf)==-1) {
      keyvalue_t* first=getFirstUnusedArgument(1,pa);
      if (first) {
	gdp->cf=cf_conv(first->value);
	if (((int)gdp->cf)==-1) {
	  rrd_set_error("bad CF for DEF/CDEF: %s",first->value); return 1; }
      } else { rrd_set_error("No positional CDEF"); return 1; }
    }
    break;
  case GF_VDEF:
    break;
  default:
    rrd_set_error("Encountered unknown type variable '%s'",
		  im->gdes[gdp->vidx].vname);
    return 1;
  }
  /* and get positional format */
  if (gdp->format[0]==0) {
    dprintfparsed("Processing positional format\n");
    keyvalue_t* first=getFirstUnusedArgument(1,pa);
    if (first) {
      strncpy(gdp->format,first->keyvalue,FMT_LEG_LEN);
      dprintfparsed("got positional format: %s\n",gdp->format);
    } else { rrd_set_error("No positional CF/FORMAT"); return 1; }
  }
  /* debug output */
  dprintf("=================================\n");
  if (gf==GF_GPRINT) {
    dprintf("GPRINT : %s\n",pa->arg_orig);
  } else {
    dprintf("PRINT  : %s\n",pa->arg_orig);
  }
  dprintf("VNAME : %s (%li)\n",gdp->vname,gdp->vidx);
  if ((int)gdp->cf>-1) {
    dprintf("CF : (%u)\n",gdp->cf);
  }
  dprintf("FORMAT: \"%s\"\n",gdp->legend);
  dprintf("=================================\n");

  /* and return */
  return 0;
}