diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-10-02 20:11:29 +0200 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-10-02 20:11:29 +0200 |
commit | 02debd1b5d39f2a0722fb73e8b4541b5ce986fb7 (patch) | |
tree | 14a7367ac49fb19b4b8e3783d35b1c6a1b7266a0 /src/p_lblock.c | |
parent | Normed p_args_next (diff) | |
download | 42-minishell-02debd1b5d39f2a0722fb73e8b4541b5ce986fb7.tar.gz 42-minishell-02debd1b5d39f2a0722fb73e8b4541b5ce986fb7.tar.bz2 42-minishell-02debd1b5d39f2a0722fb73e8b4541b5ce986fb7.tar.xz 42-minishell-02debd1b5d39f2a0722fb73e8b4541b5ce986fb7.tar.zst 42-minishell-02debd1b5d39f2a0722fb73e8b4541b5ce986fb7.zip |
Normed p_lblock
Diffstat (limited to '')
-rw-r--r-- | src/p_lblock.c | 63 |
1 files changed, 42 insertions, 21 deletions
diff --git a/src/p_lblock.c b/src/p_lblock.c index a9b7144..b0a5c6a 100644 --- a/src/p_lblock.c +++ b/src/p_lblock.c @@ -24,43 +24,64 @@ #include "s_lpipes.h" #include "s_struct.h" -int8_t p_line_block(const char line[], t_msh *msh) +static uint8_t p_get_nextif(char *words[], size_t i) { - /* TODO: norme */ - uint64_t i; - t_line_block *link; - char **words; - char *ptr; uint8_t nextif; - t_bool next; - i = 0; nextif = 0; - if ((words = p_split_line((char*)line)) == NULL) - return (-1); + if (words[i][ft_strlen(words[i]) - 1] == '0') + nextif = 0; + else if (words[i][ft_strlen(words[i]) - 1] == '1') + nextif = 1; + else + nextif = 2; + words[i][ft_strlen(words[i]) - 1] = '\0'; + return (nextif); +} + +static int8_t p_loop(char *words[], t_msh *msh) +{ + t_line_block *link; + size_t i; + uint8_t nextif; + + i = 0; while (words[i] != NULL) { - if (words[i][ft_strlen(words[i]) - 1] == '0') - nextif = 0; - else if (words[i][ft_strlen(words[i]) - 1] == '1') - nextif = 1; - else - nextif = 2; - words[i][ft_strlen(words[i]) - 1] = '\0'; - next = FALSE; - if ((ptr = ft_strchr(words[i], '|')) != NULL) + nextif = p_get_nextif(words, i); + if (ft_strchr(words[i], '|') != NULL) { if ((link = s_line_new(NULL, 0)) == NULL) return (-1); if ((s_split_pipes(words[i], msh)) == NULL) return (-1); - next = TRUE; + s_line_add_back(&msh->curr, link); + i++; + continue ; } - if (next == FALSE && (link = s_line_new(words[i], nextif)) == NULL) + if ((link = s_line_new(words[i], nextif)) == NULL) return (-1); s_line_add_back(&msh->curr, link); i++; } + return (0); +} + +/* +** TOOD: ft_strchr('|'): danger /!\ rewrite this shit +*/ + +int8_t p_line_block(const char line[], t_msh *msh) +{ + char **words; + + if ((words = p_split_line((char*)line)) == NULL) + return (-1); + if (p_loop(words, msh) != 0) + { + ft_delwords(words); + return (-1); + } ft_delwords(words); return (0); } |