diff options
Diffstat (limited to '')
-rw-r--r-- | Makefile | 1 | ||||
-rw-r--r-- | src/e_externs.c | 19 | ||||
-rw-r--r-- | src/p_lcom_next.c | 23 | ||||
-rw-r--r-- | src/s_lcom.c | 5 | ||||
-rw-r--r-- | src/s_lcom_next.c | 38 | ||||
-rw-r--r-- | src/s_lcom_next.h | 20 | ||||
-rw-r--r-- | src/s_struct.h | 1 |
7 files changed, 86 insertions, 21 deletions
@@ -48,6 +48,7 @@ SRCS_NAME += m_redirs SRCS_NAME += s_destroy SRCS_NAME += s_init SRCS_NAME += s_lcom +SRCS_NAME += s_lcom_next SRCS_NAME += s_lvars SRCS_NAME += s_lpipes SRCS_NAME += p_line diff --git a/src/e_externs.c b/src/e_externs.c index 7593c3d..0e3c2bb 100644 --- a/src/e_externs.c +++ b/src/e_externs.c @@ -16,6 +16,7 @@ #include <stdint.h> #include <unistd.h> +#include "b_export_next.h" #include "e_externs_next.h" #include "f_fail.h" #include "m_redirs.h" @@ -34,6 +35,20 @@ static void } static void + e_export_env_fork(t_lcom *ptr, + t_msh *msh) +{ + char **re_ptr; + + re_ptr = ptr->env_fork; + while (*re_ptr != NULL) + { + b_export_with_equals(*re_ptr, msh); + re_ptr++; + } +} + +static void exec_path(const char fullpath[], t_lcom *ptr, t_msh *msh) @@ -43,8 +58,8 @@ static void if ((pid = fork()) == 0) { - /* if (ptr->env_fork != NULL) */ - /* e_export_env_fork(ptr->env_fork, msh); */ + if (ptr->env_fork != NULL) + e_export_env_fork(ptr, msh); e_extern_child(fullpath, ptr, msh); } else if (pid < 0) diff --git a/src/p_lcom_next.c b/src/p_lcom_next.c index e461d55..9a39dd0 100644 --- a/src/p_lcom_next.c +++ b/src/p_lcom_next.c @@ -178,32 +178,17 @@ static char static void p_add_to_env_fork(int64_t i, char *words[], - t_lcom *ptr, t_msh *msh) { int64_t j; - (void)msh; - (void)words; j = 0; - if ((ptr->env_fork = (char**)malloc((i + 1) * sizeof(char*))) == NULL) - { - ft_delwords(words); - f_alloc_and_destroy_msh(msh); - } while(j < i) { - if ((ptr->env_fork[j] = ft_strdup(words[j])) == NULL) - f_alloc_and_destroy_msh(msh); + ft_strlcpy(msh->env_fork_tmp[j], words[j], ft_strlen(words[j]) + 1); j++; } - ptr->env_fork[j] = NULL; - /* TODO: delete this */ - i = 0; - while (ptr->env_fork[i] != NULL) { - ft_printf("[%s]\n", ptr->env_fork[i]); - } - ft_printf("[%s]\n", ptr->env_fork[i]); + msh->env_fork_tmp[j][0] = '\0'; } char @@ -234,7 +219,9 @@ char if (i == 0) isvar = FALSE; if (isvar == TRUE) - p_add_to_env_fork(i, words, msh->curr, msh); + p_add_to_env_fork(i, words, msh); + else + msh->env_fork_tmp[0][0] = '\0'; break ; } i++; diff --git a/src/s_lcom.c b/src/s_lcom.c index 7ef64b3..536a8ff 100644 --- a/src/s_lcom.c +++ b/src/s_lcom.c @@ -17,6 +17,7 @@ #include "p_lcom.h" #include "p_lcom_next.h" #include "s_struct.h" +#include "s_lcom_next.h" static int8_t fill_lcom(char *words[], @@ -107,7 +108,7 @@ void t_lcom *lcom_new(const char word[], - t_msh *msh) + t_msh *msh) { /* TODO: norme */ t_lcom *link; @@ -135,6 +136,8 @@ t_lcom if (!(words = p_subst_vars(words, msh))) return (NULL); words = p_check_args_equals(words, msh); + if (msh->env_fork_tmp[0][0] != '\0') + lcom_cpy_env_fork(&link, msh); if (fill_lcom(words, &link) < 0) { ft_delwords(words); diff --git a/src/s_lcom_next.c b/src/s_lcom_next.c new file mode 100644 index 0000000..b7e4482 --- /dev/null +++ b/src/s_lcom_next.c @@ -0,0 +1,38 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* s_lcom_next.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/14 17:19:27 by rbousset #+# #+# */ +/* Updated: 2020/02/14 17:19:29 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#include <libft.h> +#include <stdlib.h> + +#include "f_fail.h" + +void + lcom_cpy_env_fork(t_lcom **link, + t_msh *msh) +{ + size_t i; + size_t j; + + i = 0; + while (msh->env_fork_tmp[i][0] != '\0') + i++; + if (((*link)->env_fork = (char**)malloc((i + 1) * sizeof(char*))) == NULL) + f_alloc_and_destroy_msh(msh); + j = 0; + while (j < i) + { + if (((*link)->env_fork[j] = ft_strdup(msh->env_fork_tmp[j])) == NULL) + f_alloc_and_destroy_msh(msh); + j++; + } + (*link)->env_fork[j] = NULL; +} diff --git a/src/s_lcom_next.h b/src/s_lcom_next.h new file mode 100644 index 0000000..96ae01c --- /dev/null +++ b/src/s_lcom_next.h @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* s_lcom_next.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/14 17:19:27 by rbousset #+# #+# */ +/* Updated: 2020/02/14 17:19:29 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef S_LCOM_NEXT_H +#define S_LCOM_NEXT_H + +#include "s_struct.h" + +void lcom_cpy_env_fork(t_lcom **link, t_msh *msh); + +#endif diff --git a/src/s_struct.h b/src/s_struct.h index c2caf92..a730b78 100644 --- a/src/s_struct.h +++ b/src/s_struct.h @@ -61,6 +61,7 @@ typedef struct s_msh char *shname; char **bu_ref; char *cwd; + char env_fork_tmp[128][1024]; uint8_t (*bu_ptr[FT_BUILTINS_COUNT])(char **, struct s_msh*); struct s_lcom *curr; struct s_lvars *vars; |