1
0
mirror of https://gitlab.com/klmp200/fish.git synced 2024-11-13 04:13:19 +00:00

ça core dump quelque peu

This commit is contained in:
Aethor 2017-05-16 07:32:19 +02:00
parent 83f695c538
commit c1e13ab7c8
5 changed files with 76 additions and 8 deletions

View File

@ -158,8 +158,13 @@ int fishExecute(WordArray *array) {
return 1;
for (i=0; i < getNbBuiltins(); i++){
if (!strcmp(array->words[0], getBuiltinCommandsStr()[i])){
return getBuiltinCommands()[i](array);
if(array->words[0] != NULL){
if (!strcmp(array->words[0], getBuiltinCommandsStr()[i])){
return getBuiltinCommands()[i](array);
}
}
else{
crash();
}
}

View File

@ -2,18 +2,59 @@
#include <stdio.h>
#include <stdlib.h>
#include <dirent.h>
#include <string.h>
#include "fish_core.h"
#include "fish_globbing.h"
WordList * fishExpand(WordList *wordArray) {
WordList * fishExpand(WordList *wordList) {
wordArray = expandInDir("./", "*");
if(wordList->size > 1){
int i;
return wordArray;
WordList* newWordList = createWordList();
if(newWordList == NULL){
crash();
}
newWordList->first = wordList->first;
newWordList->size = 0;
WordListElement* tempElement = wordList->first->next;
for(i=0; i<wordList->size; i++){
//newWordList = concatWordList(newWordList, recursiveExpand(tempElement->word));
//newWordList = concatWordList(newWordList, NULL);
if(tempElement != NULL){
tempElement = tempElement->next;
}
}
return newWordList;
}
else return wordList;
}
WordList* recursiveExpand(char * completePath){
if (stringContains(completePath, '/')){
return expandInDir("./",completePath);
}
return NULL;
}
WordArray * getFiles(char* path){
@ -21,6 +62,7 @@ WordArray * getFiles(char* path){
dirent* dir;
int i = 0;
WordArray* files = (WordArray*) malloc(sizeof(WordArray));
@ -40,14 +82,14 @@ WordArray * getFiles(char* path){
while((dir = readdir(directory)) != NULL){
/*if(dir->d_name != "." && dir->d_name != ".."){*/
if(!strcmp(dir->d_name, ".") && !strcmp(dir->d_name, "..")){
printf("%s\n", dir->d_name);
files->words[i] = dir->d_name;
i++;
files->size++;
//}
}
}

View File

@ -13,4 +13,6 @@ int comparator(char* string1, char* string2);
WordList* expandInDir(char*, char*);
WordList* recursiveExpand(char* completePath);
#endif //FISH_FISH_GLOBBING_H

View File

@ -105,7 +105,8 @@ void freeWordList(WordList *list) {
WordList* concatWordList(WordList* list1, WordList* list2){
if(list1->last != NULL){
if(list1 != NULL && list2 != NULL && list1->size >= 1 && list2->size >=1){
list1->last->next = list2->first;
list2->first->previous = list1->last;
list1->last = list2->last;
@ -155,3 +156,19 @@ WordList *wordArrayToWordList(WordArray *array) {
return list;
}
int stringContains(char * string, char charToTest){
int i = 0;
while(string[i] != '\0'){
if(string[i] != charToTest){
return 0;
}
i++;
}
return 1;
}

View File

@ -27,4 +27,6 @@ WordList * wordArrayToWordList(WordArray * array);
WordList* concatWordList(WordList* list1, WordList* list2);
int stringContains(char* string, char charToTest);
#endif //FISH_FISH_UTILS_H