fix multiple optional arguments

Assuming the argument definition "?xy", it was previously not possible
to specify only x. Also, the syntax will now be shown as "[x [y]]"
instead of "[x] [y]".
This commit is contained in:
Tilka 2012-04-19 03:06:52 +02:00
parent e925db2b98
commit 4f0c8e0356
2 changed files with 14 additions and 9 deletions

View File

@ -163,7 +163,10 @@ static enum command_parse_status command_extract_arguments(struct command_base*
token = list_get_first(tokens);
if (!token || !*token)
{
status = (arg_code == '?' ? cmd_status_ok : cmd_status_missing_args);
if (arg_code == '?' || opt == 1)
status = cmd_status_ok;
else
status = cmd_status_missing_args;
break;
}
@ -257,7 +260,7 @@ static enum command_parse_status command_extract_arguments(struct command_base*
{
hub_free(data);
data = NULL;
return cmd_status_arg_number;
status = cmd_status_arg_number;
}
break;
@ -360,10 +363,13 @@ void command_get_syntax(struct command_handle* handler, struct cbuffer* buf)
{
for (n = 0; n < strlen(handler->args); n++)
{
if (n > 0 && !opt) cbuf_append(buf, " ");
if (n > 0)
cbuf_append(buf, " ");
if (opt)
cbuf_append(buf, "[");
switch (handler->args[n])
{
case '?': cbuf_append(buf, "["); opt = 1; continue;
case '?': opt = 1; continue;
case 'n': cbuf_append(buf, "<nick>"); break;
case 'u': cbuf_append(buf, "<user>"); break;
case 'i': cbuf_append(buf, "<cid>"); break;
@ -376,11 +382,10 @@ void command_get_syntax(struct command_handle* handler, struct cbuffer* buf)
case 'N': cbuf_append(buf, "<number>"); break;
}
if (opt)
{
opt++;
}
while (opt--)
cbuf_append(buf, "]");
opt = 0;
}
}
}
}

View File

@ -83,7 +83,7 @@ struct hub_command
{
const char* message; /**<<< "The complete message." */
char* prefix; /**<<< "The prefix extracted from the message." */
struct linked_list* args; /**<<< "List of all parsed arguments from the message. Type depends on expectations." */
struct linked_list* args; /**<<< "List of arguments of type struct hub_command_arg_data. Parsed from message." */
enum command_parse_status status; /**<<< "Status of the hub_command." */
command_handler handler; /**<<< "The function handler to call in order to invoke this command." */
const struct hub_user* user; /**<<< "The user who invoked this command." */