From aaf2b0adc8a5b3ece05a6b68c826068d97956006 Mon Sep 17 00:00:00 2001 From: mcolonna Date: Thu, 17 Oct 2024 17:59:41 +0200 Subject: [PATCH] fix: map parsing error --- map_utils.h | 7 +------ map_utils1.c | 13 ++++++++----- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/map_utils.h b/map_utils.h index 733d6f4..6f35bba 100644 --- a/map_utils.h +++ b/map_utils.h @@ -6,7 +6,7 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/03 15:05:13 by mc #+# #+# */ -/* Updated: 2024/10/15 17:23:40 by mcolonna ### ########.fr */ +/* Updated: 2024/10/17 17:58:23 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ @@ -43,11 +43,6 @@ bool read_color_parameter(const char *name, t_color *dest, bool read_string_parameter(const char *name, const char **dest, t_stream *stream, bool *redefined); -/// @brief Set the map to initial values. Every texture becomes NULL -/// and every color becomes 0xFF000000. -/// @param dest Map to reset. -void reset_map(t_map *dest); - /// @brief Read a map-formatted string. /// If an error occurs, write an error message on stderr. /// @param dest Will be set to the map. diff --git a/map_utils1.c b/map_utils1.c index 4e12115..9edd47a 100644 --- a/map_utils1.c +++ b/map_utils1.c @@ -6,7 +6,7 @@ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/03 15:02:09 by mc #+# #+# */ -/* Updated: 2024/10/17 16:09:31 by mcolonna ### ########.fr */ +/* Updated: 2024/10/17 17:59:05 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ @@ -75,7 +75,7 @@ bool read_string_parameter(const char *name, const char **dest, return (!err); } -void reset_map(t_map *dest) +static void read_map2(t_map *dest, bool *err, bool *rdf) { dest->cases = NULL; dest->color_ceiling = 0xFF000000; @@ -84,18 +84,20 @@ void reset_map(t_map *dest) dest->texture_west = NULL; dest->texture_north = NULL; dest->texture_south = NULL; + *err = false; + *rdf = false; } bool read_map(t_map *dest, t_stream *stream) { bool err; bool rdf; + int old_stream_i; - reset_map(dest); - err = false; - rdf = false; + read_map2(dest, &err, &rdf); while (!rdf && !err && stream->str[stream->i]) { + old_stream_i = stream->i; if ((read_expected_string("\n", stream, &err), err) && !read_string_parameter("NO", &dest->texture_north, stream, &rdf) && !read_string_parameter("SO", &dest->texture_south, stream, &rdf) @@ -104,6 +106,7 @@ bool read_map(t_map *dest, t_stream *stream) && !read_color_parameter("F", &dest->color_floor, stream, &rdf) && !read_color_parameter("C", &dest->color_ceiling, stream, &rdf)) { + stream->i = old_stream_i; err = !read_map_description(dest, stream); break ; }