aboutsummaryrefslogtreecommitdiffstats
path: root/src/ft_get_map_redo.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ft_get_map_redo.c')
-rw-r--r--src/ft_get_map_redo.c54
1 files changed, 34 insertions, 20 deletions
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;