mirror of
https://codeberg.org/ACME-Corporation/cub3d.git
synced 2025-12-06 09:58:09 +01:00
fix: give error for trailing chars after map
https://www.notion.so/Pas-d-erreur-detect-pour-une-map-avec-des-characters-apres-la-map-239551de06f480bc8f07e3fbe844ecd7?v=233551de06f480718417000cf26e3225&source=copy_link
This commit is contained in:
parent
2d3d614ab3
commit
3543807548
3 changed files with 24 additions and 6 deletions
|
|
@ -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),
|
||||||
|
|
|
||||||
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue