「✨」 feat(Merged parsing): parsing finished
Parsing done
This commit is contained in:
Submodule MacroLibX updated: 5a09ebb179...4d640ed70c
14
Makefile
14
Makefile
@ -18,9 +18,19 @@ INCLUDE = -I $(I_DIR) -I $(LIBFT_DIR)/$(I_DIR) -I $(MACRO_DIR)/$(I_DIR)
|
||||
|
||||
SRCS = src/utils/mess_error.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_arg.c \
|
||||
src/parsing/check_id_text.c \
|
||||
src/parsing/check_rgb.c \
|
||||
src/parsing/color_utils.c \
|
||||
src/parsing/find_player.c \
|
||||
src/parsing/principal_pars.c \
|
||||
src/parsing/start.c \
|
||||
src/cub3d.c
|
||||
|
||||
OBJS = $(addprefix $(OBJSDIR), $(SRCS:.c=.o))
|
||||
@ -33,9 +43,9 @@ LIB = libft/libft.a \
|
||||
$(NAME): $(OBJS)
|
||||
@make -sj $(nproc) -C $(LIBFT_DIR)
|
||||
@echo "✅ Libft compiled"
|
||||
@make -sj $(nproc) -C $(MACRO_DIR) > /dev/null
|
||||
@make -sj $(nproc) -C $(MACRO_DIR)
|
||||
@echo "✅ MacroLibX compiled"
|
||||
@$(CC) $(FLAGS) $(OBJS) $(LIB) -o $(NAME)
|
||||
@$(CC) $(OBJS) $(LIB) -o $(NAME) $(FLAGS)
|
||||
@echo "✅ Compiled"
|
||||
|
||||
$(OBJSDIR)%.o: %.c
|
||||
|
0
ea_texture.png
Executable file
0
ea_texture.png
Executable file
@ -6,21 +6,13 @@
|
||||
/* By: madumerg <madumerg@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/09/04 17:01:05 by madumerg #+# #+# */
|
||||
/* Updated: 2024/09/12 12:54:48 by madumerg ### ########.fr */
|
||||
/* Updated: 2024/10/05 14:30:04 by madumerg ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef CUB3D_H
|
||||
# define CUB3D_H
|
||||
|
||||
# include "../libft/includes/libft.h"
|
||||
# include "mess_err.h"
|
||||
# include <stdlib.h>
|
||||
# include <math.h>
|
||||
# include <unistd.h>
|
||||
# include <fcntl.h>
|
||||
# include <stdio.h>
|
||||
# include "parsing.h"
|
||||
|
||||
|
||||
#endif
|
||||
|
@ -6,10 +6,13 @@
|
||||
/* By: madumerg <madumerg@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/09/04 21:59:56 by madumerg #+# #+# */
|
||||
/* Updated: 2024/09/11 14:18:39 by madumerg ### ########.fr */
|
||||
/* Updated: 2024/10/05 18:34:04 by madumerg ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
//general
|
||||
#define CRASH "Memory problems or open failed"
|
||||
|
||||
//for argurments
|
||||
|
||||
#define ERR_ARGS "Wrong number of arguments"
|
||||
@ -21,5 +24,14 @@
|
||||
#define NOT_CLOSE "The map isn't closed"
|
||||
#define ERR_PLAYER "Incorrect number of players"
|
||||
#define WRONG_CHAR "Invalid character in the map"
|
||||
#define MISS_MAP "Missing map"
|
||||
|
||||
//for permission
|
||||
//for information map
|
||||
|
||||
#define ERR_IMG "Problem with image"
|
||||
#define WRONG_F_IMG "Wrong type of image"
|
||||
#define DUP_ACR "There is a duplicate acronym"
|
||||
#define NOT_FOUND "Information searched is not complete"
|
||||
#define ERR_COLOR "The number is not between 0 and 255"
|
||||
#define WRONG_F_RGB "Wrong format RGB"
|
||||
#define INVALID_CHAR "Invalid character in format color"
|
||||
|
@ -6,13 +6,20 @@
|
||||
/* By: madumerg <madumerg@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/09/12 12:49:16 by madumerg #+# #+# */
|
||||
/* Updated: 2024/09/12 16:58:29 by madumerg ### ########.fr */
|
||||
/* Updated: 2024/10/05 18:43:16 by madumerg ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef PARSING_H
|
||||
# define PARSING_H
|
||||
|
||||
# include "libft.h"
|
||||
# include "ft_printf.h"
|
||||
# include "mess_err.h"
|
||||
# include <stdlib.h>
|
||||
# include <unistd.h>
|
||||
# include <fcntl.h>
|
||||
|
||||
typedef struct s_coord
|
||||
{
|
||||
int x;
|
||||
@ -21,32 +28,82 @@ typedef struct s_coord
|
||||
|
||||
typedef struct s_pars
|
||||
{
|
||||
int f_color;
|
||||
int c_color;
|
||||
int f_color;
|
||||
int c_color;
|
||||
int color;
|
||||
char l_player;
|
||||
t_coord coor;
|
||||
char *no_png;
|
||||
char *so_png;
|
||||
char *we_png;
|
||||
char *ea_png;
|
||||
char **map;
|
||||
} t_pars;
|
||||
|
||||
//check_arg.c
|
||||
int check_err_arg(int ac, char **av);
|
||||
int check_format_file(char *file);
|
||||
//start.c
|
||||
t_pars init_pars(void);
|
||||
int basics_check(int ac, char **av, t_pars *pars);
|
||||
|
||||
//check_arg.c
|
||||
int check_err_arg(int ac, char **av);
|
||||
int check_format_file(char *file);
|
||||
|
||||
//check_id_text.c
|
||||
int detect_info(char **tab, t_pars *pars);
|
||||
|
||||
//check_image.c
|
||||
int assign_img(char *sign, char *path, t_pars *pars);
|
||||
int check_texture(char *sign, char *path, t_pars *pars);
|
||||
|
||||
//check_map.c
|
||||
int err_not_close(char after, char before, char down, char up);
|
||||
int actual_char(char actual);
|
||||
int check_map_close(char **map);
|
||||
int count_player(char **map);
|
||||
int check_char_map(char **map);
|
||||
int err_not_close(char after, char before, char down, char up);
|
||||
int actual_char(char actual);
|
||||
int check_map_close(char **map);
|
||||
int check_char_map(char **map);
|
||||
|
||||
//check_rgb.c
|
||||
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);
|
||||
|
||||
//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
|
||||
int verif_info_map(char *av);
|
||||
int verif_all_map(char **map);
|
||||
char **parse_map(char *map);
|
||||
int verif_info_file(char *av, t_pars *pars);
|
||||
int verif_all_map(char **map, t_pars *pars);
|
||||
char **parse_file(char *map, int ct, int i);
|
||||
|
||||
//mess_error.c in utils
|
||||
int err_mess(char *str);
|
||||
int err_mess(char *str);
|
||||
|
||||
//parse_utils.c
|
||||
char **info_map(char **file);
|
||||
void info_map(char **file, char ***f_part);
|
||||
int verif_char(char c);
|
||||
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 verif_char(char c);
|
||||
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
|
||||
|
@ -12,6 +12,33 @@
|
||||
|
||||
#include "../includes/libft.h"
|
||||
|
||||
char *ft_strjoin_gnl(char *s1, char *s2)
|
||||
{
|
||||
size_t len;
|
||||
size_t i;
|
||||
size_t j;
|
||||
char *str;
|
||||
|
||||
if (!s2)
|
||||
return (NULL);
|
||||
len = ft_strlen(s1) + ft_strlen(s2);
|
||||
str = malloc(sizeof(char) * (len + 1));
|
||||
if (!str)
|
||||
return (NULL);
|
||||
i = 0;
|
||||
while (s1[i] != '\0')
|
||||
{
|
||||
str[i] = s1[i];
|
||||
i++;
|
||||
}
|
||||
j = 0;
|
||||
while (s2[j] != '\0')
|
||||
str[i++] = s2[j++];
|
||||
free(s1);
|
||||
str[i] = '\0';
|
||||
return (str);
|
||||
}
|
||||
|
||||
char ft_end_of_line(char *line, char *buffer)
|
||||
{
|
||||
int i;
|
||||
@ -60,7 +87,7 @@ char *get_next_line(int fd)
|
||||
buffer = ft_calloc(sizeof(char), (BUFFER_SIZE + 1));
|
||||
while (buffer && line)
|
||||
{
|
||||
line = ft_strjoin(line, buffer);
|
||||
line = ft_strjoin_gnl(line, buffer);
|
||||
if (!line)
|
||||
return (NULL);
|
||||
if (ft_end_of_line(line, buffer) == 1)
|
||||
|
46
map.cub
Normal file → Executable file
46
map.cub
Normal file → Executable file
@ -1,22 +1,30 @@
|
||||
NO ./path_to_the_north_texture
|
||||
|
||||
SO ./path_to_the_south_texture
|
||||
|
||||
WE ./path_to_the_west_texture
|
||||
|
||||
EA ./path_to_the_east_texture
|
||||
NO ./no_texture.png
|
||||
|
||||
|
||||
SO ./so_texture.png
|
||||
|
||||
WE ./we_texture.png
|
||||
EA ./ea_texture.png
|
||||
C 255,100,200
|
||||
F 50,0,250
|
||||
|
||||
|
||||
111111
|
||||
1000W1
|
||||
1111111
|
||||
|
||||
11111111111111
|
||||
11
|
||||
11101
|
||||
1111111111111111
|
||||
|
||||
|
||||
|
||||
111111111111111
|
||||
111111111111111111111111
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
F 220,100,0
|
||||
C 225,30,0
|
||||
|
||||
11111
|
||||
1001S1
|
||||
11111
|
||||
11111
|
||||
11111
|
||||
11101
|
||||
11111
|
||||
111
|
||||
101
|
||||
111
|
||||
|
0
no_texture.png
Normal file
0
no_texture.png
Normal file
0
so_texture.png
Executable file
0
so_texture.png
Executable file
27
src/cub3d.c
Normal file
27
src/cub3d.c
Normal file
@ -0,0 +1,27 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* cub3d.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: madumerg <madumerg@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/09/04 16:58:27 by madumerg #+# #+# */
|
||||
/* Updated: 2024/10/05 18:45:09 by madumerg ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "cub3d.h"
|
||||
|
||||
int main(int ac, char **av)
|
||||
{
|
||||
t_pars pars;
|
||||
|
||||
pars = init_pars();
|
||||
if (basics_check(ac, av, &pars) == 1)
|
||||
{
|
||||
free_pars(&pars);
|
||||
return (1);
|
||||
}
|
||||
free_pars(&pars);
|
||||
return (0);
|
||||
}
|
21
src/other.c
Normal file
21
src/other.c
Normal file
@ -0,0 +1,21 @@
|
||||
|
||||
void f_c_color(void *mlx, void *win, t_pars *pars)
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
|
||||
x = 0;
|
||||
y = 0;
|
||||
|
||||
while (y <= (400 / 2)) //changer 400 par le define
|
||||
{
|
||||
x = 0;
|
||||
while (x <= 800) //changer 800 par le define
|
||||
{
|
||||
mlx_pixel_put(mlx, win, x, y, pars->c_color);
|
||||
mlx_pixel_put(mlx, win, x, 400 - y, pars->f_color); // changer 400 par le define
|
||||
x++;
|
||||
}
|
||||
y++;
|
||||
}
|
||||
}
|
@ -6,11 +6,11 @@
|
||||
/* By: madumerg <madumerg@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/09/04 21:33:35 by madumerg #+# #+# */
|
||||
/* Updated: 2024/09/12 12:57:41 by madumerg ### ########.fr */
|
||||
/* Updated: 2024/10/05 15:39:53 by madumerg ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "cub3d.h"
|
||||
#include "parsing.h"
|
||||
|
||||
int check_err_arg(int ac, char **av)
|
||||
{
|
||||
@ -24,10 +24,7 @@ int check_err_arg(int ac, char **av)
|
||||
return (err_mess(ERR_TYPE));
|
||||
fd = open(av[1], O_RDONLY);
|
||||
if (fd == -1)
|
||||
{
|
||||
close(fd);
|
||||
return (err_mess(EMPTY));
|
||||
}
|
||||
rd = read(fd, buf, 10);
|
||||
close(fd);
|
||||
return (rd);
|
||||
|
@ -0,0 +1,32 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* check_id_text.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: madumerg <madumerg@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/09/16 09:38:32 by madumerg #+# #+# */
|
||||
/* Updated: 2024/10/05 15:51:44 by madumerg ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "parsing.h"
|
||||
|
||||
int detect_info(char **tab, t_pars *pars)
|
||||
{
|
||||
if (ft_strncmp("NO", tab[0], 2) == 0 && count_tab(tab) == 2)
|
||||
return (check_texture(tab[0], tab[1], pars));
|
||||
else if (ft_strncmp("SO", tab[0], 2) == 0 && count_tab(tab) == 2)
|
||||
return (check_texture(tab[0], tab[1], pars));
|
||||
else if (ft_strncmp("WE", tab[0], 2) == 0 && count_tab(tab) == 2)
|
||||
return (check_texture(tab[0], tab[1], pars));
|
||||
else if (ft_strncmp("EA", tab[0], 2) == 0 && count_tab(tab) == 2)
|
||||
return (check_texture(tab[0], tab[1], pars));
|
||||
else if (ft_strncmp("F", tab[0], 1) == 0 && count_tab(tab) == 2)
|
||||
return (check_format_rgb("F", tab, pars));
|
||||
else if (ft_strncmp("C", tab[0], 1) == 0 && count_tab(tab) == 2)
|
||||
return (check_format_rgb("C", tab, pars));
|
||||
else
|
||||
return (err_mess(NOT_FOUND));
|
||||
return (0);
|
||||
}
|
86
src/parsing/check_image.c
Normal file
86
src/parsing/check_image.c
Normal file
@ -0,0 +1,86 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* check_image.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: madumerg <madumerg@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/09/19 10:44:07 by madumerg #+# #+# */
|
||||
/* Updated: 2024/10/05 13:39:06 by madumerg ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "parsing.h"
|
||||
|
||||
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 = ft_strdup(path);
|
||||
else
|
||||
return (err_mess(DUP_ACR));
|
||||
}
|
||||
else if (ft_strcmp("EA", sign) == 0)
|
||||
{
|
||||
if (pars->ea_png == NULL)
|
||||
pars->ea_png = ft_strdup(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 = ft_strdup(path);
|
||||
else
|
||||
return (err_mess(DUP_ACR));
|
||||
}
|
||||
else if (ft_strcmp("SO", sign) == 0)
|
||||
{
|
||||
if (pars->so_png == NULL)
|
||||
pars->so_png = ft_strdup(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);
|
||||
}
|
@ -6,21 +6,21 @@
|
||||
/* By: madumerg <madumerg@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/09/11 11:24:13 by madumerg #+# #+# */
|
||||
/* Updated: 2024/09/12 12:57:24 by madumerg ### ########.fr */
|
||||
/* Updated: 2024/09/29 20:37:16 by madumerg ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "cub3d.h"
|
||||
#include "parsing.h"
|
||||
|
||||
int err_not_close(char after, char before, char down, char up)
|
||||
{
|
||||
if (after == ' ' || after == '\0')
|
||||
if (after == ' ' || after == '\0' || after == '\n')
|
||||
return (1);
|
||||
else if (before == ' ' || before == '\0')
|
||||
else if (before == ' ' || before == '\0' || before == '\n')
|
||||
return (1);
|
||||
else if (down == ' ' || down == '\0')
|
||||
else if (down == ' ' || down == '\0' || down == '\n')
|
||||
return (1);
|
||||
else if (up == ' ' || up == '\0')
|
||||
else if (up == ' ' || up == '\0' || up == '\n')
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
@ -39,6 +39,8 @@ int check_map_close(char **map)
|
||||
int x;
|
||||
|
||||
y = 0;
|
||||
if (last_first_line(map) == 1)
|
||||
return (1);
|
||||
while (map[y])
|
||||
{
|
||||
x = 0;
|
||||
@ -56,31 +58,6 @@ int check_map_close(char **map)
|
||||
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 y;
|
||||
|
@ -0,0 +1,93 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* check_rgb.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: madumerg <madumerg@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/09/16 09:36:07 by madumerg #+# #+# */
|
||||
/* Updated: 2024/10/05 18:10:09 by madumerg ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "parsing.h"
|
||||
|
||||
int check_nb_color(char *r, char *g, char *b)
|
||||
{
|
||||
if (ft_strlen(r) > 3 || ft_strlen(g) > 3 || ft_strlen(b) > 3 || \
|
||||
ft_atoi(r) > 255 || ft_atoi(g) > 255 || ft_atoi(b) > 255)
|
||||
return (-1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int save_color(char *tab, t_pars *pars, int j, int i)
|
||||
{
|
||||
char *r;
|
||||
char *g;
|
||||
char *b;
|
||||
|
||||
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));
|
||||
free(r);
|
||||
free(g);
|
||||
free(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)
|
||||
{
|
||||
static int ct_f;
|
||||
static int ct_c;
|
||||
|
||||
if (ft_strcmp(sign, "F") == 0)
|
||||
ct_f++;
|
||||
if (ft_strcmp(sign, "C") == 0)
|
||||
ct_c++;
|
||||
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, 0) == -1)
|
||||
return (err_mess(ERR_COLOR));
|
||||
if (ct_f > 1 || ct_c > 1)
|
||||
return (err_mess(DUP_ACR));
|
||||
if (ft_strcmp(sign, "F") == 0)
|
||||
pars->f_color = pars->color;
|
||||
if (ft_strcmp(sign, "C") == 0)
|
||||
pars->c_color = pars->color;
|
||||
return (0);
|
||||
}
|
60
src/parsing/color_utils.c
Normal file
60
src/parsing/color_utils.c
Normal file
@ -0,0 +1,60 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* color_utils.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: madumerg <madumerg@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/09/18 19:44:37 by madumerg #+# #+# */
|
||||
/* Updated: 2024/10/05 17:52:43 by madumerg ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "parsing.h"
|
||||
|
||||
int create_argb(int r, int g, int b)
|
||||
{
|
||||
return (255 << 24 | 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
64
src/parsing/find_player.c
Normal 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/29 20:37:45 by madumerg ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "parsing.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);
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
// convertir tt les whites spaces en simple espace sur les 6 1ere lignes
|
||||
|
||||
WARNIIIIIINNNNNNNNNNNNNGGG TESTER LES MALLOC A NULL
|
||||
|
||||
//faire struct de coor
|
||||
utiliser la ft pour couleur
|
@ -6,61 +6,108 @@
|
||||
/* By: madumerg <madumerg@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/09/12 12:44:52 by madumerg #+# #+# */
|
||||
/* Updated: 2024/09/12 16:49:20 by madumerg ### ########.fr */
|
||||
/* Updated: 2024/10/05 18:35:52 by madumerg ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "cub3d.h"
|
||||
#include "parsing.h"
|
||||
|
||||
int check_info(char **l)
|
||||
int all_data_verif(char **tab, t_pars *pars)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int verif_info_map(char *av)
|
||||
{
|
||||
char **map;
|
||||
char **f_part;
|
||||
|
||||
map = parse_map(av);
|
||||
f_part = info_map(map);
|
||||
if (check_info(f_part) == 1)
|
||||
if (detect_info(tab, pars) == 1)
|
||||
{
|
||||
free_tab(tab);
|
||||
return (1);
|
||||
if (verif_all_map(map) == 1)
|
||||
return (1);
|
||||
}
|
||||
|
||||
int verif_all_map(char **map)
|
||||
{
|
||||
if (check_char_map(map) == 1)
|
||||
return (err_mess(WRONG_CHAR));
|
||||
if (count_player(map) == 1)
|
||||
return (err_mess(ERR_PLAYER));
|
||||
if (check_map_close(map) == 1)
|
||||
return (err_mess(NOT_CLOSE));
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
char **parse_map(char *map)
|
||||
int check_info(char **file, t_pars *pars)
|
||||
{
|
||||
char **tab;
|
||||
int i;
|
||||
int ct;
|
||||
|
||||
ct = 0;
|
||||
i = 0;
|
||||
while (file[i])
|
||||
{
|
||||
if (ct == 6)
|
||||
break ;
|
||||
if (space_line(file[i]) == 1)
|
||||
{
|
||||
ct++;
|
||||
tab = ft_split(file[i], ' ');
|
||||
if (tab == NULL || all_data_verif(tab, pars) == 1)
|
||||
return (1);
|
||||
free_tab(tab);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
if (pars->f_color == 0 || pars->c_color == 0 || pars->ea_png == NULL || \
|
||||
pars->no_png == NULL || pars->so_png == NULL || pars->we_png == NULL)
|
||||
return (err_mess(NOT_FOUND));
|
||||
return (0);
|
||||
}
|
||||
|
||||
int verif_info_file(char *av, t_pars *pars)
|
||||
{
|
||||
char **map;
|
||||
|
||||
map = parse_file(av, 0, 1);
|
||||
if (map == NULL)
|
||||
return (err_mess(CRASH));
|
||||
if (check_info(map, pars) == 1 || all_skip(map, pars) == 1)
|
||||
{
|
||||
free_tab(map);
|
||||
return (1);
|
||||
}
|
||||
free_tab(map);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int verif_all_map(char **map, t_pars *pars)
|
||||
{
|
||||
if (longest_line(map) == 1)
|
||||
return (1);
|
||||
pars->map = alloc_map(map, longest_line(map));
|
||||
if (pars->map == NULL)
|
||||
return (err_mess(CRASH));
|
||||
if (check_char_map(pars->map) == 1)
|
||||
return (err_mess(WRONG_CHAR));
|
||||
if (count_player(pars->map, pars, 0) == 1)
|
||||
return (err_mess(ERR_PLAYER));
|
||||
if (check_map_close(pars->map) == 1)
|
||||
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);
|
||||
}
|
||||
|
||||
char **parse_file(char *map, int ct, int i)
|
||||
{
|
||||
int fd;
|
||||
char **parse_map;
|
||||
char *save;
|
||||
char *join;
|
||||
|
||||
fd = open(map, O_RDONLY);
|
||||
save = get_next_line(fd);
|
||||
join = ft_calloc(1, 1);
|
||||
if (!join)
|
||||
if (fd < 0)
|
||||
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);
|
||||
free(save);
|
||||
save = get_next_line(fd);
|
||||
close(fd);
|
||||
return (NULL);
|
||||
}
|
||||
parse_map = ft_split(join, '\n');
|
||||
free(join);
|
||||
close(fd);
|
||||
parse_map[0] = get_next_line(fd);
|
||||
while (i <= ct)
|
||||
{
|
||||
parse_map[i] = get_next_line(fd);
|
||||
i++;
|
||||
}
|
||||
close (fd);
|
||||
return (parse_map);
|
||||
}
|
||||
|
40
src/parsing/start.c
Normal file
40
src/parsing/start.c
Normal file
@ -0,0 +1,40 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* start.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: madumerg <madumerg@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/05 18:42:05 by madumerg #+# #+# */
|
||||
/* Updated: 2024/10/05 18:44:40 by madumerg ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "parsing.h"
|
||||
|
||||
t_pars init_pars(void)
|
||||
{
|
||||
t_pars new;
|
||||
|
||||
new.f_color = -1;
|
||||
new.c_color = -1;
|
||||
new.color = 0;
|
||||
new.l_player = 0;
|
||||
new.coor.x = 0;
|
||||
new.coor.y = 0;
|
||||
new.no_png = NULL;
|
||||
new.so_png = NULL;
|
||||
new.we_png = NULL;
|
||||
new.ea_png = NULL;
|
||||
new.map = NULL;
|
||||
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);
|
||||
}
|
41
src/utils/clear_free.c
Normal file
41
src/utils/clear_free.c
Normal 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/29 20:34:58 by madumerg ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "parsing.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);
|
||||
}
|
@ -6,11 +6,11 @@
|
||||
/* By: madumerg <madumerg@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/09/07 17:35:14 by madumerg #+# #+# */
|
||||
/* Updated: 2024/09/11 11:10:48 by adjoly ### ########.fr */
|
||||
/* Updated: 2024/09/29 20:35:10 by madumerg ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "cub3d.h"
|
||||
#include "parsing.h"
|
||||
|
||||
int err_mess(char *str)
|
||||
{
|
||||
|
@ -6,43 +6,28 @@
|
||||
/* By: madumerg <madumerg@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/09/11 14:20:54 by madumerg #+# #+# */
|
||||
/* Updated: 2024/09/12 16:20:31 by madumerg ### ########.fr */
|
||||
/* Updated: 2024/09/29 20:35:22 by madumerg ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "cub3d.h"
|
||||
#include "parsing.h"
|
||||
|
||||
char **info_map(char **file)
|
||||
{
|
||||
char **f_part;
|
||||
int i;
|
||||
int j;
|
||||
|
||||
i = 0;
|
||||
j = 0;
|
||||
f_part = ft_calloc(6, sizeof(char *));
|
||||
if (!f_part)
|
||||
return (NULL);
|
||||
while (i < 6)
|
||||
{
|
||||
f_part[j] = file[i];
|
||||
j++;
|
||||
i++;
|
||||
}
|
||||
return (f_part);
|
||||
}
|
||||
|
||||
void convert_white_s(char *str)
|
||||
int space_line(char *line)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (str[i])
|
||||
convert_white_s(line);
|
||||
while (line[i])
|
||||
{
|
||||
if (str[i] >= 9 && str[i] <= 13)
|
||||
str[i] = 32;
|
||||
i++;
|
||||
if (line[i] == ' ' || (line[i] >= 9 && line[i] <= 13))
|
||||
i++;
|
||||
else
|
||||
break ;
|
||||
}
|
||||
if (line[i] != '\0')
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int verif_char(char c)
|
||||
|
101
src/utils/parse_utils_three.c
Normal file
101
src/utils/parse_utils_three.c
Normal file
@ -0,0 +1,101 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* parse_utils_three.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: madumerg <madumerg@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/09/28 15:40:12 by madumerg #+# #+# */
|
||||
/* Updated: 2024/10/05 18:49:41 by madumerg ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "parsing.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)
|
||||
{
|
||||
free_tab(tmp);
|
||||
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);
|
||||
}
|
90
src/utils/parse_utils_two.c
Normal file
90
src/utils/parse_utils_two.c
Normal file
@ -0,0 +1,90 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* parse_utils_two.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: madumerg <madumerg@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/09/17 15:12:28 by madumerg #+# #+# */
|
||||
/* Updated: 2024/09/29 20:35:50 by madumerg ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "parsing.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)
|
||||
{
|
||||
int k;
|
||||
|
||||
k = i;
|
||||
while (old_map[i])
|
||||
{
|
||||
replace_nl(old_map[i]);
|
||||
i++;
|
||||
}
|
||||
if (verif_all_map(&old_map[k], 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);
|
||||
}
|
79
src/utils/utils.c
Normal file
79
src/utils/utils.c
Normal file
@ -0,0 +1,79 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* utils.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: madumerg <madumerg@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/09/20 09:57:13 by madumerg #+# #+# */
|
||||
/* Updated: 2024/10/05 18:33:01 by madumerg ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "parsing.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]);
|
||||
if (stock == 0)
|
||||
return (err_mess(MISS_MAP));
|
||||
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
0
tamere.jpeg
Normal file
0
we_texture.png
Normal file
0
we_texture.png
Normal file
Reference in New Issue
Block a user