diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-10-01 19:14:01 +0200 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-10-01 19:14:01 +0200 |
commit | 426399f98b6cf68c2eee448de49ea091ac7a0562 (patch) | |
tree | e68f2f1ed1fca3bd54d7525d81f29e1bd6836703 /src/m_loop_counter.c | |
parent | Renormed m_loop (diff) | |
download | 42-minishell-426399f98b6cf68c2eee448de49ea091ac7a0562.tar.gz 42-minishell-426399f98b6cf68c2eee448de49ea091ac7a0562.tar.bz2 42-minishell-426399f98b6cf68c2eee448de49ea091ac7a0562.tar.xz 42-minishell-426399f98b6cf68c2eee448de49ea091ac7a0562.tar.zst 42-minishell-426399f98b6cf68c2eee448de49ea091ac7a0562.zip |
Normed m_loop
Diffstat (limited to 'src/m_loop_counter.c')
-rw-r--r-- | src/m_loop_counter.c | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/src/m_loop_counter.c b/src/m_loop_counter.c new file mode 100644 index 0000000..55a3b27 --- /dev/null +++ b/src/m_loop_counter.c @@ -0,0 +1,80 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* m_loop_counter.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" + +char *m_counter_line_backslash(int32_t fd, uint8_t psx, char *l, 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] != C_NUL) + { + l = ft_nrealloc(l, + ft_strlen(l) + 1, + ft_strlen(l) + ft_strlen(counter_line)); + ft_memcpy(l + ft_strlen(l) - 1, + counter_line, + ft_strlen(counter_line) + 1); + } + ft_memdel((void*)&counter_line); + return (l); +} + +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] != C_NUL) + { + 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_counter_line_quotes(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] != C_NUL) + { + line = ft_nrealloc(line, + ft_strlen(line) + 1, + ft_strlen(line) + ft_strlen(counter_line) + 2); + line[ft_strlen(line) + 1] = '\0'; + line[ft_strlen(line)] = '\n'; + ft_memcpy(line + ft_strlen(line), + counter_line, + ft_strlen(counter_line) + 1); + } + ft_memdel((void*)&counter_line); + return (line); +} |