-
Notifications
You must be signed in to change notification settings - Fork 0
/
validation_functions.c
116 lines (106 loc) · 2.24 KB
/
validation_functions.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
105
106
107
108
109
110
111
112
113
114
115
116
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* validation_functions.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ccosnean <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/13 14:41:22 by ccosnean #+# #+# */
/* Updated: 2016/12/13 14:41:23 by ccosnean ### ########.fr */
/* */
/* ************************************************************************** */
#include "list.h"
int ft_is_valid(char *c)
{
if (*c != '.' && *c != '#' && *c != '\n')
ft_error(0);
if (*c == '.')
return (1);
if (*c == '\n' || *c == '\0')
return (0);
return (ft_is_valid_char(c));
}
void ft_check(char *str)
{
int len;
int hei;
int hash;
int conn;
len = 0;
hei = 0;
hash = 0;
conn = 0;
while (*str)
{
if (*str == '#')
hash++;
if (*str == '#' && ft_is_connected(str))
conn++;
if (*str == '\n' && hei < 3)
len = 0;
else if (ft_is_valid(str))
len++;
if ((*str == '\n' || *str == '\0') && len < 4)
hei++;
str++;
}
if (len != 4 || hei != 3 || hash != 4 || conn != 3)
ft_error(0);
}
t_list *ft_start_check(char *str, t_list *h)
{
int i;
char m[21];
i = 0;
while (*str)
{
m[i] = *str;
str++;
i++;
if (i == 21)
{
ft_check(m);
h = ft_save_tetrimino(m, h);
i = 0;
}
}
if (i != 0)
ft_error(0);
return (h);
}
int ft_check_spaces(char *str)
{
int sp;
sp = 0;
while (*(str++))
{
if (*str == '\n')
{
while (*(str++) == '\n')
sp++;
if (sp > 2)
ft_error(0);
sp = 0;
}
}
return (1);
}
t_list *ft_make_map(char *map, int i, t_list *h)
{
int k;
k = 0;
while (map[i] == '\n' || map[i] == '\0')
{
k++;
i--;
}
if (k != 2)
ft_error(0);
map[i + 2] = '\n';
map[i + 3] = '\0';
if (ft_check_spaces(map))
h = ft_start_check(map, h);
else
ft_error(0);
return (h);
}