From 2f44f02c33c23c7a2aaf3a0d13aeed9ee1289df4 Mon Sep 17 00:00:00 2001 From: Sebastien GODARD Date: Fri, 12 Apr 2019 17:47:43 +0200 Subject: [PATCH] sadf: Add new flag FO_LC_NUMERIC_C 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 --- format.c | 6 ++++-- sadf.c | 13 +++++-------- sadf.h | 7 ++++++- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/format.c b/format.c index e2202f1..7d6987a 100644 --- 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 ae08035..8e7100e 100644 --- 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 8a18967..e93dd53 100644 --- a/sadf.h +++ b/sadf.h @@ -43,7 +43,11 @@ /* 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) -- 2.40.0