#include #include #include #include #include static void ft_check_cub(const char *map_path, t_cub *clist) { char **words; size_t i; if (!(words = ft_split(map_path, '.'))) { ft_dprintf(STDERR_FILENO, "Error\n"); ft_dprintf(STDERR_FILENO, "\033[31;1mMap is not a .cub\033[0m\n"); ft_free_words(words, NULL); ft_exit(2, clist); } i = 0; while (words[i]) i++; if (ft_strcmp(words[i - 1], "cub")) { ft_dprintf(STDERR_FILENO, "Error\n"); ft_dprintf(STDERR_FILENO, "\033[31;1mMap is not a .cub\033[0m\n"); ft_free_words(words, NULL); ft_exit(2, clist); } ft_free_words(words, NULL); } static void ft_check_last_line(t_cub *clist) { size_t i; size_t j; i = 0; while (clist->map[i]) i++; j = 0; while (clist->map[i - 1][j]) { if (clist->map[i - 1][j] != '1' && clist->map[i - 1][j] != '\0') ft_map_error(11 + i - 1, clist); j++; } } /* ** I can't close fd */ void ft_parse_map(const char *map_path, t_cub *clist) { int fd; ft_check_cub(map_path, clist); fd = open(map_path, O_RDONLY); if (fd < 0) { ft_dprintf(STDERR_FILENO, "Error\n"); ft_dprintf(STDERR_FILENO, "\033[31;1mNo map\033[0m\n"); ft_exit(2, clist); } ft_get_res(fd, clist); if (ft_get_tex(fd, clist) < 0) return ; ft_check_empty_line(fd, 6, clist); if (ft_get_sprite_tex(fd, clist) < 0) return ; ft_get_colors(fd, 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_print_list(clist); close(fd); }