diff --git a/42sh/Makefile b/42sh/Makefile index aa57f27a..bf50e0d4 100644 --- a/42sh/Makefile +++ b/42sh/Makefile @@ -6,14 +6,14 @@ # By: wescande +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2016/08/29 21:32:58 by wescande #+# #+# # -# Updated: 2017/03/23 00:29:22 by ariard ### ########.fr # +# Updated: 2017/03/23 00:55:25 by ariard ### ########.fr # # # # **************************************************************************** # NAME = 42sh CC = gcc -FLAGS = -Wall -Wextra -Werror -fvisibility=hidden -fsanitize=address +FLAGS = -Wall -Wextra -Werror #-fvisibility=hidden #-fsanitize=address D_FLAGS = -g DELTA = $$(echo "$$(tput cols)-47"|bc) diff --git a/42sh/log b/42sh/log new file mode 100644 index 00000000..4bb9c0c4 --- /dev/null +++ b/42sh/log @@ -0,0 +1,63 @@ +env lvl 2 +env lvl 3 +env lvl 4 +env lvl 5 +env lvl 6 +env lvl 7 +env lvl 8 +env lvl 7 +env lvl 8 +env lvl 9 +env lvl 6 +env lvl 7 +env lvl 8 +env lvl 9 +env lvl 8 +env lvl 9 +env lvl 10 +env lvl 5 +env lvl 6 +env lvl 7 +env lvl 8 +env lvl 9 +env lvl 8 +env lvl 9 +env lvl 10 +env lvl 7 +env lvl 8 +env lvl 9 +env lvl 10 +env lvl 9 +env lvl 10 +env lvl 11 +env lvl 4 +env lvl 5 +env lvl 6 +env lvl 7 +env lvl 8 +env lvl 9 +env lvl 8 +env lvl 9 +env lvl 10 +env lvl 7 +env lvl 8 +env lvl 9 +env lvl 10 +env lvl 9 +env lvl 10 +env lvl 11 +env lvl 6 +env lvl 7 +env lvl 8 +env lvl 9 +env lvl 10 +env lvl 9 +env lvl 10 +env lvl 11 +env lvl 8 +env lvl 9 +env lvl 10 +env lvl 11 +env lvl 10 +env lvl 11 +env lvl 12 diff --git a/42sh/src/builtin/builtin_math.c b/42sh/src/builtin/builtin_math.c index 9bdb8261..d2916c52 100644 --- a/42sh/src/builtin/builtin_math.c +++ b/42sh/src/builtin/builtin_math.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/17 18:54:00 by ariard #+# #+# */ -/* Updated: 2017/03/22 22:26:37 by jhalford ### ########.fr */ +/* Updated: 2017/03/23 01:08:14 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/exec_var.c b/42sh/src/exec/exec_var.c index 4c63ea9e..8fa2f3b9 100644 --- a/42sh/src/exec/exec_var.c +++ b/42sh/src/exec/exec_var.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 11:12:05 by ariard #+# #+# */ -/* Updated: 2017/03/23 00:30:46 by ariard ### ########.fr */ +/* Updated: 2017/03/23 00:51:22 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,8 +21,10 @@ int exec_var(t_btree **ast) char *equal; node = (*ast)->item; + DG("before"); if (!(av = token_to_argv(node->data.cmd.token, 1))) return (0); + DG("after"); var = av[0]; if ((equal = ft_strchr(av[0], '='))) *equal = 0; diff --git a/42sh/src/exec/plaunch_function.c b/42sh/src/exec/plaunch_function.c index c1b7ca60..8b5da368 100644 --- a/42sh/src/exec/plaunch_function.c +++ b/42sh/src/exec/plaunch_function.c @@ -6,36 +6,34 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/08 03:23:59 by wescande #+# #+# */ -/* Updated: 2017/03/22 19:37:08 by jhalford ### ########.fr */ +/* Updated: 2017/03/23 03:15:20 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -#define FUNCERR_0 SHELL_NAME ":maximum nested function level reached" +#define FUNCERR_0 ":maximum nested function level reached" +#define FUNC_LVL 200 int plaunch_function(t_process *p) { - char *temp; - char *func_lvl; - int value; + static int protection= 0; - func_lvl = ft_sstrstr(data_singleton()->env, "FUNC_LVL"); - if ((temp = func_lvl)) - { - func_lvl += ft_strlenchr(func_lvl, '=') + 1; - if ((value = ft_atoi(func_lvl)) >= 199) - { - ft_strdel(&temp); - return (SH_ERR(FUNCERR_0)); - } - value += 1; - } - else - value = 0; + if (ft_atoi(ft_getenv(data_singleton()->env, "FUNC_LVL")) > 10) + return(SH_ERR(FUNCERR_0)); + + if (protection >= FUNC_LVL) + return(SH_ERR(FUNCERR_0)); + protection++; + +// jack faut qu on parle builtin_setenv("setenv", (char *[]){"env", "FUNC_LVL", - ft_itoa(value), 0}, NULL); + ft_itoa(ft_atoi(ft_getenv(data_singleton()->env, "FUNC_LVL")) + 1), + NULL}, NULL); ft_exec(&p->data.function.content); - builtin_setenv("setenv", (char *[]){"env", "FUNC_LVL", "0", 0}, NULL); + builtin_setenv("setenv", (char *[]){"env", "FUNC_LVL", + ft_itoa(ft_atoi(ft_getenv(data_singleton()->env, "FUNC_LVL")) - 1), + NULL}, NULL); + protection--; return (ft_atoi(ft_getenv(data_singleton()->env, "?"))); } diff --git a/42sh/src/main/data_init.c b/42sh/src/main/data_init.c index 0abc6637..7921b68a 100644 --- a/42sh/src/main/data_init.c +++ b/42sh/src/main/data_init.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/28 19:26:32 by jhalford #+# #+# */ -/* Updated: 2017/03/22 15:55:07 by jhalford ### ########.fr */ +/* Updated: 2017/03/23 03:16:08 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -66,6 +66,9 @@ int data_init(int ac, char **av) data->lst_func = NULL; lexer_init(&data->lexer); parser_init(&data->parser); + if (!ft_getenv(data_singleton()->env, "FUNC_LVL")) + builtin_setenv("setenv", (char *[]){"env", "FUNC_LVL", "-1", + NULL}, NULL); if ((term_name = ft_getenv(data->env, "TERM")) == NULL) { term_name = "dumb";