aboutsummaryrefslogtreecommitdiffstats
path: root/src/ft_parse_map.c
blob: 0a4aa454f41be327744c12eb9aeddaced7010ae1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <libft.h>
#include <cub3d.h>
#include <stdlib.h>
#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(const char *map_path, t_win *wlist)
{
	int		fd;

	ft_check_cub(map_path, wlist);
	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(2, wlist);
	}
	ft_get_res(fd, wlist);
	if (ft_get_tex(fd, wlist) < 0)
		return ;
}