-
Notifications
You must be signed in to change notification settings - Fork 0
/
check.c
114 lines (104 loc) · 2.34 KB
/
check.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* check.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jschotte <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/12/02 13:01:19 by jschotte #+# #+# */
/* Updated: 2015/12/18 15:45:51 by jschotte ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
#include <stdlib.h>
void ft_count(char *str)
{
int i;
int piece;
int point;
int back;
i = 0;
piece = 0;
point = 0;
back = 0;
while (str[i] != '\0')
{
if (str[i] == '#')
piece++;
else if (str[i] == '.')
point++;
else if (str[i] == '\n')
back++;
i++;
}
if (piece != 4 || point != 12 || back != 4)
ft_exit();
}
int ft_count_link(char *str, int i)
{
int nb;
nb = 0;
if (str[i + 1] == '#')
nb++;
if (str[i + 5] == '#')
nb++;
if (str[i - 1] == '#')
nb++;
if (str[i - 5] == '#')
nb++;
return (nb);
}
void ft_check_tab(char **tab)
{
int i;
int j;
int link;
i = 0;
while (tab[i])
{
j = 0;
ft_count(tab[i]);
link = 0;
while (tab[i][j] != '\0')
{
if (tab[i][j] == '#')
{
if (tab[i][j + 1] != '#' && tab[i][j - 1] != '#'
&& tab[i][j + 5] != '#' && tab[i][j - 5] != '#')
ft_exit();
link += ft_count_link(tab[i], j);
}
j++;
}
if (link < 6)
ft_exit();
i++;
}
}
char **ft_check_arg(int ret)
{
char **tab;
tab = NULL;
if (ret < 420)
{
if ((ret / 20 - 1 != ret % 20 || (ret / 20 == 0 && ret % 20 != 1)))
ft_exit();
if ((tab = (char**)malloc(sizeof(tab) * (ret % 20 + 2))) == NULL)
ft_exit();
}
else if (ret >= 420)
{
if ((ret / 20 - 1 != ret % 20 + 21))
ft_exit();
if ((tab = (char**)malloc(sizeof(tab) * (ret % 20 + 22))) == NULL)
ft_exit();
}
return (tab);
}
int ft_get_size(int ret)
{
if (ret < 420)
return (ret % 20 + 1);
else
return (ret % 20 + 21);
}