|
@@ -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;
|