diff --git a/CMakeLists.txt b/CMakeLists.txt index 4c897d1..4113671 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,5 +4,5 @@ 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) +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 diff --git a/fish_shell/fish_core.c b/fish_shell/fish_core.c index 3269ea0..268c63e 100644 --- a/fish_shell/fish_core.c +++ b/fish_shell/fish_core.c @@ -62,8 +62,7 @@ WordArray * split(char *string, char *separator){ } if (tokens == NULL || to_delete == NULL || tokens->words == NULL){ - fprintf(stderr, "fish: Error allocating fucking pointer !"); - exit(EXIT_FAILURE); + crash(); } while((token = strsep(&to_delete, separator)) != NULL){ @@ -95,8 +94,7 @@ char *fishReadLine() { int c; if (line == NULL){ - fprintf(stderr, "fish: Error allocating fucking buffer shit !"); - exit(EXIT_FAILURE); + crash(); } while (1){ @@ -118,8 +116,7 @@ char *fishReadLine() { bufferSize+=bufferSize; line = realloc(line, bufferSize); if (line == NULL){ - fprintf(stderr, "fish: Error allocating fucking buffer shit !"); - exit(EXIT_FAILURE); + crash(); } } } @@ -135,8 +132,7 @@ char *fishExpand(char *line) { Settings *getSettings() { Settings *s = (Settings*) malloc(sizeof(Settings)); if (s == NULL){ - fprintf(stderr, "fish: Error allocating fucking settings"); - exit(EXIT_FAILURE); + crash(); } s->PS1 = strdup("\n~>"); diff --git a/fish_shell/fish_core.h b/fish_shell/fish_core.h index 6173064..d391e9f 100644 --- a/fish_shell/fish_core.h +++ b/fish_shell/fish_core.h @@ -8,6 +8,7 @@ #include "fish_types.h" #include "fish_commands.h" +#include "fish_utils.h" /* WordArray functions */ diff --git a/fish_shell/fish_utils.c b/fish_shell/fish_utils.c new file mode 100644 index 0000000..ef59f02 --- /dev/null +++ b/fish_shell/fish_utils.c @@ -0,0 +1,11 @@ +// +// Created by Antoine Bartuccio on 15/05/2017. +// + +#include +#include + +void crash(){ + fprintf(stderr, "fish: Error allocating fucking pointer !"); + exit(EXIT_FAILURE); +} diff --git a/fish_shell/fish_utils.h b/fish_shell/fish_utils.h new file mode 100644 index 0000000..27de991 --- /dev/null +++ b/fish_shell/fish_utils.h @@ -0,0 +1,10 @@ +// +// Created by Antoine Bartuccio on 15/05/2017. +// + +#ifndef FISH_FISH_UTILS_H +#define FISH_FISH_UTILS_H + +void crash(); + +#endif //FISH_FISH_UTILS_H