diff options
| author | Charles <sircharlesaze@gmail.com> | 2020-04-01 15:55:57 +0200 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2020-04-01 15:55:57 +0200 |
| commit | 2eb59ee61e49b60472f82c000dd4f3536bd1987c (patch) | |
| tree | 190ac7bc42051ee9fcc7c1d781be16afa4d43075 /src/builtin/builtin.c | |
| parent | 551e668e1b7a030fdff236067963100c7d8747a5 (diff) | |
| download | minishell-2eb59ee61e49b60472f82c000dd4f3536bd1987c.tar.gz minishell-2eb59ee61e49b60472f82c000dd4f3536bd1987c.tar.bz2 minishell-2eb59ee61e49b60472f82c000dd4f3536bd1987c.zip | |
Added builtin support in command eval, Refactoring eval/builtin function, Added doc
Diffstat (limited to 'src/builtin/builtin.c')
| -rw-r--r-- | src/builtin/builtin.c | 61 |
1 files changed, 61 insertions, 0 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); +} |
