summaryrefslogtreecommitdiffstats
path: root/src/p_lblock_next.c
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-09-10 19:28:08 +0200
committerJozanLeClerc <bousset.rudy@gmail.com>2020-09-10 19:28:08 +0200
commit20b9a703186d7bf06936467ae3e8108cfbee43dd (patch)
tree0a183595d7f5f0ec1ae1d4364c4d7118f7f33231 /src/p_lblock_next.c
parentRemoved debug printf (diff)
download42-minishell-20b9a703186d7bf06936467ae3e8108cfbee43dd.tar.gz
42-minishell-20b9a703186d7bf06936467ae3e8108cfbee43dd.tar.bz2
42-minishell-20b9a703186d7bf06936467ae3e8108cfbee43dd.tar.xz
42-minishell-20b9a703186d7bf06936467ae3e8108cfbee43dd.tar.zst
42-minishell-20b9a703186d7bf06936467ae3e8108cfbee43dd.zip
I was born an idiot I swear
Diffstat (limited to '')
-rw-r--r--src/p_lblock_next.c23
1 files changed, 22 insertions, 1 deletions
diff --git a/src/p_lblock_next.c b/src/p_lblock_next.c
index 8b22f7c..21cd4a7 100644
--- a/src/p_lblock_next.c
+++ b/src/p_lblock_next.c
@@ -26,12 +26,31 @@
/* TODO: norme */
static char
+ *p_double_them_bs(char varval[])
+{
+ char *ptr;
+
+ ptr = varval;
+ while (*ptr != C_NUL)
+ {
+ if (*ptr == C_BACKS)
+ {
+ ptr = ft_memmove(ptr + 1, ptr, ft_strlen(ptr) + 1);
+ varval[ptr - varval] = C_BACKS;
+ }
+ ptr++;
+ }
+ return (varval);
+}
+
+static char
*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;
@@ -40,13 +59,15 @@ static char
ft_iswhitespace(ptr[varlen]) == FALSE)
varlen += 1;
ft_strlcpy(tmp, ptr + i, varlen + 1 - i);
- u_get_var_value(varval, tmp, 4096, msh);
+ u_get_var_value(varval, tmp, ARG_MAX, msh);
+ p_double_them_bs(varval);
ft_strlcpy(tmp, ptr + varlen, varlen);
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;
*(p) = word + (i + ft_strlen(varval) - 1);
return (word);
}