mirror of
https://codeberg.org/ACME-Corporation/cub3d.git
synced 2025-12-06 09:58:09 +01:00
style: use a constant for error message length
relates to, but does not full resolve: https://www.notion.so/Constante-Magique-dans-le-code-233551de06f480ef9687fa3d711db137?v=233551de06f480718417000cf26e3225&source=copy_link
This commit is contained in:
parent
d7ca150c74
commit
6aecc3ba6e
3 changed files with 20 additions and 15 deletions
|
|
@ -6,12 +6,13 @@
|
|||
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/06/06 17:54:42 by tchampio #+# #+# */
|
||||
/* Updated: 2025/07/21 15:27:15 by kcolin ### ########.fr */
|
||||
/* Updated: 2025/07/22 12:15:32 by kcolin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../../libft/includes/libft.h"
|
||||
#include "../utils/colors.h"
|
||||
#include "mapdata.h"
|
||||
#include "populate_map.h"
|
||||
#include "checkers.h"
|
||||
#include "setters.h"
|
||||
|
|
@ -60,10 +61,10 @@ bool check_cubfile(char *file, t_mapdata *map)
|
|||
int fd;
|
||||
|
||||
if (!check_filename(map, file))
|
||||
return (ft_strlcpy(map->error, "File is not a .cub file", 25), false);
|
||||
return (ft_strlcpy(map->error, "Not a .cub file", ERRLEN), false);
|
||||
fd = open(file, O_RDONLY);
|
||||
if (fd < 0)
|
||||
return (ft_strlcpy(map->error, "Can't open file", 16), false);
|
||||
return (ft_strlcpy(map->error, "Can't open file", ERRLEN), false);
|
||||
if (add_textures(fd, map) != 0)
|
||||
return (close(fd), false);
|
||||
if (map->error[0])
|
||||
|
|
@ -71,13 +72,14 @@ bool check_cubfile(char *file, t_mapdata *map)
|
|||
populate_maps(map, fd);
|
||||
if (!check_walls(map))
|
||||
return (close(fd), ft_strlcpy(map->error,
|
||||
"Map is malformed (invalid chars or missing walls)", 51),
|
||||
"Map is malformed (invalid chars or missing walls)", ERRLEN),
|
||||
false);
|
||||
if (!check_bare_minimum(map))
|
||||
return (close(fd), ft_strlcpy(map->error, "No players", 11), false);
|
||||
return (close(fd), ft_strlcpy(map->error, "No player", ERRLEN), false);
|
||||
map->isvalid = true;
|
||||
flood_fill(map, map->startx, map->starty);
|
||||
if (!map->isvalid)
|
||||
return (close(fd), ft_strlcpy(map->error, "Map has holes!", 16), false);
|
||||
return (close(fd), ft_strlcpy(map->error, "Holes in map", ERRLEN),
|
||||
false);
|
||||
return (true);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/07/17 14:58:19 by kcolin #+# #+# */
|
||||
/* Updated: 2025/07/22 12:20:12 by tchampio ### ########.fr */
|
||||
/* Updated: 2025/07/22 12:36:53 by kcolin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -23,6 +23,8 @@ typedef enum e_direction
|
|||
WEST
|
||||
} t_direction;
|
||||
|
||||
# define ERRLEN 1024
|
||||
|
||||
typedef struct s_mapdata
|
||||
{
|
||||
char *filename;
|
||||
|
|
@ -40,7 +42,7 @@ typedef struct s_mapdata
|
|||
int startx;
|
||||
int starty;
|
||||
t_direction startdirection;
|
||||
char error[1024];
|
||||
char error[ERRLEN];
|
||||
} t_mapdata;
|
||||
|
||||
#endif // MAPDATA_H
|
||||
|
|
|
|||
|
|
@ -6,12 +6,13 @@
|
|||
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/06/21 19:35:43 by tchampio #+# #+# */
|
||||
/* Updated: 2025/07/22 12:20:29 by tchampio ### ########.fr */
|
||||
/* Updated: 2025/07/22 12:36:22 by kcolin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../../libft/includes/libft.h"
|
||||
#include "../utils/frees.h"
|
||||
#include "mapdata.h"
|
||||
|
||||
bool perform_color_checks(int *color, char *strcolor, t_mapdata *map)
|
||||
{
|
||||
|
|
@ -24,7 +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",
|
||||
1024);
|
||||
ERRLEN);
|
||||
return (false);
|
||||
}
|
||||
i++;
|
||||
|
|
@ -32,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", 1024);
|
||||
ft_strlcpy(map->error, "invalid value for colors", ERRLEN);
|
||||
return (false);
|
||||
}
|
||||
*color = colorvalue;
|
||||
|
|
@ -52,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", 16);
|
||||
ft_strlcpy(map->error, "too many colors", 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", 18), 0);
|
||||
return (ft_strlcpy(map->error, "Not enough colors", ERRLEN), 0);
|
||||
if (!isok)
|
||||
return (0);
|
||||
finalcolor = ((rgb[0] & 0xff) << 16)
|
||||
|
|
@ -76,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", 1024);
|
||||
ft_strlcpy(map->error, "Duplicated texture directive", ERRLEN);
|
||||
return (2);
|
||||
}
|
||||
*texture = ft_strdup(texture_name);
|
||||
|
|
@ -97,7 +98,7 @@ int set_textures(char *line, t_mapdata *map)
|
|||
tab = ft_split(line, ' ');
|
||||
if (tab[0][0] == '1')
|
||||
return (ft_strlcpy(map->error,
|
||||
"Map started before all the textures", 1024), 1);
|
||||
"Map started before all the textures", ERRLEN), 1);
|
||||
retvalue = 0;
|
||||
if (tab[0] && tab[1])
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue