parse-options: make resuming easier after PARSE_OPT_STOP_AT_NON_OPTION
Introduce a PARSE_OPT_NON_OPTION state, so parse_option_step() callers can easily distinguish between non-options and other reasons for option parsing termination (like "--"). Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jonathan Nieder committed
Dec 1, 2010 at 17:32 UTC
979240fee32628c317998f3c3fe2619cf01decc2
2 files changed
+3
-1
parse-options.c
+2
-1
@@ -373,7 +373,7 @@ int parse_options_step(struct parse_opt_ctx_t *ctx,
373
if (parse_nodash_opt(ctx, arg, options) == 0)
374
continue;
375
if (ctx->flags & PARSE_OPT_STOP_AT_NON_OPTION)
376
- break;
376
+ return PARSE_OPT_NON_OPTION;
377
ctx->out[ctx->cpidx++] = ctx->argv[0];
378
continue;
379
}
@@ -455,6 +455,7 @@ int parse_options(int argc, const char **argv, const char *prefix,
455
switch (parse_options_step(&ctx, options, usagestr)) {
456
case PARSE_OPT_HELP:
457
exit(129);
458
+ case PARSE_OPT_NON_OPTION:
459
case PARSE_OPT_DONE:
460
break;
461
default: /* PARSE_OPT_UNKNOWN */
parse-options.h
+1
@@ -167,6 +167,7 @@ extern NORETURN void usage_msg_opt(const char *msg,
167
enum {
168
PARSE_OPT_HELP = -1,
169
PARSE_OPT_DONE,
170
+ PARSE_OPT_NON_OPTION,
171
PARSE_OPT_UNKNOWN
172
};
173