diff options
author | Rudy Bousset <rbousset@z2r5p2.le-101.fr> | 2020-02-03 20:28:38 +0100 |
---|---|---|
committer | Rudy Bousset <rbousset@z2r5p2.le-101.fr> | 2020-02-03 20:28:38 +0100 |
commit | 635748945ab8b67ac505abd5cf9b493b728f84f5 (patch) | |
tree | 6ad67dc98940e83b92af31c0dc2bc036c47e021b /src | |
parent | Missing texture bug fix (diff) | |
download | 42-cub3d-635748945ab8b67ac505abd5cf9b493b728f84f5.tar.gz 42-cub3d-635748945ab8b67ac505abd5cf9b493b728f84f5.tar.bz2 42-cub3d-635748945ab8b67ac505abd5cf9b493b728f84f5.tar.xz 42-cub3d-635748945ab8b67ac505abd5cf9b493b728f84f5.tar.zst 42-cub3d-635748945ab8b67ac505abd5cf9b493b728f84f5.zip |
Check doubles, nicer parsing
Diffstat (limited to 'src')
-rw-r--r-- | src/ft_select_get.c | 61 |
1 files changed, 28 insertions, 33 deletions
diff --git a/src/ft_select_get.c b/src/ft_select_get.c index 0594415..b248101 100644 --- a/src/ft_select_get.c +++ b/src/ft_select_get.c @@ -13,27 +13,30 @@ #include <libft.h> #include <cub3d.h> +#include <stddef.h> #include <stdint.h> static int8_t -ft_check_exists_one(int8_t ret, t_cub *clist) +ft_check_exists(int8_t ret, t_cub *clist) { + if (ret == 12) + return (12); if (ret == 0 && (clist->wlist->x_size != -1 || clist->wlist->y_size != -1)) - ret = -1; + return (-1); else if (ret == 1 && (clist->no_tex_path[0])) - ret = -1; + return (-1); else if (ret == 2 && (clist->so_tex_path[0])) - ret = -1; + return (-1); else if (ret == 3 && (clist->ea_tex_path[0])) - ret = -1; + return (-1); else if (ret == 4 && (clist->we_tex_path[0])) - ret = -1; + return (-1); else if (ret == 5 && (clist->sprite_path[0])) - ret = -1; + return (-1); else if (ret == 6 && (clist->f_color != -1)) - ret = -1; + return (-1); else if (ret == 7 && (clist->c_color != -1)) - ret = -1; + return (-1); return (ret); } @@ -41,26 +44,23 @@ static int8_t ft_get_id(char **words, t_cub *clist) { int8_t ret; + char ref[9][3]; - if (!ft_strncmp(words[0], "R", 2)) - ret = 0; - else if (!ft_strncmp(words[0], "NO", 3)) - ret = 1; - else if (!ft_strncmp(words[0], "SO", 3)) - ret = 2; - else if (!ft_strncmp(words[0], "EA", 3)) - ret = 3; - else if (!ft_strncmp(words[0], "WE", 3)) - ret = 4; - else if (!ft_strncmp(words[0], "S", 2)) - ret = 5; - else if (!ft_strncmp(words[0], "F", 2)) - ret = 6; - else if (!ft_strncmp(words[0], "C", 2)) - ret = 7; - else + ft_memcpy(ref[0], "R\0", 3); + ft_memcpy(ref[1], "NO", 3); + ft_memcpy(ref[2], "SO", 3); + ft_memcpy(ref[3], "EA", 3); + ft_memcpy(ref[4], "WE", 3); + ft_memcpy(ref[5], "S\0", 3); + ft_memcpy(ref[6], "F\0", 3); + ft_memcpy(ref[7], "C\0", 3); + ft_memcpy(ref[8], "", 1); + ret = 0; + while (ft_strncmp(words[0], ref[ret], 3) && ref[ret][0]) + ret++; + if (ret == 8) ret = 12; - ret = ft_check_exists_one(ret, clist); + ret = ft_check_exists(ret, clist); return (ret); } @@ -83,16 +83,11 @@ uint8_t ft_free_words(words); return (12); } - if (id < 0) + if (id < 0 || (*fun_ptr[id])(words, clist) < 0) { ft_free_words(words); return (-1); } - if ((*fun_ptr[id])(words, clist) < 0) - { - ft_free_words(words); - return (ft_map_error(clist)); - } ft_free_words(words); return (id); } |