diff --git a/includes/minishell.h b/includes/minishell.h index 81ee1ea..c9f9c81 100644 --- a/includes/minishell.h +++ b/includes/minishell.h @@ -13,7 +13,7 @@ #ifndef MINISHELL_H # define MINISHELL_H -# define DEBUG 0 +# define DEBUG 1 typedef struct s_ast_n t_ast_n; typedef struct s_node t_node; diff --git a/srcs/parsing/ast/commands.c b/srcs/parsing/ast/commands.c index bbd1b0e..a5afa11 100644 --- a/srcs/parsing/ast/commands.c +++ b/srcs/parsing/ast/commands.c @@ -75,10 +75,12 @@ void create_cmd(t_ast_n *self, t_node *lst) create_redir(lst, self); // debug int i = -1; + ft_debug("==== CMD REDIR\n"); while (self->files && self->files[++i]) - ft_debug("redir : [%d]%s\n",self->redir[i], self->files[i]); - ft_debug("====\n"); + ft_debug("redi : [%d]%s\n",self->redir[i], self->files[i]); + ft_debug("==== CMD ARGS\n"); i = -1; while (self->args && self->args[++i]) ft_debug("args : %s\n",self->args[i], self->args[i]); + ft_debug("==== CMD DONE\n\n"); } diff --git a/srcs/parsing/ast/subsh.c b/srcs/parsing/ast/subsh.c index 7a201b2..d714f2d 100644 --- a/srcs/parsing/ast/subsh.c +++ b/srcs/parsing/ast/subsh.c @@ -46,5 +46,12 @@ void create_subsh(t_ast_n *self, t_node *lst, t_msh *msh) self->redir = ft_calloc(1, sizeof(t_redir)); self->redir[0] = _NR; create_redir_subsh(lst, self); + // debug + int i = -1; + ft_debug("==== SUBSH REDIR\n"); + while (self->redir[++i]) + ft_debug("subsh_redir : [%d]%s\n", self->redir[i], self->files[i]); + ft_debug("==== SUBSH DONE\n\n"); + // free(cutted); } diff --git a/srcs/parsing/ast/top_token.c b/srcs/parsing/ast/top_token.c index 8457d37..c31c12b 100644 --- a/srcs/parsing/ast/top_token.c +++ b/srcs/parsing/ast/top_token.c @@ -13,6 +13,17 @@ #include "../../../includes/minishell.h" static int last_tok_subsh(t_node *lst) +{ + while (lst) + { + if ((lst->next == NULL) && !ft_strncmp(lst->val, ")", 1)) + return (1); + lst = lst->next; + } + return (0); +} + +static int last_tok_redir(t_node *lst) { while (lst) { @@ -56,7 +67,7 @@ t_node *get_top_token(t_node *lst, t_state *state) *state = _SUBSH; if (!ft_strncmp(lst->val, "(", 1) && last_tok_subsh(lst)) return (lst); - else if (find_token("&&", lst)) + if (find_token("&&", lst)) { *state = _AND; return (find_token("&&", lst)); @@ -71,6 +82,8 @@ t_node *get_top_token(t_node *lst, t_state *state) *state = _PLINE; return (find_token("|", lst)); } + else if (!ft_strncmp(lst->val, "(", 1) && last_tok_redir(lst)) + return (lst); else { *state = UNDEF;