command: fix loadfile command

This was broken by commit bb6b543812. Note that the original pull
request was fine, but it was broken by my own stupidity when I was
"improving" it.

The problem is that the new loadfile argument was not considered
optional anymore after my changes. The original pull request did handle
this by setting .defval to a dummy value, but I removed that part.

Fix it again by introducing a flag that designates that the parameter is
optional. (I didn't want to add it to m_option.h, because technically,
all options are optional, and it's not possible to have non-optional
options.)
This commit is contained in:
wm4 2014-02-24 23:02:20 +01:00
parent 0adb8a9aaf
commit 761975d47b
3 changed files with 6 additions and 3 deletions

View File

@ -122,7 +122,7 @@ const struct mp_cmd_def mp_cmds[] = {
ARG_STRING,
OARG_CHOICE(0, ({"replace", 0}, {"0", 0},
{"append", 1}, {"1", 1})),
OPT_KEYVALUELIST(ARG(str_list), 0),
OPT_KEYVALUELIST(ARG(str_list), MP_CMD_OPT_ARG),
}},
{ MP_CMD_LOADLIST, "loadlist", {
ARG_STRING,

View File

@ -24,6 +24,8 @@
#define MP_CMD_MAX_ARGS 10
#define MP_CMD_OPT_ARG 0x1000
struct mp_cmd_def {
int id; // one of MP_CMD_...
const char *name; // user-visible name (as used in input.conf)

View File

@ -199,10 +199,11 @@ static struct mp_cmd *parse_cmd(struct parse_ctx *ctx, int def_flags)
if (is_vararg)
continue;
// Skip optional arguments
if (opt->defval) {
if (opt->defval || (opt->flags & MP_CMD_OPT_ARG)) {
struct mp_cmd_arg *cmdarg = &cmd->args[cmd->nargs];
cmdarg->type = opt;
m_option_copy(opt, &cmdarg->v, opt->defval);
if (opt->defval)
m_option_copy(opt, &cmdarg->v, opt->defval);
cmd->nargs++;
continue;
}