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

#include "libft.h"
#include "minishell.h"
#include "utils.h"

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);
	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);
		simple_builtins(msh);
		free_minishell_line(msh);
	}
	ft_lstclear_safe(msh, &msh->commands, free_command_list);
	free_minishell(&msh);
	rl_clear_history();
	return (EXIT_SUCCESS);
}
