summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-07-31 19:25:39 +0200
committerJozanLeClerc <bousset.rudy@gmail.com>2020-07-31 19:25:39 +0200
commitcaa35c6770ea21112ccf38d8637d15f2bc717ea6 (patch)
tree3ceeb87b2ca8038f656c0de588d0dce229558074 /src
parentNot too bad (diff)
download42-minishell-caa35c6770ea21112ccf38d8637d15f2bc717ea6.tar.gz
42-minishell-caa35c6770ea21112ccf38d8637d15f2bc717ea6.tar.bz2
42-minishell-caa35c6770ea21112ccf38d8637d15f2bc717ea6.tar.xz
42-minishell-caa35c6770ea21112ccf38d8637d15f2bc717ea6.tar.zst
42-minishell-caa35c6770ea21112ccf38d8637d15f2bc717ea6.zip
Stuff to fix
Diffstat (limited to '')
-rw-r--r--src/p_lcom_next.c97
-rw-r--r--src/p_lcom_next.h7
-rw-r--r--src/s_lcom.c9
3 files changed, 90 insertions, 23 deletions
diff --git a/src/p_lcom_next.c b/src/p_lcom_next.c
index 4d0ca72..e3f1dfa 100644
--- a/src/p_lcom_next.c
+++ b/src/p_lcom_next.c
@@ -17,6 +17,7 @@
#include "d_enum.h"
#include "s_struct.h"
#include "u_vars.h"
+#include "u_vars_next.h"
static int8_t
subst_those_vars(int64_t i,
@@ -43,7 +44,7 @@ static int8_t
}
char
- **subst_vars(char *words[],
+ **p_subst_vars(char *words[],
t_msh *msh)
{
char **p_words;
@@ -66,9 +67,8 @@ char
return (words);
}
-
char
- **subst_args(const char word[],
+ **p_subst_args(const char word[],
int8_t redir)
{
char **words;
@@ -97,31 +97,96 @@ char
return (words);
}
-char
- **p_check_first_arg_equals(char *words[])
+static void
+ p_register_word(char word[],
+ t_msh *msh)
{
- t_bool equals;
+ char name[255];
+ char val[255];
char *ptr;
+ size_t i;
- equals = FALSE;
- ptr = words[0];
+ name[0] = '$';
+ ptr = word;
+ i = 1;
+ while (*ptr != '=' && *ptr != '\0')
+ {
+ name[i] = *ptr;
+ i++;
+ ptr++;
+ }
+ name[i] = '\0';
+ ptr++;
+ i = 0;
while (*ptr != '\0')
{
- if (*ptr == '=')
+ val[i] = *ptr;
+ i++;
+ ptr++;
+ }
+ u_subst_var_value(name, val, msh);
+}
+
+static char
+ **p_add_to_variables_and_delete( /* t_bool equals[], */
+ char *words[],
+ int64_t i,
+ t_msh *msh)
+{
+ char *ptr;
+ t_bool reg;
+ int64_t j;
+
+ reg = FALSE;
+ ptr = words[i - 1];
+ while (*ptr != '\0' && *ptr != '=')
+ {
+ ptr++;
+ }
+ if (*ptr != '\0')
+ {
+ reg = TRUE;
+ }
+ j = 0;
+ if (reg == TRUE)
+ {
+ while (words[j])
{
- equals = TRUE;
- break ;
+ p_register_word(words[j], msh);
+ j++;
}
- ptr++;
}
- if (equals == TRUE && words[1] != NULL)
+ j = 0;
+ while (j < i)
{
ft_memdel((void*)&words[0]);
words = words + 1;
- return (words);
+ j++;
}
- else
+ return (words);
+}
+
+char
+ **p_check_args_equals(char *words[],
+ t_msh *msh)
+{
+ /* t_bool equals[255]; */
+ char *ptr;
+ int64_t i;
+
+ /* i = -1; */
+ /* while (++i < 255) */
+ /* equals[i] = FALSE; */
+ i = -1;
+ while (words[++i])
{
- return (words);
+ ptr = words[i];
+ while (*ptr != '\0' && *ptr != '=')
+ ptr++;
+ /* if (*ptr != '\0') */
+ /* equals[i] = TRUE; */
+ if (*ptr == '\0')
+ break ;
}
+ return (p_add_to_variables_and_delete(/* equals, */words, i, msh));
}
diff --git a/src/p_lcom_next.h b/src/p_lcom_next.h
index ad5c5c5..cd1ef0d 100644
--- a/src/p_lcom_next.h
+++ b/src/p_lcom_next.h
@@ -17,10 +17,11 @@
#include "s_struct.h"
-char **subst_vars(char *words[],
+char **p_subst_vars(char *words[],
t_msh *msh);
-char **subst_args(const char word[],
+char **p_subst_args(const char word[],
int8_t redir);
-char **p_check_first_arg_equals(char *words[]);
+char **p_check_args_equals(char *words[],
+ t_msh *msh);
#endif
diff --git a/src/s_lcom.c b/src/s_lcom.c
index 773814f..088f625 100644
--- a/src/s_lcom.c
+++ b/src/s_lcom.c
@@ -127,17 +127,18 @@ t_lcom
link->pipes = NULL;
if (get_redir(word, &link) != 0)
return (NULL);
- if (!(words = subst_args(word, link->redir)))
+ if (!(words = p_subst_args(word, link->redir)))
return (NULL);
- if (!(words = subst_vars(words, msh)))
+ if (!(words = p_subst_vars(words, msh)))
return (NULL);
- words = p_check_first_arg_equals(words);
+ words = p_check_args_equals(words, msh);
if (fill_lcom(words, &link) < 0)
{
ft_delwords(words);
return (NULL);
}
link->next = NULL;
- ft_delwords(words);
+ if (words[0] != NULL)
+ ft_delwords(words);
return (link);
}