From dbadd42c07b1d00a360041a257aad7ebce53f5e7 Mon Sep 17 00:00:00 2001 From: Adam Joly Date: Wed, 20 Dec 2023 14:14:35 +0100 Subject: [PATCH] parsing near finished --- fdf.h | 4 ++-- maps_reader.c | 33 +++++++++++++++++++++++---------- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/fdf.h b/fdf.h index e29a806..cb4bbbf 100644 --- a/fdf.h +++ b/fdf.h @@ -6,7 +6,7 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/12/11 05:10:42 by adjoly #+# #+# */ -/* Updated: 2023/12/18 14:18:16 by adjoly ### ########.fr */ +/* Updated: 2023/12/20 10:21:53 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ @@ -33,7 +33,7 @@ typedef struct s_map { int y; char *color; -} j t_map; +} t_map; int ft_read_map(int fd, char **map); size_t ft_countline_fd(int fd); diff --git a/maps_reader.c b/maps_reader.c index 93c19f9..b8e7868 100644 --- a/maps_reader.c +++ b/maps_reader.c @@ -6,12 +6,13 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/12/12 05:19:39 by adjoly #+# #+# */ -/* Updated: 2023/12/18 17:18:43 by adjoly ### ########.fr */ +/* Updated: 2023/12/20 10:43:54 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ #include "fdf.h" #include "libft/libft.h" +#include #include #include void ft_putstr(char *s){int i = 0;while(s[i]){write(1, &s[i], 1);i++;}} @@ -81,22 +82,31 @@ char **ft_getmap(char *file) return (map); } -t_map *ft_split_height_color(char *tmp) +t_map ft_split_height_color(char *tmp) { - t_map *height_color; + t_map height_color; int i; - while (tmp[i]) - { - + height_color.y = ft_atoi(tmp); + while (tmp[i] && tmp[i] != ',') i++; + if (tmp[i] == ',') + { + i++; + height_color.color = ft_strdup(&tmp[i]); + return (height_color); + } + else + { + height_color.color = ft_strdup("0xFFFFFF"); + return (height_color); } - return (); } t_map **ft_parse_map(char **mapfile) { int z; + int x; int line_count; char **tmp; t_map **parsed_map; @@ -107,13 +117,16 @@ t_map **ft_parse_map(char **mapfile) while (mapfile[z]) { tmp = ft_split(mapfile[z], 32); - parsed_map[z] = ft_split_height_color(tmp); + x = 0; + while (tmp[x]) + { + parsed_map[z][x] = ft_split_height_color(tmp[x]); + x++; + } } return (parsed_map); } - - int main(int ac, char **av) { (void)ac;