summaryrefslogtreecommitdiffstats
path: root/options/m_config.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2017-07-02 13:00:22 +0200
committerwm4 <wm4@nowhere>2017-07-02 13:07:36 +0200
commit3d318071982cc80867098ca5fe2641f31a289ac8 (patch)
treed388d93a5ee37e98b818733bf0e139740a048f1e /options/m_config.c
parent66478cff14faaafb124c9e80f80b6fe0ad38a050 (diff)
downloadmpv-3d318071982cc80867098ca5fe2641f31a289ac8.tar.bz2
mpv-3d318071982cc80867098ca5fe2641f31a289ac8.tar.xz
m_option: remove redundant indirections
Remove the various redundant m_config_set_option* calls, rename the remaining one to m_config_set_option_cli(), and merge the m_config_parse_option() function.
Diffstat (limited to 'options/m_config.c')
-rw-r--r--options/m_config.c50
1 files changed, 23 insertions, 27 deletions
diff --git a/options/m_config.c b/options/m_config.c
index 4c65867ae6..ea58b5a3dd 100644
--- a/options/m_config.c
+++ b/options/m_config.c
@@ -243,7 +243,7 @@ static int m_config_set_obj_params(struct m_config *config, struct mp_log *log,
for (int n = 0; args && args[n * 2 + 0]; n++) {
bstr opt = bstr0(args[n * 2 + 0]);
bstr val = bstr0(args[n * 2 + 1]);
- if (m_config_set_option(config, opt, val) < 0)
+ if (m_config_set_option_cli(config, opt, val, 0) < 0)
return -1;
}
@@ -755,7 +755,7 @@ int m_config_set_option_raw_direct(struct m_config *config,
return 0;
}
-// Similar to m_config_set_option_ext(), but set as data in its native format.
+// Similar to m_config_set_option_cli(), but set as data in its native format.
// This takes care of some details like sending change notifications.
// The type data points to is as in: co->opt
int m_config_set_option_raw(struct m_config *config, struct m_config_option *co,
@@ -833,21 +833,30 @@ static struct m_config_option *m_config_mogrify_cli_opt(struct m_config *config,
return NULL;
}
-static int m_config_parse_option(struct m_config *config, struct bstr name,
- struct bstr param, int flags)
+// Set the named option to the given string. This is for command line and config
+// file use only.
+// flags: combination of M_SETOPT_* flags (0 for normal operation)
+// Returns >= 0 on success, otherwise see OptionParserReturn.
+int m_config_set_option_cli(struct m_config *config, struct bstr name,
+ struct bstr param, int flags)
{
+ int r;
assert(config != NULL);
bool negate;
struct m_config_option *co =
m_config_mogrify_cli_opt(config, &name, &negate, &(int){0});
- if (!co)
- return M_OPT_UNKNOWN;
+ if (!co) {
+ r = M_OPT_UNKNOWN;
+ goto done;
+ }
if (negate) {
- if (param.len)
- return M_OPT_DISALLOW_PARAM;
+ if (param.len) {
+ r = M_OPT_DISALLOW_PARAM;
+ goto done;
+ }
param = bstr0("no");
}
@@ -855,12 +864,11 @@ static int m_config_parse_option(struct m_config *config, struct bstr name,
// This is the only mandatory function
assert(co->opt->type->parse);
- int r = handle_set_opt_flags(config, co, flags);
+ r = handle_set_opt_flags(config, co, flags);
if (r <= 0)
- return r;
- bool set = r == 2;
+ goto done;
- if (set) {
+ if (r == 2) {
MP_VERBOSE(config, "Setting option '%.*s' = '%.*s' (flags = %d)\n",
BSTR_P(name), BSTR_P(param), flags);
}
@@ -879,13 +887,7 @@ static int m_config_parse_option(struct m_config *config, struct bstr name,
m_option_free(co->opt, &val);
- return r;
-}
-
-int m_config_set_option_ext(struct m_config *config, struct bstr name,
- struct bstr param, int flags)
-{
- int r = m_config_parse_option(config, name, param, flags);
+done:
if (r < 0 && r != M_OPT_EXIT) {
MP_ERR(config, "Error parsing option %.*s (%s)\n",
BSTR_P(name), m_option_strerror(r));
@@ -894,12 +896,6 @@ int m_config_set_option_ext(struct m_config *config, struct bstr name,
return r;
}
-int m_config_set_option(struct m_config *config, struct bstr name,
- struct bstr param)
-{
- return m_config_set_option_ext(config, name, param, 0);
-}
-
int m_config_set_option_node(struct m_config *config, bstr name,
struct mpv_node *data, int flags)
{
@@ -1076,7 +1072,7 @@ void m_profile_set_desc(struct m_profile *p, bstr desc)
int m_config_set_profile_option(struct m_config *config, struct m_profile *p,
bstr name, bstr val)
{
- int i = m_config_set_option_ext(config, name, val,
+ int i = m_config_set_option_cli(config, name, val,
M_SETOPT_CHECK_ONLY |
M_SETOPT_FROM_CONFIG_FILE);
if (i < 0)
@@ -1103,7 +1099,7 @@ int m_config_set_profile(struct m_config *config, char *name, int flags)
}
config->profile_depth++;
for (int i = 0; i < p->num_opts; i++) {
- m_config_set_option_ext(config,
+ m_config_set_option_cli(config,
bstr0(p->opts[2 * i]),
bstr0(p->opts[2 * i + 1]),
flags | M_SETOPT_FROM_CONFIG_FILE);