From: Jonathan Nieder Date: Wed, 1 Dec 2010 23:32:55 +0000 (-0600) Subject: parse-options: make resuming easier after PARSE_OPT_STOP_AT_NON_OPTION X-Git-Tag: v1.7.4-rc0~51^2~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=979240fee32628c317998f3c3fe2619cf01decc2;p=thirdparty%2Fgit.git 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 Signed-off-by: Junio C Hamano --- diff --git a/parse-options.c b/parse-options.c index cd92686916..42b51ef145 100644 --- a/parse-options.c +++ b/parse-options.c @@ -373,7 +373,7 @@ int parse_options_step(struct parse_opt_ctx_t *ctx, if (parse_nodash_opt(ctx, arg, options) == 0) continue; if (ctx->flags & PARSE_OPT_STOP_AT_NON_OPTION) - break; + return PARSE_OPT_NON_OPTION; ctx->out[ctx->cpidx++] = ctx->argv[0]; continue; } @@ -455,6 +455,7 @@ int parse_options(int argc, const char **argv, const char *prefix, switch (parse_options_step(&ctx, options, usagestr)) { case PARSE_OPT_HELP: exit(129); + case PARSE_OPT_NON_OPTION: case PARSE_OPT_DONE: break; default: /* PARSE_OPT_UNKNOWN */ diff --git a/parse-options.h b/parse-options.h index 470bb33298..3c2ec1d092 100644 --- a/parse-options.h +++ b/parse-options.h @@ -167,6 +167,7 @@ extern NORETURN void usage_msg_opt(const char *msg, enum { PARSE_OPT_HELP = -1, PARSE_OPT_DONE, + PARSE_OPT_NON_OPTION, PARSE_OPT_UNKNOWN };