diff options
Diffstat (limited to 'src/m_prompt.c')
-rw-r--r-- | src/m_prompt.c | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/src/m_prompt.c b/src/m_prompt.c index a7c257d..94381c3 100644 --- a/src/m_prompt.c +++ b/src/m_prompt.c @@ -20,8 +20,7 @@ #include "s_struct.h" #include "u_vars.h" -static char - *m_subst_prompt_rice(char var[], t_msh *msh) +static void m_subst_prompt_rice(char var[], t_msh *msh) { char tmp[PATH_MAX]; size_t i; @@ -82,16 +81,25 @@ static char else if (var[i + 1] == '?') { ft_uitoa_s(tmp, msh->ret); - ft_strsubst_s(var, "\\?", tmp); + if (var[i + 2] == '!') + { + if (tmp[0] != '0') + ft_strsubst_s(var, "\\?!", tmp); + else + { + (void)ft_memmove(var + i, var + i + 3, (ft_strlen(var + i + 3) + 1) * sizeof(char)); + i -= 1; + } + } + else + ft_strsubst_s(var, "\\?", tmp); } } i++; } - return (var); } -static void - m_update_psx(uint8_t x, t_msh *msh) +static void m_update_psx(uint8_t x, t_msh *msh) { char var[ARG_MAX]; char psx[5]; @@ -107,8 +115,7 @@ static void ft_strlcpy(msh->ps[x - 1], var, 255); } -void - m_prompt_psx(uint8_t x, t_msh *msh) +void m_prompt_psx(uint8_t x, t_msh *msh) { m_update_psx(x, msh); ft_dprintf(STDERR_FILENO, "%s", msh->ps[x - 1]); |