diff options
Diffstat (limited to '')
-rw-r--r-- | src/p_lblock.c | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/src/p_lblock.c b/src/p_lblock.c index 7213ee4..e7faeea 100644 --- a/src/p_lblock.c +++ b/src/p_lblock.c @@ -18,11 +18,14 @@ #include <errno.h> #include "d_define.h" +#include "d_enum.h" #include "f_fail.h" #include "p_split.h" #include "s_line.h" #include "s_lpipes.h" +#include "u_parse.h" #include "s_struct.h" +#include "u_utils.h" static uint8_t p_get_nextif(char *words[], size_t i) { @@ -43,6 +46,30 @@ static uint8_t p_get_nextif(char *words[], size_t i) ** TODO: ft_strchr('|'): danger /!\ rewrite this shit */ +static t_bool p_find_good_pipe(const char word[]) +{ + char *ptr; + t_quote_mode mode; + + mode = Q_NONE; + ptr = (char*)word; + while (*ptr != C_NUL) + { + if (*ptr == C_PIPE) + { + if (mode == Q_NONE && u_is_not_escaped(word, ptr) == TRUE + && *(ptr + 1) != C_PIPE) + return (TRUE); + } + if (*ptr == C_DQUOTE) + mode = u_meet_dquote(word, ptr, mode); + else if (*ptr == C_SQUOTE) + mode = u_meet_squote(word, ptr, mode); + ptr++; + } + return (FALSE); +} + static int8_t p_loop(char *words[], t_msh *msh) { t_line_block *link; @@ -53,7 +80,7 @@ static int8_t p_loop(char *words[], t_msh *msh) while (words[i] != NULL) { nextif = p_get_nextif(words, i); - if (ft_strchr(words[i], '|') != NULL) + if (p_find_good_pipe(words[i]) == TRUE) { if ((link = s_line_new(NULL, 0)) == NULL) return (-1); |