-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmake_axis.c
More file actions
129 lines (118 loc) · 2.54 KB
/
make_axis.c
File metadata and controls
129 lines (118 loc) · 2.54 KB
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* make_axis.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgerda <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/11/23 17:56:46 by bgerda #+# #+# */
/* Updated: 2019/11/23 18:00:00 by bgerda ### ########.fr */
/* */
/* ************************************************************************** */
#include "fdf.h"
int spl_len(char *str, int *y)
{
int i;
i = 0;
while (str[i])
{
if (str[i] != '\n' && str[i])
{
(*y)++;
while (str[i] != '\n' && str[i])
i++;
}
else
i++;
}
return ((*y));
}
int spl_x_len(char *str)
{
int i;
int len;
i = 0;
len = 0;
while (str[i] != '\n' && str[i])
{
if (spl_is_number(str[i]))
{
len++;
while (spl_is_number(str[i]))
i++;
}
else
i++;
}
return (len);
}
int *take_axis(char *str, int *i)
{
int *axis;
if (!((axis) = (int *)malloc(sizeof(int) * 2)))
return (NULL);
if (spl_is_number(str[*i]))
axis[0] = ft_atoi(&str[(*i)]);
while (str[(*i)] && spl_is_number(str[*i]))
(*i)++;
if (str[(*i)] == ',')
{
(*i)++;
if (!ft_strncmp("0x", &str[(*i)], 2))
{
(*i) += 2;
axis[1] = ft_atoi_base(&str[(*i)], 16);
}
else
axis[1] = ft_atoi(&str[(*i)]);
}
else
axis[1] = 0;
while (str[(*i)] && spl_is_number(str[*i]))
(*i)++;
return (axis);
}
int **create_x(char *str, int *x, int *i)
{
int **spl_x;
static int len;
if (!len)
len = spl_x_len(str);
if (!((spl_x) = (int **)malloc(sizeof(int *) * (len + 1))))
return (NULL);
while (str[*i] != '\n' && str[*i])
{
while (!spl_is_number(str[*i]) && str[*i])
(*i)++;
if (spl_is_number(str[*i]))
{
spl_x[*x] = take_axis(str, i);
(*x)++;
}
}
spl_x[*x] = NULL;
return (spl_x);
}
int ***char_to_point(char *str)
{
int ***spl;
int x;
int y;
int i;
int len;
y = 0;
i = 0;
len = 0;
if (!(spl = (int ***)malloc(sizeof(int **) * (spl_len(str, &len) + 1))))
return (NULL);
while (y < len)
{
x = 0;
spl[y] = create_x(str, &x, &i);
y++;
if (str[i] == '\n')
i++;
}
spl[y] = NULL;
return (spl);
}