Loquicom 6 лет назад
Родитель
Сommit
26afc4c5e0
2 измененных файлов с 61 добавлено и 8 удалено
  1. 29 4
      parser.c
  2. 32 4
      parser.h

+ 29 - 4
parser.c

@@ -16,6 +16,11 @@
 #include "parser.h"
 
 /* --- Fonctions privées --- */
+/**
+ * Indique le nombre de commande dans une ligne
+ * @param char* La ligne à analyser
+ * @return int Le nombre de commande
+ */
 int nb_commands(char* line){
     //Initialisation variable
     int compteur = 0;
@@ -61,10 +66,11 @@ int nb_commands(char* line){
 }
 
 /**
- * Recup la 1er commande
- * @param c Structure commande à initialiser
- * @param line Ligne avec la commande
- * @return int Le décallage à effectuer dans line
+ * Recup la 1er commande d'une chaine de caractère pour initialiser une
+ * structure Command
+ * @param Command* Structure commande à initialiser
+ * @param char* Ligne avec la commande
+ * @return int Le décallage à effectuer dans ligne
  */
 int get_command(Command* c, char* line){
     //Declaration variable
@@ -120,6 +126,13 @@ int get_command(Command* c, char* line){
     return length + separator;
 }
 
+/**
+ * Parametre les fichiers d'entrées et de sorties d'une commande
+ * @param Command* La structure de la commande
+ * @param char* Le nom du fichier
+ * @param int Le type de redirection (constante SHELLR)
+ * @return int SHELL_OK si réussite, SHELL_ERR sinon
+ */
 int set_io(Command* c, char* filename, int redir){
     //Declaration variable
     int file;
@@ -199,6 +212,11 @@ int set_io(Command* c, char* filename, int redir){
     return SHELL_OK;
 }
 
+/**
+ * Parametre les redirection d'une commande
+ * @param Command* La commande à analyser
+ * @return int SHELL_OK si réussite, SHELL_ERR sinon
+ */
 int set_redirection(Command* c){
     boolean first = true, guillemet = false;
     char* deb, * file, * buffer = c->cmd + 1;
@@ -354,6 +372,13 @@ int set_redirection(Command* c){
     return finCmd + 1;
 }
 
+/**
+ * Sépare une commande en chaine de caractere en un tableau contenant chaque
+ * argument
+ * @param Command* La structure d'accueil du resultat
+ * @param char* La commande à découper (sans les redirections)
+ * @return int SHELL_OK si réussite, SHELL_ERR sinon
+ */
 int split_command(Command* c, char* cmd){
     //Declaration variable
     char* deb = cmd;

+ 32 - 4
parser.h

@@ -13,7 +13,7 @@
 #include "str.h"
 
 /* --- Structure --- */
-typedef struct{
+typedef struct {
     char* cmd; //La commande en string
     char* name; //Le nom de la commande
     int argc; //Le nombre d'argument
@@ -23,18 +23,46 @@ typedef struct{
     int error; //Descripteur de fihier d'erreur
     boolean erase[2]; //Si on efface le fichier
     int next; //Lien avec la prochaine commande
-}Command;
+} Command;
 
-typedef struct{
+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;
+} CommandTab;
 
 /* --- Fonctions --- */
+
+/**
+ * Parse une ligne de commande (separe les commandes et repere le lien entre elle)
+ * @param CommandTab* La structure contenant le resultat
+ * @param char* La ligne de commande à parser
+ * @return int SHELL_OK si réussite, SHELL_ERR sinon
+ */
 int parse_line(CommandTab*, char*);
+
+/**
+ * Parse une commande (repere changement entrée sortie, wildcard, découpe les
+ * arguments)
+ * @param Command* La structure commande à parser (initialisée dans une 
+ * CommandTab par la fonction parse_line)
+ * @return int SHELL_OK si réussite, SHELL_ERR sinon
+ */
 int parse_command(Command*);
+
+/**
+ * Parse toutes les commandes d'un CommandTab
+ * @param CommandTab* La structure contenant les commandes initialisée dans
+ * la fonctions parse_line)
+ * @return int SHELL_OK si réussite, SHELL_FAIL si le parse d'une des commandes
+ * échoue
+ */
 int parse_all_command(CommandTab*);
+
+/**
+ * Vide un structure CommandTab
+ * @param CommandTab* La structure à nettoyer
+ */
 void clean_command(CommandTab*);
 
 #endif /* PARSER_H */