This commit is contained in:
Ladebeze66 2024-01-15 22:48:47 +01:00
parent b1d117f94e
commit 5ad918c85c
872 changed files with 128224 additions and 0 deletions

98
versionmod/Makefile Normal file
View File

@ -0,0 +1,98 @@
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2024/01/14 16:54:48 by fgras-ca #+# #+# #
# Updated: 2024/01/15 22:11:49 by fgras-ca ### ########.fr #
# #
# **************************************************************************** #
LOGO = @echo "🅹🅾🅷🅽 🅰🅽🅳 🅻🅰🅳🅴🅱🅴🆉🅴"
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 = cub3d
LIBFT = libft.a
SRC = main.c \
./utils/ft_utils_gnl.c \
./utils/ft_utils_split.c \
./utils/ft_utils_convert.c \
./utils/ft_utils_str_1.c \
./parsing/ft_map_check.c \
./parsing/ft_read_map.c \
./parsing/ft_map_dimensions.c \
./parsing/ft_parsing.c \
./move/ft_collision.c \
./move/ft_key.c \
./move/ft_move.c \
./draw/ft_draw.c \
./draw/ft_background.c \
./draw/ft_2d_view.c \
./draw/ft_textures.c \
./draw/ft_3d_view.c \
./draw/ft_horizontal_ray.c \
./draw/ft_vertical_ray.c \
./draw/ft_pixel.c \
./draw/ft_ray_utils.c \
./window/ft_window.c \
./window/ft_player.c \
./window/ft_map.c \
./draw/ft_load_textures.c \
./window/ft_rescale.c \
./window/ft_refresh_window.c \
./parsing/ft_find_map_start.c \
SRC_DIR_LIBFT = libft/
SRC_LIBFT = $(addprefix $(SRC_DIR_LIBFT), $(LIBFT))
OBJ = $(SRC:.c=.o)
FLAG = cc -Wall -Wextra -Werror -g
RM = rm -f
all: $(NAME)
$(NAME): $(OBJ)
@echo "$(RED)Loading Libft...$(RST)"
@make -C libft
@echo "$(GREEN)Libft...Done. $(RST)"
@echo "$(RED)Compilation cub3D... $(RST)"
@$(FLAG) -Iinclude $(OBJ) -Llib -lmlx -lXext -lX11 -lm -o $(NAME)
@echo "$(GREEN)Compilation complete. $(ORANGE)Type "./cub3d" for execute the program!!$(RST)"
$(LOGO)
clean:
@echo "$(RED)Cleaning Libft... $(RST)"
@make -C libft clean
@echo "$(GREEN)Libft cleaned!! $(RST)"
@echo "$(RED)Deleating files objects... $(RST)"
@echo rm -f $(OBJ)
@echo "$(GREEN)files deleted!! $(RST)"
$(LOGO)
fclean: clean
@echo "$(RED)fclean Libft... $(RST)"
@make -C libft fclean
@echo "$(GREEN)Libft cleaned!! $(RST)"
@echo "$(RED)Delete program name... $(RST)"
@echo rm -f $(NAME)
@echo "$(GREEN)File program deleted!! $(RST)"
re: fclean all
.PHONY: all clean fclean re

BIN
versionmod/cub3d Executable file

Binary file not shown.

397
versionmod/cub3d.h Normal file
View File

