-
Notifications
You must be signed in to change notification settings - Fork 0
/
map.c
86 lines (76 loc) · 2.02 KB
/
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* map.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fvon-nag <fvon-nag@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/23 17:55:50 by fvon-nag #+# #+# */
/* Updated: 2023/02/24 09:59:32 by fvon-nag ### ########.fr */
/* */
/* ************************************************************************** */
#include "so_long.h"
int mapcheck(char *argv1)
{
char *map;
int error;
error = 0;
map = readmap(argv1);
error += checkchars(map);
error += checkmin(map);
free(map);
return (error);
}
int checkformat(char *argv1)
{
int len;
int out;
len = ft_strlen(argv1);
out = ft_strncmp(argv1 + len - 4, ".ber", 4);
if (out != 0)
ft_printf("Error\nMap needs to be in .ber format!\n");
return (out);
}
int checks(char *argv1)
{
if (checkformat(argv1) != 0)
return (1);
if (mapcheck(argv1) != 0)
return (1);
if (checkrect(argv1) != 0)
return (1);
if (pathcheck(argv1) != 0)
return (1);
return (0);
}
t_mega *initmap(char *argv1)
{
char *map;
int msize;
t_mega *out;
map = readmap(argv1);
msize = ft_strlen_nnl(map);
out = (t_mega *) ft_calloc(msize + 1, sizeof(t_mega));
out[0].structlen = msize;
free(map);
return (out);
}
char *readmap(char *map)
{
int fd;
char *temp;
char *out;
temp = ft_calloc(1, sizeof(char));
out = ft_calloc(1, sizeof(char));
fd = open(map, O_RDONLY);
while (temp)
{
temp = get_next_line(fd);
if (temp == NULL)
break ;
out = ft_gnl_strjoin(out, temp);
free(temp);
}
close(fd);
return (out);
}