diff --git a/Makefile b/Makefile index fbdc7c0..cc7d2cf 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,7 @@ CC=cc -CFLAGS=-Wall -Wextra -Werror -g -fsanitize=address -fno-omit-frame-pointer -I mlx +SANITIZERS= +#-fsanitize-address -fno-omit-frame-pointer +CFLAGS=-Wall -Wextra -Werror -g $(SANITIZERS) -I mlx SOURCEFILES=src/main.c \ src/map/map_checker.c OBJECTS=$(patsubst src/%.c,objects/%.o,$(SOURCEFILES)) diff --git a/includes/cub3d_consts.h b/includes/cub3d_consts.h new file mode 100644 index 0000000..ebd1896 --- /dev/null +++ b/includes/cub3d_consts.h @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* cub3d_consts.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tchampio @@ -61,7 +62,7 @@ int main(int argc, char **argv) t_mapdata map; if (argc < 2) - return (ft_printf("Error: Missing cub3d filename\n"), 1); + return (ft_printf("Error: Missing cub3d file\n"), 1); if (!check_cubfile(argv[1], &map)) return (ft_printf("Error: Wrong map file. Reason: %s\n", map.error), 1); mlx = mlx_init(); diff --git a/src/map/map_checker.c b/src/map/map_checker.c index 15e3106..2a22e12 100644 --- a/src/map/map_checker.c +++ b/src/map/map_checker.c @@ -1,3 +1,15 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* map_checker.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tchampio #include @@ -6,33 +18,32 @@ void print_mapdata(const t_mapdata *data) { ft_printf(BOLD CYAN "=== Map Data ===\n" RESET); - ft_printf(BOLD "Filename: " RESET "%s\n", data->filename ? data->filename : "(null)"); - ft_printf(BOLD "NO Texture: " RESET "%s\n", data->NO_texture ? data->NO_texture : "(null)"); - ft_printf(BOLD "SO Texture: " RESET "%s\n", data->SO_texture ? data->SO_texture : "(null)"); - ft_printf(BOLD "WE Texture: " RESET "%s\n", data->WE_texture ? data->WE_texture : "(null)"); - ft_printf(BOLD "EA Texture: " RESET "%s\n", data->EA_texture ? data->EA_texture : "(null)"); - + ft_printf(BOLD "Filename: " RESET "%s\n", data->filename); + ft_printf(BOLD "NO Texture: " RESET "%s\n", data->NO_texture); + ft_printf(BOLD "SO Texture: " RESET "%s\n", data->SO_texture); + ft_printf(BOLD "WE Texture: " RESET "%s\n", data->WE_texture); + ft_printf(BOLD "EA Texture: " RESET "%s\n", data->EA_texture); ft_printf(BOLD "Validity: " RESET); if (data->isvalid) ft_printf(GREEN "VALID\n" RESET); else ft_printf(RED "INVALID\n" RESET); - if (!data->isvalid && data->error[0] != '\0') { ft_printf(BOLD RED "Error: " RESET "%s\n", data->error); } - ft_printf(CYAN "=================\n" RESET); } bool set_textures(char *line, t_mapdata *map) { char **tab; - int i; + int i; tab = ft_split(line, ' '); i = 0; + if (tab[0][0] == '1') + return (false); if (tab[0] && tab[1]) { if (!ft_strncmp(tab[0], "NO", 3) || !ft_strncmp(tab[0], "no", 3)) @@ -57,8 +68,8 @@ bool add_textures(int fd, t_mapdata *map) line = get_next_line(fd); while (line) { - //ft_printf("%s", line); - set_textures(line, map); + if (!set_textures(line, map)) + return (free(line), false); free(line); line = get_next_line(fd); } @@ -68,9 +79,9 @@ bool add_textures(int fd, t_mapdata *map) bool check_filename(char *file) { - int filename_size; - int i; - int j; + int filename_size; + int i; + int j; char end[5]; filename_size = ft_strlen(file); @@ -98,7 +109,9 @@ bool check_cubfile(char *file, t_mapdata *map) fd = open(file, O_RDONLY); if (fd < 0) return (ft_strlcpy(map->error, "Can't open file", 16), false); - add_textures(fd, map); + if (!add_textures(fd, map)) + return (close(fd), ft_strlcpy(map->error, + "Map started before all the textures", 37), false); close(fd); return (true); }