[ADD] builtin unset
This commit is contained in:
parent
7c92b7fe56
commit
5bece6093b
3 changed files with 25 additions and 11 deletions
10
dev/TODO
10
dev/TODO
|
@ -1,13 +1,13 @@
|
||||||
- finding commands
|
- finding commands
|
||||||
- built-in commands
|
- built-in commands
|
||||||
- builtins:
|
- builtins:
|
||||||
- echo (with option -n)
|
x echo (with option -n)
|
||||||
- cd [path]
|
x cd [path]
|
||||||
- pwd (with no options)
|
x pwd (with no options)
|
||||||
- export (with no options)
|
- export (with no options)
|
||||||
- unset (with no options)
|
- unset (with no options)
|
||||||
- env (with no options or arguments)
|
x env (with no options or arguments)
|
||||||
- exit (with no options)
|
x exit (with no options)
|
||||||
- fix
|
- fix
|
||||||
- the builtins should get all arguments and check if they're good
|
- the builtins should get all arguments and check if they're good
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jschaft <cecile.schaft@orange.fr> +#+ +:+ +#+ */
|
/* By: jschaft <cecile.schaft@orange.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/04/23 14:15:12 by mcolonna #+# #+# */
|
/* 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
|
// Execute echo builtin
|
||||||
int echo_builtin(const char **argv);
|
int echo_builtin(const char **argv);
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -6,12 +6,27 @@
|
||||||
/* By: jschaft <cecile.schaft@orange.fr> +#+ +:+ +#+ */
|
/* By: jschaft <cecile.schaft@orange.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/06/03 12:02:45 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"
|
#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.
|
// Check if str is the name of a builtin.
|
||||||
// Return true if it is, false if not.
|
// Return true if it is, false if not.
|
||||||
bool is_builtin(const char *str)
|
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, "env", 4) == 0
|
||||||
|| ft_strncmp(str, "pwd", 4) == 0
|
|| ft_strncmp(str, "pwd", 4) == 0
|
||||||
|| ft_strncmp(str, "echo", 5) == 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)
|
if (ft_strncmp(call.program, "exit", 5) == 0)
|
||||||
env->exit = true;
|
env->exit = true;
|
||||||
/* if (ft_strncmp(call.program, "export", 7) == 0)
|
/* 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)
|
if (ft_strncmp(call.program, "unset", 6) == 0)
|
||||||
return (unset_builtin());*/
|
return (unset_builtin(env, call));
|
||||||
if (ft_strncmp(call.program, "pwd", 4) == 0)
|
if (ft_strncmp(call.program, "pwd", 4) == 0)
|
||||||
return (pwd_builtin());
|
return (pwd_builtin());
|
||||||
if (ft_strncmp(call.program, "echo", 5) == 0)
|
if (ft_strncmp(call.program, "echo", 5) == 0)
|
||||||
|
|
Loading…
Add table
Reference in a new issue