-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilestuff.c
107 lines (98 loc) · 2.37 KB
/
filestuff.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
98
99
100
101
102
103
104
105
106
107
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* filestuff.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: nolakim <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/07/14 04:14:50 by nolakim #+# #+# */
/* Updated: 2019/08/27 02:07:08 by nolakim ### ########.fr */
/* */
/* ************************************************************************** */
#include "fdf.h"
t_map *mapval(t_fdf *fdf, int **points, int y, int x)
{
t_map *f;
MAP = initmap();
f = MAP;
while (y < fdf->max_y)
{
x = 0;
while (x < fdf->max_x)
{
MAP->z = points[y][x];
MAP->x = x;
MAP->y = y;
x++;
MAP->next = initmap();
MAP = MAP->next;
}
free(points[y]);
y++;
}
free(points);
return (f);
}
void hwcount(t_fdf *fdf, int fd, char *av)
{
int i;
char *line;
char **split;
fdf = initmax(fdf);
if ((fd = open(av, O_RDONLY)) == -1)
perror("feed me a real file wtf");
while (get_next_line(fd, &line) == 1)
{
i = 0;
split = ft_strsplit(line, ' ');
while (split[i])
{
if (i > fdf->max_x)
fdf->max_x = i;
free(split[i]);
i++;
}
free(line);
free(split);
fdf->max_y++;
}
close(fd);
}
int **pointspace(t_fdf *fdf, int y)
{
int **points;
points = (int **)malloc(sizeof(int *) * fdf->max_y);
while (y != fdf->max_y)
{
points[y] = (int *)malloc(sizeof(int) * fdf->max_x);
y++;
}
return (points);
}
void filestuff(t_fdf *fdf, char *av, int y, int x)
{
int fd;
int **points;
char *line;
char **split;
hwcount(fdf, 0, av);
points = pointspace(fdf, 0);
if ((fd = open(av, O_RDONLY)) == -1)
perror("feed me a real file");
while (get_next_line(fd, &line) == 1)
{
x = 0;
split = ft_strsplit(line, ' ');
while (split[x])
{
if (ft_isdigit(split[x][0]) || split[x][0] == '-')
points[y][x] = ft_atoi(split[x]);
free(split[x]);
x++;
}
y++;
free(split);
free(line);
}
MAP = mapval(fdf, points, 0, 0);
}