-int
-rrd_parse_PVHLAST(char *line, unsigned int *eaten, graph_desc_t *gdp, image_desc_t *im) {
- int i,j;
- int colorfound=0;
- char tmpstr[MAX_VNAME_LEN + 10]; /* vname#RRGGBBAA\0 */
-
- dprintf("- parsing '%s'\n",&line[*eaten]);
- dprintf("- from line '%s'\n",line);
-
- i=scan_for_col(&line[*eaten],MAX_VNAME_LEN+9,tmpstr);
- if (line[*eaten+i]!='\0' && line[*eaten+i]!=':') {
- rrd_set_error("Cannot parse line '%s'",line);
- return 1;
- }
-
- j=i; while (j>0 && tmpstr[j]!='#') j--;
-
- if (tmpstr[j]=='#') {
- if (rrd_parse_color(&tmpstr[j],gdp)) {
- rrd_set_error("Could not parse color in '%s'",tmpstr[j]);
- return 1;
- }
- tmpstr[j]='\0';
- dprintf("- parsed color 0x%08x\n",(unsigned int)gdp->col);
- colorfound=1;
- }
-
- dprintf("- examining '%s'\n",tmpstr);
- j=0;
- if (gdp->gf == GF_VRULE) {
- sscanf(tmpstr,"%li%n",&gdp->xrule,&j);
- if (j) dprintf("- found time: %li\n",gdp->xrule);
+int rrd_parse_PVHLAST(
+ const char *const line,
+ unsigned int *const eaten,
+ graph_desc_t *const gdp,
+ image_desc_t *const im)
+{
+ int i, j, k;
+ int colorfound = 0;
+ char tmpstr[MAX_VNAME_LEN + 10]; /* vname#RRGGBBAA\0 */
+ static int spacecnt = 0;
+
+ if (spacecnt == 0) {
+ float one_space = gfx_get_text_width(im, 0,
+ im->
+ text_prop[TEXT_PROP_LEGEND].
+ font,
+ im->
+ text_prop[TEXT_PROP_LEGEND].
+ size,
+ im->tabwidth, " ") / 4.0;
+ float target_space = gfx_get_text_width(im, 0,
+ im->
+ text_prop
+ [TEXT_PROP_LEGEND].font,
+ im->
+ text_prop
+ [TEXT_PROP_LEGEND].size,
+ im->tabwidth, "oo");
+
+ spacecnt = target_space / one_space;
+ dprintf("- spacecnt: %i onespace: %f targspace: %f\n", spacecnt,
+ one_space, target_space);
+ }
+
+
+ dprintf("- parsing '%s'\n", &line[*eaten]);
+
+ /* have simpler code in the drawing section */
+ if (gdp->gf == GF_STACK) {
+ gdp->stack = 1;
+ }
+
+ i = scan_for_col(&line[*eaten], MAX_VNAME_LEN + 9, tmpstr);
+ if (line[*eaten + i] != '\0' && line[*eaten + i] != ':') {
+ rrd_set_error("Cannot parse line '%s'", line);
+ return 1;
+ }
+
+ j = i;
+ while (j > 0 && tmpstr[j] != '#')
+ j--;
+
+ if (j) {
+ tmpstr[j] = '\0';
+ }
+ /* We now have:
+ * tmpstr[0] containing vname
+ * tmpstr[j] if j!=0 then containing color
+ * i size of vname + color
+ * j if j!=0 then size of vname
+ */
+
+ /* Number or vname ?
+ * If it is an existing vname, that's OK, provided that it is a
+ * valid type (need time for VRULE, not a float)
+ * Else see if it parses as a number.
+ */
+ dprintf("- examining string '%s'\n", tmpstr);
+ if ((gdp->vidx = find_var(im, tmpstr)) >= 0) {
+ dprintf("- found vname: '%s' vidx %li\n", tmpstr, gdp->vidx);
+ switch (gdp->gf) {
+ case GF_VRULE:
+ case GF_HRULE:
+ if (im->gdes[gdp->vidx].gf != GF_VDEF) {
+ rrd_set_error("Using vname %s of wrong type in line %s\n",
+ im->gdes[gdp->gf].vname, line);
+ return 1;
+ }
+ break;
+ default:;
+ }
+ } else {
+ long time_tmp = 0;
+
+ dprintf("- it is not an existing vname\n");
+ switch (gdp->gf) {
+ case GF_VRULE:
+ k = 0;
+ sscanf(tmpstr, "%li%n", &time_tmp, &k);
+ gdp->xrule = time_tmp;
+ 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: %lf\n", gdp->yrule);
+ } else {
+ dprintf("- is is not a valid number: %lf\n", gdp->yrule);
+ 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 %0.0f,%0.0f,%0.0f,%0.0f\n", gdp->col.red,
+ gdp->col.green, gdp->col.blue, gdp->col.alpha);
+ colorfound = 1;