2023-02-06 14:41:10 -05:00
|
|
|
#include "libftx/libftx.h"
|
2023-01-31 08:40:15 -05:00
|
|
|
#include "minishell.h"
|
2023-02-15 14:52:27 -05:00
|
|
|
#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); */
|
|
|
|
/* } */
|
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
|
|
|
}
|