-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils_parser.c
49 lines (42 loc) · 1.57 KB
/
utils_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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utils_parser.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: khlavaty <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/26 12:48:04 by fvonsovs #+# #+# */
/* Updated: 2024/09/12 20:59:33 by khlavaty ### ########.fr */
/* */
/* ************************************************************************** */
#include "minirt.h"
// returns open file descriptor - manually close after!
int open_file(char *filename)
{
int fd;
fd = open(filename, O_RDONLY);
if (fd < 0)
error_throw("Cannot open file");
if (!is_rt_file(filename))
error_throw("Not an .rt file");
return (fd);
}
int is_rt_file(char *filename)
{
int len;
len = ft_strlen(filename) - 3;
if (len > 3)
return (ft_strncmp(filename + len, ".rt", 3) == 0);
return (0);
}
void add_object(t_map *map, t_obj_type type, void *object, int col)
{
t_obj *new_obj;
new_obj = malloc(sizeof(t_obj));
new_obj->type = type;
new_obj->object = object;
new_obj->color = col;
new_obj->next = map->objects;
new_obj->id = rand();
map->objects = new_obj;
}