diff --git a/includes/minishell.h b/includes/minishell.h index ea1701e..734f033 100644 --- a/includes/minishell.h +++ b/includes/minishell.h @@ -33,7 +33,7 @@ # include "exec/exec.h" # include "exec/expander.h" -# define DEBUG 0 +# define DEBUG 1 # ifndef DIO_PATH # define DIO_PATH "ast.xml" diff --git a/srcs/parsing/ast/cutll.c b/srcs/parsing/ast/cutll.c index 2ef8bc7..6a42f11 100644 --- a/srcs/parsing/ast/cutll.c +++ b/srcs/parsing/ast/cutll.c @@ -31,7 +31,17 @@ static void add_nodell(t_nodell **nodell, t_node *node) tmp->next->next = NULL; } -static t_node *get_node(t_node **lst, t_node *expected, int limiter) +static void update_subsh_l(int *shlvl, t_node *lst) +{ + if (!lst) + return; + if (!ft_strncmp(")", lst->val, 1)) + *shlvl = 0; + if (!ft_strncmp("(", lst->val, 1)) + *shlvl = 1; +} + +static t_node *get_node(t_node **lst, t_node *expected, int limiter, int *shlvl) { t_node *node; @@ -41,9 +51,9 @@ static t_node *get_node(t_node **lst, t_node *expected, int limiter) add_node_back(&node, (*lst)->val, (*lst)->token, (*lst)->pressision); (*lst) = (*lst)->next; } - while (limiter == -1 && (*lst) && ft_strncmp((*lst)->val, expected->val, - ft_strlen((*lst)->val))) + while (limiter == -1 && (*lst) && ( *shlvl == 1 || ft_strncmp((*lst)->val, expected->val, ft_strlen((*lst)->val)))) { + update_subsh_l(shlvl, *lst); add_node_back(&node, (*lst)->val, (*lst)->token, (*lst)->pressision); (*lst) = (*lst)->next; } @@ -56,20 +66,24 @@ t_nodell *cutll(t_node *lst, t_node *expected, size_t limiter) t_node *node; size_t i; t_nodell *tmp; + int shlvl; i = 0; out = NULL; + shlvl = 0; while (i <= limiter) { - node = get_node(&lst, expected, limiter); + update_subsh_l(&shlvl, lst); + node = get_node(&lst, expected, limiter, &shlvl); if (!node) break ; add_nodell(&out, node); tmp = out; while (tmp) tmp = tmp->next; - if (lst && lst->next) - lst = lst->next; + if (!lst) + break; + lst = lst->next; i++; } return (out);