From 828dd435725ea315abd2ea9875325ee3b17041a9 Mon Sep 17 00:00:00 2001 From: "Nathan P. Reiner" Date: Thu, 15 Dec 2022 18:20:33 +0100 Subject: did this while lecture (builtins, parsing, exec and env by stdlib) --- smash/main.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 smash/main.c (limited to 'smash/main.c') 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); + } +} -- cgit v1.2.3-70-g09d2