diff options
| author | Dominik Kaiser | 2025-01-20 20:14:32 +0100 |
|---|---|---|
| committer | GitHub | 2025-01-20 20:14:32 +0100 |
| commit | bd8c817797d5f2b1affe6957ffc51846a38e70ec (patch) | |
| tree | 2fc0f567b1c4f2f168a931ad0bff69e52c6c226c /src/builtins_part_two.c | |
| parent | a9aba07b52cbf98eb9c52cd8ee0cd5f5021d2931 (diff) | |
| parent | dc6a4f2d0de92984c2584ef905011e2a60792850 (diff) | |
| download | minishell-bd8c817797d5f2b1affe6957ffc51846a38e70ec.tar.gz minishell-bd8c817797d5f2b1affe6957ffc51846a38e70ec.zip | |
Merge interpreter changes into main
Miau
Diffstat (limited to 'src/builtins_part_two.c')
| -rw-r--r-- | src/builtins_part_two.c | 55 |
1 files changed, 44 insertions, 11 deletions
diff --git a/src/builtins_part_two.c b/src/builtins_part_two.c index 94ef258..e461861 100644 --- a/src/builtins_part_two.c +++ b/src/builtins_part_two.c @@ -6,7 +6,7 @@ /* By: chuhlig <chuhlig@student.42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/25 20:52:16 by chuhlig #+# #+# */ -/* Updated: 2024/10/25 20:52:46 by chuhlig ### ########.fr */ +/* Updated: 2025/01/20 19:12:33 by chuhlig ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,6 +19,8 @@ void update_oldpwd(t_env **env) char cwd[1028]; char *tmp; + prev = NULL; + current = *env; while (current) { if (ft_strncmp(current->name, "OLDPWD", 6) == 0) @@ -39,6 +41,8 @@ void update_pwd(t_env **env) char cwd[1028]; char *tmp; + prev = NULL; + current = *env; while (current) { if (ft_strncmp(current->name, "PWD", 3) == 0) @@ -55,28 +59,57 @@ void update_pwd(t_env **env) int cd(t_env **env, char **av) { t_env *current; - t_env *prev; - t_env *pwd; - current = env; + current = *env; if (av[1] == NULL) { - update_oldpwd(&env); + update_oldpwd(env); while (current) { if (ft_strncmp(current->name, "HOME", 4) == 0) break ; - prev = current; current = current->next; } if (chdir(current->value) == -1) - return ; + return (1); + update_pwd(env); } else { - update_oldpwd(&env); + update_oldpwd(env); if (chdir(av[1]) == -1) - return ; - update_pwd(&env); + return (1); + update_pwd(env); + } + return (0); +} + +int pwd(t_env *env) +{ + while (env) + { + if (ft_strncmp(env->name, "PWD", 4) == 0) + { + ft_printf("%s\n", env->value); + break ; + } + env = env->next; } -}
\ No newline at end of file + return (0); +} + +int ft_env(t_env *env) +{ + while (env != NULL) + { + if (ft_strchr(env->name, '?')) + { + env = env->next; + continue ; + } + printf("%s", env->name); + printf("=%s\n", env->value); + env = env->next; + } + return (0); +} |
