aboutsummaryrefslogtreecommitdiffstats
path: root/src/ft_check_map_line.c
diff options
context:
space:
mode:
authorRudy Bousset <rbousset@z2r4p3.le-101.fr>2020-02-17 15:57:18 +0100
committerRudy Bousset <rbousset@z2r4p3.le-101.fr>2020-02-17 15:57:18 +0100
commitac87f799abf2edbd95243f2343eda41faf30cca6 (patch)
treeb7238c2a1ec396281dacd0853cd60dfdb51476d2 /src/ft_check_map_line.c
parentNorme (diff)
download42-cub3d-ac87f799abf2edbd95243f2343eda41faf30cca6.tar.gz
42-cub3d-ac87f799abf2edbd95243f2343eda41faf30cca6.tar.bz2
42-cub3d-ac87f799abf2edbd95243f2343eda41faf30cca6.tar.xz
42-cub3d-ac87f799abf2edbd95243f2343eda41faf30cca6.tar.zst
42-cub3d-ac87f799abf2edbd95243f2343eda41faf30cca6.zip
Better parse
Diffstat (limited to '')
-rw-r--r--src/ft_check_map_line.c26
1 files changed, 21 insertions, 5 deletions
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);
}