From 484328fe04be40807bfcf170383528feeb03451d Mon Sep 17 00:00:00 2001 From: wm4 Date: Sat, 10 Sep 2016 16:29:24 +0200 Subject: options: make --h list options according to a pattern passed to it Useless feature, but I want it. Won't work on Windows due to missing fnmatch(). --- options/m_config.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'options/m_config.c') diff --git a/options/m_config.c b/options/m_config.c index 5cdfc4f67e..1f9d334026 100644 --- a/options/m_config.c +++ b/options/m_config.c @@ -29,6 +29,11 @@ #include #include +#define HAVE_FNMATCH HAVE_POSIX +#if HAVE_FNMATCH +#include +#endif + #include "libmpv/client.h" #include "mpv_talloc.h" @@ -41,6 +46,8 @@ #include "misc/node.h" #include "osdep/atomic.h" +extern const char mp_help_text[]; + static const union m_option_value default_value; // Profiles allow to predefine some sets of options that can then @@ -171,9 +178,13 @@ static int show_profile(struct m_config *config, bstr param) return M_OPT_EXIT - 1; } -static int list_options(struct m_config *config) +static int list_options(struct m_config *config, bstr val, bool show_help) { - m_config_print_option_list(config); + char s[100]; + snprintf(s, sizeof(s), "%.*s", BSTR_P(val)); + if (show_help) + mp_info(config->log, "%s", mp_help_text); + m_config_print_option_list(config, s); return M_OPT_EXIT; } @@ -762,8 +773,10 @@ static int m_config_parse_option(struct m_config *config, struct bstr name, return parse_profile(config, co->opt, name, param, set, flags); if (config->use_profiles && bstr_equals0(name, "show-profile")) return show_profile(config, param); + if (bstr_equals0(name, "h") || bstr_equals0(name, "help")) + return list_options(config, param, true); if (bstr_equals0(name, "list-options")) - return list_options(config); + return list_options(config, (bstr){0}, false); // Option with children are a bit different to parse if (co->opt->type->flags & M_OPT_TYPE_HAS_CHILD) { @@ -914,7 +927,7 @@ static int sort_opt_compare(const void *pa, const void *pb) return strcasecmp(a->name, b->name); } -void m_config_print_option_list(const struct m_config *config) +void m_config_print_option_list(const struct m_config *config, const char *name) { char min[50], max[50]; int count = 0; @@ -933,6 +946,10 @@ void m_config_print_option_list(const struct m_config *config) continue; if (co->is_hidden) continue; +#if HAVE_FNMATCH + if (fnmatch(name, co->name, 0)) + continue; +#endif MP_INFO(config, " %s%-30s", prefix, co->name); if (opt->type == &m_option_type_choice) { MP_INFO(config, " Choices:"); -- cgit v1.2.3