diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-10-02 19:44:20 +0200 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-10-02 19:44:20 +0200 |
commit | 064a9d713e14f500c10e968ee84eb558993229ae (patch) | |
tree | ae98d75dc3d4e1ae8828888e251534bcc8d56f13 /src | |
parent | Norming p_args_escape (diff) | |
download | 42-minishell-064a9d713e14f500c10e968ee84eb558993229ae.tar.gz 42-minishell-064a9d713e14f500c10e968ee84eb558993229ae.tar.bz2 42-minishell-064a9d713e14f500c10e968ee84eb558993229ae.tar.xz 42-minishell-064a9d713e14f500c10e968ee84eb558993229ae.tar.zst 42-minishell-064a9d713e14f500c10e968ee84eb558993229ae.zip |
Normed p_args_escape
Diffstat (limited to 'src')
-rw-r--r-- | src/p_args_escape.c | 49 |
1 files changed, 22 insertions, 27 deletions
diff --git a/src/p_args_escape.c b/src/p_args_escape.c index de00861..d878004 100644 --- a/src/p_args_escape.c +++ b/src/p_args_escape.c @@ -16,7 +16,10 @@ #include "d_define.h" #include "u_utils.h" -static t_quote_mode p_escape_squote(char *ptr, char **p, char word[], t_quote_mode mode) +static t_quote_mode p_escape_squote(char *ptr, + char **p, + char word[], + t_quote_mode mode) { if (mode == Q_NONE) { @@ -42,7 +45,10 @@ static t_quote_mode p_escape_squote(char *ptr, char **p, char word[], t_quote_mo return (mode); } -static t_quote_mode p_escape_dquote(char *ptr, char **p, char word[], t_quote_mode mode) +static t_quote_mode p_escape_dquote(char *ptr, + char **p, + char word[], + t_quote_mode mode) { if (mode == Q_NONE) { @@ -109,39 +115,28 @@ static void p_escape_arg(char word[]) } } -static void p_replace_bs(char *ptr) -{ - char *head; - - head = ptr; - while (*ptr != C_NUL) - { - if (*ptr == C_SUB && *(ptr + 1) == C_SUB) - { - (void)ft_memmove(head + (ptr - head), ptr + 1, - (ft_strlen(ptr + 1) + 1) * sizeof(char)); - *ptr = C_BACKS; - } - ptr++; - } -} - -/* -** TODO: escape \ -** TODO: escape $# special vars -** TODO: comments ################ -** TODO: escape my life -*/ - void p_args_escape_chars_and_quotes(char *words[]) { char **ptr; + char *head; + char *rptr; ptr = words; while (*ptr != NULL) { p_escape_arg(*ptr); - p_replace_bs(*ptr); + rptr = *ptr; + head = rptr; + while (*rptr != C_NUL) + { + if (*rptr == C_SUB && *(rptr + 1) == C_SUB) + { + (void)ft_memmove(head + (rptr - head), rptr + 1, + (ft_strlen(rptr + 1) + 1) * sizeof(char)); + *rptr = C_BACKS; + } + rptr++; + } ptr++; } } |