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.
This commit is contained in:
wm4 2016-09-17 18:07:40 +02:00
parent d1d5e9dda4
commit dc48893630
8 changed files with 22 additions and 26 deletions

View File

@ -96,7 +96,7 @@ static int validate_device_opt(struct mp_log *log, const m_option_t *opt,
mp_info(log, " '%s'\n", list);
list = list + strlen(list) + 1;
}
return M_OPT_EXIT - 1;
return M_OPT_EXIT;
}
return 0;
}

View File

@ -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;

View File

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

View File

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

View File

@ -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;

View File

@ -392,7 +392,7 @@ int mp_initialize(struct MPContext *mpctx, char **options)
int r = m_config_parse_mp_command_line(mpctx->mconfig, mpctx->playlist,
mpctx->global, options);
if (r < 0)
return r <= M_OPT_EXIT ? -2 : -1;
return r == M_OPT_EXIT ? -2 : -1;
update_logging(mpctx);
}

View File

@ -114,7 +114,7 @@ int mpgl_validate_backend_opt(struct mp_log *log, const struct m_option *opt,
mp_info(log, " auto (autodetect)\n");
for (int n = 0; n < MP_ARRAY_SIZE(backends); n++)
mp_info(log, " %s\n", backends[n]->name);
return M_OPT_EXIT - 1;
return M_OPT_EXIT;
}
char s[20];
snprintf(s, sizeof(s), "%.*s", BSTR_P(param));

View File

@ -3535,7 +3535,7 @@ static int validate_scaler_opt(struct mp_log *log, const m_option_t *opt,
int r = 1;
bool tscale = bstr_equals0(name, "tscale");
if (bstr_equals0(param, "help")) {
r = M_OPT_EXIT - 1;
r = M_OPT_EXIT;
} else {
snprintf(s, sizeof(s), "%.*s", BSTR_P(param));
if (!handle_scaler_opt(s, tscale))
@ -3564,7 +3564,7 @@ static int validate_window_opt(struct mp_log *log, const m_option_t *opt,
char s[20] = {0};
int r = 1;
if (bstr_equals0(param, "help")) {
r = M_OPT_EXIT - 1;
r = M_OPT_EXIT;
} else {
snprintf(s, sizeof(s), "%.*s", BSTR_P(param));
const struct filter_window *window = mp_find_filter_window(s);