1
0
mirror of https://gitlab.com/klmp200/fish.git synced 2024-11-24 18:14:18 +00:00

Black mage of regex stikes again

This commit is contained in:
Aethor 2017-05-15 19:10:46 +02:00
parent 9b6e5c7bc5
commit 83f695c538
4 changed files with 51 additions and 10 deletions

View File

@ -7,14 +7,7 @@
WordList * fishExpand(WordList *wordArray) {
int i;
//WordArray* splitParameter;
for(i=1; i<wordArray->size; i++){
}
wordArray = expandInDir("./", "*");
return wordArray;
@ -47,8 +40,15 @@ WordArray * getFiles(char* path){
while((dir = readdir(directory)) != NULL){
files->words[i] = dir->d_name;
/*if(dir->d_name != "." && dir->d_name != ".."){*/
printf("%s\n", dir->d_name);
files->words[i] = dir->d_name;
i++;
files->size++;
//}
}
@ -120,4 +120,25 @@ int comparator(char* string1, char* string2){//TODO
}
WordList* expandInDir(char* dir, char* toExpand){
int i = 0;
WordList* list = createWordList();
WordArray* files = getFiles(dir);
for(i=0; i<files->size;i++){
if(comparator(toExpand, files->words[i])){
addWordList(list, files->words[i]);
}
}
return list;
}

View File

@ -11,4 +11,6 @@ WordArray* getFiles(char* path);
/*char1 is a string with characters such as '*', '.' or '?' having special meanings*/
int comparator(char* string1, char* string2);
WordList* expandInDir(char*, char*);
#endif //FISH_FISH_GLOBBING_H

View File

@ -30,7 +30,7 @@ char *getInsult(){
char *insults[] = {
"Apprend à écrire crétin !",
"Bolos !",
"Mois aussi je sais écrire de la merde, pourtant je le fait pas !"
"Moi aussi je sais écrire de la merde, pourtant je le fait pas !"
};
if (!init){
srand((unsigned int) time(NULL));
@ -103,6 +103,22 @@ void freeWordList(WordList *list) {
free(list);
}
WordList* concatWordList(WordList* list1, WordList* list2){
if(list1->last != NULL){
list1->last->next = list2->first;
list2->first->previous = list1->last;
list1->last = list2->last;
list1->size = list1->size + list2->size;
free(list2);
return list1;
}
else{
return NULL;
}
}
WordArray *wordListToWordArray(WordList *list) {
WordArray *array = (WordArray*) malloc(sizeof(WordArray));
WordListElement *current = list->first;

View File

@ -25,4 +25,6 @@ WordArray * wordListToWordArray(WordList *list);
WordList * wordArrayToWordList(WordArray * array);
WordList* concatWordList(WordList* list1, WordList* list2);
#endif //FISH_FISH_UTILS_H