summaryrefslogtreecommitdiff
path: root/src/user/app/shell/parser.c
diff options
context:
space:
mode:
authordzwdz2023-08-14 18:51:07 +0200
committerdzwdz2023-08-14 18:51:07 +0200
commit642b5fb0007b64c77d186fcb018d571152ee1d47 (patch)
tree1c466461f3602d306be309a053edae558ef2568e /src/user/app/shell/parser.c
parent8050069c57b729c18c19b1a03ab6e4bf63b4735e (diff)
reorganization: first steps
Diffstat (limited to 'src/user/app/shell/parser.c')
-rw-r--r--src/user/app/shell/parser.c76
1 files changed, 0 insertions, 76 deletions
diff --git a/src/user/app/shell/parser.c b/src/user/app/shell/parser.c
deleted file mode 100644
index ad09348..0000000
--- a/src/user/app/shell/parser.c
+++ /dev/null
@@ -1,76 +0,0 @@
-#include "shell.h"
-#include <ctype.h>
-#include <stdbool.h>
-#include <string.h>
-
-static char skipspace(char **sp) {
- char *s = *sp;
- while (*s && isspace(*s)) s++;
- *sp = s;
- 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++;
- res = s;
- while (*s && *s != '"')
- s++;
- break;
- default:
- res = 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';
- }
-
- *sp = s;
- return res;
-}
-
-int parse(char *s, char **argv, size_t argvlen, struct redir *redir) {
- if (argvlen == 0) return -1;
- size_t argc = 0;
- char *arg;
-
- *argv = NULL;
- redir->stdout = NULL;
- redir->append = false;
-
- while (skipspace(&s)) {
- switch (*s) {
- case '>':
- s++;
- if (*s == '>') {
- s++;
- redir->append = true;
- }
- redir->stdout = parg(&s);
- break;
- default:
- arg = parg(&s);
- argv[argc++] = arg;
- if (argc >= argvlen)
- return -1;
- }
- }
- argv[argc] = NULL;
- return argc;
-}