expansion case yeaaah

This commit is contained in:
Antoine Riard 2017-03-06 19:46:09 +01:00
parent 1dbc4653fd
commit 4be3a84471
7 changed files with 34 additions and 25 deletions

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/27 20:29:56 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; t_flag attrs;
int fdin; int fdin;
t_list *op_stack; t_list *op_stack;
char *case_pattern; char **case_pattern;
int control_count; int control_count;
}; };

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/06 18:07:31 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) int exec_case(t_btree **ast)
{ {
t_astnode *node; t_astnode *node;
char *av; char **av;
t_exec *exec; t_exec *exec;
(void)ast; (void)ast;
@ -23,8 +23,7 @@ int exec_case(t_btree **ast)
exec->attrs &= ~EXEC_CASE_BRANCH; exec->attrs &= ~EXEC_CASE_BRANCH;
node = (*ast)->item; node = (*ast)->item;
av = node->data.str; av = token_to_argv(node->data.cmd.wordlist, 1);
// av = token_to_argv(node);
exec->case_pattern = av; exec->case_pattern = av;
return (0); return (0);
} }

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/06 18:07:31 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) int exec_case_branch(t_btree **ast)
{ {
t_astnode *node; t_astnode *node;
char *av; char **av;
t_exec *exec; t_exec *exec;
int i;
(void)ast;
exec = &data_singleton()->exec; exec = &data_singleton()->exec;
DG("case");
if (EXEC_IS_CASE_BRANCH(exec->attrs)) if (EXEC_IS_CASE_BRANCH(exec->attrs))
return (0); return (0);
DG("case2");
node = (*ast)->item; node = (*ast)->item;
av = node->data.str; av = token_to_argv(node->data.cmd.wordlist, 1);
// av = token_to_argv(node); i = 0;
if (ft_strcmp(av, exec->case_pattern) == 0) while (av[i])
{ {
exec->attrs |= EXEC_CASE_BRANCH; if (ft_strcmp(av[i], ((char **)exec->case_pattern)[0]) == 0)
ft_exec(&(*ast)->right); {
exec->attrs |= EXEC_CASE_BRANCH;
ft_exec(&(*ast)->right);
break ;
}
i++;
} }
return (0); return (0);
} }

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/06 20:42:20 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/04 20:42:13 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_astnode *node;
t_token *token; t_token *token;
char **my_tab;
token = (*lst)->content; token = (*lst)->content;
node = (*ast)->item; 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; node->pattern = 1;
return (0); return (0);
} }

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/15 20:49:15 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/17 22:17:14 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */