1
0
mirror of https://gitlab.com/klmp200/fish.git synced 2024-11-22 00:33:20 +00:00

Merge branch 'sli' into 'master'

0 leak memory :D

See merge request !5
This commit is contained in:
Antoine Bartuccio 2017-05-17 23:44:49 +00:00
commit 2ea166e43d
5 changed files with 35 additions and 22 deletions

View File

@ -44,8 +44,10 @@ include_directories(
"${source_dir}/googlemock/include"
)
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_FLAGS "-Wall -Werror -pedantic -fpic -Wextra -Wshadow")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FALGS} -g")
set(SOURCE_FILES fish_shell/main.c fish_shell/fish_types.h fish_shell/fish_core.h fish_shell/fish_core.c fish_shell/fish_commands.c fish_shell/fish_commands.h fish_shell/fish_globbing.c fish_shell/fish_globbing.h fish_shell/fish_utils.c fish_shell/fish_utils.h)
add_executable(fish ${SOURCE_FILES})

View File

@ -37,12 +37,12 @@ int fishCd(WordArray *args) {
perror("fish");
}
}
return 0;
freeWordArray(args);
return EXIT_SUCCESS;
}
int fishHelp(WordArray *args) {
int i;
args->size = args->size;
printf("Bartuccio Antoine, Amalvy Arthur, Yann Chevanton\n");
printf("Tape tes putains de noms de programmes et tes arguments de merde et tabasse ENTER !\n");
printf("Les commandes suivantes sont internes :\n");
@ -50,12 +50,13 @@ int fishHelp(WordArray *args) {
printf("\t%s\n", builtinCommandsStr[i]);
}
printf("Et sinon pour le reste, RTFM !");
return 0;
freeWordArray(args);
return EXIT_SUCCESS;
}
int fishExit(WordArray *args) {
args->size = args->size;
exit(EXIT_SUCCESS);
freeWordArray(args);
return EXIT_SIGNAL;
}

View File

@ -27,7 +27,7 @@ void fishLoop(Settings * settings){
free(line);
} while(status);
} while(status != EXIT_SIGNAL);
}
int countSeparators(char *string, char *separators) {
@ -145,6 +145,7 @@ int fishLoad(WordArray *array) {
} while (!WIFEXITED(status) && !WIFSIGNALED(status));
if (status) fprintf(stderr, "%s\n", getInsult());
}
freeWordArray(array);
return status;
}
@ -152,24 +153,32 @@ int fishExecute(WordList *list) {
WordList *splited = NULL;
shell_operator op = NONE;
WordArray *array = NULL;
int signal = 1;
splited = parseWordList(list, &op);
array = wordListToWordArray(list);
signal = loadRightCommand(array);
if (signal == EXIT_SIGNAL){
if (splited != NULL) freeWordList(splited);
if (array != NULL) freeWordArray(array);
return signal;
}
switch (op) {
case AND:
if (!loadRightCommand(array)) fishExecute(splited);
else freeWordList(splited);
if (!signal) signal = fishExecute(splited);
else {
if (splited != NULL) freeWordList(splited);
}
break;
case OR:
loadRightCommand(array);
fishExecute(splited);
signal = fishExecute(splited);
break;
default:
loadRightCommand(array);
break;
}
return signal;
return 1;
}
int loadRightCommand(WordArray *array){
@ -185,12 +194,12 @@ int loadRightCommand(WordArray *array){
WordList * parseWordList(WordList *list, shell_operator *an_operator) {
char *op_str[] = {
(char*) "&&",
(char*) "||"
(char*) "||",
(char*) "&&"
};
shell_operator op[] = {
AND,
OR
OR,
AND
};
WordList *newList = NULL;
int max = sizeof(op_str) / sizeof(char*);

View File

@ -5,6 +5,8 @@
#ifndef FISH_FISH_TYPES_H
#define FISH_FISH_TYPES_H
#define EXIT_SIGNAL -100
/* Custom types */
typedef enum {

View File

@ -30,7 +30,7 @@ char *getInsult(){
int picked = 0;
char *insults[] = {
(char *) "Apprend à écrire crétin !",
(char *) "Bolos !",
(char *) "Boloss !",
(char *) "Mois aussi je sais écrire de la merde, pourtant je le fait pas !",
(char *) "Oh ! Une erreur ! Comme ta vie en fait...",
(char *) "Nul !",
@ -110,12 +110,11 @@ WordArray *wordListToWordArray(WordList *list) {
if (array->words == NULL) crash();
while (current != NULL){
array->words[i] = current->word;
current->word = NULL;
array->words[i] = strdup(current->word);
current = current->next;
i++;
}
array->words[i] = NULL;
array->words[array->size] = NULL;
}
freeWordList(list);
@ -125,7 +124,7 @@ WordArray *wordListToWordArray(WordList *list) {
WordList *wordArrayToWordList(WordArray *array) {
WordList *list = createWordList();
int i = 0;
int i;
for (i=0; i<array->size; i++)
addWordList(list, array->words[i]);