summaryrefslogtreecommitdiffstats
path: root/core/m_option.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2012-09-21 09:22:25 +0200
committerwm4 <wm4@nowhere>2013-02-09 00:21:17 +0100
commit267a889cc2c5ca688a2b8fc93cf8e5349a3c8a44 (patch)
treeee2561f256db05092e61fa797be4b7ecaf3db991 /core/m_option.c
parent5412993724aee1126bfc8dfbc0422ebe5251b9b6 (diff)
downloadmpv-267a889cc2c5ca688a2b8fc93cf8e5349a3c8a44.tar.bz2
mpv-267a889cc2c5ca688a2b8fc93cf8e5349a3c8a44.tar.xz
options: unify single dash and double dash options
There were two option syntax variations: "old": -opt value "new": --opt=value "-opt=value" was invalid, and "--opt value" meant "--opt=" followed by a separate option "value" (i.e. interpreted as filename). There isn't really any reason to do this. The "old" syntax used to be ambiguous (you had to call the option parser to know whether the following argument is an option value or a new option), but that has been removed. Further, using "=" in the option string is always unambiguous. Since the distinction between the two option variants is confusing, just remove the difference and allow "--opt value" and "-opt=value". To make this easier, do some other cleanups as well (e.g. avoid having to do a manual lookup of the option just to check for M_OPT_PRE_PARSE, which somehow ended up with finally getting rid of the m_config.mode member). Error reporting is still a mess, and we opt for reporting too many rather than too few errors to the user. There shouldn't be many user-visible changes. The --framedrop and --term-osd options now always require parameters. The --mute option is intentionally made ambiguous: it works like a flag option, but a value can be passed to it explicitly ("--mute=auto"). If the interpretation of the option is ambiguous (like "--mute auto"), the second string is interpreted as separate option or filename. (Normal flag options are actually ambiguous in this way too.)
Diffstat (limited to 'core/m_option.c')
-rw-r--r--core/m_option.c23
1 files changed, 12 insertions, 11 deletions
diff --git a/core/m_option.c b/core/m_option.c
index 078f9f327b..595675cebb 100644
--- a/core/m_option.c
+++ b/core/m_option.c
@@ -43,17 +43,18 @@ char *m_option_strerror(int code)
{
switch (code) {
case M_OPT_UNKNOWN:
- return mp_gtext("Unrecognized option name");
+ return mp_gtext("option not found");
case M_OPT_MISSING_PARAM:
- return mp_gtext("Required parameter for option missing");
+ return mp_gtext("option requires parameter");
case M_OPT_INVALID:
- return mp_gtext("Option parameter could not be parsed");
+ return mp_gtext("option parameter could not be parsed");
case M_OPT_OUT_OF_RANGE:
- return mp_gtext("Parameter is outside values allowed for option");
+ return mp_gtext("parameter is outside values allowed for option");
+ case M_OPT_DISALLOW_PARAM:
+ return mp_gtext("option doesn't take a parameter");
case M_OPT_PARSER_ERR:
- return mp_gtext("Parser error");
default:
- return NULL;
+ return mp_gtext("parser error");
}
}
@@ -144,7 +145,7 @@ const m_option_type_t m_option_type_flag = {
// need yes or no in config files
.name = "Flag",
.size = sizeof(int),
- .flags = M_OPT_TYPE_OLD_SYNTAX_NO_PARAM,
+ .flags = M_OPT_TYPE_OPTIONAL_PARAM,
.parse = parse_flag,
.print = print_flag,
.copy = copy_opt,
@@ -165,7 +166,7 @@ static int parse_store(const m_option_t *opt, struct bstr name,
mp_msg(MSGT_CFGPARSER, MSGL_ERR,
"Invalid parameter for %.*s flag: %.*s\n",
BSTR_P(name), BSTR_P(param));
- return M_OPT_INVALID;
+ return M_OPT_DISALLOW_PARAM;
}
}
@@ -173,7 +174,7 @@ const m_option_type_t m_option_type_store = {
// can only be activated
.name = "Flag",
.size = sizeof(int),
- .flags = M_OPT_TYPE_OLD_SYNTAX_NO_PARAM,
+ .flags = M_OPT_TYPE_OPTIONAL_PARAM,
.parse = parse_store,
};
@@ -1039,7 +1040,7 @@ static int parse_print(const m_option_t *opt, struct bstr name,
const m_option_type_t m_option_type_print = {
.name = "Print",
- .flags = M_OPT_TYPE_OLD_SYNTAX_NO_PARAM,
+ .flags = M_OPT_TYPE_OPTIONAL_PARAM,
.parse = parse_print,
};
@@ -1051,7 +1052,7 @@ const m_option_type_t m_option_type_print_func_param = {
const m_option_type_t m_option_type_print_func = {
.name = "Print",
- .flags = M_OPT_TYPE_ALLOW_WILDCARD | M_OPT_TYPE_OLD_SYNTAX_NO_PARAM,
+ .flags = M_OPT_TYPE_ALLOW_WILDCARD | M_OPT_TYPE_OPTIONAL_PARAM,
.parse = parse_print,
};