From: Daniel Wagner Date: Thu, 10 Feb 2022 16:57:01 +0000 (+0100) Subject: argconfig: Increase the flag value X-Git-Tag: v2.0-rc3~4^2~1 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=8f75eb067f7fd1b2f7683f82280cf74cb86e8c26;p=users%2Fsagi%2Fnvme-cli.git argconfig: Increase the flag value If the flag is provided several time increase the flag value. This is a pretty ugly fix for how getopt_long_only() handles '--verbose' vs '-v'. getopt_long_only() returns 0 when --verbose is used and 'v' for -v hence we will not usually not take the short option path for --verbose. Break out in the short option parsing when non flag options are used. Another uglyliness here is that it sets up long options differently depending on short or long version is used. For the short version we have to use value_addr. Signed-off-by: Daniel Wagner --- diff --git a/util/argconfig.c b/util/argconfig.c index 27d5e94f..de6e8bec 100644 --- a/util/argconfig.c +++ b/util/argconfig.c @@ -219,7 +219,8 @@ int argconfig_parse(int argc, char *argv[], const char *program_desc, } if (option_index == options_count) continue; - if (long_opts[option_index].flag) { + if (long_opts[option_index].flag && + options[option_index].config_type == CFG_NONE) { *(uint8_t *)(long_opts[option_index].flag) = 1; continue; } @@ -292,7 +293,10 @@ int argconfig_parse(int argc, char *argv[], const char *program_desc, * * So we need to increase 'val', not 'value_addr'. */ - long_opts[option_index].val++; + if (!c) + long_opts[option_index].val++; + else + *((int *)value_addr) += 1; } else if (s->config_type == CFG_LONG) { *((unsigned long *)value_addr) = strtoul(optarg, &endptr, 0); if (errno || optarg == endptr) {