42_minishell/main.c

50 lines
1.5 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/16 15:16:14 by cchauvet #+# #+# */
/* Updated: 2023/02/16 18:19:49 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int main(int ac, char **av, char **env)
{
t_list **cmds;
char *line;
t_data data;
if (ac == 1)
return (1);
line = ft_normalizer(av[1]);
if (line == NULL)
return (1);
if (ft_syntatic_verif(line) == 1)
{
free(line);
return (1);
}
data.env = init_env(env);
if (data.env == NULL)
return (1);
cmds = ft_parse_cmds(line, data.env);
if (cmds == NULL)
return (1);
if (ft_cmds_executor(cmds, data.env) == 1)
{
ft_lstclear(data.env, env_del);
ft_lstclear(cmds, ft_cmddel);
return (1);
}
ft_lstclear(data.env, env_del);
ft_lstclear(cmds, ft_cmddel);
free(cmds);
free(data.env);
free(line);
return (0);
}