From 6576c47b566fb8cb06ef808f0b40bbf157bccbcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kha=C3=AFs=20COLIN?= Date: Wed, 9 Apr 2025 14:04:14 +0200 Subject: [PATCH] exec: command to toggle execution Execution starts out being enabled. But it can be toggled on and off by using the .exec command. --- src/get_command.c | 8 +++++++- src/minishell.c | 4 +++- src/minishell.h | 5 +++-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/get_command.c b/src/get_command.c index a3a30ab..76acb82 100644 --- a/src/get_command.c +++ b/src/get_command.c @@ -6,7 +6,7 @@ /* By: khais +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/02/19 18:03:11 by khais #+# #+# */ -/* Updated: 2025/04/09 13:59:20 by khais ### ########.fr */ +/* Updated: 2025/04/09 14:03:39 by khais ### ########.fr */ /* */ /* ************************************************************************** */ @@ -45,6 +45,12 @@ static char *handle_special_command(char *line, t_minishell *app) ft_printf("[dbg: %d]\n", (int)app->debug); line[0] = '\0'; } + if (ft_strcmp(".exec", line) == 0) + { + app->exec = !app->exec; + ft_printf("[exec: %d]\n", (int)app->exec); + line[0] = '\0'; + } return (line); } diff --git a/src/minishell.c b/src/minishell.c index 52e6da4..154617c 100644 --- a/src/minishell.c +++ b/src/minishell.c @@ -33,9 +33,10 @@ */ static void execute_command(t_simple_cmd *cmd, t_minishell *app) { + if (app->exec == false) + return ; set_exec_mode_sig_handling(); simple_cmd_execute(cmd, app); - simple_cmd_destroy(cmd); set_interactive_mode_sig_handling(); } @@ -71,6 +72,7 @@ static void app_init(t_minishell *app, char **envp) { ft_bzero(app, sizeof(t_minishell)); app->env = env_from_envp(envp); + app->exec = true; } int main(int argc, char *argv[], char **envp) diff --git a/src/minishell.h b/src/minishell.h index cea5010..d6f9c0f 100644 --- a/src/minishell.h +++ b/src/minishell.h @@ -5,8 +5,8 @@ /* +:+ +:+ +:+ */ /* By: khais +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2025/04/09 13:49:28 by khais #+# #+# */ -/* Updated: 2025/04/15 12:01:54 by khais ### ########.fr */ +/* Created: 2025/04/09 14:02:47 by khais #+# #+# */ +/* Updated: 2025/04/15 12:02:18 by khais ### ########.fr */ /* */ /* ************************************************************************** */ @@ -119,6 +119,7 @@ typedef struct s_minishell int lines_read; int last_return_value; bool debug; + bool exec; } t_minishell; t_redirect *t_redirect_add_back(t_redirect **init, t_redirect *back);