string dump() { return "<string> \"" + val + '"'; }
};
-static arg_val null_arg;
+arg_val null_arg;
/*** Parser ***/
while (adefs[num_args].name)
num_args++;
- c->args.resize(num_args, &null_arg);
-
token_type t = next_token();
if (t != TOK_OPEN_PAREN)
{
argi++;
if (!adefs[argi].name)
parse_error("Command %s has no parameter %s", cdef->name, token.c_str());
- if (c->args.at(argi)->given())
+ if (c->args.count(token))
parse_error("Parameter %s given multiple times", token.c_str());
t = next_token();
if (t == TOK_EQUAL)
parse_error("Parameter %s must have a value", adef->name);
}
- c->args.at(argi) = val;
+ c->args[adef->name] = val;
t = next_token();
if (t == TOK_CLOSE_PAREN)
}
for (uint i=0; i<num_args; i++)
- if ((adefs[i].type & AT_MANDATORY) && !c->args.at(i)->given())
+ if ((adefs[i].type & AT_MANDATORY) && !c->args.count(adefs[i].name))
parse_error("Command %s is missing a parameter %s", cdef->name, adefs[i].name);
}
static void debug_cmd(cmd *c, uint indent=0)
{
printf("%*sCommand %s\n", indent, "", c->def->name);
- for (size_t i=0; i < c->args.size(); i++)
+ for (uint i=0; c->def->arg_defs[i].name; i++)
{
const arg_def *adef = &c->def->arg_defs[i];
- string dump = c->args.at(i)->dump();
+ string dump = c->arg(adef->name)->dump();
printf("%*sArg #%d: %s = %s\n", indent+4, "", (int) i, adef->name, dump.c_str());
}
if (c->pipe)