summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjoe <rbousset@42lyon.fr>2020-12-04 17:32:50 +0100
committerjoe <rbousset@42lyon.fr>2020-12-04 17:32:50 +0100
commit2e080e838d9f615e1e8c0f88b06823645de54fc6 (patch)
tree36e3461fa4f6f3f892af9852697b7da66261c841
parentin progress (diff)
download42-minishell-2e080e838d9f615e1e8c0f88b06823645de54fc6.tar.gz
42-minishell-2e080e838d9f615e1e8c0f88b06823645de54fc6.tar.bz2
42-minishell-2e080e838d9f615e1e8c0f88b06823645de54fc6.tar.xz
42-minishell-2e080e838d9f615e1e8c0f88b06823645de54fc6.tar.zst
42-minishell-2e080e838d9f615e1e8c0f88b06823645de54fc6.zip
Good now
-rw-r--r--libft/include/libft.h6
-rw-r--r--src/c_init.c13
2 files changed, 12 insertions, 7 deletions
diff --git a/libft/include/libft.h b/libft/include/libft.h
index 265d87c..427f873 100644
--- a/libft/include/libft.h
+++ b/libft/include/libft.h
@@ -23,11 +23,13 @@
# define BUFFER_SIZE 72
# endif
-typedef enum e_bool
+typedef unsigned char t_bool;
+
+enum e_bool
{
FALSE,
TRUE
-} t_bool;
+};
typedef struct s_list
{
diff --git a/src/c_init.c b/src/c_init.c
index a10daa7..f707c69 100644
--- a/src/c_init.c
+++ b/src/c_init.c
@@ -122,8 +122,9 @@ char *ft_strrbavchr(const char *s, int c, size_t start)
char *c_set_ptr(t_bool reset, char key, t_msh *msh)
{
- static char *p = NULL;
- static char *context = NULL;
+ static char *p = NULL;
+ static char *context = NULL;
+ static t_bool sw = FALSE;
if (reset == TRUE)
{
@@ -142,18 +143,20 @@ char *c_set_ptr(t_bool reset, char key, t_msh *msh)
{
p = msh->curr_hist_ptr;
context = msh->curr_hist_ptr;
+ sw = TRUE;
}
if ((key == -1 && p - context != 0) || key == 1)
{
p += (key == -1) ? (2 * key) : (0);
- while (((key == -1 && p - context != 0) || key == 1)
+ while (sw == FALSE && ((key == -1 && p - context != 0) || key == 1)
&& *p != C_LF && *p != C_NUL)
p += key;
- if (key == 1 && p - context == 1)
- p -= 1;
+ if (sw == TRUE)
+ sw = FALSE;
if (p - context != 0 && *p != C_NUL)
p += 1;
}
+ /* ft_printf("\n\r[%s]\n\r[%s]\n\r", context, p); */
return (p);
}