/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* heredoc.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: cchauvet #include int *ft_get_heredoc() { static int heredoc = -1; return (&heredoc); } int ft_heredoc(t_data *data, char *stop) { char *line; char *line_clean; int fds[2]; if (pipe(fds) == -1) return (-2); *ft_get_heredoc() = dup(0); ft_printf("> "); line = get_next_line(*ft_get_heredoc()); while (line != NULL) { line[ft_strlen(line) - 1] = '\0'; if (ft_strcmp(line, stop) == 0) { free(line); break ; } line_clean = ft_env_filler(data, line); free(line); ft_putendl_fd(line_clean, fds[1]); free(line_clean); ft_printf("> "); line = get_next_line(*ft_get_heredoc()); if (line == NULL && *ft_get_heredoc() == -1) { close(fds[0]); close(fds[1]); return (-2); } } close(fds[1]); *ft_get_heredoc() = -1; return (fds[0]); }