1
0
mirror of https://github.com/mpv-player/mpv synced 2025-03-31 15:59:34 +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,
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),

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,
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,

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_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.

View File

@ -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),

View File

@ -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;

View File

@ -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;