From 5bece6093bf6a67cb9112cabbd7701add0d36b34 Mon Sep 17 00:00:00 2001 From: mcolonna Date: Thu, 27 Jun 2024 16:08:38 +0200 Subject: [PATCH] [ADD] builtin unset --- dev/TODO | 10 +++++----- include/builtins.h | 3 +-- src/builtin.c | 23 +++++++++++++++++++---- 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/dev/TODO b/dev/TODO index 81d685f..c517849 100644 --- a/dev/TODO +++ b/dev/TODO @@ -1,13 +1,13 @@ - finding commands - built-in commands - builtins: - - echo (with option -n) - - cd [path] - - pwd (with no options) + x echo (with option -n) + x cd [path] + x pwd (with no options) - export (with no options) - unset (with no options) - - env (with no options or arguments) - - exit (with no options) + x env (with no options or arguments) + x exit (with no options) - fix - the builtins should get all arguments and check if they're good diff --git a/include/builtins.h b/include/builtins.h index afb69ad..dabb054 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/27 15:54:05 by mcolonna ### ########.fr */ +/* Updated: 2024/06/27 16:08:14 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ @@ -24,5 +24,4 @@ int exec_builtin(t_call call, t_env *env); // Execute echo builtin int echo_builtin(const char **argv); - #endif diff --git a/src/builtin.c b/src/builtin.c index 46676a4..021a633 100644 --- a/src/builtin.c +++ b/src/builtin.c @@ -6,12 +6,27 @@ /* By: jschaft +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/03 12:02:45 by jschaft #+# #+# */ -/* Updated: 2024/06/27 15:54:44 by mcolonna ### ########.fr */ +/* Updated: 2024/06/27 16:07:13 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ #include "include.h" +static int unset_builtin(t_env *env, t_call call) +{ + t_variable var; + int i; + + var.value = ""; + i = -1; + while (call.argv[++i]) + { + var.name = call.argv[++i]; + variables_set(env->variables, var); + } + return (0); +} + // Check if str is the name of a builtin. // Return true if it is, false if not. bool is_builtin(const char *str) @@ -23,7 +38,7 @@ bool is_builtin(const char *str) || 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, "unset", 6) == 0 ); } @@ -78,9 +93,9 @@ int exec_builtin(t_call call, t_env *env) if (ft_strncmp(call.program, "exit", 5) == 0) env->exit = true; /* if (ft_strncmp(call.program, "export", 7) == 0) - return (export_builtin(call.argv)); + return (export_builtin(call.argv));*/ if (ft_strncmp(call.program, "unset", 6) == 0) - return (unset_builtin());*/ + return (unset_builtin(env, call)); if (ft_strncmp(call.program, "pwd", 4) == 0) return (pwd_builtin()); if (ft_strncmp(call.program, "echo", 5) == 0)