diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-01-28 15:19:25 +0100 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-01-28 15:19:25 +0100 |
commit | becd4588f7bce0823228f721bffe40ee2e3bd68c (patch) | |
tree | dda3788b46d5a68c8c3a702631fcebc85c8607eb /src/ft_parse_map.c | |
parent | Wonderful my entier parsing is wrong (diff) | |
download | 42-cub3d-becd4588f7bce0823228f721bffe40ee2e3bd68c.tar.gz 42-cub3d-becd4588f7bce0823228f721bffe40ee2e3bd68c.tar.bz2 42-cub3d-becd4588f7bce0823228f721bffe40ee2e3bd68c.tar.xz 42-cub3d-becd4588f7bce0823228f721bffe40ee2e3bd68c.tar.zst 42-cub3d-becd4588f7bce0823228f721bffe40ee2e3bd68c.zip |
Everything is terrible but this might work
Diffstat (limited to '')
-rw-r--r-- | src/ft_parse_map.c | 31 |
1 files changed, 26 insertions, 5 deletions
diff --git a/src/ft_parse_map.c b/src/ft_parse_map.c index 1911e5c..c94a91b 100644 --- a/src/ft_parse_map.c +++ b/src/ft_parse_map.c @@ -31,7 +31,7 @@ ft_check_cub(const char *map_path, t_cub *clist) } static void -ft_check_last_line(t_cub *clist) +ft_check_map_last_line(t_cub *clist) { size_t i; size_t j; @@ -48,9 +48,30 @@ ft_check_last_line(t_cub *clist) } } -/* -** I can't close fd -*/ +static int +ft_parse_it(int fd, t_cub *clist) +{ + char *line; + char **words; + + if (get_next_line(fd, &line) <= 0) + { + ft_memdel(line); + return (ft_map_error(clist->line_chk, clist)); + } + if (!line[0]) + { + ft_memdel(line); + return (ft_parse_it(fd, clist)); + } + if (!(words = ft_split(line, ' '))) + { + ft_memdel(line); + return (ft_map_error(clist->line_chk, clist)); + } + ft_memdel(line); + return (ft_select_get(words, clist)); +} void ft_parse_map(const char *map_path, t_cub *clist) @@ -75,7 +96,7 @@ ft_parse_map(const char *map_path, t_cub *clist) ft_check_empty_line(fd, 10, clist); if (ft_get_map(fd, clist) < 0) ft_map_error(11, clist); - ft_check_last_line(clist); + ft_check_map_last_line(clist); ft_print_list(clist); close(fd); } |