Quellcode durchsuchen

:bug: Test exemple prof

Loquicom vor 6 Jahren
Ursprung
Commit
7cdb39a965
3 geänderte Dateien mit 38 neuen und 5 gelöschten Zeilen
  1. 8 0
      file
  2. 6 0
      mysh.c
  3. 24 5
      parser.c

+ 8 - 0
file

@@ -0,0 +1,8 @@
+error.h
+str.h
+parser.h
+command.h
+execute.h
+mysh.h
+0
+0

+ 6 - 0
mysh.c

@@ -233,6 +233,7 @@ int run(CommandTab ct){
         //Si pipe creation d'un fichier commun
         nextpipe = c->next == SHELL_PIPE ;
         if(c->next == SHELL_PIPE && c->output == STDOUT){
+            nextpipe = false;
             bpipe = true;
             //Creation tube
             if(pipe(tube[tubepos]) == ERR){
@@ -293,12 +294,17 @@ int run(CommandTab ct){
             }
         }
         //Fermeture tube
+        printf("B %d\n", bpipe);
         if(bpipe){
             bpipe = false;
             if(close(outfd) == ERR){
                 addperror("Impossible de fermer tube ecriture");
                 return SHELL_FAIL;
             }
+            if(close(c->output) == ERR){
+                addperror("Impossible de fermer tube ecriture");
+                return SHELL_FAIL;
+            }
             c->output = STDOUT;
         }
         //Agit en fonction de la jointure avec la prochaine commande

+ 24 - 5
parser.c

@@ -165,11 +165,13 @@ int set_io(Command* c, char* filename, int redir){
         serrno = SEOPENF;
         return SHELL_ERR;
     }
-    //On se met à la fin du fichier
-    if(lseek(file, 0L, SEEK_END) == ERR){
-        addperror("Impossible de se deplacer dans le fichier");
-        serrno = SEOPENF;
-        return SHELL_ERR;
+    //On se met à la fin du fichier si sortie ou erreur
+    if(redir != SHELLR_IN){
+        if(lseek(file, 0L, SEEK_END) == ERR){
+            addperror("Impossible de se deplacer dans le fichier");
+            serrno = SEOPENF;
+            return SHELL_ERR;
+        }
     }
     //Analyse dans quel descripteur il doit etre mis
     switch(redir){
@@ -429,6 +431,16 @@ int split_command(Command* c, char* cmd){
                 cmd++;
                 delim = '"';
             } 
+            //Cote
+            else if(*cmd == '\''){
+                //Verif que ce n'est pas la fin
+                if(!(*(cmd + 1))){
+                    serrno = SEBADCMD;
+                    return SHELL_ERR;
+                }
+                cmd++;
+                delim = '\'';
+            } 
             //Mot sans guillemet autour
             else {
                 length = 0;
@@ -464,6 +476,13 @@ int split_command(Command* c, char* cmd){
                 length = 0;
                 delim = '"';
             } 
+            //Cote
+            else if(*cmd == '\''){
+                cmd++;
+                deb = cmd;
+                length = 0;
+                delim = '\'';
+            }
             //Mot sans guillemet autour
             else {
                 deb = cmd;