aboutsummaryrefslogtreecommitdiff
path: root/smash/main.c
diff options
context:
space:
mode:
authorNathan Reiner <nathan@nathanreiner.xyz>2023-02-09 18:05:28 +0100
committerNathan Reiner <nathan@nathanreiner.xyz>2023-02-09 18:05:28 +0100
commit799d930c2540933c23a1b6ba28e8e5e4f3bccb64 (patch)
tree7a714abcafc48060b832e7b33c64ab8e1b29a559 /smash/main.c
parent9153b4062c7b6db6119e035dc5e53184aac9fa3a (diff)
add variable system via env
Diffstat (limited to 'smash/main.c')
-rw-r--r--smash/main.c16
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)