-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmapcheck.c
99 lines (92 loc) · 2.29 KB
/
mapcheck.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* mapcheck.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: akinzeli <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/13 10:51:21 by akinzeli #+# #+# */
/* Updated: 2024/03/19 14:38:27 by akinzeli ### ########.fr */
/* */
/* ************************************************************************** */
#include "fdf.h"
void map_size(t_env *env, char *maps)
{
int fd;
char *line;
char **tab;
fd = open(maps, O_RDONLY);
if (fd < 0)
error_mes("Map Error");
line = get_next_line(fd);
if (!line)
error_mes("Map Empty");
tab = ft_split(line, ' ');
while (tab[env->map_l])
{
free(tab[env->map_l]);
env->map_l++;
}
while (line)
{
free(line);
env->map_h++;
line = get_next_line(fd);
}
free(line);
free(tab);
close(fd);
}
void size_map(t_env *env, char *maps)
{
int fd;
char *line;
char **tab;
int x;
fd = open(maps, O_RDONLY);
line = get_next_line(fd);
while (line)
{
tab = ft_split(line, ' ');
free(line);
x = 0;
while (tab[x])
{
free(tab[x]);
x++;
}
free(tab);
if (x < env->map_l || x > env->map_l)
error_mes("Map format error");
line = get_next_line(fd);
}
free(line);
close(fd);
}
void parse_map(t_env *env, char *file)
{
int fd;
char *line;
char **tab;
fd = open(file, O_RDONLY);
env->final_map = malloc(sizeof(int *) * env->map_h);
if (!env->final_map)
error_mes("Error Malloc");
while (env->y < env->map_h)
{
env->final_map[env->y] = malloc(sizeof(int) * env->map_l);
if (!env->final_map[env->y])
error_mes("Error Malloc");
line = get_next_line(fd);
tab = ft_split(line, ' ');
free(line);
env->x = -1;
while (++env->x < env->map_l)
{
env->final_map[env->y][env->x] = ft_atoi(tab[env->x]);
free(tab[env->x]);
}
env->y++;
free(tab);
}
}