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 07545657bf.
This commit is contained in:
Christoph Heinrich 2023-02-26 16:19:55 +01:00 committed by sfan5
parent d941564d48
commit a265da9f25
1 changed files with 63 additions and 0 deletions

View File

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