diff options
| author | Dominik Kaiser | 2025-01-15 18:55:47 +0100 |
|---|---|---|
| committer | Dominik Kaiser | 2025-01-15 18:55:47 +0100 |
| commit | 9f2424c0dca6073d1e97f290ad890a2ad7143ef1 (patch) | |
| tree | 8e12b2c3eff834e8d03b7bfe2c8fdee46220d2cc /src | |
| parent | 79aeeaa6692c1c2c8282df751ff6fda1ba445883 (diff) | |
| download | minishell-9f2424c0dca6073d1e97f290ad890a2ad7143ef1.tar.gz minishell-9f2424c0dca6073d1e97f290ad890a2ad7143ef1.zip | |
Fix collect_redirs and start refactoring heredoc
Diffstat (limited to 'src')
| -rw-r--r-- | src/collect_redirs.c | 16 | ||||
| -rw-r--r-- | 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 <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); } 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 <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; @@ -44,11 +46,16 @@ char *read_heredoc(char *delimiter) } 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); +} |
