clean: norm part2 (FINAL)
This commit is contained in:
@ -6,17 +6,16 @@
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/21 12:45:16 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/03/28 15:46:43 by cchauvet ### ########.fr */
|
||||
/* Updated: 2023/03/29 18:53:35 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "execution_private.h"
|
||||
|
||||
static int ft_own_cmd(t_data *data, t_cmd *cmd)
|
||||
static int ft_execute_own_cmd(t_data *data, t_cmd *cmd)
|
||||
{
|
||||
int return_code;
|
||||
|
||||
return_code = -1;
|
||||
if (ft_strcmp(cmd->executable, "pwd") == 0)
|
||||
return_code = pwd(cmd->fd_out[0]);
|
||||
else if (ft_strcmp(cmd->executable, "env") == 0)
|
||||
@ -29,7 +28,7 @@ static int ft_own_cmd(t_data *data, t_cmd *cmd)
|
||||
return_code = (unset(data->env, cmd->args, cmd->fd_out[0]));
|
||||
else if (ft_strcmp(cmd->executable, "echo") == 0)
|
||||
return_code = (echo(cmd->fd_out[0], cmd->args + 1));
|
||||
else if (ft_strcmp(cmd->executable, "exit") == 0)
|
||||
else
|
||||
{
|
||||
return_code = ft_exit(cmd->args + 1);
|
||||
if (return_code >= 0)
|
||||
@ -72,7 +71,7 @@ static int ft_cmd_executor(t_data *data, t_cmd *cmd, int fd)
|
||||
|
||||
if (cmd->own_cmd == 1)
|
||||
{
|
||||
exit_code = ft_own_cmd(data, cmd);
|
||||
exit_code = ft_execute_own_cmd(data, cmd);
|
||||
ft_closer(cmd->fd_in);
|
||||
ft_closer(cmd->fd_out);
|
||||
if (exit_code == -1)
|
||||
@ -104,7 +103,6 @@ int ft_cmds_executor(t_data *data)
|
||||
{
|
||||
content = current->content;
|
||||
fds[0] = -1;
|
||||
fds[1] = -1;
|
||||
if (current->next != NULL)
|
||||
{
|
||||
if (pipe(fds) == -1)
|
||||
@ -112,7 +110,9 @@ int ft_cmds_executor(t_data *data)
|
||||
ft_add_fd(content->fd_out, fds[1]);
|
||||
ft_add_fd(((t_cmd *)(current->next->content))->fd_in, fds[0]);
|
||||
}
|
||||
if (ft_cmd_executor(data, content, fds[0]))
|
||||
if (content->fd_in[0] == -2 || content->fd_out[0] == -2)
|
||||
ft_mega_closer(content->fd_in, content->fd_out);
|
||||
else if (ft_cmd_executor(data, content, fds[0]))
|
||||
return (1);
|
||||
current = current->next;
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/03/28 15:45:53 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/03/28 15:45:54 by cchauvet ### ########.fr */
|
||||
/* Updated: 2023/03/29 18:55:22 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -17,7 +17,6 @@
|
||||
# include "../cmd/cmd.h"
|
||||
# include "../env/env.h"
|
||||
# include "../builtins/builtins.h"
|
||||
# include "../utils/utils.h"
|
||||
|
||||
void ft_closer(int fds[2]);
|
||||
void ft_add_fd(int fds[2], int fd);
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user