diff options
-rw-r--r-- | src/c_init.c | 20 | ||||
-rw-r--r-- | src/m_loop.c | 1 |
2 files changed, 19 insertions, 2 deletions
diff --git a/src/c_init.c b/src/c_init.c index 09a7828..a10daa7 100644 --- a/src/c_init.c +++ b/src/c_init.c @@ -106,6 +106,20 @@ static short return (0); } +char *ft_strrbavchr(const char *s, int c, size_t start) +{ + size_t i; + + i = ft_strlen(s) - start; + while (s[i] != c) + { + if (i == 0) + return (NULL); + i--; + } + return ((char*)&s[i]); +} + char *c_set_ptr(t_bool reset, char key, t_msh *msh) { static char *p = NULL; @@ -123,8 +137,8 @@ char *c_set_ptr(t_bool reset, char key, t_msh *msh) p = msh->prev_hist + ft_strlen(msh->prev_hist); context = msh->prev_hist; } - else if (key == 1 && context == msh->prev_hist - && p == msh->prev_hist + ft_strlen(msh->prev_hist)) + if (key == 1 && context == msh->prev_hist + && p == ft_strrbavchr(msh->prev_hist, '\n', 2) + 1) { p = msh->curr_hist_ptr; context = msh->curr_hist_ptr; @@ -135,6 +149,8 @@ char *c_set_ptr(t_bool reset, char key, t_msh *msh) while (((key == -1 && p - context != 0) || key == 1) && *p != C_LF && *p != C_NUL) p += key; + if (key == 1 && p - context == 1) + p -= 1; if (p - context != 0 && *p != C_NUL) p += 1; } diff --git a/src/m_loop.c b/src/m_loop.c index b249935..c7ca9cc 100644 --- a/src/m_loop.c +++ b/src/m_loop.c @@ -142,6 +142,7 @@ unsigned char m_loop(int fd, t_msh *msh) gnl = 1; msh->curr_hist_ptr = hist; c_get_msh(1, msh); + c_set_ptr(TRUE, 0, msh); signal(SIGINT, c_signal_int); signal(SIGQUIT, c_signal_ign); while (gnl > 0) |