1
0
mirror of https://github.com/mpv-player/mpv synced 2025-04-11 04:01:31 +00:00

options: simplify handling of some help options

This commit is contained in:
wm4 2013-12-26 19:22:40 +01:00
parent 4ea8612b40
commit dacb6ad98f
6 changed files with 28 additions and 74 deletions

View File

@ -184,20 +184,6 @@ int async_quit_request;
static int parse_config(struct input_ctx *ictx, bool builtin, bstr data, static int parse_config(struct input_ctx *ictx, bool builtin, bstr data,
const char *location, const char *restrict_section); 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 #define OPT_BASE_STRUCT struct MPOpts
// Our command line options // Our command line options
@ -205,8 +191,8 @@ static const m_option_t input_config[] = {
OPT_STRING("conf", input.config_file, CONF_GLOBAL), OPT_STRING("conf", input.config_file, CONF_GLOBAL),
OPT_INT("ar-delay", input.ar_delay, CONF_GLOBAL), OPT_INT("ar-delay", input.ar_delay, CONF_GLOBAL),
OPT_INT("ar-rate", input.ar_rate, CONF_GLOBAL), OPT_INT("ar-rate", input.ar_rate, CONF_GLOBAL),
{ "keylist", print_key_list, CONF_TYPE_PRINT_FUNC, CONF_GLOBAL | CONF_NOCFG }, OPT_PRINT("keylist", mp_print_key_list),
{ "cmdlist", print_cmd_list, CONF_TYPE_PRINT_FUNC, CONF_GLOBAL | CONF_NOCFG }, OPT_PRINT("cmdlist", mp_print_cmd_list),
OPT_STRING("js-dev", input.js_dev, CONF_GLOBAL), OPT_STRING("js-dev", input.js_dev, CONF_GLOBAL),
OPT_STRING("file", input.in_file, CONF_GLOBAL), OPT_STRING("file", input.in_file, CONF_GLOBAL),
OPT_FLAG("default-bindings", input.default_bindings, CONF_GLOBAL), OPT_FLAG("default-bindings", input.default_bindings, CONF_GLOBAL),

View File

@ -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, static int parse_print(struct mp_log *log, const m_option_t *opt,
struct bstr name, struct bstr param, void *dst) struct bstr name, struct bstr param, void *dst)
{ {
if (opt->type == CONF_TYPE_PRINT) { ((m_opt_print_fn) opt->priv)(log);
const char *msg = opt->p; return M_OPT_EXIT;
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;
} }
const m_option_type_t m_option_type_print = { const m_option_type_t m_option_type_print_fn = {
.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 = {
.name = "Print", .name = "Print",
.flags = M_OPT_TYPE_ALLOW_WILDCARD | M_OPT_TYPE_OPTIONAL_PARAM, .flags = M_OPT_TYPE_ALLOW_WILDCARD | M_OPT_TYPE_OPTIONAL_PARAM,
.parse = parse_print, .parse = parse_print,

View File

@ -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_rel_time;
extern const m_option_type_t m_option_type_choice; 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_msglevels;
extern const m_option_type_t m_option_type_print; extern const m_option_type_t m_option_type_print_fn;
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_subconfig; 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_subconfig_struct;
extern const m_option_type_t m_option_type_imgfmt; 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_size_box;
extern const m_option_type_t m_option_type_chmap; extern const m_option_type_t m_option_type_chmap;
// Callback used by m_option_type_print_func options. // Callback used by m_option_type_print_fn options.
typedef int (*m_opt_func_full_t)(struct mp_log *log, const m_option_t *, typedef void (*m_opt_print_fn)(struct mp_log *log);
const char *, const char *);
enum m_rel_time_type { enum m_rel_time_type {
REL_TIME_NONE, REL_TIME_NONE,
@ -178,8 +175,6 @@ struct m_sub_options {
#define CONF_TYPE_FLOAT (&m_option_type_float) #define CONF_TYPE_FLOAT (&m_option_type_float)
#define CONF_TYPE_DOUBLE (&m_option_type_double) #define CONF_TYPE_DOUBLE (&m_option_type_double)
#define CONF_TYPE_STRING (&m_option_type_string) #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_SUBCONFIG (&m_option_type_subconfig)
#define CONF_TYPE_STRING_LIST (&m_option_type_string_list) #define CONF_TYPE_STRING_LIST (&m_option_type_string_list)
#define CONF_TYPE_IMGFMT (&m_option_type_imgfmt) #define CONF_TYPE_IMGFMT (&m_option_type_imgfmt)
@ -291,11 +286,7 @@ struct m_option {
// Option name. // Option name.
const char *name; const char *name;
// Reserved for higher level APIs, it shouldn't be used by parsers. // Deprecated field for "old" options which mutate global state.
/** 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.
*/
void *p; void *p;
// Option type. // Option type.
@ -313,9 +304,6 @@ struct m_option {
double max; double max;
// Type dependent data (for all kinds of extended settings). // 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; void *priv;
int is_new_option; int is_new_option;
@ -635,6 +623,12 @@ extern const char m_option_path_separator;
#define OPT_STRING_VALIDATE(...) \ #define OPT_STRING_VALIDATE(...) \
OPT_STRING_VALIDATE_(__VA_ARGS__, .type = &m_option_type_string) 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. // subconf must have the type struct m_sub_options.
// All sub-options are prefixed with "name-" and are added to the current // All sub-options are prefixed with "name-" and are added to the current
// (containing) option list. // (containing) option list.

View File

@ -40,6 +40,7 @@
#include "audio/filter/af.h" #include "audio/filter/af.h"
#include "audio/decode/dec_audio.h" #include "audio/decode/dec_audio.h"
#include "player/core.h" #include "player/core.h"
#include "player/command.h"
#include "osdep/priority.h" #include "osdep/priority.h"
/* defined in demux: */ /* defined in demux: */
@ -51,11 +52,14 @@ extern int sws_flags;
extern const char mp_help_text[]; extern const char mp_help_text[];
static int print_version_opt(struct mp_log *log, const m_option_t *opt, static void print_version(struct mp_log *log)
const char *name, const char *param)
{ {
mp_print_version(log, true); 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 #if HAVE_RADIO
@ -214,7 +218,7 @@ const m_option_t mp_opts[] = {
{ "show-profile", NULL, CONF_TYPE_STRING, CONF_NOCFG }, { "show-profile", NULL, CONF_TYPE_STRING, CONF_NOCFG },
{ "list-options", NULL, CONF_TYPE_STORE, 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 }, {"leak-report", NULL, CONF_TYPE_STORE, CONF_GLOBAL | CONF_NOCFG },
OPT_FLAG("shuffle", shuffle, 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}, {"", (void *) mp_input_opts, CONF_TYPE_SUBCONFIG},
OPT_FLAG("list-properties", list_properties, CONF_GLOBAL), OPT_PRINT("list-properties", property_print_help),
{"help", (void *) mp_help_text, CONF_TYPE_PRINT, CONF_NOCFG|CONF_GLOBAL, 0, 0, NULL}, OPT_PRINT("help", print_help),
{"h", (void *) mp_help_text, CONF_TYPE_PRINT, CONF_NOCFG|CONF_GLOBAL, 0, 0, NULL}, OPT_PRINT("h", print_help),
{"version", (void *)print_version_opt, CONF_TYPE_PRINT_FUNC, CONF_NOCFG|CONF_GLOBAL|M_OPT_PRE_PARSE}, OPT_PRINT("version", print_version),
{"V", (void *)print_version_opt, CONF_TYPE_PRINT_FUNC, CONF_NOCFG|CONF_GLOBAL|M_OPT_PRE_PARSE}, OPT_PRINT("V", print_version),
#if HAVE_ENCODING #if HAVE_ENCODING
OPT_STRING("o", encode_output.file, CONF_GLOBAL), OPT_STRING("o", encode_output.file, CONF_GLOBAL),

View File

@ -133,7 +133,6 @@ typedef struct MPOpts {
int player_idle_mode; int player_idle_mode;
int slave_mode; int slave_mode;
int consolecontrols; int consolecontrols;
int list_properties;
struct m_rel_time play_start; struct m_rel_time play_start;
struct m_rel_time play_end; struct m_rel_time play_end;
struct m_rel_time play_length; struct m_rel_time play_length;

View File

@ -224,10 +224,6 @@ static bool handle_help_options(struct MPContext *mpctx)
MP_INFO(mpctx, "\n"); MP_INFO(mpctx, "\n");
opt_exit = 1; opt_exit = 1;
} }
if (opts->list_properties) {
property_print_help(log);
opt_exit = 1;
}
#if HAVE_ENCODING #if HAVE_ENCODING
if (encode_lavc_showhelp(log, &opts->encode_output)) if (encode_lavc_showhelp(log, &opts->encode_output))
opt_exit = 1; opt_exit = 1;