From cccd4692fab390d0c4fbab3fcae7f4aa55ca9f1a Mon Sep 17 00:00:00 2001 From: Charles Cabergs Date: Sat, 10 Oct 2020 11:43:05 +0200 Subject: Added comment to preprocess, redir, setup, signal, eval_cmd and utils --- src/setup.c | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) (limited to 'src/setup.c') diff --git a/src/setup.c b/src/setup.c index 2830e2d..7affe7f 100644 --- a/src/setup.c +++ b/src/setup.c @@ -6,12 +6,20 @@ /* By: charles +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/09/16 15:46:09 by charles #+# #+# */ -/* Updated: 2020/10/10 08:08:35 by cacharle ### ########.fr */ +/* Updated: 2020/10/10 11:19:44 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" +/* +** \brief Export variable if not already in environment +** \param env Environment where to export +** \param key Key to check for export +** \param value Default value +** \return True if allocation succeded, false otherwise +*/ + bool st_export_default(t_env env, char *key, char *value) { if (env_search(env, key, NULL) != NULL) @@ -19,6 +27,12 @@ bool st_export_default(t_env env, char *key, char *value) return (env_export(env, key, value) != NULL); } +/* +** \brief Setup the environment variables +** \param env Environment to setup +** \return true on success, false otherwise +*/ + bool setup_env(t_env env) { char buf[PATH_MAX + 1]; @@ -35,6 +49,12 @@ bool setup_env(t_env env) return (true); } +/* +** \brief Increment the SHLVL variable +** \param env Environment where to set SHLVL +** \return true on success, false otherwise +*/ + bool setup_shlvl(t_env env) { char shlvl_str[64]; @@ -47,6 +67,12 @@ bool setup_shlvl(t_env env) return (env_export(env, "SHLVL", shlvl_str) != NULL); } +/* +** \brief Initialize the progname global variable +** used in error messages +** \param first_arg argv[0] of minishell +*/ + void setup_progname(char *first_arg) { char *last_slash; @@ -60,6 +86,13 @@ void setup_progname(char *first_arg) g_state.progname = last_slash + 1; } +/* +** \brief Setup minishell (signals, env variables, progname) +** \param first_arg Used in setup_progname +** \param env Environment +** \return true on succes, false otherwise +*/ + bool setup(char *first_arg, t_env env) { signal(SIGINT, signal_sigint); -- cgit