1
0
mirror of https://gitlab.com/klmp200/fish.git synced 2024-11-22 08:43:20 +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) { int fishExit(WordArray *args) {
args->size = args->size; args->size = args->size;
exit(EXIT_SUCCESS); return EXIT_SIGNAL;
} }

View File

@ -20,14 +20,14 @@ void fishLoop(Settings * settings){
printf("%s", settings->PS1); printf("%s", settings->PS1);
line = fishReadLine(); line = fishReadLine();
splited = split(line, (char*) FISH_TOKENS); splited = split(line, (char*) FISH_TOKENS);
splited = fishExpand(splited); splited = fishExpand(splited);
status = fishExecute(splited); status = fishExecute(splited);
free(line); free(line);
} while(status); } while(status != EXIT_SIGNAL);
} }
int countSeparators(char *string, char *separators) { int countSeparators(char *string, char *separators) {
@ -152,24 +152,32 @@ int fishExecute(WordList *list) {
WordList *splited = NULL; WordList *splited = NULL;
shell_operator op = NONE; shell_operator op = NONE;
WordArray *array = NULL; WordArray *array = NULL;
int signal = 1;
splited = parseWordList(list, &op); splited = parseWordList(list, &op);
array = wordListToWordArray(list); array = wordListToWordArray(list);
signal = loadRightCommand(array);
if (signal == EXIT_SIGNAL){
if (splited != NULL) freeWordList(splited);
if (array != NULL) freeWordArray(array);
return signal;
}
switch (op) { switch (op) {
case AND: case AND:
if (!loadRightCommand(array)) fishExecute(splited); if (!signal) signal = fishExecute(splited);
else freeWordList(splited); else {
if (splited != NULL) freeWordList(splited);
}
break; break;
case OR: case OR:
loadRightCommand(array); signal = fishExecute(splited);
fishExecute(splited);
break; break;
default: default:
loadRightCommand(array); break;
} }
return signal;
return 1;
} }
int loadRightCommand(WordArray *array){ int loadRightCommand(WordArray *array){
@ -185,12 +193,12 @@ int loadRightCommand(WordArray *array){
WordList * parseWordList(WordList *list, shell_operator *an_operator) { WordList * parseWordList(WordList *list, shell_operator *an_operator) {
char *op_str[] = { char *op_str[] = {
(char*) "&&", (char*) "||",
(char*) "||" (char*) "&&"
}; };
shell_operator op[] = { shell_operator op[] = {
AND, OR,
OR AND
}; };
WordList *newList = NULL; WordList *newList = NULL;
int max = sizeof(op_str) / sizeof(char*); int max = sizeof(op_str) / sizeof(char*);

View File

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