summaryrefslogtreecommitdiffstats
path: root/options/m_config.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-04-11 01:39:30 +0200
committerwm4 <wm4@nowhere>2014-04-11 01:39:30 +0200
commit2c2c1203c3ac296275da122780c50fa092917c6d (patch)
treeac9168294f0b26512abf5ad707c5b92510b3b761 /options/m_config.c
parent333c8cbc29c1d0c3e397af46f0cfc4c1beef2e7f (diff)
downloadmpv-2c2c1203c3ac296275da122780c50fa092917c6d.tar.bz2
mpv-2c2c1203c3ac296275da122780c50fa092917c6d.tar.xz
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.
Diffstat (limited to 'options/m_config.c')
-rw-r--r--options/m_config.c14
1 files changed, 13 insertions, 1 deletions
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)