summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/c_init.c25
-rw-r--r--src/m_argv.c2
-rw-r--r--src/m_argv.h1
-rw-r--r--src/m_loop.c3
-rw-r--r--src/u_vars.c2
5 files changed, 24 insertions, 9 deletions
diff --git a/src/c_init.c b/src/c_init.c
index b463830..82600e8 100644
--- a/src/c_init.c
+++ b/src/c_init.c
@@ -109,23 +109,34 @@ static short
char *c_set_ptr(t_bool reset, char key, t_msh *msh)
{
static char *p = NULL;
+ static char *context = NULL;
if (reset == TRUE)
{
p = msh->curr_hist_ptr + ft_strlen(msh->curr_hist_ptr);
+ context = msh->curr_hist_ptr;
return (NULL);
}
- if ((key == -1 && p - msh->curr_hist_ptr != 0) || key == 1)
+ if (key == -1 && context == msh->curr_hist_ptr
+ && p - context == 0 && msh->prev_hist != NULL)
+ {
+ 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))
+ {
+ p = msh->curr_hist_ptr;
+ context = msh->curr_hist_ptr;
+ }
+ else if ((key == -1 && p - context != 0) || key == 1)
{
p += (key == -1) ? (2 * key) : (0);
- while (((key == -1 && p - msh->curr_hist_ptr != 0) || key == 1) && *p != C_LF && *p != C_NUL)
- {
+ while (((key == -1 && p - context != 0) || key == 1)
+ && *p != C_LF && *p != C_NUL)
p += key;
- }
- if (p - msh->curr_hist_ptr != 0 && *p != C_NUL)
- {
+ if (p - context != 0 && *p != C_NUL)
p += 1;
- }
}
return (p);
}
diff --git a/src/m_argv.c b/src/m_argv.c
index 655d54b..525439b 100644
--- a/src/m_argv.c
+++ b/src/m_argv.c
@@ -25,7 +25,7 @@
#include "s_struct.h"
#include "u_vars.h"
-static char *m_get_prev_hist(t_msh *msh)
+char *m_get_prev_hist(t_msh *msh)
{
struct stat sb;
char *hist;
diff --git a/src/m_argv.h b/src/m_argv.h
index af2711c..4f97a0d 100644
--- a/src/m_argv.h
+++ b/src/m_argv.h
@@ -15,6 +15,7 @@
# include "s_struct.h"
+char *m_get_prev_hist(t_msh *msh);
unsigned char m_argv(int argc, char *const argv[], t_msh *msh);
#endif
diff --git a/src/m_loop.c b/src/m_loop.c
index a5e816d..b249935 100644
--- a/src/m_loop.c
+++ b/src/m_loop.c
@@ -25,6 +25,7 @@
#include "c_ctrls.h"
#include "d_define.h"
#include "e_line.h"
+#include "m_argv.h"
#include "m_loop_multis.h"
#include "m_prompt.h"
#include "p_lblock.h"
@@ -100,6 +101,8 @@ static void m_handle_hist(char hist[], char line[], t_msh *msh)
if (hist_i == 254)
{
m_dump_hist(hist, msh);
+ ft_memdel((void*)&msh->prev_hist);
+ msh->prev_hist = m_get_prev_hist(msh);
hist_i = 0;
}
}
diff --git a/src/u_vars.c b/src/u_vars.c
index 266b94b..2b6fe96 100644
--- a/src/u_vars.c
+++ b/src/u_vars.c
@@ -96,7 +96,7 @@ void u_get_custom_var(char str[],
}
/*
-** void
+** unsigned char
** u_get_var_value(char str[], const char varname[], size_t dstsize, t_msh *msh)
**
** DESCRIPTION