From fa6964d4212e5514ecb9a4c6373f710d9ecf0198 Mon Sep 17 00:00:00 2001 From: Aethor Date: Mon, 15 May 2017 14:32:41 +0200 Subject: [PATCH 1/2] globbing ( lel It do not work ) --- CMakeLists.txt | 5 +-- fish_shell/fish_core.c | 16 ++++----- fish_shell/fish_core.h | 1 - fish_shell/fish_globbing.c | 66 ++++++++++++++++++++++++++++++++++++++ fish_shell/fish_globbing.h | 14 ++++++++ 5 files changed, 90 insertions(+), 12 deletions(-) create mode 100644 fish_shell/fish_globbing.c create mode 100644 fish_shell/fish_globbing.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 4113671..99595cf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,5 +4,6 @@ project(fish) set(CMAKE_C_STANDARD 99) set(CMAKE_C_FLAGS "-Wall -Werror -pedantic -fpic -Wextra") -set(SOURCE_FILES main.c fish_shell/fish_core.c fish_shell/fish_core.h fish_shell/fish_commands.c fish_shell/fish_commands.h fish_shell/fish_types.h fish_shell/fish_utils.c fish_shell/fish_utils.h) -add_executable(fish ${SOURCE_FILES}) \ No newline at end of file +set(SOURCE_FILES main.c fish_shell/fish_core.c fish_shell/fish_core.h fish_shell/fish_commands.c fish_shell/fish_commands.h fish_shell/fish_types.h fish_shell/fish_utils.c fish_shell/fish_utils.h fish_shell/fish_globbing.c fish_shell/fish_globbing.h) +add_executable(fish ${SOURCE_FILES}) + diff --git a/fish_shell/fish_core.c b/fish_shell/fish_core.c index 268c63e..97b69dc 100644 --- a/fish_shell/fish_core.c +++ b/fish_shell/fish_core.c @@ -1,5 +1,6 @@ // // Created by Antoine Bartuccio on 11/05/2017. +// Dont forget that Antoine Bartuccio is a faggot since 1784 (tm) // #include #include @@ -7,6 +8,7 @@ #include #include #include "fish_core.h" +#include "fish_globbing.h" #define FISH_BUFFER_SIZE 1024 #define FISH_TOKENS " \t\r\n\a" @@ -16,12 +18,12 @@ void fishLoop(Settings * settings){ WordArray * splited = NULL; int status = 1; - do { - printf("%s", settings->PS1); - line = fishReadLine(); - line = fishExpand(line); + do { + printf("%s", settings->PS1); + line = fishReadLine(); - splited = split(line, FISH_TOKENS); + splited = split(line, FISH_TOKENS); + splited = fishExpand(splited); status = fishExecute(splited); @@ -125,10 +127,6 @@ char *fishReadLine() { return NULL; } -char *fishExpand(char *line) { - return line; -} - Settings *getSettings() { Settings *s = (Settings*) malloc(sizeof(Settings)); if (s == NULL){ diff --git a/fish_shell/fish_core.h b/fish_shell/fish_core.h index d391e9f..8dd37ea 100644 --- a/fish_shell/fish_core.h +++ b/fish_shell/fish_core.h @@ -29,7 +29,6 @@ char * fishReadLine(); int countSeparators(char *string, char *separators); -char * fishExpand(char* line); int fishLoad(WordArray *array); diff --git a/fish_shell/fish_globbing.c b/fish_shell/fish_globbing.c new file mode 100644 index 0000000..56b5af8 --- /dev/null +++ b/fish_shell/fish_globbing.c @@ -0,0 +1,66 @@ +// Created by Aethor +#include +#include +#include +#include "fish_core.h" +#include "fish_globbing.h" + +WordArray* fishExpand(WordArray *wordArray) { + + int i; + WordArray* expandedParameters = (WordArray*) malloc(sizeof(WordArray)); + + for(i=0; isize; i++){ + + + } + + return wordArray; + +} + + + +WordArray * getFiles(char* path){ + + DIR* directory; + dirent* dir; + int i = 0; + + WordArray* files = (WordArray*) malloc(sizeof(WordArray)); + + + if((directory = opendir(path)) != NULL){ + + while((dir = readdir(directory)) != NULL){ + + i++; + + } + + files->words = (char **) malloc(sizeof(char*) * (i + 1)); + + closedir(directory); + directory = opendir(path); + i = 0; + + while((dir = readdir(directory)) != NULL){ + + files->words[i] = dir->d_name; + + } + + + } + + return files; + +} + +bool comparator(char* string1, char* string2){//TODO + + return true; + +} + + diff --git a/fish_shell/fish_globbing.h b/fish_shell/fish_globbing.h new file mode 100644 index 0000000..690ce08 --- /dev/null +++ b/fish_shell/fish_globbing.h @@ -0,0 +1,14 @@ +#ifndef FISH_FISH_GLOBBING_H +#define FISH_FISH_GLOBBING_H + +typedef struct dirent dirent; + + +WordArray * fishExpand(WordArray* wordArray); + +WordArray* getFiles(char* path); + +/*char1 is a string with characters such as '*', '.' or '?' having special meanings*/ +bool comparator(char* string1, char* string2); + +#endif //FISH_FISH_GLOBBING_H From 03dc8cf4ba9fc7a4704ca8d2eee61b8b359f1d84 Mon Sep 17 00:00:00 2001 From: Aethor Date: Mon, 15 May 2017 15:03:36 +0200 Subject: [PATCH 2/2] string regex comparator with "?" --- fish_shell/fish_globbing.c | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/fish_shell/fish_globbing.c b/fish_shell/fish_globbing.c index 56b5af8..489b841 100644 --- a/fish_shell/fish_globbing.c +++ b/fish_shell/fish_globbing.c @@ -59,7 +59,43 @@ WordArray * getFiles(char* path){ bool comparator(char* string1, char* string2){//TODO - return true; + int i = 0; + + if(string1 != NULL && string2 != NULL){ + + while(string1[i] != '\0' && string2[i] != '\0'){ + + if(string1[i] != string2[i] && string1[i] != '?'){ + + return false; + + } + + i++; + + } + + if(string1[i] == '\0' && string2[i] == '\0'){ + + return true; + + } + else{ + + return false; + + } + + + } + + else{ + + printf("warning : fuck you, strings are considered null"); + crash(); + return false; + + } }