get inputs is done

This commit is contained in:
Quinten Mennen 2025-02-26 17:25:22 +01:00
parent abb2e8563a
commit 46bea87309
2 changed files with 21 additions and 30 deletions

View File

@ -14,7 +14,8 @@
# define REDIRECT_H # define REDIRECT_H
# include "minishell.h" # include "minishell.h"
t_redirect *redirect_new(t_minishell *msh, t_token_type type, char *value); t_redirect *redirect_new(t_minishell *msh, t_token_type type, char *value);
void redirect_create(t_minishell *msh, t_list **tokens, t_list **redirects, t_token_type type);
t_list *redirect_get_inputs(t_minishell *msh, t_list *list); t_list *redirect_get_inputs(t_minishell *msh, t_list *list);
t_list *redirect_get_outputs(t_minishell *msh, t_list *list); t_list *redirect_get_outputs(t_minishell *msh, t_list *list);
int redirect_is_valid(t_list *lst, t_token *token, int mode); int redirect_is_valid(t_list *lst, t_token *token, int mode);

View File

@ -6,53 +6,43 @@
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */ /* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/23 12:29:05 by Quinten #+# #+# */ /* Created: 2025/02/23 12:29:05 by Quinten #+# #+# */
/* Updated: 2025/02/26 16:57:02 by qmennen ### ########.fr */ /* Updated: 2025/02/26 17:24:53 by qmennen ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "redirect.h" #include "redirect.h"
t_list *redirect_get_inputs(t_minishell *msh, t_list *list) static void check_heredoc(t_minishell *msh, t_list *current, t_token *token)
{ {
t_list *current; if (token->type == T_HEREDOC && redirect_is_valid(current, token, -1))
t_list *redirects; process_heredoc(msh, token, current->next->content);
t_token *token; }
int result;
t_list *redirect_get_inputs(t_minishell *msh, t_list *list)
{
t_list *current;
t_list *redirects;
t_token *token;
int flag;
redirects = NULL; redirects = NULL;
current = list; current = list;
result = 1; flag = 1;
while (current && result) token = (t_token *)current->content;
while (current && flag && !redirect_is_delimiter(token))
{ {
token = (t_token *)current->content; token = (t_token *)current->content;
if (redirect_is_delimiter(token))
break ;
if (token->type != T_REDIRECT_IN && token->type != T_HEREDOC) if (token->type != T_REDIRECT_IN && token->type != T_HEREDOC)
{ {
current = current->next; current = current->next;
continue ; continue ;
} }
if (token->type == T_HEREDOC && redirect_is_valid(current, token, -1)) check_heredoc(msh, current, token);
result = process_heredoc(msh, token, current->next->content); flag = redirect_is_valid(current, token, F_OK | R_OK);
if (redirect_is_valid(current, token, F_OK | R_OK)) redirect_create(msh, &current, &redirects, token->type);
{
ft_lstadd_back(&redirects, ft_lstnew_safe(msh,
redirect_new(msh, token->type,
ft_strdup_safe(msh,
((t_token *)current->next->content)->value))));
current = current->next;
continue;
}
else
{
ft_lstadd_front(&redirects, ft_lstnew_safe(msh, redirect_new(msh, T_ERROR, NULL)));
break;
}
current = current->next; current = current->next;
} }
if (result < 0) if (flag <= 0)
{
ft_lstadd_front(&redirects, ft_lstnew_safe(msh, redirect_new(msh, T_ERROR, NULL))); ft_lstadd_front(&redirects, ft_lstnew_safe(msh, redirect_new(msh, T_ERROR, NULL)));
}
return (redirects); return (redirects);
} }