From 46bea87309a619b65e83fc645cc0e9ce0005936e Mon Sep 17 00:00:00 2001 From: Quinten Mennen Date: Wed, 26 Feb 2025 17:25:22 +0100 Subject: [PATCH] get inputs is done --- inc/redirect.h | 3 +- src/redirect/redirect_get_inputs.c | 48 ++++++++++++------------------ 2 files changed, 21 insertions(+), 30 deletions(-) diff --git a/inc/redirect.h b/inc/redirect.h index 4a0cdbb..3c4c63f 100644 --- a/inc/redirect.h +++ b/inc/redirect.h @@ -14,7 +14,8 @@ # define REDIRECT_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_outputs(t_minishell *msh, t_list *list); int redirect_is_valid(t_list *lst, t_token *token, int mode); diff --git a/src/redirect/redirect_get_inputs.c b/src/redirect/redirect_get_inputs.c index cb864bf..8b4b383 100644 --- a/src/redirect/redirect_get_inputs.c +++ b/src/redirect/redirect_get_inputs.c @@ -6,53 +6,43 @@ /* By: qmennen +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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" -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; - t_list *redirects; - t_token *token; - int result; + if (token->type == T_HEREDOC && redirect_is_valid(current, token, -1)) + process_heredoc(msh, token, current->next->content); +} + +t_list *redirect_get_inputs(t_minishell *msh, t_list *list) +{ + t_list *current; + t_list *redirects; + t_token *token; + int flag; redirects = NULL; current = list; - result = 1; - while (current && result) + flag = 1; + token = (t_token *)current->content; + while (current && flag && !redirect_is_delimiter(token)) { token = (t_token *)current->content; - if (redirect_is_delimiter(token)) - break ; if (token->type != T_REDIRECT_IN && token->type != T_HEREDOC) { current = current->next; continue ; } - if (token->type == T_HEREDOC && redirect_is_valid(current, token, -1)) - result = process_heredoc(msh, token, current->next->content); - if (redirect_is_valid(current, token, F_OK | R_OK)) - { - 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; - } + check_heredoc(msh, current, token); + flag = redirect_is_valid(current, token, F_OK | R_OK); + redirect_create(msh, ¤t, &redirects, token->type); current = current->next; } - if (result < 0) - { + if (flag <= 0) ft_lstadd_front(&redirects, ft_lstnew_safe(msh, redirect_new(msh, T_ERROR, NULL))); - } return (redirects); }