diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-03-04 00:17:54 +0100 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-03-04 00:17:54 +0100 |
commit | 46ed1046b3d8e9dfbb9438552582898c3c79a9f5 (patch) | |
tree | fd1d0c451944d55945375cceeda800ac6664cf27 /src/ft_get_map.c | |
parent | Map update (diff) | |
download | 42-cub3d-46ed1046b3d8e9dfbb9438552582898c3c79a9f5.tar.gz 42-cub3d-46ed1046b3d8e9dfbb9438552582898c3c79a9f5.tar.bz2 42-cub3d-46ed1046b3d8e9dfbb9438552582898c3c79a9f5.tar.xz 42-cub3d-46ed1046b3d8e9dfbb9438552582898c3c79a9f5.tar.zst 42-cub3d-46ed1046b3d8e9dfbb9438552582898c3c79a9f5.zip |
Chelou maps work, now sides check
Diffstat (limited to 'src/ft_get_map.c')
-rw-r--r-- | src/ft_get_map.c | 41 |
1 files changed, 14 insertions, 27 deletions
diff --git a/src/ft_get_map.c b/src/ft_get_map.c index fb8e0f2..08c9734 100644 --- a/src/ft_get_map.c +++ b/src/ft_get_map.c @@ -12,20 +12,10 @@ #include <libft.h> #include <cub3d.h> +#include <stdlib.h> #include <stddef.h> #include <stdint.h> -static size_t - ft_get_map_h(char **map) -{ - size_t i; - - i = 0; - while (map[i]) - i++; - return (i); -} - static void ft_linecpy(char *line, char *mapl, size_t start) { @@ -38,8 +28,6 @@ static void slen = ft_strlen(line); while (i < slen && line[i]) { - while (line[i] == ' ') - i++; mapl[j] = line[i]; i++; j++; @@ -48,16 +36,19 @@ static void } static int8_t - ft_cat_mapl(char *line, size_t i, t_cub *clist) + ft_cat_mapl(char *line, t_cub *clist) { - if (!(clist->mlist.mapl = (char *)ft_nrealloc(clist->mlist.mapl, - ((clist->mlist.map_w + 1) * i) * sizeof(char), - ((clist->mlist.map_w + 1) * (i + 1)) * sizeof(char)))) + if (!line[0] || + !(clist->mlist.mapl = (char *)ft_nrealloc(clist->mlist.mapl, + clist->mlist.mapl_len * sizeof(char), + (clist->mlist.mapl_len + ft_strlen(line) + 1) * sizeof(char)))) { ft_sprintf(clist->errmsg, FT_ERR_ALLOCATE); return (-1); } - ft_linecpy(line, clist->mlist.mapl, (clist->mlist.map_w + 1) * i); + ft_linecpy(line, clist->mlist.mapl, + clist->mlist.mapl_len); + clist->mlist.mapl_len += ft_strlen(line) + 1; return (0); } @@ -68,18 +59,16 @@ int if (!line[0]) { ft_memdel((void**)&line); - ft_sprintf(clist->errmsg, "%s", FT_ERR_READ); + ft_sprintf(clist->errmsg, FT_ERR_READ); return (-1); } - clist->mlist.map_w = ft_get_line_len(line); if (ft_check_map_line(line, 1, clist) < 0) { ft_memdel((void**)&line); - ft_sprintf(clist->errmsg, "%s", FT_ERR_READ); return (-1); } ft_memdel((void**)&clist->mlist.mapl); - if (ft_cat_mapl(line, 0, clist) < 0) + if (ft_cat_mapl(line, clist) < 0) { ft_memdel((void**)&line); return (-1); @@ -92,16 +81,14 @@ int ft_get_map_core(int fd, t_cub *clist) { int ret; - size_t i; char *line; - i = 1; ret = 1; while ((ret = get_next_line(fd, &line)) > 0) { clist->mlist.line_chk += 1; if (!line[0] || ft_check_map_line(line, 0, clist) < 0 - || ft_cat_mapl(line, i, clist) < 0) + || ft_cat_mapl(line, clist) < 0) { if (!line[0]) ft_sprintf(clist->errmsg, FT_ERR_MAP_EMPL); @@ -109,13 +96,13 @@ int return (-1); } ft_memdel((void**)&line); - i++; } ft_memdel((void**)&line); - clist->mlist.mapl[((clist->mlist.map_w + 1) * i) - 1] = '\0'; + clist->mlist.mapl[clist->mlist.mapl_len - 1] = '\0'; ft_free_words(clist->mlist.map); clist->mlist.map = ft_split(clist->mlist.mapl, '\n'); clist->mlist.map_h = ft_get_map_h(clist->mlist.map); + clist->mlist.map_w = ft_get_map_w(clist->mlist.map); ft_memdel((void**)&clist->mlist.mapl); return (0); } |