diff options
Diffstat (limited to 'options')
-rw-r--r-- | options/m_config.c | 91 | ||||
-rw-r--r-- | options/m_config.h | 10 | ||||
-rw-r--r-- | options/m_option.c | 339 | ||||
-rw-r--r-- | options/m_option.h | 18 | ||||
-rw-r--r-- | options/m_property.c | 2 | ||||
-rw-r--r-- | options/options.c | 6 |
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) re |