diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ft_b_echo.c | 2 | ||||
-rw-r--r-- | src/ft_b_echo.h | 4 | ||||
-rw-r--r-- | src/ft_b_env.c | 9 | ||||
-rw-r--r-- | src/ft_b_env.h | 4 | ||||
-rw-r--r-- | src/ft_d_define.h | 13 | ||||
-rw-r--r-- | src/ft_e_lcom.c | 2 | ||||
-rw-r--r-- | src/ft_e_lcom.h | 2 | ||||
-rw-r--r-- | src/ft_f_fail.c | 36 | ||||
-rw-r--r-- | src/ft_f_fail.h | 19 | ||||
-rw-r--r-- | src/ft_m_funptr.c | 3 | ||||
-rw-r--r-- | src/ft_m_loop.c | 2 | ||||
-rw-r--r-- | src/ft_m_loop.h | 2 | ||||
-rw-r--r-- | src/ft_p_line.c | 3 | ||||
-rw-r--r-- | src/ft_s_struct.h | 4 | ||||
-rw-r--r-- | src/minishell.c | 4 |
15 files changed, 93 insertions, 16 deletions
diff --git a/src/ft_b_echo.c b/src/ft_b_echo.c index d5e4a64..326967d 100644 --- a/src/ft_b_echo.c +++ b/src/ft_b_echo.c @@ -14,7 +14,7 @@ #include <stdint.h> #include "ft_s_struct.h" -int32_t +uint8_t ft_b_echo(char *args[], t_msh *msh) { diff --git a/src/ft_b_echo.h b/src/ft_b_echo.h index 07da189..7fd7463 100644 --- a/src/ft_b_echo.h +++ b/src/ft_b_echo.h @@ -16,7 +16,7 @@ #include <stdint.h> #include "ft_s_struct.h" -int32_t ft_b_echo(char *args[], - t_msh *msh); +uint8_t ft_b_echo(char *args[], + t_msh *msh); #endif diff --git a/src/ft_b_env.c b/src/ft_b_env.c index eb3b107..d3df62d 100644 --- a/src/ft_b_env.c +++ b/src/ft_b_env.c @@ -13,15 +13,20 @@ #include <libft.h> #include <stdint.h> #include "ft_b_env.h" +#include "ft_f_fail.h" #include "ft_s_struct.h" -int32_t +uint8_t ft_b_env(char *args[], t_msh *msh) { char **ptr; - (void)args; + if (args[0]) + { + ft_fail_no_options("env"); + return (127); + } ptr = msh->envp; while (*ptr) { diff --git a/src/ft_b_env.h b/src/ft_b_env.h index 3e843b0..192c5d9 100644 --- a/src/ft_b_env.h +++ b/src/ft_b_env.h @@ -16,7 +16,7 @@ #include <stdint.h> #include "ft_s_struct.h" -int32_t ft_b_env(char *args[], - t_msh *msh); +uint8_t ft_b_env(char *args[], + t_msh *msh); #endif diff --git a/src/ft_d_define.h b/src/ft_d_define.h index b30be21..e5ef970 100644 --- a/src/ft_d_define.h +++ b/src/ft_d_define.h @@ -13,8 +13,21 @@ #ifndef FT_D_DEFINE_H #define FT_D_DEFINE_H +#include "ft_d_enum.h" + +/* +** ====== CLASSICS ====== +*/ + #define FT_PS_ONE "minishell ~> " #define FT_BUILTINS "echo|cd|pwd|export|unset|env|exit|cat" #define FT_BUILTINS_COUNT 8 +/* +** ====== FAIL MSG ====== +*/ + +#define FT_FAIL_ALLOC "failed to allocate memory" +#define FT_FAIL_NO_OPTIONS "no options required" + #endif diff --git a/src/ft_e_lcom.c b/src/ft_e_lcom.c index b928004..409cbb1 100644 --- a/src/ft_e_lcom.c +++ b/src/ft_e_lcom.c @@ -29,7 +29,7 @@ static uint8_t return (i); } -int32_t +uint8_t ft_e_lcom(t_msh *msh) { t_lcom *ptr; diff --git a/src/ft_e_lcom.h b/src/ft_e_lcom.h index ccb1db4..5724544 100644 --- a/src/ft_e_lcom.h +++ b/src/ft_e_lcom.h @@ -16,6 +16,6 @@ #include <stdint.h> #include "ft_s_struct.h" -int32_t ft_e_lcom(t_msh *msh); +uint8_t ft_e_lcom(t_msh *msh); #endif diff --git a/src/ft_f_fail.c b/src/ft_f_fail.c new file mode 100644 index 0000000..aed16d0 --- /dev/null +++ b/src/ft_f_fail.c @@ -0,0 +1,36 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_f_fail.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/14 17:19:27 by rbousset #+# #+# */ +/* Updated: 2020/02/14 17:19:29 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#include <libft.h> +#include <stdlib.h> +#include <unistd.h> +#include "ft_d_define.h" + +static void + ft_write_fail(const char concern[], + const char msg[]) +{ + ft_dprintf(STDERR_FILENO, "%s: %s\n", concern, msg); +} + +void + ft_fail_no_options(const char concern[]) +{ + ft_write_fail(concern, FT_FAIL_NO_OPTIONS); +} + +void + ft_fail_alloc(void) +{ + ft_write_fail("minishell", FT_FAIL_ALLOC); + exit(FT_RET_ALLOC); +} diff --git a/src/ft_f_fail.h b/src/ft_f_fail.h new file mode 100644 index 0000000..f34fd25 --- /dev/null +++ b/src/ft_f_fail.h @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_f_fail.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/14 17:19:27 by rbousset #+# #+# */ +/* Updated: 2020/02/14 17:19:29 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_F_FAIL_H +#define FT_F_FAIL_H + +void ft_fail_no_options(const char concern[]); +void ft_fail_alloc(void); + +#endif diff --git a/src/ft_m_funptr.c b/src/ft_m_funptr.c index a9e7882..813e5a3 100644 --- a/src/ft_m_funptr.c +++ b/src/ft_m_funptr.c @@ -15,6 +15,7 @@ #include "ft_b_echo.h" #include "ft_b_env.h" #include "ft_d_enum.h" +#include "ft_f_fail.h" #include "ft_m_funptr.h" #include "ft_s_struct.h" @@ -31,6 +32,6 @@ void /* msh->bu_ptr[7] = ft_b_cat; */ if (!(msh->bu_ref = ft_split(FT_BUILTINS, '|'))) { - exit(FT_RET_ALLOC); + ft_fail_alloc(); } } diff --git a/src/ft_m_loop.c b/src/ft_m_loop.c index 10a4f5e..b156b08 100644 --- a/src/ft_m_loop.c +++ b/src/ft_m_loop.c @@ -20,7 +20,7 @@ #include "ft_p_line.h" #include "ft_s_lcom.h" -int32_t +uint8_t ft_m_loop(t_msh *msh) { int8_t gnl; diff --git a/src/ft_m_loop.h b/src/ft_m_loop.h index 564d447..b7a6b12 100644 --- a/src/ft_m_loop.h +++ b/src/ft_m_loop.h @@ -16,6 +16,6 @@ #include <stdint.h> #include "ft_s_struct.h" -int32_t ft_m_loop(t_msh *msh); +uint8_t ft_m_loop(t_msh *msh); #endif diff --git a/src/ft_p_line.c b/src/ft_p_line.c index f299f64..df31973 100644 --- a/src/ft_p_line.c +++ b/src/ft_p_line.c @@ -13,6 +13,7 @@ #include <libft.h> #include <stdlib.h> #include "ft_d_enum.h" +#include "ft_f_fail.h" #include "ft_p_lcom.h" #include "ft_p_line.h" #include "ft_s_struct.h" @@ -36,6 +37,6 @@ void } if (ft_p_lcom(line, count, msh) < 0) { - exit(FT_RET_ALLOC); + ft_fail_alloc(); } } diff --git a/src/ft_s_struct.h b/src/ft_s_struct.h index 9719a6f..1f062c2 100644 --- a/src/ft_s_struct.h +++ b/src/ft_s_struct.h @@ -27,9 +27,9 @@ typedef struct s_msh { char *ps_one; char **envp; - int32_t ret; + uint8_t ret; char **bu_ref; - int32_t (*bu_ptr[FT_BUILTINS_COUNT])(char **, struct s_msh*); + uint8_t (*bu_ptr[FT_BUILTINS_COUNT])(char **, struct s_msh*); struct s_lcom *curr; } t_msh; diff --git a/src/minishell.c b/src/minishell.c index 4b8e763..fc4c4be 100644 --- a/src/minishell.c +++ b/src/minishell.c @@ -14,6 +14,7 @@ #include <stdint.h> #include "minishell.h" #include "ft_d_enum.h" +#include "ft_f_fail.h" #include "ft_m_loop.h" #include "ft_s_struct.h" #include "ft_s_init.h" @@ -31,7 +32,7 @@ int (void)argv; if (!(msh = ft_init_msh(envp))) { - return (FT_RET_ALLOC); + ft_fail_alloc(); } msh->ret = ft_m_loop(msh); ret = msh->ret; @@ -47,6 +48,7 @@ int ** b_ -> builtins related ** d_ -> defines related ** e_ -> exec related +** f_ -> failure related ** m_ -> core minishell related ** p_ -> parse related ** s_ -> structs related |