From 02debd1b5d39f2a0722fb73e8b4541b5ce986fb7 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Fri, 2 Oct 2020 20:11:29 +0200 Subject: Normed p_lblock --- TODO.org | 1 + src/p_lblock.c | 63 ++++++++++++++++++++++++++++++++++++++-------------------- src/p_lblock.h | 8 ++++---- 3 files changed, 47 insertions(+), 25 deletions(-) diff --git a/TODO.org b/TODO.org index 5ccc785..287329d 100644 --- a/TODO.org +++ b/TODO.org @@ -20,6 +20,7 @@ CLOSED: [2020-09-26 Sat 19:43] ** TODO [#A] msh ~> qwewqrqrqwrqwrqr ($? and output vs bash) ** TODO [#A] pipes don't split "qweqwreq | qweqweqe" +** TODO [#A] bus error on msh ~> exit ** DONE [#A] SEGV on pipes ** DONE [#B] forked write(2) stuff on cd ** DONE [#B] Multiline && || 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); } diff --git a/src/p_lblock.h b/src/p_lblock.h index b5052f3..88a8b1e 100644 --- a/src/p_lblock.h +++ b/src/p_lblock.h @@ -10,12 +10,12 @@ /* */ /* ************************************************************************** */ -#ifndef P_LCOM_H -#define P_LCOM_H +#ifndef FT_P_LCOM_H +# define FT_P_LCOM_H -#include +# include -#include "s_struct.h" +# include "s_struct.h" int8_t p_line_block(const char line[], t_msh *msh); -- cgit v1.2.3