-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
60 lines (55 loc) · 1.63 KB
/
main.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bahsoka <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/08 22:48:56 by bahsoka #+# #+# */
/* Updated: 2021/10/08 22:48:58 by bahsoka ### ########.fr */
/* */
/* ************************************************************************** */
#include "so_long.h"
int read_map(char *fileName, t_map *map)
{
int fd;
int reader;
char temp_map[BUFFER_SIZE];
fd = open(fileName, O_RDONLY);
if (fd == -1)
return (-1);
reader = read(fd, temp_map, BUFFER_SIZE);
if (reader == -1)
return (-1);
temp_map[reader] = '\0';
setWidth(temp_map, map);
setHeight(temp_map, map);
if (checkMapSizes(temp_map, map) == -1)
{
printf("Error mapSize\n");
return (-1);
}
if (allocateMem(map) == 0)
return (-1);
writeMapToArr(temp_map, map);
if (workMap(map) == -1)
return (-1);
return (1);
}
int main(int argc, char *argv[])
{
t_map map;
if (argc == 2)
{
if (read_map(argv[1], &map) == -1)
{
printf("Error\n");
return (0);
}
}
else
{
printf("Please write correct!\n");
}
return (0);
}