diff options
Diffstat (limited to '')
-rw-r--r-- | src/s_init.c (renamed from src/ft_s_init.c) | 39 |
1 files changed, 27 insertions, 12 deletions
diff --git a/src/ft_s_init.c b/src/s_init.c index f3ebaf6..a0ea9a3 100644 --- a/src/ft_s_init.c +++ b/src/s_init.c @@ -1,7 +1,7 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* ft_s_init.c :+: :+: :+: */ +/* s_init.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ @@ -15,13 +15,14 @@ #include <stdlib.h> #include <unistd.h> -#include "ft_d_define.h" -#include "ft_m_funptr.h" -#include "ft_s_init.h" -#include "ft_u_vars.h" +#include "d_define.h" +#include "m_funptr.h" +#include "s_init.h" +#include "u_vars.h" +#include "u_vars_next.h" static char - **ft_dupenv_del(char **nenvp, + **dupenv_del(char **nenvp, uint64_t i) { while (i > 0) @@ -34,7 +35,7 @@ static char } static char - **ft_dupenv(char *const envp[]) + **dupenv(char *const envp[]) { uint64_t i; char **nenvp; @@ -52,15 +53,28 @@ static char while (envp[i]) { if (!(nenvp[i] = ft_strdup(envp[i]))) - return (ft_dupenv_del(nenvp, i)); + return (dupenv_del(nenvp, i)); i++; } nenvp[i] = NULL; return (nenvp); } +static void + inc_shlvl(t_msh *msh) +{ + char *str_one; + char *str_two; + + u_subst_var_value("$SHLVL", + str_one = ft_itoa( + ft_atoi(str_two = u_get_var_value("$SHLVL", msh)) + 1), msh); + ft_memdel((void*)&str_one); + ft_memdel((void*)&str_two); +} + t_msh - *ft_init_msh(char *const argv[], + *init_msh(char *const argv[], char *const envp[]) { t_msh *msh; @@ -73,13 +87,14 @@ t_msh return (NULL); /* TODO: shname: care about "./", try with symlinks */ msh->envp = NULL; - if (!(msh->envp = ft_dupenv(envp))) + if (!(msh->envp = dupenv(envp))) return (NULL); msh->cwd = NULL; - msh->cwd = ft_subst_var_value("$PWD", msh); + msh->cwd = u_get_var_value("$PWD", msh); msh->ret = 0; - ft_init_buptr(msh); + init_buptr(msh); msh->curr = NULL; msh->vars = NULL; + inc_shlvl(msh); return (msh); } |