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.c40
1 files changed, 34 insertions, 6 deletions
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 <stddef.h>
#include <stdint.h>
+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++;