minishell/src/parser/parser_get_commands.c
2025-02-23 12:34:34 +01:00

41 lines
1.7 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* parser_get_commands.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/11 14:06:02 by qmennen #+# #+# */
/* Updated: 2025/02/18 20:36:01 by qmennen ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
t_list *parser_get_commands(t_minishell *minishell)
{
t_list *command_list;
t_list *current;
t_command *command;
t_token *token;
command_list = NULL;
if (!minishell->tokens)
return (NULL);
current = minishell->tokens;
while (current)
{
token = (t_token *) current->content;
command = parser_command_new(ft_strdup(token->value));
command->args = parser_get_arguments(current, minishell);
command->redirect_in = redirect_get_inputs(current);
ft_lstadd_back(&command_list, ft_lstnew(command));
while (current && (((t_token *)current->content)->type < 3 || ((t_token *)current->content)->type == T_REDIRECT_IN))
current = current->next;
if (current && ((t_token *)current->content)->type >= 3)
current = current->next;
}
// ft_lstiter(command_list, print_commands);
return (command_list);
}