-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathboundaries.c
More file actions
77 lines (69 loc) · 1.85 KB
/
Copy pathboundaries.c
File metadata and controls
77 lines (69 loc) · 1.85 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* boundaries.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rahidalg <rahidalg@student.42madrid.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/01/17 11:53:55 by rahidalg #+# #+# */
/* Updated: 2025/01/18 08:40:28 by rahidalg ### ########.fr */
/* */
/* ************************************************************************** */
#include "so_long.h"
void close_mlx(t_mlx_data *data)
{
free_images(data);
mlx_destroy_display(data->mlx_ptr);
free(data->mlx_ptr);
}
int boundaries_checker(t_mlx_data *data, char *dir, int size_x, int size_y)
{
int fd;
char *line;
fd = open(dir, O_RDONLY);
line = get_next_line(fd);
if (!get_boundaries(fd, line, size_x, size_y))
{
close_mlx(data);
ft_printf("Error\nThe boundaries are open!\n");
return (0);
}
close(fd);
return (1);
}
void check_full_line(char *line, int *error)
{
int i;
i = 0;
while (line[i] != '\n' && line[i] != '\0')
{
if (line[i] != '1')
*error = 1;
i++;
}
i = 0;
}
int get_boundaries(int fd, char *line, int size_x, int size_y)
{
int i;
int error;
i = 0;
error = 0;
while (line != NULL)
{
if (i == 0 || i == size_y - 1)
{
check_full_line(line, &error);
}
else
{
if (line[0] != '1' || line[size_x - 1] != '1')
error = 1;
}
i++;
line = read_next_line(fd, line);
}
if (error == 1)
return (0);
return (1);
}