From 247023e3fac41c99b5580d69262837429fb2bfed Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Sat, 5 Sep 2020 17:03:49 +0200 Subject: Fuck shell --- src/m_prompt.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/m_prompt.c') diff --git a/src/m_prompt.c b/src/m_prompt.c index ad3c957..1ea8d70 100644 --- a/src/m_prompt.c +++ b/src/m_prompt.c @@ -54,7 +54,8 @@ static char while (tmp[j] != '/' && j != 0) j--; j++; - ft_memmove(tmp, tmp + j, (ft_strlen(tmp) - j) + 1); + (void)ft_memmove(tmp, tmp + j, + ((ft_strlen(tmp) - j) + 1) * sizeof(char)); } var = ft_strsubst(var, "\\W", tmp); ft_memdel((void*)&tmp); -- cgit v1.2.3 From 4543c3ba3222d47780ad3e091cfe6f3098cc2bca Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Sun, 6 Sep 2020 21:56:20 +0200 Subject: Stacked --- src/m_prompt.c | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) (limited to 'src/m_prompt.c') 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 #include #include +#include #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]); -- cgit v1.2.3 From 20b9a703186d7bf06936467ae3e8108cfbee43dd Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Thu, 10 Sep 2020 19:28:08 +0200 Subject: I was born an idiot I swear --- src/m_prompt.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src/m_prompt.c') diff --git a/src/m_prompt.c b/src/m_prompt.c index d0269e4..dc17939 100644 --- a/src/m_prompt.c +++ b/src/m_prompt.c @@ -24,15 +24,21 @@ static char *m_subst_prompt_rice(char var[], t_msh *msh) { char tmp[PATH_MAX]; + char *ptr; size_t i; size_t j; i = 0; - while (var[i] != '\0') + while (var[i] != C_NUL) { - if (var[i] == '\\') + if (var[i] == C_BACKS) { - if (var[i + 1] == 'w') + if (var[i + 1] == '0' && var[i + 2] == '3' && var[i + 3] == '3') + { + ft_memmove(var + i, var + i + 3, ft_strlen(var + i + 3) + 1); + var[i] = C_ESC; + } + else if (var[i + 1] == 'w') { u_get_var_value(tmp, "$PWD", PATH_MAX, msh); if (tmp[0] != C_NUL) -- cgit v1.2.3 From 89c27ba72e11665823cba7023f694a8639891ccb Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Thu, 10 Sep 2020 19:53:00 +0200 Subject: New libft func, cool stuff --- src/m_prompt.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'src/m_prompt.c') diff --git a/src/m_prompt.c b/src/m_prompt.c index dc17939..2d88088 100644 --- a/src/m_prompt.c +++ b/src/m_prompt.c @@ -24,7 +24,6 @@ static char *m_subst_prompt_rice(char var[], t_msh *msh) { char tmp[PATH_MAX]; - char *ptr; size_t i; size_t j; @@ -42,9 +41,9 @@ static char { u_get_var_value(tmp, "$PWD", PATH_MAX, msh); if (tmp[0] != C_NUL) - var = ft_strsubst(var, "\\w", tmp); + ft_strsubst_s(var, "\\w", tmp); else - var = ft_strsubst(var, "\\w", "?"); + ft_strsubst_s(var, "\\w", "?"); } else if (var[i + 1] == 'W') { @@ -60,10 +59,10 @@ static char (void)ft_memmove(tmp, tmp + j, ((ft_strlen(tmp) - j) + 1) * sizeof(char)); } - var = ft_strsubst(var, "\\W", tmp); + ft_strsubst_s(var, "\\W", tmp); } else - var = ft_strsubst(var, "\\w", "?"); + ft_strsubst_s(var, "\\w", "?"); } else if (var[i + 1] == 'v') var = ft_strsubst(var, "\\v", FT_MSH_VERSION); -- cgit v1.2.3 From 4b84aadfcb1dcc46d686fd984e0566d84e116278 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Thu, 10 Sep 2020 20:21:39 +0200 Subject: LOT to fix --- src/m_prompt.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src/m_prompt.c') diff --git a/src/m_prompt.c b/src/m_prompt.c index 2d88088..ff491c8 100644 --- a/src/m_prompt.c +++ b/src/m_prompt.c @@ -34,9 +34,14 @@ static char { if (var[i + 1] == '0' && var[i + 2] == '3' && var[i + 3] == '3') { - ft_memmove(var + i, var + i + 3, ft_strlen(var + i + 3) + 1); + (void)ft_memmove(var + i, var + i + 3, ft_strlen(var + i + 3) + 1); var[i] = C_ESC; } + else if (var[i + 1] == 'n') + { + (void)ft_memmove(var + i, var + i + 1, ft_strlen(var + i + 1) + 1); + var[i] = C_LF; + } else if (var[i + 1] == 'w') { u_get_var_value(tmp, "$PWD", PATH_MAX, msh); @@ -65,9 +70,9 @@ static char ft_strsubst_s(var, "\\w", "?"); } else if (var[i + 1] == 'v') - var = ft_strsubst(var, "\\v", FT_MSH_VERSION); + ft_strsubst_s(var, "\\v", FT_MSH_VERSION); else if (var[i + 1] == 's') - var = ft_strsubst(var, "\\s", FT_PROGNAME); + ft_strsubst_s(var, "\\s", FT_PROGNAME); } i++; } -- cgit v1.2.3 From 6f756ee6112c723cfe0f8ece2d530b249aa47e00 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Fri, 11 Sep 2020 15:05:31 +0200 Subject: Fix --- src/m_prompt.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'src/m_prompt.c') diff --git a/src/m_prompt.c b/src/m_prompt.c index ff491c8..584a98d 100644 --- a/src/m_prompt.c +++ b/src/m_prompt.c @@ -34,14 +34,20 @@ static char { if (var[i + 1] == '0' && var[i + 2] == '3' && var[i + 3] == '3') { - (void)ft_memmove(var + i, var + i + 3, ft_strlen(var + i + 3) + 1); + (void)ft_memmove(var + i, var + (i + 3), (ft_strlen(var + (i + 3)) + 1) * sizeof(char)); var[i] = C_ESC; } else if (var[i + 1] == 'n') { - (void)ft_memmove(var + i, var + i + 1, ft_strlen(var + i + 1) + 1); + (void)ft_memmove(var + i, var + (i + 1), (ft_strlen(var + (i + 1)) + 1) * sizeof(char)); var[i] = C_LF; } + else if (var[i + 1] == 'h' || var[i + 1] == 'H') + { + gethostname(tmp, 255); + (void)ft_memmove(var + i + ft_strlen(tmp), var + (i + 2), (ft_strlen(var + (i + 2)) + 1) * sizeof(char)); + (void)ft_memcpy(var + i, tmp, ft_strlen(tmp) * sizeof(char)); + } else if (var[i + 1] == 'w') { u_get_var_value(tmp, "$PWD", PATH_MAX, msh); @@ -82,11 +88,11 @@ static char static void m_update_psx(uint8_t x, t_msh *msh) { - char var[2048]; + char var[ARG_MAX]; char psx[5]; ft_sprintf(psx, "$PS%hhu", x); - u_get_var_value(var, psx, 2048, msh); + u_get_var_value(var, psx, ARG_MAX, msh); if (var[0] == C_NUL) { msh->ps[x - 1][0] = '\0'; -- cgit v1.2.3