1
0

🚧」 test: testing things, might broke.

This commit is contained in:
Maelys
2024-09-28 20:48:32 +02:00
parent a6929e15e1
commit 073fd2f2ff
20 changed files with 778 additions and 215 deletions

View File

@ -18,10 +18,17 @@ INCLUDE = -I $(I_DIR) -I $(LIBFT_DIR)/$(I_DIR) -I $(MACRO_DIR)/$(I_DIR)
SRCS = src/utils/mess_error.c \ SRCS = src/utils/mess_error.c \
src/utils/parse_utils.c \ src/utils/parse_utils.c \
src/utils/parse_utils_two.c \
src/utils/parse_utils_three.c \
src/utils/utils.c \
src/utils/clear_free.c \
src/parsing/check_image.c \
src/parsing/check_map.c \ src/parsing/check_map.c \
src/parsing/check_arg.c \ src/parsing/check_arg.c \
src/parsing/check_id_text.c \ src/parsing/check_id_text.c \
src/parsing/check_rgb.c \ src/parsing/check_rgb.c \
src/parsing/color_utils.c \
src/parsing/find_player.c \
src/parsing/principal_pars.c \ src/parsing/principal_pars.c \
src/cub3d.c src/cub3d.c

View File

@ -6,7 +6,7 @@
/* By: madumerg <madumerg@42angouleme.fr> +#+ +:+ +#+ */ /* By: madumerg <madumerg@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/09/04 17:01:05 by madumerg #+# #+# */ /* Created: 2024/09/04 17:01:05 by madumerg #+# #+# */
/* Updated: 2024/09/15 20:43:25 by madumerg ### ########.fr */ /* Updated: 2024/09/28 15:55:04 by madumerg ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -23,5 +23,4 @@
# include <stdio.h> # include <stdio.h>
# include "parsing.h" # include "parsing.h"
#endif #endif

View File

@ -6,10 +6,13 @@
/* By: madumerg <madumerg@42angouleme.fr> +#+ +:+ +#+ */ /* By: madumerg <madumerg@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/09/04 21:59:56 by madumerg #+# #+# */ /* Created: 2024/09/04 21:59:56 by madumerg #+# #+# */
/* Updated: 2024/09/16 12:18:42 by madumerg ### ########.fr */ /* Updated: 2024/09/28 16:52:46 by madumerg ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
//general
#define CRASH "Memory problems or open failed"
//for argurments //for argurments
#define ERR_ARGS "Wrong number of arguments" #define ERR_ARGS "Wrong number of arguments"
@ -22,9 +25,14 @@
#define ERR_PLAYER "Incorrect number of players" #define ERR_PLAYER "Incorrect number of players"
#define WRONG_CHAR "Invalid character in the map" #define WRONG_CHAR "Invalid character in the map"
//for permission //for information map
#define ERR_IMG "Problem with image" #define ERR_IMG "Problem with image"
#define WRONG_F_IMG "Wrong type of image"
#define DUP_ACR "There is a duplicate acronym" #define DUP_ACR "There is a duplicate acronym"
#define DUP_IMG "There is a duplicate image" #define DUP_IMG "There is a duplicate image"
#define NOT_FOUND "Information searched is not complete" #define NOT_FOUND "Information searched is not complete"
#define ERR_COLOR "The number is not between 0 and 255"
#define DUP_COLOR "Impossible to have the same color on the floor and ceiling"
#define WRONG_F_RGB "Wrong format RGB"
#define INVALID_CHAR "Invalid character in format color"

View File

@ -6,7 +6,7 @@
/* By: madumerg <madumerg@42angouleme.fr> +#+ +:+ +#+ */ /* By: madumerg <madumerg@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/09/12 12:49:16 by madumerg #+# #+# */ /* Created: 2024/09/12 12:49:16 by madumerg #+# #+# */
/* Updated: 2024/09/16 14:23:15 by madumerg ### ########.fr */ /* Updated: 2024/09/28 17:54:07 by madumerg ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -23,11 +23,14 @@ typedef struct s_pars
{ {
int f_color; int f_color;
int c_color; int c_color;
int color;
char l_player;
t_coord coor; t_coord coor;
char *no_png; char *no_png;
char *so_png; char *so_png;
char *we_png; char *we_png;
char *ea_png; char *ea_png;
char **map;
} t_pars; } t_pars;
//check_arg.c //check_arg.c
@ -35,32 +38,63 @@ int check_err_arg(int ac, char **av);
int check_format_file(char *file); int check_format_file(char *file);
//check_id_text.c //check_id_text.c
int check_texture(char *sign, char *path, t_pars *pars);
int detect_info(char **tab, t_pars *pars); int detect_info(char **tab, t_pars *pars);
//check_image.c
int assign_img(char *sign, char *path, t_pars *pars);
int check_dup_img(t_pars *pars); int check_dup_img(t_pars *pars);
int check_texture(char *sign, char *path, t_pars *pars);
//check_map.c //check_map.c
int err_not_close(char after, char before, char down, char up); int err_not_close(char after, char before, char down, char up);
int actual_char(char actual); int actual_char(char actual);
int check_map_close(char **map); int check_map_close(char **map);
int count_player(char **map);
int check_char_map(char **map); int check_char_map(char **map);
//check_rgb.c //check_rgb.c
int check_format_rgb(char **tab); int check_format_rgb(char *sign, char **tab, t_pars *pars);
//color_utils.c
int create_argb(int r, int g, int b);
char *ft_strndup_color(char *src, int start, int end);
int check_char_color(char *tab);
int check_dup_color(t_pars *pars);
//find_player.c
int search_letter(char **map, int i, char l);
int count_player(char **map, t_pars *pars, int ct);
//principal_pars.c //principal_pars.c
int verif_info_file(char *av, t_pars *pars); int verif_info_file(char *av, t_pars *pars);
int verif_all_map(char **map); int verif_all_map(char **map, t_pars *pars);
char **parse_map(char *map); char **parse_file(char *map, int ct, int i);
//mess_error.c in utils //mess_error.c in utils
int err_mess(char *str); int err_mess(char *str);
//parse_utils.c //parse_utils.c
char **info_map(char **file); char **info_map(char **file);
void convert_white_s(char *str);
int verif_char(char c); int verif_char(char c);
int count_tab(char **tab);
int space_line(char *line); int space_line(char *line);
//parse_utils_two.c
int ft_count_line_map(char **map, int y);
void replace_nl(char *l);
int recup_map(char **old_map, int i, t_pars *pars);
int all_skip(char **map, t_pars *pars);
//parse_utils_three.c
char **alloc_map(char **old_map, int size);
char *fill_line(char *l, int size);
int last_first_line(char **map);
//utils.c
int count_tab(char **tab);
void convert_white_s(char *str);
int longest_line(char **line);
int count_line_file(int fd);
//clear_free.c
void free_tab(char **tab);
void free_pars(t_pars *pars);
#endif #endif

35
map.cub
View File

@ -1,17 +1,20 @@
NO ./no_texture.png
SO ./so_texture.png
WE ./we_texture.png
EA ./ea_texture.png
F 220 , 100, 0
C 225, 30, 0
11111
1001S1
11111
11111
11111
11101
11111
111
101 NO ./no_texture.png
111 SO ./so_texture.png
WE ./we_texture.png
EA ./ea_texture.png
C 7,4,4
F 7,4,40
111111
1000W1
111111

View File

@ -6,7 +6,7 @@
/* By: madumerg <madumerg@42angouleme.fr> +#+ +:+ +#+ */ /* By: madumerg <madumerg@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/09/04 16:58:27 by madumerg #+# #+# */ /* Created: 2024/09/04 16:58:27 by madumerg #+# #+# */
/* Updated: 2024/09/16 13:54:52 by madumerg ### ########.fr */ /* Updated: 2024/09/28 20:12:50 by madumerg ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -16,8 +16,10 @@ t_pars init_pars(void)
{ {
t_pars new; t_pars new;
new.f_color = 0; new.f_color = -1;
new.c_color = 0; new.c_color = -1;
new.color = 0;
new.l_player = 0;
new.coor.x = 0; new.coor.x = 0;
new.coor.y = 0; new.coor.y = 0;
new.no_png = NULL; new.no_png = NULL;
@ -27,14 +29,34 @@ t_pars init_pars(void)
return (new); return (new);
} }
int basics_check(int ac, char **av, t_pars *pars)
{
if (check_err_arg(ac, av) == 1)
return (1);
if (verif_info_file(av[1], pars) == 1)
return (1);
return (0);
}
int main(int ac, char **av) int main(int ac, char **av)
{ {
t_pars pars; t_pars pars;
int i;
i = 0;
pars = init_pars(); pars = init_pars();
if (check_err_arg(ac, av) == 1) if (basics_check(ac, av, &pars) == 1)
return (1); return (1);
if (verif_info_file(av[1], &pars) == 1) printf ("f color %d\n", pars.f_color);
printf("main\n"); printf ("c color %d\n", pars.c_color);
printf ("x = %d\n", pars.coor.x);
printf ("y = %d\n", pars.coor.y);
printf ("no_png --> %s\n", pars.no_png);
printf ("so_png --> %s\n", pars.so_png);
printf ("we_png --> %s\n", pars.we_png);
printf ("ea_png --> %s\n", pars.ea_png);
while (pars.map[i])
printf("|%s|\n", pars.map[i++]);
free_pars(&pars);
return (0); return (0);
} }

View File

@ -6,78 +6,12 @@
/* By: madumerg <madumerg@42angouleme.fr> +#+ +:+ +#+ */ /* By: madumerg <madumerg@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/09/16 09:38:32 by madumerg #+# #+# */ /* Created: 2024/09/16 09:38:32 by madumerg #+# #+# */
/* Updated: 2024/09/16 14:38:35 by madumerg ### ########.fr */ /* Updated: 2024/09/28 17:06:14 by madumerg ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "cub3d.h" #include "cub3d.h"
int check_dup_img(t_pars *pars)
{
if (!pars->no_png || !pars->so_png || !pars->we_png || !pars->ea_png)
return (err_mess(NOT_FOUND));
if (ft_strcmp(pars->no_png, pars->so_png) == 0 || \
ft_strcmp(pars->no_png, pars->we_png) == 0 || \
ft_strcmp(pars->no_png, pars->ea_png) == 0 || \
ft_strcmp(pars->so_png, pars->we_png) == 0 || \
ft_strcmp(pars->we_png, pars->ea_png) == 0)
return (err_mess(DUP_IMG));
return (0);
}
int assign_img_two(char *sign, char *path, t_pars *pars)
{
if (ft_strcmp("WE", sign) == 0)
{
if (pars->we_png == NULL)
pars->we_png = path;
else
return (err_mess(DUP_ACR));
}
else if (ft_strcmp("EA", sign) == 0)
{
if (pars->ea_png == NULL)
pars->ea_png = path;
else
return (err_mess(DUP_ACR));
}
return (0);
}
int assign_img(char *sign, char *path, t_pars *pars)
{
if (ft_strcmp("NO", sign) == 0)
{
if (pars->no_png == NULL)
pars->no_png = path;
else
return (err_mess(DUP_ACR));
}
else if (ft_strcmp("SO", sign) == 0)
{
if (pars->so_png == NULL)
pars->so_png = path;
else
return (err_mess(DUP_ACR));
}
if (assign_img_two(sign, path, pars) == 1)
return (1);
return (0);
}
int check_texture(char *sign, char *path, t_pars *pars)
{
int fd;
fd = -1;
fd = open(path, O_RDONLY, 0644);
if (fd < 0)
return (err_mess(ERR_IMG));
if (assign_img(sign, path, pars) == 1)
return (1);
return (0);
}
int detect_info(char **tab, t_pars *pars) int detect_info(char **tab, t_pars *pars)
{ {
if (ft_strcmp("NO", tab[0]) == 0 && count_tab(tab) == 2) if (ft_strcmp("NO", tab[0]) == 0 && count_tab(tab) == 2)
@ -88,10 +22,10 @@ int detect_info(char **tab, t_pars *pars)
return (check_texture(tab[0], tab[1], pars)); return (check_texture(tab[0], tab[1], pars));
else if (ft_strcmp("EA", tab[0]) == 0 && count_tab(tab) == 2) else if (ft_strcmp("EA", tab[0]) == 0 && count_tab(tab) == 2)
return (check_texture(tab[0], tab[1], pars)); return (check_texture(tab[0], tab[1], pars));
else if (ft_strcmp("F", tab[0]) == 0) else if (ft_strcmp("F", tab[0]) == 0 && count_tab(tab) == 2)
check_format_rgb(tab); return (check_format_rgb("F", tab, pars));
else if (ft_strcmp("C", tab[0]) == 0) else if (ft_strcmp("C", tab[0]) == 0 && count_tab(tab) == 2)
check_format_rgb(tab); return (check_format_rgb("C", tab, pars));
else else
return (err_mess(NOT_FOUND)); return (err_mess(NOT_FOUND));
return (0); return (0);

99
src/parsing/check_image.c Normal file
View File

@ -0,0 +1,99 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* check_image.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: madumerg <madumerg@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/09/19 10:44:07 by madumerg #+# #+# */
/* Updated: 2024/09/28 20:14:47 by madumerg ### ########.fr */
/* */
/* ************************************************************************** */
#include "cub3d.h"
int check_dup_img(t_pars *pars)
{
if (!pars->no_png || !pars->so_png || !pars->we_png || !pars->ea_png)
return (err_mess(NOT_FOUND));
if (ft_strcmp(pars->no_png, pars->so_png) == 0 || \
ft_strcmp(pars->no_png, pars->we_png) == 0 || \
ft_strcmp(pars->no_png, pars->ea_png) == 0 || \
ft_strcmp(pars->so_png, pars->we_png) == 0 || \
ft_strcmp(pars->we_png, pars->ea_png) == 0)
return (err_mess(DUP_IMG));
return (0);
}
int assign_img_two(char *sign, char *path, t_pars *pars)
{
if (ft_strcmp("WE", sign) == 0)
{
if (pars->we_png == NULL)
pars->we_png = path;
else
return (err_mess(DUP_ACR));
}
else if (ft_strcmp("EA", sign) == 0)
{
if (pars->ea_png == NULL)
pars->ea_png = path;
else
return (err_mess(DUP_ACR));
}
return (0);
}
int assign_img(char *sign, char *path, t_pars *pars)
{
if (ft_strcmp("NO", sign) == 0)
{
if (pars->no_png == NULL)
pars->no_png = path;
else
return (err_mess(DUP_ACR));
}
else if (ft_strcmp("SO", sign) == 0)
{
if (pars->so_png == NULL)
pars->so_png = path;
else
return (err_mess(DUP_ACR));
}
if (assign_img_two(sign, path, pars) == 1)
return (1);
return (0);
}
int format_img(char *img)
{
int len;
len = ft_strlen(img) - 1;
if (img[len] == 'g' && img[len - 1] == 'n' && \
img[len - 2] == 'p' && img[len - 3] == '.')
return (0);
return (1);
}
int check_texture(char *sign, char *path, t_pars *pars)
{
int fd;
fd = -1;
fd = open(path, O_RDONLY, 0644);
if (fd < 0)
return (err_mess(ERR_IMG));
if (format_img(path) == 1)
{
close(fd);
return (err_mess(WRONG_F_IMG));
}
if (assign_img(sign, path, pars) == 1)
{
close(fd);
return (1);
}
close(fd);
return (0);
}

