From eb14b18a33973021c30124775513795b689cec27 Mon Sep 17 00:00:00 2001 From: wm4 Date: Fri, 2 Sep 2016 19:24:12 +0200 Subject: [PATCH] config: allow profile forward-references in default profile This works by first parsing a config file into the default profile, and applying it once parsing the whole file is finished. This won't work across config files (not even if you include other config files via "include=file.conf"). --- options/m_config.c | 11 +++++++++-- options/m_config.h | 4 ++++ options/parse_configfile.c | 14 ++++++-------- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/options/m_config.c b/options/m_config.c index f3bbe7d8c9..a456430ceb 100644 --- a/options/m_config.c +++ b/options/m_config.c @@ -928,8 +928,8 @@ struct m_profile *m_config_get_profile0(const struct m_config *config, struct m_profile *m_config_add_profile(struct m_config *config, char *name) { - if (!name || !name[0] || strcmp(name, "default") == 0) - return NULL; // never a real profile + if (!name || !name[0]) + name = "default"; struct m_profile *p = m_config_get_profile0(config, name); if (p) return p; @@ -986,6 +986,13 @@ int m_config_set_profile(struct m_config *config, char *name, int flags) return 0; } +void m_config_finish_default_profile(struct m_config *config, int flags) +{ + struct m_profile *p = m_config_add_profile(config, NULL); + m_config_set_profile(config, p->name, flags); + p->num_opts = 0; +} + struct mpv_node m_config_get_profiles(struct m_config *config) { struct mpv_node root; diff --git a/options/m_config.h b/options/m_config.h index 7a4c15a08e..1e23a2b0dd 100644 --- a/options/m_config.h +++ b/options/m_config.h @@ -230,6 +230,10 @@ struct m_profile *m_config_get_profile0(const struct m_config *config, char *name); struct m_profile *m_config_get_profile(const struct m_config *config, bstr name); +// Apply and clear the default profile - it's the only profile that new config +// files do not simply append to (for configfile parser). +void m_config_finish_default_profile(struct m_config *config, int flags); + /* Get the profile with the given name, creating it if necessary. * \param config The config object. * \param arg The profile's name. diff --git a/options/parse_configfile.c b/options/parse_configfile.c index 8ccf6579ba..e7c877349d 100644 --- a/options/parse_configfile.c +++ b/options/parse_configfile.c @@ -128,15 +128,11 @@ int m_config_parse(m_config_t *config, const char *location, bstr data, } int res; - if (profile) { - if (bstr_equals0(option, "profile-desc")) { - m_profile_set_desc(profile, value); - res = 0; - } else { - res = m_config_set_profile_option(config, profile, option, value); - } + if (bstr_equals0(option, "profile-desc")) { + m_profile_set_desc(profile, value); + res = 0; } else { - res = m_config_set_option_ext(config, option, value, flags); + res = m_config_set_profile_option(config, profile, option, value); } if (res < 0) { MP_ERR(config, "%s setting option %.*s='%.*s' failed.\n", @@ -154,6 +150,8 @@ int m_config_parse(m_config_t *config, const char *location, bstr data, } } + m_config_finish_default_profile(config, flags); + talloc_free(tmp); return 1; }