From 26debd1a134bfe6b4b400136c75b30d368a39252 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Tue, 28 Apr 2020 14:45:38 +0200 Subject: Ok cd --- src/ft_e_builtins.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/ft_e_builtins.c') diff --git a/src/ft_e_builtins.c b/src/ft_e_builtins.c index bc3eece..1045856 100644 --- a/src/ft_e_builtins.c +++ b/src/ft_e_builtins.c @@ -16,6 +16,7 @@ #include #include +#include "ft_b_builtins.h" #include "ft_m_redirs.h" #include "ft_s_destroy.h" #include "ft_s_lcom.h" @@ -37,6 +38,8 @@ static void static void ft_e_builtin_parent(pid_t pid, + const t_lcom *ptr, + uint8_t bu_id, t_msh *msh) { int32_t status; @@ -44,6 +47,10 @@ static void while (wait(&status) != pid) ; msh->ret = WEXITSTATUS(status); + if (bu_id == 1 && msh->ret == 0) + { + ft_b_cd(ptr->argv + 1, msh); + } } void @@ -64,6 +71,6 @@ void } else { - ft_e_builtin_parent(pid, msh); + ft_e_builtin_parent(pid, ptr, bu_id, msh); } } -- cgit v1.2.3 From abec91e56b179d9d327da2d3d9ae960f5260e14f Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Tue, 28 Apr 2020 15:09:25 +0200 Subject: Nice functional cd --- src/ft_e_builtins.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/ft_e_builtins.c') diff --git a/src/ft_e_builtins.c b/src/ft_e_builtins.c index 1045856..c78a80c 100644 --- a/src/ft_e_builtins.c +++ b/src/ft_e_builtins.c @@ -16,7 +16,6 @@ #include #include -#include "ft_b_builtins.h" #include "ft_m_redirs.h" #include "ft_s_destroy.h" #include "ft_s_lcom.h" @@ -49,8 +48,11 @@ static void msh->ret = WEXITSTATUS(status); if (bu_id == 1 && msh->ret == 0) { - ft_b_cd(ptr->argv + 1, msh); + msh->bu_ptr[bu_id](ptr->argv + 1, msh); + /* TODO: export $PWD */ } + else if (bu_id == 6) + msh->bu_ptr[bu_id](ptr->argv + 1, msh); } void -- cgit v1.2.3 From 86b25977265727217ec3360c3dc19b74f2bd448f Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Tue, 28 Apr 2020 15:49:58 +0200 Subject: exit is fine --- src/ft_e_builtins.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'src/ft_e_builtins.c') diff --git a/src/ft_e_builtins.c b/src/ft_e_builtins.c index c78a80c..382f85d 100644 --- a/src/ft_e_builtins.c +++ b/src/ft_e_builtins.c @@ -42,17 +42,28 @@ static void t_msh *msh) { int32_t status; + int32_t ret; while (wait(&status) != pid) ; - msh->ret = WEXITSTATUS(status); + ret = WEXITSTATUS(status); + if (bu_id != 6) + msh->ret = ret; if (bu_id == 1 && msh->ret == 0) { msh->bu_ptr[bu_id](ptr->argv + 1, msh); /* TODO: export $PWD */ } - else if (bu_id == 6) - msh->bu_ptr[bu_id](ptr->argv + 1, msh); + else if (bu_id == 6 && ret == 0) + { + if (ptr->argv[1]) + ret = ft_atoi(ptr->argv[1]); + else + ret = msh->ret; + ft_lcom_clear(&msh->curr); + ft_s_destroy(msh); + exit(ret); + } } void -- cgit v1.2.3