diff options
author | Anton Khirnov <anton@khirnov.net> | 2023-12-15 08:24:14 +0100 |
---|---|---|
committer | Anton Khirnov <anton@khirnov.net> | 2023-12-22 11:39:57 +0100 |
commit | b472c46a7020bfcd74952c04914a929476b701f2 (patch) | |
tree | 3c4182dcd307e3141777dbfda6b32b4f83aa0aa3 /fftools/cmdutils.c | |
parent | 25c98566e8a45b50415c80ca6450282f2ec0657a (diff) |
fftools/cmdutils: simplify handling of the HAS_ARG option flag
This option flag only carries nontrivial information for options that
call a function, in all other cases its presence can be inferred from
the option type (bool options do not have arguments, all other types do)
and is thus nothing but useless clutter.
Change the option parsing code to infer its value when it can, and drop
the flag from options where it's not needed.
Diffstat (limited to 'fftools/cmdutils.c')
-rw-r--r-- | fftools/cmdutils.c | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c index 86cd3bddb4..f5b3dc7346 100644 --- a/fftools/cmdutils.c +++ b/fftools/cmdutils.c @@ -223,6 +223,17 @@ static inline void prepare_app_arguments(int *argc_ptr, char ***argv_ptr) } #endif /* HAVE_COMMANDLINETOARGVW */ +static int opt_has_arg(const OptionDef *o) +{ + if (o->flags & OPT_BOOL) + return 0; + if (o->flags & + (OPT_STRING | OPT_INT | OPT_FLOAT | OPT_INT64 | + OPT_SPEC | OPT_TIME | OPT_DOUBLE)) + return 1; + return !!(o->flags & HAS_ARG); +} + static int write_option(void *optctx, const OptionDef *po, const char *opt, const char *arg) { @@ -331,7 +342,7 @@ int parse_option(void *optctx, const char *opt, const char *arg, av_log(NULL, AV_LOG_ERROR, "Unrecognized option '%s'\n", opt); return AVERROR(EINVAL); } - if (po->flags & HAS_ARG && !arg) { + if (opt_has_arg(po) && !arg) { av_log(NULL, AV_LOG_ERROR, "Missing argument for option '%s'\n", opt); return AVERROR(EINVAL); } @@ -340,7 +351,7 @@ int parse_option(void *optctx, const char *opt, const char *arg, if (ret < 0) return ret; - return !!(po->flags & HAS_ARG); + return opt_has_arg(po); } int parse_options(void *optctx, int argc, char **argv, const OptionDef *options, @@ -432,7 +443,7 @@ int locate_option(int argc, char **argv, const OptionDef *options, (po->name && !strcmp(optname, po->name))) return i; - if (!po->name || po->flags & HAS_ARG) + if (!po->name || opt_has_arg(po)) i++; } return 0; @@ -770,7 +781,7 @@ do { \ if (po->flags & OPT_EXIT) { /* optional argument, e.g. -h */ arg = argv[optindex++]; - } else if (po->flags & HAS_ARG) { + } else if (opt_has_arg(po)) { GET_ARG(arg); } else { arg = "1"; |