From e8aedb0ef4f73961a98a1505527dc9ec8780a0d5 Mon Sep 17 00:00:00 2001 From: dzwdz Date: Wed, 27 Jul 2022 21:09:31 +0200 Subject: user/shell: basic shell script support --- src/user/app/shell/parser.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'src/user/app/shell/parser.c') diff --git a/src/user/app/shell/parser.c b/src/user/app/shell/parser.c index bd70350..878202d 100644 --- a/src/user/app/shell/parser.c +++ b/src/user/app/shell/parser.c @@ -13,11 +13,16 @@ static char skipspace(char **sp) { return *s; } +static bool isspecial(char c) { + return c == '>' || c == '#'; +} + static char *parg(char **sp) { char *s = *sp; char *res = NULL; if (skipspace(&s)) { + // TODO incorrectly handles strings like a"b" switch (*s) { case '"': s++; @@ -27,8 +32,13 @@ static char *parg(char **sp) { break; default: res = s; - while (*s && !isspace(*s) && *s != '>') + while (*s && !isspace(*s) && !isspecial(*s)) s++; + if (*s == '#') { + *s = '\0'; /* end parsing early */ + if (res == s) /* don't output an empty arg */ + res = NULL; + } break; } if (*s) *s++ = '\0'; -- cgit v1.2.3