diff options
Diffstat (limited to '')
-rw-r--r-- | src/p_lcom_next.c | 50 |
1 files changed, 43 insertions, 7 deletions
diff --git a/src/p_lcom_next.c b/src/p_lcom_next.c index 997878e..e461d55 100644 --- a/src/p_lcom_next.c +++ b/src/p_lcom_next.c @@ -157,8 +157,7 @@ static char if (!(rewords = (char**)malloc((j + 1) * sizeof(char*)))) { ft_delwords(words); - s_destroy(msh); - f_fail_alloc(msh); + f_alloc_and_destroy_msh(msh); } k = i; while (i - k < j) @@ -166,8 +165,7 @@ static char if (!(rewords[i - k] = ft_strdup(words[i]))) { ft_delwords(words); - s_destroy(msh); - f_fail_alloc(msh); + f_alloc_and_destroy_msh(msh); } i++; } @@ -177,6 +175,37 @@ static char return (rewords); } +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); + 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]); +} + char **p_check_args_equals(char *words[], t_msh *msh) @@ -187,18 +216,25 @@ char int64_t i; i = 0; - reg = TRUE; - isvar = TRUE; + reg = FALSE; + isvar = FALSE; while (words[i]) { ptr = words[i]; while (*ptr != '\0' && *ptr != '=') ptr++; - if (*ptr == '\0' || words[i][0] == '=' || ft_isdigit(words[i][0])) + if (*ptr == '=') + { + reg = TRUE; + isvar = TRUE; + } + if (*ptr == '\0' || words[i][0] == '=' || ft_isdigit(words[i][0]) == 1) { reg = FALSE; if (i == 0) isvar = FALSE; + if (isvar == TRUE) + p_add_to_env_fork(i, words, msh->curr, msh); break ; } i++; |