From 9b6e5c7bc52b2e8353784f838300c911ed5cd697 Mon Sep 17 00:00:00 2001 From: klmp200 Date: Mon, 15 May 2017 16:53:56 +0200 Subject: [PATCH] Refactor avec des listes --- fish_shell/fish_core.c | 15 +++++++++------ fish_shell/fish_core.h | 2 +- fish_shell/fish_globbing.c | 2 +- fish_shell/fish_globbing.h | 2 +- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/fish_shell/fish_core.c b/fish_shell/fish_core.c index 08652db..43e4d18 100644 --- a/fish_shell/fish_core.c +++ b/fish_shell/fish_core.c @@ -15,7 +15,8 @@ void fishLoop(Settings * settings){ char * line = NULL; - WordArray * splited = NULL; + WordList* splited = NULL; + WordArray* array = NULL; int status = 1; do { @@ -25,9 +26,10 @@ void fishLoop(Settings * settings){ splited = split(line, FISH_TOKENS); splited = fishExpand(splited); - status = fishExecute(splited); + array = wordListToWordArray(splited); + status = fishExecute(array); - freeWordArray(splited); + freeWordArray(array); free(line); } while(status); } @@ -49,7 +51,7 @@ int countSeparators(char *string, char *separators) { return nb; } -WordArray * split(char *string, char *separator){ +WordList * split(char *string, char *separator){ WordList *list = createWordList(); char *to_delete = strdup(string); char *to_delete_bak = to_delete; @@ -64,7 +66,7 @@ WordArray * split(char *string, char *separator){ free(to_delete_bak); - return wordListToWordArray(list); + return list; } char *fishReadLine() { @@ -109,8 +111,9 @@ Settings *getSettings() { Settings *s = (Settings*) malloc(sizeof(Settings)); if (s == NULL){ crash(); + } else { + s->PS1 = strdup("\n~>"); } - s->PS1 = strdup("\n~>"); return s; } diff --git a/fish_shell/fish_core.h b/fish_shell/fish_core.h index cca1b34..2b8cad1 100644 --- a/fish_shell/fish_core.h +++ b/fish_shell/fish_core.h @@ -12,7 +12,7 @@ /* WordArray functions */ -WordArray * split(char *string, char *separator); +WordList * split(char *string, char *separator); /* Settings functions */ diff --git a/fish_shell/fish_globbing.c b/fish_shell/fish_globbing.c index 639dc7c..1ca078c 100644 --- a/fish_shell/fish_globbing.c +++ b/fish_shell/fish_globbing.c @@ -5,7 +5,7 @@ #include "fish_core.h" #include "fish_globbing.h" -WordArray* fishExpand(WordArray *wordArray) { +WordList * fishExpand(WordList *wordArray) { int i; //WordArray* splitParameter; diff --git a/fish_shell/fish_globbing.h b/fish_shell/fish_globbing.h index 0e70a26..0d76d04 100644 --- a/fish_shell/fish_globbing.h +++ b/fish_shell/fish_globbing.h @@ -4,7 +4,7 @@ typedef struct dirent dirent; -WordArray * fishExpand(WordArray* wordArray); +WordList * fishExpand(WordList *wordArray); WordArray* getFiles(char* path);