summaryrefslogtreecommitdiffstats
path: root/src/m_prompt.c
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-09-06 21:56:20 +0200
committerJozanLeClerc <bousset.rudy@gmail.com>2020-09-06 21:56:20 +0200
commit4543c3ba3222d47780ad3e091cfe6f3098cc2bca (patch)
treefb8a70bf05464a6fa2c820cc43ea34421340c903 /src/m_prompt.c
parentCommit from minishell (diff)
download42-minishell-4543c3ba3222d47780ad3e091cfe6f3098cc2bca.tar.gz
42-minishell-4543c3ba3222d47780ad3e091cfe6f3098cc2bca.tar.bz2
42-minishell-4543c3ba3222d47780ad3e091cfe6f3098cc2bca.tar.xz
42-minishell-4543c3ba3222d47780ad3e091cfe6f3098cc2bca.tar.zst
42-minishell-4543c3ba3222d47780ad3e091cfe6f3098cc2bca.zip
Stacked
Diffstat (limited to 'src/m_prompt.c')
-rw-r--r--src/m_prompt.c32
1 files changed, 13 insertions, 19 deletions
diff --git a/src/m_prompt.c b/src/m_prompt.c
index 1ea8d70..d0269e4 100644
--- a/src/m_prompt.c
+++ b/src/m_prompt.c
@@ -13,6 +13,7 @@
#include <libft.h>
#include <stdint.h>
#include <unistd.h>
+#include <limits.h>
#include "d_define.h"
#include "m_prompt.h"
@@ -20,12 +21,11 @@
#include "u_vars.h"
static char
- *m_subst_prompt_rice(char var[],
- t_msh *msh)
+ *m_subst_prompt_rice(char var[], t_msh *msh)
{
+ char tmp[PATH_MAX];
size_t i;
size_t j;
- char *tmp;
i = 0;
while (var[i] != '\0')
@@ -34,19 +34,16 @@ static char
{
if (var[i + 1] == 'w')
{
- tmp = u_get_var_value("$PWD", msh);
- if (tmp != NULL)
- {
+ u_get_var_value(tmp, "$PWD", PATH_MAX, msh);
+ if (tmp[0] != C_NUL)
var = ft_strsubst(var, "\\w", tmp);
- ft_memdel((void*)&tmp);
- }
else
var = ft_strsubst(var, "\\w", "?");
}
else if (var[i + 1] == 'W')
{
- tmp = u_get_var_value("$PWD", msh);
- if (tmp != NULL)
+ u_get_var_value(tmp, "$PWD", PATH_MAX, msh);
+ if (tmp[0] != C_NUL)
{
j = ft_strlen(tmp);
if (j > 1)
@@ -58,7 +55,6 @@ static char
((ft_strlen(tmp) - j) + 1) * sizeof(char));
}
var = ft_strsubst(var, "\\W", tmp);
- ft_memdel((void*)&tmp);
}
else
var = ft_strsubst(var, "\\w", "?");
@@ -74,26 +70,24 @@ static char
}
static void
- m_update_psx(uint8_t x,
- t_msh *msh)
+ m_update_psx(uint8_t x, t_msh *msh)
{
- char *var;
+ char var[2048];
char psx[5];
ft_sprintf(psx, "$PS%hhu", x);
- if ((var = u_get_var_value(psx, msh)) == NULL)
+ u_get_var_value(var, psx, 2048, msh);
+ if (var[0] == C_NUL)
{
msh->ps[x - 1][0] = '\0';
return ;
}
- var = m_subst_prompt_rice(var, msh);
+ m_subst_prompt_rice(var, msh);
ft_strlcpy(msh->ps[x - 1], var, ft_strlen(var) + 1);
- ft_memdel((void*)&var);
}
void
- m_prompt_psx(uint8_t x,
- t_msh *msh)
+ m_prompt_psx(uint8_t x, t_msh *msh)
{
m_update_psx(x, msh);
ft_dprintf(STDERR_FILENO, "%s", msh->ps[x - 1]);