aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRudy Bousset <rbousset@z2r5p2.le-101.fr>2020-01-27 17:50:39 +0100
committerRudy Bousset <rbousset@z2r5p2.le-101.fr>2020-01-27 17:50:39 +0100
commitf1665c083bc156008082c76dbf1c031eeb9df341 (patch)
tree02ee5925ba40144c19bd1ea608537a0f3b0ab503 /src
parentCan't believe it (diff)
download42-cub3d-f1665c083bc156008082c76dbf1c031eeb9df341.tar.gz
42-cub3d-f1665c083bc156008082c76dbf1c031eeb9df341.tar.bz2
42-cub3d-f1665c083bc156008082c76dbf1c031eeb9df341.tar.xz
42-cub3d-f1665c083bc156008082c76dbf1c031eeb9df341.tar.zst
42-cub3d-f1665c083bc156008082c76dbf1c031eeb9df341.zip
quick commit
Diffstat (limited to 'src')
-rw-r--r--src/ft_get_map.c63
-rw-r--r--src/ft_print_list.c8
2 files changed, 68 insertions, 3 deletions
diff --git a/src/ft_get_map.c b/src/ft_get_map.c
index a45052c..1c672e6 100644
--- a/src/ft_get_map.c
+++ b/src/ft_get_map.c
@@ -3,18 +3,75 @@
#include <stddef.h>
#include <stdlib.h>
+/* static char */
+/* **ft_split_lines(char *line, int count) */
+/* { */
+/* } */
+
+static int
+ft_linecpy(char *line, char *mapL)
+{
+ size_t i;
+
+ i = 0;
+ while (i < ft_strlen(line))
+ {
+ mapL[i] = line[i];
+ i += 2;
+ }
+ mapL[i + 1] = '\n';
+ return (0);
+}
+
+static int
+ft_check_err(char *line, size_t size, t_win *wlist)
+{
+ size_t i;
+
+ i = 1;
+ if (ft_strlen(line) != size)
+ return (-1);
+ while (i < ft_strlen(line) && line[i])
+ {
+ if (line[i] != ' ')
+ return (ft_map_error(11, wlist));
+ i += 2;
+ }
+ return (0);
+}
int
ft_get_map(int fd, t_win *wlist)
{
size_t i;
+ size_t len;
char *line;
+ char *mapL;
- ft_free_words(wlist->clist->map, NULL);
- i = 0;
- if (!(wlist->clist->map = (char**)malloc(40 * sizeof(char*))))
+ /* ft_free_words(wlist->clist->map, NULL); */
+ /* if (!(wlist->clist->map = (char**)malloc(40 * sizeof(char*)))) */
+ /* return (-1); */
+ if (get_next_line(fd, &line) > 0)
+ {
+ len = ft_strlen(line);
+ ft_check_err(line, len, wlist);
+ if (!(mapL = (char*)malloc((len + 1) * sizeof(char))))
+ ft_linecpy(line, mapL);
+ ft_memdel(line);
+ }
+ else
return (-1);
+ i = 1;
while (get_next_line(fd, &line) > 0)
{
+ ft_check_err(line, len, wlist);
+ mapL = (char*)ft_nrealloc(mapL, ((len + 1) * i) * sizeof(char), (((len + 1) * i) + ft_strlen(line) + 1) * sizeof(char));
+ ft_linecpy(line, mapL);
+ ft_memdel(line);
+ i++;
}
+ mapL[(i * (len + 1)) + 1] = '\0';
+ ft_printf("mapL [%s]\n", mapL);
+ wlist->clist->map = ft_split(mapL, '\n');
+ ft_memdel(mapL);
return (0);
}
diff --git a/src/ft_print_list.c b/src/ft_print_list.c
index 547bdb2..f038740 100644
--- a/src/ft_print_list.c
+++ b/src/ft_print_list.c
@@ -4,6 +4,8 @@
void
ft_print_list(t_win *wlist)
{
+ size_t i;
+
ft_printf("x size [%d]\n", wlist->x_size);
ft_printf("y size [%d]\n", wlist->y_size);
ft_printf("North - [%s]\n", wlist->clist->no_tex_path);
@@ -13,4 +15,10 @@ ft_print_list(t_win *wlist)
ft_printf("Sprite [%s]\n", wlist->clist->sprite_path);
ft_printf("F color [%d]\n", wlist->clist->f_color);
ft_printf("C color [%d]\n", wlist->clist->c_color);
+ i = 0;
+ while (wlist->clist->map[i])
+ {
+ ft_printf("Map Line %zu [%s]\n", i + 1, wlist->clist->map[i]);
+ i++;
+ }
}