aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/env.h4
-rw-r--r--include/minishell.h8
-rw-r--r--src/env.c2
-rw-r--r--src/interpreter.c89
-rw-r--r--src/main.c4
-rw-r--r--src/repl.c4
6 files changed, 11 insertions, 100 deletions
diff --git a/include/env.h b/include/env.h
index 1e6941d..a35bec3 100644
--- a/include/env.h
+++ b/include/env.h
@@ -6,7 +6,7 @@
/* By: chuhlig <chuhlig@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/08 16:53:39 by dkaiser #+# #+# */
-/* Updated: 2024/10/21 14:57:24 by dkaiser ### ########.fr */
+/* Updated: 2024/10/25 19:53:38 by chuhlig ### ########.fr */
/* */
/* ************************************************************************** */
@@ -22,4 +22,4 @@ typedef struct s_env
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); \ No newline at end of file
diff --git a/include/minishell.h b/include/minishell.h
index 6282ea6..b2a3845 100644
--- a/include/minishell.h
+++ b/include/minishell.h
@@ -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/21 15:00:05 by dkaiser ### ########.fr */
+/* Updated: 2024/10/25 16:10:21 by chuhlig ### ########.fr */
/* */
/* ************************************************************************** */
@@ -29,7 +29,7 @@
int init(void);
int init_signal_handling(void);
-void repl(const char *prompt, t_env *env);
+void repl(const char *prompt, t_env **env);
t_list *parse(t_token *tokens);
t_node *parse_cmd(t_token *tokens);
@@ -37,7 +37,7 @@ t_redirection *collect_redirs(t_token **tokens);
void print_ast(t_node *ast);
-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 --git a/src/env.c b/src/env.c
index ed93ec0..3110965 100644
--- a/src/env.c
+++ b/src/env.c
@@ -6,7 +6,7 @@
/* By: chuhlig <chuhlig@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/17 14:31:07 by chuhlig #+# #+# */
-/* Updated: 2024/10/21 15:07:51 by dkaiser ### ########.fr */
+/* Updated: 2024/10/25 19:17:54 by chuhlig ### ########.fr */
/* */
/* ************************************************************************** */
diff --git a/src/interpreter.c b/src/interpreter.c
index 458f2af..e69de29 100644
--- a/src/interpreter.c
+++ b/src/interpreter.c
@@ -1,89 +0,0 @@
-/* ************************************************************************** */
-/* */
-/* ::: :::::::: */
-/* interpreter.c :+: :+: :+: */
-/* +:+ +:+ +:+ */
-/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */
-/* +#+#+#+#+#+ +#+ */
-/* Created: 2024/08/05 13:15:24 by dkaiser #+# #+# */
-/* Updated: 2024/10/25 13:25:33 by dkaiser ### ########.fr */
-/* */
-/* ************************************************************************** */
-
-#include "debug_tools.h"
-#include "minishell.h"
-#include <stdlib.h>
-#include <sys/_types/_pid_t.h>
-#include <sys/cdefs.h>
-#include <sys/wait.h>
-#include <unistd.h>
-
-static int eval_rec(t_node *node, t_env *env, int in_fd);
-
-int eval(t_node *node, t_env *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
- {
- waitpid(pid, &result, 0);
- }
- return (result);
-}
-
-static int eval_rec(t_node *node, t_env *env, int in_fd)
-{
- pid_t pid;
- int result;
- int p[2];
-
- 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 --git a/src/main.c b/src/main.c
index c3e0ec7..18530bb 100644
--- a/src/main.c
+++ b/src/main.c
@@ -6,7 +6,7 @@
/* By: chuhlig <chuhlig@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/22 17:14:03 by dkaiser #+# #+# */
-/* Updated: 2024/10/21 15:02:56 by dkaiser ### ########.fr */
+/* Updated: 2024/10/25 16:06:32 by chuhlig ### ########.fr */
/* */
/* ************************************************************************** */
@@ -22,5 +22,5 @@ int main(int argc, char *argv[], char *envp[])
if (init())
return (1);
getenvlst(&env, envp);
- repl("Minishell $ ", env);
+ repl("Minishell $ ", &env);
}
diff --git a/src/repl.c b/src/repl.c
index 931e25e..9fae849 100644
--- a/src/repl.c
+++ b/src/repl.c
@@ -6,14 +6,14 @@
/* By: chuhlig <chuhlig@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/24 16:07:04 by dkaiser #+# #+# */
-/* Updated: 2024/10/17 15:25:48 by dkaiser ### ########.fr */
+/* Updated: 2024/10/22 17:05:14 by chuhlig ### ########.fr */
/* */
/* ************************************************************************** */
#include "../include/minishell.h"
#include "token.h"
-void repl(const char *prompt, t_env *env)
+void repl(const char *prompt, t_env **env)
{
char *input;
t_token *token_list;