diff --git a/fish_shell/fish_globbing.c b/fish_shell/fish_globbing.c index 1ca078c..e764635 100644 --- a/fish_shell/fish_globbing.c +++ b/fish_shell/fish_globbing.c @@ -7,14 +7,7 @@ WordList * fishExpand(WordList *wordArray) { - int i; - //WordArray* splitParameter; - - for(i=1; isize; i++){ - - - - } + wordArray = expandInDir("./", "*"); return wordArray; @@ -47,8 +40,15 @@ WordArray * getFiles(char* path){ while((dir = readdir(directory)) != NULL){ - files->words[i] = dir->d_name; + /*if(dir->d_name != "." && dir->d_name != ".."){*/ + printf("%s\n", dir->d_name); + files->words[i] = dir->d_name; + i++; + files->size++; + + //} + } @@ -120,4 +120,25 @@ int comparator(char* string1, char* string2){//TODO } +WordList* expandInDir(char* dir, char* toExpand){ + + int i = 0; + WordList* list = createWordList(); + WordArray* files = getFiles(dir); + + for(i=0; isize;i++){ + + if(comparator(toExpand, files->words[i])){ + + addWordList(list, files->words[i]); + + } + + } + + + return list; + +} + diff --git a/fish_shell/fish_globbing.h b/fish_shell/fish_globbing.h index 0d76d04..2d635bf 100644 --- a/fish_shell/fish_globbing.h +++ b/fish_shell/fish_globbing.h @@ -11,4 +11,6 @@ WordArray* getFiles(char* path); /*char1 is a string with characters such as '*', '.' or '?' having special meanings*/ int comparator(char* string1, char* string2); +WordList* expandInDir(char*, char*); + #endif //FISH_FISH_GLOBBING_H diff --git a/fish_shell/fish_utils.c b/fish_shell/fish_utils.c index a018a8f..e07251f 100644 --- a/fish_shell/fish_utils.c +++ b/fish_shell/fish_utils.c @@ -30,7 +30,7 @@ char *getInsult(){ char *insults[] = { "Apprend à écrire crétin !", "Bolos !", - "Mois aussi je sais écrire de la merde, pourtant je le fait pas !" + "Moi aussi je sais écrire de la merde, pourtant je le fait pas !" }; if (!init){ srand((unsigned int) time(NULL)); @@ -103,6 +103,22 @@ void freeWordList(WordList *list) { free(list); } +WordList* concatWordList(WordList* list1, WordList* list2){ + + if(list1->last != NULL){ + list1->last->next = list2->first; + list2->first->previous = list1->last; + list1->last = list2->last; + list1->size = list1->size + list2->size; + free(list2); + return list1; + } + else{ + return NULL; + } + +} + WordArray *wordListToWordArray(WordList *list) { WordArray *array = (WordArray*) malloc(sizeof(WordArray)); WordListElement *current = list->first; diff --git a/fish_shell/fish_utils.h b/fish_shell/fish_utils.h index 70e3725..d94dffa 100644 --- a/fish_shell/fish_utils.h +++ b/fish_shell/fish_utils.h @@ -25,4 +25,6 @@ WordArray * wordListToWordArray(WordList *list); WordList * wordArrayToWordList(WordArray * array); +WordList* concatWordList(WordList* list1, WordList* list2); + #endif //FISH_FISH_UTILS_H