89 lines
2.2 KiB
C
89 lines
2.2 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* main.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2023/02/16 15:16:14 by cchauvet #+# #+# */
|
|
/* Updated: 2023/02/17 13:13:19 by cchauvet ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "minishell.h"
|
|
|
|
int main(int ac, char **av, char **env)
|
|
{
|
|
t_list **cmds;
|
|
char *line;
|
|
int infile;
|
|
int outfile;
|
|
t_data data;
|
|
|
|
if (ac == 1)
|
|
return (1);
|
|
data.env = init_env(env);
|
|
if (data.env == NULL)
|
|
return (1);
|
|
line = ft_normalizer(av[1]);
|
|
if (line == NULL)
|
|
{
|
|
ft_lstclear(data.env, env_del);
|
|
free(data.env);
|
|
return (1);
|
|
}
|
|
if (ft_syntatic_verif(line) == 1)
|
|
{
|
|
ft_lstclear(data.env, env_del);
|
|
free(data.env);
|
|
free(line);
|
|
return (1);
|
|
}
|
|
outfile = ft_outfile(line);
|
|
if (outfile == -2)
|
|
{
|
|
ft_lstclear(data.env, env_del);
|
|
free(data.env);
|
|
free(line);
|
|
return (1);
|
|
}
|
|
infile = ft_infile(line);
|
|
if (infile == -2)
|
|
{
|
|
close(outfile);
|
|
ft_lstclear(data.env, env_del);
|
|
free(data.env);
|
|
free(line);
|
|
return (1);
|
|
}
|
|
cmds = ft_parse_cmds(line, data.env, infile, outfile);
|
|
if (cmds == NULL)
|
|
{
|
|
close(outfile);
|
|
close(infile);
|
|
ft_lstclear(data.env, env_del);
|
|
ft_lstclear(cmds, ft_cmddel);
|
|
free(cmds);
|
|
free(data.env);
|
|
free(line);
|
|
return (1);
|
|
}
|
|
if (ft_cmds_executor(cmds, data.env) == 1)
|
|
{
|
|
close(outfile);
|
|
close(infile);
|
|
ft_lstclear(data.env, env_del);
|
|
ft_lstclear(cmds, ft_cmddel);
|
|
free(cmds);
|
|
free(data.env);
|
|
free(line);
|
|
return (1);
|
|
}
|
|
ft_lstclear(data.env, env_del);
|
|
ft_lstclear(cmds, ft_cmddel);
|
|
free(cmds);
|
|
free(data.env);
|
|
free(line);
|
|
return (0);
|
|
}
|