@ -0,0 +1,397 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* cub3d.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/14 16:56:52 by fgras-ca #+# #+# */
/* Updated: 2024/01/15 22:13:17 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef CUB3D_H
# define CUB3D_H
# include <stdlib.h>
# include <stdio.h>
# include <fcntl.h>
# include <math.h>
# include <unistd.h>
# include <sys/time.h>
# include <stdbool.h>
# include <assert.h>
# include "include/mlx.h"
# include "libft/libft.h"
# ifndef BUFFER_SIZE
# define BUFFER_SIZE 100000
# endif
# define PI 3.14159265359
# define P2 PI/2
# define P3 3*PI/2
# define COLBUF 2
# define NUMRAY 1280
# define FOVIEW 60
# define DISRAY 1000000
# define DOF 120
# define WIDTH 1780
# define HEIGHT 720
# define BOV 500
# define MAX_LINE_LENGTH 1024
typedef enum {
NORTH,
SOUTH,
WEST,
EAST,
NONE // Utilisé lorsqu'aucun mur n'est touché
} WallDirection;
typedef struct s_img
{
int height;
int width;
int ground_width;
void *i;
char *addr;
int bpp;
int line_len;
int endian;
} t_img;
typedef struct s_struture_map
{
char *map;
char *buff;
char **temp_list;
int i;
int j;
int temp;
int mapX;
int mapY;
int mapS;
} t_structure_map;
typedef struct s_struture_player
{
float px;
float py;
float pdx;
float pdy;
float pa;
} t_structure_player;
typedef struct s_struture_img
{
void *img_player;
void *img_wall;
void *buffer;
char *addr;
int bpp;
int endian;
int ground_height;
int ground_width;
void *ground;
int line_len;
int bpp_bis;
int endian_bis;
int line_len_bis;
void *test[27];
void *roomadslam[10];
void *tgsway[20];
void *pedro_wall;
void *north_texture;
void *south_texture;
void *west_texture;
void *east_texture;
int texture_width;
int texture_height;
} t_structure_img;
typedef struct s_struture_windows
{
void *mlx;
void *win;
int height;
int width;
} t_structure_windows;
typedef struct s_structure_main
{
int fd;
struct timeval start_time;
struct timeval end_time;
int frame_count;
t_structure_windows s_win;
t_structure_img s_img;
t_structure_map s_map;
t_structure_player s_player;
} t_structure_main;
typedef struct s_res_params {
char *original_data;
void *rescaled_img;
char *rescaled_data;
float x_ratio;
float y_ratio;
int original_x;
int original_y;
int pixel_pos_rescaled;
int pixel_pos_original;
} t_res_params;
typedef struct s_rescale_params {
void *original_img;
int original_width;
int original_height;
int new_width;
int new_height;
int px;
int py;
t_res_params *res;
} t_rescale_params;
typedef struct s_position_params {
int *future_px;
int *future_py;
int pdx;
int pdy;
int collisionBuffer;
int px;
int py;
double pa;
char direction;
} t_position_params;
typedef struct s_map_params {
t_structure_map *map_info;
const char *buffer;
int length;
int *maxWidth;
int *height;
int *currentWidth;
int *isNewLine;
} t_map_params;
typedef struct s_square_params {
t_structure_main *w;
int x;
int y;
int xo;
int yo;
int color;
} t_square_params;
typedef struct s_sky_ground_params {
t_structure_main *w;
int startHeight;
int endHeight;
int color;
int backgroundOffsetX;
} t_sky_ground_params;
typedef struct s_line_params {
t_structure_main *w;
int x0;
int y0;
int x1;
int y1;
int color;
} t_line_params;
typedef struct s_line_deltas {
int dx;
int dy;
int sx;
int sy;
int err;
t_line_params *params;
} t_line_deltas;
typedef struct s_ray_params {
t_structure_main *w;
int r;
int tileSize;
float rx;
float ry;
float disT;
WallDirection wallDir;
int numRays;
int color;
int start3DHeight;
int max3DHeight;
float lineH;
float lineOff;
int backgroundOffsetX;
int raywidth;
} t_ray_params;
typedef struct s_texture_params {
t_structure_main *w;
int startX;
int endX;
float lineOff;
float lineH;
WallDirection wallDir;
float rx;
float ry;
float disT;
} t_texture_params;
typedef struct s_ray_calc_params {
t_structure_main *w;
float ra;
float *disRay;
float *rx;
float *ry;
WallDirection *wallDir;
float xo;
float yo;
int dof;
} t_ray_calc_params;
typedef struct s_texture_data
{
char *data;
int bpp;
int size_line;
int endian;
} t_texture_data;
typedef struct s_init_params {
t_structure_main *w;
int tilesize;
int numrays;
float FOV;
float DR;
} t_init_params;
typedef struct s_ray_properties {
float disH;
float disV;
WallDirection hwalldir;
WallDirection vwalldir;
float hx;
float hy;
float vx;
float vy;
} t_ray_properties;
typedef struct {
int tilesize;
int numrays;
float FOV;
float DR;
float ra;
} t_base_params;
typedef struct {
float disH;
float disV;
float disT;
float hx;
float hy;
float vx;
float vy;
WallDirection hwalldir;
WallDirection vwalldir;
} t_ray_state;
typedef struct {
t_structure_main *w;
int r;
int color;
} t_ray_calc;
typedef struct {
t_base_params base_params;
t_ray_state ray_state;
t_ray_calc ray_calc;
t_ray_params rayparams;
t_ray_calc_params hrayparams;
t_ray_calc_params vrayparams;
} t_drawrays2d_params;
typedef struct {
int jkl;
int yui;
} t_state;
typedef struct {
t_structure_main *w;
t_state state;
} t_global_struct;
typedef struct s_texture
{
char *north;
char *south;
char *west;
char *east;
unsigned int floor_color;
unsigned int ceil_color;
} t_texture;
//ft_utils_split.c 5 / 5
char **ft_split(char const *s, char c);
//ft_utils_gnl.c 4 / 5
char *get_next_line(int fd);
/*ft_key.c 3/5*/
int *kill_prog(t_structure_main *w);
void move(int key, t_structure_main *w);
int deal_key(int key, t_structure_main *w);
size_t ft_strlen(const char *s);
char *ft_strdup(const char *src);
char *ft_strjoin(char *left_str, char *buff);
char *ft_strchr(const char *s, int c);
/*collision*/
void calculate_future_position(t_position_params *params);
int check_collision(t_structure_main *w, int future_px, int future_py);
void calculate_future_position_right_left(t_position_params *params);
//ft_utils_convert.c 1/5
char *ft_itoa(int nb);
/*parsing*/
char *read_map(const char* filename, int* length);
int is_map_closed(char* map, int width, int height);
bool parse_map(const char *map_content, int length, t_structure_map *map_info);
int check_borders(char *map, int maxWidth, int height);
int check_interior(char *map, int maxWidth, int height);
void exit_error(t_structure_main *w);
void update_max_dimensions(t_map_params *params);
void process_character(t_map_params *params, int *i);
void get_map_dimensions(t_map_params *params);
void fill_map_space(t_structure_map *map_info, int maxWidth, int height);
void copy_map_data(t_map_params *params);
bool load_cub_file(const char *filename, t_texture *textures, t_structure_map *map_info);
/*textures*/
void load_wall_textures(t_structure_main *w);
void draw_texture(t_texture_params *tex_params);
int get_texture_color(t_structure_main *w, WallDirection wallDir, int textureX, int textureY);
/*3D view*/
void drawray(t_ray_params *ray_params);
void draw_background(t_structure_main *w);
float correctFisheye(float distance, float ra, float playerAngle);
//2D map
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_map(t_structure_main *w);
void put_pixel_img(t_structure_main *w, int x, int y, int color);
void draw_square_raw(t_square_params *params);
void draw_line(t_line_params *params);
void drawrays2d(t_structure_main *w);
//Ray
void calculateverticalray(t_ray_calc_params *params);
void handle_ra_vertical(t_ray_calc_params *params, float nTan, int tileSize);
void calculatehorizontalray(t_ray_calc_params *params);
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);
//window
void init_windows(t_structure_main *w);
void init_player(t_structure_main *w);
void init_mlx_and_window(t_structure_main *w);
void sleep_mouse(t_global_struct *global_struct);
#endif

