From 477ea057edf32486e944ef4e33023e9ab6636e07 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Sat, 12 Sep 2020 15:07:22 +0200 Subject: Aliases work, fucker --- src/b_export_next.c | 11 +++++------ src/e_builtins.c | 3 ++- src/p_lblock_next.c | 13 ++++++++++--- src/s_com.c | 2 +- 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/b_export_next.c b/src/b_export_next.c index 059fbc6..1fc732e 100644 --- a/src/b_export_next.c +++ b/src/b_export_next.c @@ -13,6 +13,7 @@ #include #include +#include "d_define.h" #include "b_export_next.h" #include "f_fail.h" #include "s_lvars.h" @@ -21,8 +22,7 @@ #include "u_vars.h" static char - **b_get_var(const char arg[], - t_msh *msh) + **b_get_var(const char arg[], t_msh *msh) { size_t len; char **var; @@ -44,8 +44,7 @@ static char } static int64_t - b_is_it_in_env(const char varname[], - t_msh *msh) + b_is_it_in_env(const char varname[], t_msh *msh) { char **env_dup; size_t i; @@ -66,8 +65,7 @@ static int64_t } static void - b_add_to_env(const char arg[], - t_msh *msh) + b_add_to_env(const char arg[], t_msh *msh) { size_t i; char **nenvp; @@ -98,6 +96,7 @@ void char **var; int64_t env_i; + varval[0] = C_NUL; var = b_get_var(arg, msh); if ((env_i = b_is_it_in_env(var[FT_VAR_NAME] + 1, msh)) != -1) { diff --git a/src/e_builtins.c b/src/e_builtins.c index fb7b0ba..7c86a5f 100644 --- a/src/e_builtins.c +++ b/src/e_builtins.c @@ -21,6 +21,7 @@ #include "b_export_mute.h" #include "m_loop.h" #include "m_redirs.h" +#include "s_com.h" #include "s_destroy.h" #include "s_line.h" #include "s_struct.h" @@ -66,7 +67,6 @@ static void int32_t status; int32_t ret; - (void)ptr; while (wait(&status) != pid) ; ret = WEXITSTATUS(status); @@ -83,6 +83,7 @@ static void { if (msh->fd == STDIN_FILENO) m_dump_hist(msh); + s_com_destroy(&msh->com); s_line_clear(&msh->curr); s_destroy(msh); exit(ret); diff --git a/src/p_lblock_next.c b/src/p_lblock_next.c index 8b755da..707acc0 100644 --- a/src/p_lblock_next.c +++ b/src/p_lblock_next.c @@ -113,13 +113,13 @@ static t_bool void p_subst_alias(char word[], t_msh *msh) { - char *ptr; + char value[ARG_MAX]; char tmp[255]; size_t locat[2]; + char *ptr; t_bool good; t_quote_mode mode; - (void)msh; mode = Q_NONE; ptr = word; ptr = p_skip_whitespace(ptr); @@ -157,7 +157,14 @@ void ft_strlcpy(tmp, word + locat[0], ((locat[1] - locat[0] < 253) ? (locat[1] - locat[0]) : (254)) + 1); - ft_printf("(%s)\n", tmp); + if (u_get_alias_value(value, tmp, ARG_MAX, msh) != 0) + return ; + (void)ft_memmove(word + (locat[0] + ft_strlen(value)), + word + locat[1], + ft_strlen(word + locat[1]) + 1 * sizeof(char)); + (void)ft_memmove(word + locat[0], + value, + ft_strlen(value) * sizeof(char)); } } diff --git a/src/s_com.c b/src/s_com.c index b85905e..a5c594a 100644 --- a/src/s_com.c +++ b/src/s_com.c @@ -116,7 +116,7 @@ t_com ft_strlcpy(nword, word, ARG_MAX); if (p_get_redir(nword, &com) != 0) return (NULL); - /* if (msh->alias != NULL) */ + if (msh->alias != NULL) p_subst_alias(nword, msh); p_subst_vars(nword, msh); if ((words = p_split_args(nword, com->redir)) == NULL) -- cgit v1.2.3