aboutsummaryrefslogtreecommitdiffstats
path: root/src/ft_get_map_redo.c
blob: 004dd3dc70aac17c555c8318e5cea820cdc6bc86 (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
54
55
56
57
58
59
60
#include <libft.h>
#include <cub3d.h>
#include <stddef.h>
#include <stdlib.h>

static int8_t
ft_check_line(char *line, uint8_t l, t_cub *clist)
{
	size_t	i;

	i = 0;
	while (line[i])
	{
		if (l != 1)
		{
			if (!ft_ischarset("012NSEW ", line[i]))
				return (-1);
			if (ft_ischarset("NSEW", line[i]))
				clist->nsew += 1;
			if (clist->nsew > 1)
				return (-1);
		}
		else
		{
			if (!ft_ischarset("1 ", line[i]))
				return (-1);
		}
		i++;
	}
	if (line[0] != '1' || line[i - 1] != '1')
		return (-1);
	return (0);
}

int
ft_get_first_line(char *line, t_cub *clist)
{
	if (!line[0])
	{
		ft_memdel(line);
		return (-1);
	}
	if (ft_check_line(line, 1, clist) < 0)
	{
		ft_memdel(line);
		return (-1);
	}
	return (1);
}

int
ft_get_map(int fd, t_cub *clist)
{
	int		ret;

	(void)fd;
	(void)ret;
	(void)clist;
	return (0);
}