diff options
Diffstat (limited to '')
-rw-r--r-- | src/e_externs_pipes.c | 59 |
1 files changed, 46 insertions, 13 deletions
diff --git a/src/e_externs_pipes.c b/src/e_externs_pipes.c index c9f677f..02978db 100644 --- a/src/e_externs_pipes.c +++ b/src/e_externs_pipes.c @@ -24,15 +24,41 @@ #include "m_redirs.h" #include "s_destroy.h" #include "s_lcom.h" +#include "s_lpipes.h" #include "s_struct.h" +static uint8_t + get_builtin_id(const char com[], + t_msh *msh) +{ + uint8_t i; + + i = 0; + while (msh->bu_ref[i] && ft_strncmp(com, msh->bu_ref[i], + ft_strlen(msh->bu_ref[i]) + 1) != 0) + { + i++; + } + return (i); +} + static void e_extern_child(const char *fullpath, t_lcom *ptr, t_msh *msh) { + uint8_t bu_id; + uint8_t ret; + dup_redirs(ptr, msh); - execve(fullpath, ptr->argv, msh->envp); + if (ft_strncmp(fullpath, "builtin", 8) == 0) + { + bu_id = get_builtin_id(ptr->com, msh); + ret = msh->bu_ptr[bu_id](ptr->argv + 1, msh); + exit(ret); + } + else + execve(fullpath, ptr->argv, msh->envp); /* TODO: handle execve failed */ } @@ -57,12 +83,12 @@ static void struct s_lpipes *head, t_msh *msh) { - size_t pipes; - size_t i; - size_t j; - int fd[256][2]; - int pid; - int status; + size_t pipes; + size_t i; + size_t j; + int fd[256][2]; + int pid; + int status; /* TODO: norm, error mgmnt */ pipes = e_get_pipes_count(head); @@ -100,9 +126,6 @@ static void close(fd[i][FT_READ_END]); i++; } - /* while (wait(&status) != pid) */ - /* ; */ - /* msh->ret = WEXITSTATUS(status); */ waitpid(pid, &status, 0); msh->ret = WEXITSTATUS(status); } @@ -112,14 +135,17 @@ void t_msh *msh) { struct s_lpipes *head; + /* struct s_lpipes *head_del; */ struct s_lpipes *rptr; char **envpath; char **fullpath; size_t i; size_t pipes; + uint8_t bu_id; head = ptr; rptr = ptr; + /* head_del = ptr; */ pipes = e_get_pipes_count(head); if (!(fullpath = (char **)malloc((pipes + 2) * sizeof(char *)))) f_alloc_and_destroy_msh(msh); @@ -129,19 +155,26 @@ void { if (ft_ischarset("/.", rptr->one->com[0])) { - if (!(fullpath[i] = ft_strdup(rptr->one->com))) + if ((fullpath[i] = ft_strdup(rptr->one->com)) == NULL) f_alloc_and_destroy_msh(msh); } else if ((envpath = get_env_path(msh)) != NULL) { - fullpath[i] = search_in_path(rptr->one->com, envpath, msh); + if ((bu_id = get_builtin_id(rptr->one->com, msh)) + < FT_BUILTINS_COUNT) + { + if ((fullpath[i] = ft_strdup("builtin")) == NULL) + f_alloc_and_destroy_msh(msh); + } + else + fullpath[i] = search_in_path(rptr->one->com, envpath, msh); ft_delwords(envpath); } - /* TODO: deal if not found etc */ i++; rptr = rptr->next; } i = 0; exec_path((const char**)fullpath, head, msh); ft_delwords(fullpath); + /* lpipes_clear(&head_del); */ } |