-
Notifications
You must be signed in to change notification settings - Fork 0
/
valid.c
104 lines (94 loc) · 1.91 KB
/
valid.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
100
101
102
103
104
#include "header/so_long.h"
void ft_find_width(char **argv, t_Mapinfo *map_info)
{
int fd;
int i;
char *str;
fd = open(argv[1], O_RDONLY);
if (fd == -1)
ft_print_error("Cant open");
i = 0;
str = malloc(sizeof(*str));
if (!str)
ft_print_error("Malloc error");
*str = 'y';
while (str != NULL)
{
free(str);
str = get_next_line(fd);
i++;
}
free (str);
map_info->width = i - 1;
}
void ft_parse_map(char **argv, t_Mapinfo *map_info)
{
int fd;
char *buff;
int i;
ft_find_width(argv, map_info);
map_info->map = malloc((map_info->width + 1) * sizeof(*(map_info->map)));
if (!map_info->map)
ft_print_error("Malloc error");
fd = open(argv[1], O_RDONLY);
if (fd == -1)
ft_print_error("Cant open");
i = -1;
buff = "hello";
while (buff != NULL)
{
buff = NULL;
buff = get_next_line(fd);
map_info->map[++i] = buff;
}
free (buff);
}
void ft_is_rect(t_Mapinfo *map_info)
{
int i;
i = -1;
map_info->length = ft_strlen(map_info->map[0]);
while (map_info->map[++i] != NULL)
{
if (ft_strlen(map_info->map[i]) != (size_t)map_info->length)
ft_print_error("Not rectangular");
}
}
void ft_is_fenced(t_Mapinfo *map_info)
{
int i;
int j;
i = -1;
while (++i < map_info->length)
if (map_info->map[0][i] != '1')
ft_print_error("Not fenced");
j = 0;
while (++j < map_info->width - 1)
{
if (map_info->map[j][0] != '1')
ft_print_error("Not fenced");
if (map_info->map[j][i - 1] != '1')
ft_print_error("Not fenced");
}
i = -1;
while (++i < map_info->length)
if (map_info->map[j][i] != '1')
ft_print_error("Not fenced");
}
void ft_is_valid(t_Mapinfo *map_info)
{
int i;
int j;
j = -1;
while (++j < map_info->width)
{
i = -1;
while (++i < map_info->length)
{
if ((map_info->map[j][i] != '1') && (map_info->map[j][i] != '0')
&& (map_info->map[j][i] != 'C') && (map_info->map[j][i] != 'E')
&& (map_info->map[j][i] != 'P'))
ft_print_error("Not valid");
}
}
}