From 598c360d22fa9b3c863f74bb6280472fd805fa0d Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Mon, 17 Aug 2020 18:12:18 +0200 Subject: Fixed unset not working --- TODO.org | 6 ++++-- src/b_cd.c | 15 +++++---------- src/e_builtins.c | 2 ++ src/p_lcom_next.c | 22 ++++++++++++++++++++++ src/p_lcom_next.h | 1 + src/s_com.c | 2 ++ 6 files changed, 36 insertions(+), 12 deletions(-) diff --git a/TODO.org b/TODO.org index 0784155..f984b02 100644 --- a/TODO.org +++ b/TODO.org @@ -3,10 +3,12 @@ ** DONE VISUAL=qweqwe crontab -e <=== deal with it ** DONE cd qweqwe <=== stderr ** DONE [#A] lpipes leaks <=== this is a big one (split lpipes | lcom | com) +** DONE [#B] forked write(2) stuff on cd ** TODO [#C] fix that goddamn exit(2) 25 leak ** TODO [#C] lpipes leaks on builtins (same as above man) ** TODO [#C] Handle memory ** TODO [#C] Go full stack to ken dash in the ass +** TODO [#C] ./qwe.sh <=== handle bad shebang * Stuff to add ** DONE [#A] builtins to pipes @@ -14,8 +16,8 @@ ** DONE [#B] && || ** TODO [#B] & ** TODO [#B] $_ +** TODO [#B] .minishellrc +** TODO [#B] .minishell_history ** TODO [#C] Norm ** TODO [#C] [ builtin <=== pretty cool yet simple stuff ( [ $a -eq 1 ] ) ** DONE [#C] Read scripts -** TODO [#B] .minishellrc -** TODO [#B] .minishell_history diff --git a/src/b_cd.c b/src/b_cd.c index 2248a89..d2b1042 100644 --- a/src/b_cd.c +++ b/src/b_cd.c @@ -32,14 +32,6 @@ static void { f_alloc_and_destroy_msh(msh); } - if (ft_strncmp("~/", *path, 2) == 0 || !ft_strncmp("~", *path, 2)) - { - if (!(*path = ft_strsubst(*path, - "~", u_get_var_value("$HOME", msh)))) - { - f_alloc_and_destroy_msh(msh); - } - } } static void @@ -142,8 +134,11 @@ uint8_t } else if (argc == 0) { - if (!(path = u_get_var_value("$HOME", msh))) - return (1); + if ((path = u_get_var_value("$HOME", msh)) == NULL) + { + ft_dprintf(STDERR_FILENO, "minishell: cd: HOME not set\n"); + return (2); + } } else set_path(&path, args, msh); diff --git a/src/e_builtins.c b/src/e_builtins.c index c00114d..e1dbfbb 100644 --- a/src/e_builtins.c +++ b/src/e_builtins.c @@ -71,6 +71,8 @@ static void msh->bu_ptr[bu_id](ptr->argv + 1, msh); else if (bu_id == FT_ID_EXPORT) b_export_mute(ptr->argv + 1, msh); + else if (bu_id == FT_ID_UNSET) + msh->bu_ptr[bu_id](ptr->argv + 1, msh); else if (bu_id == FT_ID_EXIT && ret == 0) { s_line_clear(&msh->curr); diff --git a/src/p_lcom_next.c b/src/p_lcom_next.c index 3f18ec1..b04d393 100644 --- a/src/p_lcom_next.c +++ b/src/p_lcom_next.c @@ -101,6 +101,28 @@ char return (words); } +char + **p_subst_home(char *words[], + t_msh *msh) +{ + char *path; + char **ptr; + + if ((path = u_get_var_value("$HOME", msh)) == NULL) + return (words); + ptr = words; + while (*ptr != NULL) + { + if (*ptr[0] == '~') + { + *ptr = ft_strsubst(*ptr, "~", path); + } + ptr++; + } + ft_memdel((void*)&path); + return (words); +} + static void p_register_word(char word[], t_msh *msh) diff --git a/src/p_lcom_next.h b/src/p_lcom_next.h index f9ae416..dea86bd 100644 --- a/src/p_lcom_next.h +++ b/src/p_lcom_next.h @@ -19,6 +19,7 @@ char **p_subst_vars(char *words[], t_msh *msh); char **p_subst_args(const char word[], int8_t redir); +char **p_subst_home(char *word[], t_msh *msh); char **p_check_args_equals(char *words[], t_msh *msh); #endif diff --git a/src/s_com.c b/src/s_com.c index 1bde96c..550616c 100644 --- a/src/s_com.c +++ b/src/s_com.c @@ -117,6 +117,8 @@ t_com return (NULL); if ((words = p_subst_vars(words, msh)) == NULL) return (NULL); + if ((words = p_subst_home(words, msh)) == NULL) + return (NULL); words = p_check_args_equals(words, msh); if (msh->env_fork_tmp[0][0] != '\0') com_cpy_env_fork(&com, msh); -- cgit v1.2.3