-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalid_data.c
84 lines (76 loc) · 1.78 KB
/
valid_data.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* valid_data.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dgonor <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/07/23 17:30:22 by dgonor #+# #+# */
/* Updated: 2018/07/23 17:30:25 by dgonor ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_lem.h"
int check_int(char *ptr)
{
int j;
int i;
j = 0;
i = -1;
while (ptr[++i])
{
if (ft_isdigit(ptr[i]))
j++;
j--;
}
if (j != 0)
return (1);
if (ft_strlen(ptr) > 10)
return (1);
if (ft_atoi(ptr) > 2147483647)
return (1);
return (0);
}
int check_coord(char *coord, t_game *data)
{
int i;
i = -1;
while (coord[++i])
{
if (!ft_isdigit(coord[i]))
{
data->error = 7;
return (0);
}
}
return ((check_int(coord) ? 1 : 0));
}
int check_name(char *name, t_game *data)
{
int i;
i = -1;
while (name[++i])
{
if (name[i] == ' ' || name[i] == '-' || name[i] == 'L')
{
data->error = 6;
return (1);
}
}
return (0);
}
void valid_start_end(t_game *data)
{
if (data->room)
{
if (!(data->room[data->end].link))
{
data->error = 15;
error(data);
}
if (!(data->room[data->start].link))
{
data->error = 16;
error(data);
}
}
}