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

Perfect logic is perfect

This commit is contained in:
Antoine Bartuccio 2017-05-26 18:34:30 +02:00
parent ace3a81850
commit 17d9364f37
2 changed files with 18 additions and 11 deletions

View File

@ -33,9 +33,11 @@ builtinCommand **getBuiltinCommands(){
int fishCd(WordArray *args) {
if (args->size < 2){
fprintf(stderr, "fish: Où sont les arguments de ta commande \"cd\" connard ?!\n");
return EXIT_FAILURE;
} else {
if (chdir(args->words[1]) != 0){
perror("fish");
return EXIT_FAILURE;
}
}
freeWordArray(args);

View File

@ -156,33 +156,38 @@ int fishExecute(WordList *list) {
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:
signal = fishExecute(list);
if (!signal) signal = fishExecute(splited);
else {
if (splited != NULL) freeWordList(splited);
splited = NULL;
}
break;
case REVERSE_AND:
if (signal) signal = fishExecute(splited);
signal = fishExecute(list);
if (signal && signal != EXIT_SIGNAL) signal = fishExecute(splited);
else {
if (splited != NULL) freeWordList(splited);
splited = NULL;
}
break;
case OR:
signal = fishExecute(splited);
signal = fishExecute(list);
if (signal != EXIT_SIGNAL) signal = fishExecute(splited);
break;
default:
break;
array = wordListToWordArray(list);
signal = loadRightCommand(array);
splited = NULL;
}
if (signal == EXIT_SIGNAL){
if (splited != NULL) freeWordList(splited);
if (array != NULL) freeWordArray(array);
}
return signal;
}