diff options
author | Rudy Bousset <rbousset@z2r4p3.le-101.fr> | 2020-02-17 16:25:11 +0100 |
---|---|---|
committer | Rudy Bousset <rbousset@z2r4p3.le-101.fr> | 2020-02-17 16:25:11 +0100 |
commit | 4f207400fd8e6724d321b6f2fa79fba5f16f9d59 (patch) | |
tree | 3896037d8a5938044bd6b6d49a18ad6305b948f0 /src | |
parent | Added libbsd to linux Makefile (diff) | |
parent | ready to merge (diff) | |
download | 42-cub3d-4f207400fd8e6724d321b6f2fa79fba5f16f9d59.tar.gz 42-cub3d-4f207400fd8e6724d321b6f2fa79fba5f16f9d59.tar.bz2 42-cub3d-4f207400fd8e6724d321b6f2fa79fba5f16f9d59.tar.xz 42-cub3d-4f207400fd8e6724d321b6f2fa79fba5f16f9d59.tar.zst 42-cub3d-4f207400fd8e6724d321b6f2fa79fba5f16f9d59.zip |
Merge branch 'better_parse'
Diffstat (limited to 'src')
-rw-r--r-- | src/ft_check_ext.c | 25 | ||||
-rw-r--r-- | src/ft_check_map_line.c | 66 | ||||
-rw-r--r-- | src/ft_draw_verline.c | 4 | ||||
-rw-r--r-- | src/ft_exit.c | 2 | ||||
-rw-r--r-- | src/ft_get_colors.c | 86 | ||||
-rw-r--r-- | src/ft_get_map.c | 6 | ||||
-rw-r--r-- | src/ft_get_res.c | 26 | ||||
-rw-r--r-- | src/ft_get_screen_size.c | 4 | ||||
-rw-r--r-- | src/ft_get_sprite.c | 14 | ||||
-rw-r--r-- | src/ft_get_tex.c | 52 | ||||
-rw-r--r-- | src/ft_init_lists.c | 1 | ||||
-rw-r--r-- | src/ft_init_winlx.c | 2 | ||||
-rw-r--r-- | src/ft_map_error.c | 6 | ||||
-rw-r--r-- | src/ft_parse_map.c | 62 | ||||
-rw-r--r-- | src/ft_raycasting.c | 2 | ||||
-rw-r--r-- | src/ft_select_get.c | 2 |
16 files changed, 272 insertions, 88 deletions
diff --git a/src/ft_check_ext.c b/src/ft_check_ext.c new file mode 100644 index 0000000..9a953d0 --- /dev/null +++ b/src/ft_check_ext.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_check_ext.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/17 15:33:28 by rbousset #+# #+# */ +/* Updated: 2020/02/17 15:33:29 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#include <libft.h> +#include <stdint.h> + +int8_t + ft_check_ext(const char *filep, const char *ext) +{ + const uint8_t extlen = ft_strlen(ext); + + if (ft_strncmp(filep + (ft_strlen(filep) - extlen), ext, extlen)) + return (-1); + else + return (0); +} diff --git a/src/ft_check_map_line.c b/src/ft_check_map_line.c index 9e4e484..1009aa3 100644 --- a/src/ft_check_map_line.c +++ b/src/ft_check_map_line.c @@ -15,6 +15,38 @@ #include <stddef.h> #include <stdint.h> +static int8_t + ft_first_checks(char *line, size_t i, t_cub *clist) +{ + if (!ft_ischarset("012NSEW ", line[i])) + { + ft_strlcpy(clist->errmsg, FT_ERR_ILL_MAP, + ft_strlen(FT_ERR_ILL_MAP) + 1); + return (-1); + } + if (ft_ischarset("NSEW", line[i])) + clist->mlist->isspawn += 1; + if (clist->mlist->isspawn > 1) + { + ft_strlcpy(clist->errmsg, FT_ERR_MULT_SPAWN, + ft_strlen(FT_ERR_MULT_SPAWN) + 1); + return (-1); + } + return (0); +} + +static int8_t + ft_second_checks(char *line, size_t i, t_cub *clist) +{ + if (!ft_ischarset("1 ", line[i])) + { + ft_strlcpy(clist->errmsg, FT_ERR_ILL_MAP, + ft_strlen(FT_ERR_ILL_MAP) + 1); + return (-1); + } + return (0); +} + size_t ft_get_line_len(char *line) { @@ -32,32 +64,44 @@ size_t return (i - j); } +static int8_t + ft_check_side_walls(char *line, size_t i, t_cub *clist) +{ + if (line[0] != '1' || line[i - 1] != '1') + { + ft_strlcpy(clist->errmsg, FT_ERR_ILL_ENTRY, + ft_strlen(FT_ERR_ILL_ENTRY) + 1); + return (-1); + } + return (0); +} + int8_t ft_check_map_line(char *line, uint8_t l, t_cub *clist) { size_t i; - i = 0; - while (line[i]) + i = -1; + while (line[++i]) { if (l != 1) { - if (!ft_ischarset("012NSEW ", line[i])) - return (-1); - if (ft_ischarset("NSEW", line[i])) - clist->mlist->isspawn += 1; - if (clist->mlist->isspawn > 1) + if (ft_first_checks(line, i, clist) < 0) return (-1); } else { - if (!ft_ischarset("1 ", line[i])) + if (ft_second_checks(line, i, clist) < 0) return (-1); } - i++; } - if (line[0] != '1' || line[i - 1] != '1' - || ft_get_line_len(line) != clist->mlist->map_w) + if (ft_check_side_walls(line, i, clist) < 0) return (-1); + if (ft_get_line_len(line) != clist->mlist->map_w) + { + ft_strlcpy(clist->errmsg, FT_ERR_MAP_LEN, + ft_strlen(FT_ERR_MAP_LEN) + 1); + return (-1); + } return (0); } diff --git a/src/ft_draw_verline.c b/src/ft_draw_verline.c index d7ebe34..5c5ed29 100644 --- a/src/ft_draw_verline.c +++ b/src/ft_draw_verline.c @@ -15,7 +15,7 @@ static void ft_draw_floor(t_cub *cl, int32_t y, int32_t x) { - while (y < cl->wlist->y_size) + while ((uint32_t)y < cl->wlist->y_size) { *(int*)(cl->img.ptr + (x * 4 + (y * cl->img.sizeline))) = ft_rgb_to_hex(cl->f_rgb); @@ -47,7 +47,7 @@ int8_t y1 = 0; if (y2 < 0) y2 = 0; - if (y2 >= cl->wlist->y_size) + if ((uint32_t)y2 >= cl->wlist->y_size) y2 = cl->wlist->x_size - 1; if (y1 > y2) { diff --git a/src/ft_exit.c b/src/ft_exit.c index d4b69ba..f0a94a3 100644 --- a/src/ft_exit.c +++ b/src/ft_exit.c @@ -43,8 +43,6 @@ int mlx_destroy_window(clist->wlist->wlx, clist->wlist->winptr); ft_free_lists(clist); ft_printf("Exiting program\n"); - if (exit_code < 0 || exit_code > 0) - ft_printf("Exit code: %hhu\n", exit_code); exit(exit_code); return (0); } diff --git a/src/ft_get_colors.c b/src/ft_get_colors.c index 869dd71..f54fabc 100644 --- a/src/ft_get_colors.c +++ b/src/ft_get_colors.c @@ -13,17 +13,57 @@ #include <libft.h> #include <cub3d.h> #include <stddef.h> +#include <stdint.h> -static int - ft_check_digits(const char *word) +static int8_t + ft_check_color_digits(char **num, t_cub *clist) { size_t i; + uint8_t j; i = 0; - while (ft_isdigit(word[i])) - i++; - if (i != ft_strlen(word)) + j = 0; + while (j < 3) + { + while (ft_isdigit(num[j][i])) + i++; + if (i != ft_strlen(num[j])) + { + ft_free_words(num); + ft_strlcpy(clist->errmsg, FT_ERR_COLOR_ALPHA, + ft_strlen(FT_ERR_COLOR_ALPHA) + 1); + return (-1); + } + i = 0; + j++; + } + return (0); +} + +static int8_t + ft_check_max_int(char **num, t_cub *clist) +{ + if (ft_atoi(num[0]) > 255 || ft_atoi(num[1]) > 255 + || ft_atoi(num[2]) > 255) + { + ft_strlcpy(clist->errmsg, FT_ERR_COLOR_MAX, + ft_strlen(FT_ERR_COLOR_MAX) + 1); + ft_free_words(num); + return (-1); + } + return (0); +} + +static int8_t + ft_check_nums_amount(char **num, t_cub *clist) +{ + if (!num[0] || !num[1] || !num[2] || num[3]) + { + ft_strlcpy(clist->errmsg, FT_ERR_COLOR_ARGS, + ft_strlen(FT_ERR_COLOR_ARGS) + 1); + ft_free_words(num); return (-1); + } return (0); } @@ -33,17 +73,22 @@ int8_t char **num; if (!(*words) || !words[1] || words[2]) + { + ft_strlcpy(clist->errmsg, FT_ERR_ARGS, ft_strlen(FT_ERR_ARGS) + 1); return (-1); + } if (!(num = ft_split(words[1], ','))) - return (-1); - if (!num[0] || !num[1] || !num[2] || num[3] || - ft_check_digits(num[0]) || ft_check_digits(num[1]) || - ft_check_digits(num[2]) || ft_atoi(num[0]) > 255 || - ft_atoi(num[1]) > 255 || ft_atoi(num[2]) > 255) { - ft_free_words(num); + ft_strlcpy(clist->errmsg, FT_ERR_ALLOCATE, + ft_strlen(FT_ERR_ALLOCATE) + 1); return (-1); } + if (ft_check_nums_amount(num, clist) < 0) + return (-1); + if (ft_check_color_digits(num, clist) < 0) + return (-1); + if (ft_check_max_int(num, clist) < 0) + return (-1); clist->f_rgb.r = ft_atoi(num[0]); clist->f_rgb.g = ft_atoi(num[1]); clist->f_rgb.b = ft_atoi(num[2]); @@ -56,18 +101,23 @@ int8_t { char **num; - if (!(*words) || ft_strcmp(*words, "C") || !words[1] || words[2]) + if (!(*words) || !words[1] || words[2]) + { + ft_strlcpy(clist->errmsg, FT_ERR_ARGS, ft_strlen(FT_ERR_ARGS) + 1); return (-1); + } if (!(num = ft_split(words[1], ','))) - return (-1); - if (!num[0] || !num[1] || !num[2] || num[3] || - ft_check_digits(num[0]) || ft_check_digits(num[1]) || - ft_check_digits(num[2]) || ft_atoi(num[0]) > 255 || - ft_atoi(num[1]) > 255 || ft_atoi(num[2]) > 255) { - ft_free_words(num); + ft_strlcpy(clist->errmsg, FT_ERR_ALLOCATE, + ft_strlen(FT_ERR_ALLOCATE) + 1); return (-1); } + if (ft_check_nums_amount(num, clist) < 0) + return (-1); + if (ft_check_color_digits(num, clist) < 0) + return (-1); + if (ft_check_max_int(num, clist) < 0) + return (-1); clist->c_rgb.r = ft_atoi(num[0]); clist->c_rgb.g = ft_atoi(num[1]); clist->c_rgb.b = ft_atoi(num[2]); diff --git a/src/ft_get_map.c b/src/ft_get_map.c index ee23c7a..cb677da 100644 --- a/src/ft_get_map.c +++ b/src/ft_get_map.c @@ -53,7 +53,11 @@ static int8_t 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)))) + { + ft_strlcpy(clist->errmsg, FT_ERR_ALLOCATE, + ft_strlen(FT_ERR_ALLOCATE) + 1); return (-1); + } ft_linecpy(line, clist->mlist->mapl, (clist->mlist->map_w + 1) * i); return (0); } @@ -65,12 +69,14 @@ int if (!line[0]) { ft_memdel((void**)&line); + ft_strlcpy(clist->errmsg, FT_ERR_READ, ft_strlen(FT_ERR_READ) + 1); 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_strlcpy(clist->errmsg, FT_ERR_READ, ft_strlen(FT_ERR_READ) + 1); return (-1); } ft_memdel((void**)&clist->mlist->mapl); diff --git a/src/ft_get_res.c b/src/ft_get_res.c index 86a3186..8607f62 100644 --- a/src/ft_get_res.c +++ b/src/ft_get_res.c @@ -12,9 +12,10 @@ #include <libft.h> #include <cub3d.h> +#include <stdint.h> static int8_t - ft_checkdigit(const char *word) + ft_checkdigit(const char *word, t_cub *clist) { size_t i; @@ -22,7 +23,11 @@ static int8_t while (ft_isdigit(word[i])) i++; if (i != ft_strlen(word)) + { + ft_strlcpy(clist->errmsg, FT_ERR_RES_ALPHA, + ft_strlen(FT_ERR_RES_ALPHA) + 1); return (-1); + } return (0); } @@ -34,20 +39,23 @@ int8_t wlist = clist->wlist; if (!(*words + 0) || !(*(words + 1)) || !(*(words + 2)) || (*(words + 3))) + { + ft_strlcpy(clist->errmsg, FT_ERR_ARGS, ft_strlen(FT_ERR_ARGS) + 1); return (-1); - if ((ft_checkdigit(words[1]) < 0) || - (ft_checkdigit(words[2]) < 0)) + } + if ((ft_checkdigit(words[1], clist) < 0) || + (ft_checkdigit(words[2], clist) < 0)) return (-1); wlist->x_size = ft_atoi(words[1]); wlist->y_size = ft_atoi(words[2]); - if (wlist->x_size < 1 - || wlist->y_size < 1) + if (wlist->x_size <= 1 + || wlist->y_size <= 1) + { + ft_strlcpy(clist->errmsg, FT_ERR_RES_SMALL, + ft_strlen(FT_ERR_RES_SMALL) + 1); return (-1); + } if (ft_get_screen_size(wlist) < 0) return (-1); - if (wlist->x_size > wlist->x_max_size) - wlist->x_size = wlist->x_max_size; - if (wlist->y_size > wlist->y_max_size) - wlist->y_size = wlist->y_max_size; return (0); } diff --git a/src/ft_get_screen_size.c b/src/ft_get_screen_size.c index fe368c4..2b437c3 100644 --- a/src/ft_get_screen_size.c +++ b/src/ft_get_screen_size.c @@ -24,5 +24,9 @@ int8_t return (-1); wlist->x_max_size = ft_atoi(words[0]); wlist->y_max_size = ft_atoi(words[1]); + if (wlist->x_size > wlist->x_max_size) + wlist->x_size = wlist->x_max_size; + if (wlist->y_size > wlist->y_max_size) + wlist->y_size = wlist->y_max_size; return (ft_free_words(words)); } diff --git a/src/ft_get_sprite.c b/src/ft_get_sprite.c index cdea85c..791f51f 100644 --- a/src/ft_get_sprite.c +++ b/src/ft_get_sprite.c @@ -12,14 +12,28 @@ #include <libft.h> #include <cub3d.h> +#include <stdint.h> int8_t ft_get_sprite(char **words, t_cub *clist) { if (!(*words) || !words[1] || words[2]) + { + ft_strlcpy(clist->errmsg, FT_ERR_ARGS, ft_strlen(FT_ERR_ARGS) + 1); return (-1); + } + if (ft_check_ext(*(words + 1), ".xpm") < 0) + { + ft_strlcpy(clist->errmsg, FT_ERR_NOT_A_XPM, + ft_strlen(FT_ERR_NOT_A_XPM) + 1); + return (-1); + } ft_memdel((void**)&clist->mlist->sprite_path); if (!(clist->mlist->sprite_path = ft_strdup(*(words + 1)))) + { + ft_strlcpy(clist->errmsg, FT_ERR_ALLOCATE, + ft_strlen(FT_ERR_ALLOCATE) + 1); return (-1); + } return (0); } diff --git a/src/ft_get_tex.c b/src/ft_get_tex.c index 1965e72..ad093ed 100644 --- a/src/ft_get_tex.c +++ b/src/ft_get_tex.c @@ -18,10 +18,23 @@ int8_t ft_get_tex_no(char **words, t_cub *clist) { if (!(*words) || !(*(words + 1)) || (*(words + 2))) + { + ft_strlcpy(clist->errmsg, FT_ERR_ARGS, ft_strlen(FT_ERR_ARGS) + 1); return (-1); + } + if (ft_check_ext(*(words + 1), ".xpm") < 0) + { + ft_strlcpy(clist->errmsg, FT_ERR_NOT_A_XPM, + ft_strlen(FT_ERR_NOT_A_XPM) + 1); + return (-1); + } ft_memdel((void**)&clist->mlist->no_tex_path); if (!(clist->mlist->no_tex_path = ft_strdup(*(words + 1)))) + { + ft_strlcpy(clist->errmsg, FT_ERR_ALLOCATE, + ft_strlen(FT_ERR_ALLOCATE) + 1); return (-1); + } return (0); } @@ -29,10 +42,23 @@ int8_t ft_get_tex_so(char **words, t_cub *clist) { if (!(*words) || !(*(words + 1)) || (*(words + 2))) + { + ft_strlcpy(clist->errmsg, FT_ERR_ARGS, ft_strlen(FT_ERR_ARGS) + 1); + return (-1); + } + if (ft_check_ext(*(words + 1), ".xpm") < 0) + { + ft_strlcpy(clist->errmsg, FT_ERR_NOT_A_XPM, + ft_strlen(FT_ERR_NOT_A_XPM) + 1); return (-1); + } ft_memdel((void**)&clist->mlist->so_tex_path); if (!(clist->mlist->so_tex_path = ft_strdup(*(words + 1)))) + { + ft_strlcpy(clist->errmsg, FT_ERR_ALLOCATE, + ft_strlen(FT_ERR_ALLOCATE) + 1); return (-1); + } return (0); } @@ -40,10 +66,23 @@ int8_t ft_get_tex_ea(char **words, t_cub *clist) { if (!(*words) || !(*(words + 1)) || (*(words + 2))) + { + ft_strlcpy(clist->errmsg, FT_ERR_ARGS, ft_strlen(FT_ERR_ARGS) + 1); return (-1); + } + if (ft_check_ext(*(words + 1), ".xpm") < 0) + { + ft_strlcpy(clist->errmsg, FT_ERR_NOT_A_XPM, + ft_strlen(FT_ERR_NOT_A_XPM) + 1); + return (-1); + } ft_memdel((void**)&clist->mlist->ea_tex_path); if (!(clist->mlist->ea_tex_path = ft_strdup(*(words + 1)))) + { + ft_strlcpy(clist->errmsg, FT_ERR_ALLOCATE, + ft_strlen(FT_ERR_ALLOCATE) + 1); return (-1); + } return (0); } @@ -51,9 +90,22 @@ int8_t ft_get_tex_we(char **words, t_cub *clist) { if (!(*words) || !(*(words + 1)) || (*(words + 2))) + { + ft_strlcpy(clist->errmsg, FT_ERR_ARGS, ft_strlen(FT_ERR_ARGS) + 1); + return (-1); + } + if (ft_check_ext(*(words + 1), ".xpm") < 0) + { + ft_strlcpy(clist->errmsg, FT_ERR_NOT_A_XPM, + ft_strlen(FT_ERR_NOT_A_XPM) + 1); return (-1); + } ft_memdel((void**)&clist->mlist->we_tex_path); if (!(clist->mlist->we_tex_path = ft_strdup(*(words + 1)))) + { + ft_strlcpy(clist->errmsg, FT_ERR_ALLOCATE, + ft_strlen(FT_ERR_ALLOCATE) + 1); return (-1); + } return (0); } diff --git a/src/ft_init_lists.c b/src/ft_init_lists.c index dc50231..95f0488 100644 --- a/src/ft_init_lists.c +++ b/src/ft_init_lists.c @@ -73,6 +73,7 @@ static t_cub if (!(clist->plist = ft_init_player()) || !(clist->mlist = ft_init_map())) return (NULL); + ft_bzero(clist->errmsg, 40); clist->minimap = 0; clist->f_rgb = ft_init_rgb(); clist->c_rgb = ft_init_rgb(); diff --git a/src/ft_init_winlx.c b/src/ft_init_winlx.c index 1b60477..6657408 100644 --- a/src/ft_init_winlx.c +++ b/src/ft_init_winlx.c @@ -26,7 +26,7 @@ int clist->wlist->x_size, clist->wlist->y_size, "Cub3D"))) return (-1); clist->wlist->inited = 1; - ft_printf("Created window of size %dx%d\n", + ft_printf("Created window of size %ux%u\n", clist->wlist->x_size, clist->wlist->y_size); return (0); } diff --git a/src/ft_map_error.c b/src/ft_map_error.c index 263eee8..5d5ab68 100644 --- a/src/ft_map_error.c +++ b/src/ft_map_error.c @@ -15,10 +15,12 @@ #include <unistd.h> int - ft_map_error(t_cub *clist) + ft_map_error(const char *errmsg, t_cub *clist) { ft_dprintf(STDERR_FILENO, "Error\n"); ft_dprintf(STDERR_FILENO, - "\033[1;31mMap error: line %zu\033[0m\n", clist->mlist->line_chk); + "\033[1;31mMap error: line %zu: %s\033[0m\n", + clist->mlist->line_chk, + errmsg); return (ft_exit(4, clist)); } diff --git a/src/ft_parse_map.c b/src/ft_parse_map.c index 0e1a1e7..4fd870b 100644 --- a/src/ft_parse_map.c +++ b/src/ft_parse_map.c @@ -18,32 +18,6 @@ #include <stdint.h> 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) { t_map *ml; @@ -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,33 +63,39 @@ 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) + while (ret != 12 && ret >= 0) 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_map_error(clist->errmsg, clist); ft_check_map_last_line(clist); ft_get_player_spawn(clist->plist, clist); ft_check_missing(clist); diff --git a/src/ft_raycasting.c b/src/ft_raycasting.c index a4446b3..bf33374 100644 --- a/src/ft_raycasting.c +++ b/src/ft_raycasting.c @@ -55,7 +55,7 @@ void if (cl->rlist.wall_t < 0) cl->rlist.wall_t = 0; cl->rlist.wall_b = cl->rlist.line_h / 2 + wl->y_size / 2; - if (cl->rlist.wall_b >= wl->y_size) + if (cl->rlist.wall_b >= (float)wl->y_size) cl->rlist.wall_b = wl->y_size - 1; ft_draw_verline(cl, i, cl->rlist.wall_t - 1, cl->rlist.wall_b); i++; diff --git a/src/ft_select_get.c b/src/ft_select_get.c index f550d98..4b82430 100644 --- a/src/ft_select_get.c +++ b/src/ft_select_get.c @@ -86,7 +86,7 @@ int8_t if (id < 0 || (*fun_ptr[id])(words, clist) < 0) { ft_free_words(words); - return (-1); + return ((id < 0) ? (-2) : (-1)); } ft_free_words(words); return (id); |