-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpars_resol.c
104 lines (96 loc) · 2.35 KB
/
pars_resol.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* pars_resol.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lbrandy <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/03/16 14:39:51 by lbrandy #+# #+# */
/* Updated: 2021/04/03 12:04:44 by lbrandy ### ########.fr */
/* */
/* ************************************************************************** */
#include "cub3d.h"
static int count_res(char *s, int len)
{
int i;
int number;
i = 0;
if (len > 7)
return (16384);
while (s[i] == '0')
i++;
if (!ft_isdigit(s[i]))
error_handler("incorrect resolution\n");
number = ft_atoi(&s[i]);
if (number == 0)
error_handler("incorrect resolution\n");
return (number);
}
int len_number(char *s, int flag)
{
int len;
len = 0;
while (*s == '0')
s++;
if (!ft_isdigit(*s) && flag == 0)
error_handler("incorrect resolution\n");
if (!ft_isdigit(*s) && flag == 1)
len++;
while (*s && ft_isdigit(*s))
{
s++;
len++;
}
return (len);
}
static int check_valid(char *res)
{
int count;
int i;
i = 0;
count = 0;
while (res[i])
{
if (!ft_isdigit(res[i]) && res[i] != ' ' && res[i] != '+')
return (-1);
i++;
}
i = 0;
while (res[i])
{
if (ft_isdigit(res[i]))
{
while (res[i] == '0')
i++;
i += len_number(&res[i], 0);
count++;
}
if (res[i])
i++;
}
return (count);
}
void pars_res(char *res, t_textures *t, int len)
{
if (check_valid(res) == -1 || check_valid(res) != 2)
error_handler("incorrect resolution\n");
if (t->x != -1 && t->y != -1)
error_handler("duplicate data\n");
skip_spaces(&res);
len = len_number(res, 0);
if (ft_isdigit(*res))
t->x = count_res(res, len);
skip(&res, 1);
skip_spaces(&res);
len = len_number(res, 0);
if (ft_isdigit(*res))
t->y = count_res(res, len);
skip(&res, 1);
while (*res)
{
if (*res == ' ')
res++;
else
error_handler("incorrect resolution\n");
}
}