-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreader.c
102 lines (91 loc) · 2.47 KB
/
reader.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* map_reader.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: obalagur <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/03/31 15:43:32 by obalagur #+# #+# */
/* Updated: 2018/03/31 15:43:38 by obalagur ### ########.fr */
/* */
/* ************************************************************************** */
#include "fdf.h"
t_vortex_group *make_vortex_group(char *line)
{
t_vortex_group static *v_g = NULL;
add_group(&v_g, set_group(make_vortex(line)));
return (v_g);
}
void split_lines(char **splited_line, t_vortex3d **v, int entry)
{
int color;
int num;
int x;
static int check_x = 0;
x = 0;
color = WHITE;
while (*splited_line)
{
if (ft_strlen(*splited_line) > 1 &&
(*splited_line)[1] == 'x')
color = ft_atoi_base((*splited_line) + 2, 16);
else
{
num = ft_atoi(*splited_line);
add_vortex(v, set_vortex(x, entry, num, color));
color = WHITE;
x++;
}
ft_strdel(&(*splited_line));
splited_line++;
}
if (check_x != x && check_x != 0)
terminate(NULL, "exception -> invalid data in map");
check_x = x;
}
t_vortex3d *make_vortex(char *line)
{
char **splited_line;
static int entry = 0;
t_vortex3d *v;
v = NULL;
if (line)
{
splited_line = ft_splinter(line, " ,\0");
split_lines(splited_line, &v, entry);
entry++;
free(splited_line);
splited_line = NULL;
}
return (v);
}
void make_vertical_pointer(t_vortex_group *v_g)
{
t_vortex_group *v_g_temp;
t_vortex3d *v;
t_vortex3d *v_n;
if (v_g == NULL)
return ;
v_g_temp = v_g;
while (v_g_temp->next)
{
v = v_g_temp->vortex;
v_n = v_g_temp->next->vortex;
while (v)
{
v->next_v = v_n;
v = v->next;
v_n = v_n->next;
}
v_g_temp = v_g_temp->next;
}
}
t_vortex_group *read_file(char *file)
{
t_vortex_group *v_g;
v_g = (t_vortex_group *)for_each_gnl(file, (void *)make_vortex_group);
if (!v_g)
terminate(NULL, "exception -> invalid map");
make_vertical_pointer(v_g);
return (v_g);
}