From 3bd3984e92fdfb529c37b31c6f0570abab1ed54e Mon Sep 17 00:00:00 2001 From: WlodekM Date: Fri, 14 Feb 2025 19:12:47 +0200 Subject: initial commit; beginning work on smolsh --- progs/shel/shel.c | 42 ++++++++++++++++++++++++++++++++++++++++++ progs/touch/touch.c | 13 +++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 progs/shel/shel.c create mode 100644 progs/touch/touch.c (limited to 'progs') diff --git a/progs/shel/shel.c b/progs/shel/shel.c new file mode 100644 index 0000000..f375250 --- /dev/null +++ b/progs/shel/shel.c @@ -0,0 +1,42 @@ +#include +#include +#include +#include +#include + +void parseInput(char *input, char *command, char *argv) { + bool reachedArgv = false; + char arg[32] = {0}; + int idx = 0; + int argvIdx = 1; + + for (int i = 0; i < sizeof(input); i++) + { + if (reachedArgv) { + arg[idx] = input[i]; + idx++; + continue; + } + if (input[i] == ' ') { + arg[idx] == '\0'; + strcpy(command, arg); + reachedArgv = true; + memset(arg, 0, sizeof(arg)); + idx++; + continue; + } + arg[idx] = input[i]; + idx++; + } + +} + +int main() { + char input[255] = {0}; + char command[128] = {0}; + char *argv[32] = {0}; + char *env[32] = {"PATH=/bin"}; + char path[128] = "/"; + + parseInput(input, command, argv); +} \ No newline at end of file diff --git a/progs/touch/touch.c b/progs/touch/touch.c new file mode 100644 index 0000000..815dae3 --- /dev/null +++ b/progs/touch/touch.c @@ -0,0 +1,13 @@ +#include +#include +#include +#include + +int main(int argc, char *argv[]) { + if (!argv[1]) { + write(1, "you IDIOT, you forgot to include the file name, MORON\n", 55); + exit(1); + } + int fd2 = open(argv[1], O_RDWR | O_CREAT, S_IRUSR | S_IRGRP | S_IROTH); + exit(0); +} \ No newline at end of file -- cgit 1.4.1-2-gfad0