aboutsummaryrefslogtreecommitdiffstats
path: root/src/ft_check_map_line.c
diff options
context:
space:
mode:
authorRudy Bousset <rbousset@z2r5p2.le-101.fr>2020-01-29 19:14:24 +0100
committerRudy Bousset <rbousset@z2r5p2.le-101.fr>2020-01-29 19:14:24 +0100
commit38a81ff5a1dcb2cd07e10330fcbedf665ff7bc05 (patch)
tree6023bb970371c979e1051393989fcba11cb09a3d /src/ft_check_map_line.c
parentChanged names (diff)
download42-cub3d-38a81ff5a1dcb2cd07e10330fcbedf665ff7bc05.tar.gz
42-cub3d-38a81ff5a1dcb2cd07e10330fcbedf665ff7bc05.tar.bz2
42-cub3d-38a81ff5a1dcb2cd07e10330fcbedf665ff7bc05.tar.xz
42-cub3d-38a81ff5a1dcb2cd07e10330fcbedf665ff7bc05.tar.zst
42-cub3d-38a81ff5a1dcb2cd07e10330fcbedf665ff7bc05.zip
C'est bav
Diffstat (limited to '')
-rw-r--r--src/ft_check_map_line.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/ft_check_map_line.c b/src/ft_check_map_line.c
new file mode 100644
index 0000000..1c8c6c6
--- /dev/null
+++ b/src/ft_check_map_line.c
@@ -0,0 +1,49 @@
+#include <libft.h>
+#include <cub3d.h>
+#include <stdint.h>
+
+size_t
+ft_get_line_len(char *line)
+{
+ size_t i;
+ size_t j;
+
+ i = 0;
+ j = 0;
+ while (line[i])
+ {
+ if (line[i] == ' ')
+ j++;
+ i++;
+ }
+ return (i - j);
+}
+
+int8_t
+ft_check_map_line(char *line, uint8_t l, t_cub *clist)
+{
+ size_t i;
+
+ i = 0;
+ while (line[i])
+ {
+ if (l != 1)
+ {
+ if (!ft_ischarset("012NSEW ", line[i]))
+ return (-1);
+ if (ft_ischarset("NSEW", line[i]))
+ clist->nsew += 1;
+ if (clist->nsew > 1)
+ return (-1);
+ }
+ else
+ {
+ if (!ft_ischarset("1 ", line[i]))
+ return (-1);
+ }
+ i++;
+ }
+ if (line[0] != '1' || line[i - 1] != '1')
+ return (-1);
+ return (0);
+}