From dc48893630d11829121a45137460afb45e24ef2d Mon Sep 17 00:00:00 2001 From: wm4 Date: Sat, 17 Sep 2016 18:07:40 +0200 Subject: options: simplify M_OPT_EXIT There were multiple values under M_OPT_EXIT (M_OPT_EXIT-n for n>=0). Somehow M_OPT_EXIT-n either meant error code n (with n==0 no error?), or the number of option valus consumed (0 or 1). The latter is MPlayer legacy, which left it to the option type parsers to determine whether an option took a value or not. All of this was changed in mpv, by requiring the user to use explicit syntax ("--opt=val" instead of "-opt val"). In any case, the n value wasn't even used (anymore), so rip this all out. Now M_OPT_EXIT-1 doesn't mean anything, and could be used by a new error code. --- options/m_config.c | 14 +++++++------- options/m_option.c | 14 +++++++------- options/m_option.h | 5 +---- options/parse_commandline.c | 5 ++--- 4 files changed, 17 insertions(+), 21 deletions(-) (limited to 'options') diff --git a/options/m_config.c b/options/m_config.c index 2bc187b444..50fa9248a1 100644 --- a/options/m_config.c +++ b/options/m_config.c @@ -116,13 +116,13 @@ static int parse_profile(struct m_config *config, const struct m_option *opt, struct m_profile *p; if (!config->profiles) { MP_INFO(config, "No profiles have been defined.\n"); - return M_OPT_EXIT - 1; + return M_OPT_EXIT; } MP_INFO(config, "Available profiles:\n"); for (p = config->profiles; p; p = p->next) MP_INFO(config, "\t%s\t%s\n", p->name, p->desc ? p->desc : ""); MP_INFO(config, "\n"); - return M_OPT_EXIT - 1; + return M_OPT_EXIT; } char **list = NULL; @@ -148,7 +148,7 @@ static int show_profile(struct m_config *config, bstr param) return M_OPT_MISSING_PARAM; if (!(p = m_config_get_profile(config, param))) { MP_ERR(config, "Unknown profile '%.*s'.\n", BSTR_P(param)); - return M_OPT_EXIT - 1; + return M_OPT_EXIT; } if (!config->profile_depth) MP_INFO(config, "Profile %s: %s\n", p->name, @@ -175,7 +175,7 @@ static int show_profile(struct m_config *config, bstr param) config->profile_depth--; if (!config->profile_depth) MP_INFO(config, "\n"); - return M_OPT_EXIT - 1; + return M_OPT_EXIT; } static int list_options(struct m_config *config, bstr val, bool show_help) @@ -814,7 +814,7 @@ static int parse_subopts(struct m_config *config, char *name, char *prefix, abort(); r = m_config_parse_option(config,bstr0(n), bstr0(lst[2 * i + 1]), flags); if (r < 0) { - if (r > M_OPT_EXIT) { + if (r != M_OPT_EXIT) { MP_ERR(config, "Error parsing suboption %s/%s (%s)\n", name, lst[2 * i], m_option_strerror(r)); r = M_OPT_INVALID; @@ -832,7 +832,7 @@ int m_config_parse_suboptions(struct m_config *config, char *name, if (!subopts || !*subopts) return 0; int r = parse_subopts(config, name, "", bstr0(subopts), 0); - if (r < 0 && r > M_OPT_EXIT) { + if (r < 0 && r != M_OPT_EXIT) { MP_ERR(config, "Error parsing suboption %s (%s)\n", name, m_option_strerror(r)); r = M_OPT_INVALID; @@ -844,7 +844,7 @@ int m_config_set_option_ext(struct m_config *config, struct bstr name, struct bstr param, int flags) { int r = m_config_parse_option(config, name, param, flags); - if (r < 0 && r > M_OPT_EXIT) { + if (r < 0 && r != M_OPT_EXIT) { MP_ERR(config, "Error parsing option %.*s (%s)\n", BSTR_P(name), m_option_strerror(r)); r = M_OPT_INVALID; diff --git a/options/m_option.c b/options/m_option.c index fa9a9578ab..4ef5481ceb 100644 --- a/options/m_option.c +++ b/options/m_option.c @@ -2104,7 +2104,7 @@ static int parse_imgfmt(struct mp_log *log, const m_option_t *opt, mp_info(log, " %s", list[i]); mp_info(log, "\n"); talloc_free(list); - return M_OPT_EXIT - 1; + return M_OPT_EXIT; } unsigned int fmt = mp_imgfmt_from_name(param, true); @@ -2175,7 +2175,7 @@ static int parse_afmt(struct mp_log *log, const m_option_t *opt, for (int i = 1; i < AF_FORMAT_COUNT; i++) mp_info(log, " %s", af_fmt_to_str(i)); mp_info(log, "\n"); - return M_OPT_EXIT - 1; + return M_OPT_EXIT; } int fmt = 0; @@ -2219,7 +2219,7 @@ static int parse_channels(struct mp_log *log, const m_option_t *opt, mp_info(log, "\nOther values:\n" " auto-safe\n"); } - return M_OPT_EXIT - 1; + return M_OPT_EXIT; } bool auto_safe = bstr_equals0(param, "auto-safe"); @@ -2670,7 +2670,7 @@ static int get_obj_param(struct mp_log *log, bstr opt_name, bstr obj_name, BSTR_P(opt_name), BSTR_P(obj_name), BSTR_P(name)); return M_OPT_UNKNOWN; } - if (r > M_OPT_EXIT) + if (r != M_OPT_EXIT) mp_err(log, "Option %.*s: " "Error while parsing %.*s parameter %.*s (%.*s)\n", BSTR_P(opt_name), BSTR_P(obj_name), BSTR_P(name), @@ -2696,7 +2696,7 @@ static int get_obj_param(struct mp_log *log, bstr opt_name, bstr obj_name, } r = m_config_set_option_ext(config, bstr0(opt), val, flags); if (r < 0) { - if (r > M_OPT_EXIT) + if (r != M_OPT_EXIT) mp_err(log, "Option %.*s: " "Error while parsing %.*s parameter %s (%.*s)\n", BSTR_P(opt_name), BSTR_P(obj_name), opt, BSTR_P(val)); @@ -2776,7 +2776,7 @@ print_help: ; mp_warn(log, "Option %.*s: item %.*s doesn't exist.\n", BSTR_P(opt_name), BSTR_P(name)); } - r = M_OPT_EXIT - 1; + r = M_OPT_EXIT; exit: free_str_list(&args); @@ -2973,7 +2973,7 @@ static int parse_obj_settings_list(struct mp_log *log, const m_option_t *opt, } } mp_info(log, "\n"); - return M_OPT_EXIT - 1; + return M_OPT_EXIT; } if (op == OP_CLR) { diff --git a/options/m_option.h b/options/m_option.h index a4019f411a..6435584716 100644 --- a/options/m_option.h +++ b/options/m_option.h @@ -417,8 +417,7 @@ struct m_option { // On success parsers return a number >= 0. // // To indicate that MPlayer should exit without playing anything, -// parsers return M_OPT_EXIT minus the number of parameters they -// consumed: \ref M_OPT_EXIT or \ref M_OPT_EXIT-1. +// parsers return M_OPT_EXIT. // // On error one of the following (negative) error codes is returned: @@ -442,8 +441,6 @@ struct m_option { #define M_OPT_PARSER_ERR -6 // Returned when MPlayer should exit. Used by various help stuff. -/** M_OPT_EXIT must be the lowest number on this list. - */ #define M_OPT_EXIT -7 char *m_option_strerror(int code); diff --git a/options/parse_commandline.c b/options/parse_commandline.c index ab1f28f72b..b90912e786 100644 --- a/options/parse_commandline.c +++ b/options/parse_commandline.c @@ -151,11 +151,10 @@ int m_config_parse_mp_command_line(m_config_t *config, struct playlist *files, if (mode == LOCAL) flags |= M_SETOPT_BACKUP | M_SETOPT_CHECK_ONLY; int r = m_config_set_option_ext(config, p.arg, p.param, flags); - if (r <= M_OPT_EXIT) { + if (r == M_OPT_EXIT) { ret = r; goto err_out; - } - if (r < 0) { + } else if (r < 0) { MP_FATAL(config, "Setting command line option '--%.*s=%.*s' failed.\n", BSTR_P(p.arg), BSTR_P(p.param)); goto err_out; -- cgit v1.2.3