diff options
Diffstat (limited to 'smash/main.c')
| -rw-r--r-- | smash/main.c | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/smash/main.c b/smash/main.c index 48aaed6..645f4eb 100644 --- a/smash/main.c +++ b/smash/main.c @@ -1,10 +1,12 @@ #include "exec.h" #include "comment.h" +#include "env.h" #include "../lib/sys/io.h" #include "../lib/cstr/cstr.h" #include "../lib/sys/dup2.h" #include "../lib/sys/exit.h" +#include "../lib/malloc/malloc.h" #include "../lib/io/io.h" #include "../lib/sys/errno.h" @@ -53,14 +55,17 @@ int io_getline(int fd, char *linebuf) return size; } -int main(int argc, char *argv[], char *envp[]) +int main(int argc, char *argv[]) { char prompt[] = "$ "; i64 line_length; int fd = STDIN_FD; char linebuf[BUFSIZ]; + char *line; - if (argc == 2) { + init_arg_env(argc, (const char**)argv); + + if (argc > 1) { fd = open(argv[1], OPEN_READ_ONLY, 0); if (fd < 0) { @@ -80,11 +85,14 @@ int main(int argc, char *argv[], char *envp[]) } remove_comment(linebuf); - line_length = cstr_length(linebuf); + line = new_line_and_replace_vars(linebuf, BUFSIZ); + line_length = cstr_length(line); if (line_length > 0) { - exec(linebuf); + exec(line); } + + free(line); } if (fd != STDOUT_FD) |