From 7885c3ee09a542bd427b334fb448712831b9f929 Mon Sep 17 00:00:00 2001 From: narnaud Date: Wed, 11 May 2022 15:30:49 +0200 Subject: [PATCH] fix: operators --- caller.c | 19 +++++++++++++------ minishell.h | 4 ++-- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/caller.c b/caller.c index 9a55fae..8bbf1cc 100755 --- a/caller.c +++ b/caller.c @@ -6,7 +6,7 @@ /* By: mea +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/05/03 11:48:16 by narnaud #+# #+# */ -/* Updated: 2022/05/11 01:24:29 by narnaud@stude ### ########.fr */ +/* Updated: 2022/05/11 15:29:42 by narnaud@stude ### ########.fr */ /* */ /* ************************************************************************** */ @@ -52,12 +52,19 @@ int builtin_call(t_datas *datas, t_command *cmd) return (-1); } +int check_skip(t_datas *datas, t_command *cmd) +{ + if (cmd->next && ((cmd->ope == AND && !datas->exit_code) \ + || (cmd->ope == OR && datas->exit_code))) + return (0); + return (1); +} + int piper(t_datas *datas, t_command *cmd) { int pip[2]; pid_t pid; int status; - int exit_code; if (cmd->ope == PIPE) { @@ -79,11 +86,11 @@ int piper(t_datas *datas, t_command *cmd) else { waitpid(pid, &status, 0); - exit_code = handle_status(datas, status); - if (cmd->next && ((cmd->ope == AND && !exit_code) \ - || (cmd->ope == OR && exit_code))) + datas->exit_code = handle_status(datas, status); + while (cmd->next && check_skip(datas, cmd)) + cmd = cmd->next; + if (cmd->next) piper(datas, cmd->next); - datas->exit_code = exit_code; } return (1); } diff --git a/minishell.h b/minishell.h index f0f0ed7..de7d606 100755 --- a/minishell.h +++ b/minishell.h @@ -6,7 +6,7 @@ /* By: mea +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/05/02 13:50:44 by narnaud #+# #+# */ -/* Updated: 2022/05/11 01:24:53 by narnaud@stude ### ########.fr */ +/* Updated: 2022/05/11 15:19:11 by narnaud@stude ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,7 +15,7 @@ # define ENVP_MAX_SIZE 1024 # define STR_MAX_SIZE 1024 # define PATHS_MAX_SIZE 126 -# define DEBUG 1 +# define DEBUG 0 # include "libft/libft.h" # include