options: simplify and rename m_option_type_store

This was an annoying option type. And still is. But at least it's on the
same level as m_option_type_print_fn now, and can probably cleaned up
further like it. Both types are for options that are only on the command
line, always have special handling (i.e. do something with them in
parse_commandline.c before passing them to the generic
m_config.c/m_option.c layers), and are m_options only for --list-options
and (oddly) the split_opt_silent() function.
This commit is contained in:
wm4 2017-06-23 20:51:12 +02:00
parent 633152e55a
commit 0729bee415
3 changed files with 27 additions and 50 deletions

View File

@ -202,42 +202,6 @@ const m_option_type_t m_option_type_flag = {
.get = flag_get,
};
// Single-value, write-only flag
static int parse_store(struct mp_log *log, const m_option_t *opt,
struct bstr name, struct bstr param, void *dst)
{
if (param.len == 0) {
if (dst)
VAL(dst) = opt->max;
return 0;
} else {
mp_err(log, "Invalid parameter for %.*s flag: %.*s\n",
BSTR_P(name), BSTR_P(param));
return M_OPT_DISALLOW_PARAM;
}
}
static int store_set(const m_option_t *opt, void *dst, struct mpv_node *src)
{
if (src->format != MPV_FORMAT_FLAG)
return M_OPT_UNKNOWN;
if (!src->u.flag)
return M_OPT_INVALID;
VAL(dst) = opt->max;
return 1;
}
const m_option_type_t m_option_type_store = {
// can only be activated
.name = "Flag",
.size = sizeof(int),
.flags = M_OPT_TYPE_OPTIONAL_PARAM,
.parse = parse_store,
.copy = copy_opt,
.set = store_set,
};
// Integer
#undef VAL
@ -1654,8 +1618,6 @@ const m_option_type_t m_option_type_msglevels = {
.set = set_msglevels,
};
/////////////////// Print
static int parse_print(struct mp_log *log, const m_option_t *opt,
struct bstr name, struct bstr param, void *dst)
{
@ -1669,6 +1631,24 @@ const m_option_type_t m_option_type_print_fn = {
.parse = parse_print,
};
static int parse_dummy_flag(struct mp_log *log, const m_option_t *opt,
struct bstr name, struct bstr param, void *dst)
{
if (param.len) {
mp_err(log, "Invalid parameter for %.*s flag: %.*s\n",
BSTR_P(name), BSTR_P(param));
return M_OPT_DISALLOW_PARAM;
}
return 0;
}
const m_option_type_t m_option_type_dummy_flag = {
// can only be activated
.name = "Flag",
.flags = M_OPT_TYPE_OPTIONAL_PARAM,
.parse = parse_dummy_flag,
};
#undef VAL
// Read s sub-option name, or a positional sub-opt value.

View File

@ -37,7 +37,7 @@ struct mpv_node;
// Simple types
extern const m_option_type_t m_option_type_flag;
extern const m_option_type_t m_option_type_store;
extern const m_option_type_t m_option_type_dummy_flag;
extern const m_option_type_t m_option_type_int;
extern const m_option_type_t m_option_type_int64;
extern const m_option_type_t m_option_type_intpair;
@ -201,7 +201,6 @@ struct m_sub_options {
};
#define CONF_TYPE_FLAG (&m_option_type_flag)
#define CONF_TYPE_STORE (&m_option_type_store)
#define CONF_TYPE_INT (&m_option_type_int)
#define CONF_TYPE_INT64 (&m_option_type_int64)
#define CONF_TYPE_FLOAT (&m_option_type_float)
@ -222,7 +221,6 @@ struct m_sub_options {
// size/alignment requirements for option values in general.
union m_option_value {
int flag; // not the C type "bool"!
int store;
int int_;
int64_t int64;
int intpair[2];
@ -579,10 +577,6 @@ extern const char m_option_path_separator;
#define OPT_FLAG(...) \
OPT_GENERAL(int, __VA_ARGS__, .type = &m_option_type_flag)
#define OPT_FLAG_STORE(optname, varname, flags, value) \
OPT_GENERAL(int, optname, varname, flags, .max = value, \
.type = &m_option_type_store)
#define OPT_STRINGLIST(...) \
OPT_GENERAL(char**, __VA_ARGS__, .type = &m_option_type_string_list)

View File

@ -229,19 +229,22 @@ const struct m_sub_options dvd_conf = {
const m_option_t mp_opts[] = {
// handled in command line pre-parser (parse_commandline.c)
{"v", CONF_TYPE_STORE, M_OPT_FIXED | CONF_NOCFG | M_OPT_NOPROP, .offset = -1},
{"v", &m_option_type_dummy_flag, M_OPT_FIXED | CONF_NOCFG | M_OPT_NOPROP,
.offset = -1},
{"playlist", CONF_TYPE_STRING, CONF_NOCFG | M_OPT_MIN | M_OPT_FIXED | M_OPT_FILE,
.min = 1, .offset = -1},
{"{", CONF_TYPE_STORE, CONF_NOCFG | M_OPT_FIXED | M_OPT_NOPROP, .offset = -1},
{"}", CONF_TYPE_STORE, CONF_NOCFG | M_OPT_FIXED | M_OPT_NOPROP, .offset = -1},
{"{", &m_option_type_dummy_flag, CONF_NOCFG | M_OPT_FIXED | M_OPT_NOPROP,
.offset = -1},
{"}", &m_option_type_dummy_flag, CONF_NOCFG | M_OPT_FIXED | M_OPT_NOPROP,
.offset = -1},
// handled in m_config.c
{ "include", CONF_TYPE_STRING, M_OPT_FILE, .offset = -1},
{ "profile", CONF_TYPE_STRING_LIST, 0, .offset = -1},
{ "show-profile", CONF_TYPE_STRING, CONF_NOCFG | M_OPT_FIXED | M_OPT_NOPROP,
.offset = -1},
{ "list-options", CONF_TYPE_STORE, CONF_NOCFG | M_OPT_FIXED | M_OPT_NOPROP,
.offset = -1},
{ "list-options", &m_option_type_dummy_flag, CONF_NOCFG | M_OPT_FIXED |
M_OPT_NOPROP, .offset = -1},
OPT_FLAG("list-properties", property_print_help,
CONF_NOCFG | M_OPT_FIXED | M_OPT_NOPROP),
{ "help", CONF_TYPE_STRING, CONF_NOCFG | M_OPT_FIXED | M_OPT_NOPROP |