get inputs is done
This commit is contained in:
parent
abb2e8563a
commit
46bea87309
@ -15,6 +15,7 @@
|
||||
# include "minishell.h"
|
||||
|
||||
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);
|
||||
|
||||
@ -6,53 +6,43 @@
|
||||
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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"
|
||||
|
||||
static void check_heredoc(t_minishell *msh, t_list *current, t_token *token)
|
||||
{
|
||||
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 result;
|
||||
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);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user