From b96c18b5a12dc3f581ee0050aa48b2b3d7df26ec Mon Sep 17 00:00:00 2001 From: salad Date: Wed, 16 Dec 2020 13:46:31 +0100 Subject: check for leaks.......again --- src/c_init.c | 20 ++++++-------------- src/c_init.h | 1 + src/c_utils.c | 2 +- src/c_utils_next.c | 15 ++++++++++++++- src/c_utils_next.h | 3 ++- 5 files changed, 24 insertions(+), 17 deletions(-) diff --git a/src/c_init.c b/src/c_init.c index 0001660..59cb5fa 100644 --- a/src/c_init.c +++ b/src/c_init.c @@ -116,28 +116,18 @@ char return (p); } -/* TODO : key_up_down should manage and set the correct key */ - static char *c_process_key(char **line, char *buf, t_caps *tcaps, t_msh *msh) { - char *ptr; - if (ft_isprint(buf[0])) c_add_char(line, buf, tcaps); else if (((*((unsigned int *)buf)) == UP_K) || - ((*((unsigned int *)buf)) == CTRL_P)) - { - ptr = c_set_ptr(FALSE, -1, msh); - c_key_up_down(line, tcaps, ptr); - c_redraw_line(*line, tcaps); - } - else if (((*((unsigned int *)buf)) == DOWN_K) || + ((*((unsigned int *)buf)) == CTRL_P) || + ((*((unsigned int *)buf)) == DOWN_K) || ((*((unsigned int *)buf)) == CTRL_N)) { - ptr = c_set_ptr(FALSE, 1, msh); - c_key_up_down(line, tcaps, ptr); - c_redraw_line(*line, tcaps); + tcaps->key = c_set_key(buf); + c_key_up_down(line, tcaps, msh); } else if ((*((unsigned int *)buf)) == DEL_K) { @@ -167,6 +157,8 @@ short msh->sig = 0; tcaps.plen = (unsigned int)m_plen(msh->ps[psx - 1]); *line = NULL; + if (!(*line = ft_calloc(sizeof(char), 1))) + return (-1); if (!(c_get_win_size(&tcaps.ws))) return (-1); while (!(ft_strchr(nread, '\n'))) diff --git a/src/c_init.h b/src/c_init.h index dae8513..a9e7605 100644 --- a/src/c_init.h +++ b/src/c_init.h @@ -47,6 +47,7 @@ typedef struct s_caps unsigned int nlines; unsigned short psx; unsigned short plen; + short key; } t_caps; char *c_set_ptr(t_bool reset, char key, t_msh *msh); diff --git a/src/c_utils.c b/src/c_utils.c index 1fff5a1..10013d7 100644 --- a/src/c_utils.c +++ b/src/c_utils.c @@ -86,7 +86,7 @@ void i = -1; j = 0; - len = (*line != NULL) ? (ft_strlen(*line) + 2) : 2; + len = (ft_strlen(*line) + 2); if (!(dst = (char*)ft_calloc(sizeof(char), len))) return ; while (++i < (int)len) diff --git a/src/c_utils_next.c b/src/c_utils_next.c index c57ab1d..27a88db 100644 --- a/src/c_utils_next.c +++ b/src/c_utils_next.c @@ -16,8 +16,18 @@ #include "c_init.h" #include "c_keys.h" +#include "c_utils.h" #include "d_define.h" +short c_set_key(char *buf) +{ + if (((*((unsigned int *)buf)) == UP_K) || + ((*((unsigned int *)buf)) == CTRL_P)) + return (-1); + else + return (1); +} + t_msh *c_get_msh(int mode, t_msh *src) { static t_msh *msh; @@ -29,14 +39,17 @@ t_msh *c_get_msh(int mode, t_msh *src) return (msh); } -void c_key_up_down(char *line[], t_caps *tcaps, char *ptr) +void c_key_up_down(char *line[], t_caps *tcaps, t_msh *msh) { char tmp[ARG_MAX]; + char *ptr; + ptr = c_set_ptr(FALSE, tcaps->key, msh); c_home_key(tcaps->plen, tcaps); ft_substr_s(tmp, ptr, 0, ft_strclen(ptr, '\n')); ft_memdel((void*)&(*line)); tputs(tgetstr("ce", NULL), 1, ft_putchar); *line = ft_strdup(tmp); tcaps->cpos = ft_strlen(*line); + c_redraw_line(*line, tcaps); } diff --git a/src/c_utils_next.h b/src/c_utils_next.h index 60681d6..1cf0132 100644 --- a/src/c_utils_next.h +++ b/src/c_utils_next.h @@ -15,7 +15,8 @@ # include "c_init.h" -void c_key_up_down(char *line[], t_caps *tcaps, char *ptr); +short c_set_key(char *buf); +void c_key_up_down(char *line[], t_caps *tcaps, t_msh *msh); t_msh *c_get_msh(int mode, t_msh *src); #endif -- cgit v1.2.3