- sscanf(tmpstr,"%lf%n",&gdp->yrule,&j);
- if (j) dprintf("- found number: %f\n",gdp->yrule);
- }
- if (!j) {
- if ((gdp->vidx=find_var(im,tmpstr))<0) {
- rrd_set_error("Not a valid vname: %s in line %s",tmpstr,line);
- return 1;
- }
- dprintf("- found vname: '%s' vidx %li\n",tmpstr,gdp->vidx);
- }
- /* "*eaten" is still pointing to the original location,
- ** "*eaten +i" is pointing to the character after the color
- ** or to the terminating '\0' in which case we're finished.
- */
- if (line[*eaten+i]=='\0') {
- *eaten+=i;
- return 0;
- }
- *eaten+=++i;
-
- /* If a color is specified and the only remaining part is
- ** ":STACK" then it is assumed to be the legend. An empty
- ** legend can be specified as expected. This means the
- ** following can be done: LINE1:x#FF0000FF::STACK
- */
- if (colorfound) { /* no legend if no color */
- if (gdp->gf == GF_TICK) {
- dprintf("- looking for optional number\n");
- sscanf(&line[*eaten],"%lf%n",&gdp->yrule,&j);
- if (j) {
- dprintf("- found number %f\n",gdp->yrule);
- (*eaten)+=j;
- if (gdp->yrule > 1.0 || gdp->yrule < -1.0) {
- rrd_set_error("Tick factor should be <= 1.0");
- return 1;
- }
- if (line[*eaten] == ':')
- (*eaten)++;
- } else {
- dprintf("- not found, defaulting to 0.1\n");
- gdp->yrule=0.1;
- return 0;
- }
- }
- dprintf("- looking for optional legend\n");
- dprintf("- in '%s'\n",&line[*eaten]);
- /* the legend for a graph item must start with "m " the first
- m will then be over drawn with a color box. Since there
- is ample space I overwrite the first few characters of the line
- with the material that I want to see in the legend */
- if (line[*eaten] != '\0' && line[*eaten] != ':'){
- *eaten = *eaten - 2;
- line[*eaten] = 'm';
- line[*eaten+1] = ' ';
- }
- if (rrd_parse_legend(line, eaten, gdp)) return 1;
- }
-
- /* PART, HRULE, VRULE and TICK cannot be stacked. We're finished */
- if ( (gdp->gf == GF_HRULE)
- || (gdp->gf == GF_VRULE)
+ dprintf("- it is not an existing vname\n");
+ switch (gdp->gf) {
+ case GF_VRULE:
+ k = 0;
+ sscanf(tmpstr, "%li%n", &gdp->xrule, &k);
+ if (((j != 0) && (k == j)) || ((j == 0) && (k == i))) {
+ dprintf("- found time: %li\n", gdp->xrule);
+ } else {
+ dprintf("- is is not a valid number: %li\n", gdp->xrule);
+ rrd_set_error
+ ("parameter '%s' does not represent time in line %s\n",
+ tmpstr, line);
+ return 1;
+ }
+ default:
+ k = 0;
+ sscanf(tmpstr, "%lf%n", &gdp->yrule, &k);
+ if (((j != 0) && (k == j)) || ((j == 0) && (k == i))) {
+ dprintf("- found number: %f\n", gdp->yrule);
+ } else {
+ dprintf("- is is not a valid number: %li\n", gdp->xrule);
+ rrd_set_error
+ ("parameter '%s' does not represent a number in line %s\n",
+ tmpstr, line);
+ return 1;
+ }
+ }
+ }
+
+ if (j) {
+ j++;
+ dprintf("- examining color '%s'\n", &tmpstr[j]);
+ if (rrd_parse_color(&tmpstr[j], gdp)) {
+ rrd_set_error("Could not parse color in '%s'", &tmpstr[j]);
+ return 1;
+ }
+ dprintf("- parsed color 0x%08x\n", (unsigned int) gdp->col);
+ colorfound = 1;
+ } else {
+ dprintf("- no color present in '%s'\n", tmpstr);
+ }
+
+ (*eaten) += i; /* after vname#color */
+ if (line[*eaten] != '\0') {
+ (*eaten)++; /* after colon */
+ }
+
+ if (gdp->gf == GF_TICK) {
+ dprintf("- parsing '%s'\n", &line[*eaten]);
+ dprintf("- looking for optional TICK number\n");
+ j = 0;
+ sscanf(&line[*eaten], "%lf%n", &gdp->yrule, &j);
+ if (j) {
+ if (line[*eaten + j] != '\0' && line[*eaten + j] != ':') {
+ rrd_set_error("Cannot parse TICK fraction '%s'", line);
+ return 1;
+ }
+ dprintf("- found number %f\n", gdp->yrule);
+ if (gdp->yrule > 1.0 || gdp->yrule < -1.0) {
+ rrd_set_error("Tick factor should be <= 1.0");
+ return 1;
+ }
+ (*eaten) += j;
+ } else {
+ dprintf("- not found, defaulting to 0.1\n");
+ gdp->yrule = 0.1;
+ }
+ if (line[*eaten] == '\0') {
+ dprintf("- done parsing line\n");
+ return 0;
+ } else {
+ if (line[*eaten] == ':') {
+ (*eaten)++;
+ } else {
+ rrd_set_error("Can't make sense of that TICK line");
+ return 1;
+ }
+ }
+ }
+
+ dprintf("- parsing '%s'\n", &line[*eaten]);
+
+ /* Legend is next. A legend without a color is an error.
+ ** Stacking an item without having a legend is OK however
+ ** then an empty legend should be specified.
+ ** LINE:val#color:STACK means legend is string "STACK"
+ ** LINE:val#color::STACK means no legend, and do STACK
+ ** LINE:val:STACK is an error (legend but no color)
+ ** LINE:val::STACK means no legend, and do STACK
+ */
+ if (colorfound) {
+ int err = 0;
+ char *linecp = strdup(line);
+
+ dprintf("- looking for optional legend\n");
+
+ dprintf("- examining '%s'\n", &line[*eaten]);
+ if (linecp[*eaten] != '\0' && linecp[*eaten] != ':') {
+ int spi;
+
+ /* If the legend is not empty, it has to be prefixed with spacecnt ' ' characters. This then gets
+ * replaced by the color box later on. */
+ for (spi = 0; spi < spacecnt && (*eaten) > 1; spi++) {
+ linecp[--(*eaten)] = ' ';
+ }
+ }
+
+ if (rrd_parse_legend(linecp, eaten, gdp))
+ err = 1;
+ free(linecp);
+ if (err)
+ return 1;
+
+ dprintf("- found legend '%s'\n", &gdp->legend[2]);
+ } else {
+ dprintf("- skipping empty legend\n");
+ if (line[*eaten] != '\0' && line[*eaten] != ':') {
+ rrd_set_error("Legend set but no color: %s", &line[*eaten]);
+ return 1;
+ }
+ }
+ if (line[*eaten] == '\0') {
+ dprintf("- done parsing line\n");
+ return 0;
+ }
+ (*eaten)++; /* after colon */
+
+ /* PART, HRULE, VRULE and TICK cannot be stacked. */
+ if ((gdp->gf == GF_HRULE)
+ || (gdp->gf == GF_VRULE)