View File

@ -0,0 +1,88 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_2d_view.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/12 17:49:42 by fgras-ca #+# #+# */
/* Updated: 2024/01/15 18:44:32 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#include "../cub3d.h"
float correctfisheye(float distance, float ra, float playerAngle)
{
float ca;
ca = playerAngle - ra;
if (ca < 0)
ca += 2 * PI;
if (ca > 2 * PI)
ca -= 2 * PI;
return (distance * cos(ca));
}
void init_base_params(t_base_params *params, t_structure_main *w)
{
params->tilesize = w->s_map.mapS;
params->numrays = NUMRAY;
params->FOV = FOVIEW * (PI / 180);
params->DR = params->FOV / params->numrays;
params->ra = w->s_player.pa - (params->FOV / 2);
draw_background(w);
}
void calculate_ray(t_base_params *base, t_ray_state *state,
t_ray_calc *calc, t_ray_params *rayparams)
{
if (state->disH < state->disV)
{
rayparams->disT = state->disH;
calc->color = 0xFF0000;
rayparams->wallDir = state->hwalldir;
rayparams->rx = state->hx;
rayparams->ry = state->hy;
}
else
{
rayparams->disT = state->disV;
calc->color = 0x00FF00;
rayparams->wallDir = state->vwalldir;
rayparams->rx = state->vx;
rayparams->ry = state->vy;
}
rayparams->disT = correctfisheye(rayparams->disT,
base->ra, calc->w->s_player.pa);
rayparams->w = calc->w;
rayparams->tileSize = base->tilesize;
rayparams->r = calc->r;
rayparams->numRays = base->numrays;
rayparams->color = calc->color;
}
void drawrays2d(t_structure_main *w)
{
t_drawrays2d_params params;
init_base_params(&params.base_params, w);
params.ray_calc.w = w;
params.ray_calc.r = 0;
while (params.ray_calc.r++ < params.base_params.numrays)
{
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.ray_state.disH, &params.ray_state.hx,
&params.ray_state.hy, &params.ray_state.hwalldir};
params.vrayparams = (t_ray_calc_params){w, params.base_params.ra,
&params.ray_state.disV, &params.ray_state.vx,
&params.ray_state.vy, &params.ray_state.vwalldir};
calculatehorizontalray(&params.hrayparams);
calculateverticalray(&params.vrayparams);
calculate_ray(&params.base_params, &params.ray_state,
&params.ray_calc, &params.rayparams);
drawray(&params.rayparams);
params.base_params.ra += params.base_params.DR;
}
}

Binary file not shown.

View File

@ -0,0 +1,61 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_3d_view.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/12 17:35:53 by fgras-ca #+# #+# */
/* Updated: 2024/01/14 17:19:42 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#include "../cub3d.h"
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->lineOff = rayParams->lineOff;
textureparams->lineH = rayParams->lineH;
textureparams->wallDir = rayParams->wallDir;
textureparams->rx = rayParams->rx + rayParams->backgroundOffsetX;
textureparams->ry = rayParams->ry;
textureparams->disT = rayParams->disT;
}
void drawray(t_ray_params *rayparams)
{
t_line_params lineparams;
t_texture_params textureparams;
rayparams->start3DHeight = 0;
rayparams->max3DHeight = rayparams->w->s_win.height
+ rayparams->start3DHeight;
rayparams->lineH = (rayparams->tileSize * rayparams->max3DHeight)
/ rayparams->disT;
if (rayparams->lineH > rayparams->max3DHeight)
{
rayparams->lineH = rayparams->max3DHeight;
}
rayparams->lineOff = ((rayparams->max3DHeight - rayparams->lineH) / 2);
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_line_params(&lineparams, rayparams);
draw_line(&lineparams);
init_texture_params(&textureparams, rayparams);
draw_texture(&textureparams);
}

Binary file not shown.

View File

@ -0,0 +1,47 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_background.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/11 23:19:39 by fgras-ca #+# #+# */
/* Updated: 2024/01/14 17:37:52 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#include "../cub3d.h"
void draw_sky_ground(t_sky_ground_params *params)
{
t_square_params square_params;
square_params.w = params->w;
square_params.x = params->backgroundOffsetX;
square_params.y = params->startHeight;
square_params.xo = params->w->s_win.width + params->backgroundOffsetX;
square_params.yo = params->endHeight;
square_params.color = params->color;
draw_square_raw(&square_params);
}
void draw_background(t_structure_main *w)
{
int backgroundoffsetx;
t_sky_ground_params sky_params;
t_sky_ground_params ground_params;
backgroundoffsetx = BOV;
sky_params.w = w;
sky_params.startHeight = 0;
sky_params.endHeight = w->s_win.height / 2;
sky_params.color = 0xB2FFFF;
sky_params.backgroundOffsetX = backgroundoffsetx;
draw_sky_ground(&sky_params);
ground_params.w = w;
ground_params.startHeight = w->s_win.height / 2;
ground_params.endHeight = w->s_win.height;
ground_params.color = 0x280000;
ground_params.backgroundOffsetX = backgroundoffsetx;
draw_sky_ground(&ground_params);
}

Binary file not shown.

89
versionmod/draw/ft_draw.c Normal file
View File

@ -0,0 +1,89 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_draw.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/11 22:38:28 by fgras-ca #+# #+# */
/* Updated: 2024/01/14 17:54:44 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#include "../cub3d.h"
void draw_square(t_structure_main *w, int x, int y, int color)
{
int xo;
int yo;
int size;
int i;
int j;
xo = x * w->s_map.mapS;
yo = y * w->s_map.mapS;
size = w->s_map.mapS;
i = 0;
while (i < size)
{
j = 0;
while (j < size)
{
put_pixel_img(w, xo + j, yo + i, color);
j++;
}
i++;
}
}
static void init_line_deltas(t_line_deltas *deltas)
{
(deltas->dx) = abs(deltas->params->x1 - deltas->params->x0);
(deltas->dy) = abs(deltas->params->y1 - deltas->params->y0);
(deltas->err) = (deltas->dx) - (deltas->dy);
if (deltas->params->x0 < deltas->params->x1)
(deltas->sx) = 1;
else
(deltas->sx) = -1;
if (deltas->params->y0 < deltas->params->y1)
(deltas->sy) = 1;
else
(deltas->sy) = -1;
}
static void trace_line(t_line_deltas *deltas)
{
int e2;
while (deltas->params->x0 != deltas->params->x1
|| deltas->params->y0 != deltas->params->y1)
{
put_pixel_img(deltas->params->w, deltas->params->x0,
deltas->params->y0, deltas->params->color);
e2 = 2 * (deltas->err);
if (e2 > -((deltas->dy)))
{
(deltas->err) -= (deltas->dy);
deltas->params->x0 += (deltas->sx);
}
if (e2 < (deltas->dx))
{
(deltas->err) += (deltas->dx);
deltas->params->y0 += (deltas->sy);
}
}
}
void draw_line(t_line_params *params)
{
t_line_deltas deltas;
deltas.params = params;
init_line_deltas(&deltas);
trace_line(&deltas);
}
float dist(float ax, float ay, float bx, float by)
{
return (sqrt((bx - ax) * (bx - ax) + (by - ay) * (by - ay)));
}

BIN
versionmod/draw/ft_draw.o Normal file

Binary file not shown.

View File

@ -0,0 +1,82 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_horizontal_ray.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/12 19:53:47 by fgras-ca #+# #+# */
/* Updated: 2024/01/14 18:34:26 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#include "../cub3d.h"
void handle_ra_equal_pi(t_ray_calc_params *params)
{
*params->rx = params->w->s_player.px;
*params->ry = params->w->s_player.py;
params->dof = DOF;
}
void inithorizontalray(t_ray_calc_params *params)
{
float atan;
int tilesize;
atan = -1 / tan(params->ra);
tilesize = params->w->s_map.mapS;
if (params->ra != PI)
handle_ra_not_equal_pi(params, atan, tilesize);
else
handle_ra_equal_pi(params);
}
void update_ray_params(t_ray_calc_params *params, int mx, int my)
{
int mp;
mp = my * params->w->s_map.mapX + mx;
if (mp >= 0 && mp < params->w->s_map.mapX * params->w->s_map.mapY
&& params->w->s_map.map[mp] == '1')
{
params->dof = DOF;
*params->disRay = dist(params->w->s_player.px, params->w->s_player.py,
*params->rx, *params->ry);
if (params->ra > PI)
*params->wallDir = NORTH;
else
*params->wallDir = SOUTH;
}
}
void processhorizontalray(t_ray_calc_params *params)
{
int mx;
int my;
int tilesize;
tilesize = params->w->s_map.mapS;
*params->disRay = DISRAY;
while (params->dof < DOF)
{
mx = (int)(*params->rx) / tilesize;
my = (int)(*params->ry) / tilesize;
update_ray_params(params, mx, my);
if (params->dof < DOF)
{
*params->rx += params->xo;
*params->ry += params->yo;
params->dof++;
}
}
}
void calculatehorizontalray(t_ray_calc_params *params)
{
params->xo = 0;
params->yo = 0;
params->dof = 0;
inithorizontalray(params);
processhorizontalray(params);
}

Binary file not shown.

View File

@ -0,0 +1,44 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_load_textures.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/14 20:30:59 by fgras-ca #+# #+# */
/* Updated: 2024/01/14 20:56:42 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#include "../cub3d.h"
void load_texture(t_structure_main *w, char *file_path, void **texture_ptr)
{
int width;
int height;
width = 0;
height = 0;
*texture_ptr = mlx_xpm_file_to_image(w->s_win.mlx,
file_path, &width, &height);
if (!(*texture_ptr))
{
fprintf(stderr, "Failed to load texture: %s\n", file_path);
exit_error(w);
}
w->s_img.texture_width = width;
w->s_img.texture_height = height;
}
void load_wall_textures(t_structure_main *w)
{
load_texture(w, "textures/NO.xpm", (void **)&w->s_img.north_texture);
load_texture(w, "textures/SO.xpm", (void **)&w->s_img.south_texture);
load_texture(w, "textures/WE.xpm", (void **)&w->s_img.west_texture);
load_texture(w, "textures/EA.xpm", (void **)&w->s_img.east_texture);
}
void exit_error(t_structure_main *w)
{
exit(1);
}

Binary file not shown.

View File

@ -0,0 +1,50 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_pixel.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/14 17:54:04 by fgras-ca #+# #+# */
/* Updated: 2024/01/14 17:54:40 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#include "../cub3d.h"
void put_pixel_img(t_structure_main *w, int x, int y, int color)
{
char *dst;
if (x >= 0 && y >= 0 && x < w->s_win.width && y < w->s_win.height)
{
dst = w->s_img.addr + (y * w->s_img.line_len + x * (w->s_img.bpp / 8));
*(unsigned int *)dst = color;
}
else
{
}
}
void draw_square_raw(t_square_params *params)
{
int i;
int j;
int size_x;
int size_y;
i = 0;
size_x = abs(params->xo - params->x);
size_y = abs(params->yo - params->y);
while (i < size_y)
{
j = 0;
while (j < size_x)
{
put_pixel_img(params->w, params->x + j,
params->y + i, params->color);
j++;
}
i++;
}
}

BIN
versionmod/draw/ft_pixel.o Normal file

Binary file not shown.

View File

@ -0,0 +1,59 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_ray_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/14 18:25:39 by fgras-ca #+# #+# */
/* Updated: 2024/01/14 18:41:22 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#include "../cub3d.h"
void handle_ra_vertical(t_ray_calc_params *params, float nTan, int tileSize)
{
if (params->ra > P2 && params->ra < P3)
{
*params->rx = (((int)params->w->s_player.px / tileSize)
* tileSize) - 0.0001;
params->xo = -tileSize;
}
else if (params->ra < P2 || params->ra > P3)
{
*params->rx = (((int)params->w->s_player.px / tileSize)
* tileSize) + tileSize;
params->xo = tileSize;
}
else
{
*params->rx = params->w->s_player.px;
*params->ry = params->w->s_player.py;
params->dof = DOF;
return ;
}
*params->ry = (params->w->s_player.px - *params->rx)
* nTan + params->w->s_player.py;
params->yo = -params->xo * nTan;
}
void handle_ra_not_equal_pi(t_ray_calc_params *params,
float atan, int tilesize)
{
if (params->ra > PI)
{
*params->ry = (((int)params->w->s_player.py / tilesize)
* tilesize) - 0.0001;
params->yo = -tilesize;
}
else
{
*params->ry = (((int)params->w->s_player.py / tilesize)
* tilesize) + tilesize;
params->yo = tilesize;
}
*params->rx = (params->w->s_player.py - *params->ry)
* atan + params->w->s_player.px;
params->xo = -params->yo * atan;
}

Binary file not shown.

View File

@ -0,0 +1,104 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_textures.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/12 17:39:11 by fgras-ca #+# #+# */
/* Updated: 2024/01/14 21:26:16 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#include "../cub3d.h"
void draw_texture_line(t_texture_params *params, float y, int textureY)
{
int x;
int texturewidth;
int texturex;
int color;
texturewidth = params->w->s_img.texture_width;
x = params->startX;
while (x < params->endX)
{
if (params->wallDir == NORTH || params->wallDir == SOUTH)
texturex = (int)(params->rx * texturewidth
/ params->w->s_map.mapS) % texturewidth;
else
texturex = (int)(params->ry * texturewidth
/ params->w->s_map.mapS) % texturewidth;
if (texturex >= texturewidth)
texturex = texturewidth - 1;
color = get_texture_color(params->w,
params->wallDir, texturex, textureY);
put_pixel_img(params->w, x, y, color);
x++;
}
}
void draw_texture(t_texture_params *params)
{
int textureheight;
float y;
float perspectivefactor;
int texturey;
textureheight = params->w->s_img.texture_height;
y = params->lineOff;
while (y < params->lineOff + params->lineH)
{
perspectivefactor = (y - params->lineOff) / params->lineH;
texturey = perspectivefactor * textureheight;
if (texturey >= textureheight)
texturey = textureheight - 1;
draw_texture_line(params, y, texturey);
y++;
}
}
void *get_selected_texture(t_structure_main *w, WallDirection wallDir)
{
if (wallDir == NORTH)
return (w->s_img.north_texture);
else if (wallDir == SOUTH)
return (w->s_img.south_texture);
else if (wallDir == WEST)
return (w->s_img.west_texture);
else if (wallDir == EAST)
return (w->s_img.east_texture);
else
{
fprintf(stderr, "Invalid wall direction.\n");
exit_error(w);
return (NULL);
}
}
t_texture_data get_texture_data(void *texture)
{
t_texture_data texture_data;
texture_data.data = mlx_get_data_addr(texture, &texture_data.bpp,
&texture_data.size_line, &texture_data.endian);
return (texture_data);
}
int get_texture_color(t_structure_main *w, WallDirection wallDir,
int textureX, int textureY)
{
void *selected_texture;
t_texture_data texture_data;
int pixel_pos;
selected_texture = get_selected_texture(w, wallDir);
if (selected_texture == NULL)
{
return (0);
}
texture_data = get_texture_data(selected_texture);
pixel_pos = (textureX + textureY * w->s_img.texture_width)
* (texture_data.bpp / 8);
return (*(int *)(texture_data.data + pixel_pos));
}

Binary file not shown.

View File

@ -0,0 +1,72 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_vertical_ray.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/12 20:03:21 by fgras-ca #+# #+# */
/* Updated: 2024/01/14 18:39:19 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#include "../cub3d.h"
void initverticalray(t_ray_calc_params *params)
{
float ntan;
int tilesize;
ntan = -tan(params->ra);
tilesize = params->w->s_map.mapS;
handle_ra_vertical(params, ntan, tilesize);
}
void update_vertical_ray_params(t_ray_calc_params *params, int mx, int my)
{
int mp;
mp = my * params->w->s_map.mapX + mx;
if (mp >= 0 && mp < params->w->s_map.mapX * params->w->s_map.mapY
&& params->w->s_map.map[mp] == '1')
{
params->dof = DOF;
*params->disRay = dist(params->w->s_player.px, params->w->s_player.py,
*params->rx, *params->ry);
if (params->ra > P2 && params->ra < P3)
*params->wallDir = WEST;
else
*params->wallDir = EAST;
}
}
void processverticalray(t_ray_calc_params *params)
{
int mx;
int my;
int tilesize;
tilesize = params->w->s_map.mapS;
*params->disRay = DISRAY;
while (params->dof < DOF)
{
mx = (int)(*params->rx) / tilesize;
my = (int)(*params->ry) / tilesize;
update_vertical_ray_params(params, mx, my);
if (params->dof < DOF)
{
*params->rx += params->xo;
*params->ry += params->yo;
params->dof++;
}
}
}
void calculateverticalray(t_ray_calc_params *params)
{
params->xo = 0;
params->yo = 0;
params->dof = 0;
initverticalray(params);
processverticalray(params);
}

Binary file not shown.

139
versionmod/include/mlx.h Normal file
View File

@ -0,0 +1,139 @@
/*
** mlx.h for MinilibX in
**
** Made by Charlie Root
** Login <ol@epitech.net>
**
** Started on Mon Jul 31 16:37:50 2000 Charlie Root
** Last update Tue May 15 16:23:28 2007 Olivier Crouzet
*/
/*
** 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
#define MLX_H
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);
/*
** return void *0 if failed
*/
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);
/*
** 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,
int *size_line, int *endian);
/*
** 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 mlx_get_color_value(void *mlx_ptr, int color);
/*
** dealing with Events
*/
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);
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_xpm_to_image(void *mlx_ptr, char **xpm_data,
int *width, int *height);
void *mlx_xpm_file_to_image(void *mlx_ptr, char *filename,
int *width, int *height);
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);
/*
** 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 */

