From ac87f799abf2edbd95243f2343eda41faf30cca6 Mon Sep 17 00:00:00 2001 From: Rudy Bousset Date: Mon, 17 Feb 2020 15:57:18 +0100 Subject: Better parse --- src/ft_check_map_line.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'src/ft_check_map_line.c') 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); } -- cgit v1.2.3