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
This commit is contained in:
Khaïs COLIN 2025-04-15 15:44:14 +02:00
parent 1a949bdcab
commit 81ba53237c
4 changed files with 16 additions and 6 deletions

View file

@ -6,7 +6,7 @@
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */ /* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/27 16:21:56 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) if (cmd == NULL || cmd->words == NULL || cmd->words->word == NULL)
return ; return ;
simple_cmd_post_process_debug(cmd, app);
if (post_process_command(cmd, app) == NULL) if (post_process_command(cmd, app) == NULL)
return ; return ;
simple_cmd_execute_debug(cmd, app); simple_cmd_execute_debug(cmd, app);

View file

@ -6,7 +6,7 @@
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */ /* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/10 15:36:26 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); 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);
}
}

View file

@ -6,7 +6,7 @@
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */ /* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/10 15:36:08 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" # include "../../minishell.h"
void simple_cmd_execute_debug(t_simple_cmd *cmd, t_minishell *app); 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 #endif // SIMPLE_CMD_EXECUTE_DEBUG_H

View file

@ -6,7 +6,7 @@
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */ /* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/31 10:28:28 by jguelen #+# #+# */ /* 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; t_wordlist *tokens;
ft_errno(FT_ESUCCESS); ft_errno(FT_ESUCCESS);
app->last_return_value = 0;
if (!command_line) if (!command_line)
return (NULL); return (NULL);
tokens = minishell_wordsplit(command_line); 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); root_cmd = minishell_cmds_parse(app, &tokens);
if (!root_cmd) if (!root_cmd)
{ {
if (ft_errno_get() != FT_ESUCCESS && !app->last_return_value) if (ft_errno_get() != FT_ESUCCESS)
app->last_return_value = 1; app->last_return_value = 1;
return (wordlist_destroy(tokens), NULL); return (wordlist_destroy(tokens), NULL);
} }