From 50096be197b1494aeca567684e9ffc8a230e10c8 Mon Sep 17 00:00:00 2001 From: mcolonna Date: Tue, 25 Jun 2024 13:37:50 +0200 Subject: [PATCH] change exec_builtins prototype --- include/builtins.h | 4 ++-- src/builtin.c | 21 ++++++++------------- src/exec_command.c | 10 +++++----- 3 files changed, 15 insertions(+), 20 deletions(-) diff --git a/include/builtins.h b/include/builtins.h index d604fd7..e73e5d2 100644 --- a/include/builtins.h +++ b/include/builtins.h @@ -6,7 +6,7 @@ /* By: jschaft +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/04/23 14:15:12 by mcolonna #+# #+# */ -/* Updated: 2024/06/25 11:38:41 by jschaft ### ########.fr */ +/* Updated: 2024/06/25 13:28:18 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,6 +19,6 @@ bool is_builtin(const char *str); // Execute the builtin command -int exec_builtin(t_call call, char *const envp[]); +int exec_builtin(t_call call, t_env *env); #endif diff --git a/src/builtin.c b/src/builtin.c index 3f29f8d..a07b947 100644 --- a/src/builtin.c +++ b/src/builtin.c @@ -6,7 +6,7 @@ /* By: jschaft +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/03 12:02:45 by jschaft #+# #+# */ -/* Updated: 2024/06/25 11:46:40 by jschaft ### ########.fr */ +/* Updated: 2024/06/25 13:37:36 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,11 +19,12 @@ bool is_builtin(const char *str) return ( ft_strncmp(str, "cd", 3) == 0 || ft_strncmp(str, "exit", 5) == 0 - || ft_strncmp(str, "export", 7) == 0 +// || ft_strncmp(str, "export", 7) == 0 || ft_strncmp(str, "env", 4) == 0 || ft_strncmp(str, "pwd", 4) == 0 - || ft_strncmp(str, "echo", 5) == 0 - || ft_strncmp(str, "unset", 6) == 0); +// || ft_strncmp(str, "echo", 5) == 0 +// || ft_strncmp(str, "unset", 6) == 0 + ); } // Execute the builtin cd for the specified path. @@ -66,22 +67,16 @@ static int env_builtin(char *const envp[]) return (0); } -void exit_builtin(void) -{ - mem_freeall(*get_global_mc_pointer()); - exit(0); -} - // Execute the specified builtin. // The builtin must exist. // Return the error value returned by the builtin. // TODO all the builtins -int exec_builtin(t_call call, char *const envp[]) +int exec_builtin(t_call call, t_env *env) { if (ft_strncmp(call.program, "cd", 3) == 0) return (cd_builtin(call.argv[1])); if (ft_strncmp(call.program, "exit", 5) == 0) - exit_builtin(); + env->exit = true; /* if (ft_strncmp(call.program, "export", 7) == 0) return (export_builtin(call.argv)); if (ft_strncmp(call.program, "unset", 6) == 0) @@ -89,6 +84,6 @@ int exec_builtin(t_call call, char *const envp[]) if (ft_strncmp(call.program, "pwd", 4) == 0) return (pwd_builtin()); if (ft_strncmp(call.program, "env", 4) == 0) - return (env_builtin(envp)); + return (env_builtin(env->envp)); return (1); } diff --git a/src/exec_command.c b/src/exec_command.c index 6f62a88..420a063 100644 --- a/src/exec_command.c +++ b/src/exec_command.c @@ -6,7 +6,7 @@ /* By: jschaft +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/04/24 13:48:00 by jschaft #+# #+# */ -/* Updated: 2024/06/25 11:38:46 by jschaft ### ########.fr */ +/* Updated: 2024/06/25 13:29:58 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ @@ -91,7 +91,7 @@ static int create_pipes(t_exec_command_global *global, t_command command) } static int exec_each_call(t_exec_command_global *global, - t_command command, char *const envp[]) + t_command command, t_env *env) { int i; int r; @@ -103,9 +103,9 @@ static int exec_each_call(t_exec_command_global *global, inout[0] = global->pipes[i].pipe[0]; inout[1] = global->pipes[i + 1].pipe[1]; if (is_builtin(command.calls[i].program)) - r = exec_builtin(command.calls[i], envp); + r = exec_builtin(command.calls[i], env); else - r = execute_call(global, command.calls[i], inout, envp); + r = execute_call(global, command.calls[i], inout, env->envp); if (r) return (r); } @@ -128,7 +128,7 @@ int execute_command(t_env *env, t_command command) r = create_pipes(&global, command); if (r) return (r); - r = exec_each_call(&global, command, env->envp); + r = exec_each_call(&global, command, env); close_all_pipes(&global); while (wait(NULL) != -1) ;