Attached a patch for the rrd-tool LIBDBI integration with the following improvements:
[rrdtool.git] / src / rrd_graph_helper.c
index d4b3732..b5be2ef 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
- * RRDtool 1.2.99907080300  Copyright by Tobi Oetiker, 1997-2007
+ * RRDtool 1.3.2  Copyright by Tobi Oetiker, 1997-2008
  ****************************************************************************
  * rrd_graph_helper.c  commandline parser functions 
  *                     this code initially written by Alex van den Bogaerdt
@@ -516,10 +516,10 @@ int rrd_parse_textalign(
 }
 
 
-/* Parsing of PART, VRULE, HRULE, LINE, AREA, STACK and TICK
+/* Parsing of VRULE, HRULE, LINE, AREA, STACK and TICK
 ** is done in one function.
 **
-** Stacking PART, VRULE, HRULE or TICK is not allowed.
+** Stacking VRULE, HRULE or TICK is not allowed.
 **
 ** If a number (which is valid to enter) is more than a
 ** certain amount of characters, it is caught as an error.
@@ -541,18 +541,12 @@ int rrd_parse_PVHLAST(
         float     one_space = gfx_get_text_width(im, 0,
                                                  im->
                                                  text_prop[TEXT_PROP_LEGEND].
-                                                 font,
-                                                 im->
-                                                 text_prop[TEXT_PROP_LEGEND].
-                                                 size,
+                                                 font_desc,
                                                  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,
+                                                    [TEXT_PROP_LEGEND].font_desc,
                                                     im->tabwidth, "oo");
 
         spacecnt = target_space / one_space;
@@ -739,7 +733,7 @@ int rrd_parse_PVHLAST(
     }
     (*eaten)++;         /* after colon */
 
