From 9c587711fc62b560809686491548aad35627bc57 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Sun, 6 Sep 2020 17:47:39 +0200 Subject: I'm lost --- src/p_args_escape.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/p_args_escape.c b/src/p_args_escape.c index 2df2e0f..8a2e27f 100644 --- a/src/p_args_escape.c +++ b/src/p_args_escape.c @@ -17,7 +17,7 @@ #include "u_utils.h" static t_quote_mode - p_escape_squote(char *ptr, char word[], t_quote_mode mode) + p_escape_squote(char *ptr, char **p, char word[], t_quote_mode mode) { if (mode == Q_NONE) { @@ -25,6 +25,7 @@ static t_quote_mode { (void)ft_memmove(word + (ptr - word), ptr + 1, (ft_strlen(ptr + 1) + 1) * sizeof(char)); + *(p) -= 1; return (Q_SINGLE); } else @@ -36,13 +37,14 @@ static t_quote_mode { (void)ft_memmove(word + (ptr - word), ptr + 1, (ft_strlen(ptr + 1) + 1) * sizeof(char)); + *(p) -= 1; return (Q_NONE); } return (mode); } static t_quote_mode - p_escape_dquote(char *ptr, char word[], t_quote_mode mode) + p_escape_dquote(char *ptr, char **p, char word[], t_quote_mode mode) { if (mode == Q_NONE) { @@ -50,6 +52,7 @@ static t_quote_mode { (void)ft_memmove(word + (ptr - word), ptr + 1, (ft_strlen(ptr + 1) + 1) * sizeof(char)); + *(p) -= 1; return (Q_DOUBLE); } else @@ -61,18 +64,24 @@ static t_quote_mode { (void)ft_memmove(word + (ptr - word), ptr + 1, (ft_strlen(ptr + 1) + 1) * sizeof(char)); + *(p) -= 1; return (Q_NONE); } return (mode); } static void - p_escape_bs(char *ptr, char word[], t_quote_mode mode) + p_escape_bs(char *ptr, char **p, char word[], t_quote_mode mode) { if (mode == Q_NONE) { (void)ft_memmove(word + (ptr - word), ptr + 1, (ft_strlen(ptr + 1) + 1) * sizeof(char)); + if (*ptr == C_BS) + { + *(word + (ptr - word)) = 26; + } + *(p) -= 1; } else if (mode == Q_DOUBLE) { @@ -81,11 +90,13 @@ static void (void)ft_memmove(word + (ptr - word), ptr + 1, (ft_strlen(ptr + 1) + 1) * sizeof(char)); *(word + (ptr - word)) = 26; + *(p) -= 1; } else if (*(ptr + 1) == C_DQUOTE) { (void)ft_memmove(word + (ptr - word), ptr + 1, (ft_strlen(ptr + 1) + 1) * sizeof(char)); + *(p) -= 1; } } } @@ -101,11 +112,11 @@ static void while (*ptr != C_NULL) { if (*ptr == C_SQUOTE) - mode = p_escape_squote(ptr, word, mode); + mode = p_escape_squote(ptr, &ptr, word, mode); else if (*ptr == C_DQUOTE) - mode = p_escape_dquote(ptr, word, mode); + mode = p_escape_dquote(ptr, &ptr, word, mode); if (*ptr == C_BS) - p_escape_bs(ptr, word, mode); + p_escape_bs(ptr, &ptr, word, mode); ptr++; } } -- cgit v1.2.3