From f10e352f8740009d1a93f90160fda7aeabf2a2dc Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Mon, 24 Aug 2020 18:05:34 +0200 Subject: Counter | and counter \ --- src/m_loop_next.c | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 src/m_loop_next.c (limited to 'src/m_loop_next.c') diff --git a/src/m_loop_next.c b/src/m_loop_next.c new file mode 100644 index 0000000..9aa7129 --- /dev/null +++ b/src/m_loop_next.c @@ -0,0 +1,95 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* m_loop_next.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rbousset +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/14 17:19:27 by rbousset #+# #+# */ +/* Updated: 2020/02/14 17:19:29 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include +#include + +#include "m_prompt.h" +#include "s_struct.h" + +static char + *m_counter_line_backslash(int32_t fd, uint8_t psx, char *line, t_msh *msh) +{ + char *counter_line; + + if (fd == STDIN_FILENO) + m_prompt_psx(psx, msh); + get_next_line(fd, &counter_line); + if (counter_line[0] != 0) + { + line = ft_nrealloc(line, + ft_strlen(line) + 1, + ft_strlen(line) + ft_strlen(counter_line)); + ft_memcpy(line + ft_strlen(line) - 1, + counter_line, + ft_strlen(counter_line) + 1); + } + ft_memdel((void*)&counter_line); + return (line); +} + +static char + *m_counter_line_pipes(int32_t fd, uint8_t psx, char *line, t_msh *msh) +{ + char *counter_line; + + if (fd == STDIN_FILENO) + m_prompt_psx(psx, msh); + get_next_line(fd, &counter_line); + if (counter_line[0] != 0) + { + line = ft_nrealloc(line, + ft_strlen(line) + 1, + ft_strlen(line) + ft_strlen(counter_line) + 1); + ft_memcpy(line + ft_strlen(line), + counter_line, + ft_strlen(counter_line) + 1); + } + ft_memdel((void*)&counter_line); + return (line); +} + +char + *m_check_multi_backslash(int32_t fd, char *line, t_msh *msh) +{ + if (line[ft_strlen(line) - 1] == '\\') + { + line = m_counter_line_backslash(fd, 2, line, msh); + line = m_check_multi_backslash(fd, line, msh); + } + return (line); +} + +char + *m_check_multi_pipe(int32_t fd, char *line, t_msh *msh) +{ + char *pipe; + + if ((pipe = ft_strrchr(line, '|')) != NULL) + { + pipe++; + while (*pipe != '\0') + { + if (ft_isspace(*pipe) == FALSE) + { + return (line); + } + pipe++; + } + line = m_counter_line_pipes(fd, 2, line, msh); + line = m_check_multi_backslash(fd, line, msh); + line = m_check_multi_pipe(fd, line, msh); + } + return (line); +} + -- cgit v1.2.3