diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-01-24 18:19:20 +0100 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-01-24 18:19:20 +0100 |
commit | 4286b43e9e35242b03f5a38af1099f77901c0b3e (patch) | |
tree | 6ee93930d83e24f047cbd72dbfbcbd8ebfa14dfc /src | |
parent | Added a second map for error management (diff) | |
download | 42-cub3d-4286b43e9e35242b03f5a38af1099f77901c0b3e.tar.gz 42-cub3d-4286b43e9e35242b03f5a38af1099f77901c0b3e.tar.bz2 42-cub3d-4286b43e9e35242b03f5a38af1099f77901c0b3e.tar.xz 42-cub3d-4286b43e9e35242b03f5a38af1099f77901c0b3e.tar.zst 42-cub3d-4286b43e9e35242b03f5a38af1099f77901c0b3e.zip |
Much cleaner
Diffstat (limited to 'src')
-rw-r--r-- | src/ft_get_tex.c | 3 | ||||
-rw-r--r-- | src/ft_init_lists.c | 3 | ||||
-rw-r--r-- | src/ft_init_winlx.c | 2 | ||||
-rw-r--r-- | src/ft_parse_map.c | 29 | ||||
-rw-r--r-- | src/main.c | 2 |
5 files changed, 37 insertions, 2 deletions
diff --git a/src/ft_get_tex.c b/src/ft_get_tex.c index 65c8441..6bd2b7c 100644 --- a/src/ft_get_tex.c +++ b/src/ft_get_tex.c @@ -14,7 +14,10 @@ ft_get_tex_no(int fd, t_win *wlist) return (ft_exit(5, wlist)); if (!(*words) || ft_strcmp(*words, "NO") || !(*(words + 1)) || (*(words + 2))) + { + ft_free_words(words); return (ft_map_error(2, wlist)); + } ft_memdel(wlist->clist->no_tex_path); len = ft_strlen(*(words + 1)); if (!(wlist->clist->no_tex_path = (char*)malloc((len + 1) * sizeof(char)))) diff --git a/src/ft_init_lists.c b/src/ft_init_lists.c index 4aa2d81..799204b 100644 --- a/src/ft_init_lists.c +++ b/src/ft_init_lists.c @@ -11,6 +11,9 @@ t_win if (!(wlist = (t_win*)malloc(sizeof(t_win)))) return (NULL); + if (!(wlist->wlx = ft_calloc(1, 1)) || + !(wlist->winptr = ft_calloc(1, 1))) + return (NULL); return (wlist); } diff --git a/src/ft_init_winlx.c b/src/ft_init_winlx.c index 0e272fd..a4b7208 100644 --- a/src/ft_init_winlx.c +++ b/src/ft_init_winlx.c @@ -6,8 +6,10 @@ int ft_init_winlx(t_win *wlist) { + ft_memdel(wlist->wlx); if (!(wlist->wlx = mlx_init())) return (-1); + ft_memdel(wlist->winptr); if (!(wlist->winptr = (void*)malloc(wlist->x_size * wlist->y_size))) return (-1); if (!(wlist->winptr = mlx_new_window(wlist->wlx, wlist->x_size,\ diff --git a/src/ft_parse_map.c b/src/ft_parse_map.c index f4eb4f0..0a4aa45 100644 --- a/src/ft_parse_map.c +++ b/src/ft_parse_map.c @@ -4,15 +4,42 @@ #include <fcntl.h> #include <unistd.h> +static void +ft_check_cub(const char *map_path, t_win *wlist) +{ + 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(2, wlist); + } + 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); + ft_exit(2, wlist); + } + ft_free_words(words); +} + /* ** I can't close fd */ void -ft_parse_map(t_win *wlist, const char *map_path) +ft_parse_map(const char *map_path, t_win *wlist) { int fd; + ft_check_cub(map_path, wlist); fd = open(map_path, O_RDONLY); if (fd < 0) { @@ -15,7 +15,7 @@ int ft_memdel(wlist); return (1); } - ft_parse_map(wlist, "map/map_one.cub"); + ft_parse_map("map/map_two.cub", wlist); if (ft_init_winlx(wlist) < 0) return (ft_exit(3, wlist)); mlx_key_hook(wlist->winptr, ft_key_event, wlist); |