This commit is contained in:
Quinten 2025-02-23 11:58:13 +01:00
parent 8da0e0a036
commit 24752c9d08
2 changed files with 79 additions and 39 deletions

View File

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

View File

@ -0,0 +1,39 @@
# include "minishell.h"
static int valid_def(t_list *list, t_token *token)
{
t_token *next;
if (!list->next)
return (0);
next = (t_token *)list->next->content;
if (!next)
return (0);
return ((token->type == T_REDIRECT_IN || token->type == T_HEREDOC) && next->type < 3);
}
static t_redirect *redirect_new()
{
t_redirect *result;
}
void parser_get_input_redirects(t_list *list)
{
t_list *current;
t_list *redirects;
t_token *token;
redirects = NULL;
current = list;
while (current)
{
token = (t_token *)current->content;
if (valid_def(current, token))
{
ft_lstaddfront(&redirects, ft_lstnew());
}
else
break ;
current = current->next;
}
}