summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-07-27 21:27:08 +0200
committerwm4 <wm4@nowhere>2013-07-28 18:56:09 +0200
commit85bee4f071d3506d4fe39dff45bd319d263663f0 (patch)
tree18c9a7a28d78134a1814a6d4c77763e51127ec01
parentc070fa865fcf75cace05bf492a68f6a2c6137fb3 (diff)
downloadmpv-85bee4f071d3506d4fe39dff45bd319d263663f0.tar.bz2
mpv-85bee4f071d3506d4fe39dff45bd319d263663f0.tar.xz
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.
-rw-r--r--core/m_config.c24
1 files changed, 24 insertions, 0 deletions
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)