[ADD] include environment variables in shell vars
This commit is contained in:
parent
0898d3b79a
commit
8cfd839045
2 changed files with 24 additions and 3 deletions
2
dev/TODO
2
dev/TODO
|
@ -3,8 +3,8 @@
|
||||||
- signals
|
- signals
|
||||||
- ^C, ^D, ^\
|
- ^C, ^D, ^\
|
||||||
- variables
|
- variables
|
||||||
- environment variables
|
|
||||||
- $?
|
- $?
|
||||||
|
- uses $PATH in env.variables instead of envp
|
||||||
- builtins:
|
- builtins:
|
||||||
- echo (with option -n)
|
- echo (with option -n)
|
||||||
- cd [path]
|
- cd [path]
|
||||||
|
|
25
src/main.c
25
src/main.c
|
@ -6,12 +6,33 @@
|
||||||
/* By: jschaft <cecile.schaft@orange.fr> +#+ +:+ +#+ */
|
/* By: jschaft <cecile.schaft@orange.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/04/23 14:33:45 by mcolonna #+# #+# */
|
/* 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"
|
#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.
|
// Execute a command from a string.
|
||||||
static int do_command(t_env *env, const char *str)
|
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.mc_command = NULL;
|
||||||
env.errorstatus = 0;
|
env.errorstatus = 0;
|
||||||
env.envp = envp;
|
env.envp = envp;
|
||||||
variables = list_createempty(env.mc_global);
|
variables = variables_from_envp(env, envp);
|
||||||
env.variables = &variables;
|
env.variables = &variables;
|
||||||
handle_signals();
|
handle_signals();
|
||||||
start(&env);
|
start(&env);
|
||||||
|
|
Loading…
Add table
Reference in a new issue