From be78dfbdf88e26839cba9bc2875569e57045b7b2 Mon Sep 17 00:00:00 2001 From: wescande Date: Wed, 8 Mar 2017 03:10:46 +0100 Subject: [PATCH] commit pour recup lib & node_copy --- 42sh/includes/builtin.h | 4 +--- 42sh/src/exec/is_function.c | 27 +++++++++++++++++++++++++++ 42sh/src/exec/process_setexec.c | 8 ++++---- 42sh/src/parser/add_func.c | 6 +++--- 4 files changed, 35 insertions(+), 10 deletions(-) create mode 100644 42sh/src/exec/is_function.c diff --git a/42sh/includes/builtin.h b/42sh/includes/builtin.h index be6045e4..3662a1f0 100644 --- a/42sh/includes/builtin.h +++ b/42sh/includes/builtin.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 17:21:56 by jhalford #+# #+# */ -/* Updated: 2017/03/07 17:29:38 by jhalford ### ########.fr */ +/* Updated: 2017/03/08 03:08:48 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -32,6 +32,4 @@ int builtin_bg(const char *path, char *const av[], char *const envp[]); int builtin_history(const char *path, char *const av[], char *const envp[]); int builtin_hash(const char *path, char *const av[], char *const envp[]); -extern t_stof g_builtins[]; - #endif diff --git a/42sh/src/exec/is_function.c b/42sh/src/exec/is_function.c new file mode 100644 index 00000000..227acb3c --- /dev/null +++ b/42sh/src/exec/is_function.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* is_function.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: wescande +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/03/08 02:45:15 by wescande #+# #+# */ +/* Updated: 2017/03/08 03:10:25 by wescande ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "minishell.h" + +t_btree *is_function(t_process *p) +{ + t_list *tmp; + + tmp = data_singleton()->lst_func; + while (tmp) + { + if (!ft_strcmp(((t_astnode *)tmp->content)->data.str, p->data.cmd.av[0])) + btree_map(p->data.subshell.content, node_copy); + tmp = tmp->next; + } + return (NULL); +} diff --git a/42sh/src/exec/process_setexec.c b/42sh/src/exec/process_setexec.c index 4242fb47..5f27ecf0 100644 --- a/42sh/src/exec/process_setexec.c +++ b/42sh/src/exec/process_setexec.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 17:07:10 by jhalford #+# #+# */ -/* Updated: 2017/03/07 21:44:37 by wescande ### ########.fr */ +/* Updated: 2017/03/08 03:08:30 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,9 +16,9 @@ int process_setexec(t_process *p) { p->data.cmd.path = NULL; p->data.cmd.execf = NULL; - /* if ((p->execf = is_function(p))) */ - /* p->type = PROCESS_FUNCTION; */ - if ((p->data.cmd.execf = is_builtin(p))) + if ((p->data.subshell.content = is_function(p))) + p->type = PROCESS_FUNCTION; + else if ((p->data.cmd.execf = is_builtin(p))) p->type = PROCESS_BUILTIN; else if (ft_strchr(p->data.cmd.av[0], '/')) { diff --git a/42sh/src/parser/add_func.c b/42sh/src/parser/add_func.c index 736e7e22..66041625 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/07 10:49:15 by ariard ### ########.fr */ +/* Updated: 2017/03/08 03:04:45 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -25,6 +25,7 @@ int isfunc_name(t_btree **ast, t_list **lst) { DG("add func name"); node->type = FNAME; + node->data.str = ft_strdup(token->data); return (1); } if (node->type == FNAME && token->type == TK_PAREN_CLOSE && node->nest == 0) @@ -87,8 +88,7 @@ int add_one_func(t_btree **ast, t_list **lst) { t_btree *func_ast; - (void)lst; -// func_ast = btree_map(*ast, &id); + func_ast = btree_map(*ast, node_copy); ft_lsteadd(&data_singleton()->lst_func, ft_lstnew(&func_ast, sizeof(*ast))); DG("arbre ajoute"); return (0);