-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidate.c
More file actions
89 lines (81 loc) · 2.27 KB
/
validate.c
File metadata and controls
89 lines (81 loc) · 2.27 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* validate.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: passef <passef@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/01/09 16:54:33 by passef #+# #+# */
/* Updated: 2018/01/12 01:40:07 by passef ### ########.fr */
/* */
/* ************************************************************************** */
#include "bistromatic.h"
int chk_operand(t_env *e)
{
int i;
int j;
int res;
i = 0;
j = 0;
res = 0;
while (e->input[i])
{
if (!(ft_strchr(e->base_str, e->input[i])))
{
printf("Un caractere de l'input n'est pas present dans la base");
return (0);
}
i++;
}
return (1);
}
int chk_next_handle(t_env *e, int i)
{
if (e->input[i] == ')')
{
if (e->input[i + 1] == '%' || e->input[i + 1] == '/' || e->input[i + 1] == ')')
return (1);
}
if (e->input[i + 1] == '+' || e->input[i + 1] == '-' || e->input[i + 1] == '(')
return (1);
if (ft_strchr(e->base_str, e->input[i + 1]))
return (1);
return (0);
}
int chk_next_i(t_env *e)
{
int i;
int res;
i = 0;
res = 0;
while (e->input[i])
{
if (e->input[i] == '+')
chk_next_handle(e, i) ? res = 1 : 0;
if (e->input[i] == '-')
chk_next_handle(e, i) ? res = 1 : 0;
if (e->input[i] == '*')
chk_next_handle(e, i) ? res = 1 : 0;
if (e->input[i] == '/')
chk_next_handle(e, i) ? res = 1 : 0;
if (e->input[i] == '(')
chk_next_handle(e, i) ? res = 1 : 0;
if (e->input[i] == ')')
chk_next_handle(e, i) ? res = 1 : 0;
if (ft_strchr(e->base_str, e->input[i]))
chk_next_handle(e, i) ? res = 1 : 0;
}
return (res);
}
int validate_input(t_env *e)
{
int res;
res = 0;
if (!chk_operand(e))
return (0);
if (!(e->input[ft_strlen(e->input) - 1] == ')'))
return (0);
if (!chk_next_i(e))
return (0);
return (res);
}