From b143102f6d0ffe383cca346336bcb745ed029a49 Mon Sep 17 00:00:00 2001 From: wm4 Date: Fri, 27 Feb 2015 15:36:50 +0100 Subject: options: minor simplification in flag option parser --- options/m_option.c | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) (limited to 'options') diff --git a/options/m_option.c b/options/m_option.c index ca90c52624..699ecb4539 100644 --- a/options/m_option.c +++ b/options/m_option.c @@ -124,29 +124,23 @@ static int clamp_flag(const m_option_t *opt, void *val) static int parse_flag(struct mp_log *log, const m_option_t *opt, struct bstr name, struct bstr param, void *dst) { - if (param.len) { - if (!bstrcmp0(param, "yes")) { - if (dst) - VAL(dst) = 1; - return 1; - } - if (!bstrcmp0(param, "no")) { - if (dst) - VAL(dst) = 0; - return 1; - } - mp_fatal(log, "Invalid parameter for %.*s flag: %.*s\n", - BSTR_P(name), BSTR_P(param)); - mp_info(log, "Valid values are:\n"); - mp_info(log, " yes\n"); - mp_info(log, " no\n"); - mp_info(log, " (passing nothing)\n"); - return M_OPT_INVALID; - } else { + if (bstr_equals0(param, "yes") || !param.len) { if (dst) VAL(dst) = 1; - return 0; + return 1; } + if (bstr_equals0(param, "no")) { + if (dst) + VAL(dst) = 0; + return 1; + } + mp_fatal(log, "Invalid parameter for %.*s flag: %.*s\n", + BSTR_P(name), BSTR_P(param)); + mp_info(log, "Valid values are:\n"); + mp_info(log, " yes\n"); + mp_info(log, " no\n"); + mp_info(log, " (passing nothing)\n"); + return M_OPT_INVALID; } static char *print_flag(const m_option_t *opt, const void *val) -- cgit v1.2.3