-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpars_color.c
69 lines (60 loc) · 1.83 KB
/
pars_color.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* pars_color.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lbrandy <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/03/13 16:38:42 by lbrandy #+# #+# */
/* Updated: 2021/03/13 17:06:03 by lbrandy ### ########.fr */
/* */
/* ************************************************************************** */
void check_color(t_textures *tex, int type)
{
if (type == 0)
if (tex->F != -1)
write(1, "error\n", 1);
if (type == 1)
if (tex->C != -1)
write(1, "error\n", 1);
}
static void skip(char **s, int flag)
{
if (flag == 0)
while ((**s < '0' || **s > '9') && **s)
(*s)++;
if (flag == 1)
while (**s >= '0' && **s <= '9' && **s)
(*s)++;
}
static void color_init(char **s, int *count)
{
int color;
color = ft_atoi(*s);
skip(s, 1);
skip(s, 0);
(*count)++;
}
void create_color(char *s, t_textures *tex, int *count, int type)
{
int R;
int G;
int B;
R = color_init(&s, count);
G = color_init(&s, count);
B = color_init(&s, count);
if (type == 0)
tex->F = R << 16 | G << 8 | B;
if (type == 1)
tex->C = R << 16 | G << 8 | B;
}
void pars_colors(t_textures *tex, int type, char *s)
{
int count;
count = 0;
check_color(tex, type);
skip_spaces(&s);
create_color(s, tex, &count, type);
if (count != 3 || *s != '\0')
write(1, "error\n", 6);
}