From 83f695c53887355d6c7e5c26946ac49b2fa4211d Mon Sep 17 00:00:00 2001 From: Aethor Date: Mon, 15 May 2017 19:10:46 +0200 Subject: [PATCH 1/2] Black mage of regex stikes again --- fish_shell/fish_globbing.c | 39 +++++++++++++++++++++++++++++--------- fish_shell/fish_globbing.h | 2 ++ fish_shell/fish_utils.c | 18 +++++++++++++++++- fish_shell/fish_utils.h | 2 ++ 4 files changed, 51 insertions(+), 10 deletions(-) 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 From c1e13ab7c869b2512fac4a2cfbade859ec8cf0b9 Mon Sep 17 00:00:00 2001 From: Aethor Date: Tue, 16 May 2017 07:32:19 +0200 Subject: [PATCH 2/2] =?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