aboutsummaryrefslogtreecommitdiff
path: root/src/collect_redirs.c
diff options
context:
space:
mode:
authorDominik Kaiser2025-01-15 18:15:16 +0100
committerDominik Kaiser2025-01-15 18:15:16 +0100
commit29932bf9401f511cfa4b2fbb183bb174ecf13c24 (patch)
treefcb9af9d5fb8bb587dcd5091f405c555120f1093 /src/collect_redirs.c
parent348f46d8ad351f83821831ec997fec91aee43d5c (diff)
downloadminishell-29932bf9401f511cfa4b2fbb183bb174ecf13c24.tar.gz
minishell-29932bf9401f511cfa4b2fbb183bb174ecf13c24.zip
Fix waiting errors
Diffstat (limited to 'src/collect_redirs.c')
-rw-r--r--src/collect_redirs.c35
1 files changed, 21 insertions, 14 deletions
diff --git a/src/collect_redirs.c b/src/collect_redirs.c
index 84ebd71..02c866f 100644
--- a/src/collect_redirs.c
+++ b/src/collect_redirs.c
@@ -6,14 +6,16 @@
/* By: chuhlig <chuhlig@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/02 13:49:31 by dkaiser #+# #+# */
-/* Updated: 2025/01/14 16:55:20 by chuhlig ### ########.fr */
+/* Updated: 2025/01/15 18:10:46 by dkaiser ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
-static void collect_and_check_redir(t_redirection *result, t_token **cur);
-static void set_redir(t_redirection *redir, int type, char *specifier);
+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 *specifier,
+ t_env *env);
static char *read_heredoc(char *delimiter)
{
@@ -56,7 +58,7 @@ static char *read_heredoc(char *delimiter)
return (result);
}
-t_redirection *collect_redirs(t_token **tokens)
+t_redirection *collect_redirs(t_token **tokens, t_env *env)
{
t_redirection *result;
t_token *cur;
@@ -65,12 +67,12 @@ t_redirection *collect_redirs(t_token **tokens)
result = malloc(sizeof(t_redirection) * 2);
if (result == NULL)
return (free_tokens(*tokens), NULL);
- set_redir(&result[0], 0, NULL);
- set_redir(&result[1], 0, NULL);
+ set_redir(&result[0], 0, NULL, env);
+ set_redir(&result[1], 0, NULL, env);
while (cur != NULL && cur->next != NULL)
{
if (cur->type == REDIR_TOKEN && cur->next->type == STRING_TOKEN)
- collect_and_check_redir(result, &cur);
+ collect_and_check_redir(result, &cur, env);
else if (cur->type == REDIR_TOKEN)
return (free(result), NULL);
else
@@ -81,13 +83,18 @@ t_redirection *collect_redirs(t_token **tokens)
return (result);
}
-static void set_redir(t_redirection *redir, int type, char *specifier)
+static void set_redir(t_redirection *redir, int type, char *specifier,
+ t_env *env)
{
redir->type = type;
- redir->specifier = specifier;
+ if (specifier != NULL)
+ redir->specifier = format_string(specifier, env);
+ else
+ redir->specifier = specifier;
}
-static void collect_and_check_redir(t_redirection *result, t_token **cur)
+static void collect_and_check_redir(t_redirection *result, t_token **cur,
+ t_env *env)
{
char *heredoc_data;
t_token *next_token;
@@ -101,17 +108,17 @@ static void collect_and_check_redir(t_redirection *result, t_token **cur)
perror("Heredoc allocation failed");
return ;
}
- set_redir(&result[0], INPUT_LIMITER, heredoc_data);
+ set_redir(&result[0], INPUT_LIMITER, heredoc_data, env);
}
else if ((*cur)->content.redir_type == INPUT_FILE)
set_redir(&result[0], INPUT_FILE,
- ft_strdup((*cur)->next->content.string));
+ ft_strdup((*cur)->next->content.string), env);
else if ((*cur)->content.redir_type == OUTPUT_OVERRIDE)
set_redir(&result[1], OUTPUT_OVERRIDE,
- ft_strdup((*cur)->next->content.string));
+ ft_strdup((*cur)->next->content.string), env);
else if ((*cur)->content.redir_type == OUTPUT_APPEND)
set_redir(&result[1], OUTPUT_APPEND,
- ft_strdup((*cur)->next->content.string));
+ ft_strdup((*cur)->next->content.string), env);
next_token = (*cur)->next;
free_token_and_connect(*cur);
if (next_token)