fixed indentation
[rrdtool.git] / src / rrd_graph_helper.c
index 06a0ed1..0a6fabc 100644 (file)
 int       rrd_parse_find_gf(
     const char *const,
     unsigned int *const,
-    graph_desc_t * const);
+    graph_desc_t *const);
+
 int       rrd_parse_legend(
     const char *const,
     unsigned int *const,
-    graph_desc_t * const);
+    graph_desc_t *const);
+
 int       rrd_parse_color(
     const char *const,
-    graph_desc_t * const);
+    graph_desc_t *const);
+
+int       rrd_parse_textalign(
+    const char *const,
+    unsigned int *const,
+    graph_desc_t *const);
+
+
 int       rrd_parse_CF(
     const char *const,
     unsigned int *const,
-    graph_desc_t * const,
+    graph_desc_t *const,
     enum cf_en *const);
+
 int       rrd_parse_print(
     const char *const,
     unsigned int *const,
-    graph_desc_t * const,
-    image_desc_t * const);
+    graph_desc_t *const,
+    image_desc_t *const);
+
 int       rrd_parse_shift(
     const char *const,
     unsigned int *const,
-    graph_desc_t * const,
-    image_desc_t * const);
+    graph_desc_t *const,
+    image_desc_t *const);
+
 int       rrd_parse_xport(
     const char *const,
     unsigned int *const,
-    graph_desc_t * const,
-    image_desc_t * const);
+    graph_desc_t *const,
+    image_desc_t *const);
+
 int       rrd_parse_PVHLAST(
     const char *const,
     unsigned int *const,
-    graph_desc_t * const,
-    image_desc_t * const);
+    graph_desc_t *const,
+    image_desc_t *const);
+
 int       rrd_parse_make_vname(
     const char *const,
     unsigned int *const,
-    graph_desc_t * const,
-    image_desc_t * const);
+    graph_desc_t *const,
+    image_desc_t *const);
+
 int       rrd_parse_find_vname(
     const char *const,
     unsigned int *const,
-    graph_desc_t * const,
-    image_desc_t * const);
+    graph_desc_t *const,
+    image_desc_t *const);
+
 int       rrd_parse_def(
     const char *const,
     unsigned int *const,
-    graph_desc_t * const,
-    image_desc_t * const);
+    graph_desc_t *const,
+    image_desc_t *const);
+
 int       rrd_parse_vdef(
     const char *const,
     unsigned int *const,
-    graph_desc_t * const,
-    image_desc_t * const);
+    graph_desc_t *const,
+    image_desc_t *const);
+
 int       rrd_parse_cdef(
     const char *const,
     unsigned int *const,
-    graph_desc_t * const,
-    image_desc_t * const);
-
-
+    graph_desc_t *const,
+    image_desc_t *const);
 
 int rrd_parse_find_gf(
     const char *const line,
     unsigned int *const eaten,
-    graph_desc_t * const gdp)
+    graph_desc_t *const gdp)
 {
     char      funcname[11], c1 = 0;
     int       i = 0;
@@ -207,7 +223,7 @@ int rrd_parse_find_gf(
 int rrd_parse_legend(
     const char *const line,
     unsigned int *const eaten,
-    graph_desc_t * const gdp)
+    graph_desc_t *const gdp)
 {
     int       i;
 
@@ -230,7 +246,7 @@ int rrd_parse_legend(
 
 int rrd_parse_color(
     const char *const string,
-    graph_desc_t * const gdp)
+    graph_desc_t *const gdp)
 {
     unsigned int r = 0, g = 0, b = 0, a = 0, i;
 
@@ -266,14 +282,14 @@ int rrd_parse_color(
     default:
         return 1;       /* wrong number of digits */
     }
-    gdp->col = r << 24 | g << 16 | b << 8 | a;
+    gdp->col = gfx_hex_to_col(r << 24 | g << 16 | b << 8 | a);
     return 0;
 }
 
 int rrd_parse_CF(
     const char *const line,
     unsigned int *const eaten,
-    graph_desc_t * const gdp,
+    graph_desc_t *const gdp,
     enum cf_en *cf)
 {
     char      symname[CF_NAM_SIZE];
@@ -308,8 +324,8 @@ int rrd_parse_CF(
 int rrd_parse_find_vname(
     const char *const line,
     unsigned int *const eaten,
-    graph_desc_t * const gdp,
-    image_desc_t * const im)
+    graph_desc_t *const gdp,
+    image_desc_t *const im)
 {
     char      tmpstr[MAX_VNAME_LEN + 1];
     int       i;
@@ -343,8 +359,8 @@ int rrd_parse_find_vname(
 int rrd_parse_print(
     const char *const line,
     unsigned int *const eaten,
-    graph_desc_t * const gdp,
-    image_desc_t * const im)
+    graph_desc_t *const gdp,
+    image_desc_t *const im)
 {
     /* vname:CF:format in case of DEF-based vname
      ** vname:CF:format in case of CDEF-based vname
@@ -389,8 +405,8 @@ int rrd_parse_print(
 int rrd_parse_shift(
     const char *const line,
     unsigned int *const eaten,
-    graph_desc_t * const gdp,
-    image_desc_t * const im)
+    graph_desc_t *const gdp,
+    image_desc_t *const im)
 {
     int       i;
 
@@ -449,8 +465,8 @@ int rrd_parse_shift(
 int rrd_parse_xport(
     const char *const line,
     unsigned int *const eaten,
-    graph_desc_t * const gdp,
-    image_desc_t * const im)
+    graph_desc_t *const gdp,
+    image_desc_t *const im)
 {
     if ((gdp->vidx = rrd_parse_find_vname(line, eaten, gdp, im)) < 0)
         return 1;
@@ -475,6 +491,28 @@ int rrd_parse_xport(
     return 0;
 }
 
+int rrd_parse_textalign(
+    const char *const line,
+    unsigned int *const eaten,
+    graph_desc_t *const gdp)
+{
+    if (strcmp(&line[*eaten], "left") == 0) {
+        gdp->txtalign = TXA_LEFT;
+    } else if (strcmp(&line[*eaten], "right") == 0) {
+        gdp->txtalign = TXA_RIGHT;
+    } else if (strcmp(&line[*eaten], "justified") == 0) {
+        gdp->txtalign = TXA_JUSTIFIED;
+    } else if (strcmp(&line[*eaten], "center") == 0) {
+        gdp->txtalign = TXA_CENTER;
+    } else {
+        rrd_set_error("Unknown alignement type '%s'", &line[*eaten]);
+        return 1;
+    }
+    *eaten += strlen(&line[*eaten]);
+    return 0;
+}
+
+
 /* Parsing of PART, VRULE, HRULE, LINE, AREA, STACK and TICK
 ** is done in one function.
 **
@@ -488,8 +526,8 @@ int rrd_parse_xport(
 int rrd_parse_PVHLAST(
     const char *const line,
     unsigned int *const eaten,
-    graph_desc_t * const gdp,
-    image_desc_t * const im)
+    graph_desc_t *const gdp,
+    image_desc_t *const im)
 {
     int       i, j, k;
     int       colorfound = 0;
@@ -497,23 +535,22 @@ int rrd_parse_PVHLAST(
     static int spacecnt = 0;
 
     if (spacecnt == 0) {
-        float     one_space = gfx_get_text_width(im->canvas, 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, "    ",
-                                                 0) / 4.0;
-        float     target_space = gfx_get_text_width(im->canvas, 0,
+                                                 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", 0);
+                                                    im->tabwidth, "oo");
 
         spacecnt = target_space / one_space;
         dprintf("- spacecnt: %i onespace: %f targspace: %f\n", spacecnt,
@@ -607,7 +644,8 @@ int rrd_parse_PVHLAST(
             rrd_set_error("Could not parse color in '%s'", &tmpstr[j]);
             return 1;
         }
-        dprintf("- parsed color 0x%08x\n", (unsigned int) gdp->col);
+        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);
@@ -701,9 +739,6 @@ int rrd_parse_PVHLAST(
     /* PART, HRULE, VRULE and TICK cannot be stacked. */
     if ((gdp->gf == GF_HRULE)
         || (gdp->gf == GF_VRULE)
-#ifdef WITH_PIECHART
-        || (gdp->gf == GF_PART)
-#endif
         || (gdp->gf == GF_TICK)
         )
         return 0;
@@ -714,7 +749,7 @@ int rrd_parse_PVHLAST(
         j = scan_for_col(&line[*eaten], 5, tmpstr);
         if (line[*eaten + j] != '\0' && line[*eaten + j] != ':') {
             /* not 5 chars */
-            rrd_set_error("Garbage found where STACK expected");
+            rrd_set_error("STACK expected and not found");
             return 1;
         }
         if (!strcmp("STACK", tmpstr)) {
@@ -722,7 +757,7 @@ int rrd_parse_PVHLAST(
             gdp->stack = 1;
             (*eaten) += j;
         } else {
-            rrd_set_error("Garbage found where STACK expected");
+            rrd_set_error("STACK expected and not found");
             return 1;
         }
     }
@@ -739,8 +774,8 @@ int rrd_parse_PVHLAST(
 int rrd_parse_make_vname(
     const char *const line,
     unsigned int *const eaten,
-    graph_desc_t * const gdp,
-    image_desc_t * const im)
+    graph_desc_t *const gdp,
+    image_desc_t *const im)
 {
     char      tmpstr[MAX_VNAME_LEN + 10];
     int       i = 0;
@@ -765,8 +800,8 @@ int rrd_parse_make_vname(
 int rrd_parse_def(
     const char *const line,
     unsigned int *const eaten,
-    graph_desc_t * const gdp,
-    image_desc_t * const im)
+    graph_desc_t *const gdp,
+    image_desc_t *const im)
 {
     int       i = 0;
     char      command[7];   /* step, start, end, reduce */
@@ -890,8 +925,8 @@ int rrd_parse_def(
 int rrd_parse_vdef(
     const char *const line,
     unsigned int *const eaten,
-    graph_desc_t * const gdp,
-    image_desc_t * const im)
+    graph_desc_t *const gdp,
+    image_desc_t *const im)
 {
     char      tmpstr[MAX_VNAME_LEN + 1];    /* vname\0 */
     int       i = 0;
@@ -928,8 +963,8 @@ int rrd_parse_vdef(
 int rrd_parse_cdef(
     const char *const line,
     unsigned int *const eaten,
-    graph_desc_t * const gdp,
-    image_desc_t * const im)
+    graph_desc_t *const gdp,
+    image_desc_t *const im)
 {
     dprintf("- parsing '%s'\n", &line[*eaten]);
     if (rrd_parse_make_vname(line, eaten, gdp, im))
@@ -947,7 +982,7 @@ int rrd_parse_cdef(
 void rrd_graph_script(
     int argc,
     char *argv[],
-    image_desc_t * const im,
+    image_desc_t *const im,
     int optno)
 {
     int       i;
@@ -975,6 +1010,10 @@ void rrd_graph_script(
             if (rrd_parse_shift(argv[i], &eaten, gdp, im))
                 return;
             break;
+        case GF_TEXTALIGN: /* left|right|center|justified */
+            if (rrd_parse_textalign(argv[i], &eaten, gdp))
+                return;
+            break;
         case GF_XPORT:
             if (rrd_parse_xport(argv[i], &eaten, gdp, im))
                 return;
@@ -989,9 +1028,6 @@ void rrd_graph_script(
             if (rrd_parse_legend(argv[i], &eaten, gdp))
                 return;
             break;
-#ifdef WITH_PIECHART
-        case GF_PART:  /* value[#color[:legend]] */
-#endif
         case GF_VRULE: /* value#color[:legend] */
         case GF_HRULE: /* value#color[:legend] */
         case GF_LINE:  /* vname-or-value[#color[:legend]][:STACK] */
@@ -1029,14 +1065,14 @@ void rrd_graph_script(
             break;
         }
         if (gdp->debug) {
-            dprintf("used %i out of %i chars\n", eaten, strlen(argv[i]));
+            dprintf("used %i out of %zi chars\n", eaten, strlen(argv[i]));
             dprintf("parsed line: '%s'\n", argv[i]);
             dprintf("remaining: '%s'\n", &argv[i][eaten]);
             if (eaten >= strlen(argv[i]))
                 dprintf("Command finished successfully\n");
         }
         if (eaten < strlen(argv[i])) {
-            rrd_set_error("Garbage '%s' after command:\n%s",
+            rrd_set_error("I don't understand '%s' in command: '%s'.",
                           &argv[i][eaten], argv[i]);
             return;
         }