summaryrefslogtreecommitdiffstats
path: root/mpvcore
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-11-23 21:29:05 +0100
committerwm4 <wm4@nowhere>2013-11-23 21:29:05 +0100
commit82605903469798f701706d8522ef8f461514ed08 (patch)
tree8cd8ec06a5b4003ed752c85941917ed19df6cceb /mpvcore
parentacfeb869a38d7f7a4e5bb273082e9cc63a02b15a (diff)
downloadmpv-82605903469798f701706d8522ef8f461514ed08.tar.bz2
mpv-82605903469798f701706d8522ef8f461514ed08.tar.xz
options: provide a way for --vf to print custom help
Useful in rather special situations. See following commits.
Diffstat (limited to 'mpvcore')
-rw-r--r--mpvcore/m_option.c23
-rw-r--r--mpvcore/m_option.h8
2 files changed, 18 insertions, 13 deletions
diff --git a/mpvcore/m_option.c b/mpvcore/m_option.c
index 1a237c7f5e..54ab15ba58 100644
--- a/mpvcore/m_option.c
+++ b/mpvcore/m_option.c
@@ -2068,9 +2068,10 @@ static int get_obj_param(bstr opt_name, bstr obj_name, struct m_config *config,
// If config is NULL, all parameters are accepted without checking.
// _ret set to NULL can be used for checking-only.
// flags can contain any M_SETOPT_* flag.
-int m_obj_parse_sub_config(struct bstr opt_name, struct bstr name,
- struct bstr *pstr, struct m_config *config,
- int flags, char ***ret)
+static int m_obj_parse_sub_config(struct bstr opt_name, struct bstr name,
+ struct bstr *pstr, struct m_config *config,
+ int flags, void (*print_help_fn)(void),
+ char ***ret)
{
int nold = 0;
char **args = NULL;
@@ -2120,6 +2121,8 @@ int m_obj_parse_sub_config(struct bstr opt_name, struct bstr name,
print_help: ;
if (config) {
+ if (print_help_fn)
+ print_help_fn();
m_config_print_option_list(config);
} else {
mp_msg(MSGT_CFGPARSER, MSGL_WARN, "Option %.*s doesn't exist.\n",
@@ -2179,7 +2182,7 @@ static int parse_obj_settings(struct bstr opt, struct bstr *pstr,
struct m_config *config = m_config_from_obj_desc_noalloc(NULL, &desc);
bstr s = bstr0(desc.init_options);
m_obj_parse_sub_config(opt, str, &s, config,
- M_SETOPT_CHECK_ONLY, &plist);
+ M_SETOPT_CHECK_ONLY, NULL, &plist);
assert(s.len == 0);
talloc_free(config);
}
@@ -2192,9 +2195,13 @@ static int parse_obj_settings(struct bstr opt, struct bstr *pstr,
bstr param = bstr_splice(*pstr, 0, next);
*pstr = bstr_cut(*pstr, next);
if (!bstrcmp0(param, "help")) {
- mp_msg(MSGT_CFGPARSER, MSGL_WARN,
- "Option %.*s: %.*s has no option description.\n",
- BSTR_P(opt), BSTR_P(str));
+ if (desc.print_help) {
+ desc.print_help();
+ } else {
+ mp_msg(MSGT_CFGPARSER, MSGL_WARN,
+ "Option %.*s: %.*s has no option description.\n",
+ BSTR_P(opt), BSTR_P(str));
+ }
return M_OPT_EXIT - 1;
}
if (_ret) {
@@ -2207,7 +2214,7 @@ static int parse_obj_settings(struct bstr opt, struct bstr *pstr,
if (!skip)
config = m_config_from_obj_desc_noalloc(NULL, &desc);
r = m_obj_parse_sub_config(opt, str, pstr, config,
- M_SETOPT_CHECK_ONLY,
+ M_SETOPT_CHECK_ONLY, desc.print_help,
_ret ? &plist : NULL);
talloc_free(config);
if (r < 0)
diff --git a/mpvcore/m_option.h b/mpvcore/m_option.h
index 443412a035..5e3184a964 100644
--- a/mpvcore/m_option.h
+++ b/mpvcore/m_option.h
@@ -110,8 +110,10 @@ struct m_obj_desc {
// This member is usually set by m_obj_list_find() only, and read by the
// option parser. It's not used anywhere else.
const char *init_options;
- // Don't list entries with "help"
+ // Don't list entry with "help"
bool hidden;
+ // Callback to print custom help if "help" is passed
+ void (*print_help)(void);
};
// Extra definition needed for \ref m_option_type_obj_settings_list options.
@@ -150,10 +152,6 @@ typedef struct m_obj_settings {
*/
extern const m_option_type_t m_option_type_obj_settings_list;
-int m_obj_parse_sub_config(struct bstr opt_name, struct bstr name,
- struct bstr *pstr, struct m_config *config,
- int flags, char ***ret);
-
struct m_opt_choice_alternatives {
char *name;
int value;