diff --git a/42sh/includes/exec.h b/42sh/includes/exec.h index 576a1c3f..d9f8261e 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/14 21:17:31 by jhalford ### ########.fr */ +/* Updated: 2017/03/15 01:07:00 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -62,7 +62,7 @@ struct s_data_cond struct s_data_list { - t_ld *list_word; + t_ld *token; t_btree *content; }; diff --git a/42sh/src/exec/exec_case_branch.c b/42sh/src/exec/exec_case_branch.c index 76596970..9335cdaa 100644 --- a/42sh/src/exec/exec_case_branch.c +++ b/42sh/src/exec/exec_case_branch.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 20:33:45 by wescande #+# #+# */ -/* Updated: 2017/03/07 20:34:48 by wescande ### ########.fr */ +/* Updated: 2017/03/15 01:21:45 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,23 +17,20 @@ int exec_case_branch(t_btree **ast) t_astnode *node; char **av; t_exec *exec; - int i; + DG("exec branch case"); exec = &data_singleton()->exec; if (EXEC_IS_CASE_BRANCH(exec->attrs)) return (0); node = (*ast)->item; - av = token_to_argv(node->data.cmd.wordlist, 1); - i = 0; - while (av[i]) - { - if (ft_strcmp(av[i], ((char **)exec->case_pattern)[0]) == 0) - { - exec->attrs |= EXEC_CASE_BRANCH; - ft_exec(&(*ast)->right); - break ; - } - i++; + av = token_to_argv(node->data.cmd.token, 1); + DG("compare pattern %s ", av[0]); + DG("and case %s", ((char **)exec->case_pattern)[0]); + DG(); + if (ft_strcmp(av[0], ((char **)exec->case_pattern)[0]) == 0) + { + exec->attrs |= EXEC_CASE_BRANCH; + ft_exec(&(*ast)->right); } return (0); } diff --git a/42sh/src/exec/exec_leaf.c b/42sh/src/exec/exec_leaf.c index e986fbe3..4707ff05 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/14 22:55:12 by ariard ### ########.fr */ +/* Updated: 2017/03/15 01:50:11 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/ft_exec.c b/42sh/src/exec/ft_exec.c index 667e6ac9..c6424172 100644 --- a/42sh/src/exec/ft_exec.c +++ b/42sh/src/exec/ft_exec.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/27 20:30:32 by jhalford #+# #+# */ -/* Updated: 2017/03/14 22:10:56 by ariard ### ########.fr */ +/* Updated: 2017/03/15 01:53:18 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/node_copy.c b/42sh/src/exec/node_copy.c index b31cf2f2..d79e1e2a 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/14 00:49:02 by ariard ### ########.fr */ +/* Updated: 2017/03/15 01:24:26 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -31,6 +31,6 @@ void *node_copy(void *data) 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) - new->data.cmd.wordlist = ft_ld_copy(old->data.cmd.token, &tab_esc_copy); + new->data.cmd.token = ft_ld_copy(old->data.cmd.token, &tab_esc_copy); return (new); } diff --git a/42sh/src/exec/pfree_list.c b/42sh/src/exec/pfree_list.c index 55236f61..ac896c97 100644 --- a/42sh/src/exec/pfree_list.c +++ b/42sh/src/exec/pfree_list.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/08 02:37:04 by wescande #+# #+# */ -/* Updated: 2017/03/13 22:31:32 by jhalford ### ########.fr */ +/* Updated: 2017/03/15 01:05:43 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,7 +14,7 @@ int pfree_list(t_process *p) { - ft_ld_del(&p->data.d_for.list_word, &ft_tabdel); + ft_ld_del(&p->data.d_for.token, &ft_tabdel); btree_del(&p->data.d_for.content, &ast_free); return (0); } diff --git a/42sh/src/exec/plaunch_case.c b/42sh/src/exec/plaunch_case.c index 8d88d699..8c7e49b1 100644 --- a/42sh/src/exec/plaunch_case.c +++ b/42sh/src/exec/plaunch_case.c @@ -6,25 +6,21 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 19:02:23 by wescande #+# #+# */ -/* Updated: 2017/03/15 00:04:09 by ariard ### ########.fr */ +/* Updated: 2017/03/15 01:10:32 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" + static int do_case(t_process *p) { t_exec *exec; + DG("exec case"); exec = &data_singleton()->exec; exec->attrs &= ~EXEC_CASE_BRANCH; - exec->case_pattern = token_to_argv(p->data.d_case.list_word, 1); -/* ft_exec(&p->data.d_if.condition); - if (!(ft_strcmp(ft_getenv(data_singleton()->env, "?"), "0"))) - { - exec->attrs |= EXEC_IF_BRANCH; - ft_exec(&p->data.d_if.content); - } - return (ft_atoi(ft_getenv(data_singleton()->env, "?")));*/ + exec->case_pattern = token_to_argv(p->data.d_case.token, 1); + ft_exec(&p->data.d_if.content); return (0); } diff --git a/42sh/src/exec/plaunch_for.c b/42sh/src/exec/plaunch_for.c index aa7fd313..9fe5eaed 100644 --- a/42sh/src/exec/plaunch_for.c +++ b/42sh/src/exec/plaunch_for.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 17:34:43 by wescande #+# #+# */ -/* Updated: 2017/03/15 00:03:12 by ariard ### ########.fr */ +/* Updated: 2017/03/15 01:57:25 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,10 +19,11 @@ static int do_for(t_process *p) char **av; char *var; - temp = p->data.d_for.list_word; + temp = p->data.d_for.token; var = ((char **)temp->content)[0]; if (!word_is_assignment(temp->content)) return (error_badidentifier(var)); + DG(); temp = temp->next; while (temp) { diff --git a/42sh/src/exec/plaunch_while.c b/42sh/src/exec/plaunch_while.c index d1e4a65f..2920c659 100644 --- a/42sh/src/exec/plaunch_while.c +++ b/42sh/src/exec/plaunch_while.c @@ -6,29 +6,12 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 17:20:53 by wescande #+# #+# */ -/* Updated: 2017/03/13 20:28:53 by jhalford ### ########.fr */ +/* Updated: 2017/03/15 00:55:31 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -/* -int exec_while(t_btree **ast) -{ - int ret; - DG("exec while condition"); - ft_exec(&(*ast)->left); - DG("ret :[%s]", ft_getenv(data_singleton()->env, "?")); - while (!(ft_strcmp(ft_getenv(data_singleton()->env, "?"), "0"))) - { - DG("in the while"); - ft_exec(&(*ast)->right); - ret = ft_atoi(ft_getenv(data_singleton()->env, "?")); - ft_exec(&(*ast)->left); - } - exit(ret); - return (0); -} -*/ + static int do_while(t_process *p) { int ret; diff --git a/42sh/src/exec/process_launch.c b/42sh/src/exec/process_launch.c index f6b226e6..2e140bdf 100644 --- a/42sh/src/exec/process_launch.c +++ b/42sh/src/exec/process_launch.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/13 22:21:19 by jhalford #+# #+# */ -/* Updated: 2017/03/14 22:34:22 by jhalford ### ########.fr */ +/* Updated: 2017/03/15 01:52:43 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/process_set.c b/42sh/src/exec/process_set.c index f648a7d6..c57402e4 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/13 22:40:00 by jhalford ### ########.fr */ +/* Updated: 2017/03/15 00:57:31 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/pset_case.c b/42sh/src/exec/pset_case.c index e6aa9cde..bbc0ddb6 100644 --- a/42sh/src/exec/pset_case.c +++ b/42sh/src/exec/pset_case.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 20:36:04 by wescande #+# #+# */ -/* Updated: 2017/03/13 20:31:21 by jhalford ### ########.fr */ +/* Updated: 2017/03/15 01:46:29 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,7 +14,8 @@ int pset_case(t_process *p, t_btree *ast) { - p->data.d_case.list_word = ft_ld_copy(((t_astnode *)ast->item)->data.cmd.wordlist, tab_esc_copy); + DG("set case"); + p->data.d_case.token = ft_ld_copy(((t_astnode *)ast->item)->data.cmd.token, tab_esc_copy); p->data.d_case.content = btree_map(ast->right, &node_copy); p->type = PROCESS_CASE; return (0); diff --git a/42sh/src/exec/pset_for.c b/42sh/src/exec/pset_for.c index a5b4a4f6..3049e566 100644 --- a/42sh/src/exec/pset_for.c +++ b/42sh/src/exec/pset_for.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 19:38:05 by wescande #+# #+# */ -/* Updated: 2017/03/13 20:31:21 by jhalford ### ########.fr */ +/* Updated: 2017/03/15 01:57:17 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,7 +14,7 @@ int pset_for(t_process *p, t_btree *ast) { - p->data.d_for.list_word = ft_ld_copy(((t_astnode *)ast->item)->data.cmd.wordlist, tab_esc_copy); + p->data.d_for.token = ft_ld_copy(((t_astnode *)ast->item)->data.cmd.token, tab_esc_copy); p->data.d_for.content = btree_map(ast->right, &node_copy); p->type = PROCESS_FOR; return (0); diff --git a/42sh/src/parser/add_case.c b/42sh/src/parser/add_case.c index 5f1083a7..1ea216dc 100644 --- a/42sh/src/parser/add_case.c +++ b/42sh/src/parser/add_case.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/04 20:42:13 by ariard #+# #+# */ -/* Updated: 2017/03/15 00:46:52 by ariard ### ########.fr */ +/* Updated: 2017/03/15 01:09:23 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/add_cmd.c b/42sh/src/parser/add_cmd.c index 4b7eaff3..ed1afa72 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 00:45:46 by ariard ### ########.fr */ +/* Updated: 2017/03/15 01:35:15 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,7 +17,6 @@ t_distrostree g_distrostree[] = {&superflous_token, &add_null}, {&isdir_sep, &add_redir_type}, {&isdir_word, &add_redir_word}, - {&isloop_condition, &add_loop_condition}, {&isloop, &add_loop_cmd}, {&iscondition_branch, &add_branch}, {&iscondition, &add_condition_cmd}, @@ -60,7 +59,7 @@ static int no_del_token(t_btree **ast, t_list **lst) return (0); if (node->type != TK_DO && node->type != TK_THEN && node->type != CMD && node->type != REDIR - && node->type != TK_ASSIGNMENT_WORD) + && node->type != TK_ASSIGNMENT_WORD && node->type != TK_FOR) return (1); } return (0); @@ -73,7 +72,7 @@ int add_cmd(t_btree **ast, t_list **lst) int i; i = -1; - while (++i < 15) + while (++i < 14) { if (g_distrostree[i].test(ast, lst) == 1) { @@ -89,14 +88,18 @@ int add_cmd(t_btree **ast, t_list **lst) node = (*ast)->item; if (token->type == TK_IF) add_if(ast, lst); - else if (token->type != TK_WORD) + else if (token->type != TK_WORD && token->type != TK_NAME) node->type = token->type; - else if (node->type != TK_CASE && node->type != TK_PAREN_OPEN) + else if (node->type != TK_CASE && node->type != TK_PAREN_OPEN && node->type != TK_FOR) node->type = CMD; - if (token->type == TK_WORD || token->type == TK_ASSIGNMENT_WORD) + if (token->type == TK_WORD || token->type == TK_ASSIGNMENT_WORD || token->type == TK_NAME) + { + DG("type is %s", read_state(node->type)); ft_ld_pushback(&node->data.cmd.token, gen_tab(token->data, token->esc, token->esc2, 1)); - if (token->type == TK_WORD) + } + if ((token->type == TK_WORD || token->type == TK_NAME) + && (node->type == TK_CASE || node->type == TK_PAREN_OPEN)) node->pattern = 1; return (0); } diff --git a/42sh/src/parser/add_loop.c b/42sh/src/parser/add_loop.c index d8694a03..4b2713bc 100644 --- a/42sh/src/parser/add_loop.c +++ b/42sh/src/parser/add_loop.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/17 22:17:14 by ariard #+# #+# */ -/* Updated: 2017/03/13 16:12:35 by ariard ### ########.fr */ +/* Updated: 2017/03/15 01:45:34 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,12 +15,19 @@ int isloop(t_btree **ast, t_list **lst) { t_astnode *node; + t_token *token; - (void)lst; node = NULL; + token = (*lst)->content; if (*ast) { node = (*ast)->item; + if (node->type == TK_FOR && (token->type == TK_NEWLINE + || token->type == TK_SEMI) && node->pattern == 0) + return (1); + if (node->type == TK_FOR && (token->type == TK_WORD || token->type == TK_NAME) + && node->pattern == 0) + return (0); if ((node->type == TK_NEWLINE || node->type == TK_SEMI || node->type == TK_AMP || node->type == TK_PIPE) && isloop(&(*ast)->right, lst) == 1) @@ -79,6 +86,15 @@ int add_loop_cmd(t_btree **ast, t_list **lst) int add_loop_sep(t_btree **ast, t_list **lst) { + t_astnode *node; + + node = NULL; + if (*ast) + { + node = (*ast)->item; + if (node->type == TK_FOR && node->pattern == 0) + return (0); + } if (!(*ast)->right) return (add_sep(&(*ast)->left, lst)); else diff --git a/42sh/src/parser/add_sep.c b/42sh/src/parser/add_sep.c index c57a0944..f61ba420 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/13 16:25:31 by ariard ### ########.fr */ +/* Updated: 2017/03/15 01:41:06 by ariard ### ########.fr */ /* */ /* ************************************************************************** */