From f000625ab920fbc9f2d664f92cd2420f2d750e5d Mon Sep 17 00:00:00 2001 From: mdev9 Date: Tue, 5 Mar 2024 16:40:09 +0100 Subject: [PATCH] added redirections priority between input and output --- srcs/exec.c | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/srcs/exec.c b/srcs/exec.c index 35b38d2..7d306c0 100755 --- a/srcs/exec.c +++ b/srcs/exec.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/07 14:12:49 by tomoron #+# #+# */ -/* Updated: 2024/03/05 15:55:58 by marde-vr ### ########.fr */ +/* Updated: 2024/03/05 16:22:14 by marde-vr ### ########.fr */ /* */ /* ************************************************************************** */ @@ -428,6 +428,18 @@ void get_out_type(t_msh *msh, t_cmd *cmds) } } +int first_is_in_type(t_msh *msh) +{ + t_cmd *cur_cmd; + + cur_cmd = msh->cmds; + while (cur_cmd && cur_cmd->type == ARG && cur_cmd->next) + cur_cmd = cur_cmd->next; + if (cur_cmd->type == PIPE || cur_cmd->type == RED_I || cur_cmd->type == HERE_DOC) + return (1); + return (0); +} + void exec_command(t_msh *msh) { int cmd_count; @@ -448,9 +460,20 @@ void exec_command(t_msh *msh) msh->fds[i] = ft_calloc(2, sizeof(int *)); if (!msh->fds[i]) ft_exit(msh, 1); - get_in_type(msh, msh->cmds); - if (!g_return_code) //maybe???? + + if (first_is_in_type(msh)) + { + get_in_type(msh, msh->cmds); + if (!g_return_code) //maybe???? + get_out_type(msh, msh->cmds); + } + else + { get_out_type(msh, msh->cmds); + if (!g_return_code) //maybe???? + get_in_type(msh, msh->cmds); + } + //ft_printf_fd(2, "%d\n", msh->out_fd); //ft_printf_fd(2, "cmd: %s\n", msh->cmds->token); if (!cmd_is_builtin(msh, msh->cmds->token))