efn/main.c

42 lines
1.0 KiB
C
Raw Normal View History

2022-04-02 17:22:49 +00:00
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]);
}
}
2022-04-02 11:40:10 +00:00
int
main(int argc, char **argv) {
static char buf[COM_BUF_SIZE];
while(1) {
2022-04-02 12:46:20 +00:00
memset(buf, 0, sizeof(buf));
2022-04-02 16:12:22 +00:00
printf(" > ");
char *com = fgets(buf, sizeof(buf), stdin);
2022-04-02 12:46:20 +00:00
for (int i = 0; i < sizeof(buf); i++)
if (buf[i] == '\n')
buf[i] = '\0';
2022-04-02 11:40:10 +00:00
if (com != NULL) {
2022-04-02 12:46:20 +00:00
if (commands[com[0]] != NULL) commands[com[0]](buf);
else puts("invalid command.");
}
}
return 0;
2022-04-02 11:40:10 +00:00
}
2022-04-02 12:46:20 +00:00