View File

@ -6,7 +6,7 @@
/* By: madumerg <madumerg@42angouleme.fr> +#+ +:+ +#+ */ /* By: madumerg <madumerg@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/09/11 11:24:13 by madumerg #+# #+# */ /* Created: 2024/09/11 11:24:13 by madumerg #+# #+# */
/* Updated: 2024/09/12 12:57:24 by madumerg ### ########.fr */ /* Updated: 2024/09/28 15:48:38 by madumerg ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -14,13 +14,13 @@
int err_not_close(char after, char before, char down, char up) int err_not_close(char after, char before, char down, char up)
{ {
if (after == ' ' || after == '\0') if (after == ' ' || after == '\0' || after == '\n')
return (1); return (1);
else if (before == ' ' || before == '\0') else if (before == ' ' || before == '\0' || before == '\n')
return (1); return (1);
else if (down == ' ' || down == '\0') else if (down == ' ' || down == '\0' || down == '\n')
return (1); return (1);
else if (up == ' ' || up == '\0') else if (up == ' ' || up == '\0' || up == '\n')
return (1); return (1);
return (0); return (0);
} }
@ -39,6 +39,8 @@ int check_map_close(char **map)
int x; int x;
y = 0; y = 0;
if (last_first_line(map) == 1)
return (1);
while (map[y]) while (map[y])
{ {
x = 0; x = 0;
@ -56,31 +58,6 @@ int check_map_close(char **map)
return (0); return (0);
} }
int count_player(char **map)
{
int y;
int x;
int cpt;
cpt = 0;
y = 0;
while (map[y])
{
x = 0;
while (map[y][x])
{
if (map[y][x] == 'N' || map[y][x] == 'S' || \
map[y][x] == 'E' || map[y][x] == 'W')
cpt++;
x++;
}
y++;
}
if (cpt != 1)
return (1);
return (0);
}
int check_char_map(char **map) int check_char_map(char **map)
{ {
int y; int y;

View File

@ -6,21 +6,78 @@
/* By: madumerg <madumerg@42angouleme.fr> +#+ +:+ +#+ */ /* By: madumerg <madumerg@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/09/16 09:36:07 by madumerg #+# #+# */ /* Created: 2024/09/16 09:36:07 by madumerg #+# #+# */
/* Updated: 2024/09/16 14:59:30 by madumerg ### ########.fr */ /* Updated: 2024/09/28 17:08:01 by madumerg ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "cub3d.h" #include "cub3d.h"
int check_format_rgb(char **tab) int check_nb_color(char *r, char *g, char *b)
{ {
int i = 0; if (ft_strlen(r) > 3 || ft_strlen(g) > 3 || ft_strlen(b) > 3 || \
while (tab[i]) ft_atoi(r) > 255 || ft_atoi(g) > 255 || ft_atoi(b) > 255)
printf(".%s.\n", tab[i++]); return (-1);
return (0); return (0);
} }
int create_argb(int a, int r, int g, int b) int save_color(char *tab, t_pars *pars, int j)
{ {
return (a << 24 | r << 16 | g << 8 | b); char *r;
char *g;
char *b;
int i;
i = 0;
while (tab[i] != ',')
i++;
r = ft_strndup_color(tab, 0, i);
i += 1;
j = i;
while (tab[i] != ',')
i++;
g = ft_strndup_color(tab, j, i);
i += 1;
j = i;
while (tab[i])
i++;
b = ft_strndup_color(tab, j, i);
if (check_nb_color(r, g, b) == -1)
return (-1);
pars->color = create_argb(ft_atoi(r), ft_atoi(g), ft_atoi(b));
return (0);
}
int count_precise_char(char *str, char c)
{
int ct;
int i;
i = 0;
ct = 0;
while (str[i])
{
if (str[i] == c)
ct++;
i++;
}
if (ct != 2)
return (1);
return (0);
}
int check_format_rgb(char *sign, char **tab, t_pars *pars)
{
if (count_tab(tab) > 2)
return (err_mess(NOT_FOUND));
if (check_char_color(tab[1]) == 1)
return (err_mess(INVALID_CHAR));
if (count_precise_char(tab[1], ',') == 1)
return (err_mess(WRONG_F_RGB));
if (save_color(tab[1], pars, 0) == -1)
return (err_mess(ERR_COLOR));
if (ft_strcmp(sign, "F") == 0)
pars->f_color = pars->color;
else if (ft_strcmp(sign, "C") == 0)
pars->c_color = pars->color;
return (0);
} }

69
src/parsing/color_utils.c Normal file
View File

@ -0,0 +1,69 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* color_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: madumerg <madumerg@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/09/18 19:44:37 by madumerg #+# #+# */
/* Updated: 2024/09/28 17:32:06 by madumerg ### ########.fr */
/* */
/* ************************************************************************** */
#include "cub3d.h"
int check_dup_color(t_pars *pars)
{
if (pars->c_color < 0 || pars->f_color < 0)
return (err_mess(NOT_FOUND));
if (pars->c_color == pars->f_color)
return (err_mess(DUP_COLOR));
return (0);
}
int create_argb(int r, int g, int b)
{
return (r << 16 | g << 8 | b);
}
char *ft_strndup_color(char *src, int start, int end)
{
int size;
char *dest;
int i;
size = start;
i = 0;
dest = ft_calloc(sizeof(char), ft_strlen(src) + 1);
if (dest == NULL)
return (NULL);
while (size < end)
{
dest[i] = src[size];
size++;
i++;
}
dest[i] = '\0';
return (dest);
}
int valid_char_color(char c)
{
if (c == ',' || (c >= '0' && c <= '9'))
return (0);
return (1);
}
int check_char_color(char *tab)
{
int i;
i = 0;
while (tab[i])
{
if (valid_char_color(tab[i]) == 1)
return (1);
i++;
}
return (0);
}

