aboutsummaryrefslogtreecommitdiff
path: root/src
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
parent348f46d8ad351f83821831ec997fec91aee43d5c (diff)
downloadminishell-29932bf9401f511cfa4b2fbb183bb174ecf13c24.tar.gz
minishell-29932bf9401f511cfa4b2fbb183bb174ecf13c24.zip
Fix waiting errors
Diffstat (limited to 'src')
-rw-r--r--src/collect_redirs.c35
-rw-r--r--src/interpreter.c4
-rw-r--r--src/parse_cmd.c4
3 files changed, 24 insertions, 19 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)
diff --git a/src/interpreter.c b/src/interpreter.c
index a1d3823..0a6d781 100644
--- a/src/interpreter.c
+++ b/src/interpreter.c
@@ -6,7 +6,7 @@
/* By: chuhlig <chuhlig@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/12/17 19:15:49 by chuhlig #+# #+# */
-/* Updated: 2025/01/14 19:52:27 by chuhlig ### ########.fr */
+/* Updated: 2025/01/15 18:10:25 by dkaiser ### ########.fr */
/* */
/* ************************************************************************** */
@@ -77,7 +77,6 @@ int eval_rec(t_node *node, t_env **env, int in_fd)
pid_t pid;
int p[2];
int result;
- int status;
int original_stdin;
if (node->type == PIPE_NODE)
@@ -98,7 +97,6 @@ int eval_rec(t_node *node, t_env **env, int in_fd)
original_stdin = dup(STDIN_FILENO);
dup2(p[0], STDIN_FILENO);
result = eval_rec(node->content.pipe.right, env, p[0]);
- waitpid(pid, &status, 0);
dup2(original_stdin, STDIN_FILENO);
close(original_stdin);
}
diff --git a/src/parse_cmd.c b/src/parse_cmd.c
index 3c4eb96..9ca741b 100644
--- a/src/parse_cmd.c
+++ b/src/parse_cmd.c
@@ -6,7 +6,7 @@
/* By: chuhlig <chuhlig@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/08 15:06:25 by dkaiser #+# #+# */
-/* Updated: 2025/01/11 16:04:50 by chuhlig ### ########.fr */
+/* Updated: 2025/01/15 17:22:58 by dkaiser ### ########.fr */
/* */
/* ************************************************************************** */
@@ -19,7 +19,7 @@ t_node *parse_cmd(t_token *tokens, t_env **env)
char **args;
t_redirection *redirs;
- redirs = collect_redirs(&tokens);
+ redirs = collect_redirs(&tokens, *env);
if (redirs == NULL)
return (NULL);
args = collect_args(&tokens, env);