1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-11-23 02:03:02 +01:00

small fix

This commit is contained in:
Jfreegman 2013-11-09 22:08:25 -05:00
parent ce05e206f1
commit 8643d14777

View File

@ -10,20 +10,22 @@
#include "chat_commands.h" #include "chat_commands.h"
#include "execute.h" #include "execute.h"
/* Parses input command and puts args into arg array.
Returns number of arguments on success, -1 on failure. */
static int parse_command(WINDOW *window, char *cmd, char (*args)[MAX_STR_SIZE]) static int parse_command(WINDOW *window, char *cmd, char (*args)[MAX_STR_SIZE])
{ {
int num_args = 0; int num_args = 0;
bool cmd_end = false; // flags when we get to the end of cmd bool cmd_end = false; // flags when we get to the end of cmd
char *end; // points to the end of the current arg char *end; // points to the end of the current arg
/* Put arguments into args array (characters wrapped in double quotes count as one arg) */ /* characters wrapped in double quotes count as one arg */
while (!cmd_end && num_args < MAX_NUM_ARGS) { while (!cmd_end && num_args < MAX_NUM_ARGS) {
if (*cmd == '\"') { if (*cmd == '\"') {
end = strchr(cmd+1, '\"'); end = strchr(cmd+1, '\"');
if (end++ == NULL) { /* Increment past the end quote */ if (end++ == NULL) { /* Increment past the end quote */
wprintw(window, "Invalid argument. Did you forget a closing \"?\n"); wprintw(window, "Invalid argument. Did you forget a closing \"?\n");
return; return -1;
} }
cmd_end = *end == '\0'; cmd_end = *end == '\0';
@ -51,6 +53,9 @@ void execute(WINDOW *window, ToxWindow *prompt, Tox *m, char *cmd, int mode)
char args[MAX_NUM_ARGS][MAX_STR_SIZE] = {0}; char args[MAX_NUM_ARGS][MAX_STR_SIZE] = {0};
int num_args = parse_command(window, cmd, args); int num_args = parse_command(window, cmd, args);
if (num_args == -1)
return;
/* Attempt to match input to command functions. If non-global command mode is specified, /* Attempt to match input to command functions. If non-global command mode is specified,
try the specified mode's commands first, then upon failure try global commands. try the specified mode's commands first, then upon failure try global commands.