-
Notifications
You must be signed in to change notification settings - Fork 0
/
trash.c
84 lines (76 loc) · 1.85 KB
/
trash.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* trash.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tespandj <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/20 20:36:25 by tespandj #+# #+# */
/* Updated: 2024/06/20 20:36:28 by tespandj ### ########.fr */
/* */
/* ************************************************************************** */
#include "fdf.h"
int value_z(struct fdf *fdf, int x, int y)
{
int z;
if (!fdf->map->matrix[y])
z = 0;
else
z = talanatoi(fdf, fdf->map->matrix[y][x]);
return (z);
}
static int signs(t_fdf *fdf, char *str)
{
int sign;
int i;
i = 0;
sign = 1;
if ((str[i] == '-') || (str[i] == '+'))
{
if (str[i] == '-')
sign = -sign;
i++;
}
if (!(str[i] >= '0' && str[i] <= '9'))
{
fdf->map->fd = 42;
return (0);
}
return (sign);
}
int talanatoi(t_fdf *fdf, char *str)
{
long long int res;
int i;
i = 0;
res = 0;
if ((str[i] == '-') || (str[i] == '+'))
i++;
while (str[i] >= '0' && str[i] <= '9')
{
res = res * 10 + (str[i] - 48);
i++;
}
res *= signs(fdf, str);
if (res > 2147483647 || res < -2147483648)
{
fdf->map->fd = 42;
return (0);
}
return (res);
}
void freend(struct fdf *fdf)
{
freematrix(fdf->map);
free(fdf->map);
free(fdf->data);
free(fdf->cam);
}
void free_buffer(int fd, char **line)
{
while (*line)
{
free(*line);
*line = gnl(fd);
}
}