shlvl_init(), set SHLVL

+ export builtin small change
This commit is contained in:
LuckyLaszlo
2021-12-08 06:36:52 +01:00
parent bcc82aabaf
commit cee6a8962b
5 changed files with 61 additions and 19 deletions

View File

@@ -6,7 +6,7 @@
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/08 09:22:12 by lperrey #+# #+# */
/* Updated: 2021/12/04 15:11:20 by lperrey ### ########.fr */
/* Updated: 2021/12/08 06:27:51 by lperrey ### ########.fr */
/* */
/* ************************************************************************** */
@@ -14,6 +14,7 @@
static char *init_prompt_base(void);
static int init_readline_hook(void);
static int shlvl_init(void);
int init(t_all *c)
{
@@ -24,30 +25,42 @@ int init(t_all *c)
rl_startup_hook = NULL;
environ = ft_dup_2d_arr(environ, (t_dup_f)ft_strdup);
if (!environ)
return (ft_reti_perror(0, "ft_dup_2d_arr(environ) error"));
return (ft_reti_perror(0, "ft_dup_2d_arr(environ)"));
c->path = retrieve_path();
if (!shlvl_init())
return (ft_reti_perror(0, "shlvl_init()"));
c->prompt_base = init_prompt_base();
if (!c->prompt_base)
return (ft_reti_perror(0, "init_prompt_base() error"));
return (ft_reti_perror(0, "init_prompt_base()"));
c->prompt = init_prompt(c->prompt_base);
if (!c->prompt)
return (ft_reti_perror(0, "init_prompt() error"));
return (ft_reti_perror(0, "init_prompt()"));
set_signals_behaviour();
return (1);
}
char **retrieve_path(void)
static int shlvl_init(void)
{
char *path;
char **path_split;
char *tmp;
path = getenv("PATH");
if (!path)
return (ft_retp_print(NULL, "minishell: Warning, $PATH not set\n", 2));
path_split = ft_split(path, ':');
if (!path_split)
return (ft_retp_perror(NULL, "retrieve_path()"));
return (path_split);
tmp = getenv("SHLVL");
if (tmp && ft_isdigit_str(tmp))
{
tmp = ft_itoa(ft_atoi(tmp) + 1);
if (!tmp)
return (0);
tmp = ft_strjoinfree_s2("SHLVL=", tmp);
if (!tmp)
return (0);
if (export_var(tmp) == -1)
return (0);
}
else
{
if (export_var("SHLVL=1") == -1)
return (0);
}
return (1);
}
static char *init_prompt_base(void)