64
src/parsing/find_player.c Normal file
View File

@ -0,0 +1,64 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* find_player.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: madumerg <madumerg@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/09/17 14:57:11 by madumerg #+# #+# */
/* Updated: 2024/09/19 09:55:38 by madumerg ### ########.fr */
/* */
/* ************************************************************************** */
#include "cub3d.h"
int search_letter(char **map, int i, char l)
{
int x;
int y;
y = 0;
while (map[y])
{
x = 0;
while (map[y][x])
{
if (map[y][x] == l)
{
if (i == 0)
return (x);
else if (i == 1)
return (y);
}
x++;
}
y++;
}
return (0);
}
int count_player(char **map, t_pars *pars, int ct)
{
int y;
int x;
y = 0;
while (map[y])
{
x = 0;
while (map[y][x])
{
if (map[y][x] == 'N' || map[y][x] == 'S' || \
map[y][x] == 'E' || map[y][x] == 'W')
{
pars->l_player = map[y][x];
ct++;
}
x++;
}
y++;
}
if (ct != 1)
return (1);
return (0);
}

View File

@ -1,18 +0,0 @@
// convertir tt les whites spaces en simple espace sur les 6 1ere lignes
//check si .png
WARNIIIIIINNNNNNNNNNNNNGGG TESTER LES MALLOC A NULL
//faire search player
utiliser la ft pour couleur
no so
no we
no ea
so we
so ea
we ea

