-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmap_validations3.c
82 lines (73 loc) · 1.26 KB
/
map_validations3.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
#include "so_long.h"
int find_size(t_map *or_map, char c)
{
int i;
int j;
char **str;
i = 0;
str = or_map->map;
while (str && str[i])
{
j = 0;
while (str[i][j])
j++;
i++;
}
if (c == 'y')
return (i);
if (c == 'x')
return (j);
return (0);
}
int verify_extension(char *str)
{
const char *map_ext = ".ber";
int i;
int j;
i = 0;
j = 3;
while (str[i])
i++;
i--;
while (j >= 0)
{
if (str[i] != map_ext[j])
return (FILE_EXTENSION_ERROR);
j--;
i--;
}
if (i < 0)
return (FILE_EXTENSION_ERROR);
return (NO_ERROR);
}
int check_clear_line(char *map)
{
int i;
i = 0;
while (map[i])
{
if (map[i] == '\n' && map[i + 1] == '\n')
{
free(map);
return (MAP_ERROR);
}
i++;
}
return (NO_ERROR);
}
int verify_errors(t_map *or_map)
{
int error;
error = NO_ERROR;
if (verify_map_pec(or_map->map) == WRONG_PEC)
error = print_error(WRONG_PEC);
else if (verify_map_items(or_map->map) == WRONG_CHARACTER)
error = print_error(WRONG_CHARACTER);
else if (map_is_square(or_map->map) == SQUARE_MAP)
error = print_error(SQUARE_MAP);
else if (map_is_closed(or_map->map) == CLOSED_MAP)
error = print_error(CLOSED_MAP);
else if (map_is_playable(or_map) == PLAYABLE_MAP)
error = print_error(PLAYABLE_MAP);
return (error);
}