From f9db2f1cd5708457625fe01fe84a36449ffeebef Mon Sep 17 00:00:00 2001 From: Aethor Date: Tue, 30 May 2017 11:31:00 +0200 Subject: [PATCH 1/7] =?UTF-8?q?un=20globbing=20r=C3=A9cursif,=20mais=20obs?= =?UTF-8?q?cur=20et=20cass=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fish_shell/fish_globbing.c | 134 ++++++++++++++++++++++++++++--------- fish_shell/fish_globbing.h | 4 ++ 2 files changed, 105 insertions(+), 33 deletions(-) diff --git a/fish_shell/fish_globbing.c b/fish_shell/fish_globbing.c index 6cc6efe..808f0ee 100644 --- a/fish_shell/fish_globbing.c +++ b/fish_shell/fish_globbing.c @@ -54,52 +54,120 @@ WordList * fishExpand(WordList *wordList) { } -WordList* expandWord(char* word){ +WordList* expandWord(char* path){ - if(!stringContains(word, '/')){ + if(!stringContains(path, '/')){ - return getFiles((char*) "./", word); + return getFiles((char*) "./", path); } else{ - WordList* pathList = splitWordIntoList(word, '/'); - WordList* expandedArgsList = createWordList(); - if (expandedArgsList == NULL) crash(); - WordListElement* tempElement; - int i; - - if(pathList->size >= 1){ - tempElement = pathList->first; - for(i=0; i < pathList->size; i++){ - - printf("\nBASE PATH %s\n", tempElement->word); - char* tempPath = getPath(tempElement->word); - printf("\nPATH : %s\n", tempPath); - char* tempFileName = getFileName(tempElement->word); - printf("\nFILENAME : %s\n", tempFileName); - - concatWordList(expandedArgsList, getFiles(tempPath, tempFileName)); - printWordList(expandedArgsList); - tempElement = tempElement->next; - - free(tempPath); - free(tempFileName); - - } - } - - freeWordList(pathList); - - return expandedArgsList; - //return getFiles(word, (char*) "*");//temporary + WordList* expandedList = createWordList(); + recursiveExpandWord(path, expandedList); + return expandedList; } } +void recursiveExpandWord(char* path, WordList* listToExpand){ + + int lastToExpand = 1; + int i = 0; + int indexToExpand = -1; + + //TODO : free + WordList* pathToList = splitWordIntoList(path, '/'); + WordListElement* tempElement; //beware of the size, should be checked before anyway + tempElement = pathToList->first; + + + while(i < pathToList->size - 1 && indexToExpand == -1){ + + if(stringContains(tempElement->word, '*') || stringContains(tempElement->word, '?')){ + indexToExpand = i; + lastToExpand = 0; + } + + i++; + tempElement = tempElement->next; + + } + + + if(lastToExpand){ + concatWordList(listToExpand, getFiles(getPath(path), getFileName(path))); + free(pathToList); + } + else{ + + char* correctedPath = concatWordListToWord(pathToList,0, indexToExpand); + WordList* foundFiles = getFiles(getPath(correctedPath), getFileName(correctedPath)); + + if(foundFiles->size > 0){ + + tempElement = foundFiles->first; + char* concatenedEndOfPath = concatWordListToWord(foundFiles, indexToExpand + 1, foundFiles->size - 1); + + for(i=0; i < foundFiles->size; i++){ + + tempElement->word = trueStrcat(tempElement->word, concatenedEndOfPath); + recursiveExpandWord(tempElement->word, listToExpand); + + tempElement = tempElement->next; + + } + + free(concatenedEndOfPath); + + } + + freeWordList(pathToList); + free(correctedPath); + freeWordList(foundFiles); + + } + + +} + +char* concatWordListToWord(WordList* list,int firstElemIndex, int lastElemIndex){ + + if(list->size == 0 || list == NULL) crash(); + + int i; + char* concatenedString = (char*) malloc(sizeof(char)); + if(concatenedString == NULL) crash(); + + if(lastElemIndex > list->size -1){ + lastElemIndex = list->size - 1; + fprintf(stderr, "fish : Warning : you are a miserable failure, your element is beyond the list. pfff. I corrected it for you."); + } + if(firstElemIndex > lastElemIndex){ + firstElemIndex = lastElemIndex; + fprintf(stderr, "fish : Warning : how are you so bad ? your inferior index is superior to your superior index. pfff. I corrected it for you."); + } + + WordListElement* tempElement = list->first; + for(i=0; i < firstElemIndex; i++){ + + tempElement = tempElement->next; + + } + for(i=firstElemIndex; i < lastElemIndex; i++){ + + trueStrcat(concatenedString, tempElement->word); + tempElement = tempElement->next; + + } + + return concatenedString; + +} + char* getFileName(char* string){ if(!stringContains(string, '/')){ diff --git a/fish_shell/fish_globbing.h b/fish_shell/fish_globbing.h index 0bdaae4..690d9ae 100644 --- a/fish_shell/fish_globbing.h +++ b/fish_shell/fish_globbing.h @@ -10,6 +10,8 @@ WordList* getFiles(char* path, char* wildcardedString); WordList* expandWord(char* word); +void recursiveExpandWord(char* path, WordList* listToExpand); + int wildcardedStringMatches(char* string1, char* string2); WordList* splitWordIntoList(char* string, char splitchar); @@ -18,4 +20,6 @@ char* getFileName(char* string); char* getPath(char* string); +char* concatWordListToWord(WordList* list, int firstElemIndex, int lastElemIndex); + #endif //FISH_FISH_GLOBBING_H From 04d20b726cea6d6bd3b4fdbd0c0dbc3d1aadf336 Mon Sep 17 00:00:00 2001 From: Aethor Date: Tue, 30 May 2017 11:31:00 +0200 Subject: [PATCH 2/7] =?UTF-8?q?un=20globbing=20r=C3=A9cursif,=20mais=20obs?= =?UTF-8?q?cur=20et=20cass=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fish_shell/fish_globbing.c | 134 ++++++++++++++++++++++++++++--------- fish_shell/fish_globbing.h | 4 ++ 2 files changed, 105 insertions(+), 33 deletions(-) diff --git a/fish_shell/fish_globbing.c b/fish_shell/fish_globbing.c index 6cc6efe..808f0ee 100644 --- a/fish_shell/fish_globbing.c +++ b/fish_shell/fish_globbing.c @@ -54,52 +54,120 @@ WordList * fishExpand(WordList *wordList) { } -WordList* expandWord(char* word){ +WordList* expandWord(char* path){ - if(!stringContains(word, '/')){ + if(!stringContains(path, '/')){ - return getFiles((char*) "./", word); + return getFiles((char*) "./", path); } else{ - WordList* pathList = splitWordIntoList(word, '/'); - WordList* expandedArgsList = createWordList(); - if (expandedArgsList == NULL) crash(); - WordListElement* tempElement; - int i; - - if(pathList->size >= 1){ - tempElement = pathList->first; - for(i=0; i < pathList->size; i++){ - - printf("\nBASE PATH %s\n", tempElement->word); - char* tempPath = getPath(tempElement->word); - printf("\nPATH : %s\n", tempPath); - char* tempFileName = getFileName(tempElement->word); - printf("\nFILENAME : %s\n", tempFileName); - - concatWordList(expandedArgsList, getFiles(tempPath, tempFileName)); - printWordList(expandedArgsList); - tempElement = tempElement->next; - - free(tempPath); - free(tempFileName); - - } - } - - freeWordList(pathList); - - return expandedArgsList; - //return getFiles(word, (char*) "*");//temporary + WordList* expandedList = createWordList(); + recursiveExpandWord(path, expandedList); + return expandedList; } } +void recursiveExpandWord(char* path, WordList* listToExpand){ + + int lastToExpand = 1; + int i = 0; + int indexToExpand = -1; + + //TODO : free + WordList* pathToList = splitWordIntoList(path, '/'); + WordListElement* tempElement; //beware of the size, should be checked before anyway + tempElement = pathToList->first; + + + while(i < pathToList->size - 1 && indexToExpand == -1){ + + if(stringContains(tempElement->word, '*') || stringContains(tempElement->word, '?')){ + indexToExpand = i; + lastToExpand = 0; + } + + i++; + tempElement = tempElement->next; + + } + + + if(lastToExpand){ + concatWordList(listToExpand, getFiles(getPath(path), getFileName(path))); + free(pathToList); + } + else{ + + char* correctedPath = concatWordListToWord(pathToList,0, indexToExpand); + WordList* foundFiles = getFiles(getPath(correctedPath), getFileName(correctedPath)); + + if(foundFiles->size > 0){ + + tempElement = foundFiles->first; + char* concatenedEndOfPath = concatWordListToWord(foundFiles, indexToExpand + 1, foundFiles->size - 1); + + for(i=0; i < foundFiles->size; i++){ + + tempElement->word = trueStrcat(tempElement->word, concatenedEndOfPath); + recursiveExpandWord(tempElement->word, listToExpand); + + tempElement = tempElement->next; + + } + + free(concatenedEndOfPath); + + } + + freeWordList(pathToList); + free(correctedPath); + freeWordList(foundFiles); + + } + + +} + +char* concatWordListToWord(WordList* list,int firstElemIndex, int lastElemIndex){ + + if(list->size == 0 || list == NULL) crash(); + + int i; + char* concatenedString = (char*) malloc(sizeof(char)); + if(concatenedString == NULL) crash(); + + if(lastElemIndex > list->size -1){ + lastElemIndex = list->size - 1; + fprintf(stderr, "fish : Warning : you are a miserable failure, your element is beyond the list. pfff. I corrected it for you."); + } + if(firstElemIndex > lastElemIndex){ + firstElemIndex = lastElemIndex; + fprintf(stderr, "fish : Warning : how are you so bad ? your inferior index is superior to your superior index. pfff. I corrected it for you."); + } + + WordListElement* tempElement = list->first; + for(i=0; i < firstElemIndex; i++){ + + tempElement = tempElement->next; + + } + for(i=firstElemIndex; i < lastElemIndex; i++){ + + trueStrcat(concatenedString, tempElement->word); + tempElement = tempElement->next; + + } + + return concatenedString; + +} + char* getFileName(char* string){ if(!stringContains(string, '/')){ diff --git a/fish_shell/fish_globbing.h b/fish_shell/fish_globbing.h index 0bdaae4..690d9ae 100644 --- a/fish_shell/fish_globbing.h +++ b/fish_shell/fish_globbing.h @@ -10,6 +10,8 @@ WordList* getFiles(char* path, char* wildcardedString); WordList* expandWord(char* word); +void recursiveExpandWord(char* path, WordList* listToExpand); + int wildcardedStringMatches(char* string1, char* string2); WordList* splitWordIntoList(char* string, char splitchar); @@ -18,4 +20,6 @@ char* getFileName(char* string); char* getPath(char* string); +char* concatWordListToWord(WordList* list, int firstElemIndex, int lastElemIndex); + #endif //FISH_FISH_GLOBBING_H From 354844f79fae4d4bf2d2c4f057d3a79e7fa11572 Mon Sep 17 00:00:00 2001 From: Aethor Date: Fri, 2 Jun 2017 13:43:31 +0200 Subject: [PATCH 3/7] =?UTF-8?q?recursive=20globbing,=20mais=20=C3=A7a=20le?= =?UTF-8?q?ak?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fish_shell/fish_globbing.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/fish_shell/fish_globbing.c b/fish_shell/fish_globbing.c index 808f0ee..e326a50 100644 --- a/fish_shell/fish_globbing.c +++ b/fish_shell/fish_globbing.c @@ -79,9 +79,8 @@ void recursiveExpandWord(char* path, WordList* listToExpand){ int i = 0; int indexToExpand = -1; - //TODO : free WordList* pathToList = splitWordIntoList(path, '/'); - WordListElement* tempElement; //beware of the size, should be checked before anyway + WordListElement* tempElement; //beware of the size, should be checked before anyway (?) tempElement = pathToList->first; @@ -104,13 +103,14 @@ void recursiveExpandWord(char* path, WordList* listToExpand){ } else{ - char* correctedPath = concatWordListToWord(pathToList,0, indexToExpand); + char* correctedPath = concatWordListToWord(pathToList,0, indexToExpand + 1); WordList* foundFiles = getFiles(getPath(correctedPath), getFileName(correctedPath)); + printWordList(foundFiles); if(foundFiles->size > 0){ tempElement = foundFiles->first; - char* concatenedEndOfPath = concatWordListToWord(foundFiles, indexToExpand + 1, foundFiles->size - 1); + char* concatenedEndOfPath = concatWordListToWord(pathToList, indexToExpand + 1, foundFiles->size - 1); for(i=0; i < foundFiles->size; i++){ @@ -141,6 +141,7 @@ char* concatWordListToWord(WordList* list,int firstElemIndex, int lastElemIndex) int i; char* concatenedString = (char*) malloc(sizeof(char)); if(concatenedString == NULL) crash(); + concatenedString[0] = '\0'; if(lastElemIndex > list->size -1){ lastElemIndex = list->size - 1; @@ -159,7 +160,7 @@ char* concatWordListToWord(WordList* list,int firstElemIndex, int lastElemIndex) } for(i=firstElemIndex; i < lastElemIndex; i++){ - trueStrcat(concatenedString, tempElement->word); + concatenedString = trueStrcat(concatenedString, tempElement->word); tempElement = tempElement->next; } @@ -314,6 +315,11 @@ WordList* splitWordIntoList(char* string, char splitChar){ WordList* newWordList = createWordList(); if(newWordList == NULL) crash(); + if(string[0] == '.'){ + addEndWordList(newWordList, (char*) "."); + i++; + } + while(!finished){ if(string[i] == splitChar || string[i] == '\0'){ From a487a29cb837ac4058f2fa75ccdc5607eb2bf15b Mon Sep 17 00:00:00 2001 From: Aethor Date: Fri, 2 Jun 2017 14:58:43 +0200 Subject: [PATCH 4/7] FUCK GIT --- fish_shell/fish_globbing.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/fish_shell/fish_globbing.c b/fish_shell/fish_globbing.c index 551acec..cea748e 100644 --- a/fish_shell/fish_globbing.c +++ b/fish_shell/fish_globbing.c @@ -66,6 +66,7 @@ WordList* expandWord(char* path){ WordList* expandedList = createWordList(); recursiveExpandWord(path, expandedList); + printWordList(expandedList); return expandedList; } @@ -75,11 +76,14 @@ WordList* expandWord(char* path){ void recursiveExpandWord(char* path, WordList* listToExpand){ + printf("launching recursive expand on %s\n", path); + int lastToExpand = 1; int i = 0; int indexToExpand = -1; WordList* pathToList = splitWordIntoList(path, '/'); + printWordList(pathToList); WordListElement* tempElement; //beware of the size, should be checked before anyway (?) tempElement = pathToList->first; @@ -104,13 +108,18 @@ void recursiveExpandWord(char* path, WordList* listToExpand){ else{ char* correctedPath = concatWordListToWord(pathToList,0, indexToExpand + 1); + printf("correctedPath is : %s\n", correctedPath); WordList* foundFiles = getFiles(getPath(correctedPath), getFileName(correctedPath)); + printf("list of found files :\n"); printWordList(foundFiles); if(foundFiles->size > 0){ tempElement = foundFiles->first; char* concatenedEndOfPath = concatWordListToWord(pathToList, indexToExpand + 1, foundFiles->size - 1); + printf("list to be concatened is : \n"); + printWordList(pathToList); + printf("concatenedEndOfPath is : %s\n", concatenedEndOfPath); for(i=0; i < foundFiles->size; i++){ @@ -131,7 +140,6 @@ void recursiveExpandWord(char* path, WordList* listToExpand){ } - return concatenedString; } @@ -145,12 +153,13 @@ char* concatWordListToWord(WordList* list,int firstElemIndex, int lastElemIndex) concatenedString[0] = '\0'; if(lastElemIndex > list->size -1){ + printf("last elem index was %i, while size-1 was %i\n", lastElemIndex, list->size - 1); lastElemIndex = list->size - 1; - fprintf(stderr, "fish : Warning : you are a miserable failure, your element is beyond the list. pfff. I corrected it for you."); + fprintf(stderr, "fish : Warning : you are a miserable failure, your element is beyond the list. pfff. I corrected it for you.\n"); } if(firstElemIndex > lastElemIndex){ firstElemIndex = lastElemIndex; - fprintf(stderr, "fish : Warning : how are you so bad ? your inferior index is superior to your superior index. pfff. I corrected it for you."); + fprintf(stderr, "fish : Warning : how are you so bad ? your inferior index is superior to your superior index. pfff. I corrected it for you.\n"); } WordListElement* tempElement = list->first; From 04db376a0b98124eb02735a721b114e186414552 Mon Sep 17 00:00:00 2001 From: Aethor Date: Fri, 2 Jun 2017 15:26:14 +0200 Subject: [PATCH 5/7] ??? --- fish_shell/fish_globbing.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fish_shell/fish_globbing.c b/fish_shell/fish_globbing.c index cea748e..6461877 100644 --- a/fish_shell/fish_globbing.c +++ b/fish_shell/fish_globbing.c @@ -116,7 +116,7 @@ void recursiveExpandWord(char* path, WordList* listToExpand){ if(foundFiles->size > 0){ tempElement = foundFiles->first; - char* concatenedEndOfPath = concatWordListToWord(pathToList, indexToExpand + 1, foundFiles->size - 1); + char* concatenedEndOfPath = concatWordListToWord(pathToList, indexToExpand + 1, pathToList->size - 1); printf("list to be concatened is : \n"); printWordList(pathToList); printf("concatenedEndOfPath is : %s\n", concatenedEndOfPath); From 0d00964ee9b260fdd665a4c5bf758b15598ccd6e Mon Sep 17 00:00:00 2001 From: Aethor Date: Fri, 2 Jun 2017 17:53:45 +0200 Subject: [PATCH 6/7] Va mourir git --- fish_shell/fish_globbing.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/fish_shell/fish_globbing.c b/fish_shell/fish_globbing.c index 6461877..2553cf9 100644 --- a/fish_shell/fish_globbing.c +++ b/fish_shell/fish_globbing.c @@ -102,7 +102,10 @@ void recursiveExpandWord(char* path, WordList* listToExpand){ if(lastToExpand){ + printf("found %i files in %s, looking for regex %s\n", getFiles(getPath(path), getFileName(path))->size,getPath(path), getFileName(path)); concatWordList(listToExpand, getFiles(getPath(path), getFileName(path))); + printf("listToExpand should be : \n"); + printWordList(listToExpand); free(pathToList); } else{ @@ -110,13 +113,13 @@ void recursiveExpandWord(char* path, WordList* listToExpand){ char* correctedPath = concatWordListToWord(pathToList,0, indexToExpand + 1); printf("correctedPath is : %s\n", correctedPath); WordList* foundFiles = getFiles(getPath(correctedPath), getFileName(correctedPath)); - printf("list of found files :\n"); + printf("list of found files in %s, looking for regex %s:\n", getPath(correctedPath), getFileName(correctedPath)); printWordList(foundFiles); if(foundFiles->size > 0){ tempElement = foundFiles->first; - char* concatenedEndOfPath = concatWordListToWord(pathToList, indexToExpand + 1, pathToList->size - 1); + char* concatenedEndOfPath = concatWordListToWord(pathToList, indexToExpand, pathToList->size - 1); printf("list to be concatened is : \n"); printWordList(pathToList); printf("concatenedEndOfPath is : %s\n", concatenedEndOfPath); @@ -185,12 +188,19 @@ char* getFileName(char* string){ return string; } else{ - int i = 0; + /*int i = 0; while(string[i] != '/'){ i++; } - return strndup(string + i + 1, strlen(string) - i); + return strndup(string + i + 1, strlen(string) - i);*/ + + int i = strlen(string) - 1; + while(string[i] != '/'){ + i--; + } + printf("strndup SAID %s\n", strndup(string + 1 + i,strlen(string) - 1)); + return strndup(string + i + 1,strlen(string) - 1); } } From b568ec339aaf1a1d05f2f1631cfe7427d57bd3cf Mon Sep 17 00:00:00 2001 From: Aethor Date: Tue, 6 Jun 2017 10:37:58 +0200 Subject: [PATCH 7/7] =?UTF-8?q?=C3=A7a=20ne=20leak=20plus,=20bash=20rend?= =?UTF-8?q?=20l'argent?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fish_shell/fish_globbing.c | 53 +++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/fish_shell/fish_globbing.c b/fish_shell/fish_globbing.c index 2553cf9..fd58a76 100644 --- a/fish_shell/fish_globbing.c +++ b/fish_shell/fish_globbing.c @@ -66,7 +66,6 @@ WordList* expandWord(char* path){ WordList* expandedList = createWordList(); recursiveExpandWord(path, expandedList); - printWordList(expandedList); return expandedList; } @@ -76,14 +75,12 @@ WordList* expandWord(char* path){ void recursiveExpandWord(char* path, WordList* listToExpand){ - printf("launching recursive expand on %s\n", path); int lastToExpand = 1; int i = 0; int indexToExpand = -1; WordList* pathToList = splitWordIntoList(path, '/'); - printWordList(pathToList); WordListElement* tempElement; //beware of the size, should be checked before anyway (?) tempElement = pathToList->first; @@ -102,31 +99,36 @@ void recursiveExpandWord(char* path, WordList* listToExpand){ if(lastToExpand){ - printf("found %i files in %s, looking for regex %s\n", getFiles(getPath(path), getFileName(path))->size,getPath(path), getFileName(path)); - concatWordList(listToExpand, getFiles(getPath(path), getFileName(path))); - printf("listToExpand should be : \n"); - printWordList(listToExpand); - free(pathToList); + char* tmpPath = getPath(path); + char* tmpFileName = getFileName(path); + concatWordList(listToExpand, getFiles(tmpPath, tmpFileName)); + free(tmpPath); + free(tmpFileName); + freeWordList(pathToList); } else{ char* correctedPath = concatWordListToWord(pathToList,0, indexToExpand + 1); - printf("correctedPath is : %s\n", correctedPath); - WordList* foundFiles = getFiles(getPath(correctedPath), getFileName(correctedPath)); - printf("list of found files in %s, looking for regex %s:\n", getPath(correctedPath), getFileName(correctedPath)); - printWordList(foundFiles); + char* pathOfCorrectedPath = getPath(correctedPath); + char* fileNameOfCorrectedPath = getFileName(correctedPath); + WordList* foundFiles = getFiles(pathOfCorrectedPath, fileNameOfCorrectedPath); + char* tmpWord = NULL; + + free(pathOfCorrectedPath); + free(fileNameOfCorrectedPath); + free(correctedPath); if(foundFiles->size > 0){ tempElement = foundFiles->first; char* concatenedEndOfPath = concatWordListToWord(pathToList, indexToExpand, pathToList->size - 1); - printf("list to be concatened is : \n"); - printWordList(pathToList); - printf("concatenedEndOfPath is : %s\n", concatenedEndOfPath); for(i=0; i < foundFiles->size; i++){ + tmpWord = tempElement->word; tempElement->word = trueStrcat(tempElement->word, concatenedEndOfPath); + free(tmpWord); + tmpWord = NULL; recursiveExpandWord(tempElement->word, listToExpand); tempElement = tempElement->next; @@ -138,7 +140,6 @@ void recursiveExpandWord(char* path, WordList* listToExpand){ } freeWordList(pathToList); - free(correctedPath); freeWordList(foundFiles); } @@ -152,11 +153,11 @@ char* concatWordListToWord(WordList* list,int firstElemIndex, int lastElemIndex) int i; char* concatenedString = (char*) malloc(sizeof(char)); + char* tmpConcatenedString = concatenedString; if(concatenedString == NULL) crash(); concatenedString[0] = '\0'; if(lastElemIndex > list->size -1){ - printf("last elem index was %i, while size-1 was %i\n", lastElemIndex, list->size - 1); lastElemIndex = list->size - 1; fprintf(stderr, "fish : Warning : you are a miserable failure, your element is beyond the list. pfff. I corrected it for you.\n"); } @@ -174,6 +175,7 @@ char* concatWordListToWord(WordList* list,int firstElemIndex, int lastElemIndex) for(i=firstElemIndex; i < lastElemIndex; i++){ concatenedString = trueStrcat(concatenedString, tempElement->word); + free(tmpConcatenedString); tempElement = tempElement->next; } @@ -184,24 +186,23 @@ char* concatWordListToWord(WordList* list,int firstElemIndex, int lastElemIndex) char* getFileName(char* string){ + int wordSize = strlen(string) - 1; + if(!stringContains(string, '/')){ return string; } else{ - /*int i = 0; + + int i = wordSize; + while(string[i] != '/'){ - i++; + i--; } - return strndup(string + i + 1, strlen(string) - i);*/ + return strndup(string + i + 1,wordSize); - int i = strlen(string) - 1; - while(string[i] != '/'){ - i--; - } - printf("strndup SAID %s\n", strndup(string + 1 + i,strlen(string) - 1)); - return strndup(string + i + 1,strlen(string) - 1); } + }