42_minishell/main.c
Camille Chauvet edbd267c0d merge
2023-02-16 15:17:32 +01:00

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 15:16:45 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);
if (cmds == NULL)
return (1);
if (ft_cmds_executor(cmds, 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);
}