diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-08-10 20:35:52 +0200 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-08-10 20:35:52 +0200 |
commit | 479176671b83f8edc366de87556104003fde880a (patch) | |
tree | 99338eb480e78f4e995d8f865733b69172e795e9 | |
parent | New TODO's (diff) | |
download | 42-minishell-479176671b83f8edc366de87556104003fde880a.tar.gz 42-minishell-479176671b83f8edc366de87556104003fde880a.tar.bz2 42-minishell-479176671b83f8edc366de87556104003fde880a.tar.xz 42-minishell-479176671b83f8edc366de87556104003fde880a.tar.zst 42-minishell-479176671b83f8edc366de87556104003fde880a.zip |
Okok
Diffstat (limited to '')
-rw-r--r-- | TODO.org | 2 | ||||
-rw-r--r-- | src/e_externs_pipes.c | 59 | ||||
-rw-r--r-- | src/e_pipes.c | 37 | ||||
-rw-r--r-- | src/s_lpipes.c | 4 |
4 files changed, 68 insertions, 34 deletions
@@ -2,6 +2,7 @@ ** DONE PWD=qwe; pwd <== recheck ** DONE VISUAL=qweqwe crontab -e <=== deal with it ** DONE cd qweqwe <=== stderr +** TODO lpipes leaks <=== this is a big one (split lpipes | lcom | com) ** TODO [#C] Handle memory * Stuff to add @@ -9,4 +10,5 @@ ** TODO [#A] Proper ~ subst ** TODO [#B] && || ** TODO [#B] & +** TODO [#C] $_ ** TODO [#C] Norm 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); */ } diff --git a/src/e_pipes.c b/src/e_pipes.c index 29ee5d4..223a467 100644 --- a/src/e_pipes.c +++ b/src/e_pipes.c @@ -19,31 +19,30 @@ #include "s_lpipes.h" #include "s_struct.h" -static uint8_t - get_builtin_id(const char com[], - t_msh *msh) -{ - uint8_t i; +/* 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); -} +/* 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); */ +/* } */ void e_pipes(t_lcom *ptr, t_msh *msh) { - uint8_t bu_id; + /* uint8_t bu_id; */ - if ((bu_id = get_builtin_id(ptr->pipes->one->com, msh)) - < FT_BUILTINS_COUNT) - e_builtin(ptr->pipes->one, bu_id, msh); - else - e_externs_pipes(ptr->pipes, msh); + /* if ((bu_id = get_builtin_id(ptr->pipes->one->com, msh)) */ + /* < FT_BUILTINS_COUNT) */ + /* e_builtin(ptr->pipes->one, bu_id, msh); */ + e_externs_pipes(ptr->pipes, msh); lpipes_clear(&ptr->pipes); } diff --git a/src/s_lpipes.c b/src/s_lpipes.c index cb78df3..69a6cc4 100644 --- a/src/s_lpipes.c +++ b/src/s_lpipes.c @@ -53,8 +53,8 @@ void while (tmp) { renext = tmp->next; - lcom_clear(&tmp->one); - ft_memdel((void*)&tmp); + /* lcom_clear(&tmp->one); */ + /* ft_memdel((void*)&tmp); */ tmp = renext; } *lpipes = NULL; |