BIN
versionmod/lib/libmlx.a Normal file

Binary file not shown.

Binary file not shown.

102
versionmod/libft/Makefile Executable file
View File

@ -0,0 +1,102 @@
# **************************************************************************** #
# #
# ::: :::::::: #
# 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

38
versionmod/libft/ft_atoi.c Executable file
View File

@ -0,0 +1,38 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 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
versionmod/libft/ft_atoi.o Normal file

Binary file not shown.

25
versionmod/libft/ft_bzero.c Executable file
View File

@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 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
versionmod/libft/ft_bzero.o Normal file

Binary file not shown.

28
versionmod/libft/ft_calloc.c Executable file
View File

@ -0,0 +1,28 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 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.

21
versionmod/libft/ft_isalnum.c Executable file
View File

@ -0,0 +1,21 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 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.

21
versionmod/libft/ft_isalpha.c Executable file
View File

@ -0,0 +1,21 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 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.

20
versionmod/libft/ft_isascii.c Executable file
View File

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 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.

21
versionmod/libft/ft_isdigit.c Executable file
View File

@ -0,0 +1,21 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 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.

20
versionmod/libft/ft_isprint.c Executable file
View File

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 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.

56
versionmod/libft/ft_itoa.c Executable file
View File

@ -0,0 +1,56 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 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
versionmod/libft/ft_itoa.o Normal file

