diff options
author | WlodekM <[email protected]> | 2025-02-14 19:35:57 +0200 |
---|---|---|
committer | WlodekM <[email protected]> | 2025-02-14 19:35:57 +0200 |
commit | 778b24d74f4763f46ea874a6777e39b794006c44 (patch) | |
tree | 7f9b131d0bce7e3c7898dbe18fd69cccd292afe7 /progs/shel | |
parent | a8cde132b0f2ff7d6c7a3616ad3e75a70af072b9 (diff) |
smolshel - works
Diffstat (limited to 'progs/shel')
-rw-r--r-- | progs/shel/shel.c | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/progs/shel/shel.c b/progs/shel/shel.c index f375250..e3221f4 100644 --- a/progs/shel/shel.c +++ b/progs/shel/shel.c @@ -1,34 +1,48 @@ #include <unistd.h> #include <stdlib.h> +#include <stdio.h> #include <sys/wait.h> #include <stdbool.h> #include <string.h> -void parseInput(char *input, char *command, char *argv) { +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++) + for (int i = 0; i < strlen(input); i++) { + char *a = {&(input[i])}; if (reachedArgv) { + if (input[i] == ' ') { + arg[idx] = '\0'; + argv[argvIdx] = strdup(arg); + memset(arg, 0, sizeof(arg)); + argvIdx++; + idx = 0; + continue; + } arg[idx] = input[i]; idx++; continue; } if (input[i] == ' ') { - arg[idx] == '\0'; + arg[idx] = '\0'; strcpy(command, arg); reachedArgv = true; memset(arg, 0, sizeof(arg)); - idx++; + idx = 0; continue; } arg[idx] = input[i]; idx++; } - + argv[0] = command; + if (reachedArgv) { + arg[idx] = '\0'; + argv[argvIdx] = strdup(arg); + } } int main() { @@ -38,5 +52,7 @@ int main() { char *env[32] = {"PATH=/bin"}; char path[128] = "/"; + strcpy(input, "/bin/echo meow"); parseInput(input, command, argv); + execve(command, argv, 0); } \ No newline at end of file |