From fbc52949004a067a5c2cfefae1ff3415dbe04a96 Mon Sep 17 00:00:00 2001 From: Rudy Bousset Date: Sat, 15 Feb 2020 18:51:30 +0100 Subject: In progress --- src/ft_parse_map.c | 58 ++++++++++++++++++------------------------------------ 1 file changed, 19 insertions(+), 39 deletions(-) (limited to 'src/ft_parse_map.c') diff --git a/src/ft_parse_map.c b/src/ft_parse_map.c index 0e1a1e7..0eef871 100644 --- a/src/ft_parse_map.c +++ b/src/ft_parse_map.c @@ -17,32 +17,6 @@ #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); - ft_exit(6, clist); - } - i = 0; - while (words[i]) - i++; - if (ft_strncmp(words[i - 1], "cub", 3)) - { - ft_dprintf(STDERR_FILENO, "Error\n"); - ft_dprintf(STDERR_FILENO, "\033[31;1mMap is not a .cub\033[0m\n"); - ft_free_words(words); - ft_exit(6, clist); - } - ft_free_words(words); -} - static void ft_check_map_last_line(t_cub *clist) { @@ -58,16 +32,16 @@ static void while (ml->map[i - 1][j]) { if (ml->map[i - 1][j] != '1' && ml->map[i - 1][j] != '\0') - ft_map_error(clist); + ft_map_error(FT_ERR_MAP_L_L, clist); j++; } } static int8_t - ft_error_here(char *line, t_cub *clist) +ft_error_here(const char *errmsg, char *line, t_cub *clist) { ft_memdel((void**)&line); - return (ft_map_error(clist)); + return (ft_map_error(errmsg, clist)); } static int8_t @@ -79,9 +53,9 @@ static int8_t clist->mlist->line_chk += 1; if ((ret = get_next_line(fd, &line)) < 0) - return (ft_map_error(clist)); + return (ft_map_error(FT_ERR_READ, clist)); if (ret == 0) - return (ft_error_here(line, clist)); + return (ft_error_here(FT_ERR_UNFINISHED, line, clist)); if (!line[0]) { ft_memdel((void**)&line); @@ -89,31 +63,37 @@ static int8_t } if (!ft_ischarset("RNSEWFC1\0", line[0]) || !(words = ft_split(line, ' '))) - return (ft_error_here(line, clist)); + return (ft_error_here(FT_ERR_ILL_ENTRY, line, clist)); if ((ret = ft_select_get(words, clist)) == 12) return ((ft_get_map_first_line(line, clist) < 0) ? (-1) : (12)); ft_memdel((void**)&line); return (ret); } +static void + ft_no_map_error(t_cub *clist) +{ + ft_dprintf(STDERR_FILENO, "Error\n"); + ft_dprintf(STDERR_FILENO, "\033[31;1mNo map\033[0m\n"); + ft_exit(5, clist); +} + void ft_parse_map(const char *map_path, t_cub *clist) { int fd; int8_t ret; - ft_check_cub(map_path, clist); + if (ft_check_ext(map_path, ".cub") < 0) + ft_map_error(FT_ERR_NOT_A_CUB, 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(5, clist); - } + ft_no_map_error(clist); ret = 1; while (ret != 12 && ret != -1) ret = ft_parse_it(fd, clist); - (ret == -1) ? (ft_map_error(clist)) : 0; + (ret == -2) ? (ft_map_error(FT_ERR_ALR_SET, clist)) : 0; + (ret == -1) ? (ft_map_error(clist->errmsg, clist)) : 0; if (ft_get_map_core(fd, clist) < 0) ft_map_error(clist); ft_check_map_last_line(clist); -- cgit v1.2.3 From 030fe8c3316d1e1f5f3dea81c3fffd8e00c16afa Mon Sep 17 00:00:00 2001 From: Rudy Bousset Date: Sat, 15 Feb 2020 20:29:21 +0100 Subject: Work in progress, res now --- src/ft_parse_map.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/ft_parse_map.c') diff --git a/src/ft_parse_map.c b/src/ft_parse_map.c index 0eef871..c4aa011 100644 --- a/src/ft_parse_map.c +++ b/src/ft_parse_map.c @@ -90,12 +90,12 @@ void if (fd < 0) ft_no_map_error(clist); ret = 1; - while (ret != 12 && ret != -1) + while (ret != 12 && ret >= 0) ret = ft_parse_it(fd, clist); (ret == -2) ? (ft_map_error(FT_ERR_ALR_SET, clist)) : 0; (ret == -1) ? (ft_map_error(clist->errmsg, clist)) : 0; if (ft_get_map_core(fd, clist) < 0) - ft_map_error(clist); + ft_map_error(clist->errmsg, clist); ft_check_map_last_line(clist); ft_get_player_spawn(clist->plist, clist); ft_check_missing(clist); -- cgit v1.2.3 From e40442466e3f20f83a2d7755a6038bc3fc27fa8e Mon Sep 17 00:00:00 2001 From: Rudy Bousset Date: Mon, 17 Feb 2020 15:36:49 +0100 Subject: Norme --- src/ft_parse_map.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/ft_parse_map.c') diff --git a/src/ft_parse_map.c b/src/ft_parse_map.c index c4aa011..4fd870b 100644 --- a/src/ft_parse_map.c +++ b/src/ft_parse_map.c @@ -38,7 +38,7 @@ static void } static int8_t -ft_error_here(const char *errmsg, char *line, t_cub *clist) + ft_error_here(const char *errmsg, char *line, t_cub *clist) { ft_memdel((void**)&line); return (ft_map_error(errmsg, clist)); -- cgit v1.2.3