shlvl
This commit is contained in:
@ -6,7 +6,7 @@
|
|||||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/02/18 18:29:20 by marde-vr #+# #+# */
|
/* Created: 2024/02/18 18:29:20 by marde-vr #+# #+# */
|
||||||
/* Updated: 2024/04/23 12:49:46 by tomoron ### ########.fr */
|
/* Updated: 2024/04/24 13:03:32 by tomoron ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -88,9 +88,10 @@ t_env *export_set_env(t_env *env, char *name, char *value, int append)
|
|||||||
t_env *tmp;
|
t_env *tmp;
|
||||||
|
|
||||||
tmp = env;
|
tmp = env;
|
||||||
if (!value)
|
if (!value || !name)
|
||||||
{
|
{
|
||||||
free(name);
|
free(name);
|
||||||
|
free(value);
|
||||||
ft_printf_fd(2, "minishell: malloc failed");
|
ft_printf_fd(2, "minishell: malloc failed");
|
||||||
return (env);
|
return (env);
|
||||||
}
|
}
|
||||||
|
18
srcs/main.c
18
srcs/main.c
@ -6,7 +6,7 @@
|
|||||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/02/02 21:59:20 by tomoron #+# #+# */
|
/* Created: 2024/02/02 21:59:20 by tomoron #+# #+# */
|
||||||
/* Updated: 2024/04/23 14:33:16 by tomoron ### ########.fr */
|
/* Updated: 2024/04/24 13:05:21 by tomoron ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -71,6 +71,21 @@ t_env *get_env(char **envp)
|
|||||||
return (env);
|
return (env);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
t_env *add_shlvl(t_env *env)
|
||||||
|
{
|
||||||
|
int nb;
|
||||||
|
char *tmp;
|
||||||
|
|
||||||
|
tmp = ft_get_env(env, "SHLVL");
|
||||||
|
if(!tmp)
|
||||||
|
nb = 0;
|
||||||
|
else
|
||||||
|
nb = ft_atoi(tmp);
|
||||||
|
nb++;
|
||||||
|
env = export_set_env(env, ft_strdup("SHLVL"), ft_itoa(nb), 0);
|
||||||
|
return(env);
|
||||||
|
}
|
||||||
|
|
||||||
int init_minishell(t_msh **msh, int argc, char **argv, char **envp)
|
int init_minishell(t_msh **msh, int argc, char **argv, char **envp)
|
||||||
{
|
{
|
||||||
struct termios t_p;
|
struct termios t_p;
|
||||||
@ -81,6 +96,7 @@ int init_minishell(t_msh **msh, int argc, char **argv, char **envp)
|
|||||||
(void)argc;
|
(void)argc;
|
||||||
(void)argv;
|
(void)argv;
|
||||||
(*msh)->env = get_env(envp);
|
(*msh)->env = get_env(envp);
|
||||||
|
(*msh)->env = add_shlvl((*msh)->env);
|
||||||
tcgetattr(1, &t_p);
|
tcgetattr(1, &t_p);
|
||||||
(*msh)->echoctl = t_p.c_lflag & ECHOCTL;
|
(*msh)->echoctl = t_p.c_lflag & ECHOCTL;
|
||||||
signal(SIGINT, signal_handler_interactive); //enables ctrl-C
|
signal(SIGINT, signal_handler_interactive); //enables ctrl-C
|
||||||
|
Reference in New Issue
Block a user