[ADD] include environment variables in shell vars

This commit is contained in:
mcolonna 2024-06-20 18:18:50 +02:00
parent 0898d3b79a
commit 8cfd839045
2 changed files with 24 additions and 3 deletions

View file

@ -3,8 +3,8 @@
- signals
- ^C, ^D, ^\
- variables
- environment variables
- $?
- uses $PATH in env.variables instead of envp
- builtins:
- echo (with option -n)
- cd [path]

View file

@ -6,12 +6,33 @@
/* By: jschaft <cecile.schaft@orange.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/23 14:33:45 by mcolonna #+# #+# */
/* Updated: 2024/06/18 15:40:48 by mcolonna ### ########.fr */
/* Updated: 2024/06/20 18:17:03 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
#include "include.h"
static t_list variables_from_envp(t_env env, char *const envp[])
{
t_list r;
char **splitted;
t_variable *var;
int i;
r = list_createempty(env.mc_global);
i = 0;
while (envp[i])
{
splitted = str_split(fatal_error, env.mc_global, envp[i], "=");
var = mem_alloc(fatal_error, env.mc_global, sizeof(t_variable));
var->name = splitted[0];
var->value = splitted[1];
list_add(fatal_error, &r, var);
i++;
}
return (r);
}
// Execute a command from a string.
static int do_command(t_env *env, const char *str)
{
@ -65,7 +86,7 @@ int main(const int argc, const char *argv[], char *const envp[])
env.mc_command = NULL;
env.errorstatus = 0;
env.envp = envp;
variables = list_createempty(env.mc_global);
variables = variables_from_envp(env, envp);
env.variables = &variables;
handle_signals();
start(&env);