]> granicus.if.org Git - sysstat/commitdiff
sadf: Add new flag FO_LC_NUMERIC_C
authorSebastien GODARD <sysstat@users.noreply.github.com>
Fri, 12 Apr 2019 15:47:43 +0000 (17:47 +0200)
committerSebastien GODARD <sysstat@users.noreply.github.com>
Fri, 12 Apr 2019 15:47:43 +0000 (17:47 +0200)
This flag indicates that corresponding output format shall use a decimal
point, e.g. to be locale independant (SVG output) or compliant with
RFC7159 (JSON output).

Signed-off-by: Sebastien GODARD <sysstat@users.noreply.github.com>
format.c
sadf.c
sadf.h

index e2202f1c439a1834cf1b07f01ccd242cf2b1fe6d..7d6987acabab4f105c25bc28d30814b0dcf70dd4 100644 (file)
--- a/format.c
+++ b/format.c
@@ -97,7 +97,8 @@ struct report_format xml_fmt = {
  */
 struct report_format json_fmt = {
        .id             = F_JSON_OUTPUT,
-       .options        = FO_HEADER_ONLY + FO_LOCAL_TIME + FO_TEST_MARKUP,
+       .options        = FO_HEADER_ONLY + FO_LOCAL_TIME + FO_TEST_MARKUP +
+                         FO_LC_NUMERIC_C,
        .f_header       = print_json_header,
        .f_statistics   = print_json_statistics,
        .f_timestamp    = print_json_timestamp,
@@ -125,7 +126,8 @@ struct report_format conv_fmt = {
  */
 struct report_format svg_fmt = {
        .id             = F_SVG_OUTPUT,
-       .options        = FO_HEADER_ONLY + FO_LOCAL_TIME + FO_NO_TRUE_TIME,
+       .options        = FO_HEADER_ONLY + FO_LOCAL_TIME + FO_NO_TRUE_TIME +
+                         FO_LC_NUMERIC_C,
        .f_header       = print_svg_header,
        .f_statistics   = NULL,
        .f_timestamp    = NULL,
diff --git a/sadf.c b/sadf.c
index ae080354b142fa87ae288e11a4a1124dfb3b4d38..8e7100ef430406a77ca20a8973bd3c92fe722405 100644 (file)
--- a/sadf.c
+++ b/sadf.c
@@ -1025,11 +1025,6 @@ void logic1_display_loop(int ifd, char *file, struct file_activity *file_actlst,
        long cnt = 1;
        char *pcparchive = (char *) dparm;
 
-       if (format == F_JSON_OUTPUT) {
-               /* Use a decimal point to make JSON code compliant with RFC7159 */
-               setlocale(LC_NUMERIC, "C");
-       }
-
        /* Count items in file. Needed only for PCP output */
        if (format == F_PCP_OUTPUT) {
                count_file_items(ifd, file, file_magic, file_actlst, rectime, loctime);
@@ -1328,9 +1323,6 @@ void svg_display_loop(int ifd, char *file, struct file_activity *file_actlst,
        long cnt = 1;
        int graph_nr = 0;
 
-       /* Use a decimal point to make SVG code locale independent */
-       setlocale(LC_NUMERIC, "C");
-
        /* Init custom colors palette */
        init_custom_color_palette();
 
@@ -1468,6 +1460,11 @@ void read_stats_from_file(char dfile[], char pcparchive[])
        /* Perform required allocations */
        allocate_structures(act);
 
+       if (SET_LC_NUMERIC_C(fmt[f_position]->options)) {
+               /* Use a decimal point */
+               setlocale(LC_NUMERIC, "C");
+       }
+
        /* Call function corresponding to selected output format */
        if (*fmt[f_position]->f_display) {
                (*fmt[f_position]->f_display)(ifd, dfile, file_actlst, &file_magic,
diff --git a/sadf.h b/sadf.h
index 8a18967c7c112785a970ebf4109dcda529df1929..e93dd530951c5f7c3e3841b58207c988be8a74ac 100644 (file)
--- a/sadf.h
+++ b/sadf.h
 
 /* Format options */
 
-/* Unused      0x01 */
+/*
+ * Indicate that a decimal point should be used to make output
+ * locale independent.
+ */
+#define FO_LC_NUMERIC_C                0x01
 
 /*
  * Indicate that output should stop after the header is displayed.
@@ -92,6 +96,7 @@
  */
 #define FO_NO_TRUE_TIME                0x100
 
+#define SET_LC_NUMERIC_C(m)            (((m) & FO_LC_NUMERIC_C)        == FO_LC_NUMERIC_C)
 #define ACCEPT_HEADER_ONLY(m)          (((m) & FO_HEADER_ONLY)         == FO_HEADER_ONLY)
 #define ACCEPT_BAD_FILE_FORMAT(m)      (((m) & FO_BAD_FILE_FORMAT)     == FO_BAD_FILE_FORMAT)
 #define ACCEPT_LOCAL_TIME(m)           (((m) & FO_LOCAL_TIME)          == FO_LOCAL_TIME)