summaryrefslogtreecommitdiffstats
path: root/src/p_redirs_heredoc.c
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-09-28 19:34:00 +0200
committerJozanLeClerc <bousset.rudy@gmail.com>2020-09-28 19:34:00 +0200
commit4df7b992eac08144283cfc589c2a8bc6f4c136ee (patch)
tree291bbce77b0f5b609ced0108757b27b3483471da /src/p_redirs_heredoc.c
parentNew libft funcs (diff)
download42-minishell-4df7b992eac08144283cfc589c2a8bc6f4c136ee.tar.gz
42-minishell-4df7b992eac08144283cfc589c2a8bc6f4c136ee.tar.bz2
42-minishell-4df7b992eac08144283cfc589c2a8bc6f4c136ee.tar.xz
42-minishell-4df7b992eac08144283cfc589c2a8bc6f4c136ee.tar.zst
42-minishell-4df7b992eac08144283cfc589c2a8bc6f4c136ee.zip
Fix redirs done
Diffstat (limited to '')
-rw-r--r--src/p_redirs_heredoc.c34
1 files changed, 27 insertions, 7 deletions
diff --git a/src/p_redirs_heredoc.c b/src/p_redirs_heredoc.c
index 6b939fe..6ba06f1 100644
--- a/src/p_redirs_heredoc.c
+++ b/src/p_redirs_heredoc.c
@@ -18,30 +18,50 @@
#include "m_prompt.h"
#include "s_struct.h"
-char *p_get_heredoc(const char path[], t_msh *msh)
+static void p_skip_tabs(char *line[], const int8_t redir)
+{
+ char *ptr;
+
+ if (redir != -3)
+ return ;
+ ptr = *line;
+ while (ptr[0] != C_NUL && ptr[0] == C_HT)
+ {
+ (void)ft_memmove(ptr, ptr + 1, (ft_strlen(ptr) + 1) * sizeof(char));
+ }
+}
+
+static void p_append_line(char *heredoc[], const char line[])
+{
+ char *ptr;
+
+ ptr = *heredoc;
+ ft_strlcpy(ptr + ft_strlen(ptr), line, ft_strlen(line) + 1);
+ ptr[ft_strlen(ptr) + 1] = C_NUL;
+ ptr[ft_strlen(ptr)] = C_LF;
+}
+
+char *p_get_heredoc(const char path[], const int8_t redir, t_msh *msh)
{
char *heredoc;
char *line;
int8_t gnl;
- line = NULL;
- heredoc = NULL;
- gnl = 1;
if ((heredoc = ft_strdup("")) == NULL)
return (NULL);
+ gnl = 1;
while (gnl > 0)
{
if (msh->fd == STDIN_FILENO)
m_prompt_psx(2, msh);
gnl = get_next_line(msh->fd, &line);
+ p_skip_tabs(&line, redir);
if (ft_strncmp(path, line, ft_strlen(path) + 1) == 0)
break ;
if ((heredoc = ft_nrealloc(heredoc, ft_strlen(heredoc) + 1,
ft_strlen(heredoc) + ft_strlen(line) + 2)) == NULL)
break ;
- ft_strlcpy(heredoc + ft_strlen(heredoc), line, ft_strlen(line) + 1);
- heredoc[ft_strlen(heredoc) + 1] = C_NUL;
- heredoc[ft_strlen(heredoc)] = C_LF;
+ p_append_line(&heredoc, line);
ft_memdel((void*)&line);
}