From ba9751e0898a7fe9fdf7328c2239a2947a0c35a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kha=C3=AFs=20COLIN?= Date: Tue, 8 Apr 2025 16:10:34 +0200 Subject: [PATCH] do postprocessing for each simple_cmd before execution --- src/executing/simple_cmd/simple_cmd_execute.c | 24 ++++++++++++++++++- src/minishell.c | 2 +- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/executing/simple_cmd/simple_cmd_execute.c b/src/executing/simple_cmd/simple_cmd_execute.c index 87e8997..60f5a6f 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/04 19:56:34 by khais ### ########.fr */ +/* Updated: 2025/04/07 17:56:56 by khais ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,6 +21,10 @@ #include #include #include +#include "../../parser/remove_quotes/remove_quotes.h" +#include "../../postprocess/expansion/expand_vars.h" +#include "../../postprocess/fieldsplit/fieldsplit.h" +#include "../../postprocess/expansion/expand_wildcard.h" static void command_not_found(t_simple_cmd *cmd) { @@ -62,6 +66,22 @@ static t_simple_cmd *handle_redirections(t_simple_cmd *cmd, t_minishell *app) return (cmd); } +/* +** Do all the post-processing steps relating to a command. +*/ +static t_simple_cmd *post_process_command(t_simple_cmd *cmd, t_minishell *app) +{ + if (simple_cmd_expand_vars(cmd, app) == NULL) + return (simple_cmd_destroy(cmd), NULL); + if (simple_cmd_fieldsplit(cmd) == NULL) + return (simple_cmd_destroy(cmd), NULL); + if (simple_cmd_expand_wildcards(cmd) == NULL) + return (simple_cmd_destroy(cmd), NULL); + if (simple_cmd_remove_quotes(cmd) == NULL) + return (simple_cmd_destroy(cmd), NULL); + return (cmd); +} + void simple_cmd_execute(t_simple_cmd *cmd, t_minishell *app) { char *exe; @@ -69,6 +89,8 @@ void simple_cmd_execute(t_simple_cmd *cmd, t_minishell *app) if (cmd == NULL || cmd->words == NULL || cmd->words->word == NULL) return ; + if (post_process_command(cmd, app) == NULL) + return ; if (handle_redirections(cmd, app) == NULL) return ; if (execute_builtin(cmd, app) != BUILTIN_INVALID) diff --git a/src/minishell.c b/src/minishell.c index 55324f5..27ddc99 100644 --- a/src/minishell.c +++ b/src/minishell.c @@ -6,7 +6,7 @@ /* By: khais +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/02/06 13:44:06 by kcolin #+# #+# */ -/* Updated: 2025/04/15 11:53:49 by khais ### ########.fr */ +/* Updated: 2025/04/15 11:54:46 by khais ### ########.fr */ /* */ /* ************************************************************************** */