aboutsummaryrefslogtreecommitdiff
path: root/src/collect_redirs.c
diff options
context:
space:
mode:
authorDominik Kaiser2025-01-15 18:55:47 +0100
committerDominik Kaiser2025-01-15 18:55:47 +0100
commit9f2424c0dca6073d1e97f290ad890a2ad7143ef1 (patch)
tree8e12b2c3eff834e8d03b7bfe2c8fdee46220d2cc /src/collect_redirs.c
parent79aeeaa6692c1c2c8282df751ff6fda1ba445883 (diff)
downloadminishell-9f2424c0dca6073d1e97f290ad890a2ad7143ef1.tar.gz
minishell-9f2424c0dca6073d1e97f290ad890a2ad7143ef1.zip
Fix collect_redirs and start refactoring heredoc
Diffstat (limited to 'src/collect_redirs.c')
-rw-r--r--src/collect_redirs.c16
1 files changed, 10 insertions, 6 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 <chuhlig@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);
}