From 9f2424c0dca6073d1e97f290ad890a2ad7143ef1 Mon Sep 17 00:00:00 2001 From: Dominik Kaiser Date: Wed, 15 Jan 2025 18:55:47 +0100 Subject: [PATCH] Fix collect_redirs and start refactoring heredoc --- src/collect_redirs.c | 16 ++++++++++------ src/read_heredoc.c | 17 ++++++++++++----- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/collect_redirs.c b/src/collect_redirs.c index 2947c52..4decda7 100644 --- a/src/collect_redirs.c +++ b/src/collect_redirs.c @@ -6,7 +6,7 @@ /* By: chuhlig +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/08/02 13:49:31 by dkaiser #+# #+# */ -/* Updated: 2025/01/15 18:33:36 by dkaiser ### ########.fr */ +/* Updated: 2025/01/15 18:54:42 by dkaiser ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,7 +16,8 @@ static void collect_and_check_redir(t_redirection *result, t_token **cur, t_env *env); static void set_redir(t_redirection *redir, int type, char *spec, t_env *env); -static char *get_heredoc_data(t_token *cur); +static int set_heredoc_data(t_token *cur, t_redirection *result, + t_env *env); t_redirection *collect_redirs(t_token **tokens, t_env *env) { @@ -62,7 +63,8 @@ static void collect_and_check_redir(t_redirection *result, t_token **cur, str = ft_strdup((*cur)->next->content.string); if ((*cur)->content.redir_type == INPUT_LIMITER) { - set_redir(&result[0], INPUT_LIMITER, get_heredoc_data(*cur), env); + if (!set_heredoc_data(*cur, result, env)) + return ; } else if ((*cur)->content.redir_type == INPUT_FILE) set_redir(&result[0], INPUT_FILE, str, env); @@ -81,19 +83,21 @@ static void collect_and_check_redir(t_redirection *result, t_token **cur, *cur = NULL; } -static char *get_heredoc_data(t_token *cur) +static int set_heredoc_data(t_token *cur, t_redirection *result, t_env *env) { char *heredoc_data; + heredoc_data = NULL; if (cur->content.redir_type == INPUT_LIMITER) { heredoc_data = read_heredoc(cur->next->content.string); if (!heredoc_data) { perror("Heredoc allocation failed"); - return ; + return (0); } set_redir(&result[0], INPUT_LIMITER, heredoc_data, env); } - return (heredoc_data); + set_redir(&result[0], INPUT_LIMITER, heredoc_data, env); + return (1); } diff --git a/src/read_heredoc.c b/src/read_heredoc.c index 78efbd7..4b45b14 100644 --- a/src/read_heredoc.c +++ b/src/read_heredoc.c @@ -6,12 +6,14 @@ /* By: dkaiser