[PATCH 5/6] parse-options: allow OPTION_ARGUMENT to take argument
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
parse-options.c | 18 +++++++++++++++---
1 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/parse-options.c b/parse-options.c
index 58bb83d..3a1575a 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -218,11 +218,23 @@ static int parse_long_opt(struct parse_opt_ctx_t *p, const char *arg,
if (options->type == OPTION_ARGUMENT) {
if (!rest)
continue;
- if (*rest == '=')
- return opterror(options, "takes no value", flags);
+ if (*rest == '=') {
+ if (options->flags & PARSE_OPT_NOARG)
+ return opterror(options, "takes no value", flags);
+ p->out[p->cpidx++] = *p->argv;
+ return 0;
+ }
+
if (*rest)
continue;
- p->out[p->cpidx++] = arg - 2;
+ p->out[p->cpidx++] = *p->argv;
+ if (!(options->flags & PARSE_OPT_NOARG)) {
+ p->argv++;
+ p->argc--;
+ if (!*p->argv)
+ return opterror(options, "takes no value", flags);
+ p->out[p->cpidx++] = *p->argv;
+ }
return 0;
}
if (!rest) {
--
1.7.4.74.g639db