]> git.dkaiser.de - 42/minishell.git/commitdiff
Fix waiting errors
authorDominik Kaiser <dkaiser@3-H-6.42heilbronn.de>
Wed, 15 Jan 2025 17:15:16 +0000 (18:15 +0100)
committerDominik Kaiser <dkaiser@3-H-6.42heilbronn.de>
Wed, 15 Jan 2025 17:15:16 +0000 (18:15 +0100)
include/minishell.h
src/collect_redirs.c
src/interpreter.c
src/parse_cmd.c

index 88b22d53bca564a5732732d5a5d0214b5ae8f0fd..2a426cf6e739b86f6dbd409e9f335783f5c682f8 100644 (file)
@@ -6,7 +6,7 @@
 /*   By: chuhlig <chuhlig@student.42.fr>            +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2024/06/22 17:14:49 by dkaiser           #+#    #+#             */
-/*   Updated: 2025/01/15 16:35:40 by dkaiser          ###   ########.fr       */
+/*   Updated: 2025/01/15 17:20:56 by dkaiser          ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
@@ -35,7 +35,7 @@ void                  repl(const char *prompt, t_env **env, int *promptflag);
 
 t_list                 *parse(t_token *tokens, t_env **env);
 t_node                 *parse_cmd(t_token *tokens, t_env **env);
-t_redirection  *collect_redirs(t_token **tokens);
+t_redirection  *collect_redirs(t_token **tokens, t_env *env);
 
 void                   print_ast(t_node *ast);
 int                            eval(t_node *node, t_env **env);
index 84ebd719f76c89e7576e4a46f46fe4c81d0bae7e..02c866fd321e21d749b5ce352d05e17e867f9ac0 100644 (file)
@@ -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)
index a1d382358b035b353880b64dbb8f6861e48644b4..0a6d7815d9e7a7ac5cd62b66b0de9da1aacbed3a 100644 (file)
@@ -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);
                }
index 3c4eb965f683aa1ab0a5238ee58f0376b0afa6f8..9ca741bd384d3edeef614228876cd70d69b0ff3d 100644 (file)
@@ -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);