From 799d930c2540933c23a1b6ba28e8e5e4f3bccb64 Mon Sep 17 00:00:00 2001 From: Nathan Reiner Date: Thu, 9 Feb 2023 18:05:28 +0100 Subject: add variable system via env --- smash/main.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'smash/main.c') 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) -- cgit v1.2.3-70-g09d2