summaryrefslogtreecommitdiffstats
path: root/src/p_lcom_next.c
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-08-10 17:56:38 +0200
committerJozanLeClerc <bousset.rudy@gmail.com>2020-08-10 17:56:38 +0200
commit4b233e06a16bf5183223e8253b4d9ac9ee59e6a2 (patch)
treedc36a64dcad37e076f478aadc7cccb0f322ea192 /src/p_lcom_next.c
parentpwd TODO done (diff)
download42-minishell-4b233e06a16bf5183223e8253b4d9ac9ee59e6a2.tar.gz
42-minishell-4b233e06a16bf5183223e8253b4d9ac9ee59e6a2.tar.bz2
42-minishell-4b233e06a16bf5183223e8253b4d9ac9ee59e6a2.tar.xz
42-minishell-4b233e06a16bf5183223e8253b4d9ac9ee59e6a2.tar.zst
42-minishell-4b233e06a16bf5183223e8253b4d9ac9ee59e6a2.zip
Work in progress
Diffstat (limited to '')
-rw-r--r--src/p_lcom_next.c50
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++;