From 4be3a84471a0fb93c3d9adc16a27c921d803885f Mon Sep 17 00:00:00 2001 From: Antoine Riard Date: Mon, 6 Mar 2017 19:46:09 +0100 Subject: [PATCH] expansion case yeaaah --- 42sh/includes/exec.h | 4 ++-- 42sh/src/exec/exec_case.c | 7 +++---- 42sh/src/exec/exec_case_branch.c | 30 ++++++++++++++++-------------- 42sh/src/exec/exec_for.c | 2 +- 42sh/src/parser/add_case.c | 12 ++++++++++-- 42sh/src/parser/add_cmd.c | 2 +- 42sh/src/parser/add_loop.c | 2 +- 7 files changed, 34 insertions(+), 25 deletions(-) diff --git a/42sh/includes/exec.h b/42sh/includes/exec.h index e7d93dc5..d43904a2 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/06 18:11:21 by ariard ### ########.fr */ +/* Updated: 2017/03/06 19:16:30 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -73,7 +73,7 @@ struct s_exec t_flag attrs; int fdin; t_list *op_stack; - char *case_pattern; + char **case_pattern; int control_count; }; diff --git a/42sh/src/exec/exec_case.c b/42sh/src/exec/exec_case.c index b167b905..ed982dac 100644 --- a/42sh/src/exec/exec_case.c +++ b/42sh/src/exec/exec_case.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/06 18:07:31 by ariard #+# #+# */ -/* Updated: 2017/03/05 15:29:22 by wescande ### ########.fr */ +/* Updated: 2017/03/06 19:37:20 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,7 +15,7 @@ int exec_case(t_btree **ast) { t_astnode *node; - char *av; + char **av; t_exec *exec; (void)ast; @@ -23,8 +23,7 @@ int exec_case(t_btree **ast) exec->attrs &= ~EXEC_CASE_BRANCH; node = (*ast)->item; - av = node->data.str; -// av = token_to_argv(node); + av = token_to_argv(node->data.cmd.wordlist, 1); exec->case_pattern = av; return (0); } diff --git a/42sh/src/exec/exec_case_branch.c b/42sh/src/exec/exec_case_branch.c index ae8308c2..2d0db420 100644 --- a/42sh/src/exec/exec_case_branch.c +++ b/42sh/src/exec/exec_case_branch.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/06 18:07:31 by ariard #+# #+# */ -/* Updated: 2017/03/05 15:29:46 by wescande ### ########.fr */ +/* Updated: 2017/03/06 19:36:55 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,23 +15,25 @@ int exec_case_branch(t_btree **ast) { t_astnode *node; - char *av; - t_exec *exec; + char **av; + t_exec *exec; + int i; - (void)ast; exec = &data_singleton()->exec; - - DG("case"); if (EXEC_IS_CASE_BRANCH(exec->attrs)) return (0); - DG("case2"); node = (*ast)->item; - av = node->data.str; -// av = token_to_argv(node); - if (ft_strcmp(av, exec->case_pattern) == 0) - { - exec->attrs |= EXEC_CASE_BRANCH; - ft_exec(&(*ast)->right); - } + 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++; + } return (0); } diff --git a/42sh/src/exec/exec_for.c b/42sh/src/exec/exec_for.c index 5159c515..632f5773 100644 --- a/42sh/src/exec/exec_for.c +++ b/42sh/src/exec/exec_for.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/06 20:42:20 by ariard #+# #+# */ -/* Updated: 2017/03/06 19:02:36 by ariard ### ########.fr */ +/* Updated: 2017/03/06 19:37:02 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/add_case.c b/42sh/src/parser/add_case.c index 1a87f15f..111d9397 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/06 15:11:04 by ariard ### ########.fr */ +/* Updated: 2017/03/06 19:36:37 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -89,10 +89,18 @@ int add_pattern(t_btree **ast, t_list **lst) { t_astnode *node; t_token *token; + char **my_tab; token = (*lst)->content; node = (*ast)->item; - node->data.str = ft_strdup(token->data); + if ((my_tab = (char **)malloc(sizeof(char *) * 4))) + { + my_tab[0] = ft_strdup(token->data); + my_tab[1] = (char *)dup_char_esc(token->esc, token->size >> 3); + my_tab[2] = (char *)dup_char_esc(token->esc2, token->size >> 3); + my_tab[3] = NULL; + } + ft_ld_pushback(&node->data.cmd.wordlist, my_tab); node->pattern = 1; return (0); } diff --git a/42sh/src/parser/add_cmd.c b/42sh/src/parser/add_cmd.c index 42793da2..b4e6b650 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/06 18:48:57 by ariard ### ########.fr */ +/* Updated: 2017/03/06 19:36:34 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/add_loop.c b/42sh/src/parser/add_loop.c index 2bb3cd59..f15c044d 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/06 19:02:46 by ariard ### ########.fr */ +/* Updated: 2017/03/06 19:06:03 by ariard ### ########.fr */ /* */ /* ************************************************************************** */