Code

fix use of %s in strftime rrdgraph (G)PRINT commands ... bug (#277) found by Denis...
[rrdtool-all.git] / program / src / rrd_graph.c
index 8f5f44f90b60a7c0c560dbfd8158d5d8c14a70ca..b9d954757fdfeb979371a677ede66a6a7fadf793 100644 (file)
@@ -1,4 +1,4 @@
-/****************************************************************************
+/****************************************************************************s
  * RRDtool 1.3.9  Copyright by Tobi Oetiker, 1997-2009
  ****************************************************************************
  * rrd__graph.c  produce graphs from data in rrdfiles
@@ -1520,7 +1520,7 @@ int print_calc(
                 }
             }           /* prepare printval */
 
-            if ((percent_s = strstr(im->gdes[i].format, "%S")) != NULL) {
+            if (!im->gdes[i].strftm && (percent_s = strstr(im->gdes[i].format, "%S")) != NULL) {
                 /* Magfact is set to -1 upon entry to print_calc.  If it
                  * is still less than 0, then we need to run auto_scale.
                  * Otherwise, put the value into the correct units.  If
@@ -1534,7 +1534,7 @@ int print_calc(
                     printval /= magfact;
                 }
                 *(++percent_s) = 's';
-            } else if (strstr(im->gdes[i].format, "%s") != NULL) {
+            } else if (!im->gdes[i].strftm && strstr(im->gdes[i].format, "%s") != NULL) {
                 auto_scale(im, &printval, &si_symb, &magfact);
             }
 
@@ -2005,7 +2005,7 @@ int draw_horizontal_grid(
                             }
                         }
                         else {
-                           sprintf(graph_label_right,im->second_axis_format,sval);
+                           sprintf(graph_label_right,im->second_axis_format,sval,"");
                         }        
                         gfx_text ( im,
                                X1+7, Y0,
@@ -3706,15 +3706,19 @@ rrd_info_t *rrd_graph_v(
     rrd_info_t *grinfo;
     rrd_graph_init(&im);
     /* a dummy surface so that we can measure text sizes for placements */
+     old_locale = setlocale(LC_NUMERIC, NULL);
+     setlocale(LC_NUMERIC, "C");
     
     rrd_graph_options(argc, argv, &im);
     if (rrd_test_error()) {
+        setlocale(LC_NUMERIC, old_locale); /* reenable locale */
         rrd_info_free(im.grinfo);
         im_free(&im);
         return NULL;
     }
 
     if (optind >= argc) {
+        setlocale(LC_NUMERIC, old_locale); /* reenable locale */
         rrd_info_free(im.grinfo);
         im_free(&im);
         rrd_set_error("missing filename");
@@ -3722,6 +3726,7 @@ rrd_info_t *rrd_graph_v(
     }
 
     if (strlen(argv[optind]) >= MAXPATH) {
+        setlocale(LC_NUMERIC, old_locale); /* reenable locale */
         rrd_set_error("filename (including path) too long");
         rrd_info_free(im.grinfo);
         im_free(&im);
@@ -3736,6 +3741,7 @@ rrd_info_t *rrd_graph_v(
     }
 
     rrd_graph_script(argc, argv, &im, 1);
+    setlocale(LC_NUMERIC, old_locale); /* reenable locale */
     if (rrd_test_error()) {
         rrd_info_free(im.grinfo);
         im_free(&im);