From e95ab7393a267f15fb7be915efb2538382bbf838 Mon Sep 17 00:00:00 2001 From: dzwdz Date: Sun, 10 Oct 2021 15:38:12 +0000 Subject: init/shell: basic argument splitting --- src/init/shell.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'src/init/shell.c') diff --git a/src/init/shell.c b/src/init/shell.c index d61f46f..12382e0 100644 --- a/src/init/shell.c +++ b/src/init/shell.c @@ -6,6 +6,17 @@ static int tty_fd = 0; // TODO put in stdlib +static char *split(char *base) { + while (*base) { + if (*base == ' ' || *base == '\t') { + *base++ = '\0'; + return base; + } + base++; + } + return NULL; +} + static int readline(char *buf, size_t max) { char c; size_t pos = 0; @@ -36,9 +47,12 @@ static int readline(char *buf, size_t max) { void shell_loop(void) { static char cmd[256]; + char *args; + for (;;) { printf(PROMPT); readline(cmd, 256); - printf(" %s\n", cmd); + args = split(cmd); + printf(" %s | %s\n", cmd, args); } } -- cgit v1.2.3