42 lines
1.0 KiB
C
42 lines
1.0 KiB
C
void
|
|
parse_command(char *input) {
|
|
static char com[COM_BUF_SIZE];
|
|
memcpy(com, input, COM_BUF_SIZE);
|
|
static char *starts[128];
|
|
memset(starts, 0, sizeof(starts));
|
|
int next_start = 0;
|
|
com[COM_BUF_SIZE - 1] = ' ';
|
|
for (int i = 0; i < COM_BUF_SIZE; i++) {
|
|
for (; com[i] == ' ' && i < COM_BUF_SIZE; i++);
|
|
if (i >= COM_BUF_SIZE) break;
|
|
starts[next_start] = com + i;
|
|
for(; i < COM_BUF_SIZE && com[i] != ' '; i++)
|
|
;
|
|
com[i] = '\0';
|
|
next_start++;
|
|
}
|
|
|
|
for (int i = 0; starts[i] != NULL; i++) {
|
|
puts(starts[i]);
|
|
}
|
|
}
|
|
|
|
int
|
|
main(int argc, char **argv) {
|
|
static char buf[COM_BUF_SIZE];
|
|
while(1) {
|
|
memset(buf, 0, sizeof(buf));
|
|
printf(" > ");
|
|
char *com = fgets(buf, sizeof(buf), stdin);
|
|
for (int i = 0; i < sizeof(buf); i++)
|
|
if (buf[i] == '\n')
|
|
buf[i] = '\0';
|
|
if (com != NULL) {
|
|
if (commands[com[0]] != NULL) commands[com[0]](buf);
|
|
else puts("invalid command.");
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|