diff options
Diffstat (limited to 'src/ft_parse_map.c')
-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); } |