diff --git a/srcs/main.c b/srcs/main.c index f81eecf..c914b03 100644 --- a/srcs/main.c +++ b/srcs/main.c @@ -82,12 +82,8 @@ int main(int ac, char **av, char **envp) { while (!input || !input[0]) input = powerline(); - ft_debug("input: %s\n", input); - ft_debug("powerline\n"); msh->head = parser(input, msh); - ft_debug("parsed\n"); msh->ex_code = execute_command(msh->head); - ft_debug("executed\n"); free(input); input = NULL; } diff --git a/srcs/parsing/ast/ast.c b/srcs/parsing/ast/ast.c index dfca297..f464805 100644 --- a/srcs/parsing/ast/ast.c +++ b/srcs/parsing/ast/ast.c @@ -115,15 +115,28 @@ void create_redir(t_node *cpy, t_ast_n *self) t_node *get_cmd(t_node *lst) { - while (lst) + t_node *cpy; + + cpy = lst; + while (cpy) { - if (get_redir(lst) != _NR && lst->next && lst->next->next && get_redir(lst->next->next) == _NR) - return (lst); - lst = lst->next; + if (get_redir(cpy) != _NR && cpy->next && cpy->next->next && get_redir(cpy->next->next) == _NR) + return (cpy->next->next); + cpy = cpy->next; } return (lst); } +char **get_args(t_node *cmd) +{ + t_node *cpy; + + cpy = cmd; + while (cpy && !get_redir(cpy)) + cpy = cpy->next; + return (lltotab(cmd, cpy)); +} + void create_cmd(t_ast_n *self, t_node *lst) { t_node *cpy; @@ -134,8 +147,8 @@ void create_cmd(t_ast_n *self, t_node *lst) self->redir = ft_calloc(1, sizeof(t_redir)); self->redir[0] = _NR; cmd_node = get_cmd(lst); - self->cmd = cmd_node->val; - self->args = ft_split("NOT SET", " "); + self->cmd = ft_strdup(cmd_node->val); + self->args = get_args(cmd_node); cpy = lst; create_redir(cpy, self); }