View File

@ -6,7 +6,7 @@
/* By: madumerg <madumerg@42angouleme.fr> +#+ +:+ +#+ */ /* By: madumerg <madumerg@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/09/12 12:44:52 by madumerg #+# #+# */ /* Created: 2024/09/12 12:44:52 by madumerg #+# #+# */
/* Updated: 2024/09/16 14:58:26 by madumerg ### ########.fr */ /* Updated: 2024/09/28 20:40:30 by madumerg ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -15,7 +15,10 @@
int all_data_verif(char **tab, t_pars *pars) int all_data_verif(char **tab, t_pars *pars)
{ {
if (detect_info(tab, pars) == 1) if (detect_info(tab, pars) == 1)
{
free_tab(tab);
return (1); return (1);
}
return (0); return (0);
} }
@ -31,10 +34,13 @@ int check_info(char **l, t_pars *pars)
while (l[i]) while (l[i])
{ {
tab = ft_split(l[i], ' '); tab = ft_split(l[i], ' ');
if (tab == NULL)
return (1);
if (all_data_verif(tab, pars) == 1) if (all_data_verif(tab, pars) == 1)
return (1); return (1);
i++; i++;
} }
free_tab(tab);
return (0); return (0);
} }
@ -43,49 +49,67 @@ int verif_info_file(char *av, t_pars *pars)
char **map; char **map;
char **f_part; char **f_part;
(void)pars; map = parse_file(av, 0, 1);
map = parse_map(av); if (map == NULL)
return (err_mess(CRASH));
f_part = info_map(map); f_part = info_map(map);
if (check_info(f_part, pars) == 1) if (f_part == NULL)
{
free_tab(map);
return (err_mess(CRASH));
}
if (check_info(f_part, pars) == 1 || check_dup_img(pars) == 1 || \
check_dup_color(pars) == 1)
{
free_tab(map);
return (1);
}
if (all_skip(map, pars) == 1)
return (1); return (1);
// if (check_dup_img(pars) == 1)
// return (1);
// if (verif_all_map(map) == 1)
// return (1);
return (0); return (0);
} }
int verif_all_map(char **map) int verif_all_map(char **map, t_pars *pars)
{ {
if (check_char_map(map) == 1) pars->map = alloc_map(map, longest_line(map));
free_tab(map);
if (pars->map == NULL)
return (err_mess(CRASH));
if (check_char_map(pars->map) == 1)
return (err_mess(WRONG_CHAR)); return (err_mess(WRONG_CHAR));
if (count_player(map) == 1) if (count_player(pars->map, pars, 0) == 1)
return (err_mess(ERR_PLAYER)); return (err_mess(ERR_PLAYER));
if (check_map_close(map) == 1) if (check_map_close(pars->map) == 1)
return (err_mess(NOT_CLOSE)); return (err_mess(NOT_CLOSE));
pars->coor.x = search_letter(pars->map, 0, pars->l_player);
pars->coor.y = search_letter(pars->map, 1, pars->l_player);
return (0); return (0);
} }
char **parse_map(char *map) char **parse_file(char *map, int ct, int i)
{ {
int fd; int fd;
char **parse_map; char **parse_map;
char *save;
char *join;
fd = open(map, O_RDONLY); fd = open(map, O_RDONLY);
save = get_next_line(fd); if (fd < 0)
join = ft_calloc(1, 1);
if (!join)
return (NULL); return (NULL);
while (save != NULL) ct = count_line_file(fd);
fd = open(map, O_RDONLY);
if (fd < 0)
return (NULL);
parse_map = ft_calloc(sizeof(char *), ct + 1);
if (!parse_map)
{ {
join = ft_strjoin(join, save); close(fd);
free(save); return (NULL);
save = get_next_line(fd);
} }
parse_map = ft_split(join, '\n'); parse_map[0] = get_next_line(fd);
free(join); while (i <= ct)
close(fd); {
parse_map[i] = get_next_line(fd);
i++;
}
close (fd);
return (parse_map); return (parse_map);
} }

41
src/utils/clear_free.c Normal file
View File

@ -0,0 +1,41 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* clear_free.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: madumerg <madumerg@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/09/28 17:37:10 by madumerg #+# #+# */
/* Updated: 2024/09/28 17:43:25 by madumerg ### ########.fr */
/* */
/* ************************************************************************** */
#include "cub3d.h"
void free_tab(char **tab)
{
char **tmp;
tmp = tab;
while (tmp && *tmp)
{
free(*tmp);
tmp++;
}
free(tab);
tab = NULL;
}
void free_pars(t_pars *pars)
{
if (pars->no_png)
free(pars->no_png);
if (pars->so_png)
free(pars->so_png);
if (pars->we_png)
free(pars->we_png);
if (pars->ea_png)
free(pars->ea_png);
if (pars->map)
free_tab(pars->map);
}

