diff options
-rw-r--r-- | inc/cub3d_defines.h | 3 | ||||
-rw-r--r-- | src/ft_check_map_line.c | 26 |
2 files changed, 23 insertions, 6 deletions
diff --git a/inc/cub3d_defines.h b/inc/cub3d_defines.h index e9a9a7d..0c9a294 100644 --- a/inc/cub3d_defines.h +++ b/inc/cub3d_defines.h @@ -67,8 +67,9 @@ # define FT_ERR_COLOR_ALPHA "colors should be digits only" # define FT_ERR_COLOR_MAX "colors should be maximum 255" # define FT_ERR_COLOR_ARGS "colors three numbers separated by commas" -# define FT_ERR_ILL_ENTRY "illegal map entry" # define FT_ERR_UNFINISHED "no map" +# define FT_ERR_MAP_LEN "map length inconsistency" +# define FT_ERR_ILL_ENTRY "illegal map entry" # define FT_ERR_ALR_SET "duplicate entry" # define FT_ERR_ILL_MAP "map contains illegal char" # define FT_ERR_MULT_SPAWN "multiple spawn points" diff --git a/src/ft_check_map_line.c b/src/ft_check_map_line.c index 7ab2731..1009aa3 100644 --- a/src/ft_check_map_line.c +++ b/src/ft_check_map_line.c @@ -64,13 +64,25 @@ size_t return (i - j); } +static int8_t + ft_check_side_walls(char *line, size_t i, t_cub *clist) +{ + if (line[0] != '1' || line[i - 1] != '1') + { + ft_strlcpy(clist->errmsg, FT_ERR_ILL_ENTRY, + ft_strlen(FT_ERR_ILL_ENTRY) + 1); + return (-1); + } + return (0); +} + int8_t ft_check_map_line(char *line, uint8_t l, t_cub *clist) { size_t i; - i = 0; - while (line[i]) + i = -1; + while (line[++i]) { if (l != 1) { @@ -82,10 +94,14 @@ int8_t if (ft_second_checks(line, i, clist) < 0) return (-1); } - i++; } - if (line[0] != '1' || line[i - 1] != '1' - || ft_get_line_len(line) != clist->mlist->map_w) + if (ft_check_side_walls(line, i, clist) < 0) return (-1); + if (ft_get_line_len(line) != clist->mlist->map_w) + { + ft_strlcpy(clist->errmsg, FT_ERR_MAP_LEN, + ft_strlen(FT_ERR_MAP_LEN) + 1); + return (-1); + } return (0); } |