aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ast.c18
-rw-r--r--src/builtin/builtin.c29
-rw-r--r--src/builtin/cd.c14
-rw-r--r--src/builtin/echo.c14
-rw-r--r--src/builtin/env.c14
-rw-r--r--src/builtin/exit.c16
-rw-r--r--src/builtin/export.c16
-rw-r--r--src/builtin/pwd.c14
-rw-r--r--src/builtin/unset.c14
-rw-r--r--src/env.c13
-rw-r--r--src/eval/eval.c32
-rw-r--r--src/eval/exec.c20
-rw-r--r--src/eval/pipe.c18
-rw-r--r--src/main.c4
-rw-r--r--src/parse/lexer.c2
-rw-r--r--src/parse/parse.c2
-rw-r--r--src/path.c16
-rw-r--r--src/utils.c12
18 files changed, 206 insertions, 62 deletions
diff --git a/src/ast.c b/src/ast.c
index 12761ac..2393a95 100644
--- a/src/ast.c
+++ b/src/ast.c
@@ -1,11 +1,23 @@
-/**
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ast.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/01 17:05:42 by charles #+# #+# */
+/* Updated: 2020/04/01 17:05:44 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+/*
** \file ast.c
** \brief AST functions
*/
#include "ast.h"
-/**
+/*
** \brief Create a new AST node according to `tag`
** \param tag Tag of node
** \param data Pointer to node data (t_cmd or t_line)
@@ -30,7 +42,7 @@ t_ast *ast_new(t_ast_tag tag, void *data)
return (ast);
}
-/**
+/*
** \brief Destroy an AST node and all his child nodes
** \param ast AST to destroy
*/
diff --git a/src/builtin/builtin.c b/src/builtin/builtin.c
index 4889f9c..65e8cf4 100644
--- a/src/builtin/builtin.c
+++ b/src/builtin/builtin.c
@@ -1,15 +1,27 @@
-/**
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* builtin.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/01 17:11:01 by charles #+# #+# */
+/* Updated: 2020/04/01 17:46:48 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+/*
** \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[] = {
+static struct s_builtin_entry g_builtin_lookup[] = {
{"echo", builtin_echo},
{"cd", builtin_cd},
{"pwd", builtin_pwd},
@@ -19,14 +31,15 @@ static struct s_builtin_entry g_builtin_lookup[] = {
{"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 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)
+int builtin_dispatch_run(char **argv, t_env env)
{
size_t i;
@@ -40,13 +53,13 @@ int builtin_dispatch_run(char **argv, t_env env)
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)
+bool builtin_check_exec_name(char *exec_name)
{
size_t i;
diff --git a/src/builtin/cd.c b/src/builtin/cd.c
index db629b0..dc88dae 100644
--- a/src/builtin/cd.c
+++ b/src/builtin/cd.c
@@ -1,4 +1,16 @@
-/**
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* cd.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/01 17:10:20 by charles #+# #+# */
+/* Updated: 2020/04/01 17:10:21 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+/*
** \file cd.c
** \brief `cd` builtin
*/
diff --git a/src/builtin/echo.c b/src/builtin/echo.c
index c9e8cc7..9b7a8f6 100644
--- a/src/builtin/echo.c
+++ b/src/builtin/echo.c
@@ -1,4 +1,16 @@
-/**
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* echo.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/01 17:10:47 by charles #+# #+# */
+/* Updated: 2020/04/01 17:10:48 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+/*
** \file echo.c
** \brief `echo` builtin
*/
diff --git a/src/builtin/env.c b/src/builtin/env.c
index 352e2c3..d3f4024 100644
--- a/src/builtin/env.c
+++ b/src/builtin/env.c
@@ -1,4 +1,16 @@
-/**
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* env.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/01 17:10:32 by charles #+# #+# */
+/* Updated: 2020/04/01 17:10:33 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+/*
** \file env.c
** \brief `env` builtin
*/
diff --git a/src/builtin/exit.c b/src/builtin/exit.c
index bd41f0f..1e6ec45 100644
--- a/src/builtin/exit.c
+++ b/src/builtin/exit.c
@@ -1,11 +1,23 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* exit.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/01 17:10:16 by charles #+# #+# */
+/* Updated: 2020/04/01 17:10:17 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
#include "minishell.h"
-/**
+/*
** \file exit.c
** \brief `exit` builtin
*/
-int builtin_exit(char **argv, t_env env)
+int builtin_exit(char **argv, t_env env)
{
(void)argv;
(void)env;
diff --git a/src/builtin/export.c b/src/builtin/export.c
index 1b148a9..8a62412 100644
--- a/src/builtin/export.c
+++ b/src/builtin/export.c
@@ -1,4 +1,16 @@
-/**
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* export.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/01 17:11:34 by charles #+# #+# */
+/* Updated: 2020/04/01 17:11:38 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+/*
** \file export.c
** \brief `export` builtin
*/
@@ -9,7 +21,5 @@ 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 6e0971f..ab0b1d8 100644
--- a/src/builtin/pwd.c
+++ b/src/builtin/pwd.c
@@ -1,4 +1,16 @@
-/**
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* pwd.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/01 17:10:40 by charles #+# #+# */
+/* Updated: 2020/04/01 17:10:40 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+/*
** \file pwd.c
** \brief `pwd` builtin
*/
diff --git a/src/builtin/unset.c b/src/builtin/unset.c
index 1fc5ce1..2ae6c27 100644
--- a/src/builtin/unset.c
+++ b/src/builtin/unset.c
@@ -1,4 +1,16 @@
-/**
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* unset.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/01 17:10:51 by charles #+# #+# */
+/* Updated: 2020/04/01 17:10:51 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+/*
** \file unset.c
** \brief `unset` builtin
*/
diff --git a/src/env.c b/src/env.c
index 00fbaaf..fc26876 100644
--- a/src/env.c
+++ b/src/env.c
@@ -1,29 +1,29 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
-/* environment.c :+: :+: :+: */
+/* env.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/28 09:21:24 by cacharle #+# #+# */
-/* Updated: 2020/02/28 12:30:55 by cacharle ### ########.fr */
+/* Updated: 2020/04/01 17:03:50 by charles ### ########.fr */
/* */
/* ************************************************************************** */
-/**
+/*
** \file env.c
** \brief Environment hash table manipulation
*/
#include "minishell.h"
-/**
+/*
** \brief Number of buckets of an environment hash table
*/
#define MS_ENV_HT_SIZE 2048
-/**
+/*
** \brief Convert array of string to environment hash table
** \param envp array of string (each in the format `name=value`)
** \return Environment hash table or NULL on error
@@ -57,7 +57,7 @@ t_env env_from_array(char **envp)
return (env);
}
-/**
+/*
** \brief Convert environment to array of string
** \param env Environment hash table
** \return Array of string on NULL on error
@@ -66,6 +66,5 @@ t_env env_from_array(char **envp)
char **env_to_array(t_env env)
{
(void)env;
- // need ft_htlen
return (NULL);
}
diff --git a/src/eval/eval.c b/src/eval/eval.c
index d2fab39..c90618c 100644
--- a/src/eval/eval.c
+++ b/src/eval/eval.c
@@ -1,18 +1,30 @@
-/**
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* eval.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/01 17:05:21 by charles #+# #+# */
+/* Updated: 2020/04/01 17:09:36 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+/*
** \file eval.c
** \brief Evaluation of an AST
*/
#include "eval.h"
-/**
+/*
** \brief Evaluate a line
** \param state State of the evaluation
** \param line Line to evaluate
** \return Last Executed command status or -1 on error
*/
-static int eval_line(t_eval_state *state, t_line *line)
+static int eval_line(t_eval_state *state, t_line *line)
{
int status;
@@ -26,14 +38,14 @@ static int eval_line(t_eval_state *state, t_line *line)
return (eval(state, line->right));
}
-/**
+/*
** \brief Evaluate a command
** \param state Evaluation state
** \param cmd Command to evaluate
** \return Executable status or -1 on error
*/
-static int eval_cmd(t_eval_state *state, t_cmd *cmd)
+static int eval_cmd(t_eval_state *state, t_cmd *cmd)
{
int child_pid;
char *exec_path;
@@ -54,7 +66,7 @@ static int eval_cmd(t_eval_state *state, t_cmd *cmd)
pipe_setup_child(state->pipe_in, state->pipe_out);
if (is_builtin)
exit(builtin_dispatch_run(cmd->argv, state->env));
- else if (execve(exec_path, cmd->argv, NULL /*env_array*/) == -1)
+ else if (execve(exec_path, cmd->argv, NULL) == -1)
exit(EXIT_FAILURE);
exit(EXIT_SUCCESS);
}
@@ -62,19 +74,19 @@ static int eval_cmd(t_eval_state *state, t_cmd *cmd)
return (WEXITSTATUS(child_pid));
}
-/**
+/*
** \brief Evaluate an AST
** \param state State of the evaluation
** \param ast Abstract syntax tree to evaluate
** \return Executable status or -1 on error
*/
-int eval(t_eval_state *state, t_ast *ast)
+int eval(t_eval_state *state, t_ast *ast)
{
errno = 0;
if (ast->tag == TAG_LINE)
- return eval_line(state, &ast->data.line);
+ return (eval_line(state, &ast->data.line));
if (ast->tag == TAG_CMD)
- return eval_cmd(state, &ast->data.cmd);
+ return (eval_cmd(state, &ast->data.cmd));
return (-1);
}
diff --git a/src/eval/exec.c b/src/eval/exec.c
index 1ac9754..e41f994 100644
--- a/src/eval/exec.c
+++ b/src/eval/exec.c
@@ -1,11 +1,23 @@
-/**
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* exec.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/01 17:06:11 by charles #+# #+# */
+/* Updated: 2020/04/01 17:06:12 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+/*
** \file exec.c
** \brief Executable name and path
*/
#include "eval.h"
-/**
+/*
** \brief Check if executable name is already a path
** \param exec_name Executable name
** \return True if valid
@@ -18,7 +30,7 @@ bool exec_is_path(char *exec_name)
|| ft_strncmp(exec_name, "/", 1) == 0);
}
-/**
+/*
** \brief Check if executable path is valid
** \param exec_path Executable path
** \return True if valid
@@ -36,7 +48,7 @@ bool exec_is_valid(char *exec_path)
return (true);
}
-/**
+/*
** \brief Search executable name in path
** \param path Path hash table
** \param path_var Path environment string in case we need to update path
diff --git a/src/eval/pipe.c b/src/eval/pipe.c
index 897a5f2..125c013 100644
--- a/src/eval/pipe.c
+++ b/src/eval/pipe.c
@@ -1,11 +1,23 @@
-/**
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* pipe.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/01 17:05:58 by charles #+# #+# */
+/* Updated: 2020/04/01 17:05:59 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+/*
** \file pipe.c
** \brief Pipes setup
*/
#include "eval.h"
-/**
+/*
** \brief Setup STDIN and STDOUT pipe in the parent process
** \param cmd Command to setup
** \param pipe_in STDIN pipe
@@ -29,7 +41,7 @@ int pipe_setup_parent(t_cmd *cmd, int pipe_in[2], int pipe_out[2])
return (0);
}
-/**
+/*
** \brief Setup STDIN and STDOUT pipe in the child process
** \param pipe_in STDIN pipe
** \param pipe_out STDOUT pipe
diff --git a/src/main.c b/src/main.c
index 1e42b87..233333d 100644
--- a/src/main.c
+++ b/src/main.c
@@ -10,7 +10,7 @@
/* */
/* ************************************************************************** */
-/**
+/*
** \file main.c
** \brief Minishell entrypoint
*/
@@ -19,7 +19,7 @@
#include "ast.h"
#include "eval.h"
-/**
+/*
** \brief Program entrypoint
** \param argc Number of arguments in `argv`
** \param argv Array of string, argument of the program
diff --git a/src/parse/lexer.c b/src/parse/lexer.c
index 57ecdf7..74a3bd4 100644
--- a/src/parse/lexer.c
+++ b/src/parse/lexer.c
@@ -1,4 +1,4 @@
-/**
+/*
** \file lexer.c
** \brief Lexer
*/
diff --git a/src/parse/parse.c b/src/parse/parse.c
index c99f0fe..ed1aa28 100644
--- a/src/parse/parse.c
+++ b/src/parse/parse.c
@@ -1,4 +1,4 @@
-/**
+/*
** \file parse.c
** \brief Parser
*/
diff --git a/src/path.c b/src/path.c
index 1136a7c..f1424cc 100644
--- a/src/path.c
+++ b/src/path.c
@@ -6,25 +6,26 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/27 15:51:01 by cacharle #+# #+# */
-/* Updated: 2020/02/28 12:33:31 by cacharle ### ########.fr */
+/* Updated: 2020/04/01 17:55:28 by charles ### ########.fr */
/* */
/* ************************************************************************** */
-/**
+/*
** \file path.c
** \brief Path hash table manipulation
*/
#include "minishell.h"
-/**
+/*
** \brief Number of buckets of a path hash table
*/
#define MS_PATH_HT_SIZE 8192
-/**
-** \brief Update `path` with all files in the directory named `dirname`.
+/*
+** \brief Update `path` with all files
+** in the directory named `dirname`.
** \param path Path hash table
** \param dirname directory name
** \return Same path or NULL on error
@@ -50,10 +51,11 @@ static t_path st_path_dir_update(t_path path, char *dirname)
return (path);
}
-/**
+/*
** \brief Update the path
** \param path Path hash table or NULL to create a new one
-** \param path_var PATH environment variable where each directory is separated by a ':'
+** \param path_var PATH environment variable where
+** each directory is separated by a ':'
** \return The updated/created path hash table or NULL on error
*/
diff --git a/src/utils.c b/src/utils.c
index 5989d71..1649199 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -1,26 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
-/* util.c :+: :+: :+: */
+/* utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/28 11:56:31 by cacharle #+# #+# */
-/* Updated: 2020/02/28 11:57:30 by cacharle ### ########.fr */
+/* Updated: 2020/04/01 17:55:34 by charles ### ########.fr */
/* */
/* ************************************************************************** */
-/**
+/*
** \file utils.c
** \brief Various functions
*/
#include "minishell.h"
-/**
-** \brief Delete function for a entry containing a allocated key and value
+/*
+** \brief Delete function for a entry containing
+** an allocated key and value
** \param entry Hash table entry
-**
*/
void ht_del_str_entry(t_ftht_entry *entry)