aboutsummaryrefslogtreecommitdiffstats
path: root/src
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
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
-rw-r--r--src/ft_get_map_redo.c54
2 files changed, 83 insertions, 20 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);
+}
diff --git a/src/ft_get_map_redo.c b/src/ft_get_map_redo.c
index 869f432..e337849 100644
--- a/src/ft_get_map_redo.c
+++ b/src/ft_get_map_redo.c
@@ -1,34 +1,38 @@
#include <libft.h>
#include <cub3d.h>
#include <stddef.h>
-#include <stdlib.h>
+#include <stdint.h>
-static int8_t
-ft_check_line(char *line, uint8_t l, t_cub *clist)
+static void
+ft_linecpy(char *line, char *mapl, size_t start)
{
size_t i;
+ size_t j;
+ size_t slen;
i = 0;
- while (line[i])
+ j = start;
+ slen = ft_strlen(line);
+ while (i < slen && 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);
- }
+ while (line[i] == ' ')
+ i++;
+ mapl[j] = line[i];
i++;
+ j++;
}
- if (line[0] != '1' || line[i - 1] != '1')
+ mapl[j] = '\0';
+}
+
+static int8_t
+ft_cat_mapl(char *line, size_t i, t_cub *clist)
+{
+ if (!(clist->mapl = (char *)ft_nrealloc(clist->mapl,
+ ((clist->map_w + 1) * i) * sizeof(char),
+ ((clist->map_w + 1) * (i + 1)) * sizeof(char))))
return (-1);
+ ft_linecpy(line, clist->mapl, (clist->map_w + 1) * i);
+ ft_printf("mapl >>>> [%s]\n", clist->mapl);
return (0);
}
@@ -40,11 +44,19 @@ ft_get_map_first_line(char *line, t_cub *clist)
ft_memdel(line);
return (-1);
}
- if (ft_check_line(line, 1, clist) < 0)
+ if (ft_check_map_line(line, 1, clist) < 0)
{
ft_memdel(line);
return (-1);
}
+ clist->map_w = ft_get_line_len(line);
+ clist->mapl = NULL;
+ if ((clist->mapl = ft_cat_mapl(line, 0, clist)) < 0)
+ {
+ ft_memdel(line);
+ return (-1);
+ }
+ ft_memdel(line);
return (1);
}
@@ -52,7 +64,9 @@ int
ft_get_map_core(int fd, t_cub *clist)
{
int ret;
+ size_t i;
+ i = 1;
(void)fd;
(void)ret;
(void)clist;