diff options
Diffstat (limited to 'options')
-rw-r--r-- | options/m_config.c | 2 | ||||
-rw-r--r-- | options/m_option.c | 23 | ||||
-rw-r--r-- | options/m_option.h | 14 |
3 files changed, 15 insertions, 24 deletions
diff --git a/options/m_config.c b/options/m_config.c index f3b73784a5..ebb24ad098 100644 --- a/options/m_config.c +++ b/options/m_config.c @@ -302,7 +302,7 @@ static void add_negation_option(struct m_config *config, const struct m_option *opt = orig->opt; int value; if (opt->type == CONF_TYPE_FLAG) { - value = opt->min; + value = 0; } else if (opt->type == CONF_TYPE_CHOICE) { // Find out whether there's a "no" choice. // m_option_parse() should be used for this, but it prints diff --git a/options/m_option.c b/options/m_option.c index 77e610f08c..b76fe072f4 100644 --- a/options/m_option.c +++ b/options/m_option.c @@ -114,9 +114,9 @@ static void copy_opt(const m_option_t *opt, void *dst, const void *src) static int clamp_flag(const m_option_t *opt, void *val) { - if (VAL(val) == opt->min || VAL(val) == opt->max) + if (VAL(val) == 0 || VAL(val) == 1) return 0; - VAL(val) = opt->min; + VAL(val) = 0; return M_OPT_OUT_OF_RANGE; } @@ -126,12 +126,12 @@ static int parse_flag(struct mp_log *log, const m_option_t *opt, if (param.len) { if (!bstrcmp0(param, "yes")) { if (dst) - VAL(dst) = opt->max; + VAL(dst) = 1; return 1; } if (!bstrcmp0(param, "no")) { if (dst) - VAL(dst) = opt->min; + VAL(dst) = 0; return 1; } mp_err(log, "Invalid parameter for %.*s flag: %.*s\n", @@ -139,33 +139,30 @@ static int parse_flag(struct mp_log *log, const m_option_t *opt, return M_OPT_INVALID; } else { if (dst) - VAL(dst) = opt->max; + VAL(dst) = 1; return 0; } } static char *print_flag(const m_option_t *opt, const void *val) { - if (VAL(val) == opt->min) - return talloc_strdup(NULL, "no"); - else - return talloc_strdup(NULL, "yes"); + return talloc_strdup(NULL, VAL(val) ? "yes" : "no"); } static void add_flag(const m_option_t *opt, void *val, double add, bool wrap) { if (fabs(add) < 0.5) return; - bool state = VAL(val) != opt->min; + bool state = !!VAL(val); state = wrap ? !state : add > 0; - VAL(val) = state ? opt->max : opt->min; + VAL(val) = state ? 1 : 0; } static int flag_set(const m_option_t *opt, void *dst, struct mpv_node *src) { if (src->format != MPV_FORMAT_FLAG) return M_OPT_UNKNOWN; - VAL(dst) = src->u.flag ? opt->max : opt->min; + VAL(dst) = !!src->u.flag; return 1; } @@ -173,7 +170,7 @@ static int flag_get(const m_option_t *opt, void *ta_parent, struct mpv_node *dst, void *src) { dst->format = MPV_FORMAT_FLAG; - dst->u.flag = VAL(src) != opt->min; + dst->u.flag = !!VAL(src); return 1; } diff --git a/options/m_option.h b/options/m_option.h index b7579bd5e9..fc210b3a43 100644 --- a/options/m_option.h +++ b/options/m_option.h @@ -549,21 +549,15 @@ extern const char m_option_path_separator; #define OPT_HELPER_REMOVEPAREN(...) __VA_ARGS__ -/* The OPT_FLAG_CONSTANTS->OPT_FLAG_CONSTANTS_ kind of redirection exists to +/* The OPT_SOMETHING->OPT_SOMETHING_ kind of redirection exists to * make the code fully standard-conforming: the C standard requires that * __VA_ARGS__ has at least one argument (though GCC for example would accept - * 0). Thus the first OPT_FLAG_CONSTANTS is a wrapper which just adds one + * 0). Thus the first OPT_SOMETHING is a wrapper which just adds one * argument to ensure __VA_ARGS__ is not empty when calling the next macro. */ #define OPT_FLAG(...) \ - OPT_GENERAL(int, __VA_ARGS__, .type = &m_option_type_flag, .max = 1) - -#define OPT_FLAG_CONSTANTS_(optname, varname, flags, offvalue, value, ...) \ - OPT_GENERAL(int, optname, varname, flags, \ - .min = offvalue, .max = value, __VA_ARGS__) -#define OPT_FLAG_CONSTANTS(...) \ - OPT_FLAG_CONSTANTS_(__VA_ARGS__, .type = &m_option_type_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, \ @@ -675,7 +669,7 @@ extern const char m_option_path_separator; {.name = optname, \ .flags = M_OPT_FIXED | 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) } + .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 |