aboutsummaryrefslogtreecommitdiff
path: root/smash/main.c
diff options
context:
space:
mode:
authorNathan P. Reiner <nathan@nathanreiner.xyz>2022-12-15 18:20:33 +0100
committerNathan P. Reiner <nathan@nathanreiner.xyz>2022-12-15 18:20:33 +0100
commit828dd435725ea315abd2ea9875325ee3b17041a9 (patch)
tree72d80411d5cecc8758fc87867521374e90caa44d /smash/main.c
parent7536d000ac9a5188378f2749ecfd7f0ccb437573 (diff)
did this while lecture (builtins, parsing, exec and env by stdlib)
Diffstat (limited to 'smash/main.c')
-rw-r--r--smash/main.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/smash/main.c b/smash/main.c
new file mode 100644
index 0000000..0b3dc20
--- /dev/null
+++ b/smash/main.c
@@ -0,0 +1,26 @@
+#include "exec.h"
+
+#include "../lib/sys/io.h"
+#include "../lib/cstr/cstr.h"
+
+#define BUFSIZ 1024
+
+void clear_buf(char *buf)
+{
+ for (int i = 0; i < BUFSIZ; ++i)
+ buf[i] = 0;
+}
+
+int main(int argc, char *argv[], char *envp[])
+{
+ char buf[BUFSIZ] = {0};
+ char prompt[] = "$ ";
+
+ while (1) {
+ write(STDOUT_FD, prompt, cstr_length(prompt));
+ read(STDIN_FD, buf, 1024);
+ buf[cstr_length(buf) - 1] = 0;
+ exec(buf);
+ clear_buf(buf);
+ }
+}