Implementing strtok and adding strtok to the shell
This commit is contained in:
parent
2695dcf2b0
commit
78768d172a
@ -95,16 +95,13 @@ DispatchCommand(char *buf)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// parse input
|
// parse input
|
||||||
argv[0] = buf;
|
nextArg = strtok(buf, " \t\r\n");
|
||||||
for (argc = 1; argc < SHELL_MAX_ARGS; argc++) {
|
for (argc = 0; argc < SHELL_MAX_ARGS; argc++) {
|
||||||
nextArg = strchr(argv[argc - 1], ' ');
|
|
||||||
if (nextArg == NULL)
|
if (nextArg == NULL)
|
||||||
{
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
*nextArg = '\0';
|
argv[argc] = nextArg;
|
||||||
argv[argc] = nextArg + 1;
|
nextArg = strtok(NULL, " \t\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
// execute command
|
// execute command
|
||||||
|
@ -18,5 +18,7 @@ char *strncpy(char *to, const char *from, size_t len);
|
|||||||
char *strcat(char *s, const char *append);
|
char *strcat(char *s, const char *append);
|
||||||
char *strncat(char *s, const char *append, size_t count);
|
char *strncat(char *s, const char *append, size_t count);
|
||||||
|
|
||||||
|
char *strtok(char *str, const char *delim);
|
||||||
|
|
||||||
#endif /* __STRING_H__ */
|
#endif /* __STRING_H__ */
|
||||||
|
|
||||||
|
@ -118,6 +118,41 @@ strlen(const char *str)
|
|||||||
return (s - str);
|
return (s - str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *
|
||||||
|
strtok(char *str, const char *delim)
|
||||||
|
{
|
||||||
|
char *rval;
|
||||||
|
static char *last;
|
||||||
|
|
||||||
|
if (str == NULL)
|
||||||
|
str = last;
|
||||||
|
|
||||||
|
// Skip deliminaters in the front
|
||||||
|
while ((str[0] != '\0') && strchr(delim, str[0])) {
|
||||||
|
str++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// We've reached the end of the string
|
||||||
|
if (str[0] == '\0')
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
// Return first non-delim until the next
|
||||||
|
rval = str;
|
||||||
|
|
||||||
|
// Skip deliminaters in the front
|
||||||
|
while ((str[0] != '\0') && !strchr(delim, str[0])) {
|
||||||
|
str++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (str[0] != '\0') {
|
||||||
|
str[0] = '\0';
|
||||||
|
str++;
|
||||||
|
}
|
||||||
|
last = str;
|
||||||
|
|
||||||
|
return rval;
|
||||||
|
}
|
||||||
|
|
||||||
void *
|
void *
|
||||||
memset(void *dst, int c, size_t length)
|
memset(void *dst, int c, size_t length)
|
||||||
{
|
{
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2006-2018 Ali Mashtizadeh
|
* Copyright (c) 2006-2023 Ali Mashtizadeh
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -226,6 +226,13 @@ void Debug_Assert(const char *fmt, ...)
|
|||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
kvprintf(fmt, consoleputc, 0, ap);
|
kvprintf(fmt, consoleputc, 0, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
||||||
|
kprintf("PC %lx FP %lx\n", __builtin_return_address(0), __builtin_frame_address(0));
|
||||||
|
kprintf("PC %lx FP %lx\n", __builtin_return_address(1), __builtin_frame_address(1));
|
||||||
|
kprintf("PC %lx FP %lx\n", __builtin_return_address(2), __builtin_frame_address(2));
|
||||||
|
kprintf("PC %lx FP %lx\n", __builtin_return_address(3), __builtin_frame_address(3));
|
||||||
|
kprintf("PC %lx FP %lx\n", __builtin_return_address(4), __builtin_frame_address(4));
|
||||||
|
kprintf("PC %lx FP %lx\n", __builtin_return_address(5), __builtin_frame_address(5));
|
||||||
|
|
||||||
Panic("");
|
Panic("");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user