-
Notifications
You must be signed in to change notification settings - Fork 0
/
validator.c
85 lines (78 loc) · 1.16 KB
/
validator.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
#include "bsq.h"
void ft_error(char *map)
{
free(map);
ft_putstr("map error\n");
}
int valid_1(char *map, int len)
{
int i;
i = 0;
if (len < 4)
return (1);
while (i < len)
{
while (i < (len - 3))
{
if (map[0] == '+')
i++;
if (map[i] < 48 || map[i] > 57)
return (1);
i++;
}
if (map[i] < 32 || map[i] > 126)
return (1);
i++;
}
if (map[i - 1] == map[i - 2]
|| map[i - 1] == map[len - 3] || map[i - 2] == map[i - 3])
return (1);
return (0);
}
int valid_3(char *map, int len)
{
int i;
int a;
i = len + 1;
a = 0;
while (map[i] != '\0')
{
while (map[i] != '\n' && map[i] != '\0')
{
if (map[i] != map[len - 2] && map[i] != map[len - 3])
return (1);
a++;
i++;
}
i++;
}
if (a == 0)
return (1);
return (0);
}
int valid_2(char *map, int len, int numb)
{
int i;
int s;
int n;
int ideal_len;
i = len + 1;
ideal_len = ft_strlen(map, '\n', (len + 1));
n = 0;
while (map[i] != '\0')
{
s = 0;
while (map[i] != '\n' && map[i] != '\0')
{
s++;
i++;
}
n++;
if (s != ideal_len || map[i] == '\0')
return (1);
i++;
}
if ((numb == 0) || (n != numb))
return (1);
return (valid_3(map, len));
}