-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherrors.c
84 lines (77 loc) · 2.15 KB
/
errors.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* errors.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ybouddou <ybouddou@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/10/19 20:08:52 by ybouddou #+# #+# */
/* Updated: 2020/12/04 09:17:18 by ybouddou ### ########.fr */
/* */
/* ************************************************************************** */
#include "cub3d.h"
void exist(t_cub3d *cub)
{
if (cub->rep.res == 0)
error_msg_free("ERROR\nResolution not found", cub);
else if (cub->rep.no == 0 || cub->rep.so == 0 || cub->rep.ea == 0 ||
cub->rep.we == 0 || cub->rep.s == 0)
error_msg_free("ERROR\nPath not found", cub);
else if (cub->rep.f == 0)
error_msg_free("ERROR\nF not found", cub);
else if (cub->rep.c == 0)
error_msg_free("ERROR\nC not found", cub);
if (cub->parse.x == 0)
{
cub->map = (char**)malloc(2 * sizeof(char*));
cub->map[0] = ft_strdup(cub->parse.line);
cub->map[1] = NULL;
}
else
push(cub);
}
void error_msg_free(char *s, t_cub3d *cub)
{
free(cub->parse.line);
free(cub->path.no);
free(cub->path.so);
free(cub->path.ea);
free(cub->path.we);
free(cub->path.s);
free(cub->image);
if (cub->parse.x > 0)
ft_free(cub->map);
ft_putstr_fd(s, 2);
exit(1);
}
void error_free(char *s, t_cub3d *cub, char **tofree)
{
ft_free(tofree);
free(cub->parse.line);
free(cub->path.no);
free(cub->path.so);
free(cub->path.ea);
free(cub->path.we);
free(cub->path.s);
free(cub->image);
ft_putstr_fd(s, 2);
exit(1);
}
void error_msg(char *s)
{
ft_putstr_fd(s, 2);
exit(1);
}
void ft_free(char **arr)
{
int i;
i = 0;
while (arr[i])
{
free(arr[i]);
arr[i] = NULL;
i++;
}
free(arr);
arr = NULL;
}