summaryrefslogtreecommitdiff
path: root/src/user/app/shell/parser.c
diff options
context:
space:
mode:
authordzwdz2022-07-27 21:09:31 +0200
committerdzwdz2022-07-27 21:09:31 +0200
commite8aedb0ef4f73961a98a1505527dc9ec8780a0d5 (patch)
tree50cdabeab0f66c66bfeb00259da0caccb2dee65e /src/user/app/shell/parser.c
parentba7aecffc3b52b39c27558b693ed4026298b58c9 (diff)
user/shell: basic shell script support
Diffstat (limited to 'src/user/app/shell/parser.c')
-rw-r--r--src/user/app/shell/parser.c12
1 files changed, 11 insertions, 1 deletions
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';