From 0a26964d62f69c0a919f61eaeac65eae57720692 Mon Sep 17 00:00:00 2001 From: klmp200 Date: Mon, 15 May 2017 16:27:44 +0200 Subject: [PATCH] =?UTF-8?q?D=C3=A9but=20d'un=20refactor=20avec=20des=20lis?= =?UTF-8?q?tes=20cha=C3=AEn=C3=A9es?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/codeStyleSettings.xml | 35 +++++++++++++++++++++++++++++++++++ fish_shell/fish_core.c | 20 +++++--------------- 2 files changed, 40 insertions(+), 15 deletions(-) create mode 100644 .idea/codeStyleSettings.xml diff --git a/.idea/codeStyleSettings.xml b/.idea/codeStyleSettings.xml new file mode 100644 index 0000000..8c27bb1 --- /dev/null +++ b/.idea/codeStyleSettings.xml @@ -0,0 +1,35 @@ + + + + + + \ No newline at end of file diff --git a/fish_shell/fish_core.c b/fish_shell/fish_core.c index 73e384c..1a3e832 100644 --- a/fish_shell/fish_core.c +++ b/fish_shell/fish_core.c @@ -48,31 +48,21 @@ int countSeparators(char *string, char *separators) { } WordArray * split(char *string, char *separator){ - int array_size = countSeparators(string, separator) + 1; - WordArray *tokens = (WordArray*) malloc(sizeof(WordArray)); + WordList *list = createWordList(); char *to_delete = strdup(string); char *to_delete_bak = to_delete; char *token = NULL; - int i = 0; - if (tokens != NULL){ - tokens->words = (char **) malloc(sizeof(char*) * (array_size + 1)); - tokens->words[array_size] = NULL; - tokens->size = array_size; - } - - if (tokens == NULL || to_delete == NULL || tokens->words == NULL){ + if (to_delete == NULL){ crash(); } - while((token = strsep(&to_delete, separator)) != NULL){ - tokens->words[i] = strdup(token); - i++; - } + while((token = strsep(&to_delete, separator)) != NULL) + addWordList(list, token); free(to_delete_bak); - return tokens; + return wordListToWordArray(list); } char *fishReadLine() {