added command parse func to main

master
bx 2022-04-02 17:22:49 +00:00
parent 0ebcdc3ad5
commit 635fb539a3
1 changed files with 24 additions and 0 deletions

24
main.c
View File

@ -1,3 +1,26 @@
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 int
main(int argc, char **argv) { main(int argc, char **argv) {
static char buf[COM_BUF_SIZE]; static char buf[COM_BUF_SIZE];
@ -19,3 +42,4 @@ main(int argc, char **argv) {