From f70f8bd3b56121bfa971522f9da6af4003ac2a99 Mon Sep 17 00:00:00 2001 From: AntoHesse Date: Mon, 6 Mar 2017 23:51:26 +0100 Subject: [PATCH] exec var --- 42sh/libft | 2 +- 42sh/src/exec/exec_var.c | 17 ++++++++++++++--- 42sh/src/exec/ft_exec.c | 1 + 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/42sh/libft b/42sh/libft index 318efc7c..dc155bf5 160000 --- a/42sh/libft +++ b/42sh/libft @@ -1 +1 @@ -Subproject commit 318efc7cfb7b7cc9d3714fa19fd2be7382b6adec +Subproject commit dc155bf51cc9de83df073669a1d2a9a915f16121 diff --git a/42sh/src/exec/exec_var.c b/42sh/src/exec/exec_var.c index 3952d5e6..3bfc50ce 100644 --- a/42sh/src/exec/exec_var.c +++ b/42sh/src/exec/exec_var.c @@ -12,13 +12,24 @@ #include "exec.h" +static int set_var(char *stream, char **var, char **value) +{ + *var = ft_strdupchr(stream, '='); + stream += ft_strlenchr(stream, '=') + 1; + *value = ft_strdup(stream); + return (0); +} + int exec_var(t_btree **ast) { t_astnode *node; char **av; - + char *var; + char *value; + node = (*ast)->item; - av = token_to_argv(node->data.cmd.token, 0); - builtin_setenv("setenv", av, data_singleton()->local_var); + av = token_to_argv(node->data.cmd.token, 1); + set_var(av[0], &var, &value); + builtin_setenv("setenv", (char*[]){var, value, 0}, data_singleton()->local_var); return (0); } diff --git a/42sh/src/exec/ft_exec.c b/42sh/src/exec/ft_exec.c index 6b78f9cb..b24b7612 100644 --- a/42sh/src/exec/ft_exec.c +++ b/42sh/src/exec/ft_exec.c @@ -28,6 +28,7 @@ t_execmap g_execmap[] = {TK_FOR, &exec_for}, {TK_CASE, &exec_case}, {TK_PAREN_OPEN, &exec_case_branch}, + {TK_ASSIGNEMENT_WORD, &exec_var}, /* {TK_SUBSHELL, &exec_}, */ {CMD, &exec_cmd}, {0, 0},