mirror of
https://github.com/Ladebeze66/cub3D.git
synced 2025-12-15 13:46:57 +01:00
manqueunefonctionnorme
This commit is contained in:
parent
fcbbe51d52
commit
7d67dfd452
12
Makefile
12
Makefile
@ -6,7 +6,7 @@
|
|||||||
# By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ #
|
# By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ #
|
||||||
# +#+#+#+#+#+ +#+ #
|
# +#+#+#+#+#+ +#+ #
|
||||||
# Created: 2024/01/14 16:54:48 by fgras-ca #+# #+# #
|
# Created: 2024/01/14 16:54:48 by fgras-ca #+# #+# #
|
||||||
# Updated: 2024/01/23 19:56:56 by fgras-ca ### ########.fr #
|
# Updated: 2024/01/29 20:12:12 by fgras-ca ### ########.fr #
|
||||||
# #
|
# #
|
||||||
# **************************************************************************** #
|
# **************************************************************************** #
|
||||||
|
|
||||||
@ -24,7 +24,6 @@ WHITE = \033[0;97m
|
|||||||
ORANGE = \033[38;5;214m
|
ORANGE = \033[38;5;214m
|
||||||
|
|
||||||
NAME = cub3d
|
NAME = cub3d
|
||||||
LIBFT = libft.a
|
|
||||||
|
|
||||||
SRC = main.c \
|
SRC = main.c \
|
||||||
./utils/ft_utils_gnl.c \
|
./utils/ft_utils_gnl.c \
|
||||||
@ -32,7 +31,6 @@ SRC = main.c \
|
|||||||
./utils/ft_utils_convert.c \
|
./utils/ft_utils_convert.c \
|
||||||
./utils/ft_utils_str_1.c \
|
./utils/ft_utils_str_1.c \
|
||||||
./parsing/ft_map_check.c \
|
./parsing/ft_map_check.c \
|
||||||
./parsing/ft_read_map.c \
|
|
||||||
./parsing/ft_map_dimensions.c \
|
./parsing/ft_map_dimensions.c \
|
||||||
./parsing/ft_parsing.c \
|
./parsing/ft_parsing.c \
|
||||||
./move/ft_collision.c \
|
./move/ft_collision.c \
|
||||||
@ -43,6 +41,7 @@ SRC = main.c \
|
|||||||
./draw/ft_2d_view.c \
|
./draw/ft_2d_view.c \
|
||||||
./draw/ft_textures.c \
|
./draw/ft_textures.c \
|
||||||
./draw/ft_3d_view.c \
|
./draw/ft_3d_view.c \
|
||||||
|
./draw/ft_3d_view_utils.c \
|
||||||
./draw/ft_horizontal_ray.c \
|
./draw/ft_horizontal_ray.c \
|
||||||
./draw/ft_vertical_ray.c \
|
./draw/ft_vertical_ray.c \
|
||||||
./draw/ft_pixel.c \
|
./draw/ft_pixel.c \
|
||||||
@ -56,10 +55,9 @@ SRC = main.c \
|
|||||||
./parsing/ft_find_map_start.c \
|
./parsing/ft_find_map_start.c \
|
||||||
./parsing/ft_textures_and_colors.c \
|
./parsing/ft_textures_and_colors.c \
|
||||||
./parsing/ft_find_player_position.c \
|
./parsing/ft_find_player_position.c \
|
||||||
|
./parsing/ft_find_player_utils.c \
|
||||||
SRC_DIR_LIBFT = libft/
|
./parsing/ft_map_check_utils.c \
|
||||||
|
./parsing/ft_text_and_col_utils.c \
|
||||||
SRC_LIBFT = $(addprefix $(SRC_DIR_LIBFT), $(LIBFT))
|
|
||||||
|
|
||||||
OBJ = $(SRC:.c=.o)
|
OBJ = $(SRC:.c=.o)
|
||||||
|
|
||||||
|
|||||||
275
cub3d.h
275
cub3d.h
@ -6,7 +6,7 @@
|
|||||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/01/14 16:56:52 by fgras-ca #+# #+# */
|
/* Created: 2024/01/14 16:56:52 by fgras-ca #+# #+# */
|
||||||
/* Updated: 2024/01/28 22:03:37 by fgras-ca ### ########.fr */
|
/* Updated: 2024/01/29 20:09:43 by fgras-ca ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -24,29 +24,30 @@
|
|||||||
# include "include/mlx.h"
|
# include "include/mlx.h"
|
||||||
|
|
||||||
# ifndef BUFFER_SIZE
|
# ifndef BUFFER_SIZE
|
||||||
# define BUFFER_SIZE 100000
|
# define BUFFER_SIZE 100000
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
# define PI 3.14159265359
|
# define PI 3.14159265359
|
||||||
# define P2 PI/2
|
# define P2 1.57079632679
|
||||||
# define P3 3*PI/2
|
# define P3 4.71238898038
|
||||||
# define COLBUF 1
|
# define COLBUF 1
|
||||||
# define NUMRAY 1280
|
# define NUMRAY 1280
|
||||||
# define FOVIEW 60
|
# define FOVIEW 60
|
||||||
# define DISRAY 1000000
|
# define DISRAY 1000000
|
||||||
# define DOF 120
|
# define DOF 120
|
||||||
# define WIDTH 1780
|
# define WIDTH 1680
|
||||||
# define HEIGHT 720
|
# define HEIGHT 720
|
||||||
# define BOV 500
|
# define BOV 400
|
||||||
# define MAX_LINE_LENGTH 100000
|
# define MAX_LINE_LENGTH 100000
|
||||||
|
# define DX_LENGTH 8
|
||||||
|
|
||||||
typedef enum {
|
typedef enum s_WallDirection {
|
||||||
NORTH,
|
NORTH,
|
||||||
SOUTH,
|
SOUTH,
|
||||||
WEST,
|
WEST,
|
||||||
EAST,
|
EAST,
|
||||||
NONE // Utilisé lorsqu'aucun mur n'est touché
|
NONE
|
||||||
} WallDirection;
|
} t_WallDirection;
|
||||||
|
|
||||||
typedef struct s_img
|
typedef struct s_img
|
||||||
{
|
{
|
||||||
@ -108,15 +109,15 @@ typedef struct s_struture_windows
|
|||||||
|
|
||||||
typedef struct s_texture
|
typedef struct s_texture
|
||||||
{
|
{
|
||||||
char *north;
|
char *north;
|
||||||
char *south;
|
char *south;
|
||||||
char *west;
|
char *west;
|
||||||
char *east;
|
char *east;
|
||||||
char *door;
|
char *door;
|
||||||
char *door_open;
|
char *door_open;
|
||||||
unsigned int floor_color;
|
unsigned int floor_color;
|
||||||
unsigned int ceil_color;
|
unsigned int ceil_color;
|
||||||
} t_texture;
|
} t_texture;
|
||||||
|
|
||||||
typedef struct s_struture_map
|
typedef struct s_struture_map
|
||||||
{
|
{
|
||||||
@ -126,9 +127,9 @@ typedef struct s_struture_map
|
|||||||
int i;
|
int i;
|
||||||
int j;
|
int j;
|
||||||
int temp;
|
int temp;
|
||||||
int mapX;
|
int map_x;
|
||||||
int mapY;
|
int map_y;
|
||||||
int mapS;
|
int map_s;
|
||||||
float player_x;
|
float player_x;
|
||||||
float player_y;
|
float player_y;
|
||||||
char player_direction;
|
char player_direction;
|
||||||
@ -136,10 +137,14 @@ typedef struct s_struture_map
|
|||||||
} t_structure_map;
|
} t_structure_map;
|
||||||
|
|
||||||
typedef struct s_sprite {
|
typedef struct s_sprite {
|
||||||
void *frames[3]; // Tableau pour stocker les frames du sprite
|
void *frames[3];
|
||||||
int width, height; // Dimensions du sprite
|
int width;
|
||||||
int current_frame; // Index de la frame actuelle
|
int height;
|
||||||
} t_sprite;
|
int current_frame;
|
||||||
|
float world_x;
|
||||||
|
float world_y;
|
||||||
|
float distance;
|
||||||
|
} t_sprite;
|
||||||
|
|
||||||
typedef struct s_structure_main
|
typedef struct s_structure_main
|
||||||
{
|
{
|
||||||
@ -166,7 +171,7 @@ typedef struct s_res_params {
|
|||||||
int original_y;
|
int original_y;
|
||||||
int pixel_pos_rescaled;
|
int pixel_pos_rescaled;
|
||||||
int pixel_pos_original;
|
int pixel_pos_original;
|
||||||
} t_res_params;
|
} t_res_params;
|
||||||
|
|
||||||
typedef struct s_rescale_params {
|
typedef struct s_rescale_params {
|
||||||
void *original_img;
|
void *original_img;
|
||||||
@ -177,30 +182,29 @@ typedef struct s_rescale_params {
|
|||||||
int px;
|
int px;
|
||||||
int py;
|
int py;
|
||||||
t_res_params *res;
|
t_res_params *res;
|
||||||
} t_rescale_params;
|
} t_rescale_params;
|
||||||
|
|
||||||
typedef struct s_position_params {
|
typedef struct s_position_params {
|
||||||
int *future_px;
|
int *future_px;
|
||||||
int *future_py;
|
int *future_py;
|
||||||
int pdx;
|
int pdx;
|
||||||
int pdy;
|
int pdy;
|
||||||
int collisionBuffer;
|
int collision_buffer;
|
||||||
int px;
|
int px;
|
||||||
int py;
|
int py;
|
||||||
double pa;
|
double pa;
|
||||||
char direction;
|
char direction;
|
||||||
} t_position_params;
|
} t_position_params;
|
||||||
|
|
||||||
|
|
||||||
typedef struct s_map_params {
|
typedef struct s_map_params {
|
||||||
t_structure_map *map_info;
|
t_structure_map *map_info;
|
||||||
const char *buffer;
|
const char *buffer;
|
||||||
int length;
|
int length;
|
||||||
int *maxWidth;
|
int *max_width;
|
||||||
int *height;
|
int *height;
|
||||||
int *currentWidth;
|
int *current_width;
|
||||||
int *isNewLine;
|
int *is_new_line;
|
||||||
} t_map_params;
|
} t_map_params;
|
||||||
|
|
||||||
typedef struct s_square_params {
|
typedef struct s_square_params {
|
||||||
t_structure_main *w;
|
t_structure_main *w;
|
||||||
@ -209,15 +213,15 @@ typedef struct s_square_params {
|
|||||||
int xo;
|
int xo;
|
||||||
int yo;
|
int yo;
|
||||||
int color;
|
int color;
|
||||||
} t_square_params;
|
} t_square_params;
|
||||||
|
|
||||||
typedef struct s_sky_ground_params {
|
typedef struct s_sky_ground_params {
|
||||||
t_structure_main *w;
|
t_structure_main *w;
|
||||||
int startHeight;
|
int start_height;
|
||||||
int endHeight;
|
int end_height;
|
||||||
int color;
|
int color;
|
||||||
int backgroundOffsetX;
|
int background_off_setx;
|
||||||
} t_sky_ground_params;
|
} t_sky_ground_params;
|
||||||
|
|
||||||
typedef struct s_line_params {
|
typedef struct s_line_params {
|
||||||
t_structure_main *w;
|
t_structure_main *w;
|
||||||
@ -226,7 +230,7 @@ typedef struct s_line_params {
|
|||||||
int x1;
|
int x1;
|
||||||
int y1;
|
int y1;
|
||||||
int color;
|
int color;
|
||||||
} t_line_params;
|
} t_line_params;
|
||||||
|
|
||||||
typedef struct s_line_deltas {
|
typedef struct s_line_deltas {
|
||||||
int dx;
|
int dx;
|
||||||
@ -235,53 +239,51 @@ typedef struct s_line_deltas {
|
|||||||
int sy;
|
int sy;
|
||||||
int err;
|
int err;
|
||||||
t_line_params *params;
|
t_line_params *params;
|
||||||
} t_line_deltas;
|
} t_line_deltas;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct s_texture_params {
|
typedef struct s_texture_params {
|
||||||
t_structure_main *w;
|
t_structure_main *w;
|
||||||
int startX;
|
int start_x;
|
||||||
int endX;
|
int end_x;
|
||||||
float lineOff;
|
float line_off;
|
||||||
float lineH;
|
float line_h;
|
||||||
WallDirection wallDir;
|
t_WallDirection wall_dir;
|
||||||
float rx;
|
float rx;
|
||||||
float ry;
|
float ry;
|
||||||
float disT;
|
float dis_t;
|
||||||
} t_texture_params;
|
} t_texture_params;
|
||||||
|
|
||||||
typedef struct s_ray_params {
|
typedef struct s_ray_params {
|
||||||
t_structure_main *w;
|
t_structure_main *w;
|
||||||
t_square_params sq;
|
t_square_params sq;
|
||||||
t_texture_params texture;
|
t_texture_params texture;
|
||||||
int r;
|
int r;
|
||||||
int tileSize;
|
int tile_size;
|
||||||
float rx;
|
float rx;
|
||||||
float ry;
|
float ry;
|
||||||
float disT;
|
float dis_t;
|
||||||
WallDirection wallDir;
|
t_WallDirection wall_dir;
|
||||||
int numRays;
|
int num_rays;
|
||||||
int color;
|
int color;
|
||||||
int start3DHeight;
|
int start3d_height;
|
||||||
int max3DHeight;
|
int max3d_height;
|
||||||
float lineH;
|
float line_h;
|
||||||
float lineOff;
|
float line_off;
|
||||||
int backgroundOffsetX;
|
int background_off_setx;
|
||||||
int raywidth;
|
int raywidth;
|
||||||
} t_ray_params;
|
} t_ray_params;
|
||||||
|
|
||||||
typedef struct s_ray_calc_params {
|
typedef struct s_ray_calc_params {
|
||||||
t_structure_main *w;
|
t_structure_main *w;
|
||||||
float ra;
|
float ra;
|
||||||
float *disRay;
|
float *dis_ray;
|
||||||
float *rx;
|
float *rx;
|
||||||
float *ry;
|
float *ry;
|
||||||
WallDirection *wallDir;
|
t_WallDirection *wall_dir;
|
||||||
float xo;
|
float xo;
|
||||||
float yo;
|
float yo;
|
||||||
int dof;
|
int dof;
|
||||||
} t_ray_calc_params;
|
} t_ray_calc_params;
|
||||||
|
|
||||||
typedef struct s_texture_data
|
typedef struct s_texture_data
|
||||||
{
|
{
|
||||||
@ -295,71 +297,109 @@ typedef struct s_init_params {
|
|||||||
t_structure_main *w;
|
t_structure_main *w;
|
||||||
int tilesize;
|
int tilesize;
|
||||||
int numrays;
|
int numrays;
|
||||||
float FOV;
|
float fo_v;
|
||||||
float DR;
|
float d_r;
|
||||||
} t_init_params;
|
} t_init_params;
|
||||||
|
|
||||||
typedef struct s_ray_properties {
|
typedef struct s_ray_properties {
|
||||||
float disH;
|
float dis_h;
|
||||||
float disV;
|
float dis_v;
|
||||||
WallDirection hwalldir;
|
t_WallDirection hwalldir;
|
||||||
WallDirection vwalldir;
|
t_WallDirection vwalldir;
|
||||||
float hx;
|
float hx;
|
||||||
float hy;
|
float hy;
|
||||||
float vx;
|
float vx;
|
||||||
float vy;
|
float vy;
|
||||||
} t_ray_properties;
|
} t_ray_properties;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct s_base_params {
|
||||||
int tilesize;
|
int tilesize;
|
||||||
int numrays;
|
int numrays;
|
||||||
float FOV;
|
float fo_v;
|
||||||
float DR;
|
float d_r;
|
||||||
float ra;
|
float ra;
|
||||||
} t_base_params;
|
} t_base_params;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct s_ray_state {
|
||||||
float disH;
|
float dis_h;
|
||||||
float disV;
|
float dis_v;
|
||||||
float disT;
|
float dis_t;
|
||||||
float hx;
|
float hx;
|
||||||
float hy;
|
float hy;
|
||||||
float vx;
|
float vx;
|
||||||
float vy;
|
float vy;
|
||||||
WallDirection hwalldir;
|
t_WallDirection hwalldir;
|
||||||
WallDirection vwalldir;
|
t_WallDirection vwalldir;
|
||||||
} t_ray_state;
|
} t_ray_state;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct s_ray_calc {
|
||||||
t_structure_main *w;
|
t_structure_main *w;
|
||||||
int r;
|
int r;
|
||||||
int color;
|
int color;
|
||||||
} t_ray_calc;
|
} t_ray_calc;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct s_drawrays2d_params {
|
||||||
t_base_params base_params;
|
t_base_params base_params;
|
||||||
t_ray_state ray_state;
|
t_ray_state ray_state;
|
||||||
t_ray_calc ray_calc;
|
t_ray_calc ray_calc;
|
||||||
t_ray_params rayparams;
|
t_ray_params rayparams;
|
||||||
t_ray_calc_params hrayparams;
|
t_ray_calc_params hrayparams;
|
||||||
t_ray_calc_params vrayparams;
|
t_ray_calc_params vrayparams;
|
||||||
} t_drawrays2d_params;
|
} t_drawrays2d_params;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct s_state {
|
||||||
int jkl;
|
int jkl;
|
||||||
int yui;
|
int yui;
|
||||||
} t_state;
|
} t_state;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct s_global_struct {
|
||||||
t_structure_main *w;
|
t_structure_main *w;
|
||||||
t_state state;
|
t_state state;
|
||||||
} t_global_struct;
|
} t_global_struct;
|
||||||
|
|
||||||
|
typedef struct s_draw_params
|
||||||
|
{
|
||||||
|
int texturewidth;
|
||||||
|
int textureheight;
|
||||||
|
int texturex;
|
||||||
|
int textureY;
|
||||||
|
int a;
|
||||||
|
int b;
|
||||||
|
int c;
|
||||||
|
double step;
|
||||||
|
int x;
|
||||||
|
int i;
|
||||||
|
} t_draw_params;
|
||||||
|
|
||||||
|
typedef struct s_collision_params
|
||||||
|
{
|
||||||
|
int dx[DX_LENGTH];
|
||||||
|
int dy[DX_LENGTH];
|
||||||
|
} t_collision_params;
|
||||||
|
|
||||||
|
typedef struct s_player_info
|
||||||
|
{
|
||||||
|
bool *found_player;
|
||||||
|
t_structure_map *map;
|
||||||
|
int line_number;
|
||||||
|
int column_number;
|
||||||
|
} t_player_info;
|
||||||
|
|
||||||
|
typedef struct s_point
|
||||||
|
{
|
||||||
|
int x;
|
||||||
|
int y;
|
||||||
|
} t_point;
|
||||||
|
|
||||||
|
typedef struct s_map_check
|
||||||
|
{
|
||||||
|
char *map;
|
||||||
|
int maxWidth;
|
||||||
|
int height;
|
||||||
|
} t_map_check;
|
||||||
|
|
||||||
//ft_utils_split.c 5 / 5
|
|
||||||
char **ft_split(char const *s, char c);
|
char **ft_split(char const *s, char c);
|
||||||
//ft_utils_gnl.c 4 / 5
|
|
||||||
char *get_next_line(int fd);
|
char *get_next_line(int fd);
|
||||||
/*ft_key.c 3/5*/
|
|
||||||
int *kill_prog(t_structure_main *w);
|
int *kill_prog(t_structure_main *w);
|
||||||
void move(int key, t_structure_main *w);
|
void move(int key, t_structure_main *w);
|
||||||
int deal_key(int key, t_structure_main *w);
|
int deal_key(int key, t_structure_main *w);
|
||||||
@ -371,13 +411,12 @@ int ft_strncmp(const char *s1, const char *s2, size_t n);
|
|||||||
int ft_strcmp(const char *s1, const char *s2);
|
int ft_strcmp(const char *s1, const char *s2);
|
||||||
void *ft_memcpy(void *dest, const void *src, size_t n);
|
void *ft_memcpy(void *dest, const void *src, size_t n);
|
||||||
void *ft_memset(void *s, int c, size_t n);
|
void *ft_memset(void *s, int c, size_t n);
|
||||||
/*collision*/
|
int can_move_to(t_structure_main *w, double future_x, double future_y);
|
||||||
int can_move_to(t_structure_main *w, double future_x, double future_y);
|
|
||||||
char *ft_itoa(int nb);
|
char *ft_itoa(int nb);
|
||||||
void draw_black_ground(t_ray_params *params, t_texture_params tparams);
|
void draw_black_ground(t_ray_params *params, t_texture_params tparams);
|
||||||
/*parsing*/
|
int is_map_closed(char *map, int width, int height);
|
||||||
int is_map_closed(char* map, int width, int height);
|
bool parse_map(const char *map_content,
|
||||||
bool parse_map(const char *map_content, int length, t_structure_map *map_info);
|
int length, t_structure_map *map_info);
|
||||||
int check_borders(char *map, int maxWidth, int height);
|
int check_borders(char *map, int maxWidth, int height);
|
||||||
int check_interior(char *map, int maxWidth, int height);
|
int check_interior(char *map, int maxWidth, int height);
|
||||||
void exit_error(t_structure_main *w);
|
void exit_error(t_structure_main *w);
|
||||||
@ -386,24 +425,25 @@ void process_character(t_map_params *params, int *i);
|
|||||||
void get_map_dimensions(t_map_params *params);
|
void get_map_dimensions(t_map_params *params);
|
||||||
void fill_map_space(t_structure_map *map_info, int maxWidth, int height);
|
void fill_map_space(t_structure_map *map_info, int maxWidth, int height);
|
||||||
void copy_map_data(t_map_params *params);
|
void copy_map_data(t_map_params *params);
|
||||||
bool load_cub_file(const char *filename, t_texture *textures, t_structure_map *map_info);
|
bool load_cub_file(const char *filename,
|
||||||
|
t_texture *textures, t_structure_map *map_info);
|
||||||
bool parse_texture_line(const char *line, t_texture *textures);
|
bool parse_texture_line(const char *line, t_texture *textures);
|
||||||
bool handle_map(int fd, char **map_buffer, int *map_length);
|
bool handle_map(int fd, char **map_buffer, int *map_length);
|
||||||
bool parse_color_line(const char *line, unsigned int *color);
|
bool parse_color_line(const char *line, unsigned int *color);
|
||||||
|
bool parse_number_from_str(const char **str, int *number);
|
||||||
bool is_valid_texture(const char *line);
|
bool is_valid_texture(const char *line);
|
||||||
bool handle_textures(int fd, t_texture *textures);
|
bool handle_textures(int fd, t_texture *textures);
|
||||||
bool find_player_position_and_direction(const char *map_content, int length, t_structure_map *map_info);
|
bool find_player(const char *map_content,
|
||||||
|
int length, t_structure_map *map);
|
||||||
void calculate_map(t_structure_map *map_info);
|
void calculate_map(t_structure_map *map_info);
|
||||||
/*textures*/
|
|
||||||
void load_wall_textures(t_structure_main *w);
|
void load_wall_textures(t_structure_main *w);
|
||||||
void draw_texture(t_texture_params *tex_params);
|
void draw_texture(t_texture_params *tex_params);
|
||||||
int get_texture_color(t_structure_main *w, WallDirection wallDir, int textureX, int textureY);
|
int get_texture_color(t_structure_main *w,
|
||||||
void draw_yolo(t_ray_params *rparams, t_texture_params *tparams, int deca);
|
t_WallDirection wallDir, int textureX, int textureY);
|
||||||
/*3D view*/
|
void draw_yolo(t_ray_params *rparams, t_texture_params *tparams, int deca);
|
||||||
void drawray(t_ray_params *ray_params);
|
void drawray(t_ray_params *ray_params);
|
||||||
void draw_background(t_structure_main *w);
|
void draw_background(t_structure_main *w);
|
||||||
float correctFisheye(float distance, float ra, float playerAngle);
|
float correctFisheye(float distance, float ra, float playerAngle);
|
||||||
//2D map
|
|
||||||
void rescale_image(t_rescale_params *params, t_structure_main *w);
|
void rescale_image(t_rescale_params *params, t_structure_main *w);
|
||||||
void draw_square(t_structure_main *w, int x, int y, int color);
|
void draw_square(t_structure_main *w, int x, int y, int color);
|
||||||
void draw_map(t_structure_main *w);
|
void draw_map(t_structure_main *w);
|
||||||
@ -411,20 +451,27 @@ void put_pixel_img(t_structure_main *w, int x, int y, int color);
|
|||||||
void draw_square_raw(t_square_params *params);
|
void draw_square_raw(t_square_params *params);
|
||||||
void draw_line(t_line_params *params);
|
void draw_line(t_line_params *params);
|
||||||
void drawrays2d(t_structure_main *w);
|
void drawrays2d(t_structure_main *w);
|
||||||
//Ray
|
|
||||||
void calculateverticalray(t_ray_calc_params *params);
|
void calculateverticalray(t_ray_calc_params *params);
|
||||||
void handle_ra_vertical(t_ray_calc_params *params, float nTan, int tileSize);
|
void handle_ra_vertical(t_ray_calc_params *params, float nTan, int tileSize);
|
||||||
void calculatehorizontalray(t_ray_calc_params *params);
|
void calculatehorizontalray(t_ray_calc_params *params);
|
||||||
void handle_ra_not_equal_pi(t_ray_calc_params *params, float atan, int tilesize);
|
void handle_ra_not_equal_pi(t_ray_calc_params *params,
|
||||||
|
float atan, int tilesize);
|
||||||
float dist(float ax, float ay, float bx, float by);
|
float dist(float ax, float ay, float bx, float by);
|
||||||
//window
|
|
||||||
void init_windows(t_structure_main *w);
|
void init_windows(t_structure_main *w);
|
||||||
void init_player(t_structure_main *w);
|
void init_player(t_structure_main *w);
|
||||||
void init_mlx_and_window(t_structure_main *w);
|
void init_mlx_and_window(t_structure_main *w);
|
||||||
void sleep_mouse(t_global_struct *global_struct);
|
void sleep_mouse(t_global_struct *global_struct);
|
||||||
//sprite
|
void init_line_params(t_line_params *lineparams, t_ray_params *rayParams);
|
||||||
void load_sprite_frames(t_sprite *sprite, void *mlx_ptr);
|
void init_texture_params(t_texture_params *textureparams,
|
||||||
void update_sprite_frame(t_sprite *sprite);
|
t_ray_params *rayParams);
|
||||||
void draw_sprite(t_sprite *sprite, void *mlx_ptr, void *win_ptr, int win_width, int win_height);
|
void initialize_variables(int *i, int *line_number,
|
||||||
|
int *column_number, bool *found_player);
|
||||||
|
bool check_for_player(char current_char, bool *found_player);
|
||||||
|
void update_player_info(t_structure_map *map_info,
|
||||||
|
int line_number, int column_number, char player_direction);
|
||||||
|
void update_position(char current_char, int *line_number, int *column_number);
|
||||||
|
bool check_for_multiple_players(bool found_player);
|
||||||
|
int check_boundaries(t_point p, t_map_check *map_check);
|
||||||
|
int is_space_surrounded_by_walls(t_map_check *map_check, t_point p);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/01/12 17:49:42 by fgras-ca #+# #+# */
|
/* Created: 2024/01/12 17:49:42 by fgras-ca #+# #+# */
|
||||||
/* Updated: 2024/01/23 17:43:56 by fgras-ca ### ########.fr */
|
/* Updated: 2024/01/29 16:20:39 by fgras-ca ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -26,39 +26,39 @@ float correctfisheye(float distance, float ra, float playerAngle)
|
|||||||
|
|
||||||
void init_base_params(t_base_params *params, t_structure_main *w)
|
void init_base_params(t_base_params *params, t_structure_main *w)
|
||||||
{
|
{
|
||||||
params->tilesize = w->s_map.mapS;
|
params->tilesize = w->s_map.map_s;
|
||||||
params->numrays = NUMRAY;
|
params->numrays = NUMRAY;
|
||||||
params->FOV = FOVIEW * (PI / 180);
|
params->fo_v = FOVIEW * (PI / 180);
|
||||||
params->DR = params->FOV / params->numrays;
|
params->d_r = params->fo_v / params->numrays;
|
||||||
params->ra = w->s_player.pa - (params->FOV / 2);
|
params->ra = w->s_player.pa - (params->fo_v / 2);
|
||||||
draw_background(w);
|
draw_background(w);
|
||||||
}
|
}
|
||||||
|
|
||||||
void calculate_ray(t_base_params *base, t_ray_state *state,
|
void calculate_ray(t_base_params *base, t_ray_state *state,
|
||||||
t_ray_calc *calc, t_ray_params *rayparams)
|
t_ray_calc *calc, t_ray_params *rayparams)
|
||||||
{
|
{
|
||||||
if (state->disH < state->disV)
|
if (state->dis_h < state->dis_v)
|
||||||
{
|
{
|
||||||
rayparams->disT = state->disH;
|
rayparams->dis_t = state->dis_h;
|
||||||
calc->color = 0xFF0000;
|
calc->color = 0xFF0000;
|
||||||
rayparams->wallDir = state->hwalldir;
|
rayparams->wall_dir = state->hwalldir;
|
||||||
rayparams->rx = state->hx;
|
rayparams->rx = state->hx;
|
||||||
rayparams->ry = state->hy;
|
rayparams->ry = state->hy;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
rayparams->disT = state->disV;
|
rayparams->dis_t = state->dis_v;
|
||||||
calc->color = 0x00FF00;
|
calc->color = 0x00FF00;
|
||||||
rayparams->wallDir = state->vwalldir;
|
rayparams->wall_dir = state->vwalldir;
|
||||||
rayparams->rx = state->vx;
|
rayparams->rx = state->vx;
|
||||||
rayparams->ry = state->vy;
|
rayparams->ry = state->vy;
|
||||||
}
|
}
|
||||||
rayparams->disT = correctfisheye(rayparams->disT,
|
rayparams->dis_t = correctfisheye(rayparams->dis_t,
|
||||||
base->ra, calc->w->s_player.pa);
|
base->ra, calc->w->s_player.pa);
|
||||||
rayparams->w = calc->w;
|
rayparams->w = calc->w;
|
||||||
rayparams->tileSize = base->tilesize;
|
rayparams->tile_size = base->tilesize;
|
||||||
rayparams->r = calc->r;
|
rayparams->r = calc->r;
|
||||||
rayparams->numRays = base->numrays;
|
rayparams->num_rays = base->numrays;
|
||||||
rayparams->color = calc->color;
|
rayparams->color = calc->color;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,16 +73,16 @@ void drawrays2d(t_structure_main *w)
|
|||||||
{
|
{
|
||||||
params.base_params.ra = fmod(params.base_params.ra + 2 * PI, 2 * PI);
|
params.base_params.ra = fmod(params.base_params.ra + 2 * PI, 2 * PI);
|
||||||
params.hrayparams = (t_ray_calc_params){w, params.base_params.ra,
|
params.hrayparams = (t_ray_calc_params){w, params.base_params.ra,
|
||||||
¶ms.ray_state.disH, ¶ms.ray_state.hx,
|
¶ms.ray_state.dis_h, ¶ms.ray_state.hx,
|
||||||
¶ms.ray_state.hy, ¶ms.ray_state.hwalldir};
|
¶ms.ray_state.hy, ¶ms.ray_state.hwalldir};
|
||||||
params.vrayparams = (t_ray_calc_params){w, params.base_params.ra,
|
params.vrayparams = (t_ray_calc_params){w, params.base_params.ra,
|
||||||
¶ms.ray_state.disV, ¶ms.ray_state.vx,
|
¶ms.ray_state.dis_v, ¶ms.ray_state.vx,
|
||||||
¶ms.ray_state.vy, ¶ms.ray_state.vwalldir};
|
¶ms.ray_state.vy, ¶ms.ray_state.vwalldir};
|
||||||
calculatehorizontalray(¶ms.hrayparams);
|
calculatehorizontalray(¶ms.hrayparams);
|
||||||
calculateverticalray(¶ms.vrayparams);
|
calculateverticalray(¶ms.vrayparams);
|
||||||
calculate_ray(¶ms.base_params, ¶ms.ray_state,
|
calculate_ray(¶ms.base_params, ¶ms.ray_state,
|
||||||
¶ms.ray_calc, ¶ms.rayparams);
|
¶ms.ray_calc, ¶ms.rayparams);
|
||||||
drawray(¶ms.rayparams);
|
drawray(¶ms.rayparams);
|
||||||
params.base_params.ra += params.base_params.DR;
|
params.base_params.ra += params.base_params.d_r;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,32 +6,50 @@
|
|||||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/01/12 17:35:53 by fgras-ca #+# #+# */
|
/* Created: 2024/01/12 17:35:53 by fgras-ca #+# #+# */
|
||||||
/* Updated: 2024/01/26 17:25:05 by fgras-ca ### ########.fr */
|
/* Updated: 2024/01/29 17:05:58 by fgras-ca ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "../cub3d.h"
|
#include "../cub3d.h"
|
||||||
|
|
||||||
void init_line_params(t_line_params *lineparams, t_ray_params *rayParams)
|
static void calculate_line_height(t_ray_params *rayparams)
|
||||||
{
|
{
|
||||||
lineparams->w = rayParams->w;
|
rayparams->line_h = (rayparams->tile_size * rayparams->max3d_height)
|
||||||
lineparams->x0 = (int)rayParams->w->s_player.px;
|
/ rayparams->dis_t;
|
||||||
lineparams->y0 = (int)rayParams->w->s_player.py;
|
if (rayparams->line_h > rayparams->max3d_height)
|
||||||
lineparams->x1 = (int)rayParams->rx;
|
{
|
||||||
lineparams->y1 = (int)rayParams->ry;
|
rayparams->line_h = rayparams->max3d_height;
|
||||||
lineparams->color = rayParams->color;
|
}
|
||||||
|
rayparams->line_off = ((rayparams->max3d_height - rayparams->line_h) / 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void init_texture_params(t_texture_params *textureparams,
|
static void calculate_deca(t_ray_params *rayparams, float *olineh, int *deca)
|
||||||
t_ray_params *rayParams)
|
|
||||||
{
|
{
|
||||||
textureparams->w = rayParams->w;
|
*olineh = (rayparams->w->s_map.map_s * rayparams->w->s_win.height)
|
||||||
textureparams->lineOff = rayParams->lineOff;
|
/ rayparams->dis_t;
|
||||||
textureparams->lineH = rayParams->lineH;
|
if (*olineh > rayparams->w->s_win.height)
|
||||||
textureparams->wallDir = rayParams->wallDir;
|
{
|
||||||
textureparams->rx = rayParams->rx + rayParams->backgroundOffsetX;
|
*deca = *olineh - rayparams->w->s_win.height;
|
||||||
textureparams->ry = rayParams->ry;
|
}
|
||||||
textureparams->disT = rayParams->disT;
|
else
|
||||||
|
{
|
||||||
|
*deca = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void set_rayparams(t_ray_params *rayparams)
|
||||||
|
{
|
||||||
|
rayparams->start3d_height = 0;
|
||||||
|
rayparams->max3d_height = rayparams->w->s_win.height
|
||||||
|
+ rayparams->start3d_height;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void set_texture_params(t_ray_params *rayparams,
|
||||||
|
t_texture_params *textureparams)
|
||||||
|
{
|
||||||
|
textureparams->start_x = rayparams->r * rayparams->raywidth
|
||||||
|
+ rayparams->background_off_setx;
|
||||||
|
textureparams->end_x = textureparams->start_x + rayparams->raywidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawray(t_ray_params *rayparams)
|
void drawray(t_ray_params *rayparams)
|
||||||
@ -40,96 +58,23 @@ void drawray(t_ray_params *rayparams)
|
|||||||
t_texture_params textureparams;
|
t_texture_params textureparams;
|
||||||
float olineh;
|
float olineh;
|
||||||
int deca;
|
int deca;
|
||||||
int color;
|
|
||||||
|
|
||||||
rayparams->start3DHeight = 0;
|
set_rayparams(rayparams);
|
||||||
rayparams->max3DHeight = rayparams->w->s_win.height
|
calculate_line_height(rayparams);
|
||||||
+ rayparams->start3DHeight;
|
rayparams->raywidth = rayparams->w->s_win.width / rayparams->num_rays;
|
||||||
rayparams->lineH = (rayparams->tileSize * rayparams->max3DHeight)
|
rayparams->background_off_setx = BOV;
|
||||||
/ rayparams->disT;
|
calculate_deca(rayparams, &olineh, &deca);
|
||||||
if (rayparams->lineH > rayparams->max3DHeight)
|
set_texture_params(rayparams, &textureparams);
|
||||||
{
|
|
||||||
rayparams->lineH = rayparams->max3DHeight;
|
|
||||||
}
|
|
||||||
rayparams->lineOff = ((rayparams->max3DHeight - rayparams->lineH) / 2);
|
|
||||||
olineh = (rayparams->w->s_map.mapS * rayparams->w->s_win.height) / rayparams->disT;
|
|
||||||
rayparams->backgroundOffsetX = BOV;
|
|
||||||
rayparams->raywidth = rayparams->w->s_win.width / rayparams->numRays;
|
|
||||||
textureparams.startX = rayparams->r * rayparams->raywidth
|
|
||||||
+ rayparams->backgroundOffsetX;
|
|
||||||
textureparams.endX = textureparams.startX + rayparams->raywidth;
|
|
||||||
init_texture_params(&textureparams, rayparams);
|
init_texture_params(&textureparams, rayparams);
|
||||||
init_line_params(&lineparams, rayparams);
|
init_line_params(&lineparams, rayparams);
|
||||||
draw_line(&lineparams);
|
draw_line(&lineparams);
|
||||||
if (olineh > rayparams->w->s_win.height)
|
|
||||||
deca = olineh - rayparams->w->s_win.height;
|
|
||||||
else
|
|
||||||
deca = 0;
|
|
||||||
draw_black_ground(rayparams, textureparams);
|
draw_black_ground(rayparams, textureparams);
|
||||||
if (deca != 0)
|
if (deca != 0)
|
||||||
|
{
|
||||||
draw_yolo(rayparams, &textureparams, deca);
|
draw_yolo(rayparams, &textureparams, deca);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
draw_texture(&textureparams);
|
draw_texture(&textureparams);
|
||||||
}
|
|
||||||
|
|
||||||
void draw_yolo(t_ray_params *rparams, t_texture_params *tparams, int deca)
|
|
||||||
{
|
|
||||||
int texturewidth;
|
|
||||||
int textureheight;
|
|
||||||
int i;
|
|
||||||
int y;
|
|
||||||
int x;
|
|
||||||
float perspectivefactor;
|
|
||||||
int texturex;
|
|
||||||
int color;
|
|
||||||
|
|
||||||
texturewidth = tparams->w->s_img.texture_width;
|
|
||||||
textureheight = tparams->w->s_img.texture_height;
|
|
||||||
i = 0;
|
|
||||||
for (y = rparams->lineOff; y < rparams->lineOff + rparams->lineH; y++) {
|
|
||||||
// La variable perspectiveFactor permet de mapper la texture en tenant compte de la perspective
|
|
||||||
perspectivefactor = (float)(y - rparams->lineOff) / rparams->lineH;
|
|
||||||
int textureY = perspectivefactor * (textureheight );
|
|
||||||
if (textureY >= textureheight) {
|
|
||||||
textureY = textureheight - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
//for (int x = startX; x < endX; x++) {
|
|
||||||
x = tparams->startX;
|
|
||||||
switch (tparams->wallDir) {
|
|
||||||
case NORTH:
|
|
||||||
case SOUTH:
|
|
||||||
// Assurez-vous que rx est normalisé correctement pour le mappage de texture
|
|
||||||
texturex = (int)(tparams->rx * texturewidth / tparams->w->s_map.mapS) % texturewidth;
|
|
||||||
break;
|
|
||||||
case WEST:
|
|
||||||
case EAST:
|
|
||||||
// Assurez-vous que ry est normalisé correctement pour le mappage de texture
|
|
||||||
texturex = (int)(tparams->ry * texturewidth / tparams->w->s_map.mapS) % texturewidth;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (texturex >= texturewidth) {
|
|
||||||
texturex = texturewidth - 1;
|
|
||||||
}
|
|
||||||
//printf("%f %f\n",lineOff, lineOff/lineH);
|
|
||||||
|
|
||||||
|
|
||||||
color = get_texture_color(tparams->w, tparams->wallDir, texturex, y);
|
|
||||||
|
|
||||||
|
|
||||||
// BLOCK OK MEH
|
|
||||||
// float ww = ((720+merde)/lineH);
|
|
||||||
// //printf("%d %d %d\n", t ,td, merde);
|
|
||||||
// put_pixel_img(w, x, (int)(iii*ww)-merde/2, color);
|
|
||||||
// iii++;
|
|
||||||
|
|
||||||
int a = tparams->lineOff - deca / 2;
|
|
||||||
int b = tparams->lineH + (deca /2);
|
|
||||||
int c = tparams->lineH;
|
|
||||||
double step = (b - a)/(double)(c - 1);
|
|
||||||
//printf("%d %d %d\n", t ,td, merde);
|
|
||||||
put_pixel_img(tparams->w, x, (int)(a + i * step), color);
|
|
||||||
i++;
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
93
draw/ft_3d_view_utils.c
Normal file
93
draw/ft_3d_view_utils.c
Normal file
@ -0,0 +1,93 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_3d_view_utils.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2024/01/29 17:00:21 by fgras-ca #+# #+# */
|
||||||
|
/* Updated: 2024/01/29 17:05:55 by fgras-ca ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "../cub3d.h"
|
||||||
|
|
||||||
|
static void set_texture_coords(t_texture_params *tparams,
|
||||||
|
t_draw_params *dparams)
|
||||||
|
{
|
||||||
|
if (tparams->wall_dir == NORTH || tparams->wall_dir == SOUTH)
|
||||||
|
{
|
||||||
|
dparams->texturex = (int)(tparams->rx * dparams->texturewidth
|
||||||
|
/ tparams->w->s_map.map_s) % dparams->texturewidth;
|
||||||
|
}
|
||||||
|
else if (tparams->wall_dir == WEST || tparams->wall_dir == EAST)
|
||||||
|
{
|
||||||
|
dparams->texturex = (int)(tparams->ry * dparams->texturewidth
|
||||||
|
/ tparams->w->s_map.map_s) % dparams->texturewidth;
|
||||||
|
}
|
||||||
|
if (dparams->texturex >= dparams->texturewidth)
|
||||||
|
{
|
||||||
|
dparams->texturex = dparams->texturewidth - 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void draw_texture_line(t_ray_params *rparams,
|
||||||
|
t_texture_params *tparams, t_draw_params *dparams, int deca)
|
||||||
|
{
|
||||||
|
int y;
|
||||||
|
int color;
|
||||||
|
float perspectivefactor;
|
||||||
|
|
||||||
|
y = rparams->line_off;
|
||||||
|
dparams->i = 0;
|
||||||
|
dparams->x = tparams->start_x;
|
||||||
|
while (y < rparams->line_off + rparams->line_h)
|
||||||
|
{
|
||||||
|
perspectivefactor = (float)(y - rparams->line_off) / rparams->line_h;
|
||||||
|
dparams->textureY = perspectivefactor * dparams->textureheight;
|
||||||
|
if (dparams->textureY >= dparams->textureheight)
|
||||||
|
dparams->textureY = dparams->textureheight - 1;
|
||||||
|
set_texture_coords(tparams, dparams);
|
||||||
|
color = get_texture_color(tparams->w,
|
||||||
|
tparams->wall_dir, dparams->texturex, y);
|
||||||
|
dparams->a = tparams->line_off - deca / 2;
|
||||||
|
dparams->b = tparams->line_h + (deca / 2);
|
||||||
|
dparams->c = tparams->line_h;
|
||||||
|
dparams->step = (dparams->b - dparams->a) / (double)(dparams->c - 1);
|
||||||
|
put_pixel_img(tparams->w, dparams->x,
|
||||||
|
(int)(dparams->a + dparams->i * dparams->step), color);
|
||||||
|
dparams->i++;
|
||||||
|
y++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void draw_yolo(t_ray_params *rparams, t_texture_params *tparams, int deca)
|
||||||
|
{
|
||||||
|
t_draw_params dparams;
|
||||||
|
|
||||||
|
dparams.texturewidth = tparams->w->s_img.texture_width;
|
||||||
|
dparams.textureheight = tparams->w->s_img.texture_height;
|
||||||
|
draw_texture_line(rparams, tparams, &dparams, deca);
|
||||||
|
}
|
||||||
|
|
||||||
|
void init_line_params(t_line_params *lineparams, t_ray_params *rayParams)
|
||||||
|
{
|
||||||
|
lineparams->w = rayParams->w;
|
||||||
|
lineparams->x0 = (int)rayParams->w->s_player.px;
|
||||||
|
lineparams->y0 = (int)rayParams->w->s_player.py;
|
||||||
|
lineparams->x1 = (int)rayParams->rx;
|
||||||
|
lineparams->y1 = (int)rayParams->ry;
|
||||||
|
lineparams->color = rayParams->color;
|
||||||
|
}
|
||||||
|
|
||||||
|
void init_texture_params(t_texture_params *textureparams,
|
||||||
|
t_ray_params *rayParams)
|
||||||
|
{
|
||||||
|
textureparams->w = rayParams->w;
|
||||||
|
textureparams->line_off = rayParams->line_off;
|
||||||
|
textureparams->line_h = rayParams->line_h;
|
||||||
|
textureparams->wall_dir = rayParams->wall_dir;
|
||||||
|
textureparams->rx = rayParams->rx + rayParams->background_off_setx;
|
||||||
|
textureparams->ry = rayParams->ry;
|
||||||
|
textureparams->dis_t = rayParams->dis_t;
|
||||||
|
}
|
||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/01/11 23:19:39 by fgras-ca #+# #+# */
|
/* Created: 2024/01/11 23:19:39 by fgras-ca #+# #+# */
|
||||||
/* Updated: 2024/01/26 17:40:14 by fgras-ca ### ########.fr */
|
/* Updated: 2024/01/29 17:08:15 by fgras-ca ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -17,10 +17,10 @@ void draw_sky_ground(t_sky_ground_params *params)
|
|||||||
t_square_params square_params;
|
t_square_params square_params;
|
||||||
|
|
||||||
square_params.w = params->w;
|
square_params.w = params->w;
|
||||||
square_params.x = params->backgroundOffsetX;
|
square_params.x = params->background_off_setx;
|
||||||
square_params.y = params->startHeight;
|
square_params.y = params->start_height;
|
||||||
square_params.xo = params->w->s_win.width + params->backgroundOffsetX;
|
square_params.xo = params->w->s_win.width + params->background_off_setx;
|
||||||
square_params.yo = params->endHeight;
|
square_params.yo = params->end_height;
|
||||||
square_params.color = params->color;
|
square_params.color = params->color;
|
||||||
draw_square_raw(&square_params);
|
draw_square_raw(&square_params);
|
||||||
}
|
}
|
||||||
@ -33,16 +33,16 @@ void draw_background(t_structure_main *w)
|
|||||||
|
|
||||||
backgroundoffsetx = BOV;
|
backgroundoffsetx = BOV;
|
||||||
sky_params.w = w;
|
sky_params.w = w;
|
||||||
sky_params.startHeight = 0;
|
sky_params.start_height = 0;
|
||||||
sky_params.endHeight = w->s_win.height / 2;
|
sky_params.end_height = w->s_win.height / 2;
|
||||||
sky_params.color = w->t->ceil_color;
|
sky_params.color = w->t->ceil_color;
|
||||||
sky_params.backgroundOffsetX = backgroundoffsetx;
|
sky_params.background_off_setx = backgroundoffsetx;
|
||||||
draw_sky_ground(&sky_params);
|
draw_sky_ground(&sky_params);
|
||||||
ground_params.w = w;
|
ground_params.w = w;
|
||||||
ground_params.startHeight = w->s_win.height / 2;
|
ground_params.start_height = w->s_win.height / 2;
|
||||||
ground_params.endHeight = w->s_win.height;
|
ground_params.end_height = w->s_win.height;
|
||||||
ground_params.color = w->t->floor_color;
|
ground_params.color = w->t->floor_color;
|
||||||
ground_params.backgroundOffsetX = backgroundoffsetx;
|
ground_params.background_off_setx = backgroundoffsetx;
|
||||||
draw_sky_ground(&ground_params);
|
draw_sky_ground(&ground_params);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,10 +51,10 @@ void draw_black_ground(t_ray_params *params, t_texture_params tparams)
|
|||||||
t_square_params square_params;
|
t_square_params square_params;
|
||||||
|
|
||||||
square_params.w = params->w;
|
square_params.w = params->w;
|
||||||
square_params.x = tparams.startX;
|
square_params.x = tparams.start_x;
|
||||||
square_params.y = params->lineOff;
|
square_params.y = params->line_off;
|
||||||
square_params.xo = square_params.x + 1;
|
square_params.xo = square_params.x + 1;
|
||||||
square_params.yo = params->lineOff + params->lineH ;
|
square_params.yo = params->line_off + params->line_h ;
|
||||||
square_params.color = 0x000000;
|
square_params.color = 0x000000;
|
||||||
draw_square_raw(&square_params);
|
draw_square_raw(&square_params);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/01/11 22:38:28 by fgras-ca #+# #+# */
|
/* Created: 2024/01/11 22:38:28 by fgras-ca #+# #+# */
|
||||||
/* Updated: 2024/01/14 17:54:44 by fgras-ca ### ########.fr */
|
/* Updated: 2024/01/29 15:47:48 by fgras-ca ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -20,9 +20,9 @@ void draw_square(t_structure_main *w, int x, int y, int color)
|
|||||||
int i;
|
int i;
|
||||||
int j;
|
int j;
|
||||||
|
|
||||||
xo = x * w->s_map.mapS;
|
xo = x * w->s_map.map_s;
|
||||||
yo = y * w->s_map.mapS;
|
yo = y * w->s_map.map_s;
|
||||||
size = w->s_map.mapS;
|
size = w->s_map.map_s;
|
||||||
i = 0;
|
i = 0;
|
||||||
while (i < size)
|
while (i < size)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/01/12 19:53:47 by fgras-ca #+# #+# */
|
/* Created: 2024/01/12 19:53:47 by fgras-ca #+# #+# */
|
||||||
/* Updated: 2024/01/25 20:37:32 by fgras-ca ### ########.fr */
|
/* Updated: 2024/01/29 17:12:54 by fgras-ca ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -25,38 +25,37 @@ void inithorizontalray(t_ray_calc_params *params)
|
|||||||
int tilesize;
|
int tilesize;
|
||||||
|
|
||||||
atan = -1 / tan(params->ra);
|
atan = -1 / tan(params->ra);
|
||||||
tilesize = params->w->s_map.mapS;
|
tilesize = params->w->s_map.map_s;
|
||||||
if (params->ra != PI)
|
if (params->ra != PI)
|
||||||
handle_ra_not_equal_pi(params, atan, tilesize);
|
handle_ra_not_equal_pi(params, atan, tilesize);
|
||||||
else
|
else
|
||||||
handle_ra_equal_pi(params);
|
handle_ra_equal_pi(params);
|
||||||
}
|
}
|
||||||
|
|
||||||
void update_ray_params(t_ray_calc_params *params, int mx, int my) {
|
void update_ray_params(t_ray_calc_params *params, int mx, int my)
|
||||||
int mp = my * params->w->s_map.mapX + mx;
|
{
|
||||||
|
int mp;
|
||||||
|
char map_pos;
|
||||||
|
|
||||||
if (mp >= 0 && mp < params->w->s_map.mapX * params->w->s_map.mapY) {
|
mp = my * params->w->s_map.map_x + mx;
|
||||||
char map_pos = params->w->s_map.map[mp];
|
if (mp >= 0 && mp < params->w->s_map.map_x * params->w->s_map.map_y)
|
||||||
|
{
|
||||||
if (map_pos == '1' || map_pos == '2') {
|
map_pos = params->w->s_map.map[mp];
|
||||||
params->dof = DOF;
|
if (map_pos == '1' || map_pos == '2')
|
||||||
*params->disRay = dist(params->w->s_player.px, params->w->s_player.py,
|
{
|
||||||
*params->rx, *params->ry);
|
params->dof = DOF;
|
||||||
|
*params->dis_ray = dist(params->w->s_player.px,
|
||||||
if (params->ra > PI)
|
params->w->s_player.py, *params->rx, *params->ry);
|
||||||
*params->wallDir = NORTH;
|
if (params->ra > PI)
|
||||||
else
|
*params->wall_dir = NORTH;
|
||||||
*params->wallDir = SOUTH;
|
else
|
||||||
|
*params->wall_dir = SOUTH;
|
||||||
// Définir le type de mur actuel
|
if (map_pos == '2')
|
||||||
if (map_pos == '2') {
|
params->w->current_wall_type = map_pos;
|
||||||
params->w->current_wall_type = map_pos;
|
else
|
||||||
} else {
|
params->w->current_wall_type = '1';
|
||||||
// Assurez-vous de réinitialiser pour les murs normaux
|
}
|
||||||
params->w->current_wall_type = '1';
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void processhorizontalray(t_ray_calc_params *params)
|
void processhorizontalray(t_ray_calc_params *params)
|
||||||
@ -65,8 +64,8 @@ void processhorizontalray(t_ray_calc_params *params)
|
|||||||
int my;
|
int my;
|
||||||
int tilesize;
|
int tilesize;
|
||||||
|
|
||||||
tilesize = params->w->s_map.mapS;
|
tilesize = params->w->s_map.map_s;
|
||||||
*params->disRay = DISRAY;
|
*params->dis_ray = DISRAY;
|
||||||
while (params->dof < DOF)
|
while (params->dof < DOF)
|
||||||
{
|
{
|
||||||
mx = (int)(*params->rx) / tilesize;
|
mx = (int)(*params->rx) / tilesize;
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/01/14 20:30:59 by fgras-ca #+# #+# */
|
/* Created: 2024/01/14 20:30:59 by fgras-ca #+# #+# */
|
||||||
/* Updated: 2024/01/25 20:34:50 by fgras-ca ### ########.fr */
|
/* Updated: 2024/01/29 17:13:50 by fgras-ca ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -37,7 +37,6 @@ void load_wall_textures(t_structure_main *w)
|
|||||||
load_texture(w, w->t->west, (void **)&w->s_img.west_texture);
|
load_texture(w, w->t->west, (void **)&w->s_img.west_texture);
|
||||||
load_texture(w, w->t->east, (void **)&w->s_img.east_texture);
|
load_texture(w, w->t->east, (void **)&w->s_img.east_texture);
|
||||||
load_texture(w, "textures/door_close.xpm", (void **)&w->s_img.door_texture);
|
load_texture(w, "textures/door_close.xpm", (void **)&w->s_img.door_texture);
|
||||||
//load_texture(w, "textures/open_door.xpm", (void **)&w->s_img.open_door_texture);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void exit_error(t_structure_main *w)
|
void exit_error(t_structure_main *w)
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/01/12 17:39:11 by fgras-ca #+# #+# */
|
/* Created: 2024/01/12 17:39:11 by fgras-ca #+# #+# */
|
||||||
/* Updated: 2024/01/25 20:34:32 by fgras-ca ### ########.fr */
|
/* Updated: 2024/01/29 17:17:21 by fgras-ca ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -20,19 +20,19 @@ void draw_texture_line(t_texture_params *params, float y, int textureY)
|
|||||||
int color;
|
int color;
|
||||||
|
|
||||||
texturewidth = params->w->s_img.texture_width;
|
texturewidth = params->w->s_img.texture_width;
|
||||||
x = params->startX;
|
x = params->start_x;
|
||||||
while (x < params->endX)
|
while (x < params->end_x)
|
||||||
{
|
{
|
||||||
if (params->wallDir == NORTH || params->wallDir == SOUTH)
|
if (params->wall_dir == NORTH || params->wall_dir == SOUTH)
|
||||||
texturex = (int)(params->rx * texturewidth
|
texturex = (int)(params->rx * texturewidth
|
||||||
/ params->w->s_map.mapS) % texturewidth;
|
/ params->w->s_map.map_s) % texturewidth;
|
||||||
else
|
else
|
||||||
texturex = (int)(params->ry * texturewidth
|
texturex = (int)(params->ry * texturewidth
|
||||||
/ params->w->s_map.mapS) % texturewidth;
|
/ params->w->s_map.map_s) % texturewidth;
|
||||||
if (texturex >= texturewidth)
|
if (texturex >= texturewidth)
|
||||||
texturex = texturewidth - 1;
|
texturex = texturewidth - 1;
|
||||||
color = get_texture_color(params->w,
|
color = get_texture_color(params->w,
|
||||||
params->wallDir, texturex, textureY);
|
params->wall_dir, texturex, textureY);
|
||||||
put_pixel_img(params->w, x, y, color);
|
put_pixel_img(params->w, x, y, color);
|
||||||
x++;
|
x++;
|
||||||
}
|
}
|
||||||
@ -46,10 +46,10 @@ void draw_texture(t_texture_params *params)
|
|||||||
int texturey;
|
int texturey;
|
||||||
|
|
||||||
textureheight = params->w->s_img.texture_height;
|
textureheight = params->w->s_img.texture_height;
|
||||||
y = params->lineOff;
|
y = params->line_off;
|
||||||
while (y < params->lineOff + params->lineH)
|
while (y < params->line_off + params->line_h)
|
||||||
{
|
{
|
||||||
perspectivefactor = (y - params->lineOff) / params->lineH;
|
perspectivefactor = (y - params->line_off) / params->line_h;
|
||||||
texturey = perspectivefactor * textureheight;
|
texturey = perspectivefactor * textureheight;
|
||||||
if (texturey >= textureheight)
|
if (texturey >= textureheight)
|
||||||
texturey = textureheight - 1;
|
texturey = textureheight - 1;
|
||||||
@ -58,14 +58,15 @@ void draw_texture(t_texture_params *params)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void *get_selected_texture(t_structure_main *w, WallDirection wallDir)
|
void *get_selected_texture(t_structure_main *w, t_WallDirection wallDir)
|
||||||
{
|
{
|
||||||
void *texture = NULL;
|
void *texture;
|
||||||
if (w->current_wall_type == '2') {
|
|
||||||
return w->s_img.door_texture; // Texture pour porte fermée
|
texture = NULL;
|
||||||
} /*else if (w->current_wall_type == '3') {
|
if (w->current_wall_type == '2')
|
||||||
return w->s_img.open_door_texture; // Texture pour porte ouverte
|
{
|
||||||
}*/
|
return (w->s_img.door_texture);
|
||||||
|
}
|
||||||
else if (wallDir == NORTH)
|
else if (wallDir == NORTH)
|
||||||
return (w->s_img.north_texture);
|
return (w->s_img.north_texture);
|
||||||
else if (wallDir == SOUTH)
|
else if (wallDir == SOUTH)
|
||||||
@ -76,12 +77,12 @@ void *get_selected_texture(t_structure_main *w, WallDirection wallDir)
|
|||||||
return (w->s_img.east_texture);
|
return (w->s_img.east_texture);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Invalid wall direction.\n");
|
printf("Invalid wall direction.\n");
|
||||||
exit_error(w);
|
exit_error(w);
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
if (texture == NULL)
|
if (texture == NULL)
|
||||||
fprintf(stderr, "get_selected_texture: selected texture is NULL\n");
|
printf("get_selected_texture: selected texture is NULL\n");
|
||||||
else
|
else
|
||||||
printf("get_selected_texture: selected texture = %p\n", texture);
|
printf("get_selected_texture: selected texture = %p\n", texture);
|
||||||
}
|
}
|
||||||
@ -95,7 +96,7 @@ t_texture_data get_texture_data(void *texture)
|
|||||||
return (texture_data);
|
return (texture_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
int get_texture_color(t_structure_main *w, WallDirection wallDir,
|
int get_texture_color(t_structure_main *w, t_WallDirection wallDir,
|
||||||
int textureX, int textureY)
|
int textureX, int textureY)
|
||||||
{
|
{
|
||||||
void *selected_texture;
|
void *selected_texture;
|
||||||
@ -108,7 +109,6 @@ int get_texture_color(t_structure_main *w, WallDirection wallDir,
|
|||||||
fprintf(stderr, "No texture selected for color retrieval\n");
|
fprintf(stderr, "No texture selected for color retrieval\n");
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
texture_data = get_texture_data(selected_texture);
|
texture_data = get_texture_data(selected_texture);
|
||||||
pixel_pos = (textureX + textureY * w->s_img.texture_width)
|
pixel_pos = (textureX + textureY * w->s_img.texture_width)
|
||||||
* (texture_data.bpp / 8);
|
* (texture_data.bpp / 8);
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/01/12 20:03:21 by fgras-ca #+# #+# */
|
/* Created: 2024/01/12 20:03:21 by fgras-ca #+# #+# */
|
||||||
/* Updated: 2024/01/25 20:37:08 by fgras-ca ### ########.fr */
|
/* Updated: 2024/01/29 17:22:00 by fgras-ca ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -18,35 +18,35 @@ void initverticalray(t_ray_calc_params *params)
|
|||||||
int tilesize;
|
int tilesize;
|
||||||
|
|
||||||
ntan = -tan(params->ra);
|
ntan = -tan(params->ra);
|
||||||
tilesize = params->w->s_map.mapS;
|
tilesize = params->w->s_map.map_s;
|
||||||
handle_ra_vertical(params, ntan, tilesize);
|
handle_ra_vertical(params, ntan, tilesize);
|
||||||
}
|
}
|
||||||
|
|
||||||
void update_vertical_ray_params(t_ray_calc_params *params, int mx, int my) {
|
void update_vertical_ray_params(t_ray_calc_params *params, int mx, int my)
|
||||||
int mp = my * params->w->s_map.mapX + mx;
|
{
|
||||||
|
int mp;
|
||||||
|
char map_pos;
|
||||||
|
|
||||||
if (mp >= 0 && mp < params->w->s_map.mapX * params->w->s_map.mapY) {
|
mp = my * params->w->s_map.map_x + mx;
|
||||||
char map_pos = params->w->s_map.map[mp];
|
if (mp >= 0 && mp < params->w->s_map.map_x * params->w->s_map.map_y)
|
||||||
|
{
|
||||||
if (map_pos == '1' || map_pos == '2') {
|
map_pos = params->w->s_map.map[mp];
|
||||||
params->dof = DOF;
|
if (map_pos == '1' || map_pos == '2')
|
||||||
*params->disRay = dist(params->w->s_player.px, params->w->s_player.py,
|
{
|
||||||
*params->rx, *params->ry);
|
params->dof = DOF;
|
||||||
|
*params->dis_ray = dist(params->w->s_player.px,
|
||||||
if (params->ra > P2 && params->ra < P3)
|
params->w->s_player.py,
|
||||||
*params->wallDir = WEST;
|
*params->rx, *params->ry);
|
||||||
else
|
if (params->ra > P2 && params->ra < P3)
|
||||||
*params->wallDir = EAST;
|
*params->wall_dir = WEST;
|
||||||
|
else
|
||||||
// Définir le type de mur actuel
|
*params->wall_dir = EAST;
|
||||||
if (map_pos == '2') {
|
if (map_pos == '2')
|
||||||
params->w->current_wall_type = map_pos;
|
params->w->current_wall_type = map_pos;
|
||||||
} else {
|
else
|
||||||
// Assurez-vous de réinitialiser pour les murs normaux
|
params->w->current_wall_type = '1';
|
||||||
params->w->current_wall_type = '1';
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void processverticalray(t_ray_calc_params *params)
|
void processverticalray(t_ray_calc_params *params)
|
||||||
@ -55,8 +55,8 @@ void processverticalray(t_ray_calc_params *params)
|
|||||||
int my;
|
int my;
|
||||||
int tilesize;
|
int tilesize;
|
||||||
|
|
||||||
tilesize = params->w->s_map.mapS;
|
tilesize = params->w->s_map.map_s;
|
||||||
*params->disRay = DISRAY;
|
*params->dis_ray = DISRAY;
|
||||||
while (params->dof < DOF)
|
while (params->dof < DOF)
|
||||||
{
|
{
|
||||||
mx = (int)(*params->rx) / tilesize;
|
mx = (int)(*params->rx) / tilesize;
|
||||||
|
|||||||
168
include/mlx.h
168
include/mlx.h
@ -1,139 +1,53 @@
|
|||||||
/*
|
/* ************************************************************************** */
|
||||||
** mlx.h for MinilibX in
|
/* */
|
||||||
**
|
/* ::: :::::::: */
|
||||||
** Made by Charlie Root
|
/* mlx.h :+: :+: :+: */
|
||||||
** Login <ol@epitech.net>
|
/* +:+ +:+ +:+ */
|
||||||
**
|
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||||
** Started on Mon Jul 31 16:37:50 2000 Charlie Root
|
/* +#+#+#+#+#+ +#+ */
|
||||||
** Last update Tue May 15 16:23:28 2007 Olivier Crouzet
|
/* Created: 2024/01/29 17:22:58 by fgras-ca #+# #+# */
|
||||||
*/
|
/* Updated: 2024/01/29 17:28:02 by fgras-ca ### ########.fr */
|
||||||
|
/* */
|
||||||
/*
|
/* ************************************************************************** */
|
||||||
** MinilibX - Please report bugs
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
** FR msg - FR msg - FR msg
|
|
||||||
**
|
|
||||||
** La MinilibX utilise 2 librairies supplementaires qu'il
|
|
||||||
** est necessaire de rajouter a la compilation :
|
|
||||||
** -lmlx -lXext -lX11
|
|
||||||
**
|
|
||||||
** La MinilibX permet le chargement des images de type Xpm.
|
|
||||||
** Notez que cette implementation est incomplete.
|
|
||||||
** Merci de communiquer tout probleme de chargement d'image
|
|
||||||
** de ce type.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef MLX_H
|
#ifndef MLX_H
|
||||||
|
# define MLX_H
|
||||||
#define MLX_H
|
|
||||||
|
|
||||||
|
|
||||||
void *mlx_init();
|
void *mlx_init();
|
||||||
/*
|
|
||||||
** needed before everything else.
|
|
||||||
** return (void *)0 if failed
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
** Basic actions
|
|
||||||
*/
|
|
||||||
|
|
||||||
void *mlx_new_window(void *mlx_ptr, int size_x, int size_y, char *title);
|
void *mlx_new_window(void *mlx_ptr, int size_x, int size_y, char *title);
|
||||||
/*
|
int mlx_clear_window(void *mlx_ptr, void *win_ptr);
|
||||||
** return void *0 if failed
|
int mlx_pixel_put(void *mlx_ptr, void *win_ptr, int x, int y, int color);
|
||||||
*/
|
|
||||||
int mlx_clear_window(void *mlx_ptr, void *win_ptr);
|
|
||||||
int mlx_pixel_put(void *mlx_ptr, void *win_ptr, int x, int y, int color);
|
|
||||||
/*
|
|
||||||
** origin for x & y is top left corner of the window
|
|
||||||
** y down is positive
|
|
||||||
** color is 0x00RRGGBB
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
** Image stuff
|
|
||||||
*/
|
|
||||||
|
|
||||||
void *mlx_new_image(void *mlx_ptr,int width,int height);
|
void *mlx_new_image(void *mlx_ptr,int width,int height);
|
||||||
/*
|
|
||||||
** return void *0 if failed
|
|
||||||
** obsolete : image2 data is stored using bit planes
|
|
||||||
** void *mlx_new_image2(void *mlx_ptr,int width,int height);
|
|
||||||
*/
|
|
||||||
char *mlx_get_data_addr(void *img_ptr, int *bits_per_pixel,
|
char *mlx_get_data_addr(void *img_ptr, int *bits_per_pixel,
|
||||||
int *size_line, int *endian);
|
int *size_line, int *endian);
|
||||||
/*
|
int mlx_put_image_to_window(void *mlx_ptr, void *win_ptr, void *img_ptr,
|
||||||
** endian : 0 = sever X is little endian, 1 = big endian
|
|
||||||
** for mlx_new_image2, 2nd arg of mlx_get_data_addr is number_of_planes
|
|
||||||
*/
|
|
||||||
int mlx_put_image_to_window(void *mlx_ptr, void *win_ptr, void *img_ptr,
|
|
||||||
int x, int y);
|
int x, int y);
|
||||||
int mlx_get_color_value(void *mlx_ptr, int color);
|
int mlx_get_color_value(void *mlx_ptr, int color);
|
||||||
|
int mlx_mouse_hook (void *win_ptr, int (*funct_ptr)(), void *param);
|
||||||
|
int mlx_key_hook (void *win_ptr, int (*funct_ptr)(), void *param);
|
||||||
/*
|
int mlx_expose_hook (void *win_ptr, int (*funct_ptr)(), void *param);
|
||||||
** dealing with Events
|
int mlx_loop_hook (void *mlx_ptr, int (*funct_ptr)(), void *param);
|
||||||
*/
|
int mlx_loop (void *mlx_ptr);
|
||||||
|
int mlx_loop_end (void *mlx_ptr);
|
||||||
int mlx_mouse_hook (void *win_ptr, int (*funct_ptr)(), void *param);
|
int mlx_string_put(void *mlx_ptr, void *win_ptr, int x, int y, int color,
|
||||||
int mlx_key_hook (void *win_ptr, int (*funct_ptr)(), void *param);
|
char *string);
|
||||||
int mlx_expose_hook (void *win_ptr, int (*funct_ptr)(), void *param);
|
|
||||||
|
|
||||||
int mlx_loop_hook (void *mlx_ptr, int (*funct_ptr)(), void *param);
|
|
||||||
int mlx_loop (void *mlx_ptr);
|
|
||||||
int mlx_loop_end (void *mlx_ptr);
|
|
||||||
|
|
||||||
/*
|
|
||||||
** hook funct are called as follow :
|
|
||||||
**
|
|
||||||
** expose_hook(void *param);
|
|
||||||
** key_hook(int keycode, void *param);
|
|
||||||
** mouse_hook(int button, int x,int y, void *param);
|
|
||||||
** loop_hook(void *param);
|
|
||||||
**
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
** Usually asked...
|
|
||||||
*/
|
|
||||||
|
|
||||||
int mlx_string_put(void *mlx_ptr, void *win_ptr, int x, int y, int color,
|
|
||||||
char *string);
|
|
||||||
void mlx_set_font(void *mlx_ptr, void *win_ptr, char *name);
|
void mlx_set_font(void *mlx_ptr, void *win_ptr, char *name);
|
||||||
void *mlx_xpm_to_image(void *mlx_ptr, char **xpm_data,
|
void *mlx_xpm_to_image(void *mlx_ptr, char **xpm_data,
|
||||||
int *width, int *height);
|
int *width, int *height);
|
||||||
void *mlx_xpm_file_to_image(void *mlx_ptr, char *filename,
|
void *mlx_xpm_file_to_image(void *mlx_ptr, char *filename,
|
||||||
int *width, int *height);
|
int *width, int *height);
|
||||||
int mlx_destroy_window(void *mlx_ptr, void *win_ptr);
|
int mlx_destroy_window(void *mlx_ptr, void *win_ptr);
|
||||||
|
int mlx_destroy_image(void *mlx_ptr, void *img_ptr);
|
||||||
|
int mlx_destroy_display(void *mlx_ptr);
|
||||||
|
int mlx_hook(void *win_ptr, int x_event, int x_mask,
|
||||||
|
int (*funct)(), void *param);
|
||||||
|
int mlx_do_key_autorepeatoff(void *mlx_ptr);
|
||||||
|
int mlx_do_key_autorepeaton(void *mlx_ptr);
|
||||||
|
int mlx_do_sync(void *mlx_ptr);
|
||||||
|
int mlx_mouse_get_pos(void *mlx_ptr, void *win_ptr, int *x, int *y);
|
||||||
|
int mlx_mouse_move(void *mlx_ptr, void *win_ptr, int x, int y);
|
||||||
|
int mlx_mouse_hide(void *mlx_ptr, void *win_ptr);
|
||||||
|
int mlx_mouse_show(void *mlx_ptr, void *win_ptr);
|
||||||
|
int mlx_get_screen_size(void *mlx_ptr, int *sizex, int *sizey);
|
||||||
|
|
||||||
int mlx_destroy_image(void *mlx_ptr, void *img_ptr);
|
#endif
|
||||||
|
|
||||||
int mlx_destroy_display(void *mlx_ptr);
|
|
||||||
|
|
||||||
/*
|
|
||||||
** generic hook system for all events, and minilibX functions that
|
|
||||||
** can be hooked. Some macro and defines from X11/X.h are needed here.
|
|
||||||
*/
|
|
||||||
|
|
||||||
int mlx_hook(void *win_ptr, int x_event, int x_mask,
|
|
||||||
int (*funct)(), void *param);
|
|
||||||
|
|
||||||
int mlx_do_key_autorepeatoff(void *mlx_ptr);
|
|
||||||
int mlx_do_key_autorepeaton(void *mlx_ptr);
|
|
||||||
int mlx_do_sync(void *mlx_ptr);
|
|
||||||
|
|
||||||
int mlx_mouse_get_pos(void *mlx_ptr, void *win_ptr, int *x, int *y);
|
|
||||||
int mlx_mouse_move(void *mlx_ptr, void *win_ptr, int x, int y);
|
|
||||||
int mlx_mouse_hide(void *mlx_ptr, void *win_ptr);
|
|
||||||
int mlx_mouse_show(void *mlx_ptr, void *win_ptr);
|
|
||||||
|
|
||||||
int mlx_get_screen_size(void *mlx_ptr, int *sizex, int *sizey);
|
|
||||||
|
|
||||||
#endif /* MLX_H */
|
|
||||||
|
|||||||
102
libft/Makefile
102
libft/Makefile
@ -1,102 +0,0 @@
|
|||||||
# **************************************************************************** #
|
|
||||||
# #
|
|
||||||
# ::: :::::::: #
|
|
||||||
# Makefile :+: :+: :+: #
|
|
||||||
# +:+ +:+ +:+ #
|
|
||||||
# By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ #
|
|
||||||
# +#+#+#+#+#+ +#+ #
|
|
||||||
# Created: 2023/02/06 12:19:21 by fgras-ca #+# #+# #
|
|
||||||
# Updated: 2024/01/15 22:06:15 by fgras-ca ### ########.fr #
|
|
||||||
# #
|
|
||||||
# **************************************************************************** #
|
|
||||||
|
|
||||||
RST = \033[0m
|
|
||||||
GRAY = \033[0;90m
|
|
||||||
RED = \033[0;91m
|
|
||||||
GREEN = \033[0;92m
|
|
||||||
YELLOW = \033[0;93m
|
|
||||||
BLUE = \033[0;94m
|
|
||||||
MAGENTA = \033[0;95m
|
|
||||||
CYAN = \033[0;96m
|
|
||||||
WHITE = \033[0;97m
|
|
||||||
ORANGE = \033[38;5;214m
|
|
||||||
|
|
||||||
NAME = libft.a
|
|
||||||
|
|
||||||
SOURCES = ft_atoi.c \
|
|
||||||
ft_isalpha.c \
|
|
||||||
ft_memchr.c \
|
|
||||||
ft_memset.c \
|
|
||||||
ft_strlcat.c \
|
|
||||||
ft_strnstr.c \
|
|
||||||
ft_toupper.c \
|
|
||||||
ft_bzero.c \
|
|
||||||
ft_isascii.c \
|
|
||||||
ft_memcmp.c \
|
|
||||||
ft_strchr.c \
|
|
||||||
ft_strlcpy.c \
|
|
||||||
ft_strrchr.c \
|
|
||||||
ft_calloc.c \
|
|
||||||
ft_isdigit.c \
|
|
||||||
ft_memcpy.c \
|
|
||||||
ft_substr.c \
|
|
||||||
ft_isalnum.c \
|
|
||||||
ft_isprint.c \
|
|
||||||
ft_memmove.c \
|
|
||||||
ft_strncmp.c \
|
|
||||||
ft_tolower.c\
|
|
||||||
ft_strtrim.c \
|
|
||||||
ft_putchar_fd.c \
|
|
||||||
ft_putstr_fd.c \
|
|
||||||
ft_putendl_fd.c \
|
|
||||||
ft_putnbr_fd.c \
|
|
||||||
ft_strmapi.c \
|
|
||||||
ft_striteri.c \
|
|
||||||
ft_itoa.c \
|
|
||||||
ft_strcmp.c \
|
|
||||||
ft_strstr.c \
|
|
||||||
ft_reallocarray.c \
|
|
||||||
ft_strcat.c \
|
|
||||||
ft_strcpy.c \
|
|
||||||
ft_realloc.c \
|
|
||||||
ft_strncpy.c \
|
|
||||||
ft_strtol.c \
|
|
||||||
ft_strtok.c \
|
|
||||||
|
|
||||||
SRCBONUS = ft_lstnew.c \
|
|
||||||
ft_lstadd_front.c \
|
|
||||||
ft_lstsize.c \
|
|
||||||
ft_lstlast.c \
|
|
||||||
ft_lstadd_back.c \
|
|
||||||
ft_lstdelone.c \
|
|
||||||
ft_lstclear.c \
|
|
||||||
ft_lstiter.c \
|
|
||||||
ft_lstiter.c \
|
|
||||||
ft_lstmap.c \
|
|
||||||
|
|
||||||
|
|
||||||
OBJECTS = $(SOURCES:.c=.o)
|
|
||||||
|
|
||||||
BONUS_OBJ = $(SRCBONUS:.c=.o)
|
|
||||||
|
|
||||||
CC = gcc
|
|
||||||
|
|
||||||
RM = rm -f
|
|
||||||
|
|
||||||
CFLAGS = -Wall -Werror -Wextra
|
|
||||||
|
|
||||||
all: $(NAME)
|
|
||||||
|
|
||||||
$(NAME): $(OBJECTS)
|
|
||||||
@echo $(CC) (CFLAGS) $(OBJECTS) -o $(NAME)
|
|
||||||
|
|
||||||
bonus: $(OBJECTS) $(BONUS_OBJ)
|
|
||||||
$(CC) (CFLAGS) $(OBJECTS) $(BONUS_OBJ) -o $(NAME)
|
|
||||||
|
|
||||||
clean:
|
|
||||||
@echo $(RM) $(OBJECTS) $(BONUS_OBJ)
|
|
||||||
|
|
||||||
fclean: clean
|
|
||||||
@echo $(RM) $(NAME) $(BONUS_OBJ)
|
|
||||||
|
|
||||||
re: fclean all
|
|
||||||
@ -1,38 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_atoi.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/02/11 16:16:54 by fgras-ca #+# #+# */
|
|
||||||
/* Updated: 2023/02/21 09:57:55 by fgras-ca ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
int ft_atoi(const char *nptr)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
int sign;
|
|
||||||
int res;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
sign = 1;
|
|
||||||
res = 0;
|
|
||||||
while (nptr[i] == 32 || (nptr[i] >= 9 && nptr[i] <= 13))
|
|
||||||
i++;
|
|
||||||
if (nptr[i] == '-' || nptr[i] == '+')
|
|
||||||
{
|
|
||||||
if (nptr[i] == '-')
|
|
||||||
sign = - (1);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
while (nptr[i] >= 48 && nptr[i] <= 57)
|
|
||||||
{
|
|
||||||
res = res * 10 + nptr[i] - 48;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return (res * sign);
|
|
||||||
}
|
|
||||||
BIN
libft/ft_atoi.o
BIN
libft/ft_atoi.o
Binary file not shown.
@ -1,25 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_bzero.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/02/04 11:37:30 by fgras-ca #+# #+# */
|
|
||||||
/* Updated: 2023/02/20 16:07:19 by fgras-ca ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void ft_bzero(void *ptr, size_t len)
|
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
while (i < len)
|
|
||||||
{
|
|
||||||
*(char *)(ptr + i) = 0;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
BIN
libft/ft_bzero.o
BIN
libft/ft_bzero.o
Binary file not shown.
@ -1,28 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_calloc.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/02/11 17:47:38 by fgras-ca #+# #+# */
|
|
||||||
/* Updated: 2023/02/21 10:45:58 by fgras-ca ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void *ft_calloc(size_t nmemb, size_t size)
|
|
||||||
{
|
|
||||||
void *ptr;
|
|
||||||
|
|
||||||
if (!nmemb || !size)
|
|
||||||
return (malloc(0));
|
|
||||||
if ((nmemb * size) / size != nmemb)
|
|
||||||
return (NULL);
|
|
||||||
ptr = malloc(size * nmemb);
|
|
||||||
if (!ptr)
|
|
||||||
return (0);
|
|
||||||
ft_bzero(ptr, size * nmemb);
|
|
||||||
return (ptr);
|
|
||||||
}
|
|
||||||
Binary file not shown.
@ -1,21 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_isalnum.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/02/01 16:21:11 by fgras-ca #+# #+# */
|
|
||||||
/* Updated: 2023/02/01 16:24:23 by fgras-ca ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
int ft_isalnum(int c)
|
|
||||||
{
|
|
||||||
if ((c >= 65 && c <= 90) || (c >= 97 && c <= 122) || (c >= 48 && c <= 57))
|
|
||||||
return (1);
|
|
||||||
else
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
Binary file not shown.
@ -1,21 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_isalpha.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/02/01 13:36:34 by fgras-ca #+# #+# */
|
|
||||||
/* Updated: 2023/02/01 13:58:21 by fgras-ca ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
int ft_isalpha(int c)
|
|
||||||
{
|
|
||||||
if ((c >= 65 && c <= 90) || (c >= 97 && c <= 122))
|
|
||||||
return (1);
|
|
||||||
else
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
Binary file not shown.
@ -1,20 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_isascii.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/02/01 16:40:31 by fgras-ca #+# #+# */
|
|
||||||
/* Updated: 2023/11/14 17:07:04 by fgras-ca ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
int ft_isascii(int c)
|
|
||||||
{
|
|
||||||
if (c >= 0 && c <= 127)
|
|
||||||
return (1);
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
Binary file not shown.
@ -1,21 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_isdigit.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/02/01 14:46:59 by fgras-ca #+# #+# */
|
|
||||||
/* Updated: 2023/02/01 15:55:00 by fgras-ca ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
int ft_isdigit(int c)
|
|
||||||
{
|
|
||||||
if (c >= 48 && c <= 57)
|
|
||||||
return (1);
|
|
||||||
else
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
Binary file not shown.
@ -1,20 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_isprint.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/02/03 12:43:03 by fgras-ca #+# #+# */
|
|
||||||
/* Updated: 2023/02/03 13:25:31 by fgras-ca ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
int ft_isprint(int c)
|
|
||||||
{
|
|
||||||
if (c >= 32 && c <= 126)
|
|
||||||
return (1);
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
Binary file not shown.
@ -1,56 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_itoa.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/02/17 15:53:35 by fgras-ca #+# #+# */
|
|
||||||
/* Updated: 2023/02/21 10:21:07 by fgras-ca ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
static size_t ft_len_nb(int nb)
|
|
||||||
{
|
|
||||||
int len;
|
|
||||||
|
|
||||||
len = 0;
|
|
||||||
if (nb <= 0)
|
|
||||||
len++;
|
|
||||||
while (nb)
|
|
||||||
{
|
|
||||||
len++;
|
|
||||||
nb = nb / 10;
|
|
||||||
}
|
|
||||||
return (len);
|
|
||||||
}
|
|
||||||
|
|
||||||
char *ft_itoa(int n)
|
|
||||||
{
|
|
||||||
int len;
|
|
||||||
char *str;
|
|
||||||
long nb;
|
|
||||||
|
|
||||||
len = ft_len_nb(n);
|
|
||||||
nb = n;
|
|
||||||
str = malloc(sizeof(char) * len +1);
|
|
||||||
if (!str)
|
|
||||||
return (0);
|
|
||||||
if (nb < 0)
|
|
||||||
{
|
|
||||||
str[0] = '-';
|
|
||||||
nb = -nb;
|
|
||||||
}
|
|
||||||
if (nb == 0)
|
|
||||||
str[0] = '0';
|
|
||||||
str[len--] = '\0';
|
|
||||||
while (nb)
|
|
||||||
{
|
|
||||||
str[len] = nb % 10 + '0';
|
|
||||||
len--;
|
|
||||||
nb = nb / 10;
|
|
||||||
}
|
|
||||||
return (str);
|
|
||||||
}
|
|
||||||
BIN
libft/ft_itoa.o
BIN
libft/ft_itoa.o
Binary file not shown.
@ -1,29 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_lstadd_back.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/02/23 18:08:00 by fgras-ca #+# #+# */
|
|
||||||
/* Updated: 2023/02/23 18:15:14 by fgras-ca ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void ft_lstadd_back(t_list **lst, t_list *new)
|
|
||||||
{
|
|
||||||
t_list *temp;
|
|
||||||
|
|
||||||
if (new && lst)
|
|
||||||
{
|
|
||||||
if (*lst)
|
|
||||||
{
|
|
||||||
temp = ft_lstlast(*lst);
|
|
||||||
temp->next = new;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
*lst = new;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,22 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_lstadd_front.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/02/22 18:06:54 by fgras-ca #+# #+# */
|
|
||||||
/* Updated: 2023/11/14 17:06:52 by fgras-ca ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void ft_lstadd_front(t_list **lst, t_list *new)
|
|
||||||
{
|
|
||||||
if (new)
|
|
||||||
{
|
|
||||||
new->next = *lst;
|
|
||||||
*lst = new;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,25 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_lstclear.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/02/23 18:19:42 by fgras-ca #+# #+# */
|
|
||||||
/* Updated: 2023/02/23 18:22:17 by fgras-ca ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void ft_lstclear(t_list **lst, void (*del)(void*))
|
|
||||||
{
|
|
||||||
t_list *temp;
|
|
||||||
|
|
||||||
while (*lst && lst)
|
|
||||||
{
|
|
||||||
temp = (*lst)->next;
|
|
||||||
ft_lstdelone(*lst, (*del));
|
|
||||||
*lst = temp;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,21 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_lstdelone.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/02/23 18:17:06 by fgras-ca #+# #+# */
|
|
||||||
/* Updated: 2023/02/23 18:33:01 by fgras-ca ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void ft_lstdelone(t_list *lst, void (*del)(void*))
|
|
||||||
{
|
|
||||||
if (!lst || !del)
|
|
||||||
return ;
|
|
||||||
del(lst->content);
|
|
||||||
free(lst);
|
|
||||||
}
|
|
||||||
@ -1,24 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_lstiter.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/02/23 18:22:52 by fgras-ca #+# #+# */
|
|
||||||
/* Updated: 2023/02/23 18:24:51 by fgras-ca ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void ft_lstiter(t_list *lst, void (*f)(void *))
|
|
||||||
{
|
|
||||||
if (!lst || !f)
|
|
||||||
return ;
|
|
||||||
while (lst)
|
|
||||||
{
|
|
||||||
f(lst->content);
|
|
||||||
lst = lst->next;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,24 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_lstlast.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/02/23 17:48:29 by fgras-ca #+# #+# */
|
|
||||||
/* Updated: 2023/02/23 18:02:44 by fgras-ca ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
t_list *ft_lstlast(t_list *lst)
|
|
||||||
{
|
|
||||||
while (lst)
|
|
||||||
{
|
|
||||||
if (lst->next == NULL)
|
|
||||||
return (lst);
|
|
||||||
lst = lst->next;
|
|
||||||
}
|
|
||||||
return (lst);
|
|
||||||
}
|
|
||||||
@ -1,35 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_lstmap.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/02/23 18:25:24 by fgras-ca #+# #+# */
|
|
||||||
/* Updated: 2023/02/23 18:29:44 by fgras-ca ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *))
|
|
||||||
{
|
|
||||||
t_list *tmp;
|
|
||||||
t_list *res;
|
|
||||||
|
|
||||||
if (!lst || !f)
|
|
||||||
return (NULL);
|
|
||||||
res = 0;
|
|
||||||
while (lst)
|
|
||||||
{
|
|
||||||
tmp = ft_lstnew((*f)(lst->content));
|
|
||||||
if (!tmp)
|
|
||||||
{
|
|
||||||
ft_lstclear(&res, del);
|
|
||||||
return (NULL);
|
|
||||||
}
|
|
||||||
ft_lstadd_back(&res, tmp);
|
|
||||||
lst = lst->next;
|
|
||||||
}
|
|
||||||
return (res);
|
|
||||||
}
|
|
||||||
@ -1,25 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_lstnew.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/02/22 17:09:25 by fgras-ca #+# #+# */
|
|
||||||
/* Updated: 2023/11/14 17:06:38 by fgras-ca ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
t_list *ft_lstnew(void *content)
|
|
||||||
{
|
|
||||||
t_list *new;
|
|
||||||
|
|
||||||
new = malloc(sizeof(t_list));
|
|
||||||
if (!new)
|
|
||||||
return (0);
|
|
||||||
new->content = content;
|
|
||||||
new->next = 0;
|
|
||||||
return (new);
|
|
||||||
}
|
|
||||||
@ -1,28 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_lstsize.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/02/23 17:17:36 by fgras-ca #+# #+# */
|
|
||||||
/* Updated: 2023/11/14 17:06:24 by fgras-ca ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
int ft_lstsize(t_list *lst)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
t_list *tmp;
|
|
||||||
|
|
||||||
tmp = lst;
|
|
||||||
i = 0;
|
|
||||||
while (tmp)
|
|
||||||
{
|
|
||||||
tmp = tmp->next;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return (i);
|
|
||||||
}
|
|
||||||
@ -1,27 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_memchr.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/02/10 13:42:10 by fgras-ca #+# #+# */
|
|
||||||
/* Updated: 2023/02/14 13:03:28 by fgras-ca ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void *ft_memchr(const void *s, int c, size_t n)
|
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
while (i < n)
|
|
||||||
{
|
|
||||||
if (((unsigned char *)s)[i] == (unsigned char)c)
|
|
||||||
return ((void *)(s + i));
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
Binary file not shown.
@ -1,27 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_memcmp.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/02/10 14:45:56 by fgras-ca #+# #+# */
|
|
||||||
/* Updated: 2023/11/14 17:18:05 by fgras-ca ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
int ft_memcmp(const void *s1, const void *s2, size_t n)
|
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
while (i < n)
|
|
||||||
{
|
|
||||||
if (((unsigned char *)s1)[i] != ((unsigned char *)s2)[i])
|
|
||||||
return (((unsigned char *)s1)[i] - ((unsigned char *)s2)[i]);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
Binary file not shown.
@ -1,32 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_memcpy.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/02/04 14:43:15 by fgras-ca #+# #+# */
|
|
||||||
/* Updated: 2023/02/20 16:13:43 by fgras-ca ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void *ft_memcpy(void *dest, const void *src, size_t n)
|
|
||||||
{
|
|
||||||
char *destmov;
|
|
||||||
char *srcmov;
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
destmov = (char *)dest;
|
|
||||||
srcmov = (char *)src;
|
|
||||||
if (!dest && !src)
|
|
||||||
return (0);
|
|
||||||
i = 0;
|
|
||||||
while (i < n)
|
|
||||||
{
|
|
||||||
destmov[i] = srcmov[i];
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return (dest);
|
|
||||||
}
|
|
||||||
Binary file not shown.
@ -1,42 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_memmove.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/02/07 11:11:49 by fgras-ca #+# #+# */
|
|
||||||
/* Updated: 2023/02/07 16:04:25 by fgras-ca ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void *ft_memmove(void *dest, const void *src, size_t n)
|
|
||||||
{
|
|
||||||
char *destmov;
|
|
||||||
char *srcmov;
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
if (!dest && !src)
|
|
||||||
return (0);
|
|
||||||
destmov = (char *)dest;
|
|
||||||
srcmov = (char *)src;
|
|
||||||
i = 0;
|
|
||||||
if (destmov > srcmov)
|
|
||||||
{
|
|
||||||
while (n--)
|
|
||||||
{
|
|
||||||
destmov[n] = srcmov[n];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
while (n--)
|
|
||||||
{
|
|
||||||
destmov[i] = srcmov[i];
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return (destmov);
|
|
||||||
}
|
|
||||||
Binary file not shown.
@ -1,26 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_memset.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/02/03 15:49:51 by fgras-ca #+# #+# */
|
|
||||||
/* Updated: 2023/11/14 17:07:29 by fgras-ca ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void *ft_memset(void *s, int c, size_t n)
|
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
while (i < n)
|
|
||||||
{
|
|
||||||
*(unsigned char *)(s + i) = (unsigned char)c;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return (s);
|
|
||||||
}
|
|
||||||
Binary file not shown.
@ -1,18 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_putchar_fd.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/02/15 11:23:07 by fgras-ca #+# #+# */
|
|
||||||
/* Updated: 2023/02/15 11:30:37 by fgras-ca ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void ft_putchar_fd(char c, int fd)
|
|
||||||
{
|
|
||||||
write(fd, &c, 1);
|
|
||||||
}
|
|
||||||
Binary file not shown.
@ -1,28 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_putendl_fd.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/02/15 13:33:49 by fgras-ca #+# #+# */
|
|
||||||
/* Updated: 2023/02/21 10:19:05 by fgras-ca ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void ft_putendl_fd(char *s, int fd)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
if (!s)
|
|
||||||
return ;
|
|
||||||
while (s[i])
|
|
||||||
{
|
|
||||||
write(fd, &s[i], 1);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
write(fd, "\n", 1);
|
|
||||||
}
|
|
||||||
Binary file not shown.
@ -1,36 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_putnbr_fd.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/02/15 13:53:25 by fgras-ca #+# #+# */
|
|
||||||
/* Updated: 2023/02/15 14:00:06 by fgras-ca ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void ft_putnbr_fd(int n, int fd)
|
|
||||||
{
|
|
||||||
if (n == -2147483648)
|
|
||||||
{
|
|
||||||
write(fd, "-2147483648", 11);
|
|
||||||
}
|
|
||||||
else if (n >= 0 && n < 10)
|
|
||||||
{
|
|
||||||
n += 48;
|
|
||||||
ft_putchar_fd(n, fd);
|
|
||||||
}
|
|
||||||
else if (n < 0)
|
|
||||||
{
|
|
||||||
ft_putchar_fd('-', fd);
|
|
||||||
ft_putnbr_fd((n * (-1)), fd);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ft_putnbr_fd(n / 10, fd);
|
|
||||||
ft_putnbr_fd(n % 10, fd);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Binary file not shown.
@ -1,27 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_putstr_fd.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/02/15 12:29:14 by fgras-ca #+# #+# */
|
|
||||||
/* Updated: 2023/02/15 19:02:37 by fgras-ca ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void ft_putstr_fd(char *s, int fd)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
if (!s || !fd)
|
|
||||||
return ;
|
|
||||||
while (s[i])
|
|
||||||
{
|
|
||||||
write(fd, &s[i], 1);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Binary file not shown.
@ -1,35 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_realloc.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/11/15 16:31:35 by fgras-ca #+# #+# */
|
|
||||||
/* Updated: 2023/12/10 13:59:12 by fgras-ca ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void *ft_realloc(void *ptr, size_t newsize, size_t oldsize)
|
|
||||||
{
|
|
||||||
char *newptr;
|
|
||||||
|
|
||||||
if (ptr == NULL)
|
|
||||||
{
|
|
||||||
return (malloc(newsize));
|
|
||||||
}
|
|
||||||
if (newsize <= oldsize)
|
|
||||||
{
|
|
||||||
return (ptr);
|
|
||||||
}
|
|
||||||
newptr = malloc(newsize);
|
|
||||||
if (newptr == NULL)
|
|
||||||
{
|
|
||||||
return (NULL);
|
|
||||||
}
|
|
||||||
ft_memcpy(newptr, ptr, oldsize);
|
|
||||||
free(ptr);
|
|
||||||
return (newptr);
|
|
||||||
}
|
|
||||||
Binary file not shown.
@ -1,32 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_reallocarray.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/11/15 15:52:29 by fgras-ca #+# #+# */
|
|
||||||
/* Updated: 2023/12/07 11:46:15 by fgras-ca ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
static size_t get_mul_no_overflow(void)
|
|
||||||
{
|
|
||||||
return ((size_t)1 << (sizeof(size_t) * 4));
|
|
||||||
}
|
|
||||||
|
|
||||||
void *ft_reallocarray(void *optr, size_t nmemb, size_t size, size_t oldsize)
|
|
||||||
{
|
|
||||||
size_t mul_no_overflow;
|
|
||||||
|
|
||||||
mul_no_overflow = get_mul_no_overflow();
|
|
||||||
if ((nmemb >= mul_no_overflow || size >= mul_no_overflow)
|
|
||||||
&& nmemb > 0 && SIZE_MAX / nmemb < size)
|
|
||||||
{
|
|
||||||
errno = ENOMEM;
|
|
||||||
return (NULL);
|
|
||||||
}
|
|
||||||
return (ft_realloc(optr, nmemb * size, oldsize));
|
|
||||||
}
|
|
||||||
Binary file not shown.
@ -1,32 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_strcat.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/11/21 19:20:36 by fgras-ca #+# #+# */
|
|
||||||
/* Updated: 2023/11/21 19:28:29 by fgras-ca ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
char *ft_strcat(char *dest, const char *src)
|
|
||||||
{
|
|
||||||
char *save;
|
|
||||||
|
|
||||||
save = dest;
|
|
||||||
while (*dest)
|
|
||||||
{
|
|
||||||
dest++;
|
|
||||||
}
|
|
||||||
while (*src)
|
|
||||||
{
|
|
||||||
*dest = *src;
|
|
||||||
dest++;
|
|
||||||
src++;
|
|
||||||
}
|
|
||||||
*dest = '\0';
|
|
||||||
return (save);
|
|
||||||
}
|
|
||||||
Binary file not shown.
@ -1,32 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_strchr.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/02/09 14:27:10 by fgras-ca #+# #+# */
|
|
||||||
/* Updated: 2023/02/21 10:54:39 by fgras-ca ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
char *ft_strchr(const char *s, int c)
|
|
||||||
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
char *str;
|
|
||||||
|
|
||||||
str = (char *)s;
|
|
||||||
i = 0;
|
|
||||||
while (str[i])
|
|
||||||
{
|
|
||||||
if (str[i] == (char)c)
|
|
||||||
return (&str[i]);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
if (str[i] == (char)c)
|
|
||||||
return (&str[i]);
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
Binary file not shown.
@ -1,23 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_strcmp.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/11/14 16:57:42 by fgras-ca #+# #+# */
|
|
||||||
/* Updated: 2023/11/14 17:10:27 by fgras-ca ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
int ft_strcmp(const char *s1, const char *s2)
|
|
||||||
{
|
|
||||||
while (*s1 && (*s1 == *s2))
|
|
||||||
{
|
|
||||||
s1++;
|
|
||||||
s2++;
|
|
||||||
}
|
|
||||||
return (*(const unsigned char *)s1 - *(const unsigned char *)s2);
|
|
||||||
}
|
|
||||||
Binary file not shown.
@ -1,28 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_strcpy.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/11/21 19:23:08 by fgras-ca #+# #+# */
|
|
||||||
/* Updated: 2023/11/21 19:26:36 by fgras-ca ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
char *ft_strcpy(char *dest, const char *src)
|
|
||||||
{
|
|
||||||
char *save;
|
|
||||||
|
|
||||||
save = dest;
|
|
||||||
while (*src)
|
|
||||||
{
|
|
||||||
*dest = *src;
|
|
||||||
dest++;
|
|
||||||
src++;
|
|
||||||
}
|
|
||||||
*dest = '\0';
|
|
||||||
return (save);
|
|
||||||
}
|
|
||||||
Binary file not shown.
@ -1,25 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_striteri.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/02/16 14:25:00 by fgras-ca #+# #+# */
|
|
||||||
/* Updated: 2023/11/14 17:08:02 by fgras-ca ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
void ft_striteri(char *s, void (*f)(unsigned int, char*))
|
|
||||||
{
|
|
||||||
unsigned int i;
|
|
||||||
|
|
||||||
if (!s)
|
|
||||||
return ;
|
|
||||||
i = 0;
|
|
||||||
while (s[i])
|
|
||||||
{
|
|
||||||
f(i, &s[i]);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Binary file not shown.
@ -1,33 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_strlcat.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/02/08 14:10:58 by fgras-ca #+# #+# */
|
|
||||||
/* Updated: 2023/11/14 17:09:41 by fgras-ca ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
size_t ft_strlcat(char *dst, const char *src, size_t size)
|
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
size_t dst_len;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
if (!dst && !size)
|
|
||||||
return (0);
|
|
||||||
dst_len = ft_strlen(dst);
|
|
||||||
if (size <= dst_len)
|
|
||||||
return (size + ft_strlen(src));
|
|
||||||
while (src[i] && i < size - dst_len -1)
|
|
||||||
{
|
|
||||||
dst[dst_len + i] = src[i];
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
dst[dst_len + i] = 0;
|
|
||||||
return (dst_len + ft_strlen(src));
|
|
||||||
}
|
|
||||||
Binary file not shown.
@ -1,32 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_strlcpy.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/02/08 13:24:31 by fgras-ca #+# #+# */
|
|
||||||
/* Updated: 2023/02/08 13:33:32 by fgras-ca ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
size_t ft_strlcpy(char *dst, const char *src, size_t size)
|
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
if (size > 0)
|
|
||||||
{
|
|
||||||
while (src[i] && i < (size - 1))
|
|
||||||
{
|
|
||||||
dst[i] = src[i];
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
dst[i] = 0;
|
|
||||||
}
|
|
||||||
while (src[i])
|
|
||||||
i++;
|
|
||||||
return (i);
|
|
||||||
}
|
|
||||||
Binary file not shown.
@ -1,33 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_strmapi.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/02/16 13:38:52 by fgras-ca #+# #+# */
|
|
||||||
/* Updated: 2023/11/14 17:04:43 by fgras-ca ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
char *ft_strmapi(const char *s, char (*f)(unsigned int, char))
|
|
||||||
{
|
|
||||||
char *result;
|
|
||||||
unsigned int i;
|
|
||||||
|
|
||||||
if (!s)
|
|
||||||
return (0);
|
|
||||||
result = malloc(sizeof(char) * (ft_strlen(s) + 1));
|
|
||||||
if (!result)
|
|
||||||
return (0);
|
|
||||||
i = 0;
|
|
||||||
while (s[i])
|
|
||||||
{
|
|
||||||
result[i] = f(i, s[i]);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
result[i] = 0;
|
|
||||||
return (result);
|
|
||||||
}
|
|
||||||
Binary file not shown.
@ -1,29 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_strncmp.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/02/09 17:12:38 by fgras-ca #+# #+# */
|
|
||||||
/* Updated: 2023/02/14 13:26:15 by fgras-ca ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
int ft_strncmp(const char *s1, const char *s2, size_t n)
|
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
if (n == 0)
|
|
||||||
{
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
while (s1[i] == s2[i] && (s1[i] != '\0' || s2[i] != '\0') && i < (n - 1))
|
|
||||||
{
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return ((unsigned char)s1[i] - (unsigned char)s2[i]);
|
|
||||||
}
|
|
||||||
Binary file not shown.
@ -1,31 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_strncpy.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/11/27 20:03:19 by fgras-ca #+# #+# */
|
|
||||||
/* Updated: 2023/12/07 11:56:51 by fgras-ca ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
char *ft_strncpy(char *dest, char *src, unsigned int n)
|
|
||||||
{
|
|
||||||
unsigned int i;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
while (src[i] != '\0' && i < n)
|
|
||||||
{
|
|
||||||
dest[i] = src[i];
|
|
||||||
++i;
|
|
||||||
}
|
|
||||||
while (i < n)
|
|
||||||
{
|
|
||||||
dest[i] = '\0';
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return (dest);
|
|
||||||
}
|
|
||||||
Binary file not shown.
@ -1,41 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_strnstr.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/02/11 14:31:40 by fgras-ca #+# #+# */
|
|
||||||
/* Updated: 2023/02/21 10:08:36 by fgras-ca ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
char *ft_strnstr(const char *haystack, const char *needle, size_t len)
|
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
size_t j;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
if (needle == haystack)
|
|
||||||
return ((char *)haystack);
|
|
||||||
if (!len && !haystack)
|
|
||||||
return (0);
|
|
||||||
while (haystack[i] != '\0')
|
|
||||||
{
|
|
||||||
j = 0;
|
|
||||||
while (haystack[i + j] == needle[j] && (i + j) < len)
|
|
||||||
{
|
|
||||||
if (haystack[i + j] == '\0' && needle[j] == '\0')
|
|
||||||
{
|
|
||||||
return ((char *)&haystack[j]);
|
|
||||||
}
|
|
||||||
j++;
|
|
||||||
}
|
|
||||||
if (needle[j] == '\0')
|
|
||||||
return ((char *)(haystack + i));
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return (NULL);
|
|
||||||
}
|
|
||||||
Binary file not shown.
@ -1,29 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_strrchr.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/02/09 16:10:11 by fgras-ca #+# #+# */
|
|
||||||
/* Updated: 2023/02/14 15:36:23 by fgras-ca ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
char *ft_strrchr(const char *s, int c)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
while (s[i])
|
|
||||||
i++;
|
|
||||||
while (i >= 0)
|
|
||||||
{
|
|
||||||
if (s[i] == (char)c)
|
|
||||||
return ((char *)(s + i));
|
|
||||||
i--;
|
|
||||||
}
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
Binary file not shown.
@ -1,42 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_strstr.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/11/14 20:54:44 by fgras-ca #+# #+# */
|
|
||||||
/* Updated: 2023/11/14 21:08:57 by fgras-ca ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
char *ft_strstr(const char *haystack, const char *needle)
|
|
||||||
{
|
|
||||||
const char *p;
|
|
||||||
const char *beginning;
|
|
||||||
const char *n;
|
|
||||||
|
|
||||||
p = haystack;
|
|
||||||
if (*needle == '\0')
|
|
||||||
return ((char *)haystack);
|
|
||||||
while (*p != '\0')
|
|
||||||
{
|
|
||||||
if (*p == *needle)
|
|
||||||
{
|
|
||||||
beginning = p;
|
|
||||||
n = needle;
|
|
||||||
while (*p == *n && *n != '\0' && *p != '\0')
|
|
||||||
{
|
|
||||||
p++;
|
|
||||||
n++;
|
|
||||||
}
|
|
||||||
if (*n == '\0')
|
|
||||||
return ((char *)beginning);
|
|
||||||
p = beginning;
|
|
||||||
}
|
|
||||||
p++;
|
|
||||||
}
|
|
||||||
return (NULL);
|
|
||||||
}
|
|
||||||
Binary file not shown.
@ -1,83 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_strtok.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/11/14 17:14:45 by fgras-ca #+# #+# */
|
|
||||||
/* Updated: 2023/12/07 11:41:34 by fgras-ca ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
static char *init_str_and_lasts(char **lasts, char *str)
|
|
||||||
{
|
|
||||||
if (str == NULL)
|
|
||||||
{
|
|
||||||
str = *lasts;
|
|
||||||
if (str == NULL)
|
|
||||||
return (NULL);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
*lasts = str;
|
|
||||||
}
|
|
||||||
return (str);
|
|
||||||
}
|
|
||||||
|
|
||||||
static char *find_token_start(char **lasts, const char *delim)
|
|
||||||
{
|
|
||||||
int ch;
|
|
||||||
|
|
||||||
ch = **lasts;
|
|
||||||
while (ch != '\0' && ft_strchr(delim, ch) != NULL)
|
|
||||||
{
|
|
||||||
(*lasts)++;
|
|
||||||
ch = **lasts;
|
|
||||||
}
|
|
||||||
if (**lasts == '\0')
|
|
||||||
{
|
|
||||||
*lasts = NULL;
|
|
||||||
return (NULL);
|
|
||||||
}
|
|
||||||
return (*lasts);
|
|
||||||
}
|
|
||||||
|
|
||||||
static char *find_token_end(char **lasts, const char *delim)
|
|
||||||
{
|
|
||||||
int ch;
|
|
||||||
char *str;
|
|
||||||
|
|
||||||
str = *lasts;
|
|
||||||
ch = **lasts;
|
|
||||||
while (ch != '\0' && ft_strchr(delim, ch) == NULL)
|
|
||||||
{
|
|
||||||
(*lasts)++;
|
|
||||||
ch = **lasts;
|
|
||||||
}
|
|
||||||
if (**lasts != '\0')
|
|
||||||
{
|
|
||||||
**lasts = '\0';
|
|
||||||
(*lasts)++;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
*lasts = NULL;
|
|
||||||
}
|
|
||||||
return (str);
|
|
||||||
}
|
|
||||||
|
|
||||||
char *ft_strtok(char *str, const char *delim)
|
|
||||||
{
|
|
||||||
static char *lasts;
|
|
||||||
|
|
||||||
str = init_str_and_lasts(&lasts, str);
|
|
||||||
if (str == NULL)
|
|
||||||
return (NULL);
|
|
||||||
str = find_token_start(&lasts, delim);
|
|
||||||
if (str == NULL)
|
|
||||||
return (NULL);
|
|
||||||
return (find_token_end(&lasts, delim));
|
|
||||||
}
|
|
||||||
Binary file not shown.
@ -1,115 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_strtol.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/12/01 14:00:32 by fgras-ca #+# #+# */
|
|
||||||
/* Updated: 2023/12/07 11:56:12 by fgras-ca ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
static int skip_whitespaces_and_sign(const char *str, int *sign)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
while (str[i] == ' ' || (str[i] >= '\t' && str[i] <= '\r'))
|
|
||||||
i++;
|
|
||||||
if (str[i] == '+' || str[i] == '-')
|
|
||||||
{
|
|
||||||
if (str[i] == '-')
|
|
||||||
*sign = -1;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return (i);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int determine_base(const char *str, int *base, int index)
|
|
||||||
{
|
|
||||||
if ((*base == 0 || *base == 16) && str[index] == '0'
|
|
||||||
&& (str[index + 1] == 'x' || str[index + 1] == 'X'))
|
|
||||||
{
|
|
||||||
*base = 16;
|
|
||||||
index += 2;
|
|
||||||
}
|
|
||||||
else if (*base == 0)
|
|
||||||
{
|
|
||||||
if (str[index] == '0')
|
|
||||||
*base = 8;
|
|
||||||
else
|
|
||||||
*base = 10;
|
|
||||||
}
|
|
||||||
return (index);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int check_base(const char *str, int *base, int *sign)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
*sign = 1;
|
|
||||||
i = skip_whitespaces_and_sign(str, sign);
|
|
||||||
i = determine_base(str, base, i);
|
|
||||||
return (i);
|
|
||||||
}
|
|
||||||
|
|
||||||
static long convert_strtol(const char *str, int base, int sign)
|
|
||||||
{
|
|
||||||
long result;
|
|
||||||
int digit;
|
|
||||||
|
|
||||||
result = 0;
|
|
||||||
while (*str)
|
|
||||||
{
|
|
||||||
digit = 0;
|
|
||||||
if (*str >= '0' && *str <= '9')
|
|
||||||
digit = *str - '0';
|
|
||||||
else if (*str >= 'A' && *str <= 'Z')
|
|
||||||
digit = *str - 'A' + 10;
|
|
||||||
else if (*str >= 'a' && *str <= 'z')
|
|
||||||
digit = *str - 'a' + 10;
|
|
||||||
else
|
|
||||||
break ;
|
|
||||||
if (digit >= base)
|
|
||||||
break ;
|
|
||||||
if (sign > 0 && result > (LONG_MAX - digit) / base)
|
|
||||||
return (errno = ERANGE, LONG_MAX);
|
|
||||||
if (sign < 0 && result < (LONG_MIN + digit) / base)
|
|
||||||
return (errno = ERANGE, LONG_MIN);
|
|
||||||
result = result * base + digit;
|
|
||||||
str++;
|
|
||||||
}
|
|
||||||
return (result * sign);
|
|
||||||
}
|
|
||||||
|
|
||||||
long ft_strtol(const char *str, char **endptr, int base)
|
|
||||||
{
|
|
||||||
int sign;
|
|
||||||
int i;
|
|
||||||
long result;
|
|
||||||
|
|
||||||
if (base < 0 || base == 1 || base > 36)
|
|
||||||
{
|
|
||||||
if (endptr)
|
|
||||||
*endptr = (char *)str;
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
i = check_base(str, &base, &sign);
|
|
||||||
result = convert_strtol(str + i, base, sign);
|
|
||||||
if (endptr)
|
|
||||||
*endptr = (char *)(str + i);
|
|
||||||
while (*str)
|
|
||||||
{
|
|
||||||
if ((*str >= '0' && *str <= '9' && *str - '0' < base)
|
|
||||||
|| (*str >= 'A' && *str <= 'Z' && *str - 'A' + 10 < base)
|
|
||||||
|| (*str >= 'a' && *str <= 'z' && *str - 'a' + 10 < base))
|
|
||||||
*endptr = (char *)(str + 1);
|
|
||||||
else
|
|
||||||
break ;
|
|
||||||
str++;
|
|
||||||
}
|
|
||||||
return (result);
|
|
||||||
}
|
|
||||||
Binary file not shown.
@ -1,52 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_strtrim.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/02/14 16:30:26 by fgras-ca #+# #+# */
|
|
||||||
/* Updated: 2023/03/13 14:12:41 by fgras-ca ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
static int char_in_set(char c, char const *set)
|
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
while (set[i])
|
|
||||||
{
|
|
||||||
if (set[i] == c)
|
|
||||||
return (1);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
char *ft_strtrim(char const *s1, char const *set)
|
|
||||||
{
|
|
||||||
char *str;
|
|
||||||
size_t i;
|
|
||||||
size_t start;
|
|
||||||
size_t end;
|
|
||||||
|
|
||||||
if (!s1)
|
|
||||||
return (0);
|
|
||||||
start = 0;
|
|
||||||
while (s1[start] && char_in_set(s1[start], set))
|
|
||||||
start++;
|
|
||||||
end = ft_strlen(s1);
|
|
||||||
while (end > start && char_in_set(s1[end - 1], set))
|
|
||||||
end--;
|
|
||||||
str = (char *)malloc(sizeof(*s1) * (end - start + 1));
|
|
||||||
if (!str)
|
|
||||||
return (0);
|
|
||||||
i = 0;
|
|
||||||
while (start < end)
|
|
||||||
str[i++] = s1[start++];
|
|
||||||
str[i] = 0;
|
|
||||||
return (str);
|
|
||||||
}
|
|
||||||
Binary file not shown.
@ -1,37 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_substr.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/02/13 15:40:49 by fgras-ca #+# #+# */
|
|
||||||
/* Updated: 2023/11/14 17:07:20 by fgras-ca ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
char *ft_substr(char const *s, unsigned int start, size_t len)
|
|
||||||
{
|
|
||||||
char *new_s;
|
|
||||||
size_t i;
|
|
||||||
size_t j;
|
|
||||||
|
|
||||||
new_s = (char *)malloc(sizeof(char) * (len + 1));
|
|
||||||
if (!s || !new_s)
|
|
||||||
return (NULL);
|
|
||||||
i = 0;
|
|
||||||
j = 0;
|
|
||||||
while (s[i])
|
|
||||||
{
|
|
||||||
if (i >= start && j < len)
|
|
||||||
{
|
|
||||||
new_s[j] = s[i];
|
|
||||||
j++;
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
new_s[j] = '\0';
|
|
||||||
return (new_s);
|
|
||||||
}
|
|
||||||
Binary file not shown.
@ -1,20 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_tolower.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/02/09 14:09:59 by fgras-ca #+# #+# */
|
|
||||||
/* Updated: 2023/02/14 13:36:02 by fgras-ca ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
int ft_tolower(int c)
|
|
||||||
{
|
|
||||||
if (c >= 65 && c <= 90)
|
|
||||||
c += 32;
|
|
||||||
return (c);
|
|
||||||
}
|
|
||||||
Binary file not shown.
@ -1,20 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_toupper.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/02/08 16:02:00 by fgras-ca #+# #+# */
|
|
||||||
/* Updated: 2023/02/14 13:36:40 by fgras-ca ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
int ft_toupper(int c)
|
|
||||||
{
|
|
||||||
if (c >= 97 && c <= 122)
|
|
||||||
c -= 32;
|
|
||||||
return (c);
|
|
||||||
}
|
|
||||||
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user