summaryrefslogtreecommitdiffstats
path: root/options/m_option.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-06-13 02:08:48 +0200
committerwm4 <wm4@nowhere>2014-06-13 02:10:45 +0200
commit6a4a5595d8d2a17188cdea64dfdfceed88d1905a (patch)
tree67ae9607f27ea120c7d1299cdf0bbbb603e5789e /options/m_option.c
parent09a61ba03ab0918d045d02427ccdc775abc38f03 (diff)
downloadmpv-6a4a5595d8d2a17188cdea64dfdfceed88d1905a.tar.bz2
mpv-6a4a5595d8d2a17188cdea64dfdfceed88d1905a.tar.xz
options: remove OPT_FLAG_CONSTANTS
This means use of the min/max fields can be dropped for the flag option type, which makes some things slightly easier. I'm also not sure if the client API handled the case of flag not being 0 or 1 correctly, and this change gets rid of this concern.
Diffstat (limited to 'options/m_option.c')
-rw-r--r--options/m_option.c23
1 files changed, 10 insertions, 13 deletions
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;
}