summaryrefslogtreecommitdiffstats
path: root/options
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2016-09-10 16:29:24 +0200
committerwm4 <wm4@nowhere>2016-09-10 16:29:24 +0200
commit484328fe04be40807bfcf170383528feeb03451d (patch)
tree85331885b9c99092ef1b745759aef447ef8a195d /options
parentebc04333d2fbcf01cad05c9aa43e8f95c810f92b (diff)
downloadmpv-484328fe04be40807bfcf170383528feeb03451d.tar.bz2
mpv-484328fe04be40807bfcf170383528feeb03451d.tar.xz
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().
Diffstat (limited to 'options')
-rw-r--r--options/m_config.c25
-rw-r--r--options/m_config.h5
-rw-r--r--options/m_option.c2
3 files changed, 23 insertions, 9 deletions
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 <stdbool.h>
#include <pthread.h>
+#define HAVE_FNMATCH HAVE_POSIX
+#if HAVE_FNMATCH
+#include <fnmatch.h>
+#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:");
diff --git a/options/m_config.h b/options/m_config.h
index 902f0bd981..e7c095623b 100644
--- a/options/m_config.h
+++ b/options/m_config.h
@@ -212,10 +212,7 @@ bool m_config_is_in_group(struct m_config *config,
// Return all (visible) option names as NULL terminated string list.
char **m_config_list_options(void *ta_parent, const struct m_config *config);
-/* Print a list of all registered options.
- * \param config The config object.
- */
-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);
/* Find the profile with the given name.
diff --git a/options/m_option.c b/options/m_option.c
index 3cd9a1fb8c..cdc6b41e34 100644
--- a/options/m_option.c
+++ b/options/m_option.c
@@ -2771,7 +2771,7 @@ print_help: ;
if (config) {
if (desc->print_help)
desc->print_help(log);
- m_config_print_option_list(config);
+ m_config_print_option_list(config, "");
} else {
mp_warn(log, "Option %.*s: item %.*s doesn't exist.\n",
BSTR_P(opt_name), BSTR_P(name));