-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpars_map.c
105 lines (95 loc) · 2.15 KB
/
pars_map.c
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* pars_map.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lbrandy <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/03/16 15:28:07 by lbrandy #+# #+# */
/* Updated: 2021/04/03 12:01:06 by lbrandy ### ########.fr */
/* */
/* ************************************************************************** */
#include "cub3d.h"
static t_list *skip_empty_lines(t_list *tmp)
{
char *s;
while (tmp)
{
s = tmp->content;
if (s)
{
while (*s == ' ')
s++;
if (*s != '\0')
break ;
}
tmp = tmp->next;
}
return (tmp);
}
static int check_str(char *s)
{
if (!*s)
return (1);
while (*s)
{
if (*s != ' ')
return (0);
s++;
}
return (0);
}
static void check_trash(t_list *map)
{
int count;
count = 0;
if (map)
{
while (map)
{
count++;
map = map->next;
}
}
else
return ;
if (count > 1)
error_handler("trash in file\n");
}
void fill_map(t_list *list, t_all *all)
{
int count;
t_list *start_map;
count = 0;
list = skip_empty_lines(list);
start_map = list;
while (start_map)
{
if (start_map->content)
{
if (!start_map || check_str(start_map->content))
break ;
count++;
start_map = start_map->next;
}
else
break ;
}
check_trash(start_map);
all->map = (char **)ft_calloc(count + 1, sizeof(char *));
if (!all->map)
error_handler("malloc error\n");
ft_filling_map(list, all, count);
}
t_pos *pars_map(t_list *list, t_all *all)
{
t_pos *p;
p = (t_pos *)malloc(sizeof(t_pos));
if (!p)
error_handler("malloc error\n");
fill_map(list, all);
init_pos(all, p);
check_boundary(all, all->map, p);
flood(p, all);
return (p);
}