From 28148eee343099f1ca4eb65d7dbf60266c8b49d4 Mon Sep 17 00:00:00 2001 From: Tokunori Ikegami Date: Sun, 16 Jul 2023 03:00:53 +0900 Subject: [PATCH 1/2] util: Set LC_ALL=C as default if -H option is not used Signed-off-by: Tokunori Ikegami --- util/argconfig.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/util/argconfig.c b/util/argconfig.c index effeea2f6..9f88957b4 100644 --- a/util/argconfig.c +++ b/util/argconfig.c @@ -41,6 +41,7 @@ #include #include #include +#include static const char *append_usage_str = ""; @@ -335,6 +336,16 @@ static bool argconfig_check_output_format_json(struct argconfig_commandline_opti return false; } +static bool argconfig_check_human_readable(struct argconfig_commandline_options *s) +{ + for (; s && s->option; s++) { + if (!strcmp(s->option, "human-readable") && s->config_type == CFG_FLAG) + return s->seen; + } + + return false; +} + int argconfig_parse(int argc, char *argv[], const char *program_desc, struct argconfig_commandline_options *options) { @@ -419,6 +430,9 @@ int argconfig_parse(int argc, char *argv[], const char *program_desc, if (argconfig_check_output_format_json(options)) argconfig_output_format_json(true); + if (!argconfig_check_human_readable(options)) + setlocale(LC_ALL, "C"); + out: free(short_opts); free(long_opts); From 887bf344669f8420e3883c8293f6755226242a4d Mon Sep 17 00:00:00 2001 From: Tokunori Ikegami Date: Sun, 16 Jul 2023 03:07:41 +0900 Subject: [PATCH 2/2] util: Delete unused CFG_BOOL argconfig type as duplicated with CFG_FLAG Signed-off-by: Tokunori Ikegami --- util/argconfig.c | 9 --------- util/argconfig.h | 1 - 2 files changed, 10 deletions(-) diff --git a/util/argconfig.c b/util/argconfig.c index 9f88957b4..78f3a6c37 100644 --- a/util/argconfig.c +++ b/util/argconfig.c @@ -178,15 +178,6 @@ static int argconfig_parse_type(struct argconfig_commandline_options *s, struct if (errno || optarg == endptr) ret = argconfig_error("integer", option[index].name, optarg); break; - case CFG_BOOL: { - int tmp = strtol(optarg, &endptr, 0); - - if (errno || tmp < 0 || tmp > 1 || optarg == endptr) - ret = argconfig_error("0 or 1", option[index].name, optarg); - else - *((int *)value) = tmp; - break; - } case CFG_BYTE: ret = argconfig_parse_byte(option[index].name, optarg, (uint8_t *)value); break; diff --git a/util/argconfig.h b/util/argconfig.h index eaf8375ab..58dd698b3 100644 --- a/util/argconfig.h +++ b/util/argconfig.h @@ -49,7 +49,6 @@ enum argconfig_types { CFG_LONG, CFG_LONG_SUFFIX, CFG_DOUBLE, - CFG_BOOL, CFG_BYTE, CFG_SHORT, CFG_POSITIVE,