diff --git a/src/main.c b/src/main.c index 107549b..e4674ed 100644 --- a/src/main.c +++ b/src/main.c @@ -3,15 +3,19 @@ /* ::: :::::::: */ /* main.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: freddy +#+ +:+ +#+ */ +/* By: tchampio +#include +#include typedef struct s_mlx_data { @@ -22,6 +26,13 @@ typedef struct s_mlx_data int endian; } t_mlx_data; +typedef struct s_mapdata +{ + char *filename; + bool isvalid; + char error[1024]; +} t_mapdata; + void my_mlx_pixel_put(t_mlx_data *data, int x, int y, int color) { char *dst; @@ -30,15 +41,36 @@ void my_mlx_pixel_put(t_mlx_data *data, int x, int y, int color) *(unsigned int*)dst = color; } +bool check_filename(char *file) +{ + (void)file; + return (false); +} + +bool check_cubfile(char *file, t_mapdata *map) +{ + int fd; + + fd = open(file, O_RDONLY); + if (fd < 0) + return (ft_strlcpy(map->error, "Can't open file", 16), false); + if (!check_filename(file)) + return (ft_strlcpy(map->error, "File is not a .cub file", 25), false); + close(fd); + return (true); +} + int main(int argc, char **argv) { void *mlx; void *mlx_win; t_mlx_data data; + t_mapdata map; if (argc < 2) return (ft_printf("Error: Missing cub3d filename\n"), 1); - (void)argv; + if (!check_cubfile(argv[1], &map)) + return (ft_printf("Error: Wrong map file. Reason: %s\n", map.error), 1); mlx = mlx_init(); mlx_win = mlx_new_window(mlx, 800, 600, "Cub3d"); data.img = mlx_new_image(mlx, 800, 600);