Khaïs COLIN 2025-07-23 13:31:58 +02:00
parent 2d3d614ab3
commit 6f0afd4543
Signed by: logistic-bot
SSH key fingerprint: SHA256:RlpiqKeXpcPFZZ4y9Ou4xi2M8OhRJovIwDlbCaMsuAo
3 changed files with 24 additions and 6 deletions

View file

@ -6,7 +6,7 @@
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */ /* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/06/06 17:54:42 by tchampio #+# #+# */ /* Created: 2025/06/06 17:54:42 by tchampio #+# #+# */
/* Updated: 2025/07/22 12:15:32 by kcolin ### ########.fr */ /* Updated: 2025/07/24 12:20:17 by kcolin ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -69,7 +69,8 @@ bool check_cubfile(char *file, t_mapdata *map)
return (close(fd), false); return (close(fd), false);
if (map->error[0]) if (map->error[0])
return (close(fd), false); return (close(fd), false);
populate_maps(map, fd); if (!populate_maps(map, fd))
return (close(fd), false);
if (!check_walls(map)) if (!check_walls(map))
return (close(fd), ft_strlcpy(map->error, return (close(fd), ft_strlcpy(map->error,
"Map is malformed (invalid chars or missing walls)", ERRLEN), "Map is malformed (invalid chars or missing walls)", ERRLEN),

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/21 15:23:47 by kcolin ### ########.fr */ /* Updated: 2025/07/23 13:34:33 by kcolin ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -52,17 +52,34 @@ void add_map_line(const char *line, t_mapdata *map)
map->mapflood = newmapflood; map->mapflood = newmapflood;
} }
void populate_maps(t_mapdata *map, int fd) /*
** return values:
** true: everything is fine
** false: error occured, caller should look at map->error
*/
bool populate_maps(t_mapdata *map, int fd)
{ {
char *line; char *line;
bool end_reached;
bool retvalue;
line = get_next_line(fd); line = get_next_line(fd);
end_reached = false;
retvalue = true;
while (line) while (line)
{ {
if (line[0] != '\n' && end_reached)
{
ft_strlcpy(map->error, "Trailing chars after map", ERRLEN);
retvalue = false;
}
if (line[0] != '\n') if (line[0] != '\n')
add_map_line(line, map); add_map_line(line, map);
if (line[0] == '\n')
end_reached = true;
free(line); free(line);
line = get_next_line(fd); line = get_next_line(fd);
} }
free(line); free(line);
return (retvalue);
} }

View file

@ -6,7 +6,7 @@
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */ /* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/07/21 15:24:31 by kcolin #+# #+# */ /* Created: 2025/07/21 15:24:31 by kcolin #+# #+# */
/* Updated: 2025/07/21 15:25:02 by kcolin ### ########.fr */ /* Updated: 2025/07/23 13:34:42 by kcolin ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -15,6 +15,6 @@
# include "mapdata.h" # include "mapdata.h"
void populate_maps(t_mapdata *map, int fd); bool populate_maps(t_mapdata *map, int fd);
#endif // POPULATE_MAP_H #endif // POPULATE_MAP_H