Replace my own implementation with simpler strtok()

This commit is contained in:
Artur Tamborski 2018-12-17 12:08:20 +01:00
parent ace246133e
commit acd001edbb

View File

@ -56,34 +56,23 @@ sigint(int signal)
int
tokenize(char *input)
{
char curr, prev = '\n';
char whitespaces[] = " \t\n";
char **tokens = g_tokens;
char *start = g_args;
char *args = g_args;
int real_input = 0;
char *token;
size_t len;
int argc = 0;
while ((curr = *input++) != '\0')
token = strtok(input, whitespaces);
while (token != NULL)
{
if (curr == ' ' || curr == '\n')
{
if (curr == prev || !real_input)
continue;
len = strlen(token) + 1;
memcpy(args, token, len);
*tokens++ = args;
args += len + 1;
argc++;
*tokens++ = start;
*args++ = '\0';
start = args;
argc++;
if (curr == '\n')
break;
} else
{
*args++ = curr;
real_input = 1;
}
prev = curr;
token = strtok(NULL, whitespaces);
}
tokens = NULL;