From 1b99d6cfe5a40323126de96b66a15ff204103da1 Mon Sep 17 00:00:00 2001 From: Aethor Date: Wed, 7 Jun 2017 17:58:44 +0200 Subject: [PATCH] Please dont be invaliiiiiiid, yeah-eah --- fish_shell/fish_globbing.c | 12 ++++++++++-- fish_shell/fish_utils.c | 21 +++++++++++++++++++++ fish_shell/fish_utils.h | 2 ++ 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/fish_shell/fish_globbing.c b/fish_shell/fish_globbing.c index fd58a76..803f305 100644 --- a/fish_shell/fish_globbing.c +++ b/fish_shell/fish_globbing.c @@ -38,6 +38,7 @@ WordList * fishExpand(WordList *wordList) { tempElement = tempElement->next; + } freeWordList(wordList); @@ -122,14 +123,20 @@ void recursiveExpandWord(char* path, WordList* listToExpand){ tempElement = foundFiles->first; char* concatenedEndOfPath = concatWordListToWord(pathToList, indexToExpand, pathToList->size - 1); + int isDir; for(i=0; i < foundFiles->size; i++){ tmpWord = tempElement->word; + + isDir = isDirectory(tmpWord); + tempElement->word = trueStrcat(tempElement->word, concatenedEndOfPath); free(tmpWord); tmpWord = NULL; - recursiveExpandWord(tempElement->word, listToExpand); + if(isDir){ + recursiveExpandWord(tempElement->word, listToExpand); + } tempElement = tempElement->next; @@ -153,7 +160,7 @@ char* concatWordListToWord(WordList* list,int firstElemIndex, int lastElemIndex) int i; char* concatenedString = (char*) malloc(sizeof(char)); - char* tmpConcatenedString = concatenedString; + char* tmpConcatenedString = NULL; if(concatenedString == NULL) crash(); concatenedString[0] = '\0'; @@ -174,6 +181,7 @@ char* concatWordListToWord(WordList* list,int firstElemIndex, int lastElemIndex) } for(i=firstElemIndex; i < lastElemIndex; i++){ + tmpConcatenedString = concatenedString; concatenedString = trueStrcat(concatenedString, tempElement->word); free(tmpConcatenedString); tempElement = tempElement->next; diff --git a/fish_shell/fish_utils.c b/fish_shell/fish_utils.c index 34cdc7b..6505798 100644 --- a/fish_shell/fish_utils.c +++ b/fish_shell/fish_utils.c @@ -7,6 +7,8 @@ #include #include #include +#include +#include #include "fish_utils.h" #include "fish_types.h" @@ -343,3 +345,22 @@ char* trueStrcat(char* string1, char* string2){ return newString; } + +int isDirectory(char* path){ + + DIR* directory = opendir(path); + + //printf("testing %s\n", path); + + if(directory != NULL){ + closedir(directory); + return 1; + } + else if(errno == ENOTDIR){ + return 0; + } + else{ + fprintf(stderr, "fish : Warning : %s is an invalid path you stupid human\n", path); + return 0; //hihi + } +} diff --git a/fish_shell/fish_utils.h b/fish_shell/fish_utils.h index d38bca3..35dd374 100644 --- a/fish_shell/fish_utils.h +++ b/fish_shell/fish_utils.h @@ -43,5 +43,7 @@ int stringContains(char* string, char charToTest); char* trueStrcat(char* string1, char* string2); +int isDirectory(char* path); + #endif //FISH_FISH_UTILS_H