diff --git a/fish_shell/fish_globbing.c b/fish_shell/fish_globbing.c index 17cb999..35a9ba6 100644 --- a/fish_shell/fish_globbing.c +++ b/fish_shell/fish_globbing.c @@ -41,6 +41,11 @@ WordList * fishExpand(WordList *wordList) { } freeWordList(wordList); + + //TODO : move this in recursion in case multiples commands are in the same line + if(newWordList->size == 1){ + addEndWordList(newWordList, (char*) ERROR_STRING); + } return newWordList; } @@ -59,6 +64,10 @@ WordList* expandWord(char* word){ else{ + WordList* testList = splitWordIntoList(word, '/'); + printWordList(testList); + freeWordList(testList); + return getFiles(word, (char*) "*");//temporary //return(); @@ -161,7 +170,7 @@ int wildcardedStringMatches(char* string1, char* string2){//TODO else{ - printf("warning : fuck you, strings are considered null"); + printf("fish : Warning : fuck you, strings are considered null"); crash(); return 0; @@ -169,4 +178,55 @@ int wildcardedStringMatches(char* string1, char* string2){//TODO } +//beware : will purposedly ignore the first occurence of the character +WordList* splitWordIntoList(char* string, char splitChar){ + if(stringContains(string, '/')){ + + int i = 0; + int mark = 0; + int finished = 0; + int firstEncounter = 0; + WordList* newWordList = createWordList(); + + while(!finished){ + + if(string[i] == splitChar || string[i] == '\0'){ + + if(!firstEncounter){ + + firstEncounter = 1; + + } + + else{ + + char* tempStr = strndup(string + mark, i - mark); + + if(tempStr == NULL){ + crash(); + } + + addEndWordList(newWordList, tempStr); + free(tempStr); + mark = i; + if(string[i] == '\0'){ + finished = 1; + } + } + + } + i++; + + } + + return newWordList; + + } + else{ + WordList* newWordList = createWordList(); + addEndWordList(newWordList, string); + return newWordList; + } + +} diff --git a/fish_shell/fish_globbing.h b/fish_shell/fish_globbing.h index 8804afc..74fc3b5 100644 --- a/fish_shell/fish_globbing.h +++ b/fish_shell/fish_globbing.h @@ -12,4 +12,6 @@ WordList* expandWord(char* word); int wildcardedStringMatches(char* string1, char* string2); +WordList* splitWordIntoList(char* string, char splitchar); + #endif //FISH_FISH_GLOBBING_H diff --git a/fish_shell/fish_types.h b/fish_shell/fish_types.h index cef1a74..958bdc4 100644 --- a/fish_shell/fish_types.h +++ b/fish_shell/fish_types.h @@ -6,6 +6,7 @@ #define FISH_FISH_TYPES_H #define EXIT_SIGNAL -100 +#define ERROR_STRING "\n" /* Custom types */ @@ -35,6 +36,7 @@ typedef struct { WordListElement * last; } WordList; + typedef struct { char *PS1; } Settings; diff --git a/fish_shell/fish_utils.c b/fish_shell/fish_utils.c index 8a6c117..febdbe2 100644 --- a/fish_shell/fish_utils.c +++ b/fish_shell/fish_utils.c @@ -331,4 +331,3 @@ int stringContains(char * string, char charToTest){ return 0; } -