From 589986012c4b3ab68e299a2eadca18f90080113b Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Thu, 14 Jul 2022 20:28:04 +0200 Subject: Merging upstream version 2.0. Signed-off-by: Daniel Baumann --- util/argconfig.c | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) (limited to 'util/argconfig.c') diff --git a/util/argconfig.c b/util/argconfig.c index 341a049..59d8f1d 100644 --- a/util/argconfig.c +++ b/util/argconfig.c @@ -39,6 +39,7 @@ #include #include #include +#include static argconfig_help_func *help_funcs[MAX_HELP_FUNC] = { NULL }; @@ -176,17 +177,8 @@ int argconfig_parse(int argc, char *argv[], const char *program_desc, if (s->option && strlen(s->option)) { long_opts[option_index].name = s->option; long_opts[option_index].has_arg = s->argument_type; - - if (s->argument_type == no_argument - && s->default_value != NULL) { - value_addr = (void *)(char *)s->default_value; - - long_opts[option_index].flag = value_addr; - long_opts[option_index].val = 1; - } else { - long_opts[option_index].flag = NULL; - long_opts[option_index].val = 0; - } + long_opts[option_index].flag = NULL; + long_opts[option_index].val = 0; } option_index++; } @@ -219,10 +211,6 @@ int argconfig_parse(int argc, char *argv[], const char *program_desc, } if (option_index == options_count) continue; - if (long_opts[option_index].flag) { - *(uint8_t *)(long_opts[option_index].flag) = 1; - continue; - } } s = &options[option_index]; @@ -282,7 +270,7 @@ int argconfig_parse(int argc, char *argv[], const char *program_desc, } *((uint32_t *) value_addr) = tmp; } else if (s->config_type == CFG_INCREMENT) { - (*((int *)value_addr))++; + *((int *)value_addr) += 1; } else if (s->config_type == CFG_LONG) { *((unsigned long *)value_addr) = strtoul(optarg, &endptr, 0); if (errno || optarg == endptr) { @@ -363,6 +351,8 @@ int argconfig_parse(int argc, char *argv[], const char *program_desc, goto out; } *((FILE **) value_addr) = f; + } else if (s->config_type == CFG_FLAG) { + *((bool *)value_addr) = true; } } free(short_opts); -- cgit v1.2.3