mirror of
https://github.com/mpv-player/mpv
synced 2025-03-09 23:58:06 +00:00
options: remove M_OPT_IMPLICIT_DEFAULT
This was to make an option without value use the option's default value (e.g. --term-osd is the same as --term-osd=auto). Make it simpler by handling this case as an empty choice. The flag was probably needed when option handling still did ambiguous argument parsing.
This commit is contained in:
parent
f97a85595b
commit
d29d4df634
@ -711,9 +711,9 @@ const m_option_t mplayer_opts[]={
|
||||
|
||||
OPT_FLAG_ON("softsleep", softsleep, 0),
|
||||
|
||||
OPT_CHOICE("term-osd", term_osd, M_OPT_IMPLICIT_DEFAULT,
|
||||
OPT_CHOICE("term-osd", term_osd, 0,
|
||||
({"force", 1},
|
||||
{"auto", 2},
|
||||
{"auto", 2}, {"", 2},
|
||||
{"off", 0})),
|
||||
|
||||
OPT_STRING("term-osd-esc", term_osd_esc, 0, OPTDEF_STR("\x1b[A\r\x1b[K")),
|
||||
|
20
m_option.c
20
m_option.c
@ -267,21 +267,13 @@ const struct m_option_type m_option_type_intpair = {
|
||||
static int parse_choice(const struct m_option *opt, struct bstr name,
|
||||
struct bstr param, void *dst)
|
||||
{
|
||||
bool allow_empty = opt->flags & M_OPT_IMPLICIT_DEFAULT;
|
||||
int ret;
|
||||
|
||||
struct m_opt_choice_alternatives *alt = opt->priv;
|
||||
if (param.len == 0) {
|
||||
if (!allow_empty)
|
||||
return M_OPT_MISSING_PARAM;
|
||||
ret = 0;
|
||||
} else {
|
||||
for ( ; alt->name; alt++)
|
||||
if (!bstrcasecmp0(param, alt->name))
|
||||
break;
|
||||
ret = 1;
|
||||
}
|
||||
for ( ; alt->name; alt++)
|
||||
if (!bstrcasecmp0(param, alt->name))
|
||||
break;
|
||||
if (!alt->name) {
|
||||
if (param.len == 0)
|
||||
return M_OPT_MISSING_PARAM;
|
||||
mp_msg(MSGT_CFGPARSER, MSGL_ERR,
|
||||
"Invalid value for option %.*s: %.*s\n",
|
||||
BSTR_P(name), BSTR_P(param));
|
||||
@ -294,7 +286,7 @@ static int parse_choice(const struct m_option *opt, struct bstr name,
|
||||
if (dst)
|
||||
*(int *)dst = alt->value;
|
||||
|
||||
return ret;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static char *print_choice(const m_option_t *opt, const void *val)
|
||||
|
@ -292,11 +292,6 @@ struct m_option {
|
||||
// The option should be set during command line pre-parsing
|
||||
#define M_OPT_PRE_PARSE (1 << 6)
|
||||
|
||||
// Accept an option without parameter, even if the option type normally requires
|
||||
// a parameter. The option value will be set to a default value.
|
||||
// For m_option_type_choice, the first listed choice will be used.
|
||||
#define M_OPT_IMPLICIT_DEFAULT (1 << 7)
|
||||
|
||||
// For options with children, add all children as top-level arguments
|
||||
// (e.g. "--parent=child=value" becomes "--parent-child=value")
|
||||
#define M_OPT_PREFIXED (1 << 8)
|
||||
|
Loading…
Reference in New Issue
Block a user