-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparser.c
87 lines (78 loc) · 2.19 KB
/
parser.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* parser.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: conguyen <conguyen@student.hive.fi> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/08 16:42:19 by conguyen #+# #+# */
/* Updated: 2022/03/22 10:58:45 by conguyen ### ########.fr */
/* */
/* ************************************************************************** */
#include "fdf.h"
static int get_width(char **arr)
{
int x;
x = 0;
while (arr[x] != NULL)
x++;
return (x);
}
static char *get_color_line(char *line)
{
int x;
x = 0;
while (1)
{
if (*line == ',')
break ;
line++;
}
line++;
while (line[x] != '\0')
{
if (line[x] == 'X')
line[x] = line[x] + 32;
if (ft_isalpha(line[x]))
if (ft_islower(line[x]))
if (line[x] != 'x')
line[x] = line[x] - 32;
x++;
}
return (line);
}
static int check_line_for_color(char *line, t_fdf *fdf, int x)
{
int c;
c = 0;
fdf->map.color[fdf->map.height][x] = 0xFFFFFF;
while (line[c] != '\0')
{
if (line[c] == ',')
return (1);
c++;
}
return (0);
}
void transform_array(char *lines, t_fdf *fdf)
{
char **lines_arr;
int x;
lines_arr = ft_strsplit(lines, ' ');
check_line(lines_arr);
if (fdf->map.width == 0)
fdf->map.width = get_width(lines_arr);
x = -1;
fdf->map.map[fdf->map.height] = (int *)malloc(sizeof(int) * fdf->map.width);
fdf->map.color[fdf->map.height] = (int *)malloc(sizeof(int)
* fdf->map.width);
while (lines_arr[++x] != NULL)
{
fdf->map.map[fdf->map.height][x] = ft_atoi(lines_arr[x]);
if (check_line_for_color(lines_arr[x], fdf, x))
if (!check_color_line(get_color_line(lines_arr[x]), fdf, x))
error_exit(lines_arr);
}
check_width(lines_arr, fdf, x);
free_str_arr(lines_arr);
}