aboutsummaryrefslogtreecommitdiff
path: root/src/builtin
diff options
context:
space:
mode:
Diffstat (limited to 'src/builtin')
-rw-r--r--src/builtin/builtin.c12
-rw-r--r--src/builtin/cd.c9
-rw-r--r--src/builtin/echo.c9
-rw-r--r--src/builtin/env.c9
-rw-r--r--src/builtin/exit.c13
-rw-r--r--src/builtin/export.c14
-rw-r--r--src/builtin/pwd.c9
-rw-r--r--src/builtin/unset.c9
8 files changed, 73 insertions, 11 deletions
diff --git a/src/builtin/builtin.c b/src/builtin/builtin.c
index 08abcd8..23a5f44 100644
--- a/src/builtin/builtin.c
+++ b/src/builtin/builtin.c
@@ -6,7 +6,7 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/01 17:11:01 by charles #+# #+# */
-/* Updated: 2020/07/17 11:16:57 by charles ### ########.fr */
+/* Updated: 2020/09/13 20:18:32 by charles ### ########.fr */
/* */
/* ************************************************************************** */
@@ -18,7 +18,8 @@
#include "minishell.h"
/*
-** \brief Array storing builtin executable name and associated functions
+** \brief Array storing builtin executable name, associated functions
+** and if they should be executed in a fork
*/
static t_builtin_entry g_builtin_lookup[] = {
@@ -31,6 +32,13 @@ static t_builtin_entry g_builtin_lookup[] = {
{"exit", builtin_exit, false},
};
+/*
+** \brief Search a builtin by name in g_builtin_lookup
+** \param name Name of the searched builtin
+** \return the builtin entry of the associated name
+** or NULL if name is not a builtin.
+*/
+
t_builtin_entry *builtin_search_func(char *name)
{
size_t i;
diff --git a/src/builtin/cd.c b/src/builtin/cd.c
index de1eeb9..3be77ea 100644
--- a/src/builtin/cd.c
+++ b/src/builtin/cd.c
@@ -6,7 +6,7 @@
/* By: charles <charles@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/01 17:10:20 by charles #+# #+# */
-/* Updated: 2020/09/12 11:09:49 by charles ### ########.fr */
+/* Updated: 2020/09/13 20:20:13 by charles ### ########.fr */
/* */
/* ************************************************************************** */
@@ -17,6 +17,13 @@
#include "minishell.h"
+/*
+** \brief Change directory
+** \param argv arguments
+** \param env environment
+** \return a status code or EVAL_FATAL on fatal error
+*/
+
int builtin_cd(char **argv, t_env env)
{
char buf[PATH_MAX + 1];
diff --git a/src/builtin/echo.c b/src/builtin/echo.c
index 9ad427a..f15a7f2 100644
--- a/src/builtin/echo.c
+++ b/src/builtin/echo.c
@@ -6,7 +6,7 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/01 17:10:47 by charles #+# #+# */
-/* Updated: 2020/09/12 15:24:34 by charles ### ########.fr */
+/* Updated: 2020/09/13 20:24:34 by charles ### ########.fr */
/* */
/* ************************************************************************** */
@@ -17,6 +17,13 @@
#include "minishell.h"
+/*
+** \brief Print it's arguments out
+** \param argv arguments
+** \param env environment
+** \return a status code or EVAL_FATAL on fatal error
+*/
+
int builtin_echo(char **argv, t_env env)
{
bool newline;
diff --git a/src/builtin/env.c b/src/builtin/env.c
index 5854828..6b430c4 100644
--- a/src/builtin/env.c
+++ b/src/builtin/env.c
@@ -6,7 +6,7 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/01 17:10:32 by charles #+# #+# */
-/* Updated: 2020/04/01 22:25:43 by charles ### ########.fr */
+/* Updated: 2020/09/13 20:23:59 by charles ### ########.fr */
/* */
/* ************************************************************************** */
@@ -17,6 +17,13 @@
#include "minishell.h"
+/*
+** \brief Print the environment variables (one on each line)
+** \param argv arguments
+** \param env environment
+** \return a status code or EVAL_FATAL on fatal error
+*/
+
int builtin_env(char **argv, t_env env)
{
(void)argv;
diff --git a/src/builtin/exit.c b/src/builtin/exit.c
index a24efad..51c8013 100644
--- a/src/builtin/exit.c
+++ b/src/builtin/exit.c
@@ -6,17 +6,24 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/01 17:10:16 by charles #+# #+# */
-/* Updated: 2020/09/10 19:41:03 by charles ### ########.fr */
+/* Updated: 2020/09/13 20:25:55 by charles ### ########.fr */
/* */
/* ************************************************************************** */
-#include "minishell.h"
-
/*
** \file exit.c
** \brief `exit` builtin
*/
+#include "minishell.h"
+
+/*
+** \brief Exit the current process with a status
+** \param argv arguments
+** \param env environment
+** \return always 0
+*/
+
int builtin_exit(char **argv, t_env env)
{
long status;
diff --git a/src/builtin/export.c b/src/builtin/export.c
index f19842e..4ac6626 100644
--- a/src/builtin/export.c
+++ b/src/builtin/export.c
@@ -6,7 +6,7 @@
/* By: charles <charles@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/01 17:11:34 by charles #+# #+# */
-/* Updated: 2020/09/13 14:16:28 by charles ### ########.fr */
+/* Updated: 2020/09/13 20:22:10 by charles ### ########.fr */
/* */
/* ************************************************************************** */
@@ -17,6 +17,11 @@
#include "minishell.h"
+/*
+** \brief Put an environment variable in the format "declare -x id=value" of bash
+** \param s Full variable (id=value)
+*/
+
static void st_put_declare_x(char *s)
{
char *equal_ptr;
@@ -51,6 +56,13 @@ static void st_put_declare_x(char *s)
ft_putchar('\n');
}
+/*
+** \brief Export variables to the environment
+** \param argv arguments
+** \param env environment
+** \return a status code or EVAL_FATAL on fatal error
+*/
+
int builtin_export(char **argv, t_env env)
{
int status;
diff --git a/src/builtin/pwd.c b/src/builtin/pwd.c
index 46c69a9..0d8a7f1 100644
--- a/src/builtin/pwd.c
+++ b/src/builtin/pwd.c
@@ -6,7 +6,7 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/01 17:10:40 by charles #+# #+# */
-/* Updated: 2020/07/19 20:27:28 by charles ### ########.fr */
+/* Updated: 2020/09/13 20:23:15 by charles ### ########.fr */
/* */
/* ************************************************************************** */
@@ -17,6 +17,13 @@
#include "minishell.h"
+/*
+** \brief Print the current directory
+** \param argv arguments
+** \param env environment
+** \return a status code or EVAL_FATAL on fatal error
+*/
+
int builtin_pwd(char **argv, t_env env)
{
char buf[PATH_MAX];
diff --git a/src/builtin/unset.c b/src/builtin/unset.c
index 30facd3..9d0c66f 100644
--- a/src/builtin/unset.c
+++ b/src/builtin/unset.c
@@ -6,7 +6,7 @@
/* By: charles <charles@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/01 17:10:51 by charles #+# #+# */
-/* Updated: 2020/09/10 13:49:58 by charles ### ########.fr */
+/* Updated: 2020/09/13 20:22:35 by charles ### ########.fr */
/* */
/* ************************************************************************** */
@@ -17,6 +17,13 @@
#include "minishell.h"
+/*
+** \brief Remove variables from the environment
+** \param argv arguments
+** \param env environment
+** \return a status code or EVAL_FATAL on fatal error
+*/
+
int builtin_unset(char **argv, t_env env)
{
size_t i;