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_check_ext.c | 13 ++++++++++++ src/ft_exit.c | 1 + src/ft_init_lists.c | 3 ++- src/ft_map_error.c | 6 ++++-- src/ft_parse_map.c | 58 ++++++++++++++++++----------------------------------- src/ft_select_get.c | 2 +- 6 files changed, 40 insertions(+), 43 deletions(-) create mode 100644 src/ft_check_ext.c (limited to 'src') diff --git a/src/ft_check_ext.c b/src/ft_check_ext.c new file mode 100644 index 0000000..f4a1e92 --- /dev/null +++ b/src/ft_check_ext.c @@ -0,0 +1,13 @@ +#include +#include + +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_exit.c b/src/ft_exit.c index d4b69ba..53af7f9 100644 --- a/src/ft_exit.c +++ b/src/ft_exit.c @@ -33,6 +33,7 @@ static void ft_memdel((void**)&clist->wlist->winptr); ft_memdel((void**)&clist->wlist->wlx); ft_memdel((void**)&clist->wlist); + ft_memdel((void**)&clist->errmsg); ft_memdel((void**)&clist); } diff --git a/src/ft_init_lists.c b/src/ft_init_lists.c index dc50231..459e522 100644 --- a/src/ft_init_lists.c +++ b/src/ft_init_lists.c @@ -71,7 +71,8 @@ static t_cub if (!(clist = (t_cub*)malloc(sizeof(t_cub)))) return (NULL); if (!(clist->plist = ft_init_player()) || - !(clist->mlist = ft_init_map())) + !(clist->mlist = ft_init_map()) || + !(clist->errmsg = ft_calloc(1, sizeof(char)))) return (NULL); clist->minimap = 0; clist->f_rgb = ft_init_rgb(); diff --git a/src/ft_map_error.c b/src/ft_map_error.c index 263eee8..cb099dc 100644 --- a/src/ft_map_error.c +++ b/src/ft_map_error.c @@ -15,10 +15,12 @@ #include 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 %3zu: %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..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); 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); -- 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_check_map_line.c | 40 ++++++++++++++++++++++++++++++++++------ src/ft_exit.c | 3 --- src/ft_get_map.c | 6 ++++++ src/ft_get_res.c | 25 ++++++++++++++++--------- src/ft_get_screen_size.c | 4 ++++ src/ft_init_lists.c | 4 ++-- src/ft_map_error.c | 2 +- src/ft_parse_map.c | 4 ++-- 8 files changed, 65 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/src/ft_check_map_line.c b/src/ft_check_map_line.c index 9e4e484..b41d052 100644 --- a/src/ft_check_map_line.c +++ b/src/ft_check_map_line.c @@ -15,6 +15,38 @@ #include #include +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) { @@ -42,16 +74,12 @@ int8_t { 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++; diff --git a/src/ft_exit.c b/src/ft_exit.c index 53af7f9..f0a94a3 100644 --- a/src/ft_exit.c +++ b/src/ft_exit.c @@ -33,7 +33,6 @@ static void ft_memdel((void**)&clist->wlist->winptr); ft_memdel((void**)&clist->wlist->wlx); ft_memdel((void**)&clist->wlist); - ft_memdel((void**)&clist->errmsg); ft_memdel((void**)&clist); } @@ -44,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_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..e51a66f 100644 --- a/src/ft_get_res.c +++ b/src/ft_get_res.c @@ -14,7 +14,7 @@ #include static int8_t - ft_checkdigit(const char *word) + ft_checkdigit(const char *word, t_cub *clist) { size_t i; @@ -22,7 +22,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 +38,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_init_lists.c b/src/ft_init_lists.c index 459e522..95f0488 100644 --- a/src/ft_init_lists.c +++ b/src/ft_init_lists.c @@ -71,9 +71,9 @@ static t_cub if (!(clist = (t_cub*)malloc(sizeof(t_cub)))) return (NULL); if (!(clist->plist = ft_init_player()) || - !(clist->mlist = ft_init_map()) || - !(clist->errmsg = ft_calloc(1, sizeof(char)))) + !(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_map_error.c b/src/ft_map_error.c index cb099dc..5d5ab68 100644 --- a/src/ft_map_error.c +++ b/src/ft_map_error.c @@ -19,7 +19,7 @@ int { ft_dprintf(STDERR_FILENO, "Error\n"); ft_dprintf(STDERR_FILENO, - "\033[1;31mMap error: line %3zu: %s\033[0m\n", + "\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 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 2fd013d7583e0388d50ff9895c5e474e2d76f79f Mon Sep 17 00:00:00 2001 From: Rudy Bousset Date: Mon, 17 Feb 2020 15:31:11 +0100 Subject: Better parse for textures and colors --- src/ft_get_colors.c | 87 ++++++++++++++++++++++++++++++++++++++++++----------- src/ft_get_res.c | 1 + src/ft_get_sprite.c | 14 +++++++++ src/ft_get_tex.c | 52 ++++++++++++++++++++++++++++++++ 4 files changed, 136 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/ft_get_colors.c b/src/ft_get_colors.c index 869dd71..3d34284 100644 --- a/src/ft_get_colors.c +++ b/src/ft_get_colors.c @@ -13,17 +13,58 @@ #include #include #include +#include -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 +74,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 +102,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_res.c b/src/ft_get_res.c index e51a66f..8607f62 100644 --- a/src/ft_get_res.c +++ b/src/ft_get_res.c @@ -12,6 +12,7 @@ #include #include +#include static int8_t ft_checkdigit(const char *word, t_cub *clist) 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 #include +#include 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); } -- 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_check_ext.c | 12 ++++++++++++ src/ft_check_map_line.c | 6 +++--- src/ft_get_colors.c | 5 ++--- src/ft_parse_map.c | 2 +- 4 files changed, 18 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/ft_check_ext.c b/src/ft_check_ext.c index f4a1e92..9a953d0 100644 --- a/src/ft_check_ext.c +++ b/src/ft_check_ext.c @@ -1,3 +1,15 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_check_ext.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rbousset +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/17 15:33:28 by rbousset #+# #+# */ +/* Updated: 2020/02/17 15:33:29 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + #include #include diff --git a/src/ft_check_map_line.c b/src/ft_check_map_line.c index b41d052..7ab2731 100644 --- a/src/ft_check_map_line.c +++ b/src/ft_check_map_line.c @@ -21,7 +21,7 @@ static int8_t if (!ft_ischarset("012NSEW ", line[i])) { ft_strlcpy(clist->errmsg, FT_ERR_ILL_MAP, - ft_strlen(FT_ERR_ILL_MAP) + 1); + ft_strlen(FT_ERR_ILL_MAP) + 1); return (-1); } if (ft_ischarset("NSEW", line[i])) @@ -29,7 +29,7 @@ static int8_t if (clist->mlist->isspawn > 1) { ft_strlcpy(clist->errmsg, FT_ERR_MULT_SPAWN, - ft_strlen(FT_ERR_MULT_SPAWN) + 1); + ft_strlen(FT_ERR_MULT_SPAWN) + 1); return (-1); } return (0); @@ -41,7 +41,7 @@ static int8_t if (!ft_ischarset("1 ", line[i])) { ft_strlcpy(clist->errmsg, FT_ERR_ILL_MAP, - ft_strlen(FT_ERR_ILL_MAP) + 1); + ft_strlen(FT_ERR_ILL_MAP) + 1); return (-1); } return (0); diff --git a/src/ft_get_colors.c b/src/ft_get_colors.c index 3d34284..f54fabc 100644 --- a/src/ft_get_colors.c +++ b/src/ft_get_colors.c @@ -16,7 +16,7 @@ #include static int8_t -ft_check_color_digits(char **num, t_cub *clist) + ft_check_color_digits(char **num, t_cub *clist) { size_t i; uint8_t j; @@ -31,8 +31,7 @@ ft_check_color_digits(char **num, t_cub *clist) { ft_free_words(num); ft_strlcpy(clist->errmsg, FT_ERR_COLOR_ALPHA, - ft_strlen(FT_ERR_COLOR_ALPHA) + 1); - + ft_strlen(FT_ERR_COLOR_ALPHA) + 1); return (-1); } i = 0; 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 From ac87f799abf2edbd95243f2343eda41faf30cca6 Mon Sep 17 00:00:00 2001 From: Rudy Bousset Date: Mon, 17 Feb 2020 15:57:18 +0100 Subject: Better parse --- src/ft_check_map_line.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/ft_check_map_line.c b/src/ft_check_map_line.c index 7ab2731..1009aa3 100644 --- a/src/ft_check_map_line.c +++ b/src/ft_check_map_line.c @@ -64,13 +64,25 @@ 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) { @@ -82,10 +94,14 @@ int8_t 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); } -- cgit v1.2.3 From 9af56266c16eaffe9375ba3edb3465c33f015b9f Mon Sep 17 00:00:00 2001 From: Rudy Bousset Date: Mon, 17 Feb 2020 16:24:04 +0100 Subject: ready to merge --- src/ft_draw_verline.c | 4 ++-- src/ft_init_winlx.c | 2 +- src/ft_raycasting.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src') 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_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_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++; -- cgit v1.2.3