]> git.dkaiser.de - 42/minishell.git/commitdiff
resolved merge conflicts
authorChristopher Uhlig <chuhlig@1-D-6.42heilbronn.de>
Fri, 25 Oct 2024 18:44:14 +0000 (20:44 +0200)
committerChristopher Uhlig <chuhlig@1-D-6.42heilbronn.de>
Fri, 25 Oct 2024 18:44:14 +0000 (20:44 +0200)
1  2 
include/env.h
include/minishell.h
src/env.c
src/interpreter.c
src/main.c

diff --cc include/env.h
index 3bf6bd6329334d4580796c88cc5ead1cb12af782,1e6941d08bd49279028aea61b374d727fd5a4dbf..a35bec37ebe176d0f49e43d512cfc8c93108fa5b
@@@ -6,7 -6,7 +6,7 @@@
  /*   By: chuhlig <chuhlig@student.42.fr>            +#+  +:+       +#+        */
  /*                                                +#+#+#+#+#+   +#+           */
  /*   Created: 2024/08/08 16:53:39 by dkaiser           #+#    #+#             */
- /*   Updated: 2024/10/17 17:08:01 by chuhlig          ###   ########.fr       */
 -/*   Updated: 2024/10/21 14:57:24 by dkaiser          ###   ########.fr       */
++/*   Updated: 2024/10/25 19:53:38 by chuhlig          ###   ########.fr       */
  /*                                                                            */
  /* ************************************************************************** */
  
@@@ -19,6 -19,7 +19,7 @@@ typedef struct s_en
        struct s_env    *next;
  }                                     t_env;
  
- void  getenvlst(t_env **env, char **en);
- void  free_envlst(t_env **env);
- char  *env_get(t_env *env, char *name);
+ void                          getenvlst(t_env **env, char **en);
+ void                          free_envlst(t_env **env);
+ char                          *env_get(t_env *env, char *name);
 -char                          **env_to_strlst(t_env *env);
++char                          **env_to_strlst(t_env *env);
index 7b6226e43292b7be869a9cd2bacd5d7e7ca55eda,6282ea6f35078782ade61abb639b82636600b76e..b2a3845dc46436652107396d4560a9c70196f3b2
@@@ -3,10 -3,10 +3,10 @@@
  /*                                                        :::      ::::::::   */
  /*   minishell.h                                        :+:      :+:    :+:   */
  /*                                                    +:+ +:+         +:+     */
 -/*   By: dkaiser <dkaiser@student.42heilbronn.de    +#+  +:+       +#+        */
 +/*   By: chuhlig <chuhlig@student.42.fr>            +#+  +:+       +#+        */
  /*                                                +#+#+#+#+#+   +#+           */
  /*   Created: 2024/06/22 17:14:49 by dkaiser           #+#    #+#             */
- /*   Updated: 2024/10/22 16:52:26 by chuhlig          ###   ########.fr       */
 -/*   Updated: 2024/10/21 15:00:05 by dkaiser          ###   ########.fr       */
++/*   Updated: 2024/10/25 16:10:21 by chuhlig          ###   ########.fr       */
  /*                                                                            */
  /* ************************************************************************** */
  
