-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmapval.c
80 lines (71 loc) · 1.69 KB
/
mapval.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* mapval.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: azaher <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/09 14:49:03 by azaher #+# #+# */
/* Updated: 2023/01/19 16:26:46 by azaher ### ########.fr */
/* */
/* ************************************************************************** */
#include "so_long.h"
int ft_strcmp(char *s1, char *s2)
{
int i;
i = 0;
while (s1[i] == s2[i] && s1[i] != '\0' && s2[i] != '\0')
i++;
return (s1[i] - s2[i]);
}
void error_exit(char **map, char *errormsg)
{
int i;
i = 0;
while (map[i])
{
free(map[i]);
i++;
}
free(map);
perror(errormsg);
exit (1);
}
size_t ft_nln_strlen(const char *s)
{
size_t l;
l = 0;
if (s == 0)
return (0);
while (*s != '\0' && *s != '\n')
{
l++;
s++;
}
return (l);
}
char **mapval(char *path)
{
char **map;
int error;
int i;
int fd;
i = 0;
fd = open(path, O_RDONLY, 0444);
if (fd < 0)
{
perror("");
exit (1);
}
error = map_is_rectangular(fd);
if (error == 1)
{
perror("Error\nInvalid map\n");
exit (1);
}
map = map_fill(path);
valid_fl_line(map);
valid_borders(map);
valid_items(map);
return (map);
}