From 16e23e8a632f8e588549391ad27306ec63c7fe3e Mon Sep 17 00:00:00 2001 From: Antoine Riard Date: Wed, 22 Mar 2017 19:35:02 +0100 Subject: [PATCH] close #150 --- 42sh/src/exec/pfree_func.c | 3 +-- 42sh/src/exec/plaunch_function.c | 6 +++--- 42sh/src/main/main.c | 3 +-- 42sh/src/parser/add_func.c | 6 ++++-- 42sh/src/parser/aggregate_sym.c | 7 +------ 42sh/src/parser/eval_sym.c | 3 +-- 42sh/src/parser/produce_sym.c | 2 +- 7 files changed, 12 insertions(+), 18 deletions(-) diff --git a/42sh/src/exec/pfree_func.c b/42sh/src/exec/pfree_func.c index 98e5fe2f..b8a467b7 100644 --- a/42sh/src/exec/pfree_func.c +++ b/42sh/src/exec/pfree_func.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/21 20:18:34 by ariard #+# #+# */ -/* Updated: 2017/03/21 20:53:45 by ariard ### ########.fr */ +/* Updated: 2017/03/22 19:25:38 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,7 +14,6 @@ int pfree_func(t_process *p) { - ft_putstr("hello"); btree_del(&p->data.function.content, &ast_free); return (0); } diff --git a/42sh/src/exec/plaunch_function.c b/42sh/src/exec/plaunch_function.c index 6a41a54a..0d5364de 100644 --- a/42sh/src/exec/plaunch_function.c +++ b/42sh/src/exec/plaunch_function.c @@ -6,13 +6,13 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/08 03:23:59 by wescande #+# #+# */ -/* Updated: 2017/03/22 16:22:34 by gwojda ### ########.fr */ +/* Updated: 2017/03/22 19:30:50 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -#define FUNCERR_0 SHELL_NAME ":maximum nested function level reached\n" +#define FUNCERR_0 SHELL_NAME ":maximum nested function level reached" int plaunch_function(t_process *p) { @@ -36,6 +36,6 @@ int plaunch_function(t_process *p) builtin_setenv("setenv", (char *[]){"env", "FUNC_LVL", ft_itoa(value), 0}, NULL); ft_exec(&p->data.function.content); - DG(); + builtin_setenv("setenv", (char *[]){"env", "FUNC_LVL", "0", 0}, NULL); return (ft_atoi(ft_getenv(data_singleton()->env, "?"))); } diff --git a/42sh/src/main/main.c b/42sh/src/main/main.c index 23405356..60194ede 100644 --- a/42sh/src/main/main.c +++ b/42sh/src/main/main.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/20 14:45:40 by gwojda #+# #+# */ -/* Updated: 2017/03/22 17:44:44 by jhalford ### ########.fr */ +/* Updated: 2017/03/22 19:00:39 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -43,7 +43,6 @@ static int handle_instruction(t_list **token, t_btree **ast) return (ret); if (do_lexer_routine(token, stream) > 0) continue ; - token_print(*token); if ((ret = do_parser_routine(token, ast)) == 1 && SH_NO_INTERACTIVE(data->opts)) return (ret); diff --git a/42sh/src/parser/add_func.c b/42sh/src/parser/add_func.c index f6b1c456..3e4988f4 100644 --- a/42sh/src/parser/add_func.c +++ b/42sh/src/parser/add_func.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/24 23:43:07 by ariard #+# #+# */ -/* Updated: 2017/03/22 16:52:57 by gwojda ### ########.fr */ +/* Updated: 2017/03/22 19:21:58 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -100,7 +100,7 @@ t_list *is_already_func(t_btree **new) ret = (new_name && new_name[0] && old_name && old_name[0] && !ft_strcmp(new_name[0], old_name[0])) ? 0 : 1; ft_tabdel(&old_name); - tmp = tmp->next; + tmp = (ret) ? tmp->next : tmp; } ft_tabdel(&new_name); if (!ret) @@ -116,8 +116,10 @@ int add_one_func(t_btree **ast, t_list **lst) (void)lst; func_ast = btree_map(*ast, &node_copy); if ((old_func = is_already_func(&func_ast))) + { ft_lst_delif(&data_singleton()->lst_func, old_func->content, &ft_addrcmp, &tree_func_free); + } ft_lsteadd(&data_singleton()->lst_func, ft_lstnew(&func_ast, sizeof(*ast))); return (0); } diff --git a/42sh/src/parser/aggregate_sym.c b/42sh/src/parser/aggregate_sym.c index fbc02382..21b6a56f 100644 --- a/42sh/src/parser/aggregate_sym.c +++ b/42sh/src/parser/aggregate_sym.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/11 15:58:38 by ariard #+# #+# */ -/* Updated: 2017/03/22 18:13:04 by ariard ### ########.fr */ +/* Updated: 2017/03/22 19:00:06 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -381,20 +381,15 @@ int aggregate_sym(t_list **stack, t_sym *new_sym, t_parstate *state) return (1); i = -1; head = (*stack)->content; - DG("aggregate head %s && sym %s", - read_state(*head), read_state(*new_sym)); while (g_aggrematch[++i].top) if (*new_sym == g_aggrematch[i].top && MATCH_STACK(*head, g_aggrematch[i].under)) { - - DG("MATCH : %s", read_state(g_aggrematch[i].new_sym)); *new_sym = g_aggrematch[i].new_sym; if (g_aggrematch[i].erase_sym) { pop_stack(stack, g_aggrematch[i].erase_sym); head = (*stack)->content; - DG("stack after pop: %s", read_state(*head)); } if (eval_sym(stack, *new_sym) && !(*state = ERROR)) return (1); diff --git a/42sh/src/parser/eval_sym.c b/42sh/src/parser/eval_sym.c index 1ebd22ee..40ff2389 100644 --- a/42sh/src/parser/eval_sym.c +++ b/42sh/src/parser/eval_sym.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/11 16:11:21 by ariard #+# #+# */ -/* Updated: 2017/03/22 18:14:39 by ariard ### ########.fr */ +/* Updated: 2017/03/22 19:00:15 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -1272,7 +1272,6 @@ int eval_sym(t_list **stack, t_sym new_sym) return (1); head = (*stack)->content; i = 0; - DG("eval head %s && sym %s", read_state(*head), read_state(new_sym)); while (g_stackmatch[i].top) { if (new_sym == g_stackmatch[i].top && *head == g_stackmatch[i].under) diff --git a/42sh/src/parser/produce_sym.c b/42sh/src/parser/produce_sym.c index a7aceda1..b2e3f4c8 100644 --- a/42sh/src/parser/produce_sym.c +++ b/42sh/src/parser/produce_sym.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/09 17:58:34 by ariard #+# #+# */ -/* Updated: 2017/03/22 18:15:08 by ariard ### ########.fr */ +/* Updated: 2017/03/22 19:26:03 by ariard ### ########.fr */ /* */ /* ************************************************************************** */