fix: Transferred trailing magic error messages as consts

This commit is contained in:
Theo Champion 2025-08-14 19:52:34 +02:00
parent db66decbf8
commit 412dc89336
3 changed files with 18 additions and 11 deletions

View file

@ -6,7 +6,7 @@
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */ /* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/07/17 14:54:36 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 EMALMAP "Map is malformed (invalid chars or missing walls)"
# define ENOPLAYER "No player" # define ENOPLAYER "No player"
# define EHOLES "Holes in map" # 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 #endif

View file

@ -6,7 +6,7 @@
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */ /* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/07/17 14:44:02 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) if (line[0] != '\n' && end_reached)
{ {
ft_strlcpy(map->error, "Trailing chars after map", ERRLEN); ft_strlcpy(map->error, ETRAILING, ERRLEN);
retvalue = false; retvalue = false;
} }
if (line[0] != '\n') if (line[0] != '\n')

View file

@ -6,12 +6,13 @@
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */ /* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/06/21 19:35:43 by tchampio #+# #+# */ /* 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 "../../libft/includes/libft.h"
#include "../utils/frees.h" #include "../utils/frees.h"
#include "../consts.h"
#include "mapdata.h" #include "mapdata.h"
bool perform_color_checks(int *color, char *strcolor, t_mapdata *map) 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])) if (!ft_isdigit(strcolor[i]))
{ {
ft_strlcpy(map->error, "invalid characters in color definition", ft_strlcpy(map->error, EBADCHARCOLOR, ERRLEN);
ERRLEN);
return (false); return (false);
} }
i++; i++;
@ -33,7 +33,7 @@ bool perform_color_checks(int *color, char *strcolor, t_mapdata *map)
colorvalue = ft_atoi(strcolor); colorvalue = ft_atoi(strcolor);
if (colorvalue < 0 || colorvalue > 255) if (colorvalue < 0 || colorvalue > 255)
{ {
ft_strlcpy(map->error, "invalid value for colors", ERRLEN); ft_strlcpy(map->error, EBADVALCOLOR, ERRLEN);
return (false); return (false);
} }
*color = colorvalue; *color = colorvalue;
@ -53,14 +53,14 @@ unsigned int set_color(const char *s, t_mapdata *map)
while (tab[i]) while (tab[i])
{ {
if (i > 2) 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); isok = perform_color_checks(&rgb[i], tab[i], map);
free(tab[i]); free(tab[i]);
i++; i++;
} }
free(tab); free(tab);
if (i <= 2) if (i <= 2)
return (ft_strlcpy(map->error, "Not enough colors", ERRLEN), 0); return (ft_strlcpy(map->error, ENOTENOUGHCOLORS, ERRLEN), 0);
if (!isok) if (!isok)
return (0); return (0);
finalcolor = ((rgb[0] & 0xff) << 16) finalcolor = ((rgb[0] & 0xff) << 16)
@ -77,7 +77,7 @@ int try_set_texture(t_mapdata *map, char **texture, char *texture_name)
{ {
if (*texture != NULL) if (*texture != NULL)
{ {
ft_strlcpy(map->error, "Duplicated texture directive", ERRLEN); ft_strlcpy(map->error, EDUPTEX, ERRLEN);
return (2); return (2);
} }
*texture = ft_strdup(texture_name); *texture = ft_strdup(texture_name);
@ -99,7 +99,7 @@ int set_textures(char *line, t_mapdata *map)
tab = ft_split(line, ' '); tab = ft_split(line, ' ');
if (tab[0][0] == '1') if (tab[0][0] == '1')
return (free_tab(tab), ft_strlcpy(map->error, return (free_tab(tab), ft_strlcpy(map->error,
"Map started before all the textures", ERRLEN), 1); EMAPBFTEX, ERRLEN), 1);
retvalue = 0; retvalue = 0;
if (tab[0] && tab[1]) if (tab[0] && tab[1])
{ {