diff options
author | salad <fmoenne-@student.le-101.fr> | 2020-12-16 13:10:11 +0100 |
---|---|---|
committer | salad <fmoenne-@student.le-101.fr> | 2020-12-16 13:10:11 +0100 |
commit | 711bc9edbd9646900fc7e00e7b3457c2070ac31f (patch) | |
tree | 2b173316fcea1f8609fc9494dadce17588f248b4 /src | |
parent | norm tobecontinued2 (diff) | |
download | 42-minishell-711bc9edbd9646900fc7e00e7b3457c2070ac31f.tar.gz 42-minishell-711bc9edbd9646900fc7e00e7b3457c2070ac31f.tar.bz2 42-minishell-711bc9edbd9646900fc7e00e7b3457c2070ac31f.tar.xz 42-minishell-711bc9edbd9646900fc7e00e7b3457c2070ac31f.tar.zst 42-minishell-711bc9edbd9646900fc7e00e7b3457c2070ac31f.zip |
qwe
Diffstat (limited to 'src')
-rw-r--r-- | src/c_ctrls.c | 12 | ||||
-rw-r--r-- | src/c_ctrls.h | 1 | ||||
-rw-r--r-- | src/c_init.c | 22 | ||||
-rw-r--r-- | src/c_keys_next.c | 11 | ||||
-rw-r--r-- | src/c_keys_next.h | 3 | ||||
-rw-r--r-- | src/c_utils.c | 2 | ||||
-rw-r--r-- | src/m_loop.c | 1 |
7 files changed, 19 insertions, 33 deletions
diff --git a/src/c_ctrls.c b/src/c_ctrls.c index 58b4517..3dca13e 100644 --- a/src/c_ctrls.c +++ b/src/c_ctrls.c @@ -17,23 +17,13 @@ #include <term.h> #include "c_ctrls.h" +#include "c_keys_next.h" #include "c_utils.h" #include "m_prompt.h" #include "m_loop.h" #include "s_destroy.h" #include "u_utils.h" -t_msh *c_get_msh(int mode, t_msh *src) -{ - static t_msh *msh; - - if (mode == 1) - { - msh = src; - } - return (msh); -} - short c_ctrl_d(t_msh *msh) { int tmp; diff --git a/src/c_ctrls.h b/src/c_ctrls.h index d4b932b..337a6f5 100644 --- a/src/c_ctrls.h +++ b/src/c_ctrls.h @@ -18,7 +18,6 @@ void c_signal_int(int signo); void c_signal_ign(int signo); -t_msh *c_get_msh(int mode, t_msh *src); short c_ctrl_l(char *line, t_caps *tcaps, t_msh *msh); short c_ctrl_d(t_msh *msh); char *c_ctrl_c(char **line, char *buf, t_msh *msh); diff --git a/src/c_init.c b/src/c_init.c index a8ec6ee..472ee75 100644 --- a/src/c_init.c +++ b/src/c_init.c @@ -76,21 +76,8 @@ 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) +char + *c_set_ptr(t_bool reset, char key, t_msh *msh) { static char *p = NULL; static char *context = NULL; @@ -109,7 +96,7 @@ char *c_set_ptr(t_bool reset, char key, t_msh *msh) context = msh->prev_hist; } if (key == 1 && context == msh->prev_hist - && p == ft_strrbavchr(msh->prev_hist, '\n', 2) + 1) + && p == ft_strrnchr(msh->prev_hist, '\n', 2) + 1) { p = msh->curr_hist_ptr; context = msh->curr_hist_ptr; @@ -136,9 +123,6 @@ static char { char *ptr; - if (*line == NULL) - if (!(*line = ft_calloc(1, sizeof(char)))) - return (NULL); if (ft_isprint(buf[0])) c_add_char(line, buf, tcaps); else if (((*((unsigned int *)buf)) == UP_K) || diff --git a/src/c_keys_next.c b/src/c_keys_next.c index ec063d3..58c8946 100644 --- a/src/c_keys_next.c +++ b/src/c_keys_next.c @@ -18,6 +18,17 @@ #include "c_keys.h" #include "d_define.h" +t_msh *c_get_msh(int mode, t_msh *src) +{ + static t_msh *msh; + + if (mode == 1) + { + msh = src; + } + return (msh); +} + void c_key_up_down(char *line[], t_caps *tcaps, char *ptr) { char tmp[ARG_MAX]; diff --git a/src/c_keys_next.h b/src/c_keys_next.h index fa79d85..1149f38 100644 --- a/src/c_keys_next.h +++ b/src/c_keys_next.h @@ -13,8 +13,9 @@ #ifndef C_KEYS_NEXT_H # define C_KEYS_NEXT_H -#include "c_init.h" +# include "c_init.h" void c_key_up_down(char *line[], t_caps *tcaps, char *ptr); +t_msh *c_get_msh(int mode, t_msh *src); #endif diff --git a/src/c_utils.c b/src/c_utils.c index 10013d7..1fff5a1 100644 --- a/src/c_utils.c +++ b/src/c_utils.c @@ -86,7 +86,7 @@ void i = -1; j = 0; - len = (ft_strlen(*line) + 2); + len = (*line != NULL) ? (ft_strlen(*line) + 2) : 2; if (!(dst = (char*)ft_calloc(sizeof(char), len))) return ; while (++i < (int)len) diff --git a/src/m_loop.c b/src/m_loop.c index c7ca9cc..fd6df37 100644 --- a/src/m_loop.c +++ b/src/m_loop.c @@ -22,6 +22,7 @@ #endif #include "c_init.h" +#include "c_keys_next.h" #include "c_ctrls.h" #include "d_define.h" #include "e_line.h" |