From 030fe8c3316d1e1f5f3dea81c3fffd8e00c16afa Mon Sep 17 00:00:00 2001 From: Rudy Bousset Date: Sat, 15 Feb 2020 20:29:21 +0100 Subject: Work in progress, res now --- src/ft_check_map_line.c | 40 ++++++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 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 9e4e484..b41d052 100644 --- a/src/ft_check_map_line.c +++ b/src/ft_check_map_line.c @@ -15,6 +15,38 @@ #include #include +static int8_t + ft_first_checks(char *line, size_t i, t_cub *clist) +{ + if (!ft_ischarset("012NSEW ", line[i])) + { + ft_strlcpy(clist->errmsg, FT_ERR_ILL_MAP, + ft_strlen(FT_ERR_ILL_MAP) + 1); + return (-1); + } + if (ft_ischarset("NSEW", line[i])) + clist->mlist->isspawn += 1; + if (clist->mlist->isspawn > 1) + { + ft_strlcpy(clist->errmsg, FT_ERR_MULT_SPAWN, + ft_strlen(FT_ERR_MULT_SPAWN) + 1); + return (-1); + } + return (0); +} + +static int8_t + ft_second_checks(char *line, size_t i, t_cub *clist) +{ + if (!ft_ischarset("1 ", line[i])) + { + ft_strlcpy(clist->errmsg, FT_ERR_ILL_MAP, + ft_strlen(FT_ERR_ILL_MAP) + 1); + return (-1); + } + return (0); +} + size_t ft_get_line_len(char *line) { @@ -42,16 +74,12 @@ int8_t { if (l != 1) { - if (!ft_ischarset("012NSEW ", line[i])) - return (-1); - if (ft_ischarset("NSEW", line[i])) - clist->mlist->isspawn += 1; - if (clist->mlist->isspawn > 1) + if (ft_first_checks(line, i, clist) < 0) return (-1); } else { - if (!ft_ischarset("1 ", line[i])) + if (ft_second_checks(line, i, clist) < 0) return (-1); } i++; -- cgit v1.2.3 From e40442466e3f20f83a2d7755a6038bc3fc27fa8e Mon Sep 17 00:00:00 2001 From: Rudy Bousset Date: Mon, 17 Feb 2020 15:36:49 +0100 Subject: Norme --- src/ft_check_map_line.c | 6 +++--- 1 file changed, 3 insertions(+), 3 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 b41d052..7ab2731 100644 --- a/src/ft_check_map_line.c +++ b/src/ft_check_map_line.c @@ -21,7 +21,7 @@ static int8_t if (!ft_ischarset("012NSEW ", line[i])) { ft_strlcpy(clist->errmsg, FT_ERR_ILL_MAP, - ft_strlen(FT_ERR_ILL_MAP) + 1); + ft_strlen(FT_ERR_ILL_MAP) + 1); return (-1); } if (ft_ischarset("NSEW", line[i])) @@ -29,7 +29,7 @@ static int8_t if (clist->mlist->isspawn > 1) { ft_strlcpy(clist->errmsg, FT_ERR_MULT_SPAWN, - ft_strlen(FT_ERR_MULT_SPAWN) + 1); + ft_strlen(FT_ERR_MULT_SPAWN) + 1); return (-1); } return (0); @@ -41,7 +41,7 @@ static int8_t if (!ft_ischarset("1 ", line[i])) { ft_strlcpy(clist->errmsg, FT_ERR_ILL_MAP, - ft_strlen(FT_ERR_ILL_MAP) + 1); + ft_strlen(FT_ERR_ILL_MAP) + 1); return (-1); } return (0); -- cgit v1.2.3 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