aboutsummaryrefslogtreecommitdiffhomepage
path: root/options
diff options
context:
space:
mode:
authorGravatar wm4 <wm4@nowhere>2013-12-21 19:45:42 +0100
committerGravatar wm4 <wm4@nowhere>2013-12-21 21:05:02 +0100
commitd8d42b44fc717c695af59c14213d54885088ea37 (patch)
tree9dbfd597e3352249cb5d1fda996d2c0ce1602fe9 /options
parenta2d144fc8f146f96e4fe97b1b2c15828e24f8494 (diff)
m_option, m_config: mp_msg conversions
Always pass around mp_log contexts in the option parser code. This of course affects all users of this API as well. In stream.c, pass a mp_null_log, because we can't do it properly yet. This will be fixed later.
Diffstat (limited to 'options')
-rw-r--r--options/m_config.c91
-rw-r--r--options/m_config.h10
-rw-r--r--options/m_option.c339
-rw-r--r--options/m_option.h18
-rw-r--r--options/m_property.c2
-rw-r--r--options/options.c6
6 files changed, 219 insertions, 247 deletions
diff --git a/options/m_config.c b/options/m_config.c
index 2b873e765c..0fc99b0257 100644
--- a/options/m_config.c
+++ b/options/m_config.c
@@ -75,20 +75,18 @@ static int parse_profile(struct m_config *config, const struct m_option *opt,
if (!bstrcmp0(param, "help")) {
struct m_profile *p;
if (!config->profiles) {
- mp_msg(MSGT_CFGPARSER, MSGL_INFO,
- "No profiles have been defined.\n");
+ MP_INFO(config, "No profiles have been defined.\n");
return M_OPT_EXIT - 1;
}
- mp_msg(MSGT_CFGPARSER, MSGL_INFO, "Available profiles:\n");
+ MP_INFO(config, "Available profiles:\n");
for (p = config->profiles; p; p = p->next)
- mp_msg(MSGT_CFGPARSER, MSGL_INFO, "\t%s\t%s\n", p->name,
- p->desc ? p->desc : "");
- mp_msg(MSGT_CFGPARSER, MSGL_INFO, "\n");
+ MP_INFO(config, "\t%s\t%s\n", p->name, p->desc ? p->desc : "");
+ MP_INFO(config, "\n");
return M_OPT_EXIT - 1;
}
char **list = NULL;
- int r = m_option_type_string_list.parse(opt, name, param, &list);
+ int r = m_option_type_string_list.parse(config->log, opt, name, param, &list);
if (r < 0)
return r;
if (!list || !list[0])
@@ -96,8 +94,7 @@ static int parse_profile(struct m_config *config, const struct m_option *opt,
for (int i = 0; list[i]; i++) {
struct m_profile *p = m_config_get_profile0(config, list[i]);
if (!p) {
- mp_msg(MSGT_CFGPARSER, MSGL_WARN, "Unknown profile '%s'.\n",
- list[i]);
+ MP_WARN(config, "Unknown profile '%s'.\n", list[i]);
r = M_OPT_INVALID;
} else if (set)
m_config_set_profile(config, p, flags);
@@ -113,12 +110,11 @@ static int show_profile(struct m_config *config, bstr param)
if (!param.len)
return M_OPT_MISSING_PARAM;
if (!(p = m_config_get_profile(config, param))) {
- mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Unknown profile '%.*s'.\n",
- BSTR_P(param));
+ MP_ERR(config, "Unknown profile '%.*s'.\n", BSTR_P(param));
return M_OPT_EXIT - 1;
}
if (!config->profile_depth)
- mp_msg(MSGT_CFGPARSER, MSGL_INFO, "Profile %s: %s\n", p->name,
+ MP_INFO(config, "Profile %s: %s\n", p->name,
p->desc ? p->desc : "");
config->profile_depth++;
for (i = 0; i < p->num_opts; i++) {
@@ -127,8 +123,7 @@ static int show_profile(struct m_config *config, bstr param)
spc[j] = ' ';
spc[config->profile_depth] = '\0';
- mp_msg(MSGT_CFGPARSER, MSGL_INFO, "%s%s=%s\n", spc,
- p->opts[2 * i], p->opts[2 * i + 1]);
+ MP_INFO(config, "%s%s=%s\n", spc, p->opts[2 * i], p->opts[2 * i + 1]);
if (config->profile_depth < MAX_PROFILE_DEPTH
&& !strcmp(p->opts[2*i], "profile")) {
@@ -149,7 +144,7 @@ static int show_profile(struct m_config *config, bstr param)
}
config->profile_depth--;
if (!config->profile_depth)
- mp_msg(MSGT_CFGPARSER, MSGL_INFO, "\n");
+ MP_INFO(config, "\n");
return M_OPT_EXIT - 1;
}
@@ -187,13 +182,13 @@ static void config_destroy(void *p)
m_option_free(config->opts[n].opt, config->opts[n].data);
}
-struct m_config *m_config_new(void *talloc_ctx, size_t size,
- const void *defaults,
+struct m_config *m_config_new(void *talloc_ctx, struct mp_log *log,
+ size_t size, const void *defaults,
const struct m_option *options)
{
struct m_config *config = talloc(talloc_ctx, struct m_config);
talloc_set_destructor(config, config_destroy);
- *config = (struct m_config) {0};
+ *config = (struct m_config) {.log = log};
// size==0 means a dummy object is created
if (size) {
config->optstruct = talloc_zero_size(config, size);
@@ -205,18 +200,19 @@ struct m_config *m_config_new(void *talloc_ctx, size_t size,
return config;
}
-struct m_config *m_config_from_obj_desc(void *talloc_ctx,
+struct m_config *m_config_from_obj_desc(void *talloc_ctx, struct mp_log *log,
struct m_obj_desc *desc)
{
- return m_config_new(talloc_ctx, desc->priv_size, desc->priv_defaults,
+ return m_config_new(talloc_ctx, log, desc->priv_size, desc->priv_defaults,
desc->options);
}
// Like m_config_from_obj_desc(), but don't allocate option struct.
struct m_config *m_config_from_obj_desc_noalloc(void *talloc_ctx,
+ struct mp_log *log,
struct m_obj_desc *desc)
{
- return m_config_new(talloc_ctx, 0, desc->priv_defaults, desc->options);
+ return m_config_new(talloc_ctx, log, 0, desc->priv_defaults, desc->options);
}
int m_config_set_obj_params(struct m_config *conf, char **args)
@@ -284,7 +280,7 @@ void m_config_backup_opt(struct m_config *config, const char *opt)
if (co) {
ensure_backup(config, co);
} else {
- mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Option %s not found.\n", opt);
+ MP_ERR(config, "Option %s not found.\n", opt);
}
}
@@ -496,15 +492,13 @@ static int m_config_parse_option(struct m_config *config, struct bstr name,
// Check if this option isn't forbidden in the current mode
if ((flags & M_SETOPT_FROM_CONFIG_FILE) && (co->opt->flags & M_OPT_NOCFG)) {
- mp_msg(MSGT_CFGPARSER, MSGL_ERR,
- "The %.*s option can't be used in a config file.\n",
+ MP_ERR(config, "The %.*s option can't be used in a config file.\n",
BSTR_P(name));
return M_OPT_INVALID;
}
if (flags & M_SETOPT_BACKUP) {
if (co->opt->flags & M_OPT_GLOBAL) {
- mp_msg(MSGT_CFGPARSER, MSGL_ERR,
- "The %.*s option is global and can't be set per-file.\n",
+ MP_ERR(config, "The %.*s option is global and can't be set per-file.\n",
BSTR_P(name));
return M_OPT_INVALID;
}
@@ -529,7 +523,8 @@ static int m_config_parse_option(struct m_config *config, struct bstr name,
return parse_subopts(config, (char *)co->name, prefix, param, flags);
}
- int r = m_option_parse(co->opt, name, param, set ? co->data : NULL);
+ int r = m_option_parse(config->log, co->opt, name, param,
+ set ? co->data : NULL);
if (r >= 0 && set && (flags & M_SETOPT_FROM_CMDLINE)) {
co->is_set_from_cmdline = true;
@@ -551,7 +546,7 @@ static int parse_subopts(struct m_config *config, char *name, char *prefix,
{
char **lst = NULL;
// Split the argument into child options
- int r = m_option_type_subconfig.parse(NULL, bstr0(""), param, &lst);
+ int r = m_option_type_subconfig.parse(config->log, NULL, bstr0(""), param, &lst);
if (r < 0)
return r;
// Parse the child options
@@ -563,9 +558,8 @@ static int parse_subopts(struct m_config *config, char *name, char *prefix,
r = m_config_parse_option(config,bstr0(n), bstr0(lst[2 * i + 1]), flags);
if (r < 0) {
if (r > M_OPT_EXIT) {
- mp_msg(MSGT_CFGPARSER, MSGL_ERR,
- "Error parsing suboption %s/%s (%s)\n",
- name, lst[2 * i], m_option_strerror(r));
+ MP_ERR(config, "Error parsing suboption %s/%s (%s)\n",
+ name, lst[2 * i], m_option_strerror(r));
r = M_OPT_INVALID;
}
break;
@@ -582,8 +576,8 @@ int m_config_parse_suboptions(struct m_config *config, char *name,
return 0;
int r = parse_subopts(config, name, "", bstr0(subopts), 0);
if (r < 0 && r > M_OPT_EXIT) {
- mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Error parsing suboption %s (%s)\n",
- name, m_option_strerror(r));
+ MP_ERR(config, "Error parsing suboption %s (%s)\n",
+ name, m_option_strerror(r));
r = M_OPT_INVALID;
}
return r;
@@ -594,8 +588,8 @@ int m_config_set_option_ext(struct m_config *config, struct bstr name,
{
int r = m_config_parse_option(config, name, param, flags);
if (r < 0 && r > M_OPT_EXIT) {
- mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Error parsing option %.*s (%s)\n",
- BSTR_P(name), m_option_strerror(r));
+ MP_ERR(config, "Error parsing option %.*s (%s)\n",
+ BSTR_P(name), m_option_strerror(r));
r = M_OPT_INVALID;
}
return r;
@@ -633,7 +627,7 @@ void m_config_print_option_list(const struct m_config *config)
int count = 0;
const char *prefix = config->is_toplevel ? "--" : "";
- mp_msg(MSGT_CFGPARSER, MSGL_INFO, "Options:\n\n");
+ MP_INFO(config, "Options:\n\n");
for (int i = 0; i < config->num_opts; i++) {
struct m_config_option *co = &config->opts[i];
const struct m_option *opt = co->opt;
@@ -641,16 +635,16 @@ void m_config_print_option_list(const struct m_config *config)
continue;
if (co->is_generated)
continue;
- mp_msg(MSGT_CFGPARSER, MSGL_INFO, " %s%-30.30s", prefix, co->name);
+ MP_INFO(config, " %s%-30.30s", prefix, co->name);
if (opt->type == &m_option_type_choice) {
- mp_msg(MSGT_CFGPARSER, MSGL_INFO, " Choices:");
+ MP_INFO(config, " Choices:");
struct m_opt_choice_alternatives *alt = opt->priv;
for (int n = 0; alt[n].name; n++)
- mp_msg(MSGT_CFGPARSER, MSGL_INFO, " %s", alt[n].name);
+ MP_INFO(config, " %s", alt[n].name);
if (opt->flags & (M_OPT_MIN | M_OPT_MAX))
- mp_msg(MSGT_CFGPARSER, MSGL_INFO, " (or an integer)");
+ MP_INFO(config, " (or an integer)");
} else {
- mp_msg(MSGT_CFGPARSER, MSGL_INFO, " %s", co->opt->type->name);
+ MP_INFO(config, " %s", co->opt->type->name);
}
if (opt->flags & (M_OPT_MIN | M_OPT_MAX)) {
snprintf(min, sizeof(min), "any");
@@ -659,23 +653,23 @@ void m_config_print_option_list(const struct m_config *config)
snprintf(min, sizeof(min), "%.14g", opt->min);
if (opt->flags & M_OPT_MAX)
snprintf(max, sizeof(max), "%.14g", opt->max);
- mp_msg(MSGT_CFGPARSER, MSGL_INFO, " (%s to %s)", min, max);
+ MP_INFO(config, " (%s to %s)", min, max);
}
char *def = NULL;
if (co->default_data)
def = m_option_print(co->opt, co->default_data);
if (def) {
- mp_msg(MSGT_CFGPARSER, MSGL_INFO, " (default: %s)", def);
+ MP_INFO(config, " (default: %s)", def);
talloc_free(def);
}
if (opt->flags & CONF_GLOBAL)
- mp_msg(MSGT_CFGPARSER, MSGL_INFO, " [global]");
+ MP_INFO(config, " [global]");
if (opt->flags & CONF_NOCFG)
- mp_msg(MSGT_CFGPARSER, MSGL_INFO, " [nocfg]");
- mp_msg(MSGT_CFGPARSER, MSGL_INFO, "\n");
+ MP_INFO(config, " [nocfg]");
+ MP_INFO(config, "\n");
count++;
}
- mp_msg(MSGT_CFGPARSER, MSGL_INFO, "\nTotal: %d options\n", count);
+ MP_INFO(config, "\nTotal: %d options\n", count);
}
struct m_profile *m_config_get_profile(const struct m_config *config, bstr name)
@@ -731,8 +725,7 @@ void m_config_set_profile(struct m_config *config, struct m_profile *p,
int flags)
{
if (config->profile_depth > MAX_PROFILE_DEPTH) {
- mp_msg(MSGT_CFGPARSER, MSGL_WARN,
- "WARNING: Profile inclusion too deep.\n");
+ MP_WARN(config, "WARNING: Profile inclusion too deep.\n");
return;
}
config->profile_depth++;
diff --git a/options/m_config.h b/options/m_config.h
index 829fa90ba7..2624f45edf 100644
--- a/options/m_config.h
+++ b/options/m_config.h
@@ -34,6 +34,7 @@ struct m_option_type;
struct m_sub_options;
struct m_obj_desc;
struct m_obj_settings;
+struct mp_log;
// Config option
struct m_config_option {
@@ -48,6 +49,8 @@ struct m_config_option {
// Config object
/** \ingroup Config */
typedef struct m_config {
+ struct mp_log *log;
+
// Registered options.
struct m_config_option *opts; // all options, even suboptions
int num_opts;
@@ -77,14 +80,15 @@ typedef struct m_config {
// and a corresponding option switch or sub-option field.
// suboptinit: if not NULL, initialize the suboption string (used for presets)
// Note that the m_config object will keep pointers to defaults and options.
-struct m_config *m_config_new(void *talloc_ctx, size_t size,
- const void *defaults,
+struct m_config *m_config_new(void *talloc_ctx, struct mp_log *log,
+ size_t size, const void *defaults,
const struct m_option *options);
-struct m_config *m_config_from_obj_desc(void *talloc_ctx,
+struct m_config *m_config_from_obj_desc(void *talloc_ctx, struct mp_log *log,
struct m_obj_desc *desc);
struct m_config *m_config_from_obj_desc_noalloc(void *talloc_ctx,
+ struct mp_log *log,
struct m_obj_desc *desc);
int m_config_set_obj_params(struct m_config *conf, char **args);
diff --git a/options/m_option.c b/options/m_option.c
index 32301b5ec3..69d8ba0376 100644
--- a/options/m_option.c
+++ b/options/m_option.c
@@ -117,8 +117,8 @@ static int clamp_flag(const m_option_t *opt, void *val)
return M_OPT_OUT_OF_RANGE;
}
-static int parse_flag(const m_option_t *opt, struct bstr name,
- struct bstr param, void *dst)
+static int parse_flag(struct mp_log *log, const m_option_t *opt,
+ struct bstr name, struct bstr param, void *dst)
{
if (param.len) {
if (!bstrcmp0(param, "yes")) {
@@ -131,8 +131,7 @@ static int parse_flag(const m_option_t *opt, struct bstr name,
VAL(dst) = opt->min;
return 1;
}
- mp_msg(MSGT_CFGPARSER, MSGL_ERR,
- "Invalid parameter for %.*s flag: %.*s\n",
+ mp_err(log, "Invalid parameter for %.*s flag: %.*s\n",
BSTR_P(name), BSTR_P(param));
return M_OPT_INVALID;
} else {
@@ -173,16 +172,15 @@ const m_option_type_t m_option_type_flag = {
// Single-value, write-only flag
-static int parse_store(const m_option_t *opt, struct bstr name,
- struct bstr param, void *dst)
+static int parse_store(struct mp_log *log, const m_option_t *opt,
+ struct bstr name, struct bstr param, void *dst)
{
if (param.len == 0 || bstrcmp0(param, "yes") == 0) {
if (dst)
VAL(dst) = opt->max;
return 0;
} else {
- mp_msg(MSGT_CFGPARSER, MSGL_ERR,
- "Invalid parameter for %.*s flag: %.*s\n",
+ mp_err(log, "Invalid parameter for %.*s flag: %.*s\n",
BSTR_P(name), BSTR_P(param));
return M_OPT_DISALLOW_PARAM;
}
@@ -202,16 +200,15 @@ const m_option_type_t m_option_type_store = {
#undef VAL
#define VAL(x) (*(float *)(x))
-static int parse_store_float(const m_option_t *opt, struct bstr name,
- struct bstr param, void *dst)
+static int parse_store_float(struct mp_log *log, const m_option_t *opt,
+ struct bstr name, struct bstr param, void *dst)
{
if (param.len == 0 || bstrcmp0(param, "yes") == 0) {
if (dst)
VAL(dst) = opt->max;
return 0;
} else {
- mp_msg(MSGT_CFGPARSER, MSGL_ERR,
- "Invalid parameter for %.*s flag: %.*s\n",
+ mp_err(log, "Invalid parameter for %.*s flag: %.*s\n",
BSTR_P(name), BSTR_P(param));
return M_OPT_DISALLOW_PARAM;
}
@@ -246,8 +243,8 @@ static int clamp_longlong(const m_option_t *opt, void *val)
return r;
}
-static int parse_longlong(const m_option_t *opt, struct bstr name,
- struct bstr param, void *dst)
+static int parse_longlong(struct mp_log *log, const m_option_t *opt,
+ struct bstr name, struct bstr param, void *dst)
{
if (param.len == 0)
return M_OPT_MISSING_PARAM;
@@ -257,22 +254,19 @@ static int parse_longlong(const m_option_t *opt, struct bstr name,
if (rest.len)
tmp_int = bstrtoll(param, &rest, 0);
if (rest.len) {
- mp_msg(MSGT_CFGPARSER, MSGL_ERR,
- "The %.*s option must be an integer: %.*s\n",
+ mp_err(log, "The %.*s option must be an integer: %.*s\n",
BSTR_P(name), BSTR_P(param));
return M_OPT_INVALID;
}
if ((opt->flags & M_OPT_MIN) && (tmp_int < opt->min)) {
- mp_msg(MSGT_CFGPARSER, MSGL_ERR,
- "The %.*s option must be >= %d: %.*s\n",
+ mp_err(log, "The %.*s option must be >= %d: %.*s\n",
BSTR_P(name), (int) opt->min, BSTR_P(param));
return M_OPT_OUT_OF_RANGE;
}
if ((opt->flags & M_OPT_MAX) && (tmp_int > opt->max)) {
- mp_msg(MSGT_CFGPARSER, MSGL_ERR,
- "The %.*s option must be <= %d: %.*s\n",
+ mp_err(log, "The %.*s option must be <= %d: %.*s\n",
BSTR_P(name), (int) opt->max, BSTR_P(param));
return M_OPT_OUT_OF_RANGE;
}
@@ -299,21 +293,21 @@ static int clamp_int64(const m_option_t *opt, void *val)
return r;
}
-static int parse_int(const m_option_t *opt, struct bstr name,
- struct bstr param, void *dst)
+static int parse_int(struct mp_log *log, const m_option_t *opt,
+ struct bstr name, struct bstr param, void *dst)
{
long long tmp;
- int r = parse_longlong(opt, name, param, &tmp);
+ int r = parse_longlong(log, opt, name, param, &tmp);
if (r >= 0 && dst)
*(int *)dst = tmp;
return r;
}
-static int parse_int64(const m_option_t *opt, struct bstr name,
- struct bstr param, void *dst)
+static int parse_int64(struct mp_log *log, const m_option_t *opt,
+ struct bstr name, struct bstr param, void *dst)
{
long long tmp;
- int r = parse_longlong(opt, name, param, &tmp);
+ int r = parse_longlong(log, opt, name, param, &tmp);
if (r >= 0 && dst)
*(int64_t *)dst = tmp;
return r;
@@ -395,8 +389,8 @@ const m_option_type_t m_option_type_int64 = {
.clamp = clamp_int64,
};
-static int parse_intpair(const struct m_option *opt, struct bstr name,
- struct bstr param, void *dst)
+static int parse_intpair(struct mp_log *log, const struct m_option *opt,
+ struct bstr name, struct bstr param, void *dst)
{
if (param.len == 0)
return M_OPT_MISSING_PARAM;
@@ -425,7 +419,7 @@ static int parse_intpair(const struct m_option *opt, struct bstr name,
return 1;
bad:
- mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Invalid integer range "
+ mp_err(log, "Invalid integer range "
"specification for option %.*s: %.*s\n",
BSTR_P(name), BSTR_P(param));
return M_OPT_INVALID;
@@ -453,8 +447,8 @@ static int clamp_choice(const m_option_t *opt, void *val)
return M_OPT_INVALID;
}
-static int parse_choice(const struct m_option *opt, struct bstr name,
- struct bstr param, void *dst)
+static int parse_choice(struct mp_log *log, const struct m_option *opt,
+ struct bstr name, struct bstr param, void *dst)
{
struct m_opt_choice_alternatives *alt = opt->priv;
for ( ; alt->name; alt++)
@@ -465,21 +459,20 @@ static int parse_choice(const struct m_option *opt, struct bstr name,
return M_OPT_MISSING_PARAM;
if ((opt->flags & M_OPT_MIN) && (opt->flags & M_OPT_MAX)) {
long long val;
- if (parse_longlong(opt, name, param, &val) == 1) {
+ if (parse_longlong(log, opt, name, param, &val) == 1) {
if (dst)
*(int *)dst = val;
return 1;
}
}
- mp_msg(MSGT_CFGPARSER, MSGL_ERR,
- "Invalid value for option %.*s: %.*s\n",
+ mp_err(log, "Invalid value for option %.*s: %.*s\n",
BSTR_P(name), BSTR_P(param));
- mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Valid values are:");
+ mp_err(log, "Valid values are:");
for (alt = opt->priv; alt->name; alt++)
- mp_msg(MSGT_CFGPARSER, MSGL_ERR, " %s", alt->name);
+ mp_err(log, " %s", alt->name);
if ((opt->flags & M_OPT_MIN) && (opt->flags & M_OPT_MAX))
- mp_msg(MSGT_CFGPARSER, MSGL_ERR, " %g-%g", opt->min, opt->max);
- mp_msg(MSGT_CFGPARSER, MSGL_ERR, "\n");
+ mp_err(log, " %g-%g", opt->min, opt->max);
+ mp_err(log, "\n");
return M_OPT_INVALID;
}
if (dst)
@@ -598,8 +591,8 @@ static int clamp_double(const m_option_t *opt, void *val)
return r;
}
-static int parse_double(const m_option_t *opt, struct bstr name,
- struct bstr param, void *dst)
+static int parse_double(struct mp_log *log, const m_option_t *opt,
+ struct bstr name, struct bstr param, void *dst)
{
if (param.len == 0)
return M_OPT_MISSING_PARAM;
@@ -611,8 +604,7 @@ static int parse_double(const m_option_t *opt, struct bstr name,
tmp_float /= bstrtod(rest, &rest);
if (rest.len) {
- mp_msg(MSGT_CFGPARSER, MSGL_ERR,
- "The %.*s option must be a floating point number or a "
+ mp_err(log, "The %.*s option must be a floating point number or a "
"ratio (numerator[:/]denominator): %.*s\n",
BSTR_P(name), BSTR_P(param));
return M_OPT_INVALID;
@@ -620,23 +612,20 @@ static int parse_double(const m_option_t *opt, struct bstr name,
if (opt->flags & M_OPT_MIN)
if (tmp_float < opt->min) {
- mp_msg(MSGT_CFGPARSER, MSGL_ERR,
- "The %.*s option must be >= %f: %.*s\n",
+ mp_err(log, "The %.*s option must be >= %f: %.*s\n",
BSTR_P(name), opt->min, BSTR_P(param));
return M_OPT_OUT_OF_RANGE;
}
if (opt->flags & M_OPT_MAX)
if (tmp_float > opt->max) {
- mp_msg(MSGT_CFGPARSER, MSGL_ERR,
- "The %.*s option must be <= %f: %.*s\n",
+ mp_err(log, "The %.*s option must be <= %f: %.*s\n",
BSTR_P(name), opt->max, BSTR_P(param));
return M_OPT_OUT_OF_RANGE;
}
if (!isfinite(tmp_float)) {
- mp_msg(MSGT_CFGPARSER, MSGL_ERR,
- "The %.*s option must be a finite number: %.*s\n",
+ mp_err(log, "The %.*s option must be a finite number: %.*s\n",
BSTR_P(name), BSTR_P(param));
return M_OPT_OUT_OF_RANGE;
}
@@ -703,11 +692,11 @@ static int clamp_float(const m_option_t *opt, void *val)
return r;
}
-static int parse_float(const m_option_t *opt, struct bstr name,
- struct bstr param, void *dst)
+static int parse_float(struct mp_log *log, const m_option_t *opt,
+ struct bstr name, struct bstr param, void *dst)
{
double tmp;
- int r = parse_double(opt, name, param, &tmp);
+ int r = parse_double(log, opt, name, param, &tmp);
if (r == 1 && dst)
VAL(dst) = tmp;
return r;
@@ -799,8 +788,8 @@ static int clamp_str(const m_option_t *opt, void *val)
return 0;
}
-static int parse_str(const m_option_t *opt, struct bstr name,
- struct bstr param, void *dst)
+static int parse_str(struct mp_log *log, const m_option_t *opt,
+ struct bstr name, struct bstr param, void *dst)
{
int r = 1;
void *tmp = talloc_new(NULL);
@@ -820,8 +809,7 @@ static int parse_str(const m_option_t *opt, struct bstr name,
if (opt->flags & M_OPT_PARSE_ESCAPES) {
char *res = unescape_string(tmp, param);
if (!res) {
- mp_msg(MSGT_CFGPARSER, MSGL_ERR,
- "Parameter has broken escapes: %.*s\n", BSTR_P(param));
+ mp_err(log, "Parameter has broken escapes: %.*s\n", BSTR_P(param));
r = M_OPT_INVALID;
goto exit;
}
@@ -829,16 +817,14 @@ static int parse_str(const m_option_t *opt, struct bstr name,
}
if ((opt->flags & M_OPT_MIN) && (param.len < opt->min)) {
- mp_msg(MSGT_CFGPARSER, MSGL_ERR,
- "Parameter must be >= %d chars: %.*s\n",
+ mp_err(log, "Parameter must be >= %d chars: %.*s\n",
(int) opt->min, BSTR_P(param));
r = M_OPT_OUT_OF_RANGE;
goto exit;
}
if ((opt->flags & M_OPT_MAX) && (param.len > opt->max)) {
- mp_msg(MSGT_CFGPARSER, MSGL_ERR,
- "Parameter must be <= %d chars: %.*s\n",
+ mp_err(log, "Parameter must be <= %d chars: %.*s\n",
(int) opt->max, BSTR_P(param));
r = M_OPT_OUT_OF_RANGE;
goto exit;
@@ -942,7 +928,7 @@ static int str_list_add(char **add, int n, void *dst, int pre)
return 1;
}
-static int str_list_del(char **del, int n, void *dst)
+static int str_list_del(struct mp_log *log, char **del, int n, void *dst)
{
char **lst, *ep;
int i, ln, s;
@@ -959,14 +945,13 @@ static int str_list_del(char **del, int n, void *dst)
for (i = 0; del[i] != NULL; i++) {
idx = strtol(del[i], &ep, 0);
if (*ep) {
- mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Invalid index: %s\n", del[i]);
+ mp_err(log, "Invalid index: %s\n", del[i]);
talloc_free(del[i]);
continue;
}
talloc_free(del[i]);
if (idx < 0 || idx >= ln) {
- mp_msg(MSGT_CFGPARSER, MSGL_ERR,
- "Index %ld is out of range.\n", idx);
+ mp_err(log, "Index %ld is out of range.\n", idx);
continue;
} else if (!lst[idx])
continue;
@@ -1016,8 +1001,8 @@ static struct bstr get_nextsep(struct bstr *ptr, char sep, bool modify)
return bstr_splice(orig, 0, str.start - orig.start);
}
-static int parse_str_list(const m_option_t *opt, struct bstr name,
- struct bstr param, void *dst)
+static int parse_str_list(struct mp_log *log, const m_option_t *opt,
+ struct bstr name, struct bstr param, void *dst)
{
char **res;
int op = OP_NONE;
@@ -1088,7 +1073,7 @@ static int parse_str_list(const m_option_t *opt, struct bstr name,
case OP_PRE:
return str_list_add(res, n, dst, 1);
case OP_DEL:
- return str_list_del(res, n, dst);
+ return str_list_del(log, res, n, dst);
}
if (VAL(dst))
@@ -1165,16 +1150,16 @@ const m_option_type_t m_option_type_string_list = {
/////////////////// Print
-static int parse_print(const m_option_t *opt, struct bstr name,
- struct bstr param, void *dst)
+static int parse_print(struct mp_log *log, const m_option_t *opt,
+ struct bstr name, struct bstr param, void *dst)
{
if (opt->type == CONF_TYPE_PRINT) {
const char *msg = opt->p;
- mp_msg(MSGT_CFGPARSER, MSGL_INFO, "%s", msg);
+ mp_info(log, "%s", msg);
} else {
char *name0 = bstrdup0(NULL, name);
char *param0 = bstrdup0(NULL, param);
- int r = ((m_opt_func_full_t) opt->p)(opt, name0, param0);
+ int r = ((m_opt_func_full_t) opt->p)(log, opt, name0, param0);
talloc_free(name0);
talloc_free(param0);
return r;
@@ -1211,7 +1196,8 @@ const m_option_type_t m_option_type_print_func = {
// Read s sub-option name, or a positional sub-opt value.
// Return 0 on succes, M_OPT_ error code otherwise.
// optname is for error reporting.
-static int read_subparam(bstr optname, bstr *str, bstr *out_subparam)
+static int read_subparam(struct mp_log *log, bstr optname,
+ bstr *str, bstr *out_subparam)
{
bstr p = *str;
bstr subparam = {0};
@@ -1221,24 +1207,21 @@ static int read_subparam(bstr optname, bstr *str, bstr *out_subparam)
subparam = bstr_splice(p, 0, optlen);
p = bstr_cut(p, optlen);
if (!bstr_startswith0(p, "\"")) {
- mp_msg(MSGT_CFGPARSER, MSGL_ERR,
- "Terminating '\"' missing for '%.*s'\n",
+ mp_err(log, "Terminating '\"' missing for '%.*s'\n",
BSTR_P(optname));
return M_OPT_INVALID;
}
p = bstr_cut(p, 1);
} else if (bstr_eatstart0(&p, "[")) {
if (!bstr_split_tok(p, "]", &subparam, &p)) {
- mp_msg(MSGT_CFGPARSER, MSGL_ERR,
- "Terminating ']' missing for '%.*s'\n",
+ mp_err(log, "Terminating ']' missing for '%.*s'\n",
BSTR_P(optname));
return M_OPT_INVALID;
}
} else if (bstr_eatstart0(&p, "%")) {
int optlen = bstrtoll(p, &p, 0);
if (!bstr_startswith0(p, "%") || (optlen > p.len - 1)) {
- mp_msg(MSGT_CFGPARSER, MSGL_ERR,
- "Invalid length %d for '%.*s'\n",
+ mp_err(log, "Invalid length %d for '%.*s'\n",
optlen, BSTR_P(optname));
return M_OPT_INVALID;
}
@@ -1261,16 +1244,17 @@ static int read_subparam(bstr optname, bstr *str, bstr *out_subparam)
// On success, set *out_name and *out_val, and advance *str
// out_val.start is NULL if there was no parameter.
// optname is for error reporting.
-static int split_subconf(bstr optname, bstr *str, bstr *out_name, bstr *out_val)
+static int split_subconf(struct mp_log *log, bstr optname, bstr *str,
+ bstr *out_name, bstr *out_val)
{
bstr p = *str;
bstr subparam = {0};
bstr subopt;
- int r = read_subparam(optname, &p, &subopt);
+ int r = read_subparam(log, optname, &p, &subopt);
if (r < 0)
return r;
if (bstr_eatstart0(&p, "=")) {
- r = read_subparam(subopt, &p, &subparam);
+ r = read_subparam(log, subopt, &p, &subparam);
if (r < 0)
return r;
}
@@ -1280,8 +1264,8 @@ static int split_subconf(bstr optname, bstr *str, bstr *out_name, bstr *out_val)
return 0;
}
-static int parse_subconf(const m_option_t *opt, struct bstr name,
- struct bstr param, void *dst)
+static int parse_subconf(struct mp_log *log, const m_option_t *opt,
+ struct bstr name, struct bstr param, void *dst)
{
int nr = 0;
char **lst = NULL;
@@ -1293,14 +1277,13 @@ static int parse_subconf(const m_option_t *opt, struct bstr name,
while (p.len) {
bstr subopt, subparam;
- int r = split_subconf(name, &p, &subopt, &subparam);
+ int r = split_subconf(log, name, &p, &subopt, &subparam);
if (r < 0)
return r;
if (bstr_startswith0(p, ":"))
p = bstr_cut(p, 1);
else if (p.len > 0) {
- mp_msg(MSGT_CFGPARSER, MSGL_ERR,
- "Incorrect termination for '%.*s'\n", BSTR_P(subopt));
+ mp_err(log, "Incorrect termination for '%.*s'\n", BSTR_P(subopt));
return M_OPT_INVALID;
}
@@ -1335,8 +1318,8 @@ const m_option_type_t m_option_type_subconfig_struct = {
#undef VAL
#define VAL(x) (*(char **)(x))
-static int parse_msglevels(const m_option_t *opt, struct bstr name,
- struct bstr param, void *dst)
+static int parse_msglevels(struct mp_log *log, const m_option_t *opt,
+ struct bstr name, struct bstr param, void *dst)
{
if (param.start == NULL)
return M_OPT_MISSING_PARAM;
@@ -1347,8 +1330,7 @@ static int parse_msglevels(const m_option_t *opt, struct bstr name,
if (res == 0)
break;
if (res < 0) {
- mp_msg(MSGT_CFGPARSER, MSGL_ERR,
- "Invalid syntax: %.*s\n", BSTR_P(s));
+ mp_err(log, "Invalid syntax: %.*s\n", BSTR_P(s));
return M_OPT_INVALID;
}
}
@@ -1373,8 +1355,8 @@ const m_option_type_t m_option_type_msglevels = {
#undef VAL
-static int parse_color(const m_option_t *opt, struct bstr name,
- struct bstr param, void *dst)
+static int parse_color(struct mp_log *log, const m_option_t *opt,
+ struct bstr name, struct bstr param, void *dst)
{
if (param.len == 0)
return M_OPT_MISSING_PARAM;
@@ -1406,11 +1388,9 @@ static int parse_color(const m_option_t *opt, struct bstr name,
return 1;
error:
- mp_msg(MSGT_CFGPARSER, MSGL_ERR,
- "Option %.*s: invalid color: '%.*s'\n",
+ mp_err(log, "Option %.*s: invalid color: '%.*s'\n",
BSTR_P(name), BSTR_P(param));
- mp_msg(MSGT_CFGPARSER, MSGL_ERR,
- "Valid colors must be in the form #RRRGGBB or #AARRGGBB (in hex)\n");
+ mp_err(log, "Valid colors must be in the form #RRRGGBB or #AARRGGBB (in hex)\n");
return M_OPT_INVALID;
}
@@ -1539,8 +1519,8 @@ void m_geometry_apply(int *xpos, int *ypos, int *widw, int *widh,
}
}
-static int parse_geometry(const m_option_t *opt, struct bstr name,
- struct bstr param, void *dst)
+static int parse_geometry(struct mp_log *log, const m_option_t *opt,
+ struct bstr name, struct bstr param, void *dst)
{
struct m_geometry gm;
if (!parse_geometry_str(&gm, param))
@@ -1552,10 +1532,9 @@ static int parse_geometry(const m_option_t *opt, struct bstr name,
return 1;
error:
- mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Option %.*s: invalid geometry: '%.*s'\n",
+ mp_err(log, "Option %.*s: invalid geometry: '%.*s'\n",
BSTR_P(name), BSTR_P(param));
- mp_msg(MSGT_CFGPARSER, MSGL_ERR,
- "Valid format: [W[%%][xH[%%]]][{+-}X[%%]{+-}Y[%%]] | [X[%%]:Y[%%]]\n");
+ mp_err(log, "Valid format: [W[%%][xH[%%]]][{+-}X[%%]{+-}Y[%%]] | [X[%%]:Y[%%]]\n");
return M_OPT_INVALID;
}
@@ -1566,8 +1545,8 @@ const m_option_type_t m_option_type_geometry = {
.copy = copy_opt,
};
-static int parse_size_box(const m_option_t *opt, struct bstr name,
- struct bstr param, void *dst)
+static int parse_size_box(struct mp_log *log, const m_option_t *opt,
+ struct bstr name, struct bstr param, void *dst)
{
struct m_geometry gm;
if (!parse_geometry_str(&gm, param))
@@ -1582,10 +1561,9 @@ static int parse_size_box(const m_option_t *opt, struct bstr name,
return 1;
error:
- mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Option %.*s: invalid size: '%.*s'\n",
+ mp_err(log, "Option %.*s: invalid size: '%.*s'\n",
BSTR_P(name), BSTR_P(param));
- mp_msg(MSGT_CFGPARSER, MSGL_ERR,
- "Valid format: W[%%][xH[%%]] or empty string\n");
+ mp_err(log, "Valid format: W[%%][xH[%%]] or empty string\n");
return M_OPT_INVALID;
}
@@ -1599,24 +1577,23 @@ const m_option_type_t m_option_type_size_box = {
#include "video/img_format.h"
-static int parse_imgfmt(const m_option_t *opt, struct bstr name,
- struct bstr param, void *dst)
+static int parse_imgfmt(struct mp_log *log, const m_option_t *opt,
+ struct bstr name, struct bstr param, void *dst)
{
if (param.len == 0)
return M_OPT_MISSING_PARAM;
if (!bstrcmp0(param, "help")) {
- mp_msg(MSGT_CFGPARSER, MSGL_INFO, "Available formats:");
+ mp_info(log, "Available formats:");
for (int i = 0; mp_imgfmt_list[i].name; i++)
- mp_msg(MSGT_CFGPARSER, MSGL_INFO, " %s", mp_imgfmt_list[i].name);
- mp_msg(MSGT_CFGPARSER, MSGL_INFO, "\n");
+ mp_info(log, " %s", mp_imgfmt_list[i].name);
+ mp_info(log, "\n");
return M_OPT_EXIT - 1;
}
unsigned int fmt = mp_imgfmt_from_name(param, true);
if (!fmt) {
- mp_msg(MSGT_CFGPARSER, MSGL_ERR,
- "Option %.*s: unknown format name: '%.*s'\n",
+ mp_err(log, "Option %.*s: unknown format name: '%.*s'\n",
BSTR_P(name), BSTR_P(param));
return M_OPT_INVALID;
}
@@ -1635,8 +1612,8 @@ const m_option_type_t m_option_type_imgfmt = {
.copy = copy_opt,
};
-static int parse_fourcc(const m_option_t *opt, struct bstr name,
- struct bstr param, void *dst)
+static int parse_fourcc(struct mp_log *log, const m_option_t *opt,
+ struct bstr name, struct bstr param, void *dst)
{
if (param.len == 0)
return M_OPT_MISSING_PARAM;
@@ -1650,8 +1627,7 @@ static int parse_fourcc(const m_option_t *opt, struct bstr name,
bstr rest;
value = bstrtoll(param, &rest, 16);
if (rest.len != 0) {
- mp_msg(MSGT_CFGPARSER, MSGL_ERR,
- "Option %.*s: invalid FourCC: '%.*s'\n",
+ mp_err(log, "Option %.*s: invalid FourCC: '%.*s'\n",
BSTR_P(name), BSTR_P(param));
return M_OPT_INVALID;
}
@@ -1672,24 +1648,23 @@ const m_option_type_t m_option_type_fourcc = {
#include "audio/format.h"
-static int parse_afmt(const m_option_t *opt, struct bstr name,
- struct bstr param, void *dst)
+static int parse_afmt(struct mp_log *log, const m_option_t *opt,
+ struct bstr name, struct bstr param, void *dst)
{
if (param.len == 0)
return M_OPT_MISSING_PARAM;
if (!bstrcmp0(param, "help")) {
- mp_msg(MSGT_CFGPARSER, MSGL_INFO, "Available formats:");
+ mp_info(log, "Available formats:");
for (int i = 0; af_fmtstr_table[i].name; i++)
- mp_msg(MSGT_CFGPARSER, MSGL_INFO, " %s", af_fmtstr_table[i].name);
- mp_msg(MSGT_CFGPARSER, MSGL_INFO, "\n");
+ mp_info(log, " %s", af_fmtstr_table[i].name);
+ mp_info(log, "\n");
return M_OPT_EXIT - 1;
}
int fmt = af_str2fmt_short(param);
if (!fmt) {
- mp_msg(MSGT_CFGPARSER, MSGL_ERR,
- "Option %.*s: unknown format name: '%.*s'\n",
+ mp_err(log, "Option %.*s: unknown format name: '%.*s'\n",
BSTR_P(name), BSTR_P(param));
return M_OPT_INVALID;
}
@@ -1710,14 +1685,14 @@ const m_option_type_t m_option_type_afmt = {
#include "audio/chmap.h"
-static int parse_chmap(const m_option_t *opt, struct bstr name,
- struct bstr param, void *dst)
+static int parse_chmap(struct mp_log *log, const m_option_t *opt,
+ struct bstr name, struct bstr param, void *dst)
{
// min>0: at least min channels, min=0: empty ok, min=-1: invalid ok
int min_ch = (opt->flags & M_OPT_MIN) ? opt->min : 1;
if (bstr_equals0(param, "help")) {
- mp_chmap_print_help(MSGT_CFGPARSER, MSGL_INFO);
+ mp_chmap_print_help(log);
return M_OPT_EXIT - 1;
}
@@ -1726,16 +1701,14 @@ static int parse_chmap(const m_option_t *opt, struct bstr name,
struct mp_chmap res = {0};
if (!mp_chmap_from_str(&res, param)) {
- mp_msg(MSGT_CFGPARSER, MSGL_ERR,
- "Error parsing channel layout: %.*s\n", BSTR_P(param));
+ mp_err(log, "Error parsing channel layout: %.*s\n", BSTR_P(param));
return M_OPT_INVALID;
}
if ((min_ch > 0 && !mp_chmap_is_valid(&res)) ||
(min_ch >= 0 && mp_chmap_is_empty(&res)))
{
- mp_msg(MSGT_CFGPARSER, MSGL_ERR,
- "Invalid channel layout: %.*s\n", BSTR_P(param));
+ mp_err(log, "Invalid channel layout: %.*s\n", BSTR_P(param));
return M_OPT_INVALID;
}
@@ -1773,8 +1746,8 @@ static int parse_timestring(struct bstr str, double *time, char endchar)
}
-static int parse_time(const m_option_t *opt, struct bstr name,
- struct bstr param, void *dst)
+static int parse_time(struct mp_log *log, const m_option_t *opt,
+ struct bstr name, struct bstr param, void *dst)
{
double time;
@@ -1782,7 +1755,7 @@ static int parse_time(const m_option_t *opt, struct bstr name,
return M_OPT_MISSING_PARAM;
if (!parse_timestring(param, &time, 0)) {
- mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Option %.*s: invalid time: '%.*s'\n",
+ mp_err(log, "Option %.*s: invalid time: '%.*s'\n",
BSTR_P(name), BSTR_P(param));
return M_OPT_INVALID;
}
@@ -1811,8 +1784,8 @@ const m_option_type_t m_option_type_time = {
// Relative time
-static int parse_rel_time(const m_option_t *opt, struct bstr name,
- struct bstr param, void *dst)
+static int parse_rel_time(struct mp_log *log, const m_option_t *opt,
+ struct bstr name, struct bstr param, void *dst)
{
struct m_rel_time t = {0};
@@ -1847,8 +1820,7 @@ static int parse_rel_time(const m_option_t *opt, struct bstr name,
goto out;
}
- mp_msg(MSGT_CFGPARSER, MSGL_ERR,
- "Option %.*s: invalid time or position: '%.*s'\n",
+ mp_err(log, "Option %.*s: invalid time or position: '%.*s'\n",
BSTR_P(name), BSTR_P(param));
return M_OPT_INVALID;
@@ -1893,9 +1865,7 @@ bool m_obj_list_find(struct m_obj_desc *dst, const struct m_obj_list *l,
} else {
// Assume it's deprecated in this case.
// Also, it's used by the VO code only, so whatever.
- mp_msg(MSGT_CFGPARSER, MSGL_WARN,
- "Driver '%s' has been replaced with '%s'!\n",
- aname, alias);
+ dst->replaced_name = aname;
}
return true;
}
@@ -2052,9 +2022,9 @@ static void copy_obj_settings_list(const m_option_t *opt, void *dst,
// Consider -vf a=b=c:d=e. This verifies "b"="c" and "d"="e" and that the
// option names/values are correct. Try to determine whether an option
// without '=' sets a flag, or whether it's a positional argument.
-static int get_obj_param(bstr opt_name, bstr obj_name, struct m_config *config,
- bstr name, bstr val, int flags, int *nold,
- bstr *out_name, bstr *out_val)
+static int get_obj_param(struct mp_log *log, bstr opt_name, bstr obj_name,
+ struct m_config *config, bstr name, bstr val,
+ int flags, int *nold, bstr *out_name, bstr *out_val)
{
int r;
@@ -2068,13 +2038,12 @@ static int get_obj_param(bstr opt_name, bstr obj_name, struct m_config *config,
r = m_config_set_option_ext(config, name, val, flags);
if (r < 0) {
if (r == M_OPT_UNKNOWN) {
- mp_msg(MSGT_CFGPARSER, MSGL_ERR,
- "Option %.*s: %.*s doesn't have a %.*s parameter.\n",
+ mp_err(log, "Option %.*s: %.*s doesn't have a %.*s parameter.\n",
BSTR_P(opt_name), BSTR_P(obj_name), BSTR_P(name));
return M_OPT_UNKNOWN;
}
if (r > M_OPT_EXIT)
- mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Option %.*s: "
+ mp_err(log, "Option %.*s: "
"Error while parsing %.*s parameter %.*s (%.*s)\n",
BSTR_P(opt_name), BSTR_P(obj_name), BSTR_P(name),
BSTR_P(val));
@@ -2092,7 +2061,7 @@ static int get_obj_param(bstr opt_name, bstr obj_name, struct m_config *config,
}
const char *opt = m_config_get_positional_option(config, *nold);
if (!opt) {
- mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Option %.*s: %.*s has only %d "
+ mp_err(log, "Option %.*s: %.*s has only %d "
"params, so you can't give more than %d unnamed params.\n",
BSTR_P(opt_name), BSTR_P(obj_name), *nold, *nold);
return M_OPT_OUT_OF_RANGE;
@@ -2100,7 +2069,7 @@ static int get_obj_param(bstr opt_name, bstr obj_name, struct m_config *config,
r = m_config_set_option_ext(config, bstr0(opt), val, flags);
if (r < 0) {
if (r > M_OPT_EXIT)
- mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Option %.*s: "
+ mp_err(log, "Option %.*s: "
"Error while parsing %.*s parameter %s (%.*s)\n",
BSTR_P(opt_name), BSTR_P(obj_name), opt, BSTR_P(val));
return r;
@@ -2118,10 +2087,11 @@ static int get_obj_param(bstr opt_name, bstr obj_name, struct m_config *config,
// If config is NULL, all parameters are accepted without checking.
// _ret set to NULL can be used for checking-only.
// flags can contain any M_SETOPT_* flag.
-static int m_obj_parse_sub_config(struct bstr opt_name, struct bstr name,
- struct bstr *pstr, struct m_config *config,
- int flags, void (*print_help_fn)(void),
- char ***ret)
+// desc is optional.
+static int m_obj_parse_sub_config(struct mp_log *log, struct bstr opt_name,
+ struct bstr name, struct bstr *pstr,
+ struct m_config *config, int flags,
+ struct m_obj_desc *desc, char ***ret)
{
int nold = 0;
char **args = NULL;
@@ -2136,12 +2106,12 @@ static int m_obj_parse_sub_config(struct bstr opt_name, struct bstr name,
while (pstr->len > 0) {
bstr fname, fval;
- r = split_subconf(opt_name, pstr, &fname, &fval);
+ r = split_subconf(log, opt_name, pstr, &fname, &fval);
if (r < 0)
goto exit;
if (bstr_equals0(fname, "help"))
goto print_help;
- r = get_obj_param(opt_name, name, config, fname, fval, flags, &nold,
+ r = get_obj_param(log, opt_name, name, config, fname, fval, flags, &nold,
&fname, &fval);
if (r < 0)
goto exit;
@@ -2171,11 +2141,11 @@ static int m_obj_parse_sub_config(struct bstr opt_name, struct bstr name,
print_help: ;
if (config) {
- if (print_help_fn)
- print_help_fn();
+ if (desc->print_help)
+ desc->print_help();
m_config_print_option_list(config);
} else {
- mp_msg(MSGT_CFGPARSER, MSGL_WARN, "Option %.*s doesn't exist.\n",
+ mp_warn(log, "Option %.*s doesn't exist.\n",
BSTR_P(opt_name));
}
r = M_OPT_EXIT - 1;
@@ -2189,8 +2159,8 @@ exit:
#define NAMECH "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-"
// Parse one item, e.g. -vf a=b:c:d,e=f:g => parse a=b:c:d into "a" and "b:c:d"
-static int parse_obj_settings(struct bstr opt, struct bstr *pstr,
- const struct m_obj_list *list,
+static int parse_obj_settings(struct mp_log *log, struct bstr opt,
+ struct bstr *pstr, const struct m_obj_list *list,
m_obj_settings_t **_ret)
{
int r;
@@ -2200,8 +2170,7 @@ static int parse_obj_settings(struct bstr opt, struct bstr *pstr,
if (bstr_eatstart0(pstr, "@")) {
if (!bstr_split_tok(*pstr, ":", &label, pstr)) {
- mp_msg(MSGT_CFGPARSER, MSGL_ERR,
- "Option %.*s: ':' expected after label.\n", BSTR_P(opt));
+ mp_err(log, "Option %.*s: ':' expected after label.\n", BSTR_P(opt));
return M_OPT_INVALID;
}
}
@@ -2215,9 +2184,13 @@ static int parse_obj_settings(struct bstr opt, struct bstr *pstr,
has_param = true;
bool skip = false;
- if (!m_obj_list_find(&desc, list, str)) {
+ if (m_obj_list_find(&desc, list, str)) {
+ if (desc.replaced_name)
+ mp_warn(log, "Driver '%s' has been replaced with '%s'!\n",
+ desc.name, desc.replaced_name);
+ } else {
if (!list->allow_unknown_entries) {
- mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Option %.*s: %.*s doesn't exist.\n",
+ mp_err(log, "Option %.*s: %.*s doesn't exist.\n",
BSTR_P(opt), BSTR_P(str));
return M_OPT_INVALID;
}
@@ -2226,9 +2199,9 @@ static int parse_obj_settings(struct bstr opt, struct bstr *pstr,
}
if (_ret && desc.init_options) {
- struct m_config *config = m_config_from_obj_desc_noalloc(NULL, &desc);
+ struct m_config *config = m_config_from_obj_desc_noalloc(NULL, log, &desc);
bstr s = bstr0(desc.init_options);
- m_obj_parse_sub_config(opt, str, &s, config,
+ m_obj_parse_sub_config(log, opt, str, &s, config,
M_SETOPT_CHECK_ONLY, NULL, &plist);
assert(s.len == 0);
talloc_free(config);
@@ -2237,9 +2210,9 @@ static int parse_obj_settings(struct bstr opt, struct bstr *pstr,
if (has_param) {
struct m_config *config = NULL;
if (!skip)
- config = m_config_from_obj_desc_noalloc(NULL, &desc);
- r = m_obj_parse_sub_config(opt, str, pstr, config,
- M_SETOPT_CHECK_ONLY, desc.print_help,
+ config = m_config_from_obj_desc_noalloc(NULL, log, &desc);
+ r = m_obj_parse_sub_config(log, opt, str, pstr, config,
+ M_SETOPT_CHECK_ONLY, &desc,
_ret ? &plist : NULL);
talloc_free(config);
if (r < 0)
@@ -2259,8 +2232,8 @@ static int parse_obj_settings(struct bstr opt, struct bstr *pstr,
// Parse a single entry for -vf-del (return 0 if not applicable)
// mark_del is bounded by the number of items in dst
-static int parse_obj_settings_del(struct bstr opt_name, struct bstr *param,
- void *dst, bool *mark_del)
+static int parse_obj_settings_del(struct mp_log *log, struct bstr opt_name,
+ struct bstr *param, void *dst, bool *mark_del)
{
bstr s = *param;
if (bstr_eatstart0(&s, "@")) {
@@ -2276,8 +2249,7 @@ static int parse_obj_settings_del(struct bstr opt_name, struct bstr *param,
if (label_index >= 0) {
mark_del[label_index] = true;
} else {
- mp_msg(MSGT_CFGPARSER, MSGL_WARN,
- "Option %.*s: item label @%.*s not found.\n",
+ mp_warn(log, "Option %.*s: item label @%.*s not found.\n",
BSTR_P(opt_name), BSTR_P(label));
}
}
@@ -2298,8 +2270,7 @@ static int parse_obj_settings_del(struct bstr opt_name, struct bstr *param,
if (id >= 0 && id < num) {
mark_del[id] = true;
} else {
- mp_msg(MSGT_CFGPARSER, MSGL_WARN,
- "Option %.*s: Index %lld is out of range.\n",
+ mp_warn(log, "Option %.*s: Index %lld is out of range.\n",
BSTR_P(opt_name), id);
}
}
@@ -2308,8 +2279,8 @@ static int parse_obj_settings_del(struct bstr opt_name, struct bstr *param,
return 1;
}
-static int parse_obj_settings_list(const m_option_t *opt, struct bstr name,
- struct bstr param, void *dst)
+static int parse_obj_settings_list(struct mp_log *log, const m_option_t *opt,
+ struct bstr name, struct bstr param, void *dst)
{
int len = strlen(opt->name);
m_obj_settings_t *res = NULL;
@@ -2338,8 +2309,7 @@ static int parse_obj_settings_list(const m_option_t *opt, struct bstr name,
char prefix[len];
strncpy(prefix, opt->name, len - 1);
prefix[len - 1] = '\0';
- mp_msg(MSGT_CFGPARSER, MSGL_ERR,
- "Option %.*s: unknown postfix %.*s\n"
+ mp_err(log, "Option %.*s: unknown postfix %.*s\n"
"Supported postfixes are:\n"
" %s-set\n"
" Overwrite the old list with the given list\n\n"
@@ -2360,17 +2330,17 @@ static int parse_obj_settings_list(const m_option_t *opt, struct bstr name,
}
if (!bstrcmp0(param, "help")) {
- mp_msg(MSGT_CFGPARSER, MSGL_INFO, "Available %s:\n", ol->description);
+ mp_info(log, "Available %s:\n", ol->description);
for (int n = 0; ; n++) {
struct m_obj_desc desc;
if (!ol->get_desc(&desc, n))
break;
if (!desc.hidden) {
- mp_msg(MSGT_CFGPARSER, MSGL_INFO, " %-15s: %s\n",
+ mp_info(log, " %-15s: %s\n",
desc.name, desc.description);
}
}
- mp_msg(MSGT_CFGPARSER, MSGL_INFO, "\n");
+ mp_info(log, "\n");
return M_OPT_EXIT - 1;
}
@@ -2388,9 +2358,9 @@ static int parse_obj_settings_list(const m_option_t *opt, struct bstr name,
while (param.len > 0) {
int r = 0;
if (op == OP_DEL)
- r = parse_obj_settings_del(name, &param, dst, mark_del);
+ r = parse_obj_settings_del(log, name, &param, dst, mark_del);
if (r == 0) {
- r = parse_obj_settings(name, &param, ol, dst ? &res : NULL);
+ r = parse_obj_settings(log, name, &param, ol, dst ? &res : NULL);
}
if (r < 0)
return r;
@@ -2460,8 +2430,7 @@ static int parse_obj_settings_list(const m_option_t *opt, struct bstr name,
for (int n = 0; res && res[n].name; n++) {
int found = obj_settings_find_by_content(list, &res[n]);
if (found < 0) {
- mp_msg(MSGT_CFGPARSER, MSGL_WARN,
- "Option %.*s: Item not found\n", BSTR_P(name));
+ mp_warn(log, "Option %.*s: Item not found\n", BSTR_P(name));
} else {
obj_settings_list_del_at(&list, found);
}
diff --git a/options/m_option.h b/options/m_option.h
index bea7a4376a..5abe605e95 100644
--- a/options/m_option.h
+++ b/options/m_option.h
@@ -31,6 +31,7 @@
typedef struct m_option_type m_option_type_t;
typedef struct m_option m_option_t;
struct m_config;
+struct mp_log;
///////////////////////////// Options types declarations ////////////////////
@@ -63,7 +64,8 @@ extern const m_option_type_t m_option_type_size_box;
extern const m_option_type_t m_option_type_chmap;
// Callback used by m_option_type_print_func options.
-typedef int (*m_opt_func_full_t)(const m_option_t *, const char *, const char *);
+typedef int (*m_opt_func_full_t)(struct mp_log *log, const m_option_t *,
+ const char *, const char *);
enum m_rel_time_type {
REL_TIME_NONE,
@@ -113,6 +115,9 @@ struct m_obj_desc {
bool hidden;
// Callback to print custom help if "help" is passed
void (*print_help)(void);
+ // Set by m_obj_list_find(). If the requested name is an old alias, this
+ // is set to the old name (while the name field uses the new name).
+ const char *replaced_name;
};
// Extra definition needed for \ref m_option_type_obj_settings_list options.
@@ -224,6 +229,7 @@ struct m_option_type {
// Parse the data from a string.
/** It is the only required function, all others can be NULL.
*
+ * \param log for outputting parser error or help messages
* \param opt The option that is parsed.
* \param name The full option name.
* \param param The parameter to parse.
@@ -233,8 +239,8 @@ struct m_option_type {
* \return On error a negative value is returned, on success the number
* of arguments consumed. For details see \ref OptionParserReturn.
*/
- int (*parse)(const m_option_t *opt, struct bstr name, struct bstr param,
- void *dst);
+ int (*parse)(struct mp_log *log, const m_option_t *opt,
+ struct bstr name, struct bstr param, void *dst);
// Print back a value in string form.
/** \param opt The option to print.
@@ -439,10 +445,10 @@ char *m_option_strerror(int code);
const m_option_t *m_option_list_find(const m_option_t *list, const char *name);
// Helper to parse options, see \ref m_option_type::parse.
-static inline int m_option_parse(const m_option_t *opt, struct bstr name,
- struct bstr param, void *dst)
+static inline int m_option_parse(struct mp_log *log, const m_option_t *opt,
+ struct bstr name, struct bstr param, void *dst)
{
- return opt->type->parse(opt, name, param, dst);
+ return opt->type->parse(log, opt, name, param, dst);
}
// Helper to print options, see \ref m_option_type::print.
diff --git a/options/m_property.c b/options/m_property.c
index 49776f6af0..9c8649c5ab 100644
--- a/options/m_property.c
+++ b/options/m_property.c
@@ -158,7 +158,7 @@ int m_property_do(struct mp_log *log, const m_option_t *prop_list,
if (!log)
return M_PROPERTY_ERROR;
// (reject 0 return value: success, but empty string with flag)
- if (m_option_parse(&opt, bstr0(name), bstr0(arg), &val) <= 0)
+ if (m_option_parse(log, &opt, bstr0(name), bstr0(arg), &val) <= 0)
return M_PROPERTY_ERROR;
r = do_action(prop_list, name, M_PROPERTY_SET, &val, ctx);
m_option_free(&opt, &val);
diff --git a/options/options.c b/options/options.c
index a4c3292c01..bd64669079 100644
--- a/options/options.c
+++ b/options/options.c
@@ -64,10 +64,10 @@ extern int sws_flags;
extern const char mp_help_text[];
-static int print_version_opt(const m_option_t *opt, const char *name,
- const char *param)
+static int print_version_opt(struct mp_log *log, const m_option_t *opt,
+ const char *name, const char *param)
{
- mp_print_version(true);
+ mp_print_version(log, true);
return M_OPT_EXIT;
}