summaryrefslogtreecommitdiffstats
path: root/src/p_lblock_next.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/p_lblock_next.c')
-rw-r--r--src/p_lblock_next.c33
1 files changed, 15 insertions, 18 deletions
diff --git a/src/p_lblock_next.c b/src/p_lblock_next.c
index 8d89cf3..a5314f2 100644
--- a/src/p_lblock_next.c
+++ b/src/p_lblock_next.c
@@ -19,6 +19,7 @@
#include "s_destroy.h"
#include "f_fail.h"
#include "s_struct.h"
+#include "u_parse.h"
#include "u_utils.h"
#include "u_vars.h"
#include "u_vars_next.h"
@@ -43,14 +44,13 @@ static char
return (varval);
}
-static char
- *p_subst_this_var(char **p, int64_t i, char word[], t_msh *msh)
+static void
+ p_subst_this_var(char **p, int64_t i, char word[], t_msh *msh)
{
char tmp[ARG_MAX];
char varval[ARG_MAX];
char *ptr;
size_t varlen;
- int32_t count;
ptr = word;
varlen = i + 1;
@@ -61,32 +61,29 @@ static char
ft_strlcpy(tmp, ptr + i, varlen + 1 - i);
u_get_var_value(varval, tmp, ARG_MAX, msh);
p_double_them_bs(varval);
- ft_strlcpy(tmp, ptr + varlen, ft_strlen(ptr + varlen) + 1);
- if ((word = ft_nrealloc(word, i, i + ft_strlen(varval) +
- ft_strlen(tmp) + 1)) == NULL)
- return (NULL);
- ft_strlcpy(word + i, varval, ft_strlen(varval) + 1);
- ft_strlcpy(word + (i + ft_strlen(varval)), tmp, ft_strlen(tmp) + 1);
- count = 0;
+ (void)ft_memmove(ptr + (i + ft_strlen(tmp)), ptr + varlen, (ft_strlen(ptr + varlen) + 1) * sizeof(char));
+ (void)ft_memmove(word + i, varval, ft_strlen(varval) * sizeof(char));
*(p) = word + (i + ft_strlen(varval) - 1);
- return (word);
}
char
*p_subst_vars(char word[], t_msh *msh)
{
- char *ptr;
+ char *ptr;
+ t_quote_mode mode;
+ mode = Q_NONE;
ptr = word;
while (*ptr != C_NUL)
{
- if (*ptr == '$' && u_is_not_escaped(word, ptr) == TRUE)
+ if (*ptr == C_DQUOTE)
+ mode = u_meet_dquote(word, ptr, mode);
+ else if (*ptr == C_SQUOTE)
+ mode = u_meet_squote(word, ptr, mode);
+ if ((mode == Q_NONE || mode == Q_DOUBLE) && *ptr == C_DOLLAR &&
+ u_is_not_escaped(word, ptr) == TRUE)
{
- if ((word = p_subst_this_var(&ptr, (ptr - word), word, msh))
- == NULL)
- {
- return (NULL);
- }
+ p_subst_this_var(&ptr, (ptr - word), word, msh);
}
ptr++;
}