From 412dc89336bd0d211703ecd6351cad185ef5f32f Mon Sep 17 00:00:00 2001 From: Theo Champion Date: Thu, 14 Aug 2025 19:52:34 +0200 Subject: [PATCH] fix: Transferred trailing magic error messages as consts --- src/consts.h | 9 ++++++++- src/map/populate_map.c | 4 ++-- src/map/setters.c | 16 ++++++++-------- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/consts.h b/src/consts.h index 84f5e96..563e3b4 100644 --- a/src/consts.h +++ b/src/consts.h @@ -6,7 +6,7 @@ /* By: kcolin +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/07/17 14:54:36 by kcolin #+# #+# */ -/* Updated: 2025/08/12 14:49:36 by tchampio ### ########.fr */ +/* Updated: 2025/08/14 19:50:28 by tchampio ### ########.fr */ /* */ /* ************************************************************************** */ @@ -48,5 +48,12 @@ # define EMALMAP "Map is malformed (invalid chars or missing walls)" # define ENOPLAYER "No player" # define EHOLES "Holes in map" +# define ETRAILING "Trailing chars after map" +# define EBADCHARCOLOR "invalid characters in color definition" +# define EBADVALCOLOR "invalid value for colors" +# define ETOOMANYCOLORS "too many colors" +# define ENOTENOUGHCOLORS "Not enough colors" +# define EDUPTEX "Duplicated texture directive" +# define EMAPBFTEX "Map started before all the textures" #endif diff --git a/src/map/populate_map.c b/src/map/populate_map.c index e35240e..4caa366 100644 --- a/src/map/populate_map.c +++ b/src/map/populate_map.c @@ -6,7 +6,7 @@ /* By: kcolin +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/07/17 14:44:02 by kcolin #+# #+# */ -/* Updated: 2025/07/23 13:34:33 by kcolin ### ########.fr */ +/* Updated: 2025/08/14 19:46:26 by tchampio ### ########.fr */ /* */ /* ************************************************************************** */ @@ -70,7 +70,7 @@ bool populate_maps(t_mapdata *map, int fd) { if (line[0] != '\n' && end_reached) { - ft_strlcpy(map->error, "Trailing chars after map", ERRLEN); + ft_strlcpy(map->error, ETRAILING, ERRLEN); retvalue = false; } if (line[0] != '\n') diff --git a/src/map/setters.c b/src/map/setters.c index 0a82082..c3c003d 100644 --- a/src/map/setters.c +++ b/src/map/setters.c @@ -6,12 +6,13 @@ /* By: kcolin +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/06/21 19:35:43 by tchampio #+# #+# */ -/* Updated: 2025/07/31 14:08:27 by kcolin ### ########.fr */ +/* Updated: 2025/08/14 19:50:20 by tchampio ### ########.fr */ /* */ /* ************************************************************************** */ #include "../../libft/includes/libft.h" #include "../utils/frees.h" +#include "../consts.h" #include "mapdata.h" bool perform_color_checks(int *color, char *strcolor, t_mapdata *map) @@ -24,8 +25,7 @@ bool perform_color_checks(int *color, char *strcolor, t_mapdata *map) { if (!ft_isdigit(strcolor[i])) { - ft_strlcpy(map->error, "invalid characters in color definition", - ERRLEN); + ft_strlcpy(map->error, EBADCHARCOLOR, ERRLEN); return (false); } i++; @@ -33,7 +33,7 @@ bool perform_color_checks(int *color, char *strcolor, t_mapdata *map) colorvalue = ft_atoi(strcolor); if (colorvalue < 0 || colorvalue > 255) { - ft_strlcpy(map->error, "invalid value for colors", ERRLEN); + ft_strlcpy(map->error, EBADVALCOLOR, ERRLEN); return (false); } *color = colorvalue; @@ -53,14 +53,14 @@ unsigned int set_color(const char *s, t_mapdata *map) while (tab[i]) { if (i > 2) - ft_strlcpy(map->error, "too many colors", ERRLEN); + ft_strlcpy(map->error, ETOOMANYCOLORS, ERRLEN); isok = perform_color_checks(&rgb[i], tab[i], map); free(tab[i]); i++; } free(tab); if (i <= 2) - return (ft_strlcpy(map->error, "Not enough colors", ERRLEN), 0); + return (ft_strlcpy(map->error, ENOTENOUGHCOLORS, ERRLEN), 0); if (!isok) return (0); finalcolor = ((rgb[0] & 0xff) << 16) @@ -77,7 +77,7 @@ int try_set_texture(t_mapdata *map, char **texture, char *texture_name) { if (*texture != NULL) { - ft_strlcpy(map->error, "Duplicated texture directive", ERRLEN); + ft_strlcpy(map->error, EDUPTEX, ERRLEN); return (2); } *texture = ft_strdup(texture_name); @@ -99,7 +99,7 @@ int set_textures(char *line, t_mapdata *map) tab = ft_split(line, ' '); if (tab[0][0] == '1') return (free_tab(tab), ft_strlcpy(map->error, - "Map started before all the textures", ERRLEN), 1); + EMAPBFTEX, ERRLEN), 1); retvalue = 0; if (tab[0] && tab[1]) {