/* 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 */
/* */
/* ************************************************************************** */
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)
{
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);
*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);
}
/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/01/15 18:22:09 by dkaiser #+# #+# */
-/* Updated: 2025/01/15 18:22:52 by dkaiser ### ########.fr */
+/* Updated: 2025/01/15 18:43:20 by dkaiser ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
+static char *concat_str(char *temp, char *line);
+
char *read_heredoc(char *delimiter)
{
char *line;
}
else
temp[0] = '\0';
- ft_strcat(temp, line);
- ft_strcat(temp, "\n");
- result = temp;
+ result = concat_str(temp, line);
total_length += line_length;
- free(line);
}
return (result);
}
+
+static char *concat_str(char *temp, char *line)
+{
+ ft_strcat(temp, line);
+ ft_strcat(temp, "\n");
+ free(line);
+ return (temp);
+}