diff options
Diffstat (limited to 'src/builtin')
| -rw-r--r-- | src/builtin/builtin.c | 61 | ||||
| -rw-r--r-- | src/builtin/cd.c | 2 | ||||
| -rw-r--r-- | src/builtin/echo.c | 3 | ||||
| -rw-r--r-- | src/builtin/env.c | 3 | ||||
| -rw-r--r-- | src/builtin/exit.c | 9 | ||||
| -rw-r--r-- | src/builtin/export.c | 12 | ||||
| -rw-r--r-- | src/builtin/pwd.c | 4 | ||||
| -rw-r--r-- | src/builtin/unset.c | 2 |
8 files changed, 87 insertions, 9 deletions
diff --git a/src/builtin/builtin.c b/src/builtin/builtin.c new file mode 100644 index 0000000..4889f9c --- /dev/null +++ b/src/builtin/builtin.c @@ -0,0 +1,61 @@ +/** +** \file builtin.c +** \brief Builtin functions +*/ + +#include "minishell.h" + +/** +** \brief Array storing builtin executable name and associated functions +*/ + +static struct s_builtin_entry g_builtin_lookup[] = { + {"echo", builtin_echo}, + {"cd", builtin_cd}, + {"pwd", builtin_pwd}, + {"export", builtin_export}, + {"unset", builtin_unset}, + {"env", builtin_env}, + {"exit", builtin_exit}, +}; + +/** +** \brief Call builtin function associated with command name +** \param argv Arguments to the builtin 'main', with argv[0] being the executable name +** \param env Environment Vector +** \return Builtin main return status +*/ + +int builtin_dispatch_run(char **argv, t_env env) +{ + size_t i; + + i = 0; + while (i < sizeof(g_builtin_lookup) / sizeof(struct s_builtin_entry)) + { + if (ft_strcmp(g_builtin_lookup[i].name, argv[0]) == 0) + return (g_builtin_lookup[i].func(argv, env)); + i++; + } + return (BUILTIN_NOT_FOUND); +} + +/** +** \brief Check if executable name is a builtin +** \param exec_name Executable name +** \return True if executable name is a builtin +*/ + +bool builtin_check_exec_name(char *exec_name) +{ + size_t i; + + i = 0; + while (i < sizeof(g_builtin_lookup) / sizeof(struct s_builtin_entry)) + { + if (ft_strcmp(g_builtin_lookup[i].name, exec_name) == 0) + return (true); + i++; + } + return (false); +} diff --git a/src/builtin/cd.c b/src/builtin/cd.c index 14c38d2..db629b0 100644 --- a/src/builtin/cd.c +++ b/src/builtin/cd.c @@ -5,7 +5,7 @@ #include "minishell.h" -int builtin_cd(t_env env, char **argv) +int builtin_cd(char **argv, t_env env) { char *path; diff --git a/src/builtin/echo.c b/src/builtin/echo.c index b9f2e28..c9e8cc7 100644 --- a/src/builtin/echo.c +++ b/src/builtin/echo.c @@ -5,10 +5,11 @@ #include "minishell.h" -int builtin_echo(char **argv) +int builtin_echo(char **argv, t_env env) { bool newline; + (void)env; newline = ft_strcmp(argv[1], "-n") == 0; if (newline) argv++; diff --git a/src/builtin/env.c b/src/builtin/env.c index 3869ead..352e2c3 100644 --- a/src/builtin/env.c +++ b/src/builtin/env.c @@ -13,8 +13,9 @@ void st_print_env_variable(t_ftht_entry *entry) ft_putchar('\n'); } -int builtin_env(t_env env) +int builtin_env(char **argv, t_env env) { + (void)argv; ft_htiter(env, st_print_env_variable); return (0); } diff --git a/src/builtin/exit.c b/src/builtin/exit.c index f4cc4fd..bd41f0f 100644 --- a/src/builtin/exit.c +++ b/src/builtin/exit.c @@ -1,4 +1,13 @@ +#include "minishell.h" + /** ** \file exit.c ** \brief `exit` builtin */ + +int builtin_exit(char **argv, t_env env) +{ + (void)argv; + (void)env; + return (0); +} diff --git a/src/builtin/export.c b/src/builtin/export.c index c0839b9..1b148a9 100644 --- a/src/builtin/export.c +++ b/src/builtin/export.c @@ -5,7 +5,11 @@ #include "minishell.h" -/* int export(t_env env, char **argv) */ -/* { */ -/* return (0); */ -/* } */ +int builtin_export(char **argv, t_env env) +{ + (void)argv; + (void)env; + /* if (ft_htset(env, ) == NULL) */ + /* return (-1); */ + return (0); +} diff --git a/src/builtin/pwd.c b/src/builtin/pwd.c index 813c4c6..6e0971f 100644 --- a/src/builtin/pwd.c +++ b/src/builtin/pwd.c @@ -5,10 +5,12 @@ #include "minishell.h" -int builtin_pwd(void) +int builtin_pwd(char **argv, t_env env) { char buf[PATH_MAX]; + (void)argv; + (void)env; ft_bzero(buf, PATH_MAX); if (getcwd(buf, PATH_MAX) == NULL) return (1); diff --git a/src/builtin/unset.c b/src/builtin/unset.c index 64f25f4..1fc5ce1 100644 --- a/src/builtin/unset.c +++ b/src/builtin/unset.c @@ -5,7 +5,7 @@ #include "minishell.h" -int builtin_unset(t_env env, char **argv) +int builtin_unset(char **argv, t_env env) { if (argv[1] == NULL) return (1); |
