summaryrefslogtreecommitdiffstats
path: root/options
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
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')
-rw-r--r--options/m_config.c50
-rw-r--r--options/m_config.h21
-rw-r--r--options/m_option.c4
-rw-r--r--options/parse_commandline.c4
4 files changed, 28 insertions, 51 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);
diff --git a/options/m_config.h b/options/m_config.h
index ff2dcf14a6..65145c093b 100644
--- a/options/m_config.h
+++ b/options/m_config.h
@@ -163,27 +163,9 @@ enum {
// Flags for safe option setting during runtime.
#define M_SETOPT_RUNTIME M_SETOPT_NO_FIXED
-// Set the named option to the given string.
-// flags: combination of M_SETOPT_* flags (0 for normal operation)
-// Returns >= 0 on success, otherwise see OptionParserReturn.
-int m_config_set_option_ext(struct m_config *config, struct bstr name,
+int m_config_set_option_cli(struct m_config *config, struct bstr name,
struct bstr param, int flags);
-/* Set an option. (Like: m_config_set_option_ext(config, name, param, 0))
- * \param config The config object.
- * \param name The option's name.
- * \param param The value of the option, can be NULL.
- * \return See \ref OptionParserReturn.
- */
-int m_config_set_option(struct m_config *config, struct bstr name,
- struct bstr param);
-
-static inline int m_config_set_option0(struct m_config *config,
- const char *name, const char *param)
-{
- return m_config_set_option(config, bstr0(name), bstr0(param));
-}
-
int m_config_set_option_raw(struct m_config *config, struct m_config_option *co,
void *data, int flags);
@@ -193,7 +175,6 @@ int m_config_set_option_raw_direct(struct m_config *config,
struct m_config_option *co,
void *data, int flags);
-// Similar to m_config_set_option_ext(), but set as data using mpv_node.
struct mpv_node;
int m_config_set_option_node(struct m_config *config, bstr name,
struct mpv_node *data, int flags);
diff --git a/options/m_option.c b/options/m_option.c
index ae63044e50..b8a9f7384c 100644
--- a/options/m_option.c
+++ b/options/m_option.c
@@ -2621,7 +2621,7 @@ static int get_obj_param(struct mp_log *log, bstr opt_name, bstr obj_name,
// If it's just "name", and the associated option exists and is a flag,
// don't accept it as positional argument.
if (val.start || m_config_option_requires_param(config, name) == 0 || nopos) {
- r = m_config_set_option_ext(config, name, val, flags);
+ r = m_config_set_option_cli(config, name, val, flags);
if (r < 0) {
if (r == M_OPT_UNKNOWN) {
mp_err(log, "Option %.*s: %.*s doesn't have a %.*s parameter.\n",
@@ -2652,7 +2652,7 @@ static int get_obj_param(struct mp_log *log, bstr opt_name, bstr obj_name,
BSTR_P(opt_name), BSTR_P(obj_name), *nold, *nold);
return M_OPT_OUT_OF_RANGE;
}
- r = m_config_set_option_ext(config, bstr0(opt), val, flags);
+ r = m_config_set_option_cli(config, bstr0(opt), val, flags);
if (r < 0) {
if (r != M_OPT_EXIT)
mp_err(log, "Option %.*s: "
diff --git a/options/parse_commandline.c b/options/parse_commandline.c
index 2eb65e5c8e..b1392ba4e1 100644
--- a/options/parse_commandline.c
+++ b/options/parse_commandline.c
@@ -146,7 +146,7 @@ int m_config_parse_mp_command_line(m_config_t *config, struct playlist *files,
int flags = M_SETOPT_FROM_CMDLINE;
if (mode == LOCAL)
flags |= M_SETOPT_BACKUP | M_SETOPT_CHECK_ONLY;
- int r = m_config_set_option_ext(config, p.arg, p.param, flags);
+ int r = m_config_set_option_cli(config, p.arg, p.param, flags);
if (r == M_OPT_EXIT) {
ret = r;
goto err_out;
@@ -291,7 +291,7 @@ void m_config_preparse_command_line(m_config_t *config, struct mpv_global *globa
// Ignore non-pre-parse options. They will be set later.
// Option parsing errors will be handled later as well.
int flags = M_SETOPT_FROM_CMDLINE | M_SETOPT_PRE_PARSE_ONLY;
- m_config_set_option_ext(config, p.arg, p.param, flags);
+ m_config_set_option_cli(config, p.arg, p.param, flags);
if (bstrcmp0(p.arg, "v") == 0)
opts->verbose++;
}