Binary file not shown.

View File

@ -0,0 +1,29 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 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;
}
}

View File

@ -0,0 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 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;
}
}

25
versionmod/libft/ft_lstclear.c Executable file
View File

@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 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;
}
}

21
versionmod/libft/ft_lstdelone.c Executable file
View File

@ -0,0 +1,21 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 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);
}

24
versionmod/libft/ft_lstiter.c Executable file
View File

@ -0,0 +1,24 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 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;
}
}

24
versionmod/libft/ft_lstlast.c Executable file
View File

@ -0,0 +1,24 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 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);
}

35
versionmod/libft/ft_lstmap.c Executable file
View File

@ -0,0 +1,35 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 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);
}

25
versionmod/libft/ft_lstnew.c Executable file
View File

@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 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);
}

28
versionmod/libft/ft_lstsize.c Executable file
View File

@ -0,0 +1,28 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 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);
}

27
versionmod/libft/ft_memchr.c Executable file
View File

@ -0,0 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 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.

27
versionmod/libft/ft_memcmp.c Executable file
View File

@ -0,0 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 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.

32
versionmod/libft/ft_memcpy.c Executable file
View File

@ -0,0 +1,32 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 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.

42
versionmod/libft/ft_memmove.c Executable file
View File

@ -0,0 +1,42 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 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.