View File

@ -6,7 +6,7 @@
/* By: madumerg <madumerg@42angouleme.fr> +#+ +:+ +#+ */ /* By: madumerg <madumerg@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/09/11 14:20:54 by madumerg #+# #+# */ /* Created: 2024/09/11 14:20:54 by madumerg #+# #+# */
/* Updated: 2024/09/16 14:55:36 by madumerg ### ########.fr */ /* Updated: 2024/09/28 17:32:42 by madumerg ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -38,7 +38,7 @@ char **info_map(char **file)
i = 0; i = 0;
j = 0; j = 0;
f_part = ft_calloc(6, sizeof(char *)); f_part = ft_calloc(6 + 1, sizeof(char *));
if (!f_part) if (!f_part)
return (NULL); return (NULL);
while (i >= j) while (i >= j)
@ -55,19 +55,6 @@ char **info_map(char **file)
return (f_part); return (f_part);
} }
void convert_white_s(char *str)
{
int i;
i = 0;
while (str[i])
{
if (str[i] >= 9 && str[i] <= 13)
str[i] = 32;
i++;
}
}
int verif_char(char c) int verif_char(char c)
{ {
if (c != '1' && c != '0' && c != 'N' && c != 'S' && c != 'W' && \ if (c != '1' && c != '0' && c != 'N' && c != 'S' && c != 'W' && \
@ -75,18 +62,3 @@ int verif_char(char c)
return (1); return (1);
return (0); return (0);
} }
int count_tab(char **tab)
{
int i;
int ct;
i = 0;
ct = 0;
while (tab[i])
{
i++;
ct++;
}
return (ct);
}

View File

@ -0,0 +1,98 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* parse_utils_three.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: madumerg <madumerg@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/09/28 15:40:12 by madumerg #+# #+# */
/* Updated: 2024/09/28 17:32:55 by madumerg ### ########.fr */
/* */
/* ************************************************************************** */
#include "cub3d.h"
char *fill_line(char *l, int size)
{
char *tmp;
int i;
int j;
i = 0;
j = 0;
tmp = ft_calloc(sizeof(char), size + 1);
if (!tmp)
return (NULL);
while (l[j])
{
tmp[i] = l[j];
i++;
j++;
}
if (i < size)
{
while (i <= size - 1)
{
tmp[i] = ' ';
i++;
}
}
tmp[i] = '\0';
return (tmp);
}
char **alloc_map(char **old_map, int size)
{
int i;
int j;
char **tmp;
i = 0;
j = 0;
tmp = ft_calloc(sizeof(char *), ft_count_line_map(old_map, 0) + 1);
if (!tmp)
return (NULL);
while (old_map[j])
{
tmp[i] = fill_line(old_map[j], size);
if (tmp[i] == NULL)
return (NULL);
i++;
j++;
}
tmp[i] = NULL;
return (tmp);
}
int line_char(char *l)
{
int i;
i = 0;
while (l[i])
{
if (actual_char(l[i]) == 0)
return (1);
else
i++;
}
return (0);
}
int last_first_line(char **map)
{
int y;
int tmp;
tmp = ft_count_line_map(map, 0);
y = 0;
while (map[y])
{
if ((y == 0 && line_char(map[y]) == 1) || \
(y == (tmp - 1) && line_char(map[y]) == 1))
return (1);
else
y++;
}
return (0);
}

