-void
-rrd_graph_script(int argc, char *argv[], image_desc_t *im)
-{
- int i;
- char symname[100];
- int linepass = 0; /* stack must follow LINE*, AREA or STACK */
-
- for (i=optind+1;i<argc;i++) {
- int argstart=0;
- int strstart=0;
- graph_desc_t *gdp;
- char *line;
- char funcname[10],vname[MAX_VNAME_LEN+1],sep[1];
- double d;
- double linewidth;
- int j,k,l,m;
-
- /* Each command is one element from *argv[], we call this "line".
- **
- ** Each command defines the most current gdes inside struct im.
- ** In stead of typing "im->gdes[im->gdes_c-1]" we use "gdp".
- */
- gdes_alloc(im);
- gdp=&im->gdes[im->gdes_c-1];
- line=argv[i];
-
- /* function:newvname=string[:ds-name:CF] for xDEF
- ** function:vname[#color[:string]] for LINEx,AREA,STACK
- ** function:vname#color[:num[:string]] for TICK
- ** function:vname-or-num#color[:string] for xRULE,PART
- ** function:vname:CF:string for xPRINT
- ** function:string for COMMENT
- */
- argstart=0;
-
- sscanf(line, "%10[A-Z0-9]:%n", funcname,&argstart);
- if (argstart==0) {
- rrd_set_error("Cannot parse function in line: %s",line);
- im_free(im);
- return;
- }
- if(sscanf(funcname,"LINE%lf",&linewidth)){
- im->gdes[im->gdes_c-1].gf = GF_LINE;
- im->gdes[im->gdes_c-1].linewidth = linewidth;
- } else {
- if ((gdp->gf=gf_conv(funcname))==-1) {
- rrd_set_error("'%s' is not a valid function name",funcname);
- im_free(im);
- return;
- }
- }
-
- /* If the error string is set, we exit at the end of the switch */
- switch (gdp->gf) {
- case GF_COMMENT:
- if (rrd_graph_legend(gdp,&line[argstart])==0)
- rrd_set_error("Cannot parse comment in line: %s",line);
- break;
- case GF_PART:
- case GF_VRULE:
- case GF_HRULE:
- j=k=l=m=0;
- sscanf(&line[argstart], "%lf%n#%n", &d, &j, &k);
- sscanf(&line[argstart], DEF_NAM_FMT "%n#%n", vname, &l, &m);
- if (k+m==0) {
- rrd_set_error("Cannot parse name or num in line: %s",line);
- break;
- }
- if (j!=0) {
- gdp->xrule=d;
- gdp->yrule=d;
- argstart+=j;
- } else if (!rrd_graph_check_vname(im,vname,line)) {
- gdp->xrule=0;
- gdp->yrule=DNAN;
- argstart+=l;
- } else break; /* exit due to wrong vname */
- if ((j=rrd_graph_color(im,&line[argstart],line,0))==0) break;
- argstart+=j;
- if (strlen(&line[argstart])!=0) {
- if (rrd_graph_legend(gdp,&line[++argstart])==0)
- rrd_set_error("Cannot parse comment in line: %s",line);
- }
- break;
- case GF_STACK:
- if (linepass==0) {
- rrd_set_error("STACK must follow another graphing element");
- break;
- }
- case GF_LINE:
- case GF_AREA:
- case GF_TICK:
- j=k=0;
- linepass=1;
- sscanf(&line[argstart],DEF_NAM_FMT"%n%1[#:]%n",vname,&j,sep,&k);
- if (j+1!=k)
- rrd_set_error("Cannot parse vname in line: %s",line);
- else if (rrd_graph_check_vname(im,vname,line))
- rrd_set_error("Undefined vname '%s' in line: %s",line);
- else
- k=rrd_graph_color(im,&line[argstart],line,1);
- if (rrd_test_error()) break;
- argstart=argstart+j+k;
- if ((strlen(&line[argstart])!=0)&&(gdp->gf==GF_TICK)) {
- j=0;
- sscanf(&line[argstart], ":%lf%n", &gdp->yrule,&j);
- argstart+=j;
- }
- if (strlen(&line[argstart])!=0)
- if (rrd_graph_legend(gdp,&line[++argstart])==0)
- rrd_set_error("Cannot parse legend in line: %s",line);
- break;
- case GF_PRINT:
- im->prt_c++;
- case GF_GPRINT:
- j=0;
- sscanf(&line[argstart], DEF_NAM_FMT ":%n",gdp->vname,&j);
- if (j==0) {
- rrd_set_error("Cannot parse vname in line: '%s'",line);
- break;
- }
- argstart+=j;
- if (rrd_graph_check_vname(im,gdp->vname,line)) return;
- j=0;
- sscanf(&line[argstart], CF_NAM_FMT ":%n",symname,&j);
-
- k=(j!=0)?rrd_graph_check_CF(im,symname,line):1;
-#define VIDX im->gdes[gdp->vidx]
- switch (k) {
- case -1: /* looks CF but is not really CF */
- if (VIDX.gf == GF_VDEF) rrd_clear_error();
- break;
- case 0: /* CF present and correct */
- if (VIDX.gf == GF_VDEF)
- rrd_set_error("Don't use CF when printing VDEF");
- argstart+=j;
- break;
- case 1: /* CF not present */
- if (VIDX.gf == GF_VDEF) rrd_clear_error();
- else rrd_set_error("Printing DEF or CDEF needs CF");
- break;
- default:
- rrd_set_error("Oops, bug in GPRINT scanning");
- }
-#undef VIDX
- if (rrd_test_error()) break;
-
- if (strlen(&line[argstart])!=0) {
- if (rrd_graph_legend(gdp,&line[argstart])==0)
- rrd_set_error("Cannot parse legend in line: %s",line);
- } else rrd_set_error("No legend in (G)PRINT line: %s",line);
- strcpy(gdp->format, gdp->legend);
- break;
- case GF_DEF:
- case GF_VDEF:
- case GF_CDEF:
- j=0;
- sscanf(&line[argstart], DEF_NAM_FMT "=%n",gdp->vname,&j);
- if (j==0) {
- rrd_set_error("Could not parse line: %s",line);
- break;
- }
- if (find_var(im,gdp->vname)!=-1) {
- rrd_set_error("Variable '%s' in line '%s' already in use\n",
- gdp->vname,line);
- break;
- }
- argstart+=j;
- switch (gdp->gf) {
- case GF_DEF:
- argstart+=scan_for_col(&line[argstart],MAXPATH,gdp->rrd);
- j=k=0;
- sscanf(&line[argstart],
- ":" DS_NAM_FMT ":" CF_NAM_FMT "%n%*s%n",
- gdp->ds_nam, symname, &j, &k);
- if ((j==0)||(k!=0)) {
- rrd_set_error("Cannot parse DS or CF in '%s'",line);
- break;
- }
- rrd_graph_check_CF(im,symname,line);
- break;
- case GF_VDEF:
- j=0;
- sscanf(&line[argstart],DEF_NAM_FMT ",%n",vname,&j);
- if (j==0) {
- rrd_set_error("Cannot parse vname in line '%s'",line);
- break;
- }
- argstart+=j;
- if (rrd_graph_check_vname(im,vname,line)) return;
- 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->vname);
- break;
- }
- vdef_parse(gdp,&line[argstart+strstart]);
- break;
- case GF_CDEF:
- if (strstr(&line[argstart],":")!=NULL) {
- rrd_set_error("Error in RPN, line: %s",line);
- break;
- }
- if ((gdp->rpnp = rpn_parse(
- (void *)im,
- &line[argstart],
- &find_var_wrapper)
- )==NULL)
- rrd_set_error("invalid rpn expression in: %s",line);
- break;
- default: break;
- }
- break;
- default: rrd_set_error("Big oops");
- }
- if (rrd_test_error()) {
- im_free(im);
- return;
- }
- }
-
- if (im->gdes_c==0){
- rrd_set_error("can't make a graph without contents");
- im_free(im); /* ??? is this set ??? */
- return;
- }
-}