Skip to content

Commit

Permalink
Norm compliant πŸŽ‰πŸŽ‰
Browse files Browse the repository at this point in the history
  • Loading branch information
LithiumOx committed Nov 22, 2023
1 parent bbfb7e8 commit 935f741
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 35 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
NAME = minishell
SRC = main \
utils/error \
utils/error_extra \
utils/miscellaneous \
structs/token \
structs/env \
Expand Down
4 changes: 3 additions & 1 deletion includes/minishell.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: mdekker/jde-baai <team@codam.nl> +#+ */
/* +#+ */
/* 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 */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -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);
Expand Down
37 changes: 3 additions & 34 deletions src/utils/error.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: mdekker/jde-baai <team@codam.nl> +#+ */
/* +#+ */
/* 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 */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
}
55 changes: 55 additions & 0 deletions src/utils/error_extra.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/* ************************************************************************** */
/* */
/* :::::::: */
/* error_extra.c :+: :+: */
/* +:+ */
/* By: mdekker/jde-baai <team@codam.nl> +#+ */
/* +#+ */
/* Created: 2023/11/22 22:29:17 by mdekker/jde #+# #+# */
/* Updated: 2023/11/22 22:36:19 by mdekker/jde ######## odam.nl */
/* */
/* ************************************************************************** */

#include <minishell.h>

/**
* @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;
}
}

0 comments on commit 935f741

Please sign in to comment.