42_minishell/main.c

50 lines
1.5 KiB
C
Raw Normal View History

2023-02-16 09:17:32 -05:00
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 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 */
/* */
/* ************************************************************************** */
2023-02-15 14:52:27 -05:00
2023-02-16 09:17:32 -05:00
#include "minishell.h"
2023-02-09 12:47:05 -05:00
2023-02-14 07:38:40 -05:00
int main(int ac, char **av, char **env)
2023-01-31 09:02:23 -05:00
{
2023-02-09 12:47:05 -05:00
t_list **cmds;
2023-02-15 14:52:27 -05:00
char *line;
2023-02-14 07:38:40 -05:00
t_data data;
2023-02-09 12:47:05 -05:00
2023-02-01 11:28:38 -05:00
if (ac == 1)
return (1);
2023-02-15 14:52:27 -05:00
line = ft_normalizer(av[1]);
2023-02-16 08:54:19 -05:00
if (line == NULL)
return (1);
if (ft_syntatic_verif(line) == 1)
{
free(line);
return (1);
}
2023-02-14 07:38:40 -05:00
data.env = init_env(env);
if (data.env == NULL)
return (1);
2023-02-15 14:52:27 -05:00
cmds = ft_parse_cmds(line);
2023-02-09 12:47:05 -05:00
if (cmds == NULL)
return (1);
2023-02-14 07:38:40 -05:00
if (ft_cmds_executor(cmds, env) == 1)
2023-02-14 01:08:25 -05:00
{
2023-02-14 07:38:40 -05:00
ft_lstclear(data.env, env_del);
2023-02-15 14:52:27 -05:00
ft_lstclear(cmds, ft_cmddel);
2023-02-09 12:47:05 -05:00
return (1);
2023-02-14 01:08:25 -05:00
}
2023-02-14 07:38:40 -05:00
ft_lstclear(data.env, env_del);
2023-02-15 14:52:27 -05:00
ft_lstclear(cmds, ft_cmddel);
2023-02-14 11:11:39 -05:00
free(cmds);
free(data.env);
2023-02-15 14:52:27 -05:00
free(line);
2023-02-14 07:38:40 -05:00
return (0);
2023-01-31 09:02:23 -05:00
}