-
Notifications
You must be signed in to change notification settings - Fork 0
/
error_bonus.c
64 lines (57 loc) · 1.62 KB
/
error_bonus.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* error_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mannouao <mannouao@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/12/10 14:52:30 by mannouao #+# #+# */
/* Updated: 2021/12/14 22:25:48 by mannouao ### ########.fr */
/* */
/* ************************************************************************** */
#include "so_long_bonus.h"
static void print_msg(char *str)
{
printf("%s\n", str);
exit(0);
}
int leav(t_data *gm)
{
free_and_err(gm, "you leaved the game !", 1, 8);
return (0);
}
void print_error(char *str)
{
write(2, "Error\n", 6);
write(2, str, ft_strlen(str));
write(2, "\n", 1);
exit(1);
}
void free_and_err(t_data *gm, char *str, int k, int x)
{
int i;
i = -1;
if (gm->map)
{
while (gm->map[++i])
free(gm->map[i]);
free(gm->map);
}
if (gm->e1_x)
free(gm->e1_x);
if (gm->e1_y)
free(gm->e1_y);
if (x != 42)
mlx_destroy_window(gm->ml, gm->wi);
if (k == 0)
print_error(str);
else if (k == 1)
print_msg(str);
}
void more_free(char *ptr1, char *ptr2)
{
if (ptr2)
free(ptr2);
free(ptr1);
print_error("invalid map !!!!!!");
}