[ADD] builtin unset

This commit is contained in:
mcolonna 2024-06-27 16:08:38 +02:00
parent 7c92b7fe56
commit 5bece6093b
3 changed files with 25 additions and 11 deletions

View file

@ -6,12 +6,27 @@
/* By: jschaft <cecile.schaft@orange.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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)