diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-10-21 18:38:29 +0200 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-10-21 18:38:29 +0200 |
commit | 7fd7a979e27b06034f1f47189bf410c9a1180357 (patch) | |
tree | 0bedc1b8b3baabd2f07d971ecbac6c5138816049 | |
parent | Typo (diff) | |
download | 42-minishell-7fd7a979e27b06034f1f47189bf410c9a1180357.tar.gz 42-minishell-7fd7a979e27b06034f1f47189bf410c9a1180357.tar.bz2 42-minishell-7fd7a979e27b06034f1f47189bf410c9a1180357.tar.xz 42-minishell-7fd7a979e27b06034f1f47189bf410c9a1180357.tar.zst 42-minishell-7fd7a979e27b06034f1f47189bf410c9a1180357.zip |
One good function
-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); |