diff options
Diffstat (limited to 'src/s_init.c')
-rw-r--r-- | src/s_init.c | 58 |
1 files changed, 32 insertions, 26 deletions
diff --git a/src/s_init.c b/src/s_init.c index 1e86727..1536cd1 100644 --- a/src/s_init.c +++ b/src/s_init.c @@ -20,6 +20,7 @@ #include <unistd.h> #include "b_export_next.h" +#include "s_set_cwd.h" #include "d_define.h" #include "f_fail.h" #include "m_funptr.h" @@ -27,7 +28,8 @@ #include "u_vars.h" #include "u_vars_next.h" -static void s_init_sqb_ref_one(t_msh *msh) +static void + s_init_sqb_ref_one(t_msh *msh) { (void)ft_memcpy(msh->sqb_ref[B_ID_SQB_B], B_SQB_B, (ft_strlen(B_SQB_B) + 1) * sizeof(char)); @@ -55,7 +57,8 @@ static void s_init_sqb_ref_one(t_msh *msh) (ft_strlen(B_SQB_X) + 1) * sizeof(char)); } -static void s_init_sqb_ref_two(t_msh *msh) +static void + s_init_sqb_ref_two(t_msh *msh) { (void)ft_memcpy(msh->sqb_ref[B_ID_SQB_Z], B_SQB_Z, (ft_strlen(B_SQB_Z) + 1) * sizeof(char)); @@ -83,13 +86,8 @@ static void s_init_sqb_ref_two(t_msh *msh) (ft_strlen(B_SQB_LT) + 1) * sizeof(char)); } -static void s_init_sqb_ref_thr(t_msh *msh) -{ - (void)ft_memcpy(msh->sqb_ref[B_ID_SQB_LE], B_SQB_LE, - (ft_strlen(B_SQB_LE) + 1) * sizeof(char)); -} - -static void s_null_some(t_msh *msh) +static void + s_null_some(t_msh *msh) { msh->fd = 0; msh->curr = NULL; @@ -100,23 +98,9 @@ static void s_null_some(t_msh *msh) msh->prev_hist = NULL; } -t_msh *s_init_msh(int argc, char *const argv[], char *const envp[]) +static t_msh + *s_init_msh_next(char *cwd, t_msh *msh) { - t_msh *msh; - char cwd[PATH_MAX]; - - if ((msh = (t_msh*)malloc(sizeof(t_msh))) == NULL) - return (NULL); - msh->envp = NULL; - (void)envp; - if ((msh->envp = s_dupenv(envp)) == NULL) - { - ft_memdel((void*)&msh); - return (NULL); - } - msh->argc = argc - 1; - msh->argv = (char**)argv; - msh->ret = 0; m_init_buptr(msh); s_null_some(msh); s_set_cwd(cwd, msh); @@ -135,6 +119,28 @@ t_msh *s_init_msh(int argc, char *const argv[], char *const envp[]) } s_init_sqb_ref_one(msh); s_init_sqb_ref_two(msh); - s_init_sqb_ref_thr(msh); + (void)ft_memcpy(msh->sqb_ref[B_ID_SQB_LE], B_SQB_LE, + (ft_strlen(B_SQB_LE) + 1) * sizeof(char)); return (msh); } + +t_msh + *s_init_msh(int argc, char *const argv[], char *const envp[]) +{ + t_msh *msh; + char cwd[PATH_MAX]; + + if ((msh = (t_msh*)malloc(sizeof(t_msh))) == NULL) + return (NULL); + msh->envp = NULL; + (void)envp; + if ((msh->envp = s_dupenv(envp)) == NULL) + { + ft_memdel((void*)&msh); + return (NULL); + } + msh->argc = argc - 1; + msh->argv = (char**)argv; + msh->ret = 0; + return (s_init_msh_next(cwd, msh)); +} |