1
0
mirror of https://gitlab.com/klmp200/fish.git synced 2024-12-22 07:41:08 +00:00

ça core dump quelque peu

This commit is contained in:
Aethor 2017-05-16 07:32:19 +02:00
parent c05b1fe398
commit 7d87fdb235
5 changed files with 79 additions and 16 deletions

View File

@ -194,10 +194,17 @@ int fishExecute(WordList *list) {
int loadRightCommand(WordArray *array){
int i;
if (array->size <= 0) return 1;
for (i = 0; i < getNbBuiltins(); i++) {
if (!strcmp(array->words[0], getBuiltinCommandsStr()[i])) {
return getBuiltinCommands()[i](array);
if (array->size < 0)
return 1;
for (i=0; i < getNbBuiltins(); i++){
if(array->words[0] != NULL){
if (!strcmp(array->words[0], getBuiltinCommandsStr()[i])){
return getBuiltinCommands()[i](array);
}
}
else{
crash();
}
}
return fishLoad(array);

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

@ -30,7 +30,6 @@ char *getInsult(){
static int init = 0;
int picked = 0;
char *insults[] = {
<<<<<<< HEAD
(char *) "Apprend à écrire crétin !",
(char *) "Boloss !",
(char *) "Mois aussi je sais écrire de la merde, pourtant je le fait pas !",
@ -38,11 +37,6 @@ char *getInsult(){
(char *) "Nul !",
(char *) "Pense à aller à l'école un jour",
(char *) "Et après on dit que c'est la faute de l'ordinateur..."
=======
"Apprend à écrire crétin !",
"Bolos !",
"Moi aussi je sais écrire de la merde, pourtant je le fait pas !"
>>>>>>> Black mage of regex stikes again
};
if (!init){
srand((unsigned int) time(NULL));
@ -125,7 +119,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;
@ -285,3 +280,18 @@ WordList *splitWordList(WordList *list, char *regex) {
return new_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

@ -37,4 +37,6 @@ char * splitWord(char * origin, int beginning_index, int size_to_delete); // Tes
WordList* concatWordList(WordList* list1, WordList* list2);
int stringContains(char* string, char charToTest);
#endif //FISH_FISH_UTILS_H