mirror of
https://gitlab.com/klmp200/fish.git
synced 2024-11-21 16:23:20 +00:00
Un globbing récursif, mais pas des masses
This commit is contained in:
parent
2c73d461fb
commit
8eabe26565
@ -64,19 +64,79 @@ WordList* expandWord(char* word){
|
|||||||
|
|
||||||
else{
|
else{
|
||||||
|
|
||||||
WordList* testList = splitWordIntoList(word, '/');
|
WordList* pathList = splitWordIntoList(word, '/');
|
||||||
printWordList(testList);
|
WordList* expandedArgsList = createWordList();
|
||||||
freeWordList(testList);
|
if (expandedArgsList == NULL) crash();
|
||||||
|
WordListElement* tempElement;
|
||||||
|
int i;
|
||||||
|
|
||||||
return getFiles(word, (char*) "*");//temporary
|
if(pathList->size >= 1){
|
||||||
//return();
|
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
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char* getFileName(char* string){
|
||||||
|
|
||||||
|
if(!stringContains(string, '/')){
|
||||||
|
return string;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
int i = 0;
|
||||||
|
while(string[i] != '/'){
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return strndup(string + i + 1, strlen(string) - i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//get path of a file
|
||||||
|
char* getPath(char* string){
|
||||||
|
|
||||||
|
if(!stringContains(string, '/')){
|
||||||
|
return string;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
|
||||||
|
int i = strlen(string) - 1;
|
||||||
|
|
||||||
|
while(i != -1 && string[i] != '/'){
|
||||||
|
|
||||||
|
i = i-1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return strndup(string, i + 1);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
WordList* getFiles(char* path, char* wildcardedString){
|
WordList* getFiles(char* path, char* wildcardedString){
|
||||||
@ -85,6 +145,7 @@ WordList* getFiles(char* path, char* wildcardedString){
|
|||||||
dirent* dir;
|
dirent* dir;
|
||||||
|
|
||||||
WordList* files = createWordList();
|
WordList* files = createWordList();
|
||||||
|
if(files == NULL) crash();
|
||||||
|
|
||||||
|
|
||||||
if((directory = opendir(path)) != NULL){
|
if((directory = opendir(path)) != NULL){
|
||||||
@ -93,12 +154,7 @@ WordList* getFiles(char* path, char* wildcardedString){
|
|||||||
|
|
||||||
if(strcmp(dir->d_name, ".") && strcmp(dir->d_name, "..") && wildcardedStringMatches(wildcardedString, dir->d_name)){//sorry strcmp but I dont like you :(
|
if(strcmp(dir->d_name, ".") && strcmp(dir->d_name, "..") && wildcardedStringMatches(wildcardedString, dir->d_name)){//sorry strcmp but I dont like you :(
|
||||||
|
|
||||||
//dont read this, and if you do, do not complain, it's strcat's fault. you've been warned.
|
char* filePath = trueStrcat(path, dir->d_name);
|
||||||
char* filePath = (char*) malloc(sizeof(char) * (strlen(path) + strlen(dir->d_name)) + 1);
|
|
||||||
if(filePath == NULL) crash();
|
|
||||||
filePath[0] = '\0';
|
|
||||||
strcat(filePath, path);
|
|
||||||
strcat(filePath, dir->d_name);
|
|
||||||
addEndWordList(files, filePath);
|
addEndWordList(files, filePath);
|
||||||
free(filePath);
|
free(filePath);
|
||||||
|
|
||||||
@ -185,9 +241,10 @@ WordList* splitWordIntoList(char* string, char splitChar){
|
|||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
int mark = 0;
|
int mark = 0;
|
||||||
int finished = 0;
|
int finished = 0; //boolean
|
||||||
int firstEncounter = 0;
|
int firstEncounter = 0; //boolean
|
||||||
WordList* newWordList = createWordList();
|
WordList* newWordList = createWordList();
|
||||||
|
if(newWordList == NULL) crash();
|
||||||
|
|
||||||
while(!finished){
|
while(!finished){
|
||||||
|
|
||||||
|
@ -14,4 +14,8 @@ int wildcardedStringMatches(char* string1, char* string2);
|
|||||||
|
|
||||||
WordList* splitWordIntoList(char* string, char splitchar);
|
WordList* splitWordIntoList(char* string, char splitchar);
|
||||||
|
|
||||||
|
char* getFileName(char* string);
|
||||||
|
|
||||||
|
char* getPath(char* string);
|
||||||
|
|
||||||
#endif //FISH_FISH_GLOBBING_H
|
#endif //FISH_FISH_GLOBBING_H
|
||||||
|
@ -331,3 +331,15 @@ int stringContains(char * string, char charToTest){
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//dont read this, and if you do, do not complain, it's strcat's fault. you've been warned.
|
||||||
|
char* trueStrcat(char* string1, char* string2){
|
||||||
|
|
||||||
|
char* newString = (char*) malloc(sizeof(char) * (strlen(string1) + strlen(string2)) + 1);
|
||||||
|
if(newString == NULL) crash();
|
||||||
|
newString[0] = '\0';
|
||||||
|
strcat(newString, string1);
|
||||||
|
strcat(newString, string2);
|
||||||
|
return newString;
|
||||||
|
|
||||||
|
}
|
||||||
|
@ -41,5 +41,7 @@ void printWordList(WordList* list);
|
|||||||
|
|
||||||
int stringContains(char* string, char charToTest);
|
int stringContains(char* string, char charToTest);
|
||||||
|
|
||||||
|
char* trueStrcat(char* string1, char* string2);
|
||||||
|
|
||||||
|
|
||||||
#endif //FISH_FISH_UTILS_H
|
#endif //FISH_FISH_UTILS_H
|
||||||
|
Loading…
Reference in New Issue
Block a user