@@@ -37,5 -37,7 +37,7 @@@ t_redirection *collect_redirs(t_token *
  
  void                  print_ast(t_node *ast);
  
- int   eval(t_node *node, t_env **env);
 -int                           eval(t_node *node, t_env *env);
++int                           eval(t_node *node, t_env **env);
+ char                  *get_cmd_path(char *cmd, t_env *env);
+ int                           execute_cmd(t_cmd *cmd, t_env *env);
  #endif
diff --cc src/env.c
index ca07f9f94f0ce5051bce2c22d03f4a02f38cf985,ed93ec03d12f7a8c3ffaa6e2b050276d6ed982f8..31109653a4a0ebb4dda35f6565b4bb6782049bdd
+++ b/src/env.c
@@@ -6,7 -6,7 +6,7 @@@
  /*   By: chuhlig <chuhlig@student.42.fr>            +#+  +:+       +#+        */
  /*                                                +#+#+#+#+#+   +#+           */
  /*   Created: 2024/10/17 14:31:07 by chuhlig           #+#    #+#             */
- /*   Updated: 2024/10/25 15:48:56 by chuhlig          ###   ########.fr       */
 -/*   Updated: 2024/10/21 15:07:51 by dkaiser          ###   ########.fr       */
++/*   Updated: 2024/10/25 19:17:54 by chuhlig          ###   ########.fr       */
  /*                                                                            */
  /* ************************************************************************** */
  
index 13f10edc89e4f2ed7d3d85e606239ff06dfb5f35,458f2afe5560404a64320dbc427efcce8fd64ef2..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
@@@ -1,55 -1,89 +1,0 @@@
--/* ************************************************************************** */
--/*                                                                            */
--/*                                                        :::      ::::::::   */
--/*   interpreter.c                                      :+:      :+:    :+:   */
--/*                                                    +:+ +:+         +:+     */
- /*   By: chuhlig <chuhlig@student.42.fr>            +#+  +:+       +#+        */
 -/*   By: dkaiser <dkaiser@student.42heilbronn.de    +#+  +:+       +#+        */
--/*                                                +#+#+#+#+#+   +#+           */
--/*   Created: 2024/08/05 13:15:24 by dkaiser           #+#    #+#             */
- /*   Updated: 2024/10/25 15:46:53 by chuhlig          ###   ########.fr       */
 -/*   Updated: 2024/10/25 13:25:33 by dkaiser          ###   ########.fr       */
--/*                                                                            */
--/* ************************************************************************** */
--
 -#include "debug_tools.h"
--#include "minishell.h"
- #include <stdio.h>
 -#include <stdlib.h>
 -#include <sys/_types/_pid_t.h>
 -#include <sys/cdefs.h>
 -#include <sys/wait.h>
 -#include <unistd.h>
--
- static int    eval_pipe(t_pipe *pipe, t_env *env);
- static int    eval_cmd(t_cmd *cmd, t_env **env);
 -static int    eval_rec(t_node *node, t_env *env, int in_fd);
--
- 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));
-       else if (node->type == CMD_NODE)
-               return (eval_cmd(&node->content.cmd, env));
 -      pid_t   pid;
 -      int             result;
 -
 -      if (node == NULL)
 -              return (EXIT_FAILURE);
 -      result = 0;
 -      pid = fork();
 -      if (pid < 0)
 -      {
 -              return (EXIT_FAILURE);
 -      }
 -      if (pid == 0)
 -      {
 -              result = eval_rec(node, env, STDIN_FILENO);
 -              exit(result);
 -      }
--      else
--      {
-               panic(UNREACHABLE);
-               return (-1);
 -              waitpid(pid, &result, 0);
--      }
 -      return (result);
--}
--
- static int    eval_pipe(t_pipe *pipe, t_env *env)
 -static int    eval_rec(t_node *node, t_env *env, int in_fd)
--{
-       dbg("TODO: PIPE");
-       eval_cmd(&pipe->left->content.cmd, &env);
-       eval_cmd(&pipe->right->content.cmd, &env);
-       return (0);
- }
 -      pid_t   pid;
 -      int             result;
 -      int             p[2];
--
- static int    eval_cmd(t_cmd *cmd, t_env **env)
- {
-       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);
 -      result = pipe(p);
 -      if (result == -1)
 -              return (EXIT_FAILURE);
 -      if (node->type == PIPE_NODE)
 -      {
 -              pid = fork();
 -              if (pid < 0)
 -              {
 -                      return (EXIT_FAILURE);
 -              }
 -              if (pid == 0)
 -              {
 -                      close(p[0]);
 -                      dup2(in_fd, STDIN_FILENO);
 -                      dup2(p[1], STDOUT_FILENO);
 -                      result = execute_cmd(&node->content.pipe.left->content.cmd, env);
 -                      exit(result);
 -              }
 -              else
 -              {
 -                      close(p[1]);
 -                      dup2(p[0], STDIN_FILENO);
 -                      result = eval_rec(node->content.pipe.right, env, p[0]);
 -              }
 -      }
 -      else if (node->type == CMD_NODE)
 -      {
 -              result = execute_cmd(&node->content.cmd, env);
 -      }
 -      else
 -      {
 -              panic(UNREACHABLE);
 -              return (EXIT_FAILURE);
 -      }
 -      return (result);
--}
diff --cc src/main.c
index 3672fddb39909a3b3ee5481e08e014ba19094180,c3e0ec797f8267b897829ed662be834eb6cf3853..18530bbe14e76fca883c767212a094827d65f4c7
@@@ -6,7 -6,7 +6,7 @@@
  /*   By: chuhlig <chuhlig@student.42.fr>            +#+  +:+       +#+        */
  /*                                                +#+#+#+#+#+   +#+           */
  /*   Created: 2024/06/22 17:14:03 by dkaiser           #+#    #+#             */
- /*   Updated: 2024/10/25 15:53:10 by chuhlig          ###   ########.fr       */
 -/*   Updated: 2024/10/21 15:02:56 by dkaiser          ###   ########.fr       */
++/*   Updated: 2024/10/25 16:06:32 by chuhlig          ###   ########.fr       */
  /*                                                                            */
  /* ************************************************************************** */