View File

@ -0,0 +1,96 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* parse_utils_two.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: madumerg <madumerg@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/09/17 15:12:28 by madumerg #+# #+# */
/* Updated: 2024/09/28 20:44:38 by madumerg ### ########.fr */
/* */
/* ************************************************************************** */
#include "cub3d.h"
int ft_count_line_map(char **file, int y)
{
while (file[y])
y++;
return (y);
}
void replace_nl(char *l)
{
int i;
i = 0;
while (l[i])
{
if (l[i] == '\n')
l[i] = '\0';
i++;
}
}
int recup_map(char **old_map, int i, t_pars *pars)
{
char **tmp;
int j;
j = 0;
tmp = ft_calloc(sizeof(char *), ft_count_line_map(old_map, i));
if (!tmp)
return (err_mess(CRASH));
while (old_map[i])
{
replace_nl(old_map[i]);
tmp[j] = old_map[i];
j++;
i++;
}
if (verif_all_map(tmp, pars) == 1)
return (1);
return (0);
}
int space_l_two(char *line)
{
int i;
i = 0;
while (line[i])
{
if (line[i] == ' ' || (line[i] >= 9 && line[i] <= 13))
i++;
else
break ;
}
if (line[i] != '\0')
return (1);
return (0);
}
int all_skip(char **map, t_pars *pars)
{
char **tmp;
int ct;
int i;
ct = 0;
i = 0;
tmp = map;
while (tmp[i])
{
if (space_line(tmp[i]) == 1)
ct++;
if (ct == 6)
break ;
i++;
}
i += 1;
while (tmp[i] && space_l_two(tmp[i]) != 1)
i++;
if (recup_map(map, i, pars) == 1)
return (1);
return (0);
}

77
src/utils/utils.c Normal file
View File

@ -0,0 +1,77 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: madumerg <madumerg@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/09/20 09:57:13 by madumerg #+# #+# */
/* Updated: 2024/09/28 14:55:56 by madumerg ### ########.fr */
/* */
/* ************************************************************************** */
#include "cub3d.h"
int count_tab(char **tab)
{
int i;
int ct;
i = 0;
ct = 0;
while (tab[i])
{
i++;
ct++;
}
return (ct);
}
void convert_white_s(char *str)
{
int i;
i = 0;
while (str[i])
{
if (str[i] >= 9 && str[i] <= 13)
str[i] = 32;
i++;
}
}
int longest_line(char **line)
{
int i;
int stock;
int actual;
stock = ft_strlen(line[0]);
i = 1;
actual = 0;
while (line[i])
{
actual = ft_strlen(line[i]);
if (actual > stock)
stock = actual;
i++;
}
return (stock);
}
int count_line_file(int fd)
{
int i;
char *gnl;
i = 0;
gnl = get_next_line(fd);
while (gnl)
{
free(gnl);
gnl = get_next_line(fd);
i++;
}
close (fd);
return (i);
}

0
tamere.jpeg Normal file
View File