/* ************************************************************************** */
/*                                                                            */
/*                                                        ::::::::            */
/*   main.c                                             :+:    :+:            */
/*                                                     +:+                    */
/*   By: whaffman <whaffman@student.codam.nl>         +#+                     */
/*                                                   +#+                      */
/*   Created: 2025/02/04 16:19:22 by whaffman      #+#    #+#                 */
/*   Updated: 2025/03/04 16:08:26 by whaffman      ########   odam.nl         */
/*                                                                            */
/* ************************************************************************** */

#include "minishell.h"

static void	main_loop(t_minishell *msh)
{
	while (TRUE)
	{
		msh->line = ft_prompt(msh);
		if (msh->line == NULL)
			break ;
		msh->lexer = ft_lexer_new(msh);
		msh->tokens = ft_parse_input(msh);
		ft_lstiter(msh->tokens, token_print);
		msh->commands = parser_get_commands(msh);
		executor_execute_pipeline(msh);
		free_minishell_line(msh);
	}
}

int	main(int argc, char **argv, char **envp)
{
	t_minishell		*msh;

	(void)argc;
	(void)argv;
	print_banner();
	history_load();
	msh = init_minishell();
	signal_init_minishell();
	environment_parse(msh, envp);
	main_loop(msh);
	free_minishell(&msh);
	rl_clear_history();
	return (EXIT_SUCCESS);
}
