From 85bee4f071d3506d4fe39dff45bd319d263663f0 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sat, 27 Jul 2013 21:27:08 +0200 Subject: [PATCH] options: print default values in --list-options Do this by recreating the m_config from scratch, which then must contain the default values. This doesn't quite work with legacy options using global variables: the default values get lost, so using --list-options will print the value as set by the config file. This also introduces a memory leak for string options backed by global variables. All of these issues will be eventually fixed by moving all options to structs. --- core/m_config.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/core/m_config.c b/core/m_config.c index 148a6888a2..be2a8dc8d4 100644 --- a/core/m_config.c +++ b/core/m_config.c @@ -613,6 +613,21 @@ int m_config_option_requires_param(struct m_config *config, bstr name) return M_OPT_UNKNOWN; } +static struct m_config *get_defaults(const struct m_config *config) +{ + return m_config_new(NULL, config->optstruct_size, + config->optstruct_defaults, config->options); +} + +static char *get_option_value_string(const struct m_config *config, + const char *name) +{ + struct m_config_option *co = m_config_get_co(config, bstr0(name)); + if (!co || !co->data) + return NULL; + return m_option_print(co->opt, co->data); +} + void m_config_print_option_list(const struct m_config *config) { char min[50], max[50]; @@ -622,6 +637,8 @@ void m_config_print_option_list(const struct m_config *config) if (!config->opts) return; + struct m_config *defaults = get_defaults(config); + mp_tmsg(MSGT_CFGPARSER, MSGL_INFO, "Options:\n\n"); for (co = config->opts; co; co = co->next) { const struct m_option *opt = co->opt; @@ -647,6 +664,11 @@ void m_config_print_option_list(const struct m_config *config) snprintf(max, sizeof(max), "%g", opt->max); mp_msg(MSGT_CFGPARSER, MSGL_INFO, " (%s to %s)", min, max); } + char *def = get_option_value_string(defaults, co->name); + if (def) { + mp_msg(MSGT_CFGPARSER, MSGL_INFO, " (default: %s)", def); + talloc_free(def); + } if (opt->flags & CONF_GLOBAL) mp_msg(MSGT_CFGPARSER, MSGL_INFO, " [global]"); if (opt->flags & CONF_NOCFG) @@ -655,6 +677,8 @@ void m_config_print_option_list(const struct m_config *config) count++; } mp_tmsg(MSGT_CFGPARSER, MSGL_INFO, "\nTotal: %d options\n", count); + + talloc_free(defaults); } struct m_profile *m_config_get_profile(const struct m_config *config, bstr name)