From 487a66394061f2d14a2fa421302966b5442d643f Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Mon, 27 Jul 2020 18:55:07 +0200 Subject: I couldn't see shit --- src/s_init.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 src/s_init.c (limited to 'src/s_init.c') diff --git a/src/s_init.c b/src/s_init.c new file mode 100644 index 0000000..454cb67 --- /dev/null +++ b/src/s_init.c @@ -0,0 +1,85 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* s_init.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rbousset +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/14 17:19:27 by rbousset #+# #+# */ +/* Updated: 2020/02/14 17:19:29 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include +#include +#include + +#include "d_define.h" +#include "m_funptr.h" +#include "s_init.h" + +static char + **dupenv_del(char **nenvp, + uint64_t i) +{ + while (i > 0) + { + ft_memdel((void*)&nenvp[i]); + i--; + } + ft_memdel((void*)&nenvp); + return (NULL); +} + +static char + **dupenv(char *const envp[]) +{ + uint64_t i; + char **nenvp; + + i = 0; + while (envp[i]) + { + i++; + } + if (!(nenvp = (char**)malloc((i + 1) * sizeof(char*)))) + { + return (NULL); + } + i = 0; + while (envp[i]) + { + if (!(nenvp[i] = ft_strdup(envp[i]))) + return (dupenv_del(nenvp, i)); + i++; + } + nenvp[i] = NULL; + return (nenvp); +} + +t_msh + *init_msh(char *const argv[], + char *const envp[]) +{ + t_msh *msh; + + if (!(msh = (t_msh*)malloc(sizeof(t_msh)))) + return (NULL); + if (!(msh->ps_one = ft_strdup(FT_PS_ONE))) + return (NULL); + if (!(msh->shname = ft_strdup(argv[0]))) + return (NULL); + /* TODO: shname: care about "./", try with symlinks */ + msh->cwd = NULL; + msh->cwd = getcwd(NULL, 0); + /* TODO: handle getcwd failed */ + msh->envp = NULL; + if (!(msh->envp = dupenv(envp))) + return (NULL); + msh->ret = 0; + init_buptr(msh); + msh->curr = NULL; + msh->vars = NULL; + return (msh); +} -- cgit v1.2.3 From bfaf4c53a8406ea0bfbd8699807b567a5322a03f Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Mon, 3 Aug 2020 19:00:47 +0200 Subject: Export is working --- src/s_init.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/s_init.c') diff --git a/src/s_init.c b/src/s_init.c index 454cb67..377cd91 100644 --- a/src/s_init.c +++ b/src/s_init.c @@ -18,6 +18,8 @@ #include "d_define.h" #include "m_funptr.h" #include "s_init.h" +#include "u_vars.h" +#include "u_vars_next.h" static char **dupenv_del(char **nenvp, @@ -58,6 +60,19 @@ static char 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 *init_msh(char *const argv[], char *const envp[]) @@ -81,5 +96,6 @@ t_msh init_buptr(msh); msh->curr = NULL; msh->vars = NULL; + inc_shlvl(msh); return (msh); } -- cgit v1.2.3