From efeb187c12a62322a8e113173d7b4d311ad32c50 Mon Sep 17 00:00:00 2001
From: Rudy Bousset <rbousset@z2r5p2.le-101.fr>
Date: Wed, 29 Jan 2020 19:25:53 +0100
Subject: Missing error management but ok

---
 src/ft_get_map_redo.c | 24 ++++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)

(limited to 'src')

diff --git a/src/ft_get_map_redo.c b/src/ft_get_map_redo.c
index e337849..32cc178 100644
--- a/src/ft_get_map_redo.c
+++ b/src/ft_get_map_redo.c
@@ -21,7 +21,7 @@ ft_linecpy(char *line, char *mapl, size_t start)
 		i++;
 		j++;
 	}
-	mapl[j] = '\0';
+	mapl[j] = '\n';
 }
 
 static int8_t
@@ -32,7 +32,6 @@ ft_cat_mapl(char *line, size_t i, t_cub *clist)
 				((clist->map_w + 1) * (i + 1)) * sizeof(char))))
 		return (-1);
 	ft_linecpy(line, clist->mapl, (clist->map_w + 1) * i);
-	ft_printf("mapl >>>> [%s]\n", clist->mapl);
 	return (0);
 }
 
@@ -51,7 +50,7 @@ ft_get_map_first_line(char *line, t_cub *clist)
 	}
 	clist->map_w = ft_get_line_len(line);
 	clist->mapl = NULL;
-	if ((clist->mapl = ft_cat_mapl(line, 0, clist)) < 0)
+	if (ft_cat_mapl(line, 0, clist) < 0)
 	{
 		ft_memdel(line);
 		return (-1);
@@ -65,10 +64,23 @@ ft_get_map_core(int fd, t_cub *clist)
 {
 	int		ret;
 	size_t	i;
+	char	*line;
 
 	i = 1;
-	(void)fd;
-	(void)ret;
-	(void)clist;
+	ret = 1;
+	while (ret > 0)
+	{
+		ret = get_next_line(fd, &line);
+		if (ret < 0)
+			return (-1);
+		if (ft_cat_mapl(line, i, clist) < 0)
+		{
+			ft_memdel(line);
+			return (-1);
+		}
+		i++;
+	}
+	clist->mapl[((clist->map_w + 1) * i) - 1] = '\0';
+	ft_printf("mapl >>>> [%s]\n", clist->mapl);
 	return (0);
 }
-- 
cgit v1.2.3