-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcount_map_len.c
More file actions
81 lines (73 loc) · 1.36 KB
/
Copy pathcount_map_len.c
File metadata and controls
81 lines (73 loc) · 1.36 KB
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
#include "fdf.h"
static int is_valid_symbol(char c)
{
if (c == ' ' || c == '-' || c == '\t')
return (1);
if (c >= '0' && c <= '9')
return (1);
ft_putstr("NOT VALID SYMBOL: ");
ft_putchar(c);
ft_putchar('\n');
return (0);
}
static int skip_color_hex(char *line, int *i)
{
int result;
result = 0;
if (line[*i] == '0' && line[*i + 1] && (line[*i + 1] == 'x' || line[*i + 1] == 'X'))
{
*i = *i + 2;
while (ft_isdigit(line[*i]) || (line[*i] >= 'A'
&& line[*i] <= 'F') || (line[*i] >= 'a' && line[*i] <= 'f'))
{
*i = *i + 1;
result = 1;
}
}
return (result);
}
static int count_len_x(t_collection *C, char *line, int not_first_line)
{
int i;
int temp_len;
i = 0;
temp_len = 0;
while (line[i] == ' ')
i++;
skip_color_hex(line, &i);
while (line[i + 1])
{
if (line[i] == ',')
{
i++;
if (!skip_color_hex(line, &i))
return (print_error(6));
}
if (!is_valid_symbol(line[i]))
return (print_error(3));
if (line[i] == ' ' && line[i + 1] != ' ')
temp_len++;
i++;
}
temp_len++;
if (not_first_line && temp_len != C->map_len.x)
return (print_error(4));
C->map_len.x = temp_len;
return (1);
}
int count_len_y(t_collection *C, int fd)
{
int i;
char *line;
i = 0;
while (get_next_line(fd, &line) > 0)
{
if (!count_len_x(C, line, i))
return (0);
if (line)
free(line);
i++;
C->map_len.y++;
}
return (1);
}