[PATCH 4/7] parse-options: let OPT__ABBREV ignore arguments.
Signed-off-by: Pierre Habouzit <madcoder@debian.org>
---
parse-options.c | 16 +++++++++-------
1 files changed, 9 insertions(+), 7 deletions(-)
diff --git a/parse-options.c b/parse-options.c
index f3f0f2a..679a963 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -359,19 +359,21 @@ void usage_with_options(const char * const *usagestr,
int parse_opt_abbrev_cb(const struct option *opt, const char *arg, int flags)
{
- int v;
-
- if (!arg) {
- v = flags & PARSE_OPT_UNSET ? 0 : DEFAULT_ABBREV;
- } else {
+ int v = flags & PARSE_OPT_UNSET ? 0 : DEFAULT_ABBREV;
+ if (arg) {
v = strtol(arg, (char **)&arg, 10);
- if (*arg)
+ if (*arg) {
+ if (flags & PARSE_OPT_MAY_IGN) {
+ *(int *)opt->value = DEFAULT_ABBREV;
+ return PARSE_OPT_IGNORE;
+ }
return opterror(opt, "expects a numerical value", 0);
+ }
if (v && v < MINIMUM_ABBREV)
v = MINIMUM_ABBREV;
else if (v > 40)
v = 40;
}
- *(int *)(opt->value) = v;
+ *(int *)opt->value = v;
return 0;
}
--
1.5.4.rc0.1148.ga3ab1-dirty