42_minishell/main.c
2023-02-15 20:52:27 +01:00

54 lines
1003 B
C

#include "libftx/libftx.h"
#include "minishell.h"
#include <fcntl.h>
/* int main(int ac, char **av) */
/* { */
/* char *line; */
/* int fd; */
/* */
/* if (ac != 2) */
/* return (1); */
/* fd = open(av[1], O_RDONLY); */
/* line = get_next_line(fd); */
/* while (line != NULL) */
/* { */
/* ft_printf(line); */
/* line = get_next_line(fd); */
/* free(line); */
/* } */
/* free(line); */
/* return (0); */
/* } */
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]);
ft_printf("%s\n", line);
data.env = init_env(env);
if (data.env == NULL)
return (1);
cmds = ft_parse_cmds(line);
if (cmds == NULL)
return (1);
ft_printf("%s\n", line);
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);
}