Compare commits

...

2 Commits

Author SHA1 Message Date
Camille Chauvet
8af6b42642 fix: invalid read 'echo sfdsdfsd cchauvet' 2023-03-31 15:23:58 +02:00
Camille Chauvet
46fe9caded fix: heredoc work now 2023-03-31 15:23:10 +02:00
2 changed files with 11 additions and 16 deletions

View File

@ -6,7 +6,7 @@
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */ /* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/15 13:35:50 by cchauvet #+# #+# */ /* Created: 2023/02/15 13:35:50 by cchauvet #+# #+# */
/* Updated: 2023/03/30 16:01:56 by cchauvet ### ########.fr */ /* Updated: 2023/03/31 15:22:21 by alouis-j ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -40,7 +40,7 @@ static char *ft_spacer_after(const char *str)
{ {
while (ft_is_in_quote(out, i - 1)) while (ft_is_in_quote(out, i - 1))
i++; i++;
if (out[i] == '\0') if (out[i - 1] == '\0' || out[i] == '\0')
break ; break ;
if (ft_is_in("><|", out[i - 1])) if (ft_is_in("><|", out[i - 1]))
{ {

View File

@ -6,7 +6,7 @@
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */ /* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/17 15:36:26 by cchauvet #+# #+# */ /* Created: 2023/02/17 15:36:26 by cchauvet #+# #+# */
/* Updated: 2023/03/29 16:37:05 by cchauvet ### ########.fr */ /* Updated: 2023/03/31 15:19:42 by alouis-j ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -31,8 +31,13 @@ static int ft_format_and_write(t_data *data, const char *str, int fd)
return (0); return (0);
} }
static int ft_heredoc2(t_data *data, char *stop, char *line, int fds[2]) static int ft_heredoc2(t_data *data, char *stop, int fds[2])
{ {
char *line;
ft_printf("> ");
line = get_next_line(*ft_get_heredoc());
if (line == NULL)
return (1);
line[ft_strlen(line) - 1] = '\0'; line[ft_strlen(line) - 1] = '\0';
if (ft_strcmp(line, stop) == 0) if (ft_strcmp(line, stop) == 0)
{ {
@ -46,30 +51,20 @@ static int ft_heredoc2(t_data *data, char *stop, char *line, int fds[2])
return (1); return (1);
} }
free(line); free(line);
ft_printf("> ");
line = get_next_line(*ft_get_heredoc());
if (line == NULL && *ft_get_heredoc() == -1)
{
ft_closer(fds);
return (1);
}
return (0); return (0);
} }
int ft_heredoc(t_data *data, char *stop) int ft_heredoc(t_data *data, char *stop)
{ {
char *line;
int fds[2]; int fds[2];
int return_code; int return_code;
if (pipe(fds) == -1) if (pipe(fds) == -1)
return (-1); return (-1);
*ft_get_heredoc() = dup(0); *ft_get_heredoc() = dup(0);
ft_printf("> "); while (true)
line = get_next_line(*ft_get_heredoc());
while (line != NULL)
{ {
return_code = ft_heredoc2(data, stop, line, fds); return_code = ft_heredoc2(data, stop, fds);
if (return_code == 2) if (return_code == 2)
break ; break ;
else if (return_code) else if (return_code)