aboutsummaryrefslogtreecommitdiff
path: root/src/setup.c
diff options
context:
space:
mode:
authorCharles Cabergs <me@cacharle.xyz>2020-10-10 11:43:05 +0200
committerCharles Cabergs <me@cacharle.xyz>2020-10-10 11:43:05 +0200
commitcccd4692fab390d0c4fbab3fcae7f4aa55ca9f1a (patch)
tree935f8aa5b19c780bdd7dbd7581dd067bad7b1eeb /src/setup.c
parent5b681182824ae45b5a27d1503de32fa2760c5800 (diff)
downloadminishell-cccd4692fab390d0c4fbab3fcae7f4aa55ca9f1a.tar.gz
minishell-cccd4692fab390d0c4fbab3fcae7f4aa55ca9f1a.tar.bz2
minishell-cccd4692fab390d0c4fbab3fcae7f4aa55ca9f1a.zip
Added comment to preprocess, redir, setup, signal, eval_cmd and utils
Diffstat (limited to 'src/setup.c')
-rw-r--r--src/setup.c35
1 files changed, 34 insertions, 1 deletions
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 <me@cacharle.xyz> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);