From 81ba53237cf7963677c5c05b8f72382222aa9928 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kha=C3=AFs=20COLIN?= Date: Tue, 15 Apr 2025 15:44:14 +0200 Subject: [PATCH] parsing: do not reset last_return_value at start of parsing we need to preserve it, to be able to show the return value from the last command --- src/executing/simple_cmd/simple_cmd_execute.c | 3 ++- src/executing/simple_cmd/simple_cmd_execute_debug.c | 11 ++++++++++- src/executing/simple_cmd/simple_cmd_execute_debug.h | 3 ++- src/parser/cmd_parsing.c | 5 ++--- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/executing/simple_cmd/simple_cmd_execute.c b/src/executing/simple_cmd/simple_cmd_execute.c index 94ce341..9c28d06 100644 --- a/src/executing/simple_cmd/simple_cmd_execute.c +++ b/src/executing/simple_cmd/simple_cmd_execute.c @@ -6,7 +6,7 @@ /* By: khais +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/03/27 16:21:56 by khais #+# #+# */ -/* Updated: 2025/04/08 16:12:36 by khais ### ########.fr */ +/* Updated: 2025/04/15 15:33:50 by khais ### ########.fr */ /* */ /* ************************************************************************** */ @@ -90,6 +90,7 @@ void simple_cmd_execute(t_simple_cmd *cmd, t_minishell *app) if (cmd == NULL || cmd->words == NULL || cmd->words->word == NULL) return ; + simple_cmd_post_process_debug(cmd, app); if (post_process_command(cmd, app) == NULL) return ; simple_cmd_execute_debug(cmd, app); diff --git a/src/executing/simple_cmd/simple_cmd_execute_debug.c b/src/executing/simple_cmd/simple_cmd_execute_debug.c index 236be0c..e775d9e 100644 --- a/src/executing/simple_cmd/simple_cmd_execute_debug.c +++ b/src/executing/simple_cmd/simple_cmd_execute_debug.c @@ -6,7 +6,7 @@ /* By: khais +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/04/10 15:36:26 by khais #+# #+# */ -/* Updated: 2025/04/10 15:37:29 by khais ### ########.fr */ +/* Updated: 2025/04/15 15:34:44 by khais ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,3 +22,12 @@ void simple_cmd_execute_debug(t_simple_cmd *cmd, t_minishell *app) simple_cmd_root_debug(cmd); } } + +void simple_cmd_post_process_debug(t_simple_cmd *cmd, t_minishell *app) +{ + if (app->debug) + { + ft_printf("about to post-process\n"); + simple_cmd_root_debug(cmd); + } +} diff --git a/src/executing/simple_cmd/simple_cmd_execute_debug.h b/src/executing/simple_cmd/simple_cmd_execute_debug.h index c5dd529..a6c3bff 100644 --- a/src/executing/simple_cmd/simple_cmd_execute_debug.h +++ b/src/executing/simple_cmd/simple_cmd_execute_debug.h @@ -6,7 +6,7 @@ /* By: khais +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/04/10 15:36:08 by khais #+# #+# */ -/* Updated: 2025/04/10 15:36:44 by khais ### ########.fr */ +/* Updated: 2025/04/15 15:34:14 by khais ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,5 +16,6 @@ # include "../../minishell.h" void simple_cmd_execute_debug(t_simple_cmd *cmd, t_minishell *app); +void simple_cmd_post_process_debug(t_simple_cmd *cmd, t_minishell *app); #endif // SIMPLE_CMD_EXECUTE_DEBUG_H diff --git a/src/parser/cmd_parsing.c b/src/parser/cmd_parsing.c index e992230..0ddda24 100644 --- a/src/parser/cmd_parsing.c +++ b/src/parser/cmd_parsing.c @@ -6,7 +6,7 @@ /* By: khais +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/03/31 10:28:28 by jguelen #+# #+# */ -/* Updated: 2025/04/15 14:15:49 by khais ### ########.fr */ +/* Updated: 2025/04/15 15:43:50 by khais ### ########.fr */ /* */ /* ************************************************************************** */ @@ -105,7 +105,6 @@ t_cmd *minishell_parse(t_minishell *app, char *command_line) t_wordlist *tokens; ft_errno(FT_ESUCCESS); - app->last_return_value = 0; if (!command_line) return (NULL); tokens = minishell_wordsplit(command_line); @@ -114,7 +113,7 @@ t_cmd *minishell_parse(t_minishell *app, char *command_line) root_cmd = minishell_cmds_parse(app, &tokens); if (!root_cmd) { - if (ft_errno_get() != FT_ESUCCESS && !app->last_return_value) + if (ft_errno_get() != FT_ESUCCESS) app->last_return_value = 1; return (wordlist_destroy(tokens), NULL); }