1
0
mirror of https://github.com/Tha14/toxic.git synced 2025-12-06 17:16:36 +01:00

cleanup/error checks

This commit is contained in:
Jfreegman
2014-07-17 03:35:18 -04:00
parent b5f34f42a8
commit e61d070def
4 changed files with 34 additions and 20 deletions

View File

@@ -82,12 +82,15 @@ static struct cmd_func chat_commands[] = {
static int parse_command(WINDOW *w, ToxWindow *self, const char *input, char (*args)[MAX_STR_SIZE])
{
char *cmd = strdup(input);
if (cmd == NULL)
exit_toxic_err("failed in parse_command", FATALERR_MEMORY);
int num_args = 0;
int i = 0; /* index of last char in an argument */
bool cmd_end = false;
/* characters wrapped in double quotes count as one arg */
while (!cmd_end && num_args < MAX_NUM_ARGS) {
while (num_args < MAX_NUM_ARGS) {
int qt_ofst = 0; /* set to 1 to offset index for quote char at end of arg */
if (*cmd == '\"') {
@@ -107,10 +110,10 @@ static int parse_command(WINDOW *w, ToxWindow *self, const char *input, char (*a
memcpy(args[num_args], cmd, i + qt_ofst);
args[num_args++][i + qt_ofst] = '\0';
if (cmd[i])
strcpy(cmd, &cmd[i + 1]);
else
cmd_end = true;
if (cmd[i] == '\0') /* no more args */
break;
strcpy(cmd, &cmd[i + 1]);
}
free(cmd);