diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-09-04 23:37:56 +0200 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-09-04 23:37:56 +0200 |
commit | 011c05984decefb425114d2d73667366d3af2045 (patch) | |
tree | 792f08823c4554c0ee31ee5059117d81ae372dc6 | |
parent | REALLY (diff) | |
download | 42-minishell-011c05984decefb425114d2d73667366d3af2045.tar.gz 42-minishell-011c05984decefb425114d2d73667366d3af2045.tar.bz2 42-minishell-011c05984decefb425114d2d73667366d3af2045.tar.xz 42-minishell-011c05984decefb425114d2d73667366d3af2045.tar.zst 42-minishell-011c05984decefb425114d2d73667366d3af2045.zip |
This is all wrong
-rw-r--r-- | src/p_args_quotes.c | 50 |
1 files changed, 31 insertions, 19 deletions
diff --git a/src/p_args_quotes.c b/src/p_args_quotes.c index a63ce38..6ecbb90 100644 --- a/src/p_args_quotes.c +++ b/src/p_args_quotes.c @@ -15,35 +15,35 @@ #include "d_define.h" -static void - p_arg_squotes(char word[]) -{ - char *ptr; +/* static void */ +/* p_arg_squotes(char word[]) */ +/* { */ +/* char *ptr; */ - ptr = word; - while ((ptr = ft_strchr(ptr, C_SQUOTE)) != NULL) - { - ft_memmove(word + (ptr - word), ptr + 1, ft_strlen(ptr + 1) + 1); - } -} +/* ptr = word; */ +/* while ((ptr = ft_strchr(ptr, C_SQUOTE)) != NULL) */ +/* { */ +/* ft_memmove(word + (ptr - word), ptr + 1, ft_strlen(ptr + 1) + 1); */ +/* } */ +/* } */ static void p_arg_dquotes(char word[]) { char *ptr; - ft_memmove(word, word + 1, ft_strlen(word)); ptr = word; while ((ptr = ft_strchr(ptr, C_DQUOTE)) != NULL) { - if (*(ptr - 1) == C_BACKSLASH && *(ptr - 2) != C_BACKSLASH) - { + if (ptr - word == 0) + ft_memmove(word, word + 1, ft_strlen(word)); + else if (ptr - word == 1 && *(ptr - 1) == C_BACKSLASH) + ptr++; + else if (ptr - word > 1 && *(ptr - 1) == C_BACKSLASH && + *(ptr - 2) != C_BACKSLASH) ptr++; - } else - { ft_memmove(word + (ptr - word), ptr + 1, ft_strlen(ptr + 1) + 1); - } } } @@ -55,11 +55,23 @@ void char *sq_ptr; ptr = words; + dq_ptr = NULL; + sq_ptr = NULL; while (*ptr != NULL) { - p_arg_squotes(*ptr); - else if (**ptr == C_DQUOTE) - p_arg_dquotes(*ptr); + dq_ptr = ft_strchr(*ptr, C_DQUOTE); + sq_ptr = ft_strchr(*ptr, C_SQUOTE); + if (dq_ptr != NULL && sq_ptr != NULL) + { + if (dq_ptr < sq_ptr) + p_arg_dquotes(*ptr); + } + /* if (**ptr == C_SQUOTE) */ + /* p_arg_squotes(*ptr); */ + /* else if (**ptr == C_DQUOTE) */ + /* p_arg_dquotes(*ptr); */ ptr++; + dq_ptr = NULL; + sq_ptr = NULL; } } |