summaryrefslogtreecommitdiffstats
path: root/src/c_init.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/c_init.c20
1 files changed, 18 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;
}