1
0
mirror of https://gitlab.com/klmp200/fish.git synced 2024-11-25 02:24:21 +00:00

Optimisation de mémoire et correction de l'orde des opérateurs

This commit is contained in:
Antoine Bartuccio 2017-05-16 22:14:06 +02:00
parent 9277f4e773
commit 774161d7ff
3 changed files with 23 additions and 13 deletions

View File

@ -55,7 +55,7 @@ int fishHelp(WordArray *args) {
int fishExit(WordArray *args) {
args->size = args->size;
exit(EXIT_SUCCESS);
return EXIT_SIGNAL;
}

View File

@ -20,14 +20,14 @@ void fishLoop(Settings * settings){
printf("%s", settings->PS1);
line = fishReadLine();
splited = split(line, (char*) FISH_TOKENS);
splited = split(line, (char*) FISH_TOKENS);
splited = fishExpand(splited);
status = fishExecute(splited);
free(line);
} while(status);
} while(status != EXIT_SIGNAL);
}
int countSeparators(char *string, char *separators) {
@ -152,24 +152,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 +193,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 {