diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-12-02 17:43:31 +0100 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-12-02 17:43:31 +0100 |
commit | 19b0278050bc1bea5e99441c3081263d96279d64 (patch) | |
tree | f87e972ecb3f4302694eb27822b6062dc9c69c85 /src/c_init.c | |
parent | pfFix (diff) | |
download | 42-minishell-19b0278050bc1bea5e99441c3081263d96279d64.tar.gz 42-minishell-19b0278050bc1bea5e99441c3081263d96279d64.tar.bz2 42-minishell-19b0278050bc1bea5e99441c3081263d96279d64.tar.xz 42-minishell-19b0278050bc1bea5e99441c3081263d96279d64.tar.zst 42-minishell-19b0278050bc1bea5e99441c3081263d96279d64.zip |
Very functionnal but extra unwanted step
Diffstat (limited to '')
-rw-r--r-- | src/c_init.c | 25 |
1 files changed, 18 insertions, 7 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); } |