From 036a49478ff6cc19abfa06b7807bd4653eb9ce33 Mon Sep 17 00:00:00 2001 From: wm4 Date: Thu, 7 May 2015 21:03:14 +0200 Subject: m_config: make m_config_set_profile() use a name Is simpler and avoids exposing profile structs to a degree. --- options/m_config.c | 23 ++++++++++++++--------- options/m_config.h | 4 ++-- player/configfiles.c | 4 ++-- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/options/m_config.c b/options/m_config.c index 4809191efc..e513019c59 100644 --- a/options/m_config.c +++ b/options/m_config.c @@ -102,12 +102,10 @@ static int parse_profile(struct m_config *config, const struct m_option *opt, if (!list || !list[0]) return M_OPT_INVALID; for (int i = 0; list[i]; i++) { - struct m_profile *p = m_config_get_profile0(config, list[i]); - if (!p) { - MP_WARN(config, "Unknown profile '%s'.\n", list[i]); - r = M_OPT_INVALID; - } else if (set) - m_config_set_profile(config, p, flags); + if (set) + r = m_config_set_profile(config, list[i], flags); + if (r < 0) + break; } m_option_free(opt, &list); return r; @@ -897,12 +895,17 @@ int m_config_set_profile_option(struct m_config *config, struct m_profile *p, return 1; } -void m_config_set_profile(struct m_config *config, struct m_profile *p, - int flags) +int m_config_set_profile(struct m_config *config, char *name, int flags) { + struct m_profile *p = m_config_get_profile0(config, name); + if (!p) { + MP_WARN(config, "Unknown profile '%s'.\n", name); + return M_OPT_INVALID; + } + if (config->profile_depth > MAX_PROFILE_DEPTH) { MP_WARN(config, "WARNING: Profile inclusion too deep.\n"); - return; + return M_OPT_UNKNOWN; } config->profile_depth++; for (int i = 0; i < p->num_opts; i++) { @@ -912,6 +915,8 @@ void m_config_set_profile(struct m_config *config, struct m_profile *p, flags | M_SETOPT_FROM_CONFIG_FILE); } config->profile_depth--; + + return 0; } void *m_config_alloc_struct(void *talloc_ctx, diff --git a/options/m_config.h b/options/m_config.h index ba14c058f7..4b29c9cde3 100644 --- a/options/m_config.h +++ b/options/m_config.h @@ -241,9 +241,9 @@ int m_config_set_profile_option(struct m_config *config, struct m_profile *p, * \param config The config object. * \param p The profile object. * \param flags M_SETOPT_* bits + * Returns error code (<0) or 0 on success */ -void m_config_set_profile(struct m_config *config, struct m_profile *p, - int flags); +int m_config_set_profile(struct m_config *config, char *name, int flags); void *m_config_alloc_struct(void *talloc_ctx, const struct m_sub_options *subopts); diff --git a/player/configfiles.c b/player/configfiles.c index b7d3795f60..52cd837ab7 100644 --- a/player/configfiles.c +++ b/player/configfiles.c @@ -84,7 +84,7 @@ void mp_parse_cfgfiles(struct MPContext *mpctx) load_all_cfgfiles(mpctx, section, "mpv.conf|config"); if (encoding) - m_config_set_profile(conf, m_config_add_profile(conf, SECT_ENCODE), 0); + m_config_set_profile(conf, SECT_ENCODE, 0); } static int try_load_config(struct MPContext *mpctx, const char *file, int flags) @@ -143,7 +143,7 @@ static void mp_auto_load_profile(struct MPContext *mpctx, char *category, m_profile_t *p = m_config_get_profile0(mpctx->mconfig, t); if (p) { MP_INFO(mpctx, "Auto-loading profile '%s'\n", t); - m_config_set_profile(mpctx->mconfig, p, FILE_LOCAL_FLAGS); + m_config_set_profile(mpctx->mconfig, t, FILE_LOCAL_FLAGS); } } -- cgit v1.2.3