From cbbe866ff44ced12a7972df363f80f69e66c4856 Mon Sep 17 00:00:00 2001 From: mdev9 Date: Tue, 2 Apr 2024 13:43:49 +0200 Subject: [PATCH] fixed redirections types handling --- srcs/input_redirections.c | 12 +++--------- srcs/pipe.c | 12 ++++++------ 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/srcs/input_redirections.c b/srcs/input_redirections.c index 296c26e..e2d9419 100644 --- a/srcs/input_redirections.c +++ b/srcs/input_redirections.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/05 18:15:27 by marde-vr #+# #+# */ -/* Updated: 2024/04/02 02:13:50 by tomoron ### ########.fr */ +/* Updated: 2024/04/02 13:28:32 by babonnet ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,7 +14,7 @@ void redirect_input(t_msh *msh) { - if (/*msh->in_type != PIPE*/ 1) + if (msh->in_type != PIPE) { if (dup2(msh->in_fd, 0) < 0) ft_exit(msh, 1); @@ -52,13 +52,7 @@ void get_in_type(t_msh *msh, t_cmd *tokens) cur_token = tokens; while (cur_token && cur_token->next && cur_token->cmd_type == CMD) cur_token = cur_token->next; - // if (cur_token->type) - //{ - // msh->in_type = cur_token->type; - // if (cur_token->type == HERE_DOC || cur_token->type == RED_I) - // open_input_file(msh, &cur_token); - //} pas sur de ce que c'est censé faire , j'ai fais un truc différent en dessous - if (cur_token->cmd_type == HERE_DOC || cur_token->cmd_type == RED_I) + if (/*cur_token->type && */cur_token->cmd_type == HERE_DOC || cur_token->cmd_type == RED_I) { msh->in_type = cur_token->cmd_type; open_input_file(msh, &cur_token); diff --git a/srcs/pipe.c b/srcs/pipe.c index 7a73713..5af5585 100644 --- a/srcs/pipe.c +++ b/srcs/pipe.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/05 18:17:25 by marde-vr #+# #+# */ -/* Updated: 2024/04/02 02:07:25 by tomoron ### ########.fr */ +/* Updated: 2024/04/02 13:24:17 by babonnet ### ########.fr */ /* */ /* ************************************************************************** */ @@ -48,11 +48,11 @@ void execute_command(t_msh *msh, char **cmd_args) void child(t_msh *msh, char **cmd_args, int i) { - // flemme - //if ((msh->in_type != ARG /*&& msh->in_type != PIPE*/) - // || (/*msh->in_type == PIPE &&*/ i > 0)) - // redirect_input(msh); - if (/*msh->out_type == PIPE ||*/ msh->out_type == RED_O + if ((msh->in_type != CMD && msh->in_type != PAREN && msh->in_type != AND + && msh->in_type != OR && msh->in_type != PIPE) + || (msh->in_type == PIPE && i > 0)) + redirect_input(msh); + if (msh->out_type == PIPE || msh->out_type == RED_O || msh->out_type == RED_O_APP) redirect_output(msh, i); close_pipe_fds(msh, i);