From 844594784f2c03466e384dbb46efcf1b2818618f Mon Sep 17 00:00:00 2001 From: Tokunori Ikegami Date: Thu, 23 Mar 2023 00:29:30 +0900 Subject: [PATCH] util: Use argconfig commandline options pointer directly Also change print help function options argument as not const variable. Fix ";;" also incorrectly used to ";". Signed-off-by: Tokunori Ikegami --- util/argconfig.c | 16 ++++++---------- util/argconfig.h | 2 +- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/util/argconfig.c b/util/argconfig.c index 33370439..f247fc54 100644 --- a/util/argconfig.c +++ b/util/argconfig.c @@ -122,21 +122,19 @@ static void show_option(const struct argconfig_commandline_options *option) } void argconfig_print_help(const char *program_desc, - const struct argconfig_commandline_options *options) + struct argconfig_commandline_options *s) { - const struct argconfig_commandline_options *s; - fprintf(stderr, "\033[1mUsage: %s\033[0m\n\n", append_usage_str); print_word_wrapped(program_desc, 0, 0, stderr); fprintf(stderr, "\n"); - if (!options || !options->option) + if (!s || !s->option) return; fprintf(stderr, "\n\033[1mOptions:\033[0m\n"); - for (s = options; (s != NULL) && (s->option != NULL); s++) + for (; s && s->option; s++) show_option(s); } @@ -598,14 +596,12 @@ void argconfig_register_help_func(argconfig_help_func * f) } } -bool argconfig_parse_seen(struct argconfig_commandline_options *options, +bool argconfig_parse_seen(struct argconfig_commandline_options *s, const char *option) { - struct argconfig_commandline_options *s; - - for (s = options; s && s->option; s++) { + for (; s && s->option; s++) { if (!strcmp(s->option, option)) - return s->seen;; + return s->seen; } return false; diff --git a/util/argconfig.h b/util/argconfig.h index 8f7e7bbe..b691159f 100644 --- a/util/argconfig.h +++ b/util/argconfig.h @@ -119,7 +119,7 @@ struct argconfig_commandline_options { typedef void argconfig_help_func(); void argconfig_append_usage(const char *str); void argconfig_print_help(const char *program_desc, - const struct argconfig_commandline_options *options); + struct argconfig_commandline_options *options); int argconfig_parse(int argc, char *argv[], const char *program_desc, struct argconfig_commandline_options *options); int argconfig_parse_subopt_string(char *string, char **options, -- 2.50.1