/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* parser_get_commands.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: qmennen +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/02/11 14:06:02 by qmennen #+# #+# */ /* Updated: 2025/02/27 16:07:54 by qmennen ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" static int is_command_token(t_token *token) { return (token->type < 3 || redirect_token_type(token)); } t_list *parser_get_commands(t_minishell *msh) { t_list *command_list; t_list *current; t_command *command; t_token *token; command_list = NULL; if (!msh->tokens) return (NULL); current = msh->tokens; while (current) { token = (t_token *) current->content; command = parser_alloc_command(msh, ft_strdup_safe(msh, token->value)); parser_create_command(msh, command, ¤t); if (! parser_validate_command(command)) break ; ft_lstadd_back(&command_list, ft_lstnew_safe(msh, command)); while (current && is_command_token((t_token *)current->content)) current = current->next; if (current && ((t_token *)current->content)->type >= 3) current = current->next; } ft_lstiter(command_list, print_commands); return (command_list); }