summaryrefslogtreecommitdiffstats
path: root/src/ft_p_lcom_next.c
diff options
context:
space:
mode:
authorsalad <fmoenne-@student.le-101.fr>2020-04-27 18:11:59 +0200
committersalad <fmoenne-@student.le-101.fr>2020-04-27 18:11:59 +0200
commitf3c766105a7dc8a3f1791374c41542ea833c53ce (patch)
treeba1ecd86edf60952a85528c2e4184c7ac9ed226e /src/ft_p_lcom_next.c
parentfecho full buffered, quotes bav (diff)
parentFinished and normed type (diff)
download42-minishell-f3c766105a7dc8a3f1791374c41542ea833c53ce.tar.gz
42-minishell-f3c766105a7dc8a3f1791374c41542ea833c53ce.tar.bz2
42-minishell-f3c766105a7dc8a3f1791374c41542ea833c53ce.tar.xz
42-minishell-f3c766105a7dc8a3f1791374c41542ea833c53ce.tar.zst
42-minishell-f3c766105a7dc8a3f1791374c41542ea833c53ce.zip
merge master into fmoenne
Diffstat (limited to '')
-rw-r--r--src/ft_p_lcom_next.c49
1 files changed, 27 insertions, 22 deletions
diff --git a/src/ft_p_lcom_next.c b/src/ft_p_lcom_next.c
index 272931d..07fadbe 100644
--- a/src/ft_p_lcom_next.c
+++ b/src/ft_p_lcom_next.c
@@ -17,46 +17,54 @@
#include "ft_s_struct.h"
#include "ft_u_vars.h"
+static int8_t
+ ft_subst_those_vars(int64_t i,
+ char **p_words,
+ t_msh *msh)
+{
+ size_t varlen;
+ char *s_varname;
+ char *varval;
+
+ varval = NULL;
+ s_varname = NULL;
+ varlen = i + 1;
+ while ((*p_words)[varlen] != '\0' && (*p_words)[varlen] != '$')
+ varlen += 1;
+ if (!(s_varname = ft_substr(*p_words, (uint32_t)i, varlen - i)))
+ return (-1);
+ varval = ft_subst_var_value(s_varname, msh);
+ *p_words = ft_strsubst(*p_words, s_varname, varval);
+ ft_memdel((void*)&s_varname);
+ ft_memdel((void*)&varval);
+ return (0);
+}
+
char
**ft_subst_vars(char *words[],
t_msh *msh)
{
- /* TODO: norme */
char **p_words;
- char *s_varname;
- char *varval;
int64_t i;
- size_t varlen;
p_words = words;
- varlen = 0;
- varval = NULL;
- s_varname = NULL;
while (*p_words)
{
while ((i = ft_strlchr(*p_words, '$')) != -1)
{
- varlen = i + 1;
- while ((*p_words)[varlen] != '\0' && (*p_words)[varlen] != '$')
- varlen += 1;
- if (!(s_varname = ft_substr(*p_words, (uint32_t)i, varlen)))
+ if (ft_subst_those_vars(i, p_words, msh) != 0)
return (NULL);
- ft_printf("a\n");
- varval = ft_subst_var_value(s_varname, msh);
- *p_words = ft_strsubst(*p_words, s_varname, varval);
- ft_memdel((void*)&s_varname);
- ft_memdel((void*)&varval);
}
p_words += 1;
}
return (words);
}
+
char
**ft_subst_args(const char word[],
int8_t redir)
{
- /* TODO: norme */
char **words;
char *subst;
size_t i;
@@ -70,11 +78,8 @@ char
i = 0;
while (word[i] && !ft_ischarset("<>", word[i]))
i++;
- if (redir > 0)
- {
- while (ft_isdigit(word[i]))
- i--;
- }
+ while (redir > 0 && ft_isdigit(word[i]))
+ i--;
if (!(subst = ft_substr(word, 0, i)))
return (NULL);
if (!(words = ft_split(subst, ' ')))