mirror of
https://codeberg.org/ACME-Corporation/cub3d.git
synced 2025-12-06 01:48:08 +01:00
Added filetype checking
This commit is contained in:
parent
8f99d23431
commit
935370ac63
5 changed files with 58 additions and 27 deletions
3
Makefile
3
Makefile
|
|
@ -1,6 +1,7 @@
|
|||
CC=cc
|
||||
CFLAGS=-Wall -Wextra -Werror -g -fsanitize=address -fno-omit-frame-pointer -I mlx
|
||||
SOURCEFILES=src/main.c
|
||||
SOURCEFILES=src/main.c \
|
||||
src/map/map_checker.c
|
||||
OBJECTS=$(patsubst src/%.c,objects/%.o,$(SOURCEFILES))
|
||||
OBJDIR=objects
|
||||
NAME=cub3d
|
||||
|
|
|
|||
15
includes/maputils.h
Normal file
15
includes/maputils.h
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
#ifndef MAPUTILS_H
|
||||
# define MAPUTILS_H
|
||||
|
||||
# include <stdbool.h>
|
||||
|
||||
typedef struct s_mapdata
|
||||
{
|
||||
char *filename;
|
||||
bool isvalid;
|
||||
char error[1024];
|
||||
} t_mapdata;
|
||||
|
||||
bool check_cubfile(char *filename, t_mapdata *map);
|
||||
|
||||
#endif
|
||||
0
objects/map/.gitkeep
Normal file
0
objects/map/.gitkeep
Normal file
27
src/main.c
27
src/main.c
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
#include "../includes/libft.h"
|
||||
#include "../includes/mlx.h"
|
||||
//#include "../includes/filecheck.h"
|
||||
#include "../includes/maputils.h"
|
||||
#include <stdbool.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
|
|
@ -26,12 +26,6 @@ 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)
|
||||
{
|
||||
|
|
@ -41,25 +35,6 @@ 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;
|
||||
|
|
|
|||
40
src/map/map_checker.c
Normal file
40
src/map/map_checker.c
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
#include "../../includes/maputils.h"
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include "../../includes/libft.h"
|
||||
|
||||
bool check_filename(char *file)
|
||||
{
|
||||
int filename_size;
|
||||
int i;
|
||||
int j;
|
||||
char end[5];
|
||||
|
||||
filename_size = ft_strlen(file);
|
||||
i = filename_size;
|
||||
j = 4;
|
||||
ft_bzero(end, 5);
|
||||
while (i > (filename_size - 5))
|
||||
{
|
||||
end[j] = file[i];
|
||||
i--;
|
||||
j--;
|
||||
}
|
||||
if (ft_strncmp(end, ".cub", 5))
|
||||
return (false);
|
||||
else
|
||||
return (true);
|
||||
}
|
||||
|
||||
bool check_cubfile(char *file, t_mapdata *map)
|
||||
{
|
||||
int fd;
|
||||
|
||||
if (!check_filename(file))
|
||||
return (ft_strlcpy(map->error, "File is not a .cub file", 25), false);
|
||||
fd = open(file, O_RDONLY);
|
||||
if (fd < 0)
|
||||
return (ft_strlcpy(map->error, "Can't open file", 16), false);
|
||||
close(fd);
|
||||
return (true);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue