-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_handl_error.c
97 lines (90 loc) · 2.34 KB
/
ft_handl_error.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_handl_error.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbourziq <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/12 21:56:05 by sbourziq #+# #+# */
/* Updated: 2024/03/12 21:56:09 by sbourziq ### ########.fr */
/* */
/* ************************************************************************** */
#include "so_long.h"
void ft_check_wall(char **res, int count)
{
if ((*res)[0] != '1')
{
free(*res);
ft_printf("Error in your map (first wall)\n");
exit(1);
}
if ((*res)[count + 1] == '\n')
{
if ((*res)[count] != '1')
{
free(*res);
ft_printf("Error in your map (last wall)\n");
exit(1);
}
}
}
void ft_check_first_wall(char **res, int height)
{
if ((height) == 1)
{
if (check_number(*res) == 1)
{
free(*res);
ft_printf("Error in your map (first wall)\n");
exit(1);
}
}
}
void ft_variable(int *fd, char **argv, int *count, t_count *check)
{
*fd = open(argv[1], O_RDONLY);
if (*fd == -1)
{
ft_printf("this map does not exit\n");
exit(0);
}
*count = 0;
check->check_e = 0;
check->check_p = 0;
check->check_n = 0;
}
void ft_morre_line(char **res, t_count *check)
{
free(*res);
if (check->check_e != 1 || check->check_p != 1 || check->check_n > 1
|| check->check_c < 1)
{
ft_printf("error , in your characters\n");
exit(1);
}
}
void ft_count_line(int *height, t_node **witdh, char **argv)
{
char *res;
int fd;
int count;
t_count check;
ft_variable(&fd, argv, &count, &check);
res = get_next_line(fd);
while (res != NULL)
{
ft_count_char(res, &check);
while (res[count] != '\n' && res[count] != '\0')
{
ft_check_wall(&res, count);
count++;
}
*witdh = ft_node(count, *witdh);
ft_check_first_wall(&res, *height);
(*height)++;
count = 0;
free(res);
res = get_next_line(fd);
}
ft_morre_line(&res, &check);
}