exec: command to toggle execution

Execution starts out being enabled. But it can be toggled on and off by using
the .exec command.
This commit is contained in:
Khaïs COLIN 2025-04-09 14:04:14 +02:00
parent ac411d36cc
commit 6576c47b56
Signed by: logistic-bot
SSH key fingerprint: SHA256:RlpiqKeXpcPFZZ4y9Ou4xi2M8OhRJovIwDlbCaMsuAo
3 changed files with 13 additions and 4 deletions

View file

@ -6,7 +6,7 @@
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);
}

View file

@ -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)

View file

@ -5,8 +5,8 @@
/* +:+ +:+ +:+ */
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);