summaryrefslogtreecommitdiff
path: root/userland/minibox/utilities/sh/sh.c
diff options
context:
space:
mode:
Diffstat (limited to 'userland/minibox/utilities/sh/sh.c')
-rw-r--r--userland/minibox/utilities/sh/sh.c26
1 files changed, 24 insertions, 2 deletions
diff --git a/userland/minibox/utilities/sh/sh.c b/userland/minibox/utilities/sh/sh.c
index 433c2e1..1505de3 100644
--- a/userland/minibox/utilities/sh/sh.c
+++ b/userland/minibox/utilities/sh/sh.c
@@ -145,8 +145,30 @@ void get_line(struct sb *s) {
}
int sh_main(int argc, char **argv) {
- (void)argc;
- (void)argv;
+ if (argc > 1) {
+ int fd = open(argv[1], O_RDONLY, 0);
+ char buffer[8192];
+ struct sb file;
+ sb_init(&file);
+
+ for (;;) {
+ int rc = read(fd, buffer, 8192);
+ if (0 == rc) {
+ break;
+ }
+ sb_append_buffer(&file, buffer, rc);
+ }
+
+ close(fd);
+ struct TOKEN *h = lex(SB_TO_SV(file));
+ struct AST *ast_h = generate_ast(h);
+ execute_ast(ast_h);
+ free_tokens(h);
+ free_ast(ast_h);
+ sb_free(&file);
+ return 0;
+ }
+
for (;;) {
char buffer[256];
printf("%s : ", getcwd(buffer, 256));