summaryrefslogtreecommitdiffstats
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
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
-rw-r--r--TODO.org2
-rw-r--r--src/d_define.h1
-rw-r--r--src/m_prompt.c12
-rw-r--r--src/p_lblock_next.c23
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
@@ -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);
}