|
@@ -18,7 +18,7 @@
|
|
|
#include "parser.h"
|
|
|
|
|
|
/* --- Extern --- */
|
|
|
-extern int serrorno;
|
|
|
+extern int serrno;
|
|
|
|
|
|
/* --- Fonctions privées --- */
|
|
|
/**
|
|
@@ -39,14 +39,14 @@ int nb_commands(char* line){
|
|
|
else if(*line == '|'){
|
|
|
//Verif que ce n'est pas le dernier carac
|
|
|
if(*(line + 1) == '\0'){
|
|
|
- serrorno = SEBADEND;
|
|
|
+ serrno = SEBADEND;
|
|
|
return SHELL_ERR;
|
|
|
}
|
|
|
//Si un || on avance de 1 en plus
|
|
|
else if(*(line + 1) == '|'){
|
|
|
//Si à la fin de la chaine
|
|
|
if(*(line + 2) == '\0'){
|
|
|
- serrorno = SEBADEND;
|
|
|
+ serrno = SEBADEND;
|
|
|
return SHELL_ERR;
|
|
|
}
|
|
|
line++;
|
|
@@ -62,7 +62,7 @@ int nb_commands(char* line){
|
|
|
}
|
|
|
//Sinon il doit y avoir un vide pour etre le & du bck ou un > avant
|
|
|
else if(*(line + 1) != '\0' && *(line - 1) != '>'){
|
|
|
- serrorno = SEBADET;
|
|
|
+ serrno = SEBADET;
|
|
|
return SHELL_ERR;
|
|
|
}
|
|
|
}
|
|
@@ -148,7 +148,7 @@ int set_io(Command* c, char* filename, int redir){
|
|
|
file = open(filename, O_CREAT | O_RDWR, S_IRWXU);
|
|
|
if(file == ERR){
|
|
|
perror("Erreur lors de l'ouverture du fichier pour la redirection : ");
|
|
|
- serrorno = SEOPENF;
|
|
|
+ serrno = SEOPENF;
|
|
|
return SHELL_ERR;
|
|
|
}
|
|
|
//Analyse dans quel descripteur il doit etre mis
|
|
@@ -215,7 +215,7 @@ int set_io(Command* c, char* filename, int redir){
|
|
|
}
|
|
|
break;
|
|
|
default :
|
|
|
- serrorno = SEREDIRTYPE;
|
|
|
+ serrno = SEREDIRTYPE;
|
|
|
return SHELL_ERR;
|
|
|
}
|
|
|
//Si on arrive ici tous est ok
|
|
@@ -239,7 +239,7 @@ int set_redirection(Command* c){
|
|
|
if(*buffer == '<'){
|
|
|
//Si il n'y a rien apres
|
|
|
if(!(*(buffer + 1))){
|
|
|
- serrorno = SEBADREDIR;
|
|
|
+ serrno = SEBADREDIR;
|
|
|
return SHELL_ERR;
|
|
|
}
|
|
|
buffer++;
|
|
@@ -250,7 +250,7 @@ int set_redirection(Command* c){
|
|
|
else if (*buffer == '>'){
|
|
|
//Si il n'y a rien apres
|
|
|
if(!(*(buffer + 1))){
|
|
|
- serrorno = SEBADREDIR;
|
|
|
+ serrno = SEBADREDIR;
|
|
|
return SHELL_ERR;
|
|
|
} else {
|
|
|
buffer++;
|
|
@@ -258,7 +258,7 @@ int set_redirection(Command* c){
|
|
|
if(*buffer == '>'){
|
|
|
//Si il n'y a rien apres
|
|
|
if(!(*(buffer + 1))){
|
|
|
- serrorno = SEBADREDIR;
|
|
|
+ serrno = SEBADREDIR;
|
|
|
return SHELL_ERR;
|
|
|
} else {
|
|
|
buffer++;
|
|
@@ -266,7 +266,7 @@ int set_redirection(Command* c){
|
|
|
if(*buffer == '&'){
|
|
|
//Si il n'y a rien apres
|
|
|
if(!(*(buffer + 1))){
|
|
|
- serrorno = SEBADREDIR;
|
|
|
+ serrno = SEBADREDIR;
|
|
|
return SHELL_ERR;
|
|
|
}
|
|
|
buffer++;
|
|
@@ -282,7 +282,7 @@ int set_redirection(Command* c){
|
|
|
else if(*buffer == '&'){
|
|
|
//Si il n'y a rien apres
|
|
|
if(!(*(buffer + 1))){
|
|
|
- serrorno = SEBADREDIR;
|
|
|
+ serrno = SEBADREDIR;
|
|
|
return SHELL_ERR;
|
|
|
}
|
|
|
redir = SHELLRE_ALL;
|
|
@@ -300,7 +300,7 @@ int set_redirection(Command* c){
|
|
|
buffer++;
|
|
|
//Si il n'y a rien apres
|
|
|
if(!(*(buffer + 1))){
|
|
|
- serrorno = SEBADREDIR;
|
|
|
+ serrno = SEBADREDIR;
|
|
|
return SHELL_ERR;
|
|
|
} else {
|
|
|
buffer++;
|
|
@@ -309,7 +309,7 @@ int set_redirection(Command* c){
|
|
|
buffer++;
|
|
|
//Si il n'y a rien apres
|
|
|
if(!(*(buffer + 1))){
|
|
|
- serrorno = SEBADREDIR;
|
|
|
+ serrno = SEBADREDIR;
|
|
|
return SHELL_ERR;
|
|
|
}
|
|
|
redir = SHELLR_ERR;
|
|
@@ -340,7 +340,7 @@ int set_redirection(Command* c){
|
|
|
return finCmd + 1;
|
|
|
}
|
|
|
//Sinon on est dans un redirection non terminée
|
|
|
- serrorno = SEBADCMD;
|
|
|
+ serrno = SEBADCMD;
|
|
|
return SHELL_ERR;
|
|
|
}
|
|
|
//Regarde si le nom du fichier est entre ""
|
|
@@ -363,7 +363,7 @@ int set_redirection(Command* c){
|
|
|
}
|
|
|
//Si fin de la commande et guillemet alors erreur
|
|
|
if(!(*buffer) && guillemet){
|
|
|
- serrorno = SEBADCMD;
|
|
|
+ serrno = SEBADCMD;
|
|
|
return SHELL_ERR;
|
|
|
}
|
|
|
//Retire guillement si besoin
|
|
@@ -413,7 +413,7 @@ int split_command(Command* c, char* cmd){
|
|
|
if(*cmd == '"'){
|
|
|
//Verif que ce n'est pas la fin
|
|
|
if(!(*(cmd + 1))){
|
|
|
- serrorno = SEBADCMD;
|
|
|
+ serrno = SEBADCMD;
|
|
|
return SHELL_ERR;
|
|
|
}
|
|
|
cmd++;
|
|
@@ -542,13 +542,13 @@ int parse_command(Command* c){
|
|
|
nbWildcard = wildcard(c->argv[i], nbWildcard, wildcardTab);
|
|
|
//Verif retour
|
|
|
if(nbWildcard == ERR){
|
|
|
- serrorno = SEWC;
|
|
|
+ serrno = SEWC;
|
|
|
return SHELL_ERR;
|
|
|
}
|
|
|
//Ajoute les wildcard dans argv (le +1 est la pour garder le NULL à la fin)
|
|
|
c->argv = insert_array(i, c->argv, c->argc + 1, wildcardTab, nbWildcard, &res);
|
|
|
if(res == ERR){
|
|
|
- serrorno = SEADDWC;
|
|
|
+ serrno = SEADDWC;
|
|
|
return SHELL_ERR;
|
|
|
}
|
|
|
c->argc = res - 1; //On ne compte pas le NULL final
|