diff options
Diffstat (limited to '')
-rw-r--r-- | src/b_exit.c | 2 | ||||
-rw-r--r-- | src/d_define.h | 1 | ||||
-rw-r--r-- | src/d_enum.h | 13 | ||||
-rw-r--r-- | src/e_builtins.c | 117 | ||||
-rw-r--r-- | src/m_minishell.c | 1 |
5 files changed, 77 insertions, 57 deletions
diff --git a/src/b_exit.c b/src/b_exit.c index 75f16bf..777bbb9 100644 --- a/src/b_exit.c +++ b/src/b_exit.c @@ -28,6 +28,7 @@ uint8_t uint8_t ret; const uint64_t argc = get_argc((const char**)args); + ret = 0; if (argc > 1) { fail_too_many_args("exit", msh); @@ -39,5 +40,6 @@ uint8_t /* TODO: non numeric args[0] */ } ft_dprintf(STDERR_FILENO, "exit\n"); + exit(ret); return (0); } diff --git a/src/d_define.h b/src/d_define.h index 175e256..6f93751 100644 --- a/src/d_define.h +++ b/src/d_define.h @@ -21,7 +21,6 @@ #define FT_PS_ONE "minishell ~> " #define FT_BUILTINS "echo|cd|pwd|export|unset|env|exit|type" -#define FT_BUILTINS_COUNT 8 #define FT_HISTFILE "minishell_history" /* diff --git a/src/d_enum.h b/src/d_enum.h index 427e0a0..ec35ca3 100644 --- a/src/d_enum.h +++ b/src/d_enum.h @@ -38,4 +38,17 @@ enum FT_READ_END }; +enum +{ + FT_ID_ECHO, + FT_ID_CD, + FT_ID_PWD, + FT_ID_EXPORT, + FT_ID_UNSET, + FT_ID_ENV, + FT_ID_EXIT, + FT_ID_TYPE, + FT_BUILTINS_COUNT +}; + #endif diff --git a/src/e_builtins.c b/src/e_builtins.c index e35416a..ca512a3 100644 --- a/src/e_builtins.c +++ b/src/e_builtins.c @@ -21,69 +21,76 @@ #include "s_lcom.h" #include "s_struct.h" -static void - e_builtin_child(const t_lcom *ptr, - uint8_t bu_id, - t_msh *msh) -{ - int32_t ret; +/* static void */ +/* e_builtin_child(const t_lcom *ptr, */ +/* uint8_t bu_id, */ +/* t_msh *msh) */ +/* { */ +/* int32_t ret; */ - dup_redirs(ptr, msh); - ret = msh->bu_ptr[bu_id](ptr->argv + 1, msh); - lcom_clear(&msh->curr); - s_destroy(msh); - exit(ret); -} +/* dup_redirs(ptr, msh); */ +/* ret = msh->bu_ptr[bu_id](ptr->argv + 1, msh); */ +/* lcom_clear(&msh->curr); */ +/* s_destroy(msh); */ +/* exit(ret); */ +/* } */ -static void - e_builtin_parent(pid_t pid, - const t_lcom *ptr, - uint8_t bu_id, - t_msh *msh) -{ - int32_t status; - int32_t ret; +/* static void */ +/* e_builtin_parent(pid_t pid, */ +/* const t_lcom *ptr, */ +/* uint8_t bu_id, */ +/* t_msh *msh) */ +/* { */ +/* int32_t status; */ +/* int32_t ret; */ - while (wait(&status) != pid) - ; - 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 && ret == 0) - { - if (ptr->argv[1]) - ret = ft_atoi(ptr->argv[1]); - else - ret = msh->ret; - lcom_clear(&msh->curr); - s_destroy(msh); - exit(ret); - } -} +/* while (wait(&status) != pid) */ +/* ; */ +/* ret = WEXITSTATUS(status); */ +/* if (bu_id != FT_ID_EXIT) */ +/* msh->ret = ret; */ +/* if (bu_id == FT_ID_CD && msh->ret == 0) */ +/* { */ +/* msh->bu_ptr[bu_id](ptr->argv + 1, msh); */ +/* /\* TODO: export $PWD *\/ */ +/* } */ +/* else if (bu_id == FT_ID_EXIT && ret == 0) */ +/* { */ +/* if (ptr->argv[1]) */ +/* ret = ft_atoi(ptr->argv[1]); */ +/* else */ +/* ret = msh->ret; */ +/* lcom_clear(&msh->curr); */ +/* s_destroy(msh); */ +/* exit(ret); */ +/* } */ +/* } */ void e_builtin(const t_lcom *ptr, uint8_t bu_id, t_msh *msh) { - pid_t pid; + int32_t ret; + + dup_redirs(ptr, msh); + ret = msh->bu_ptr[bu_id](ptr->argv + 1, msh); + lcom_clear(&msh->curr); + msh->ret = ret; + /* pid_t pid; */ - /* TODO: find a way to handle exit | bu_id = 6 */ - if ((pid = fork()) == 0) - { - e_builtin_child(ptr, bu_id, msh); - } - else if (pid < 0) - { - /* TODO: handle fork failed */ - } - else - { - e_builtin_parent(pid, ptr, bu_id, msh); - } + /* /\* TODO: find a way to handle exit | bu_id = 6 *\/ */ + /* e_builtin_child(ptr, bu_id, msh); */ + /* if ((pid = fork()) == 0) */ + /* { */ + /* e_builtin_child(ptr, bu_id, msh); */ + /* } */ + /* else if (pid < 0) */ + /* { */ + /* /\* TODO: handle fork failed *\/ */ + /* } */ + /* else */ + /* { */ + /* e_builtin_parent(pid, ptr, bu_id, msh); */ + /* } */ } diff --git a/src/m_minishell.c b/src/m_minishell.c index 66426b7..78700a1 100644 --- a/src/m_minishell.c +++ b/src/m_minishell.c @@ -40,7 +40,6 @@ int ft_dprintf(2, "%s\n", strerror(errno)); return (FT_RET_ALLOC); } - /* TODO: DELET THIS */ ret = m_argv(argc, argv, msh); s_destroy(msh); return (ret); |