From c1e13ab7c869b2512fac4a2cfbade859ec8cf0b9 Mon Sep 17 00:00:00 2001 From: Aethor Date: Tue, 16 May 2017 07:32:19 +0200 Subject: [PATCH] =?UTF-8?q?=C3=A7a=20core=20dump=20quelque=20peu?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fish_shell/fish_core.c | 9 +++++-- fish_shell/fish_globbing.c | 52 ++++++++++++++++++++++++++++++++++---- fish_shell/fish_globbing.h | 2 ++ fish_shell/fish_utils.c | 19 +++++++++++++- fish_shell/fish_utils.h | 2 ++ 5 files changed, 76 insertions(+), 8 deletions(-) diff --git a/fish_shell/fish_core.c b/fish_shell/fish_core.c index 43e4d18..3befad4 100644 --- a/fish_shell/fish_core.c +++ b/fish_shell/fish_core.c @@ -158,8 +158,13 @@ int fishExecute(WordArray *array) { return 1; for (i=0; i < getNbBuiltins(); i++){ - if (!strcmp(array->words[0], getBuiltinCommandsStr()[i])){ - return getBuiltinCommands()[i](array); + if(array->words[0] != NULL){ + if (!strcmp(array->words[0], getBuiltinCommandsStr()[i])){ + return getBuiltinCommands()[i](array); + } + } + else{ + crash(); } } diff --git a/fish_shell/fish_globbing.c b/fish_shell/fish_globbing.c index e764635..45bf4d3 100644 --- a/fish_shell/fish_globbing.c +++ b/fish_shell/fish_globbing.c @@ -2,18 +2,59 @@ #include #include #include +#include #include "fish_core.h" #include "fish_globbing.h" -WordList * fishExpand(WordList *wordArray) { +WordList * fishExpand(WordList *wordList) { - wordArray = expandInDir("./", "*"); + if(wordList->size > 1){ + int i; - return wordArray; + WordList* newWordList = createWordList(); + if(newWordList == NULL){ + crash(); + } + + newWordList->first = wordList->first; + + newWordList->size = 0; + + WordListElement* tempElement = wordList->first->next; + + for(i=0; isize; i++){ + + //newWordList = concatWordList(newWordList, recursiveExpand(tempElement->word)); + //newWordList = concatWordList(newWordList, NULL); + + if(tempElement != NULL){ + + tempElement = tempElement->next; + + } + } + + return newWordList; + + } + + else return wordList; } +WordList* recursiveExpand(char * completePath){ + + if (stringContains(completePath, '/')){ + + return expandInDir("./",completePath); + + } + + return NULL; + +} + WordArray * getFiles(char* path){ @@ -21,6 +62,7 @@ WordArray * getFiles(char* path){ dirent* dir; int i = 0; + WordArray* files = (WordArray*) malloc(sizeof(WordArray)); @@ -40,14 +82,14 @@ WordArray * getFiles(char* path){ while((dir = readdir(directory)) != NULL){ - /*if(dir->d_name != "." && dir->d_name != ".."){*/ + if(!strcmp(dir->d_name, ".") && !strcmp(dir->d_name, "..")){ printf("%s\n", dir->d_name); files->words[i] = dir->d_name; i++; files->size++; - //} + } } diff --git a/fish_shell/fish_globbing.h b/fish_shell/fish_globbing.h index 2d635bf..8438d2e 100644 --- a/fish_shell/fish_globbing.h +++ b/fish_shell/fish_globbing.h @@ -13,4 +13,6 @@ int comparator(char* string1, char* string2); WordList* expandInDir(char*, char*); +WordList* recursiveExpand(char* completePath); + #endif //FISH_FISH_GLOBBING_H diff --git a/fish_shell/fish_utils.c b/fish_shell/fish_utils.c index e07251f..b2c8e13 100644 --- a/fish_shell/fish_utils.c +++ b/fish_shell/fish_utils.c @@ -105,7 +105,8 @@ void freeWordList(WordList *list) { WordList* concatWordList(WordList* list1, WordList* list2){ - if(list1->last != NULL){ + + if(list1 != NULL && list2 != NULL && list1->size >= 1 && list2->size >=1){ list1->last->next = list2->first; list2->first->previous = list1->last; list1->last = list2->last; @@ -155,3 +156,19 @@ WordList *wordArrayToWordList(WordArray *array) { return list; } + +int stringContains(char * string, char charToTest){ + + int i = 0; + + while(string[i] != '\0'){ + + if(string[i] != charToTest){ + return 0; + } + i++; + } + + return 1; + +} diff --git a/fish_shell/fish_utils.h b/fish_shell/fish_utils.h index d94dffa..ca0b653 100644 --- a/fish_shell/fish_utils.h +++ b/fish_shell/fish_utils.h @@ -27,4 +27,6 @@ WordList * wordArrayToWordList(WordArray * array); WordList* concatWordList(WordList* list1, WordList* list2); +int stringContains(char* string, char charToTest); + #endif //FISH_FISH_UTILS_H