From 20b9a703186d7bf06936467ae3e8108cfbee43dd Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Thu, 10 Sep 2020 19:28:08 +0200 Subject: I was born an idiot I swear --- TODO.org | 2 +- src/d_define.h | 1 + src/m_prompt.c | 12 +++++++++--- src/p_lblock_next.c | 23 ++++++++++++++++++++++- 4 files changed, 33 insertions(+), 5 deletions(-) diff --git a/TODO.org b/TODO.org index 945cae0..b38f114 100644 --- a/TODO.org +++ b/TODO.org @@ -8,7 +8,7 @@ ** DONE [#A] Multiline pipes (ls |) ** DONE [#A] Go full tok + quotes ** DONE [#A] fix \; \&& \|| -** TODO [#A] Variables quotes qwe="okokoko kkok" asd='bav' +** DONE [#A] Variables quotes qwe="okokoko kkok" asd='bav' ** TODO [#A] Fix PSX \stuff subst with "" '' ** DONE [#A] ls qweqwe; echo $? <---- substitute ** TODO [#A] <>> diff --git a/src/d_define.h b/src/d_define.h index 8e73668..50b0f3c 100644 --- a/src/d_define.h +++ b/src/d_define.h @@ -68,6 +68,7 @@ #define C_NUL 0x00 #define C_SUB 0x1a +#define C_ESC 0x1b #define C_DQUOTE 0x22 #define C_SQUOTE 0x27 #define C_AMP 0x26 diff --git a/src/m_prompt.c b/src/m_prompt.c index d0269e4..dc17939 100644 --- a/src/m_prompt.c +++ b/src/m_prompt.c @@ -24,15 +24,21 @@ static char *m_subst_prompt_rice(char var[], t_msh *msh) { char tmp[PATH_MAX]; + char *ptr; size_t i; size_t j; i = 0; - while (var[i] != '\0') + while (var[i] != C_NUL) { - if (var[i] == '\\') + if (var[i] == C_BACKS) { - if (var[i + 1] == 'w') + if (var[i + 1] == '0' && var[i + 2] == '3' && var[i + 3] == '3') + { + ft_memmove(var + i, var + i + 3, ft_strlen(var + i + 3) + 1); + var[i] = C_ESC; + } + else if (var[i + 1] == 'w') { u_get_var_value(tmp, "$PWD", PATH_MAX, msh); if (tmp[0] != C_NUL) 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 @@ -25,6 +25,24 @@ /* 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) { @@ -32,6 +50,7 @@ static char 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); } -- cgit v1.2.3