summaryrefslogtreecommitdiffstats
path: root/options
diff options
context:
space:
mode:
authorChristoph Heinrich <christoph.heinrich@student.tugraz.at>2023-02-26 16:19:55 +0100
committersfan5 <sfan5@live.de>2023-02-27 11:21:49 +0100
commita265da9f25ed613212a00b8143a9b6f76d341440 (patch)
tree0c9449a366f44376a66a76b336e404afae1670c0 /options
parentd941564d48e4963b3b69370d0a8313bea2bec678 (diff)
downloadmpv-a265da9f25ed613212a00b8143a9b6f76d341440.tar.bz2
mpv-a265da9f25ed613212a00b8143a9b6f76d341440.tar.xz
Partially revert "options: remove OPT_FLAG"
The m_option_type_flag is still needed for the CONF_TYPE_FLAG (next commit). Add a comment that m_option_type_flag shouldn't be used. ref. #11373 This partially reverts commit 07545657bf73ebb4da38e26950d5203466298ec1.
Diffstat (limited to 'options')
-rw-r--r--options/m_option.c63
1 files changed, 63 insertions, 0 deletions
diff --git a/options/m_option.c b/options/m_option.c
index 61b75ec14a..8d926e6254 100644
--- a/options/m_option.c
+++ b/options/m_option.c
@@ -224,8 +224,71 @@ const m_option_type_t m_option_type_bool = {
#undef VAL
+// Flag
+
+#define VAL(x) (*(int *)(x))
+
+static int parse_flag(struct mp_log *log, const m_option_t *opt,
+ struct bstr name, struct bstr param, void *dst)
+{
+ bool bdst = false;
+ int r = parse_bool(log, opt, name, param, &bdst);
+ if (dst)
+ VAL(dst) = bdst;
+ return r;
+}
+
+static char *print_flag(const m_option_t *opt, const void *val)
+{
+ return print_bool(opt, &(bool){VAL(val)});
+}
+
+static void add_flag(const m_option_t *opt, void *val, double add, bool wrap)
+{
+ bool bval = VAL(val);
+ add_bool(opt, &bval, add, wrap);
+ VAL(val) = bval;
+}
+
+static int flag_set(const m_option_t *opt, void *dst, struct mpv_node *src)
+{
+ bool bdst = false;
+ int r = bool_set(opt, &bdst, src);
+ if (r >= 0)
+ VAL(dst) = bdst;
+ return r;
+}
+
+static int flag_get(const m_option_t *opt, void *ta_parent,
+ struct mpv_node *dst, void *src)
+{
+ return bool_get(opt, ta_parent, dst, &(bool){VAL(src)});
+}
+
+static bool flag_equal(const m_option_t *opt, void *a, void *b)
+{
+ return VAL(a) == VAL(b);
+}
+
+// Only exists for libmpv interopability and should not be used anywhere.
+const m_option_type_t m_option_type_flag = {
+ // need yes or no in config files
+ .name = "Flag",
+ .size = sizeof(int),
+ .flags = M_OPT_TYPE_OPTIONAL_PARAM | M_OPT_TYPE_CHOICE,
+ .parse = parse_flag,
+ .print = print_flag,
+ .copy = copy_opt,
+ .add = add_flag,
+ .set = flag_set,
+ .get = flag_get,
+ .equal = flag_equal,
+};
+
// Integer
+#undef VAL
+
static int clamp_longlong(const m_option_t *opt, long long i_min, long long i_max,
void *val)
{