From 2c2c1203c3ac296275da122780c50fa092917c6d Mon Sep 17 00:00:00 2001 From: wm4 Date: Fri, 11 Apr 2014 01:39:30 +0200 Subject: options: sort --list-options Until now, --list-options printed options in random order. There literally wasn't any logic in its order, they just appeared as they were declared. So just sort them. Note that we can't sort them in advance, because for certain things internal to m_config, the order actually matters. Also we're using strcasecmp(), which is bad (locale dependent), but this is output intended for human consumption, so it's not a problem. --- options/m_config.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'options/m_config.c') diff --git a/options/m_config.c b/options/m_config.c index efae6cc885..77078e58f2 100644 --- a/options/m_config.c +++ b/options/m_config.c @@ -657,15 +657,26 @@ int m_config_option_requires_param(struct m_config *config, bstr name) return M_OPT_UNKNOWN; } +static int sort_opt_compare(const void *pa, const void *pb) +{ + const struct m_config_option *a = pa; + const struct m_config_option *b = pb; + return strcasecmp(a->name, b->name); +} + void m_config_print_option_list(const struct m_config *config) { char min[50], max[50]; int count = 0; const char *prefix = config->is_toplevel ? "--" : ""; + struct m_config_option *sorted = + talloc_memdup(NULL, config->opts, config->num_opts * sizeof(sorted[0])); + qsort(sorted, config->num_opts, sizeof(sorted[0]), sort_opt_compare); + MP_INFO(config, "Options:\n\n"); for (int i = 0; i < config->num_opts; i++) { - struct m_config_option *co = &config->opts[i]; + struct m_config_option *co = &sorted[i]; const struct m_option *opt = co->opt; if (opt->type->flags & M_OPT_TYPE_HAS_CHILD) continue; @@ -706,6 +717,7 @@ void m_config_print_option_list(const struct m_config *config) count++; } MP_INFO(config, "\nTotal: %d options\n", count); + talloc_free(sorted); } char **m_config_list_options(void *ta_parent, const struct m_config *config) -- cgit v1.2.3