aboutsummaryrefslogtreecommitdiffstats
path: root/src/ft_check_map_line.c
diff options
context:
space:
mode:
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);
}