diff --git a/42sh/includes/exec.h b/42sh/includes/exec.h index d9f8261e..5485ec3b 100644 --- a/42sh/includes/exec.h +++ b/42sh/includes/exec.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/27 20:29:56 by jhalford #+# #+# */ -/* Updated: 2017/03/15 01:07:00 by ariard ### ########.fr */ +/* Updated: 2017/03/15 17:25:13 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/includes/parser.h b/42sh/includes/parser.h index 2f07a512..34fb8718 100644 --- a/42sh/includes/parser.h +++ b/42sh/includes/parser.h @@ -116,7 +116,6 @@ int add_pattern(t_btree **ast, t_list **lst); int add_subshell_cmd(t_btree **ast, t_list **lst); int add_subshell_sep(t_btree **ast, t_list **lst); int add_func_cmd(t_btree **ast, t_list **lst); -int add_func_sep(t_btree **ast, t_list **lst); int add_one_func(t_btree **ast, t_list **lst); int add_pipe(t_btree **ast, t_list **lst); int add_null(t_btree **ast, t_list **lst); @@ -178,10 +177,10 @@ union u_astdata struct s_astnode { - int pattern; - int nest; - int full; - int cache; + int pattern; + int nest; + int full; + int cache; t_type type; t_astdata data; }; diff --git a/42sh/src/builtin/is_builtin.c b/42sh/src/builtin/is_builtin.c index 4bc3a2c3..bb091637 100644 --- a/42sh/src/builtin/is_builtin.c +++ b/42sh/src/builtin/is_builtin.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 13:09:57 by jhalford #+# #+# */ -/* Updated: 2017/03/14 22:32:24 by ariard ### ########.fr */ +/* Updated: 2017/03/15 18:31:21 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -36,6 +36,7 @@ t_execf *is_builtin(t_process *p) { int i; + DG("in builtin"); i = -1; while (g_builtin[++i].name) { diff --git a/42sh/src/exec/ast_free.c b/42sh/src/exec/ast_free.c index 4d7d2c93..89f0242a 100644 --- a/42sh/src/exec/ast_free.c +++ b/42sh/src/exec/ast_free.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/05 11:50:51 by jhalford #+# #+# */ -/* Updated: 2017/03/08 00:59:53 by ariard ### ########.fr */ +/* Updated: 2017/03/15 19:18:02 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/exec_leaf.c b/42sh/src/exec/exec_leaf.c index e26f54d4..cfeea069 100644 --- a/42sh/src/exec/exec_leaf.c +++ b/42sh/src/exec/exec_leaf.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 15:47:30 by wescande #+# #+# */ -/* Updated: 2017/03/15 02:04:30 by ariard ### ########.fr */ +/* Updated: 2017/03/15 18:46:46 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/is_function.c b/42sh/src/exec/is_function.c index 36bdcd5a..e3e954e4 100644 --- a/42sh/src/exec/is_function.c +++ b/42sh/src/exec/is_function.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/08 02:45:15 by wescande #+# #+# */ -/* Updated: 2017/03/08 03:22:34 by wescande ### ########.fr */ +/* Updated: 2017/03/15 18:57:03 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,13 +14,21 @@ t_btree *is_function(t_process *p) { - t_list *tmp; + t_list *tmp; + t_btree **ast; + char **av; tmp = data_singleton()->lst_func; while (tmp) { - if (!ft_strcmp(((t_astnode *)tmp->content)->data.str, p->data.cmd.av[0])) - return (btree_map(p->data.subshell.content, node_copy)); + ast = tmp->content; + if (!*ast) + return (NULL); + av = token_to_argv(((t_astnode *)(*ast)->item)->data.cmd.token, 1); + if (!av || !av[0]) + return (NULL); + if (!ft_strcmp(av[0], p->data.cmd.av[0])) + return (btree_map((*ast)->right, node_copy)); tmp = tmp->next; } return (NULL); diff --git a/42sh/src/exec/node_copy.c b/42sh/src/exec/node_copy.c index d79e1e2a..c1785a81 100644 --- a/42sh/src/exec/node_copy.c +++ b/42sh/src/exec/node_copy.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/08 03:38:36 by wescande #+# #+# */ -/* Updated: 2017/03/15 01:24:26 by ariard ### ########.fr */ +/* Updated: 2017/03/15 16:48:40 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -30,7 +30,8 @@ void *node_copy(void *data) new->data.cmd.redir = ft_lstmap(old->data.cmd.redir, &redir_copy); new->data.cmd.token = ft_ld_copy(old->data.cmd.token, &tab_esc_copy); } - if (old->type == TK_FOR || old->type == TK_PAREN_OPEN || old->type == TK_CASE) + if (old->type == TK_FOR || old->type == TK_PAREN_OPEN || old->type == TK_CASE + || old->type == FNAME) new->data.cmd.token = ft_ld_copy(old->data.cmd.token, &tab_esc_copy); return (new); } diff --git a/42sh/src/exec/plaunch_brace.c b/42sh/src/exec/plaunch_brace.c index 728842e0..0574cd60 100644 --- a/42sh/src/exec/plaunch_brace.c +++ b/42sh/src/exec/plaunch_brace.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/13 19:09:30 by jhalford #+# #+# */ -/* Updated: 2017/03/14 00:04:09 by jhalford ### ########.fr */ +/* Updated: 2017/03/15 18:13:05 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,8 +14,10 @@ int plaunch_brace(t_process *p) { + DG(" do brace"); if (IS_PIPESINGLE(*p)) { + DG("is pipgesingle"); if (process_redirect(p)) set_exitstatus(1, 1); else diff --git a/42sh/src/exec/plaunch_function.c b/42sh/src/exec/plaunch_function.c index d0bc5bcf..ed07ac41 100644 --- a/42sh/src/exec/plaunch_function.c +++ b/42sh/src/exec/plaunch_function.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/08 03:23:59 by wescande #+# #+# */ -/* Updated: 2017/03/13 20:28:57 by jhalford ### ########.fr */ +/* Updated: 2017/03/15 19:17:01 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,6 +14,7 @@ static int do_function(t_process *p) { + DG("do function"); ft_exec(&p->data.function.content); return (ft_atoi(ft_getenv(data_singleton()->env, "?"))); } diff --git a/42sh/src/exec/process_set.c b/42sh/src/exec/process_set.c index c57402e4..74dcf000 100644 --- a/42sh/src/exec/process_set.c +++ b/42sh/src/exec/process_set.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/05 14:54:45 by jhalford #+# #+# */ -/* Updated: 2017/03/15 00:57:31 by ariard ### ########.fr */ +/* Updated: 2017/03/15 18:20:38 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -34,6 +34,7 @@ static int process_set_spec(t_process *p, t_btree *ast) if (!ast) return (0); item = ast->item; + DG("process set spec"); while (g_setprocessmap[++i].id) if (item->type == g_setprocessmap[i].id) { diff --git a/42sh/src/exec/pset_cmd.c b/42sh/src/exec/pset_cmd.c index 408faeff..43153bb5 100644 --- a/42sh/src/exec/pset_cmd.c +++ b/42sh/src/exec/pset_cmd.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 15:06:05 by wescande #+# #+# */ -/* Updated: 2017/03/14 21:25:01 by ariard ### ########.fr */ +/* Updated: 2017/03/15 18:48:13 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -27,7 +27,8 @@ int pset_cmd(t_process *p, t_btree *ast) p->type = PROCESS_FILE; if ((func = is_function(p))) { - p->data.subshell.content = func; + btree_print(STDBUG, func, &ft_putast); + p->data.function.content = func; p->type = PROCESS_FUNCTION; } else if ((p->data.cmd.execf = is_builtin(p))) diff --git a/42sh/src/parser/add_cmd.c b/42sh/src/parser/add_cmd.c index 300a4c99..209eaedf 100644 --- a/42sh/src/parser/add_cmd.c +++ b/42sh/src/parser/add_cmd.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/15 20:49:15 by ariard #+# #+# */ -/* Updated: 2017/03/15 02:12:28 by ariard ### ########.fr */ +/* Updated: 2017/03/15 16:46:16 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -95,6 +95,7 @@ int add_cmd(t_btree **ast, t_list **lst) if (token->type == TK_WORD || token->type == TK_ASSIGNMENT_WORD || token->type == TK_NAME) { DG("type is %s", read_state(node->type)); + DG("data is %s", token->data); ft_ld_pushback(&node->data.cmd.token, gen_tab(token->data, token->esc, token->esc2, 1)); } diff --git a/42sh/src/parser/add_func.c b/42sh/src/parser/add_func.c index a90a4b39..5568cf54 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/15 00:26:57 by ariard ### ########.fr */ +/* Updated: 2017/03/15 19:50:49 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -24,7 +24,6 @@ int isfunc_name(t_btree **ast, t_list **lst) if (node->type == CMD && token->type == TK_PAREN_OPEN) { node->type = FNAME; - node->data.str = ft_strdup(token->data); return (1); } if (node->type == FNAME && token->type == TK_PAREN_CLOSE @@ -81,17 +80,39 @@ int add_func_cmd(t_btree **ast, t_list **lst) return (add_cmd(&(*ast)->right, lst)); } -int add_func_sep(t_btree **ast, t_list **lst) +t_list *is_already_func(t_btree **new) { - return (add_sep(&(*ast)->right, lst)); + t_list *tmp; + t_btree **ast; + char **new_name; + char **old_name; + + tmp = data_singleton()->lst_func; + new_name = token_to_argv(((t_astnode *)(*new)->item)->data.cmd.token, 1); + while (tmp) + { + ast = tmp->content; + if (!*ast) + return (NULL); + old_name = token_to_argv(((t_astnode *)(*ast)->item)->data.cmd.token, 1); + if (!new_name || !new_name[0] || !old_name || !old_name[0]) + return (NULL); + if (!ft_strcmp(new_name[0], old_name[0])) + return (tmp); + tmp = tmp->next; + } + return (NULL); } int add_one_func(t_btree **ast, t_list **lst) { t_btree *func_ast; + t_list *old_func; (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, &ast_free); ft_lsteadd(&data_singleton()->lst_func, ft_lstnew(&func_ast, sizeof(*ast))); return (0); } diff --git a/42sh/src/parser/add_sep.c b/42sh/src/parser/add_sep.c index f61ba420..afb89bca 100644 --- a/42sh/src/parser/add_sep.c +++ b/42sh/src/parser/add_sep.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/15 19:12:07 by ariard #+# #+# */ -/* Updated: 2017/03/15 01:41:06 by ariard ### ########.fr */ +/* Updated: 2017/03/15 18:57:13 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -27,7 +27,7 @@ int add_sep(t_btree **ast, t_list **lst) else if (issubshell(ast, lst)) return (add_subshell_sep(ast, lst)); else if (isfunc(ast, lst)) - return (add_func_sep(ast, lst)); + return (add_subshell_sep(ast, lst)); else if (isbang_sep(ast, lst)) return (add_bang_sep(ast, lst)); if (!*ast) diff --git a/42sh/src/parser/ft_parse.c b/42sh/src/parser/ft_parse.c index 48c2df8c..6b2177ba 100644 --- a/42sh/src/parser/ft_parse.c +++ b/42sh/src/parser/ft_parse.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/11 16:17:38 by ariard #+# #+# */ -/* Updated: 2017/03/13 17:42:06 by ariard ### ########.fr */ +/* Updated: 2017/03/15 17:25:09 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -56,7 +56,7 @@ int ft_parse(t_btree **ast, t_list **token, t_parser *parser) else parser->state = UNDEFINED; build_tree(ast, token); - btree_print(STDBUG, *ast, &ft_putast); +// btree_print(STDBUG, *ast, &ft_putast); if ((end_instruction(&parser->stack) && !(*token)->next)) insert_linebreak(token); else diff --git a/42sh/src/parser/read_stack.c b/42sh/src/parser/read_stack.c index 398023aa..af8a85d7 100644 --- a/42sh/src/parser/read_stack.c +++ b/42sh/src/parser/read_stack.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/09 15:32:10 by ariard #+# #+# */ -/* Updated: 2017/03/14 22:11:43 by ariard ### ########.fr */ +/* Updated: 2017/03/15 16:33:57 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,6 +14,8 @@ char *read_state(t_sym current) { + if (current == FNAME) + return ("FNAME"); if (current == PIPE_CLOSE_SEQUENCE) return ("PIPE_CLOSE_SEQUENCE"); if (current == TK_BANG)