diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-09-06 17:47:39 +0200 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-09-06 17:47:39 +0200 |
commit | 9c587711fc62b560809686491548aad35627bc57 (patch) | |
tree | e41c4b845212e8a722fb17a02ddd736405f282dc /src/p_args_escape.c | |
parent | TODO.org update (diff) | |
download | 42-minishell-9c587711fc62b560809686491548aad35627bc57.tar.gz 42-minishell-9c587711fc62b560809686491548aad35627bc57.tar.bz2 42-minishell-9c587711fc62b560809686491548aad35627bc57.tar.xz 42-minishell-9c587711fc62b560809686491548aad35627bc57.tar.zst 42-minishell-9c587711fc62b560809686491548aad35627bc57.zip |
I'm lost
Diffstat (limited to '')
-rw-r--r-- | src/p_args_escape.c | 23 |
1 files 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++; } } |