summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-09-19 15:52:21 +0200
committerJozanLeClerc <bousset.rudy@gmail.com>2020-09-19 15:52:21 +0200
commite68ab8b48e10346c03643665bb19d65acc1505ee (patch)
treedb09513f0cbd712fdbac3d243fcc5eba567a15d5 /src
parentNew prompt stuff, huge fix (diff)
download42-minishell-e68ab8b48e10346c03643665bb19d65acc1505ee.tar.gz
42-minishell-e68ab8b48e10346c03643665bb19d65acc1505ee.tar.bz2
42-minishell-e68ab8b48e10346c03643665bb19d65acc1505ee.tar.xz
42-minishell-e68ab8b48e10346c03643665bb19d65acc1505ee.tar.zst
42-minishell-e68ab8b48e10346c03643665bb19d65acc1505ee.zip
Prompt stuff
Diffstat (limited to 'src')
-rw-r--r--src/m_prompt.c23
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]);