aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDominik Kaiser2024-10-17 16:06:53 +0200
committerDominik Kaiser2024-10-17 16:06:53 +0200
commite7faa6525a007e463c06a20e438a2253287011f1 (patch)
treee187b2fd0bebf7d0b10a6d5cc74d1edc9b9f3a73 /src
parent08f6e0bf8c5d3ebc7fb9b61f9913369cfdbebae2 (diff)
downloadminishell-e7faa6525a007e463c06a20e438a2253287011f1.tar.gz
minishell-e7faa6525a007e463c06a20e438a2253287011f1.zip
yes
Diffstat (limited to 'src')
-rw-r--r--src/env.c19
-rw-r--r--src/interpreter.c21
-rw-r--r--src/main.c10
-rw-r--r--src/repl.c7
4 files changed, 41 insertions, 16 deletions
diff --git a/src/env.c b/src/env.c
index 8105bf4..77ba483 100644
--- a/src/env.c
+++ b/src/env.c
@@ -6,11 +6,13 @@
/* By: chuhlig <chuhlig@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/17 14:31:07 by chuhlig #+# #+# */
-/* Updated: 2024/10/17 15:18:44 by chuhlig ### ########.fr */
+/* Updated: 2024/10/17 15:58:28 by dkaiser ### ########.fr */
/* */
/* ************************************************************************** */
#include "env.h"
+#include "get_next_line.h"
+#include "libft.h"
void getenvlst(t_env **env, char **en)
{
@@ -22,7 +24,7 @@ void getenvlst(t_env **env, char **en)
while (en[i] != NULL)
{
tmp = ft_strchr(en[i], '=');
- tmp = '\0';
+ *tmp = '\0';
current = *env;
current = malloc(sizeof(t_env));
current->name = ft_strdup(en[i]);
@@ -47,4 +49,15 @@ void free_envlst(t_env **env)
free(cur);
cur = new;
}
-} \ No newline at end of file
+}
+
+char *env_get(t_env *env, char *name)
+{
+ while (env != NULL)
+ {
+ if (!ft_strncmp(env->name, name, ft_strlen(name)))
+ return (env->value);
+ env = env->next;
+ }
+ return (NULL);
+}
diff --git a/src/interpreter.c b/src/interpreter.c
index 2a09e6d..abaeb47 100644
--- a/src/interpreter.c
+++ b/src/interpreter.c
@@ -6,21 +6,21 @@
/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/05 13:15:24 by dkaiser #+# #+# */
-/* Updated: 2024/08/05 13:33:16 by dkaiser ### ########.fr */
+/* Updated: 2024/10/17 16:01:23 by dkaiser ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
-static int eval_pipe(t_pipe *pipe);
-static int eval_cmd(t_cmd *cmd);
+static int eval_pipe(t_pipe *pipe, t_env *env);
+static int eval_cmd(t_cmd *cmd, t_env *env);
-int eval(t_node *node)
+int eval(t_node *node, t_env *env)
{
if (node->type == PIPE_NODE)
- return (eval_pipe(&node->content.pipe));
+ return (eval_pipe(&node->content.pipe, env));
else if (node->type == CMD_NODE)
- return (eval_cmd(&node->content.cmd));
+ return (eval_cmd(&node->content.cmd, env));
else
{
panic(UNREACHABLE);
@@ -28,12 +28,17 @@ int eval(t_node *node)
}
}
-static int eval_pipe(t_pipe *pipe)
+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);
return (0);
}
-static int eval_cmd(t_cmd *cmd)
+static int eval_cmd(t_cmd *cmd, t_env *env)
{
+ printf("%s\n", cmd->args[0]);
+ printf("PATH=%s\n", env_get(env, "PATH"));
return (0);
}
diff --git a/src/main.c b/src/main.c
index 8523b9e..64bc312 100644
--- a/src/main.c
+++ b/src/main.c
@@ -6,15 +6,19 @@
/* By: chuhlig <chuhlig@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/22 17:14:03 by dkaiser #+# #+# */
-/* Updated: 2024/07/18 16:44:14 by chuhlig ### ########.fr */
+/* Updated: 2024/10/17 15:34:02 by dkaiser ### ########.fr */
/* */
/* ************************************************************************** */
#include "../include/minishell.h"
-int main(void)
+int main(int argc, char *argv[], char *envp[])
{
+ t_env *env;
+ if (!argc && !argv)
+ return (1);
if (init())
return (1);
- repl("Minishell $ ");
+ getenvlst(&env, envp);
+ repl("Minishell $ ", env);
}
diff --git a/src/repl.c b/src/repl.c
index d590fec..931e25e 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/09/13 16:26:35 by dkaiser ### ########.fr */
+/* Updated: 2024/10/17 15:25:48 by dkaiser ### ########.fr */
/* */
/* ************************************************************************** */
#include "../include/minishell.h"
#include "token.h"
-void repl(const char *prompt)
+void repl(const char *prompt, t_env *env)
{
char *input;
t_token *token_list;
@@ -31,7 +31,10 @@ void repl(const char *prompt)
tokenizer(input, &token_list, '\0');
lines = parse(token_list);
if (lines)
+ {
print_ast(lines->content);
+ eval(lines->content, env);
+ }
free(input);
}
}