From ccf063f3aa36b2f883487567512523d24b35bb83 Mon Sep 17 00:00:00 2001 From: Andrei Pago Date: Wed, 5 Apr 2023 17:18:28 +0200 Subject: [PATCH] Create map with copy --- includes/parsing.h | 3 ++- srcs/main.c | 45 ++++++--------------------------------------- srcs/parsing.c | 9 ++++++++- 3 files changed, 16 insertions(+), 41 deletions(-) diff --git a/includes/parsing.h b/includes/parsing.h index 98fb731..b706281 100644 --- a/includes/parsing.h +++ b/includes/parsing.h @@ -6,7 +6,7 @@ /* By: apago +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/04/04 18:22:11 by apago #+# #+# */ -/* Updated: 2023/04/05 09:31:04 by tischmid ### ########.fr */ +/* Updated: 2023/04/05 17:17:26 by apago ### ########.fr */ /* */ /* ************************************************************************** */ @@ -41,5 +41,6 @@ int read_char(char *str, char *dst); int printable(char c); size_t count_first_line(char *line); int read_fname(char *name, t_map *map); +void copy_bytes(char *dst, char *src, size_t bytes); #endif diff --git a/srcs/main.c b/srcs/main.c index 059fecb..0a20375 100644 --- a/srcs/main.c +++ b/srcs/main.c @@ -3,57 +3,24 @@ /* ::: :::::::: */ /* main.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: tischmid +#+ +:+ +#+ */ +/* By: apago +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/04/04 21:50:50 by tischmid #+# #+# */ -/* Updated: 2023/04/05 11:04:31 by tischmid ### ########.fr */ +/* Updated: 2023/04/05 17:14:36 by apago ### ########.fr */ /* */ /* ************************************************************************** */ -#include -#include "solution.h" -#include "printing.h" #include "ft_string.h" - -void debug_set_map(t_map *map) -{ - char *str; - - str = \ - "........................................" \ - "...................X...................." \ - ".........................X..........X..." \ - "..............X........................." \ - ".........X...........................X.." \ - "............X..X........................" \ - "..................................X....." \ - "....................................X..." \ - "........................................" \ - "X.X..........................X.........." \ - "....X.................................X." \ - "..........X............................." \ - ".............................X.........." \ - "....................X......X............" \ - "............................X...X......X" \ - ".......X........X....X....X..XX........." \ - "................X........X............X." \ - "................X......X................" \ - "....X................X.......X.........." \ - "........................................"; - map->data = malloc(sizeof(char) * (ft_strlen(str) + 1)); - ft_strcpy(map->data, str); -} +#include "printing.h" +#include "solution.h" +#include int main(void) { t_map map; - if (!read_fname("./assets/map20x40.map", &map)) + if (!read_fname("./assets/subject.map", &map)) return (ft_err("map error\n", 1)); - free(map.data); - debug_set_map(&map); - map.copy = malloc(sizeof(char) * (ft_strlen(map.data) + 1)); - ft_strcpy(map.copy, map.data); solve(&map); print_map(&map, 0); free(map.data); diff --git a/srcs/parsing.c b/srcs/parsing.c index 62fdff2..c65091e 100644 --- a/srcs/parsing.c +++ b/srcs/parsing.c @@ -6,7 +6,7 @@ /* By: apago +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/04/04 16:19:27 by apago #+# #+# */ -/* Updated: 2023/04/05 16:42:50 by apago ### ########.fr */ +/* Updated: 2023/04/05 17:16:41 by apago ### ########.fr */ /* */ /* ************************************************************************** */ @@ -103,6 +103,13 @@ int parse_input(char *str, t_map *map) map->data = parse_data(&str[offset], &map->meta); if (!map->data) return (0); + map->copy = malloc(sizeof(char) * (map->meta.width * map->meta.height)); + if (!map->copy) + { + free(map->data); + return (0); + } + copy_bytes(map->copy, map->data, map->meta.width * map->meta.height); return (1); }