From dacb6ad98fb70da8e115549f3b045f00aff4034d Mon Sep 17 00:00:00 2001 From: wm4 Date: Thu, 26 Dec 2013 19:22:40 +0100 Subject: options: simplify handling of some help options --- input/input.c | 18 ++---------------- options/m_option.c | 31 +++---------------------------- options/m_option.h | 26 ++++++++++---------------- options/options.c | 22 +++++++++++++--------- options/options.h | 1 - player/main.c | 4 ---- 6 files changed, 28 insertions(+), 74 deletions(-) diff --git a/input/input.c b/input/input.c index d08ea5b6f3..94ee64cd4f 100644 --- a/input/input.c +++ b/input/input.c @@ -184,20 +184,6 @@ int async_quit_request; static int parse_config(struct input_ctx *ictx, bool builtin, bstr data, const char *location, const char *restrict_section); -static int print_key_list(struct mp_log *log, m_option_t *cfg, - char *optname, char *optparam) -{ - mp_print_key_list(log); - return M_OPT_EXIT; -} - -static int print_cmd_list(struct mp_log *log, m_option_t *cfg, - char *optname, char *optparam) -{ - mp_print_cmd_list(log); - return M_OPT_EXIT; -} - #define OPT_BASE_STRUCT struct MPOpts // Our command line options @@ -205,8 +191,8 @@ static const m_option_t input_config[] = { OPT_STRING("conf", input.config_file, CONF_GLOBAL), OPT_INT("ar-delay", input.ar_delay, CONF_GLOBAL), OPT_INT("ar-rate", input.ar_rate, CONF_GLOBAL), - { "keylist", print_key_list, CONF_TYPE_PRINT_FUNC, CONF_GLOBAL | CONF_NOCFG }, - { "cmdlist", print_cmd_list, CONF_TYPE_PRINT_FUNC, CONF_GLOBAL | CONF_NOCFG }, + OPT_PRINT("keylist", mp_print_key_list), + OPT_PRINT("cmdlist", mp_print_cmd_list), OPT_STRING("js-dev", input.js_dev, CONF_GLOBAL), OPT_STRING("file", input.in_file, CONF_GLOBAL), OPT_FLAG("default-bindings", input.default_bindings, CONF_GLOBAL), diff --git a/options/m_option.c b/options/m_option.c index 5de59500f9..9f98008c64 100644 --- a/options/m_option.c +++ b/options/m_option.c @@ -1153,36 +1153,11 @@ const m_option_type_t m_option_type_string_list = { static int parse_print(struct mp_log *log, const m_option_t *opt, struct bstr name, struct bstr param, void *dst) { - if (opt->type == CONF_TYPE_PRINT) { - const char *msg = opt->p; - mp_info(log, "%s", msg); - } else { - char *name0 = bstrdup0(NULL, name); - char *param0 = bstrdup0(NULL, param); - int r = ((m_opt_func_full_t) opt->p)(log, opt, name0, param0); - talloc_free(name0); - talloc_free(param0); - return r; - } - - if (opt->priv == NULL) - return M_OPT_EXIT; - return 0; + ((m_opt_print_fn) opt->priv)(log); + return M_OPT_EXIT; } -const m_option_type_t m_option_type_print = { - .name = "Print", - .flags = M_OPT_TYPE_OPTIONAL_PARAM, - .parse = parse_print, -}; - -const m_option_type_t m_option_type_print_func_param = { - .name = "Print", - .flags = M_OPT_TYPE_ALLOW_WILDCARD, - .parse = parse_print, -}; - -const m_option_type_t m_option_type_print_func = { +const m_option_type_t m_option_type_print_fn = { .name = "Print", .flags = M_OPT_TYPE_ALLOW_WILDCARD | M_OPT_TYPE_OPTIONAL_PARAM, .parse = parse_print, diff --git a/options/m_option.h b/options/m_option.h index abc45b07aa..7f9b89bea1 100644 --- a/options/m_option.h +++ b/options/m_option.h @@ -50,9 +50,7 @@ extern const m_option_type_t m_option_type_time; extern const m_option_type_t m_option_type_rel_time; extern const m_option_type_t m_option_type_choice; extern const m_option_type_t m_option_type_msglevels; -extern const m_option_type_t m_option_type_print; -extern const m_option_type_t m_option_type_print_func; -extern const m_option_type_t m_option_type_print_func_param; +extern const m_option_type_t m_option_type_print_fn; extern const m_option_type_t m_option_type_subconfig; extern const m_option_type_t m_option_type_subconfig_struct; extern const m_option_type_t m_option_type_imgfmt; @@ -63,9 +61,8 @@ extern const m_option_type_t m_option_type_geometry; extern const m_option_type_t m_option_type_size_box; extern const m_option_type_t m_option_type_chmap; -// Callback used by m_option_type_print_func options. -typedef int (*m_opt_func_full_t)(struct mp_log *log, const m_option_t *, - const char *, const char *); +// Callback used by m_option_type_print_fn options. +typedef void (*m_opt_print_fn)(struct mp_log *log); enum m_rel_time_type { REL_TIME_NONE, @@ -178,8 +175,6 @@ struct m_sub_options { #define CONF_TYPE_FLOAT (&m_option_type_float) #define CONF_TYPE_DOUBLE (&m_option_type_double) #define CONF_TYPE_STRING (&m_option_type_string) -#define CONF_TYPE_PRINT (&m_option_type_print) -#define CONF_TYPE_PRINT_FUNC (&m_option_type_print_func) #define CONF_TYPE_SUBCONFIG (&m_option_type_subconfig) #define CONF_TYPE_STRING_LIST (&m_option_type_string_list) #define CONF_TYPE_IMGFMT (&m_option_type_imgfmt) @@ -291,11 +286,7 @@ struct m_option { // Option name. const char *name; - // Reserved for higher level APIs, it shouldn't be used by parsers. - /** The suboption parser and func types do use it. They should instead - * use the priv field but this was inherited from older versions of the - * config code. - */ + // Deprecated field for "old" options which mutate global state. void *p; // Option type. @@ -313,9 +304,6 @@ struct m_option { double max; // Type dependent data (for all kinds of extended settings). - /** This used to be a function pointer to hold a 'reverse to defaults' func. - * Now it can be used to pass any type of extra args needed by the parser. - */ void *priv; int is_new_option; @@ -635,6 +623,12 @@ extern const char m_option_path_separator; #define OPT_STRING_VALIDATE(...) \ OPT_STRING_VALIDATE_(__VA_ARGS__, .type = &m_option_type_string) +#define OPT_PRINT(optname, fn) \ + {.name = optname, \ + .flags = M_OPT_GLOBAL | M_OPT_NOCFG | M_OPT_PRE_PARSE, \ + .type = &m_option_type_print_fn, \ + .priv = MP_EXPECT_TYPE(m_opt_print_fn, fn) } + // subconf must have the type struct m_sub_options. // All sub-options are prefixed with "name-" and are added to the current // (containing) option list. diff --git a/options/options.c b/options/options.c index 7f98149369..f53f33245e 100644 --- a/options/options.c +++ b/options/options.c @@ -40,6 +40,7 @@ #include "audio/filter/af.h" #include "audio/decode/dec_audio.h" #include "player/core.h" +#include "player/command.h" #include "osdep/priority.h" /* defined in demux: */ @@ -51,11 +52,14 @@ extern int sws_flags; extern const char mp_help_text[]; -static int print_version_opt(struct mp_log *log, const m_option_t *opt, - const char *name, const char *param) +static void print_version(struct mp_log *log) { mp_print_version(log, true); - return M_OPT_EXIT; +} + +static void print_help(struct mp_log *log) +{ + mp_info(log, "%s", mp_help_text); } #if HAVE_RADIO @@ -214,7 +218,7 @@ const m_option_t mp_opts[] = { { "show-profile", NULL, CONF_TYPE_STRING, CONF_NOCFG }, { "list-options", NULL, CONF_TYPE_STORE, CONF_NOCFG }, - // handled in mplayer.c (looks at the raw argv[]) + // handled in main.c (looks at the raw argv[]) {"leak-report", NULL, CONF_TYPE_STORE, CONF_GLOBAL | CONF_NOCFG }, OPT_FLAG("shuffle", shuffle, CONF_GLOBAL | CONF_NOCFG), @@ -614,11 +618,11 @@ const m_option_t mp_opts[] = { {"", (void *) mp_input_opts, CONF_TYPE_SUBCONFIG}, - OPT_FLAG("list-properties", list_properties, CONF_GLOBAL), - {"help", (void *) mp_help_text, CONF_TYPE_PRINT, CONF_NOCFG|CONF_GLOBAL, 0, 0, NULL}, - {"h", (void *) mp_help_text, CONF_TYPE_PRINT, CONF_NOCFG|CONF_GLOBAL, 0, 0, NULL}, - {"version", (void *)print_version_opt, CONF_TYPE_PRINT_FUNC, CONF_NOCFG|CONF_GLOBAL|M_OPT_PRE_PARSE}, - {"V", (void *)print_version_opt, CONF_TYPE_PRINT_FUNC, CONF_NOCFG|CONF_GLOBAL|M_OPT_PRE_PARSE}, + OPT_PRINT("list-properties", property_print_help), + OPT_PRINT("help", print_help), + OPT_PRINT("h", print_help), + OPT_PRINT("version", print_version), + OPT_PRINT("V", print_version), #if HAVE_ENCODING OPT_STRING("o", encode_output.file, CONF_GLOBAL), diff --git a/options/options.h b/options/options.h index 4889201b93..6e44dc838c 100644 --- a/options/options.h +++ b/options/options.h @@ -133,7 +133,6 @@ typedef struct MPOpts { int player_idle_mode; int slave_mode; int consolecontrols; - int list_properties; struct m_rel_time play_start; struct m_rel_time play_end; struct m_rel_time play_length; diff --git a/player/main.c b/player/main.c index df74d4cb56..3337ca0bd3 100644 --- a/player/main.c +++ b/player/main.c @@ -224,10 +224,6 @@ static bool handle_help_options(struct MPContext *mpctx) MP_INFO(mpctx, "\n"); opt_exit = 1; } - if (opts->list_properties) { - property_print_help(log); - opt_exit = 1; - } #if HAVE_ENCODING if (encode_lavc_showhelp(log, &opts->encode_output)) opt_exit = 1; -- cgit v1.2.3