Przeglądaj źródła

:sparkles: Gestion des redirections

Loquicom 6 lat temu
rodzic
commit
d292df9a84
1 zmienionych plików z 19 dodań i 6 usunięć
  1. 19 6
      mysh.c

+ 19 - 6
mysh.c

@@ -216,23 +216,28 @@ int run(CommandTab ct){
     int tube[ct.length][2];
     int tubepos = 0;
     int infd = -1, outfd = -1, errfd = -1;
-    boolean bpipe = false, nextpipe = false;
+    boolean bpipe = false, skippipe = false, skip = false;
     //Parcours les commandes
     for(int i = 0; i < ct.length; i++){
         c = ct.cmd[i];
+        //Si on skip
+        if(skip){
+            skip = false;
+            continue;
+        }
         //Si pipe avant
-        if(nextpipe){
+        if(skippipe){
             //Si fin chaine pipe
             if(c->next != SHELL_PIPE){
-                nextpipe = false;
+                skippipe = false;
             }
             //Passe la commande
             continue;
         }
         //Si pipe creation d'un fichier commun
-        nextpipe = c->next == SHELL_PIPE ;
+        skippipe = c->next == SHELL_PIPE ;
         if(c->next == SHELL_PIPE && c->output == STDOUT){
-            nextpipe = false;
+            skippipe = false;
             bpipe = true;
             //Creation tube
             if(pipe(tube[tubepos]) == ERR){
@@ -305,7 +310,15 @@ int run(CommandTab ct){
             c->output = STDOUT;
         }
         //Agit en fonction de la jointure avec la prochaine commande
-        /*ToDo*/
+        if(c->next == SHELL_IF){
+            if(result != EXIT_SUCCESS){
+                skip = true;
+            }
+        } else if(c->next == SHELL_ELSE){
+            if(result == EXIT_SUCCESS){
+                skip = true;
+            }
+        }
     }
     if(result != EXIT_SUCCESS){
         return SHELL_FAIL;