1
0
mirror of https://github.com/mpv-player/mpv synced 2024-12-23 15:22:09 +00:00

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").
This commit is contained in:
wm4 2016-09-02 19:24:12 +02:00
parent 9770ce6c44
commit eb14b18a33
3 changed files with 19 additions and 10 deletions

View File

@ -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;

View File

@ -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.

View File

@ -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;
}