-
Notifications
You must be signed in to change notification settings - Fork 0
/
validate_line_utilities.c
72 lines (67 loc) · 2.17 KB
/
validate_line_utilities.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* validate_line_utilities.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: onapoli- <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/08/10 12:04:12 by onapoli- #+# #+# */
/* Updated: 2020/09/03 12:59:08 by onapoli- ### ########.fr */
/* */
/* ************************************************************************** */
#include "reader.h"
int validate_line_nospace(size_t column, char element,
int *first_num, size_t this_line_limits[2])
{
if (!(*first_num) && element != '1')
return (-1);
if (!(*first_num))
{
*first_num = 1;
this_line_limits[0] = column;
}
this_line_limits[1] = column;
return (0);
}
static int validate_line_zero(char **map, size_t row, size_t column,
size_t prev_line_limits[2])
{
if (prev_line_limits[0] > column || prev_line_limits[1] < column)
return (-1);
if (!map[row + 2])
{
if (ft_strlen(map[row + 1]) < column)
return (-1);
if (map[row + 1][column] != '1')
return (-1);
}
return (0);
}
static int validate_line_zero_space(char **map, size_t row, size_t column)
{
if (map[row][column - 1] != '1' &&
map[row][column - 1] != map[row][column])
return (-1);
if (ft_strlen(map[row - 1]) >= column)
{
if (map[row - 1][column] != '1' &&
map[row - 1][column] != map[row][column])
return (-1);
}
return (0);
}
int validate_line_zeroes(char **map, size_t row, size_t column,
size_t prev_line_limits[2])
{
if (map[row][column] == '0' || map[row][column] == ' ')
{
if (validate_line_zero_space(map, row, column) == -1)
return (-1);
}
if (map[row][column] == '0')
{
if (validate_line_zero(map, row, column, prev_line_limits) == -1)
return (-1);
}
return (0);
}