+ 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 %0.0f,%0.0f,%0.0f,%0.0f\n", gdp->col.red,
+ gdp->col.green, gdp->col.blue, gdp->col.alpha);
+ 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)
+ || (gdp->gf == GF_TICK)
+ )
+ return 0;
+
+ dprintf("- parsing '%s'\n", &line[*eaten]);
+ if (line[*eaten] != '\0') {
+ dprintf("- still more, should be STACK\n");
+ j = scan_for_col(&line[*eaten], 5, tmpstr);
+ if (line[*eaten + j] != '\0' && line[*eaten + j] != ':') {
+ /* not 5 chars */
+ rrd_set_error("STACK expected and not found");
+ return 1;
+ }
+ if (!strcmp("STACK", tmpstr)) {
+ dprintf("- found STACK\n");
+ gdp->stack = 1;
+ (*eaten) += j;
+ } else {
+ rrd_set_error("STACK expected and not found");
+ return 1;
+ }
+ }
+ if (line[*eaten] == '\0') {
+ dprintf("- done parsing line\n");
+ return 0;
+ }
+ (*eaten)++;
+ dprintf("- parsing '%s'\n", &line[*eaten]);
+