-    /* PART, HRULE, VRULE and TICK cannot be stacked. */
+    /* HRULE, VRULE and TICK cannot be stacked. */
     if ((gdp->gf != GF_HRULE)
         && (gdp->gf != GF_VRULE)
         && (gdp->gf != GF_TICK)) {
@@ -764,78 +758,76 @@ int rrd_parse_PVHLAST(
             dprintf("- not STACKing\n");
     }
 
-    dprintf("- still more, should be DASHED[:...]\n");
+    dprintf("- still more, should be dashes[=...]\n");
     dprintf("- parsing '%s'\n", &line[*eaten]);
     if (line[*eaten] != '\0') {
-        // parse dash arguments here. Possible options:
-        // DASHED
-        // DASHED:dashes=n_on,n_off,n_on,n_off
-        // DASHED:dashes=n_on,n_off,n_on,n_off:dash-offset=offset
-        // start with DASHED
-        j = scan_for_col(&line[*eaten], 6, tmpstr);
-        if (!strcmp("DASHED", tmpstr)) {
+        /* parse dash arguments here. Possible options:
+           - dashes
+           - dashes=n_on[,n_off[,n_on,n_off]]
+           - dashes[=n_on[,n_off[,n_on,n_off]]]:dash-offset=offset
+           allowing 64 characters for definition of dash style */
+        j = scan_for_col(&line[*eaten], 64, tmpstr);
+        /* start with dashes */
+        if (strcmp(tmpstr, "dashes") == 0) {
+            /* if line was "dashes" or "dashes:dash-offset=xdashes="
+               tmpstr will be "dashes" */
             dprintf("- found %s\n", tmpstr);
-            // initialise all required variables we need for dashed lines
-            // using default dash length of 5 pixels
+            /* initialise all required variables we need for dashed lines
+               using default dash length of 5 pixels */
             gdp->dash = 1;
             gdp->p_dashes = (double *) malloc(sizeof(double));
             gdp->p_dashes[0] = 5;
             gdp->ndash = 1;
             gdp->offset = 0;
             (*eaten) += j;
-            if (line[*eaten] == ':')
-                (*eaten) += 1;
-        }
-        if (line[*eaten] == '\0') {
-            dprintf("- done parsing line\n");
-            return 0;
-        }
-        // DASHED:dashes=n_on,n_off,n_on,n_off
-        // allowing 64 characters for definition of dash style
-        j = scan_for_col(&line[*eaten], 64, tmpstr);
-        if (sscanf(tmpstr, "dashes=%s", tmpstr)) {
+        } else if (sscanf(tmpstr, "dashes=%s", tmpstr)) {
+            /* dashes=n_on[,n_off[,n_on,n_off]] */
             char      csv[64];
             char     *pch;
             float     dsh;
+            int       count = 0;
+            char     *saveptr;
 
             strcpy(csv, tmpstr);
-            int       count = 0;
 
-            pch = strtok(tmpstr, ",");
+            pch = strtok_r(tmpstr, ",", &saveptr);
             while (pch != NULL) {
-                pch = strtok(NULL, ",");
+                pch = strtok_r(NULL, ",", &saveptr);
                 count++;
             }
-            dprintf("- %d dash values found: ", count);
-            gdp->ndash = count;
-            if (gdp->p_dashes != NULL)
-                free(gdp->p_dashes);
-            gdp->p_dashes = (double *) malloc(sizeof(double) * count);
-            pch = strtok(csv, ",");
-            count = 0;
-            while (pch != NULL) {
-                if (sscanf(pch, "%f", &dsh)) {
-                    gdp->p_dashes[count] = (double) dsh;
-                    dprintf("%.1f ", gdp->p_dashes[count]);
-                    count++;
+            dprintf("- %d dash value(s) found: ", count);
+            if (count > 0) {
+                gdp->dash = 1;
+                gdp->ndash = count;
+                gdp->p_dashes = (double *) malloc(sizeof(double) * count);
+                pch = strtok_r(csv, ",", &saveptr);
+                count = 0;
+                while (pch != NULL) {
+                    if (sscanf(pch, "%f", &dsh)) {
+                        gdp->p_dashes[count] = (double) dsh;
+                        dprintf("%.1f ", gdp->p_dashes[count]);
+                        count++;
+                    }
+                    pch = strtok_r(NULL, ",", &saveptr);
                 }
-                pch = strtok(NULL, ",");
-            }
-            dprintf("\n");
+                dprintf("\n");
+            } else
+                dprintf("- syntax error. No dash lengths found!\n");
             (*eaten) += j;
-            if (line[*eaten] == ':')
-                (*eaten) += 1;
-        }
-        if (line[*eaten] == '\0') {
+        } else
+            dprintf("- error: expected dashes[=...], found %s\n", tmpstr);
+        if (line[*eaten] == ':') {
+            (*eaten) += 1;
+        } else if (line[*eaten] == '\0') {
             dprintf("- done parsing line\n");
             return 0;
         }
-        // DASHED:dashes=n_on,n_off,n_on,n_off:dash-offset=offset
-        // allowing 16 characters for dash-offset=....
-        // => 4 characters for the offset value
+        /* dashes[=n_on[,n_off[,n_on,n_off]]]:dash-offset=offset
+           allowing 16 characters for dash-offset=....
+           => 4 characters for the offset value */
         j = scan_for_col(&line[*eaten], 16, tmpstr);
         if (sscanf(tmpstr, "dash-offset=%lf", &gdp->offset)) {
-            dprintf("- found %s\n", tmpstr);
+            dprintf("- found dash-offset=%.1f\n", gdp->offset);
             gdp->dash = 1;
             (*eaten) += j;
             if (line[*eaten] == ':')
@@ -891,7 +883,7 @@ int rrd_parse_def(
     int       i = 0;
     char      command[7];   /* step, start, end, reduce */
     char      tmpstr[256];
-    struct rrd_time_value start_tv, end_tv;
+    rrd_time_value_t start_tv, end_tv;
     time_t    start_tmp = 0, end_tmp = 0;
     char     *parsetime_error = NULL;
 
@@ -953,7 +945,7 @@ int rrd_parse_def(
         } else if (!strcmp("start", command)) {
             i = scan_for_col(&line[*eaten], 255, tmpstr);
             (*eaten) += i;
-            if ((parsetime_error = parsetime(tmpstr, &start_tv))) {
+            if ((parsetime_error = rrd_parsetime(tmpstr, &start_tv))) {
                 rrd_set_error("start time: %s", parsetime_error);
                 return 1;
             }
@@ -961,7 +953,7 @@ int rrd_parse_def(
         } else if (!strcmp("end", command)) {
             i = scan_for_col(&line[*eaten], 255, tmpstr);
             (*eaten) += i;
-            if ((parsetime_error = parsetime(tmpstr, &end_tv))) {
+            if ((parsetime_error = rrd_parsetime(tmpstr, &end_tv))) {
                 rrd_set_error("end time: %s", parsetime_error);
                 return 1;
             }
@@ -980,8 +972,8 @@ int rrd_parse_def(
         }
         (*eaten)++;
     }
-    if (proc_start_end(&start_tv, &end_tv, &start_tmp, &end_tmp) == -1) {
-        /* error string is set in parsetime.c */
+    if (rrd_proc_start_end(&start_tv, &end_tv, &start_tmp, &end_tmp) == -1) {
+        /* error string is set in rrd_parsetime.c */
         return 1;
     }
     if (start_tmp < 3600 * 24 * 365 * 10) {