From 935f741ac383db124b6c28515d8364999edf74f0 Mon Sep 17 00:00:00 2001 From: "meesdekker.xyz" Date: Wed, 22 Nov 2023 22:38:35 +0100 Subject: [PATCH] =?UTF-8?q?Norm=20compliant=20=F0=9F=8E=89=F0=9F=8E=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Makefile | 1 + includes/minishell.h | 4 ++- src/utils/error.c | 37 +++------------------------ src/utils/error_extra.c | 55 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 62 insertions(+), 35 deletions(-) create mode 100644 src/utils/error_extra.c diff --git a/Makefile b/Makefile index cacf185..9add77c 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,7 @@ NAME = minishell SRC = main \ utils/error \ + utils/error_extra \ utils/miscellaneous \ structs/token \ structs/env \ diff --git a/includes/minishell.h b/includes/minishell.h index c556083..b0b97ee 100644 --- a/includes/minishell.h +++ b/includes/minishell.h @@ -6,7 +6,7 @@ /* By: mdekker/jde-baai +#+ */ /* +#+ */ /* Created: 2023/07/09 21:25:59 by mdekker #+# #+# */ -/* Updated: 2023/11/22 21:18:08 by mdekker/jde ######## odam.nl */ +/* Updated: 2023/11/22 22:34:36 by mdekker/jde ######## odam.nl */ /* */ /* ************************************************************************** */ @@ -128,7 +128,9 @@ bool compare_env_key(void *item, void *key); void exit_mini(char *str, int exit_code); bool set_err(t_exit type, char *msg, t_shell *data); void exec_err(char *str, t_exit type); +void exec_err_extra(char *str, t_exit type); void write_err(t_shell *data); +void write_err_extra(t_shell *data); bool rm_quotes(t_token *token, bool set_string); bool type_compare(size_t num_args, t_types type, ...); bool filter_operators(void *item); diff --git a/src/utils/error.c b/src/utils/error.c index cb43cc7..22b2b78 100644 --- a/src/utils/error.c +++ b/src/utils/error.c @@ -6,7 +6,7 @@ /* By: mdekker/jde-baai +#+ */ /* +#+ */ /* Created: 2023/07/19 21:42:24 by mdekker/jde #+# #+# */ -/* Updated: 2023/11/22 22:07:56 by mdekker/jde ######## odam.nl */ +/* Updated: 2023/11/22 22:33:11 by mdekker/jde ######## odam.nl */ /* */ /* ************************************************************************** */ @@ -64,24 +64,7 @@ void write_err(t_shell *data) write(STDERR_FILENO, "\n", 1); data->error_type = CATCH_ALL; } - if (data->exit_type == SYNTAX) - { - write(STDERR_FILENO, "minishell: syntax error near unexpected token `", - 48); - write(STDERR_FILENO, data->exit_msg, ft_strlen(data->exit_msg)); - write(STDERR_FILENO, "'\n", 2); - data->error_type = SYNTAX_ERROR; - } - if (data->exit_type == SYNTAX_MINI) - { - write(STDERR_FILENO, "minishell: syntax error: unfinished quote\n", 43); - data->error_type = 2; - } - if (data->exit_type == OUT_OF_SCOPE) - { - write(2, "minishell: operators: () ; \\ & ||: out of scope\n", 49); - data->error_type = 2; - } + write_err_extra(data); if (data->exit_type == SIGNAL_C) data->error_type = 130; } @@ -110,19 +93,5 @@ void exec_err(char *str, t_exit type) write(STDERR_FILENO, ": command not found\n", 21); exit(127); } - if (type == PERMISSION) - { - write(STDERR_FILENO, "minishell: ", 12); - write(STDERR_FILENO, str, ft_strlen(str)); - write(STDERR_FILENO, ": Permission denied\n", 21); - exit(1); // Dit moet 126 zijn, - // maar dan werkt de test niet check even of dit daadwerkelijk zo is - } - if (type == NO_SUCH) - { - write(STDERR_FILENO, "minishell: ", 12); - write(STDERR_FILENO, str, ft_strlen(str)); - write(STDERR_FILENO, ": No such file or directory\n", 29); - exit(1); - } + exec_err_extra(str, type); } diff --git a/src/utils/error_extra.c b/src/utils/error_extra.c new file mode 100644 index 0000000..e647047 --- /dev/null +++ b/src/utils/error_extra.c @@ -0,0 +1,55 @@ +/* ************************************************************************** */ +/* */ +/* :::::::: */ +/* error_extra.c :+: :+: */ +/* +:+ */ +/* By: mdekker/jde-baai +#+ */ +/* +#+ */ +/* Created: 2023/11/22 22:29:17 by mdekker/jde #+# #+# */ +/* Updated: 2023/11/22 22:36:19 by mdekker/jde ######## odam.nl */ +/* */ +/* ************************************************************************** */ + +#include + +/** + * @info NO_SUCH is volgens de tester 1 niet 126 + */ +void exec_err_extra(char *str, t_exit type) +{ + if (type == PERMISSION) + { + write(STDERR_FILENO, "minishell: ", 12); + write(STDERR_FILENO, str, ft_strlen(str)); + write(STDERR_FILENO, ": Permission denied\n", 21); + exit(1); + } + if (type == NO_SUCH) + { + write(STDERR_FILENO, "minishell: ", 12); + write(STDERR_FILENO, str, ft_strlen(str)); + write(STDERR_FILENO, ": No such file or directory\n", 29); + exit(1); + } +} + +void write_err_extra(t_shell *data) +{ + if (data->exit_type == SYNTAX) + { + write(2, "minishell: syntax error near unexpected token `", 48); + write(STDERR_FILENO, data->exit_msg, ft_strlen(data->exit_msg)); + write(STDERR_FILENO, "'\n", 2); + data->error_type = SYNTAX_ERROR; + } + if (data->exit_type == SYNTAX_MINI) + { + write(STDERR_FILENO, "minishell: syntax error: unfinished quote\n", 43); + data->error_type = 2; + } + if (data->exit_type == OUT_OF_SCOPE) + { + write(2, "minishell: operators: () ; \\ & ||: out of scope\n", 49); + data->error_type = 2; + } +}