]> git.dkaiser.de - 42/minishell.git/commitdiff
adjuste input parameter for builtins
authorChristopher Uhlig <chuhlig@1-D-6.42heilbronn.de>
Fri, 25 Oct 2024 13:56:05 +0000 (15:56 +0200)
committerChristopher Uhlig <chuhlig@1-D-6.42heilbronn.de>
Fri, 25 Oct 2024 13:56:05 +0000 (15:56 +0200)
src/interpreter.c

index abaeb474e157cf9b472399a073aced9563e2af2f..13f10edc89e4f2ed7d3d85e606239ff06dfb5f35 100644 (file)
@@ -3,22 +3,23 @@
 /*                                                        :::      ::::::::   */
 /*   interpreter.c                                      :+:      :+:    :+:   */
 /*                                                    +:+ +:+         +:+     */
-/*   By: dkaiser <dkaiser@student.42heilbronn.de    +#+  +:+       +#+        */
+/*   By: chuhlig <chuhlig@student.42.fr>            +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2024/08/05 13:15:24 by dkaiser           #+#    #+#             */
-/*   Updated: 2024/10/17 16:01:23 by dkaiser          ###   ########.fr       */
+/*   Updated: 2024/10/25 15:46:53 by chuhlig          ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
 #include "minishell.h"
+#include <stdio.h>
 
 static int     eval_pipe(t_pipe *pipe, t_env *env);
-static int     eval_cmd(t_cmd *cmd, t_env *env);
+static int     eval_cmd(t_cmd *cmd, t_env **env);
 
-int    eval(t_node *node, t_env *env)
+int    eval(t_node *node, t_env **env)
 {
        if (node->type == PIPE_NODE)
-               return (eval_pipe(&node->content.pipe, env));
+               return (eval_pipe(&node->content.pipe, *env));
        else if (node->type == CMD_NODE)
                return (eval_cmd(&node->content.cmd, env));
        else
@@ -31,14 +32,24 @@ int eval(t_node *node, t_env *env)
 static int     eval_pipe(t_pipe *pipe, t_env *env)
 {
        dbg("TODO: PIPE");
-       eval_cmd(&pipe->left->content.cmd, env);
-       eval_cmd(&pipe->right->content.cmd, env);
+       eval_cmd(&pipe->left->content.cmd, &env);
+       eval_cmd(&pipe->right->content.cmd, &env);
        return (0);
 }
 
-static int     eval_cmd(t_cmd *cmd, t_env *env)
+static int     eval_cmd(t_cmd *cmd, t_env **env)
 {
-       printf("%s\n", cmd->args[0]);
-       printf("PATH=%s\n", env_get(env, "PATH"));
+       if (ft_strncmp(cmd->args[0], "pwd", 4) == 0)
+               pwd(*env);
+       else if (ft_strncmp(cmd->args[0], "echo", 5) == 0)
+               echo(cmd->args);
+       else if (ft_strncmp(cmd->args[0], "env", 4) == 0)
+               ft_env(*env);
+       else if (ft_strncmp(cmd->args[0], "cd", 3) == 0)
+               cd(env, cmd->args);
+       else if (ft_strncmp(cmd->args[0], "unset", 6) == 0)
+               unset(cmd->args, env);
+       else if (ft_strncmp(cmd->args[0], "export", 7) == 0)
+               export(cmd->args, env);
        return (0);
 }