aboutsummaryrefslogtreecommitdiff
path: root/src/read_heredoc.c
diff options
context:
space:
mode:
authorDominik Kaiser2025-01-15 18:35:29 +0100
committerDominik Kaiser2025-01-15 18:35:29 +0100
commit79aeeaa6692c1c2c8282df751ff6fda1ba445883 (patch)
treee579137f50465efc1a554ff39b45912c2331069b /src/read_heredoc.c
parent29932bf9401f511cfa4b2fbb183bb174ecf13c24 (diff)
downloadminishell-79aeeaa6692c1c2c8282df751ff6fda1ba445883.tar.gz
minishell-79aeeaa6692c1c2c8282df751ff6fda1ba445883.zip
Refactor collect_redirs
Diffstat (limited to 'src/read_heredoc.c')
-rw-r--r--src/read_heredoc.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/read_heredoc.c b/src/read_heredoc.c
new file mode 100644
index 0000000..78efbd7
--- /dev/null
+++ b/src/read_heredoc.c
@@ -0,0 +1,54 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* read_heredoc.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* 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 */
+/* */
+/* ************************************************************************** */
+
+#include "minishell.h"
+
+char *read_heredoc(char *delimiter)
+{
+ char *line;
+ char *result;
+ char *temp;
+ size_t total_length;
+ size_t line_length;
+
+ total_length = 0;
+ result = NULL;
+ while (1)
+ {
+ line = readline("> ");
+ if (!line || ft_strcmp(line, delimiter) == 0)
+ {
+ free(line);
+ break ;
+ }
+ line_length = ft_strlen(line) + 1;
+ temp = malloc(total_length + line_length + 1);
+ if (!temp)
+ {
+ perror("malloc");
+ return (free(result), NULL);
+ }
+ if (result)
+ {
+ ft_strcpy(temp, result);
+ free(result);
+ }
+ else
+ temp[0] = '\0';
+ ft_strcat(temp, line);
+ ft_strcat(temp, "\n");
+ result = temp;
+ total_length += line_length;
+ free(line);
+ }
+ return (result);
+}