-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcheck_argv.c
45 lines (42 loc) · 1.89 KB
/
check_argv.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* check_argv.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jaesjeon <jaesjeon@student.42seoul.kr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/03 11:56:31 by jaesjeon #+# #+# */
/* Updated: 2022/11/12 19:02:31 by jaesjeon ### ########.fr */
/* */
/* ************************************************************************** */
#include "cub3d.h"
#include "ft_string.h"
#include <fcntl.h>
#include <stdio.h>
void check_argv(int argc, char *argv[], t_game *game)
{
char *filename;
size_t name_len;
int fd;
if (argc != 2)
exit_with_err("execute with one argument(.cub file)", E_INVAL);
filename = get_filename_from_path(argv[1]);
name_len = ft_strlen(filename);
if (name_len > 4 && ft_strcmp(&filename[name_len - 4], ".cub"))
{
printf("Valid filename. Try to open file\n");
fd = open(argv[1], O_RDONLY);
if (fd == ERROR)
exit_with_err("fail to open file", E_PERM);
printf("Success to open file. Reading texture elements...\n");
check_texture_elements(fd, game);
printf("All texture elements loaded. Reading map...\n");
printf("*From now on duplicated texture will be considered error\n");
read_map(fd, &game->info, &game->player);
check_map_surrounded_by_wall(game->info.map, \
game->info.map_x, game->info.map_y);
printf("Valid map. Start rendering...\n");
}
else
exit_with_err("argument must be .cub file", E_INVAL);
}