From ee5675b9bb8a0e6955d733aadf199d188058082b Mon Sep 17 00:00:00 2001
From: salad <fmoenne-@student.le-101.fr>
Date: Wed, 16 Sep 2020 13:15:00 +0200
Subject: reste 3 leaks + multiline

---
 src/c_init.c  | 21 ++++++++++++---------
 src/c_utils.c | 17 +++++++----------
 src/c_utils.h |  2 +-
 3 files changed, 20 insertions(+), 20 deletions(-)

(limited to 'src')

diff --git a/src/c_init.c b/src/c_init.c
index 2bc0be3..dfb97e3 100644
--- a/src/c_init.c
+++ b/src/c_init.c
@@ -72,6 +72,7 @@ int16_t
 	i = -1;
 	if (line == NULL)
 	{
+		ft_printf("qweqwe");
 		if (!(line = ft_calloc(1, sizeof(char))))
 			return (-1);
 	}
@@ -94,14 +95,6 @@ int16_t
 		{
 			return (c_key_right(ft_strlen(line), tcaps));
 		}
-		else if (strncmp(buf, tcaps->CL, 4) == 0)
-		{
-			return (c_ctrl_l(line, tcaps, msh));
-		}
-		else if (strncmp(buf, tcaps->CC, 4) == 0)
-		{
-			return (c_new_line(buf, NULL, msh, tcaps));
-		}
 		else if (strncmp(buf, tcaps->HM, 4) == 0)
 		{
 			return (c_home_key(tcaps));
@@ -110,13 +103,23 @@ int16_t
 		{
 			return (c_end_key(ft_strlen(line), tcaps));
 		}
+		else if (strncmp(buf, tcaps->CC, 4) == 0)
+		{
+			return (c_new_line(NULL, msh, tcaps));
+		}
+		else if (strncmp(buf, tcaps->CL, 4) == 0)
+		{
+			return (c_ctrl_l(line, tcaps, msh));
+		}
 		else if (strncmp(buf, tgetstr("kb", NULL), ft_strlen(tgetstr("kb", NULL))) == 0)
 		{
 			return (c_back_slash(&line, tcaps));
 		}
 		else if (buf[0] == '\n')
 		{
-			return (c_new_line(buf, &line, msh, tcaps));
+			c_new_line(ft_strdup(line), msh, tcaps);
+			ft_memdel((void**)&line);
+			return (1);
 		}
 		else
 			return (0);
diff --git a/src/c_utils.c b/src/c_utils.c
index 43d6452..b39e580 100644
--- a/src/c_utils.c
+++ b/src/c_utils.c
@@ -24,10 +24,9 @@
 
 /*
 ** TODO:
-**  quotes
 **  leaks on line
+**  quotes
 **  C-c
-**  tests varies
 **  NORME
 **  MULTILIGHNE
 **  term(0) on exit DONE
@@ -83,19 +82,18 @@ uint16_t
 }
 
 int16_t
-	c_new_line(char *buf,
-			char **line,
+	c_new_line(char *line,
 			t_msh *msh,
 			t_caps *tcaps)
 {
-	write(1, buf, ft_strlen(buf));
+	write(1, "\n", 1);
 	tputs(tgetstr("cr", NULL), 1, ft_putchar);
 	c_set_term_raw(0);
 	if (line != NULL)
 	{
-		m_parse_and_run_line(*line, msh);
-		*line = NULL;
-		free(*line);
+		m_parse_and_run_line(line, msh);
+		line = NULL;
+		free(line);
 	}
 	tcaps->cpos = 0;
 	tputs(tgetstr("cr", NULL), 1, ft_putchar);
@@ -133,8 +131,7 @@ char
 			j++;
 		}
 	}
-	free(str);
-	dst[i] = '\0';
+	ft_memdel((void**)&str);
 	return (dst);
 }
 
diff --git a/src/c_utils.h b/src/c_utils.h
index 62179b7..7ef396f 100644
--- a/src/c_utils.h
+++ b/src/c_utils.h
@@ -21,6 +21,6 @@ uint16_t c_get_win_size(struct winsize *ws);
 int32_t c_catch_tcaps(char *buf, char **line, t_caps *tcaps, t_msh *msh);
 char *c_insert_char(char *str, char c, t_caps *tcaps);
 int16_t c_init_keys(t_caps *tcaps);
-int16_t c_new_line(char *buf, char **line, t_msh *msh, t_caps *tcaps);
+int16_t c_new_line(char *line, t_msh *msh, t_caps *tcaps);
 
 #endif
-- 
cgit v1.2.3