summary refs log tree commit diff
path: root/progs/shel/shel.c
diff options
context:
space:
mode:
Diffstat (limited to 'progs/shel/shel.c')
-rw-r--r--progs/shel/shel.c26
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