-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);
- } else {
- 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)
+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) {