-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse.c
executable file
·58 lines (53 loc) · 1.68 KB
/
parse.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* parse.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jchapell <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/05/30 04:19:22 by lebojo #+# #+# */
/* Updated: 2023/06/01 04:52:56 by jchapell ### ########.fr */
/* */
/* ************************************************************************** */
#include "inc/proto.h"
int file_char_len(char *file_path)
{
int file;
int i;
char buffer;
file = open(file_path, O_RDONLY);
i = 0;
if (file == -1)
return (0);
while (read(file, &buffer, sizeof(char)) != 0)
i++;
close(file);
return (i);
}
void parse(char *file_path, t_level *lvl)
{
int file;
int i;
char buffer;
if (check_ext(file_path, ".ber") == 0)
exit(error("A map <.ber> expected"));
lvl->map = malloc(sizeof(char) * file_char_len(file_path));
file = open(file_path, O_RDONLY);
i = 0;
if (file == -1)
return ;
info("Parsing map...");
while (read(file, &buffer, sizeof(char)) != 0)
{
lvl->map[i++] = buffer;
if (buffer == '\n')
{
if (lvl->data.size.x == -1)
lvl->data.size.x = i - 1;
lvl->data.size.y++;
}
}
lvl->map[i] = '\0';
close(file);
info("Map parsed");
}