1
0
mirror of https://gitlab.com/klmp200/fish.git synced 2024-10-31 22:18:04 +00:00

Merge branch 'bro' into 'master'

Please dont be invaliiiiiiid, yeah-eah

See merge request !12
This commit is contained in:
Antoine Bartuccio 2017-06-07 16:04:01 +00:00
commit e6aaeaf830
3 changed files with 33 additions and 2 deletions

View File

@ -38,6 +38,7 @@ WordList * fishExpand(WordList *wordList) {
tempElement = tempElement->next; tempElement = tempElement->next;
} }
freeWordList(wordList); freeWordList(wordList);
@ -122,14 +123,20 @@ void recursiveExpandWord(char* path, WordList* listToExpand){
tempElement = foundFiles->first; tempElement = foundFiles->first;
char* concatenedEndOfPath = concatWordListToWord(pathToList, indexToExpand, pathToList->size - 1); char* concatenedEndOfPath = concatWordListToWord(pathToList, indexToExpand, pathToList->size - 1);
int isDir;
for(i=0; i < foundFiles->size; i++){ for(i=0; i < foundFiles->size; i++){
tmpWord = tempElement->word; tmpWord = tempElement->word;
isDir = isDirectory(tmpWord);
tempElement->word = trueStrcat(tempElement->word, concatenedEndOfPath); tempElement->word = trueStrcat(tempElement->word, concatenedEndOfPath);
free(tmpWord); free(tmpWord);
tmpWord = NULL; tmpWord = NULL;
if(isDir){
recursiveExpandWord(tempElement->word, listToExpand); recursiveExpandWord(tempElement->word, listToExpand);
}
tempElement = tempElement->next; tempElement = tempElement->next;
@ -153,7 +160,7 @@ char* concatWordListToWord(WordList* list,int firstElemIndex, int lastElemIndex)
int i; int i;
char* concatenedString = (char*) malloc(sizeof(char)); char* concatenedString = (char*) malloc(sizeof(char));
char* tmpConcatenedString = concatenedString; char* tmpConcatenedString = NULL;
if(concatenedString == NULL) crash(); if(concatenedString == NULL) crash();
concatenedString[0] = '\0'; concatenedString[0] = '\0';
@ -174,6 +181,7 @@ char* concatWordListToWord(WordList* list,int firstElemIndex, int lastElemIndex)
} }
for(i=firstElemIndex; i < lastElemIndex; i++){ for(i=firstElemIndex; i < lastElemIndex; i++){
tmpConcatenedString = concatenedString;
concatenedString = trueStrcat(concatenedString, tempElement->word); concatenedString = trueStrcat(concatenedString, tempElement->word);
free(tmpConcatenedString); free(tmpConcatenedString);
tempElement = tempElement->next; tempElement = tempElement->next;

View File

@ -7,6 +7,8 @@
#include <string.h> #include <string.h>
#include <time.h> #include <time.h>
#include <pcre.h> #include <pcre.h>
#include <dirent.h>
#include <errno.h>
#include "fish_utils.h" #include "fish_utils.h"
#include "fish_types.h" #include "fish_types.h"
@ -343,3 +345,22 @@ char* trueStrcat(char* string1, char* string2){
return newString; 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
}
}

View File

@ -43,5 +43,7 @@ int stringContains(char* string, char charToTest);
char* trueStrcat(char* string1, char* string2); char* trueStrcat(char* string1, char* string2);
int isDirectory(char* path);
#endif //FISH_FISH_UTILS_H #endif //FISH_FISH_UTILS_H