summaryrefslogtreecommitdiff
path: root/src/user
diff options
context:
space:
mode:
Diffstat (limited to 'src/user')
-rw-r--r--src/user/app/shell/parser.c11
-rw-r--r--src/user/app/shell/shell.c4
-rw-r--r--src/user/app/shell/shell.h8
3 files changed, 17 insertions, 6 deletions
diff --git a/src/user/app/shell/parser.c b/src/user/app/shell/parser.c
index 878202d..31c45d1 100644
--- a/src/user/app/shell/parser.c
+++ b/src/user/app/shell/parser.c
@@ -48,19 +48,24 @@ static char *parg(char **sp) {
return res;
}
-int parse(char *s, char **argv, size_t argvlen, char **redir) {
+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 = NULL;
+ redir->stdout = NULL;
+ redir->append = false;
while (skipspace(&s)) {
switch (*s) {
case '>':
s++;
- *redir = parg(&s);
+ if (*s == '>') {
+ s++;
+ redir->append = true;
+ }
+ redir->stdout = parg(&s);
break;
default:
arg = parg(&s);
diff --git a/src/user/app/shell/shell.c b/src/user/app/shell/shell.c
index 7367a4b..7f892c0 100644
--- a/src/user/app/shell/shell.c
+++ b/src/user/app/shell/shell.c
@@ -34,7 +34,7 @@ static void execp(char **argv) {
static void run(char *cmd) {
#define ARGV_MAX 16
char *argv[ARGV_MAX];
- char *redir;
+ struct redir redir;
int ret = parse(cmd, argv, ARGV_MAX, &redir);
if (ret < 0) {
@@ -58,7 +58,7 @@ static void run(char *cmd) {
return;
}
- if (redir && !freopen(redir, "w", stdout)) {
+ if (redir.stdout && !freopen(redir.stdout, redir.append ? "a" : "w", stdout)) {
// TODO stderr
exit(0);
}
diff --git a/src/user/app/shell/shell.h b/src/user/app/shell/shell.h
index 986ce22..4c7eeb3 100644
--- a/src/user/app/shell/shell.h
+++ b/src/user/app/shell/shell.h
@@ -1,4 +1,10 @@
#pragma once
+#include <stdbool.h>
#include <stddef.h>
-int parse(char *str, char **argv, size_t argvlen, char **redir);
+struct redir {
+ const char *stdout;
+ bool append;
+};
+
+int parse(char *s, char **argv, size_t argvlen, struct redir *redir);