26
versionmod/libft/ft_memset.c Executable file
View File

@ -0,0 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 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.

View File

@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 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.

View File

@ -0,0 +1,28 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 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.

36
versionmod/libft/ft_putnbr_fd.c Executable file
View File

@ -0,0 +1,36 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 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.

27
versionmod/libft/ft_putstr_fd.c Executable file
View File

@ -0,0 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 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.

35
versionmod/libft/ft_realloc.c Executable file
View File

@ -0,0 +1,35 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 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.

View File

@ -0,0 +1,32 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 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.

32
versionmod/libft/ft_strcat.c Executable file
View File

@ -0,0 +1,32 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 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.

32
versionmod/libft/ft_strchr.c Executable file
View File

@ -0,0 +1,32 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 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.

23
versionmod/libft/ft_strcmp.c Executable file
View File

@ -0,0 +1,23 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 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.

28
versionmod/libft/ft_strcpy.c Executable file
View File

@ -0,0 +1,28 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 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.

25
versionmod/libft/ft_striteri.c Executable file
View File

@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 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.

33
versionmod/libft/ft_strlcat.c Executable file
View File

@ -0,0 +1,33 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 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.

32
versionmod/libft/ft_strlcpy.c Executable file
View File

@ -0,0 +1,32 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 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.

33
versionmod/libft/ft_strmapi.c Executable file
View File

@ -0,0 +1,33 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 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.

29
versionmod/libft/ft_strncmp.c Executable file
View File

@ -0,0 +1,29 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 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.

31
versionmod/libft/ft_strncpy.c Executable file
View File

@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 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.

41
versionmod/libft/ft_strnstr.c Executable file
View File

@ -0,0 +1,41 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 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.

29
versionmod/libft/ft_strrchr.c Executable file
View File

@ -0,0 +1,29 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 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.

Some files were not shown because too many files have changed in this diff Show More