/* ************************************************************************** */
/*                                                                            */
/*                                                        ::::::::            */
/*   redirect_get_outputs.c                             :+:    :+:            */
/*                                                     +:+                    */
/*   By: qmennen <qmennen@student.codam.nl>           +#+                     */
/*                                                   +#+                      */
/*   Created: 2025/02/23 12:37:24 by Quinten       #+#    #+#                 */
/*   Updated: 2025/02/28 01:20:07 by whaffman      ########   odam.nl         */
/*                                                                            */
/* ************************************************************************** */

#include "minishell.h"

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;
	token = (t_token *)current->content;
	while (current && !redirect_is_delimiter(token))
	{
		token = (t_token *)current->content;
		if (token->type != T_REDIRECT_OUT && token->type != T_APPEND_OUT)
		{
			current = current->next;
			continue ;
		}
		flag = redirect_is_valid(current, token, -1);
		if (flag)
			redirect_create(msh, &current, &redirects, token->type);
		current = current->next;
	}
	redirect_new_error(msh, &redirects, flag);
	return (redirects);
}
