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/ft_parse_map.c | |
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 '')
-rw-r--r-- | src/ft_parse_map.c | 29 |
1 files changed, 28 insertions, 1 deletions
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) { |