From fa6964d4212e5514ecb9a4c6373f710d9ecf0198 Mon Sep 17 00:00:00 2001 From: Aethor Date: Mon, 15 May 2017 14:32:41 +0200 Subject: [PATCH 1/6] 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/6] 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; + + } } From 32a485860a0e000733cbd3fba74f920e8406b8fc Mon Sep 17 00:00:00 2001 From: Aethor Date: Mon, 15 May 2017 14:32:41 +0200 Subject: [PATCH 3/6] 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 73e384c..59d94c2 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); @@ -113,10 +115,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 6e31133..cca1b34 100644 --- a/fish_shell/fish_core.h +++ b/fish_shell/fish_core.h @@ -28,7 +28,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 3a87b110b6627947c78cbd41e02450f953fad045 Mon Sep 17 00:00:00 2001 From: Aethor Date: Mon, 15 May 2017 15:03:36 +0200 Subject: [PATCH 4/6] 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; + + } } From 7d2c33acefb413237c7bb528bb4cfbeb845a9c0b Mon Sep 17 00:00:00 2001 From: Aethor Date: Mon, 15 May 2017 16:34:40 +0200 Subject: [PATCH 5/6] regex motor is rouling comme une pierre --- fish_shell/fish_globbing.c | 49 +++++++++++++++++++++++++++++--------- fish_shell/fish_globbing.h | 2 +- 2 files changed, 39 insertions(+), 12 deletions(-) diff --git a/fish_shell/fish_globbing.c b/fish_shell/fish_globbing.c index 489b841..96fd193 100644 --- a/fish_shell/fish_globbing.c +++ b/fish_shell/fish_globbing.c @@ -8,10 +8,17 @@ WordArray* fishExpand(WordArray *wordArray) { int i; - WordArray* expandedParameters = (WordArray*) malloc(sizeof(WordArray)); + //int j; + WordArray* splitParameter; - for(i=0; isize; i++){ + for(i=1; isize; i++){ + splitParameter = split(wordArray->words[i], "/"); + printf("%s", splitParameter->words[0]); + + /*for(j=0; isize; j++){ + printf("%s", splitParameter->words[j]); + }*/ } @@ -57,32 +64,52 @@ WordArray * getFiles(char* path){ } -bool comparator(char* string1, char* string2){//TODO +int comparator(char* string1, char* string2){//TODO int i = 0; + char tempIChar; + int j = 0; if(string1 != NULL && string2 != NULL){ - while(string1[i] != '\0' && string2[i] != '\0'){ - - if(string1[i] != string2[i] && string1[i] != '?'){ + while(string1[i] != '\0' && string2[j] != '\0'){ - return false; + if(string1[i] == '*'){ + + tempIChar = string1[i+1]; + + while(string2[j] != tempIChar){ + + j++; + + if(string2[j] == '\0' && tempIChar == '\0'){ + return 1; + } + + } + i++; + + } + + if(string1[i] != string2[j] && string1[i] != '?'){ + + return 0; } i++; + j++; } - if(string1[i] == '\0' && string2[i] == '\0'){ + if(string1[i] == '\0' && string2[j] == '\0'){ - return true; + return 1; } else{ - return false; + return 0; } @@ -93,7 +120,7 @@ bool comparator(char* string1, char* string2){//TODO printf("warning : fuck you, strings are considered null"); crash(); - return false; + return 0; } diff --git a/fish_shell/fish_globbing.h b/fish_shell/fish_globbing.h index 690ce08..0e70a26 100644 --- a/fish_shell/fish_globbing.h +++ b/fish_shell/fish_globbing.h @@ -9,6 +9,6 @@ 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); +int comparator(char* string1, char* string2); #endif //FISH_FISH_GLOBBING_H From 4ead7dbb93f7e996d813bd4715bba606ecd6b72b Mon Sep 17 00:00:00 2001 From: Aethor Date: Mon, 15 May 2017 16:39:48 +0200 Subject: [PATCH 6/6] ehorihze --- fish_shell/fish_globbing.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fish_shell/fish_globbing.c b/fish_shell/fish_globbing.c index efa75a6..639dc7c 100644 --- a/fish_shell/fish_globbing.c +++ b/fish_shell/fish_globbing.c @@ -8,7 +8,7 @@ WordArray* fishExpand(WordArray *wordArray) { int i; - WordArray* splitParameter; + //WordArray* splitParameter; for(i=1; isize; i++){