diff --git a/fish_shell/fish_core.c b/fish_shell/fish_core.c index b135254..2c013ee 100644 --- a/fish_shell/fish_core.c +++ b/fish_shell/fish_core.c @@ -194,10 +194,17 @@ int fishExecute(WordList *list) { int loadRightCommand(WordArray *array){ int i; - if (array->size <= 0) return 1; - for (i = 0; i < getNbBuiltins(); i++) { - if (!strcmp(array->words[0], getBuiltinCommandsStr()[i])) { - return getBuiltinCommands()[i](array); + if (array->size < 0) + return 1; + + for (i=0; i < getNbBuiltins(); i++){ + if(array->words[0] != NULL){ + if (!strcmp(array->words[0], getBuiltinCommandsStr()[i])){ + return getBuiltinCommands()[i](array); + } + } + else{ + crash(); } } return fishLoad(array); 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 e077fa9..1f6c6ea 100644 --- a/fish_shell/fish_utils.c +++ b/fish_shell/fish_utils.c @@ -30,7 +30,6 @@ char *getInsult(){ static int init = 0; int picked = 0; char *insults[] = { -<<<<<<< HEAD (char *) "Apprend à écrire crétin !", (char *) "Boloss !", (char *) "Mois aussi je sais écrire de la merde, pourtant je le fait pas !", @@ -38,11 +37,6 @@ char *getInsult(){ (char *) "Nul !", (char *) "Pense à aller à l'école un jour", (char *) "Et après on dit que c'est la faute de l'ordinateur..." -======= - "Apprend à écrire crétin !", - "Bolos !", - "Moi aussi je sais écrire de la merde, pourtant je le fait pas !" ->>>>>>> Black mage of regex stikes again }; if (!init){ srand((unsigned int) time(NULL)); @@ -125,7 +119,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; @@ -285,3 +280,18 @@ WordList *splitWordList(WordList *list, char *regex) { return new_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 e372f4e..80dfd5f 100644 --- a/fish_shell/fish_utils.h +++ b/fish_shell/fish_utils.h @@ -37,4 +37,6 @@ char * splitWord(char * origin, int beginning_index, int size_to_delete); // Tes WordList* concatWordList(WordList* list1, WordList* list2); +int stringContains(char* string, char charToTest); + #endif //FISH_FISH_UTILS_H