m_option: add function to check whether parameters are required

To avoid that it will be duplicated with m_option.c and m_config.c.
This commit is contained in:
wm4 2013-04-21 03:18:32 +02:00
parent c6037982fd
commit 9fd2e449de
3 changed files with 11 additions and 4 deletions

View File

@ -585,10 +585,7 @@ int m_config_option_requires_param(struct m_config *config, bstr name)
if (opt) {
if (bstr_endswith0(name, "-clr"))
return 0;
if (((opt->flags & M_OPT_OPTIONAL_PARAM) ||
(opt->type->flags & M_OPT_TYPE_OPTIONAL_PARAM)))
return 0;
return 1;
return m_option_required_params(opt);
}
return M_OPT_UNKNOWN;
}

View File

@ -59,6 +59,14 @@ char *m_option_strerror(int code)
}
}
int m_option_required_params(const m_option_t *opt)
{
if (((opt->flags & M_OPT_OPTIONAL_PARAM) ||
(opt->type->flags & M_OPT_TYPE_OPTIONAL_PARAM)))
return 0;
return 1;
}
static const struct m_option *m_option_list_findb(const struct m_option *list,
struct bstr name)
{

View File

@ -464,6 +464,8 @@ static inline void m_option_free(const m_option_t *opt, void *dst)
opt->type->free(dst);
}
int m_option_required_params(const m_option_t *opt);
// Cause a compilation warning if typeof(expr) != type.
// Should be used with pointer types only.
#define MP_EXPECT_TYPE(type, expr) (0 ? (type)0 : (expr))