redirect out

This commit is contained in:
Quinten Mennen 2025-02-26 17:27:38 +01:00
parent 46bea87309
commit d96b23ca02
3 changed files with 23 additions and 16 deletions

View File

@ -17,32 +17,25 @@ t_list *redirect_get_outputs(t_minishell *msh, t_list *list)
t_list *current;
t_list *redirects;
t_token *token;
int flag;
flag = 1;
redirects = NULL;
current = list;
while (current)
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_OUT && token->type != T_APPEND_OUT)
{
current = current->next;
continue ;
}
if (redirect_is_valid(current, token, -1))
{
ft_lstadd_front(&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 ;
}
flag = redirect_is_valid(current, token, -1);
redirect_create(msh, &current, &redirects, token->type);
current = current->next;
}
if (flag <= 0)
ft_lstadd_front(&redirects, ft_lstnew_safe(msh, redirect_new(msh, T_ERROR, NULL)));
return (redirects);
}

View File

@ -23,3 +23,17 @@ t_redirect *redirect_new(t_minishell *msh, t_token_type type, char *value)
result->value = value;
return (result);
}
void redirect_create(t_minishell *msh, t_list **tokens, t_list **redirects, t_token_type type)
{
t_list *new;
t_redirect *redir;
t_token *file_token;
char *file_name;
file_token = (t_token *)((*tokens)->next->content);
file_name = ft_strdup_safe(msh, file_token->value);
redir = redirect_new(msh, type, file_name);
new = ft_lstnew_safe(msh, redir);
ft_lstadd_back(redirects, new);
*tokens = (*tokens)->next;
}

View File

@ -6,7 +6,7 @@
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/23 12:30:18 by Quinten #+# #+# */
/* Updated: 2025/02/26 16:56:51 by qmennen ### ########.fr */
/* Updated: 2025/02/26 17:12:40 by qmennen ### ########.fr */
/* */
/* ************************************************************************** */