Browse Source

:building_construction: La valeur bck lié à la chaine de commande

Loquicom 6 years ago
parent
commit
c9b154d742
3 changed files with 3 additions and 8 deletions
  1. 1 1
      mysh.c
  2. 1 6
      parser.c
  3. 1 1
      parser.h

+ 1 - 1
mysh.c

@@ -39,7 +39,7 @@ int main(int argc, char* argv[]) {
         for(int j = 0; j < c->argc; j++){
             printf("    Argument %d : %s\n", j, c->argv[j]);
         }
-        printf("Commande en fond : %d\n\n", c->bck);
+        printf("Commande en fond : %d\n\n", ct.bck);
     }
     //Supprime
     clean_command(&ct);

+ 1 - 6
parser.c

@@ -114,7 +114,6 @@ int get_command(Command* c, char* line){
     c->error = STDERR;
     c->erase[0] = false;
     c->erase[1] = false;
-    c->bck = false;
     //Trim et supprime l'ancienne chaine
     old = c->cmd;
     c->cmd = rtrim(c->cmd, ' ');
@@ -436,11 +435,6 @@ int split_command(Command* c, char* cmd){
         c->argv[i] = malloc(sizeof(char) * length);
         strncpy(c->argv[i++], deb, length);  
     }
-    //Regarde si le caractère de fin est &
-    if(*cmd == '&'){
-        //Alors en fond
-        c->bck = true;
-    }
     //Set la dernière case du tableau à null
     c->argv[i] = NULL;
     return SHELL_OK;
@@ -460,6 +454,7 @@ int parse_line(CommandTab* ct, char* line){
     //Initialisation structure
     ct->cmd = malloc(sizeof(Command*) * compteur);
     ct->length = compteur;
+    ct->bck = line[strlen(line) - 1] == '&';
     //Recupération de chaque commande
     for(int i = 0; i < compteur; i++){
         ct->cmd[i] = malloc(sizeof(Command));

+ 1 - 1
parser.h

@@ -22,13 +22,13 @@ typedef struct{
     int output; //Descripteur de fichier de sortie
     int error; //Descripteur de fihier d'erreur
     boolean erase[2]; //Si on efface le fichier
-    boolean bck; //En fond ou non
     int next; //Lien avec la prochaine commande
 }Command;
 
 typedef struct{
     Command** cmd; //Tableau avec toutes les commandes
     int length; //Taille du tableau
+    boolean bck; //Si l'ensemble de commande se fait en fond
 }CommandTab;
 
 /* --- Fonctions --- */