diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-08-24 18:05:34 +0200 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-08-24 18:05:34 +0200 |
commit | f10e352f8740009d1a93f90160fda7aeabf2a2dc (patch) | |
tree | d8c98fdad9cb985d05e63d0999c4c252c233b8c8 /src/m_loop_next.c | |
parent | TODO update (diff) | |
download | 42-minishell-f10e352f8740009d1a93f90160fda7aeabf2a2dc.tar.gz 42-minishell-f10e352f8740009d1a93f90160fda7aeabf2a2dc.tar.bz2 42-minishell-f10e352f8740009d1a93f90160fda7aeabf2a2dc.tar.xz 42-minishell-f10e352f8740009d1a93f90160fda7aeabf2a2dc.tar.zst 42-minishell-f10e352f8740009d1a93f90160fda7aeabf2a2dc.zip |
Counter | and counter \
Diffstat (limited to 'src/m_loop_next.c')
-rw-r--r-- | src/m_loop_next.c | 95 |
1 files changed, 95 insertions, 0 deletions
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 <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/14 17:19:27 by rbousset #+# #+# */ +/* Updated: 2020/02/14 17:19:29 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#include <libft.h> +#include <stdint.h> +#include <unistd.h> + +#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); +} + |