diff options
| author | Nathan P. Reiner <nathan@nathanreiner.xyz> | 2022-12-16 09:33:11 +0100 |
|---|---|---|
| committer | Nathan P. Reiner <nathan@nathanreiner.xyz> | 2022-12-16 09:33:11 +0100 |
| commit | 10c4a9af585869da2d26c136c49cc79f2ca45e50 (patch) | |
| tree | 9ac955df56f1bf3e245312f5e370bd287f32d0bf | |
| parent | d29b2c8af98f34745eca362fb1d65002170e7156 (diff) | |
implement wstdf
| -rw-r--r-- | smash/Makefile | 2 | ||||
| -rw-r--r-- | smash/builtin.c | 13 | ||||
| -rw-r--r-- | smash/exec.c | 6 | ||||
| -rw-r--r-- | smash/main.c | 8 | ||||
| -rwxr-xr-x | smash/smash | bin | 49496 -> 53248 bytes |
5 files changed, 19 insertions, 10 deletions
diff --git a/smash/Makefile b/smash/Makefile index 8a0dcee..7012bdd 100644 --- a/smash/Makefile +++ b/smash/Makefile @@ -13,4 +13,4 @@ unit_test_builtin: ./test all: - gcc main.c exec.c parser.c builtin.c ../lib/avl_tree/avl_tree.c ../lib/cstr/cstr.c ../lib/malloc/malloc.c ../lib/sys/start.S -static -nostdlib -fno-stack-protector -Wno-implicit-function-declaration -o smash -DVARIABLES_UNIT_TEST -g + gcc main.c exec.c parser.c builtin.c ../lib/io/io.c ../lib/avl_tree/avl_tree.c ../lib/cstr/cstr.c ../lib/malloc/malloc.c ../lib/sys/start.S -static -nostdlib -fno-stack-protector -Wno-implicit-function-declaration -o smash -DVARIABLES_UNIT_TEST -g diff --git a/smash/builtin.c b/smash/builtin.c index 63a4013..a5bbd17 100644 --- a/smash/builtin.c +++ b/smash/builtin.c @@ -4,6 +4,7 @@ #include "../lib/cstr/cstr.h" #include "../lib/sys/io.h" #include "../lib/sys/chdir.h" +#include "../lib/io/io.h" u64 __find_builtin_function_by_name(const char *name); @@ -32,7 +33,7 @@ int __builtin_fn_exit(int argc, const char **argv) int __builtin_fn_cd(int argc, const char **argv) { if (argc != 2) { - write(STDOUT_FD, "path missing\n", 9); + wstd("cd [path]\n"); return -1; } @@ -41,8 +42,14 @@ int __builtin_fn_cd(int argc, const char **argv) int __builtin_fn_help(int argc, const char **argv) { - write(STDOUT_FD, "This is the help page...\n", 25); - write(STDOUT_FD, "TODO: help page\n", 16); + wstdf("%s\n%s\n\n%s\n%s\n\n%s\n", + "Welcome to smash [ \033[1msma\033[0mll \033[1msh\033[0mell ].", + "\033[2mDon't blame me if it doesn't work, it's definitly a skill issue!\033[0m", + "Syntax:", + " command [args] | command [args] | ... | command [args]", + "Author Nathan P. Reiner <nathan@nathanreiner.xyz>" + ); + return 0; } diff --git a/smash/exec.c b/smash/exec.c index 3b62f41..cd18ca4 100644 --- a/smash/exec.c +++ b/smash/exec.c @@ -6,9 +6,9 @@ #include "../lib/sys/pipe.h" #include "../lib/sys/dup2.h" #include "../lib/sys/close.h" -#include "../lib/sys/io.h" #include "../lib/sys/exit.h" #include "../lib/cstr/cstr.h" +#include "../lib/io/io.h" #include "parser.h" #include "builtin.h" @@ -58,9 +58,7 @@ void exec(char *line) close(pipefd[1][PIPE_IN]); execve(argv[0], argv, envp); - write(STDOUT_FD, "command not found: ", 19); - write(STDOUT_FD, argv[0], cstr_length(argv[0])); - write(STDOUT_FD, "\n", 1); + wstdf("command not found: %s\n", argv[0]); exit(-1); } diff --git a/smash/main.c b/smash/main.c index 0b3dc20..2422363 100644 --- a/smash/main.c +++ b/smash/main.c @@ -15,12 +15,16 @@ int main(int argc, char *argv[], char *envp[]) { char buf[BUFSIZ] = {0}; char prompt[] = "$ "; + u64 line_length; while (1) { write(STDOUT_FD, prompt, cstr_length(prompt)); read(STDIN_FD, buf, 1024); - buf[cstr_length(buf) - 1] = 0; - exec(buf); + line_length = cstr_length(buf); + if (line_length > 1) { + buf[line_length - 1] = 0; + exec(buf); + } clear_buf(buf); } } diff --git a/smash/smash b/smash/smash Binary files differindex c444927..c8fedc1 100755 --- a/smash/smash +++ b/smash/smash |