diff options
-rw-r--r-- | libft/Makefile | 1 | ||||
-rw-r--r-- | libft/include/libft.h | 1 | ||||
-rw-r--r-- | libft/src/ft_strrnchr.c | 27 | ||||
-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 |
10 files changed, 48 insertions, 33 deletions
diff --git a/libft/Makefile b/libft/Makefile index 66b8081..fb67ba7 100644 --- a/libft/Makefile +++ b/libft/Makefile @@ -37,6 +37,7 @@ SRCS_NAME += ft_tolower.c SRCS_NAME += ft_toupper.c SRCS_NAME += ft_strchr.c SRCS_NAME += ft_strrchr.c +SRCS_NAME += ft_strrnchr.c SRCS_NAME += ft_strlchr.c SRCS_NAME += ft_strncmp.c SRCS_NAME += ft_strlcpy.c diff --git a/libft/include/libft.h b/libft/include/libft.h index 427f873..8ba0563 100644 --- a/libft/include/libft.h +++ b/libft/include/libft.h @@ -111,6 +111,7 @@ void *ft_nrealloc(void *ptr, size_t oldsize, size_t newsize); char *ft_strcat(char *s1, const char *s2); char *ft_strchr(const char *s, int c); char *ft_strrchr(const char *s, int c); +char *ft_strrnchr(const char *s, int c, size_t start); char *ft_strnstr(const char *haystack, const char *needle, size_t len); char *ft_strdup(const char *s1); diff --git a/libft/src/ft_strrnchr.c b/libft/src/ft_strrnchr.c new file mode 100644 index 0000000..d6b8fdd --- /dev/null +++ b/libft/src/ft_strrnchr.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strrnchr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/14 17:19:27 by rbousset #+# #+# */ +/* Updated: 2020/02/14 17:19:29 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#include <libft.h> + +char *ft_strrnchr(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]); +} 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" |