Skip to content

Commit 55dda82

Browse files
committed
parse-options.c: add a parse_options_check_flags()
Add a parse_options_check_flags() for those checks that need to check the "enum parse_opt_flags", or the "flags" and "opts" in combination. This changes no behavior, and just moves existing code around, but in a subsequent commit we'll start checking the per-option flags against the parse_options() flags, this change makes that subsequent behavior change smaller. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
1 parent 8eeee58 commit 55dda82

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

parse-options.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,18 @@ static void check_typos(const char *arg, const struct option *options)
452452
}
453453
}
454454

455+
static void parse_options_check_flags(const struct option *opts,
456+
const enum parse_opt_flags flags)
457+
{
458+
if ((flags & PARSE_OPT_KEEP_UNKNOWN) &&
459+
(flags & PARSE_OPT_STOP_AT_NON_OPTION) &&
460+
!(flags & PARSE_OPT_ONE_SHOT))
461+
BUG("STOP_AT_NON_OPTION and KEEP_UNKNOWN don't go together");
462+
if ((flags & PARSE_OPT_ONE_SHOT) &&
463+
(flags & PARSE_OPT_KEEP_ARGV0))
464+
BUG("Can't keep argv0 if you don't have it");
465+
}
466+
455467
static void parse_options_check(const struct option *opts)
456468
{
457469
char short_opts[128];
@@ -530,13 +542,7 @@ static void parse_options_start_1(struct parse_opt_ctx_t *ctx,
530542
ctx->prefix = prefix;
531543
ctx->cpidx = ((flags & PARSE_OPT_KEEP_ARGV0) != 0);
532544
ctx->flags = flags;
533-
if ((flags & PARSE_OPT_KEEP_UNKNOWN) &&
534-
(flags & PARSE_OPT_STOP_AT_NON_OPTION) &&
535-
!(flags & PARSE_OPT_ONE_SHOT))
536-
BUG("STOP_AT_NON_OPTION and KEEP_UNKNOWN don't go together");
537-
if ((flags & PARSE_OPT_ONE_SHOT) &&
538-
(flags & PARSE_OPT_KEEP_ARGV0))
539-
BUG("Can't keep argv0 if you don't have it");
545+
parse_options_check_flags(options, flags);
540546
parse_options_check(options);
541547
}
542548

0 commit comments

Comments
 (0)