github to gitea
This commit is contained in:
parent
2fa3015af4
commit
cd1882c3cc
46
Makefile
46
Makefile
|
|
@ -1,46 +0,0 @@
|
||||||
CC = gcc
|
|
||||||
CFLAGS = -fsanitize=address -g -Wall -Wextra -Werror
|
|
||||||
NAME = cub3d
|
|
||||||
|
|
||||||
SRCDIR = srcs
|
|
||||||
INCDIR = includes
|
|
||||||
LIBFT = libft/libft.a
|
|
||||||
GNL = gnl/gnl.a
|
|
||||||
|
|
||||||
SRCS = $(SRCDIR)/main.c \
|
|
||||||
$(SRCDIR)/parsing/parsing.c \
|
|
||||||
$(SRCDIR)/parsing/check_file.c \
|
|
||||||
$(SRCDIR)/parsing/init_parsing.c \
|
|
||||||
$(SRCDIR)/parsing/get_map.c \
|
|
||||||
$(SRCDIR)/parsing/line_detect.c \
|
|
||||||
$(SRCDIR)/parsing/get_textures.c \
|
|
||||||
$(SRCDIR)/parsing/check_colors.c \
|
|
||||||
$(SRCDIR)/utils/utils.c \
|
|
||||||
$(SRCDIR)/utils/init.c \
|
|
||||||
$(SRCDIR)/parsing/check_map.c \
|
|
||||||
$(SRCDIR)/parsing/check_map_2.c \
|
|
||||||
|
|
||||||
INCS = $(INCDIR)/parsing.h \
|
|
||||||
$(INCDIR)/cub.h \
|
|
||||||
|
|
||||||
all: $(NAME)
|
|
||||||
|
|
||||||
$(NAME): $(SRCS) $(INCS)
|
|
||||||
@$(MAKE) -s -C libft
|
|
||||||
@$(MAKE) -s -C gnl
|
|
||||||
$(CC) -g -I$(INCDIR) $(SRCS) -o $(NAME) $(LIBFT) $(GNL)
|
|
||||||
|
|
||||||
clean:
|
|
||||||
rm -f $(NAME)
|
|
||||||
@make clean -s -C libft
|
|
||||||
@make clean -s -C gnl
|
|
||||||
|
|
||||||
clean1:
|
|
||||||
rm -f $(NAME)
|
|
||||||
|
|
||||||
fclean: clean1
|
|
||||||
@make fclean -s -C libft
|
|
||||||
@make fclean -s -C gnl
|
|
||||||
re: fclean all
|
|
||||||
|
|
||||||
.PHONY: all clean fclean re clean1
|
|
||||||
|
|
@ -0,0 +1,68 @@
|
||||||
|
// cub3d.h
|
||||||
|
#ifndef CUB3D_H
|
||||||
|
# define CUB3D_H
|
||||||
|
# include <math.h>
|
||||||
|
# include <stdlib.h>
|
||||||
|
# include <stdbool.h>
|
||||||
|
# include "mlx.h"
|
||||||
|
|
||||||
|
# define WIN_W 1280
|
||||||
|
# define WIN_H 720
|
||||||
|
|
||||||
|
typedef struct s_img {
|
||||||
|
void *ptr;
|
||||||
|
char *addr;
|
||||||
|
int bpp;
|
||||||
|
int line_len;
|
||||||
|
int endian;
|
||||||
|
} t_img;
|
||||||
|
|
||||||
|
typedef struct s_tex {
|
||||||
|
t_img img;
|
||||||
|
int w, h;
|
||||||
|
} t_tex;
|
||||||
|
|
||||||
|
typedef struct s_keys {
|
||||||
|
bool w, a, s, d, left, right;
|
||||||
|
} t_keys;
|
||||||
|
|
||||||
|
typedef struct s_app {
|
||||||
|
void *mlx;
|
||||||
|
void *win;
|
||||||
|
t_img frame;
|
||||||
|
// map
|
||||||
|
char **map; // rectangle, accès map[y][x]
|
||||||
|
int map_w, map_h;
|
||||||
|
|
||||||
|
// player
|
||||||
|
double px, py; // position
|
||||||
|
double dirx, diry; // direction
|
||||||
|
double planex, planey; // caméra (FOV ~66° => plane longueur ~0.66)
|
||||||
|
|
||||||
|
// movement
|
||||||
|
double move_speed;
|
||||||
|
double rot_speed;
|
||||||
|
|
||||||
|
// textures (N,E,S,W) supposées chargées via parsing
|
||||||
|
t_tex tex[4];
|
||||||
|
|
||||||
|
// zbuffer pour sprites/doors bonus
|
||||||
|
double *zbuf;
|
||||||
|
|
||||||
|
t_keys keys;
|
||||||
|
} t_app;
|
||||||
|
|
||||||
|
// utils
|
||||||
|
void put_pixel(t_img *img, int x, int y, int color);
|
||||||
|
int get_tex_color(t_tex *t, int tx, int ty);
|
||||||
|
|
||||||
|
// hooks
|
||||||
|
int key_press(int keycode, t_app *a);
|
||||||
|
int key_release(int keycode, t_app *a);
|
||||||
|
int close_win(t_app *a);
|
||||||
|
|
||||||
|
// loop
|
||||||
|
int update(t_app *a);
|
||||||
|
void render_frame(t_app *a);
|
||||||
|
|
||||||
|
#endif
|
||||||
60
gnl/Makefile
60
gnl/Makefile
|
|
@ -1,60 +0,0 @@
|
||||||
# **************************************************************************** #
|
|
||||||
# #
|
|
||||||
# ::: :::::::: #
|
|
||||||
# Makefile :+: :+: :+: #
|
|
||||||
# +:+ +:+ +:+ #
|
|
||||||
# By: lfirmin lfirmim@student.42.fr> +#+ +:+ +#+ #
|
|
||||||
# +#+#+#+#+#+ +#+ #
|
|
||||||
# Created: 2024/08/12 07:07:31 by lfirmin #+# #+# #
|
|
||||||
# Updated: 2024/08/12 09:15:05 by lfirmin ### ########.fr #
|
|
||||||
# #
|
|
||||||
# **************************************************************************** #
|
|
||||||
|
|
||||||
NAME = gnl.a
|
|
||||||
SRCS_DIR = srcs/
|
|
||||||
INCS_DIR = includes/
|
|
||||||
OBJ_DIR = obj/
|
|
||||||
|
|
||||||
SRC = get_next_line.c get_next_line_utils.c
|
|
||||||
CC = cc
|
|
||||||
CFLAGS = -Wall -Wextra -Werror -fPIE
|
|
||||||
INCLUDE = -I $(INCS_DIR)
|
|
||||||
SRCS = $(addprefix $(SRCS_DIR), $(SRC))
|
|
||||||
OBJ = $(addprefix $(OBJ_DIR), $(SRC:.c=.o))
|
|
||||||
|
|
||||||
# Colors
|
|
||||||
GREEN = \033[0;32m
|
|
||||||
YELLOW = \033[0;33m
|
|
||||||
RESET = \033[0m
|
|
||||||
WHITE = \033[0;97m
|
|
||||||
|
|
||||||
# Loading animation
|
|
||||||
LOADING_CHARS = ⠋ ⠙ ⠹ ⠸ ⠼ ⠴ ⠦ ⠧ ⠇ ⠏
|
|
||||||
|
|
||||||
all: $(NAME)
|
|
||||||
|
|
||||||
$(NAME): $(OBJ)
|
|
||||||
@printf "$(YELLOW)Compiling get_next_line, Please wait...$(RESET)"
|
|
||||||
@for char in $(LOADING_CHARS); do \
|
|
||||||
printf "\r$(YELLOW)Compiling get_next_line, Please wait... $$char$(RESET)"; \
|
|
||||||
sleep 0.1; \
|
|
||||||
done
|
|
||||||
@ar rc $(NAME) $(OBJ)
|
|
||||||
@ranlib $(NAME)
|
|
||||||
@printf "\r$(GREEN)fine ! $(WHITE)get_next_line compiled successfully ! $(RESET)\n"
|
|
||||||
|
|
||||||
$(OBJ_DIR)%.o: $(SRCS_DIR)%.c
|
|
||||||
@mkdir -p $(OBJ_DIR)
|
|
||||||
@$(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@
|
|
||||||
|
|
||||||
clean:
|
|
||||||
@rm -rf $(OBJ_DIR)
|
|
||||||
@printf "$(WHITE)Clean process completed for $(GREEN)get_next_line.$(RESET)\n"
|
|
||||||
|
|
||||||
fclean: clean
|
|
||||||
@rm -f $(NAME)
|
|
||||||
@printf "$(WHITE)Full clean process completed for $(GREEN)get_next_line.$(RESET)\n"
|
|
||||||
|
|
||||||
re: fclean all
|
|
||||||
|
|
||||||
.PHONY: all clean fclean re
|
|
||||||
|
|
@ -1,32 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* get_next_line.h :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: abelghou <abelghou@student.42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2024/07/21 19:32:47 by abelghou #+# #+# */
|
|
||||||
/* Updated: 2024/07/23 20:47:15 by abelghou ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#ifndef GET_NEXT_LINE_H
|
|
||||||
# define GET_NEXT_LINE_H
|
|
||||||
|
|
||||||
# ifndef BUFFER_SIZE
|
|
||||||
# define BUFFER_SIZE 1000
|
|
||||||
# endif
|
|
||||||
|
|
||||||
# include <stdlib.h>
|
|
||||||
# include <unistd.h>
|
|
||||||
# include <stdio.h>
|
|
||||||
# include <fcntl.h>
|
|
||||||
|
|
||||||
char *ft_substr(char const *s, unsigned int start, size_t len);
|
|
||||||
int ft_strlen_g(const char *str);
|
|
||||||
char *ft_strchr_gnl(const char *s, int i);
|
|
||||||
char *ft_strdup_g(const char *s);
|
|
||||||
char *ft_strjoin(char const *s1, char const *s2);
|
|
||||||
char *get_next_line(int fd);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
Binary file not shown.
Binary file not shown.
|
|
@ -1,41 +0,0 @@
|
||||||
# get_next_line
|
|
||||||
|
|
||||||
A function that reads a line from a file descriptor.
|
|
||||||
|
|
||||||
## 💡 About
|
|
||||||
The get_next_line project is a programming function that reads a line ending with a newline character from a file descriptor. When calling the function in a loop, it will then allow you to read the text file pointed to by the file descriptor, one line at a time until the end of the file.
|
|
||||||
|
|
||||||
## 🛠️ Function Prototype
|
|
||||||
```c
|
|
||||||
char *get_next_line(int fd);
|
|
||||||
```
|
|
||||||
## 📋 Usage
|
|
||||||
```c
|
|
||||||
#include "get_next_line.h"
|
|
||||||
#include <fcntl.h>
|
|
||||||
|
|
||||||
int main(void)
|
|
||||||
{
|
|
||||||
int fd;
|
|
||||||
char *line;
|
|
||||||
|
|
||||||
fd = open("test.txt", O_RDONLY);
|
|
||||||
while ((line = get_next_line(fd)) != NULL)
|
|
||||||
{
|
|
||||||
printf("%s", line);
|
|
||||||
free(line);
|
|
||||||
}
|
|
||||||
close(fd);
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## ⚠️ Return Value
|
|
||||||
* The line that was read when successful
|
|
||||||
* NULL if there is nothing else to read or if an error occurred
|
|
||||||
|
|
||||||
## 📊 Expected Behavior
|
|
||||||
* Repeated calls to get_next_line() should let you read the text file pointed to by the file descriptor, one line at a time
|
|
||||||
* The function should return the line that was read
|
|
||||||
* If there is nothing else to read or if an error occurred, it should return NULL
|
|
||||||
* The returned line should include the terminating \n character, except if the end of file was reached and does not end with a \n character
|
|
||||||
|
|
@ -1,102 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* get_next_line.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: abelghou <abelghou@student.42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2024/07/17 21:31:24 by abelghou #+# #+# */
|
|
||||||
/* Updated: 2024/07/24 18:17:55 by abelghou ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "../include/get_next_line.h"
|
|
||||||
|
|
||||||
static char *sort_and_store(int fd, char *buf, char *backup)
|
|
||||||
{
|
|
||||||
int read_line;
|
|
||||||
char *char_temp;
|
|
||||||
|
|
||||||
read_line = 1;
|
|
||||||
while (read_line != 0)
|
|
||||||
{
|
|
||||||
read_line = read(fd, buf, BUFFER_SIZE);
|
|
||||||
if (read_line == -1)
|
|
||||||
return (0);
|
|
||||||
else if (read_line == 0)
|
|
||||||
break ;
|
|
||||||
buf[read_line] = '\0';
|
|
||||||
if (!backup)
|
|
||||||
backup = ft_strdup_g("");
|
|
||||||
if (!backup)
|
|
||||||
return (NULL);
|
|
||||||
char_temp = backup;
|
|
||||||
backup = ft_strjoin(char_temp, buf);
|
|
||||||
free(char_temp);
|
|
||||||
char_temp = NULL;
|
|
||||||
if (ft_strchr_gnl (buf, '\n'))
|
|
||||||
break ;
|
|
||||||
}
|
|
||||||
return (backup);
|
|
||||||
}
|
|
||||||
|
|
||||||
static char *extract(char *line)
|
|
||||||
{
|
|
||||||
size_t count;
|
|
||||||
char *backup;
|
|
||||||
|
|
||||||
count = 0;
|
|
||||||
while (line[count] != '\n' && line[count] != '\0')
|
|
||||||
count++;
|
|
||||||
if (line[count] == '\0' || line[1] == '\0')
|
|
||||||
return (0);
|
|
||||||
backup = ft_substr(line, count + 1, ft_strlen_g(line) - count);
|
|
||||||
if (!backup)
|
|
||||||
return (NULL);
|
|
||||||
if (*backup == '\0')
|
|
||||||
{
|
|
||||||
free (backup);
|
|
||||||
backup = NULL;
|
|
||||||
}
|
|
||||||
line[count + 1] = '\0';
|
|
||||||
return (backup);
|
|
||||||
}
|
|
||||||
|
|
||||||
char *get_next_line(int fd)
|
|
||||||
{
|
|
||||||
char *line;
|
|
||||||
char *buf;
|
|
||||||
char *temp;
|
|
||||||
static char *backup;
|
|
||||||
|
|
||||||
if (fd < 0 || BUFFER_SIZE <= 0)
|
|
||||||
return (free(backup), backup = NULL, NULL);
|
|
||||||
buf = (char *)malloc(sizeof(char) * (BUFFER_SIZE + 1));
|
|
||||||
if (!buf)
|
|
||||||
return (free(backup), backup = NULL, NULL);
|
|
||||||
line = sort_and_store(fd, buf, backup);
|
|
||||||
free(buf);
|
|
||||||
buf = NULL;
|
|
||||||
if (!line)
|
|
||||||
return (free(backup), backup = NULL, NULL);
|
|
||||||
backup = extract(line);
|
|
||||||
temp = ft_strdup_g(line);
|
|
||||||
free(line);
|
|
||||||
if (!temp)
|
|
||||||
return (free(backup), backup = NULL, NULL);
|
|
||||||
return (temp);
|
|
||||||
}
|
|
||||||
|
|
||||||
// int main()
|
|
||||||
// {
|
|
||||||
// int fd;
|
|
||||||
// char *line;
|
|
||||||
// fd = open("fd.txt", O_RDONLY);
|
|
||||||
// while((line = get_next_line(fd)) != NULL)
|
|
||||||
// {
|
|
||||||
// printf("%s", line);
|
|
||||||
// free(line);
|
|
||||||
// }
|
|
||||||
// line = get_next_line(fd);
|
|
||||||
// close(fd);
|
|
||||||
// }
|
|
||||||
|
|
@ -1,106 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* get_next_line_utils.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: abelghou <abelghou@student.42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2024/07/21 19:34:18 by abelghou #+# #+# */
|
|
||||||
/* Updated: 2024/07/23 20:06:41 by abelghou ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "../include/get_next_line.h"
|
|
||||||
|
|
||||||
char *ft_substr(char const *s, unsigned int start, size_t len)
|
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
size_t j;
|
|
||||||
char *str;
|
|
||||||
|
|
||||||
str = (char *)malloc(sizeof(*s) * (len + 1));
|
|
||||||
if (str == 0)
|
|
||||||
return (NULL);
|
|
||||||
i = 0;
|
|
||||||
j = 0;
|
|
||||||
while (s[i])
|
|
||||||
{
|
|
||||||
if (i >= start && j < len)
|
|
||||||
{
|
|
||||||
str[j] = s[i];
|
|
||||||
j++;
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
str[j] = '\0';
|
|
||||||
return (str);
|
|
||||||
}
|
|
||||||
|
|
||||||
int ft_strlen_g(const char *str)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
while (str[i])
|
|
||||||
i++;
|
|
||||||
return (i);
|
|
||||||
}
|
|
||||||
|
|
||||||
char *ft_strchr_gnl(const char *s, int i)
|
|
||||||
{
|
|
||||||
while (*s)
|
|
||||||
{
|
|
||||||
if (*s == i)
|
|
||||||
return ((char *)s);
|
|
||||||
s++;
|
|
||||||
}
|
|
||||||
if (i == '\0')
|
|
||||||
return ((char *)s);
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
char *ft_strdup_g(const char *s)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
int j;
|
|
||||||
char *str;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
j = ft_strlen_g(s);
|
|
||||||
str = (char *)malloc(sizeof(*str) * (j + 1));
|
|
||||||
if (!str)
|
|
||||||
return (NULL);
|
|
||||||
while (i < j)
|
|
||||||
{
|
|
||||||
str[i] = s[i];
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
str[i] = '\0';
|
|
||||||
return (str);
|
|
||||||
}
|
|
||||||
|
|
||||||
char *ft_strjoin(char const *s1, char const *s2)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
int j;
|
|
||||||
char *str;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
j = 0;
|
|
||||||
str = (char *)malloc(sizeof(char) * (ft_strlen_g(s1) \
|
|
||||||
+ ft_strlen_g(s2) + 1));
|
|
||||||
if (str == NULL)
|
|
||||||
return (NULL);
|
|
||||||
while (s1[i] != '\0')
|
|
||||||
{
|
|
||||||
str[i] = s1[i];
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
while (s2[j] != '\0')
|
|
||||||
{
|
|
||||||
str[i + j] = s2[j];
|
|
||||||
j++;
|
|
||||||
}
|
|
||||||
str[i + j] = '\0';
|
|
||||||
return (str);
|
|
||||||
}
|
|
||||||
|
|
@ -1,57 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* cub.h :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2025/08/22 14:56:25 by lfirmin #+# #+# */
|
|
||||||
/* Updated: 2025/10/07 12:14:42 by lfirmin ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
#ifndef CUB_H
|
|
||||||
|
|
||||||
# define CUB_H
|
|
||||||
|
|
||||||
# include "parsing.h"
|
|
||||||
# include "../libft/include/libft.h"
|
|
||||||
# include "../gnl/include/get_next_line.h"
|
|
||||||
|
|
||||||
# define ERROR_PREFIX "Error\n"
|
|
||||||
# define ERROR_EXT "Invalid file extension. Only .cub files are accepted."
|
|
||||||
# define ERROR_EMPT_PATH "Invalid map file path."
|
|
||||||
# define ERROR_INIT_DATA "Initialization of the data structure failed."
|
|
||||||
# define ERROR_INIT_TEX "Initialization of the textures structure failed."
|
|
||||||
# define ERROR_INIT_PARS "Initialization of the parsing structure failed."
|
|
||||||
# define ERROR_EMPTY "You have provided an empty file."
|
|
||||||
# define ERROR_COL "The RGB values provided are not valid or absent."
|
|
||||||
# define ERROR_NULL_P "Player not found or multiple players."
|
|
||||||
# define ERROR_BAD_CHAR "Invalid character in map."
|
|
||||||
# define ERROR_POS "Player position not found."
|
|
||||||
# define ERROR_ALLOC "Allocation failed."
|
|
||||||
# define ERROR_PLAYER "Player not found or multiple players."
|
|
||||||
# define ERROR_CHAR "Invalid character in map."
|
|
||||||
# define ERROR_DOUBLE "Multiple images/colors have been provided \
|
|
||||||
for the same texture."
|
|
||||||
# define ERROR_NOT_CLOSE "Map is not closed by walls."
|
|
||||||
# define ERROR_NOT_XMP "The texture file is not an xpm image."
|
|
||||||
|
|
||||||
typedef struct s_data
|
|
||||||
{
|
|
||||||
char **map;
|
|
||||||
char *map_path;
|
|
||||||
t_textures *texture;
|
|
||||||
t_data_parsing parsing;
|
|
||||||
} t_data;
|
|
||||||
|
|
||||||
//utils
|
|
||||||
void ft_error(char *message);
|
|
||||||
void free_char_array(char **array);
|
|
||||||
int ft_arrlen(char **arr);
|
|
||||||
void print_array(char **array);//temp
|
|
||||||
|
|
||||||
//init
|
|
||||||
int init_data(t_data *data, char *path);
|
|
||||||
void free_data(t_data *data);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
@ -1,89 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* parsing.h :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2025/08/22 14:08:04 by lfirmin #+# #+# */
|
|
||||||
/* Updated: 2025/10/07 12:16:07 by lfirmin ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#ifndef PARSING_H
|
|
||||||
# define PARSING_H
|
|
||||||
|
|
||||||
# include <stdio.h>
|
|
||||||
# include <stdlib.h>
|
|
||||||
# include <unistd.h>
|
|
||||||
# include <fcntl.h>
|
|
||||||
|
|
||||||
struct s_data;
|
|
||||||
typedef struct s_data t_data;
|
|
||||||
|
|
||||||
typedef struct s_textures
|
|
||||||
{
|
|
||||||
char *north;
|
|
||||||
char *south;
|
|
||||||
char *east;
|
|
||||||
char *west;
|
|
||||||
int floor[3];
|
|
||||||
int ceiling[3];
|
|
||||||
} t_textures;
|
|
||||||
|
|
||||||
typedef struct s_data_parsing
|
|
||||||
{
|
|
||||||
char **raw_map;
|
|
||||||
int fd_map;
|
|
||||||
int fd_map_dup;
|
|
||||||
int player[3];
|
|
||||||
} t_data_parsing;
|
|
||||||
//player -> 0 = x, 1 = y, 2 = head
|
|
||||||
|
|
||||||
//parsing
|
|
||||||
int parsing(t_data *data);
|
|
||||||
|
|
||||||
//check_file
|
|
||||||
int check_extension(char *map_path);
|
|
||||||
int check_file(char *map_path, t_data_parsing *parsing);
|
|
||||||
|
|
||||||
//get_map
|
|
||||||
int get_map(t_data *data);
|
|
||||||
int line_counter(int fd);
|
|
||||||
int put_map_on_array(t_data *data);
|
|
||||||
char *clean_line(char *raw_line);
|
|
||||||
|
|
||||||
//init_parsing
|
|
||||||
int init_parsing(t_data_parsing *parsing);
|
|
||||||
int init_textures(t_textures *textures);
|
|
||||||
int free_textures(t_textures *textures);
|
|
||||||
|
|
||||||
//line_detect
|
|
||||||
int is_config_line(char *line);
|
|
||||||
int is_empty_line(char *line);
|
|
||||||
int is_texture_line(char *line);
|
|
||||||
int is_color_line(char *line);
|
|
||||||
int check_extension_2(char *str);
|
|
||||||
|
|
||||||
//get_textures
|
|
||||||
int get_texture_path(char *line, t_textures *texture, int *j);
|
|
||||||
int validate_and_convert_rgb(char **parts, int rgb[3]);
|
|
||||||
int get_rgb_values(char *line, int rgb[3]);
|
|
||||||
int is_valid_number(char *str);
|
|
||||||
|
|
||||||
//check_colors
|
|
||||||
int check_colors(t_textures *texture);
|
|
||||||
int is_rgb(int color[3]);
|
|
||||||
|
|
||||||
// check_map
|
|
||||||
int check_map_char(char **map);
|
|
||||||
void find_player_pos(char **map, int *player);
|
|
||||||
int flood_fill(char **map_cp, int x, int y);
|
|
||||||
int rep_ex_wall(char **map_cp, int x, int y);
|
|
||||||
int check_char_and_count(char c, int *p);
|
|
||||||
|
|
||||||
//check_map_2
|
|
||||||
int hasivalidchar(char **map);
|
|
||||||
int validate_map(char **map, int *player);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
@ -0,0 +1,46 @@
|
||||||
|
// input.c
|
||||||
|
#include "cub3d.h"
|
||||||
|
#ifdef __APPLE__
|
||||||
|
# define KEY_ESC 53
|
||||||
|
# define KEY_W 13
|
||||||
|
# define KEY_A 0
|
||||||
|
# define KEY_S 1
|
||||||
|
# define KEY_D 2
|
||||||
|
# define KEY_LEFT 123
|
||||||
|
# define KEY_RIGHT 124
|
||||||
|
#else
|
||||||
|
# define KEY_ESC 65307
|
||||||
|
# define KEY_W 119
|
||||||
|
# define KEY_A 97
|
||||||
|
# define KEY_S 115
|
||||||
|
# define KEY_D 100
|
||||||
|
# define KEY_LEFT 65361
|
||||||
|
# define KEY_RIGHT 65363
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int key_press(int key, t_app *a){
|
||||||
|
if (key == KEY_ESC) close_win(a);
|
||||||
|
if (key == KEY_W) a->keys.w = true;
|
||||||
|
if (key == KEY_S) a->keys.s = true;
|
||||||
|
if (key == KEY_A) a->keys.a = true;
|
||||||
|
if (key == KEY_D) a->keys.d = true;
|
||||||
|
if (key == KEY_LEFT) a->keys.left = true;
|
||||||
|
if (key == KEY_RIGHT) a->keys.right = true;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
int key_release(int key, t_app *a){
|
||||||
|
if (key == KEY_W) a->keys.w = false;
|
||||||
|
if (key == KEY_S) a->keys.s = false;
|
||||||
|
if (key == KEY_A) a->keys.a = false;
|
||||||
|
if (key == KEY_D) a->keys.d = false;
|
||||||
|
if (key == KEY_LEFT) a->keys.left = false;
|
||||||
|
if (key == KEY_RIGHT) a->keys.right = false;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
int close_win(t_app *a){
|
||||||
|
if (a->zbuf) free(a->zbuf);
|
||||||
|
if (a->frame.ptr) mlx_destroy_image(a->mlx, a->frame.ptr);
|
||||||
|
if (a->win) mlx_destroy_window(a->mlx, a->win);
|
||||||
|
exit(0);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
@ -1,68 +0,0 @@
|
||||||
# **************************************************************************** #
|
|
||||||
# #
|
|
||||||
# ::: :::::::: #
|
|
||||||
# Makefile :+: :+: :+: #
|
|
||||||
# +:+ +:+ +:+ #
|
|
||||||
# By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ #
|
|
||||||
# +#+#+#+#+#+ +#+ #
|
|
||||||
# Created: 2024/05/19 12:59:31 by lfirmin #+# #+# #
|
|
||||||
# Updated: 2025/04/19 11:53:48 by lfirmin ### ########.fr #
|
|
||||||
# #
|
|
||||||
# **************************************************************************** #
|
|
||||||
|
|
||||||
NAME = libft.a
|
|
||||||
HEADER = ./include
|
|
||||||
SRCS_DIR = ./srcs/
|
|
||||||
SRC = ft_isalnum.c ft_isprint.c ft_memcmp.c ft_putchar_fd.c ft_split.c \
|
|
||||||
ft_strlcat.c ft_strncmp.c ft_substr.c ft_atoi.c ft_isalpha.c \
|
|
||||||
ft_itoa.c ft_memcpy.c ft_putendl_fd.c ft_strchr.c ft_strlcpy.c \
|
|
||||||
ft_strnstr.c ft_tolower.c ft_bzero.c ft_isascii.c ft_strtrim.c \
|
|
||||||
ft_memmove.c ft_putnbr_fd.c ft_strdup.c ft_strlen.c ft_strrchr.c \
|
|
||||||
ft_toupper.c ft_calloc.c ft_isdigit.c ft_memchr.c ft_memset.c \
|
|
||||||
ft_putstr_fd.c ft_strjoin.c ft_strmapi.c ft_striteri.c \
|
|
||||||
ft_lstnew_bonus.c ft_lstadd_front_bonus.c ft_lstsize_bonus.c \
|
|
||||||
ft_lstlast_bonus.c ft_lstadd_back_bonus.c ft_lstdelone_bonus.c \
|
|
||||||
ft_lstclear_bonus.c ft_lstiter_bonus.c ft_lstmap_bonus.c ft_strcmp.c \
|
|
||||||
ft_atoll.c ft_straddchar.c ft_strcpy.c ft_arrcpy.c
|
|
||||||
|
|
||||||
SRCS = $(addprefix $(SRCS_DIR), $(SRC))
|
|
||||||
CC = cc
|
|
||||||
CFLAGS = -Wall -Wextra -Werror -g3
|
|
||||||
INCLUDE = -I $(HEADER)
|
|
||||||
OBJ_DIR = obj/
|
|
||||||
OBJ = $(addprefix $(OBJ_DIR), $(SRC:.c=.o))
|
|
||||||
|
|
||||||
GREEN = \033[0;32m
|
|
||||||
YELLOW = \033[0;33m
|
|
||||||
RESET = \033[0m
|
|
||||||
WHITE = \033[0;97m
|
|
||||||
|
|
||||||
LOADING_CHARS = ⠋ ⠙ ⠹ ⠸ ⠼ ⠴ ⠦ ⠧ ⠇ ⠏
|
|
||||||
|
|
||||||
all: $(NAME)
|
|
||||||
|
|
||||||
$(NAME): $(OBJ)
|
|
||||||
@printf "$(YELLOW)Compiling libft, Please wait...$(RESET)"
|
|
||||||
@for char in $(LOADING_CHARS); do \
|
|
||||||
printf "\r$(YELLOW)Compiling libft, Please wait... $$char$(RESET)"; \
|
|
||||||
sleep 0.1; \
|
|
||||||
done
|
|
||||||
@ar rc $(NAME) $(OBJ)
|
|
||||||
@ranlib $(NAME)
|
|
||||||
@printf "\r$(GREEN)Great news ! $(WHITE)Libft compiled successfully ! $(RESET)\n"
|
|
||||||
|
|
||||||
$(OBJ_DIR)%.o: $(SRCS_DIR)%.c
|
|
||||||
@mkdir -p $(OBJ_DIR)
|
|
||||||
@$(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@
|
|
||||||
|
|
||||||
clean:
|
|
||||||
@rm -rf $(OBJ_DIR)
|
|
||||||
@printf "$(WHITE)Clean process completed for $(GREEN)Libft.$(RESET)\n"
|
|
||||||
|
|
||||||
fclean: clean
|
|
||||||
@rm -f $(NAME)
|
|
||||||
@printf "$(WHITE)Full clean process completed for $(GREEN)Libft.$(RESET)\n"
|
|
||||||
|
|
||||||
re: fclean all
|
|
||||||
|
|
||||||
.PHONY: all clean fclean re
|
|
||||||
|
|
@ -1,55 +0,0 @@
|
||||||
# Libft - 42 Project
|
|
||||||
|
|
||||||
## Description
|
|
||||||
Libft is the first project at 42 school. The aim is to recreate various standard C library functions, as well as additional functions that will be useful throughout the cursus. This library will be used in most of the future 42 projects.
|
|
||||||
|
|
||||||
## Functions
|
|
||||||
|
|
||||||
### Libc Functions
|
|
||||||
`ft_isalpha` • `ft_isdigit` • `ft_isalnum` • `ft_isascii` • `ft_isprint` • `ft_strlen` • `ft_memset` • `ft_bzero` • `ft_memcpy` • `ft_memmove` • `ft_strlcpy` • `ft_strlcat` • `ft_toupper` • `ft_tolower` • `ft_strchr` • `ft_strrchr` • `ft_strncmp` • `ft_memchr` • `ft_memcmp` • `ft_strnstr` • `ft_atoi` • `ft_calloc` • `ft_strdup`
|
|
||||||
|
|
||||||
### Additional Functions
|
|
||||||
`ft_substr` • `ft_strjoin` • `ft_strtrim` • `ft_split` • `ft_itoa` • `ft_strmapi` • `ft_striteri` • `ft_putchar_fd` • `ft_putstr_fd` • `ft_putendl_fd` • `ft_putnbr_fd`
|
|
||||||
|
|
||||||
### Bonus Functions
|
|
||||||
`ft_lstnew` • `ft_lstadd_front` • `ft_lstsize` • `ft_lstlast` • `ft_lstadd_back` • `ft_lstdelone` • `ft_lstclear` • `ft_lstiter` • `ft_lstmap`
|
|
||||||
|
|
||||||
## Getting Started
|
|
||||||
|
|
||||||
### Prerequisites
|
|
||||||
- GCC compiler
|
|
||||||
- Make
|
|
||||||
|
|
||||||
### Usage
|
|
||||||
1. Include the header in your source file:
|
|
||||||
```c
|
|
||||||
#include "libft.h"
|
|
||||||
```
|
|
||||||
|
|
||||||
### Compilation
|
|
||||||
1. Compilation:
|
|
||||||
```bash
|
|
||||||
make
|
|
||||||
```
|
|
||||||
|
|
||||||
## Cleaning
|
|
||||||
- Remove object files:
|
|
||||||
```bash
|
|
||||||
make clean
|
|
||||||
```
|
|
||||||
|
|
||||||
- Remove object files and library:
|
|
||||||
```bash
|
|
||||||
make fclean
|
|
||||||
```
|
|
||||||
|
|
||||||
- Recompile everything:
|
|
||||||
```bash
|
|
||||||
make re
|
|
||||||
```
|
|
||||||
|
|
||||||
## Testing
|
|
||||||
This project doesn't come with unit tests, but you can use external testers:
|
|
||||||
- [libft-unit-test](https://github.com/alelievr/libft-unit-test)
|
|
||||||
- [libft-war-machine](https://github.com/ska42/libft-war-machine)
|
|
||||||
- [Tripouille/libfTester](https://github.com/Tripouille/libftTester)
|
|
||||||
|
|
@ -1,93 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* libft.h :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2024/05/21 11:19:08 by lfirmin #+# #+# */
|
|
||||||
/* Updated: 2025/04/19 11:56:03 by lfirmin ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#ifndef LIBFT_H
|
|
||||||
# define LIBFT_H
|
|
||||||
|
|
||||||
# include <stdlib.h>
|
|
||||||
# include <string.h>
|
|
||||||
# include <stddef.h>
|
|
||||||
# include <stdio.h>
|
|
||||||
# include <unistd.h>
|
|
||||||
# include <limits.h>
|
|
||||||
|
|
||||||
typedef struct v
|
|
||||||
{
|
|
||||||
char **array;
|
|
||||||
int i;
|
|
||||||
int j;
|
|
||||||
int start;
|
|
||||||
int end;
|
|
||||||
} t_split_struct;
|
|
||||||
|
|
||||||
typedef struct s_list
|
|
||||||
{
|
|
||||||
void *content;
|
|
||||||
struct s_list *next;
|
|
||||||
} t_list;
|
|
||||||
|
|
||||||
int ft_isalnum(int c);
|
|
||||||
int ft_isalpha(int c);
|
|
||||||
int ft_isascii(int c);
|
|
||||||
int ft_isdigit(int c);
|
|
||||||
int ft_isprint(int c);
|
|
||||||
int ft_atoi(const char *str);
|
|
||||||
int ft_memcmp(const void *ptr1, const void *ptr2, size_t num);
|
|
||||||
int ft_strncmp(const char *s1, const char *s2, unsigned int n);
|
|
||||||
int ft_toupper(int c);
|
|
||||||
int ft_tolower(int c);
|
|
||||||
int ft_lstsize(t_list *lst);
|
|
||||||
int ft_strcmp(char *s1, char *s2);
|
|
||||||
long long ft_atoll(const char *str);
|
|
||||||
|
|
||||||
size_t ft_strlen(const char *s);
|
|
||||||
size_t ft_strlcat(char *dst, const char *src, size_t size);
|
|
||||||
size_t ft_strlcpy(char *dst, const char *src, size_t dsts);
|
|
||||||
|
|
||||||
void *ft_bzero(void *s, size_t n);
|
|
||||||
void *ft_calloc(size_t count, size_t n);
|
|
||||||
void *ft_memchr(const void *s, int c, size_t n);
|
|
||||||
void *ft_memcpy(void *dest, const void *src, size_t len);
|
|
||||||
void *ft_memset(void *b, int c, size_t len);
|
|
||||||
void *ft_memmove(void *s1, const void *s2, size_t len);
|
|
||||||
void *ft_memset(void *str, int c, size_t n);
|
|
||||||
void ft_putchar_fd(char c, int fd);
|
|
||||||
void ft_putstr_fd(char *s, int fd);
|
|
||||||
void ft_putendl_fd(char *s, int fd);
|
|
||||||
void ft_putnbr_fd(int n, int fd);
|
|
||||||
void ft_striteri(char *s, void (*f)(unsigned int, char*));
|
|
||||||
void ft_lstadd_front(t_list **lst, t_list *new);
|
|
||||||
void ft_lstadd_back(t_list **lst, t_list *new);
|
|
||||||
void ft_lstdelone(t_list *lst, void (*del)(void*));
|
|
||||||
void ft_lstclear(t_list **lst, void (*del)(void*));
|
|
||||||
void ft_lstiter(t_list *lst, void (*f)(void *));
|
|
||||||
|
|
||||||
char *ft_strchr(char const *str, int c);
|
|
||||||
char *ft_strdup(const char *src);
|
|
||||||
char *ft_strjoin(const char *s1, const char *s2);
|
|
||||||
char *ft_strnstr(const char *hay, const char *need, size_t len);
|
|
||||||
char *ft_strrchr(const char *str, int c);
|
|
||||||
char *ft_strtrim(char const *s1, char const *set);
|
|
||||||
char *ft_substr(char const *s, unsigned int start, size_t len);
|
|
||||||
char **ft_split(char const *s, char c);
|
|
||||||
char *ft_strmapi(char const *s, char (*f)(unsigned int, char));
|
|
||||||
char *ft_itoa(int n);
|
|
||||||
char *ft_straddchar(char *str, char c);
|
|
||||||
char *ft_strcpy(char *dest, char *src);
|
|
||||||
char **ft_arrcpy(char **array);
|
|
||||||
|
|
||||||
t_list *ft_lstnew(void *content);
|
|
||||||
t_list *ft_lstlast(t_list *lst);
|
|
||||||
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), \
|
|
||||||
void (*del)(void *));
|
|
||||||
|
|
||||||
#endif
|
|
||||||
BIN
libft/libft.a
BIN
libft/libft.a
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -1,41 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_arrcpy.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: lfirmin <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2024/05/21 02:18:17 by lfirmin #+# #+# */
|
|
||||||
/* Updated: 2025/10/06 14:06:37 by lfirmin ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
char **ft_arrcpy(char **array)
|
|
||||||
{
|
|
||||||
char **copy;
|
|
||||||
int i;
|
|
||||||
int len;
|
|
||||||
|
|
||||||
len = 0;
|
|
||||||
while (array[len])
|
|
||||||
len++;
|
|
||||||
copy = malloc(sizeof(char *) * (len + 1));
|
|
||||||
if (!copy)
|
|
||||||
return (NULL);
|
|
||||||
i = 0;
|
|
||||||
while (i < len)
|
|
||||||
{
|
|
||||||
copy[i] = strdup(array[i]);
|
|
||||||
if (!copy[i])
|
|
||||||
{
|
|
||||||
while (i > 0)
|
|
||||||
free(copy[--i]);
|
|
||||||
free(copy);
|
|
||||||
return (NULL);
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
copy[i] = NULL;
|
|
||||||
return (copy);
|
|
||||||
}
|
|
||||||
|
|
@ -1,40 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_atoi.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: lfirmin <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2024/05/21 10:09:46 by lfirmin #+# #+# */
|
|
||||||
/* Updated: 2024/06/03 21:02:02 by lfirmin ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
int ft_atoi(const char *str)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
int s;
|
|
||||||
int m;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
s = 0;
|
|
||||||
m = 0;
|
|
||||||
while ((str[i] <= 13 && str[i] >= 9) || str[i] == 32)
|
|
||||||
i++;
|
|
||||||
while (str[i] == '-' || str[i] == '+')
|
|
||||||
{
|
|
||||||
s++;
|
|
||||||
if (s >= 2)
|
|
||||||
return (0);
|
|
||||||
if (str[i] == '-')
|
|
||||||
m++;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
s = 0;
|
|
||||||
while (str[i] >= 48 && str[i] <= 57)
|
|
||||||
s = s * 10 + (str[i++] - 48);
|
|
||||||
if (m % 2 == 1)
|
|
||||||
s = s * -1;
|
|
||||||
return (s);
|
|
||||||
}
|
|
||||||
|
|
@ -1,38 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_atoll.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2024/11/03 17:25:06 by lfirmin #+# #+# */
|
|
||||||
/* Updated: 2024/11/03 17:25:33 by lfirmin ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
long long ft_atoll(const char *str)
|
|
||||||
{
|
|
||||||
long long result;
|
|
||||||
int sign;
|
|
||||||
|
|
||||||
result = 0;
|
|
||||||
sign = 1;
|
|
||||||
while (*str == ' ' || (*str >= 9 && *str <= 13))
|
|
||||||
str++;
|
|
||||||
if (*str == '-' || *str == '+')
|
|
||||||
{
|
|
||||||
if (*str == '-')
|
|
||||||
sign = -1;
|
|
||||||
str++;
|
|
||||||
}
|
|
||||||
while (*str >= '0' && *str <= '9')
|
|
||||||
{
|
|
||||||
if (result > INT_MAX || result < INT_MIN)
|
|
||||||
return (2147483648);
|
|
||||||
result = result * 10 + (*str - '0');
|
|
||||||
str++;
|
|
||||||
}
|
|
||||||
return (result * sign);
|
|
||||||
}
|
|
||||||
|
|
@ -1,24 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_bzero.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: lfirmin <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2024/05/21 00:20:00 by lfirmin #+# #+# */
|
|
||||||
/* Updated: 2024/05/30 19:49:23 by lfirmin ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void *ft_bzero(void *b, size_t len)
|
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
unsigned char *r;
|
|
||||||
|
|
||||||
r = (unsigned char *)b;
|
|
||||||
i = 0;
|
|
||||||
while (i < len)
|
|
||||||
r[i++] = '\0';
|
|
||||||
return (b);
|
|
||||||
}
|
|
||||||
|
|
@ -1,31 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_calloc.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: lfirmin <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2024/05/21 11:14:02 by lfirmin #+# #+# */
|
|
||||||
/* Updated: 2024/06/03 18:15:05 by lfirmin ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void *ft_calloc(size_t c, size_t s)
|
|
||||||
{
|
|
||||||
void *ptr;
|
|
||||||
long long int tmp1;
|
|
||||||
long long int tmp2;
|
|
||||||
|
|
||||||
tmp1 = (long long int)c;
|
|
||||||
tmp2 = (long long int)s;
|
|
||||||
if ((c > 4294967295 || s > 4294967295) && (tmp1 < 0 && tmp2 < 0))
|
|
||||||
return (NULL);
|
|
||||||
if (tmp1 * tmp2 < 0)
|
|
||||||
return (NULL);
|
|
||||||
ptr = malloc(c * s);
|
|
||||||
if (!ptr)
|
|
||||||
return (NULL);
|
|
||||||
ft_bzero(ptr, c * s);
|
|
||||||
return (ptr);
|
|
||||||
}
|
|
||||||
|
|
@ -1,19 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_isalnum.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2024/05/20 02:29:49 by lfirmin #+# #+# */
|
|
||||||
/* Updated: 2024/05/22 09:59:44 by lfirmin ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
int ft_isalnum(int c)
|
|
||||||
{
|
|
||||||
if ((c >= 97 && c <= 122) || (c >= 48 && c <= 57) || (c >= 65 && c <= 90))
|
|
||||||
return (1);
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
@ -1,19 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_isalpha.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2024/05/20 01:55:52 by lfirmin #+# #+# */
|
|
||||||
/* Updated: 2024/05/22 09:59:44 by lfirmin ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
int ft_isalpha(int c)
|
|
||||||
{
|
|
||||||
if ((c >= 97 && c <= 122) || (c >= 65 && c <= 90))
|
|
||||||
return (1);
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
@ -1,19 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_isascii.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2024/05/20 02:36:17 by lfirmin #+# #+# */
|
|
||||||
/* Updated: 2024/05/22 09:59:44 by lfirmin ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
int ft_isascii(int c)
|
|
||||||
{
|
|
||||||
if (c >= 0 && c <= 127)
|
|
||||||
return (1);
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
@ -1,19 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_isdigit.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2024/05/20 02:31:51 by lfirmin #+# #+# */
|
|
||||||
/* Updated: 2024/05/22 09:59:44 by lfirmin ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
int ft_isdigit(int c)
|
|
||||||
{
|
|
||||||
if (c >= 48 && c <= 57)
|
|
||||||
return (1);
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
@ -1,19 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_isprint.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2024/05/20 02:38:24 by lfirmin #+# #+# */
|
|
||||||
/* Updated: 2024/05/23 06:21:54 by lfirmin ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
int ft_isprint(int c)
|
|
||||||
{
|
|
||||||
if (((c >= 0 && c <= 31) || c >= 127 || c == EOF))
|
|
||||||
return (0);
|
|
||||||
return (1);
|
|
||||||
}
|
|
||||||
|
|
@ -1,51 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_itoa.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2024/05/24 12:59:00 by lfirmin #+# #+# */
|
|
||||||
/* Updated: 2024/05/29 10:31:36 by lfirmin ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
static size_t ft_count(long int n)
|
|
||||||
{
|
|
||||||
size_t c;
|
|
||||||
|
|
||||||
c = 0;
|
|
||||||
if (n <= 0)
|
|
||||||
c = 1;
|
|
||||||
while (n != 0)
|
|
||||||
{
|
|
||||||
n = n / 10;
|
|
||||||
c++;
|
|
||||||
}
|
|
||||||
return (c);
|
|
||||||
}
|
|
||||||
|
|
||||||
char *ft_itoa(int n)
|
|
||||||
{
|
|
||||||
char *str;
|
|
||||||
size_t size;
|
|
||||||
long int num;
|
|
||||||
|
|
||||||
num = n;
|
|
||||||
size = ft_count(num);
|
|
||||||
str = (char *)malloc(size + 1);
|
|
||||||
if (!str)
|
|
||||||
return (NULL);
|
|
||||||
str[size] = '\0';
|
|
||||||
if (num < 0)
|
|
||||||
num = -num;
|
|
||||||
while (size--)
|
|
||||||
{
|
|
||||||
str[size] = num % 10 + '0';
|
|
||||||
num = num / 10;
|
|
||||||
if (n < 0 && size == 0)
|
|
||||||
str[size] = '-';
|
|
||||||
}
|
|
||||||
return (str);
|
|
||||||
}
|
|
||||||
|
|
@ -1,27 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_lstadd_back.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2024/06/01 02:01:18 by lfirmin #+# #+# */
|
|
||||||
/* Updated: 2024/06/03 15:59:33 by lfirmin ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void ft_lstadd_back(t_list **lst, t_list *new)
|
|
||||||
{
|
|
||||||
t_list *last;
|
|
||||||
|
|
||||||
if (!new)
|
|
||||||
return ;
|
|
||||||
if (!lst || !*lst)
|
|
||||||
{
|
|
||||||
*lst = new;
|
|
||||||
return ;
|
|
||||||
}
|
|
||||||
last = ft_lstlast(*lst);
|
|
||||||
last->next = new;
|
|
||||||
}
|
|
||||||
|
|
@ -1,21 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_lstadd_front.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2024/05/31 20:34:57 by lfirmin #+# #+# */
|
|
||||||
/* Updated: 2024/05/31 20:41:34 by lfirmin ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void ft_lstadd_front(t_list **lst, t_list *new)
|
|
||||||
{
|
|
||||||
if (lst && new)
|
|
||||||
{
|
|
||||||
new->next = *lst;
|
|
||||||
*lst = new;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,28 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_lstclear.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2024/06/01 20:46:07 by lfirmin #+# #+# */
|
|
||||||
/* Updated: 2024/06/01 20:51:07 by lfirmin ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void ft_lstclear(t_list **lst, void (*del)(void*))
|
|
||||||
{
|
|
||||||
t_list *t;
|
|
||||||
|
|
||||||
if (lst)
|
|
||||||
{
|
|
||||||
while (*lst)
|
|
||||||
{
|
|
||||||
t = (*lst)->next;
|
|
||||||
ft_lstdelone(*lst, del);
|
|
||||||
(*lst) = t;
|
|
||||||
}
|
|
||||||
(*lst) = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,20 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_lstdelone.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2024/06/01 20:32:56 by lfirmin #+# #+# */
|
|
||||||
/* Updated: 2024/06/01 20:32:56 by lfirmin ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void ft_lstdelone(t_list *lst, void (*del)(void*))
|
|
||||||
{
|
|
||||||
if (!lst || !del)
|
|
||||||
return ;
|
|
||||||
del(lst->content);
|
|
||||||
free(lst);
|
|
||||||
}
|
|
||||||
|
|
@ -1,23 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_lstiter.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2024/06/01 21:05:12 by lfirmin #+# #+# */
|
|
||||||
/* Updated: 2024/06/01 21:05:12 by lfirmin ### ########.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,23 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_lstlast.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2024/06/01 01:52:09 by lfirmin #+# #+# */
|
|
||||||
/* Updated: 2024/06/01 01:57:22 by lfirmin ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
t_list *ft_lstlast(t_list *lst)
|
|
||||||
{
|
|
||||||
while (lst)
|
|
||||||
{
|
|
||||||
if (!lst->next)
|
|
||||||
return (lst);
|
|
||||||
lst = lst->next;
|
|
||||||
}
|
|
||||||
return (lst);
|
|
||||||
}
|
|
||||||
|
|
@ -1,41 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_lstmap.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2024/06/02 18:21:09 by lfirmin #+# #+# */
|
|
||||||
/* Updated: 2024/06/03 15:53:13 by lfirmin ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *))
|
|
||||||
{
|
|
||||||
t_list *new;
|
|
||||||
t_list *save;
|
|
||||||
|
|
||||||
if (!lst || !del || !f)
|
|
||||||
return (NULL);
|
|
||||||
new = ft_lstnew(lst->content);
|
|
||||||
if (!new)
|
|
||||||
return (NULL);
|
|
||||||
new->content = f(new->content);
|
|
||||||
save = new;
|
|
||||||
lst = lst->next;
|
|
||||||
while (lst)
|
|
||||||
{
|
|
||||||
new->next = ft_lstnew(lst->content);
|
|
||||||
if (!new->next)
|
|
||||||
{
|
|
||||||
ft_lstclear(&save, del);
|
|
||||||
return (NULL);
|
|
||||||
}
|
|
||||||
new->next->content = f(new->next->content);
|
|
||||||
new = new->next;
|
|
||||||
lst = lst->next;
|
|
||||||
}
|
|
||||||
new->next = NULL;
|
|
||||||
return (save);
|
|
||||||
}
|
|
||||||
|
|
@ -1,24 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_lstnew.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2024/05/31 18:41:23 by lfirmin #+# #+# */
|
|
||||||
/* Updated: 2024/05/31 20:33:26 by lfirmin ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
t_list *ft_lstnew(void *content)
|
|
||||||
{
|
|
||||||
t_list *new;
|
|
||||||
|
|
||||||
new = (t_list *)malloc(sizeof(*new));
|
|
||||||
if (!new)
|
|
||||||
return (NULL);
|
|
||||||
new->content = content;
|
|
||||||
new->next = NULL;
|
|
||||||
return (new);
|
|
||||||
}
|
|
||||||
|
|
@ -1,27 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_lstsize.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2024/05/31 22:00:49 by lfirmin #+# #+# */
|
|
||||||
/* Updated: 2024/05/31 22:12:17 by lfirmin ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
int ft_lstsize(t_list *lst)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
t_list *count;
|
|
||||||
|
|
||||||
count = lst;
|
|
||||||
i = 0;
|
|
||||||
while (count)
|
|
||||||
{
|
|
||||||
count = count->next;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return (i);
|
|
||||||
}
|
|
||||||
|
|
@ -1,26 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_memchr.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: lfirmin <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2024/05/21 07:40:39 by lfirmin #+# #+# */
|
|
||||||
/* Updated: 2024/05/22 09:59:44 by lfirmin ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void *ft_memchr(const void *s, int c, size_t n)
|
|
||||||
{
|
|
||||||
unsigned char *str;
|
|
||||||
|
|
||||||
str = (unsigned char *)s;
|
|
||||||
while (n--)
|
|
||||||
{
|
|
||||||
if (*str == (unsigned char)c)
|
|
||||||
return (str);
|
|
||||||
str++;
|
|
||||||
}
|
|
||||||
return (NULL);
|
|
||||||
}
|
|
||||||
|
|
@ -1,30 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_memcmp.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: lfirmin <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2024/05/21 07:57:58 by lfirmin #+# #+# */
|
|
||||||
/* Updated: 2024/05/22 11:34:35 by lfirmin ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
int ft_memcmp(const void *ptr1, const void *ptr2, size_t num)
|
|
||||||
{
|
|
||||||
unsigned char *pt1;
|
|
||||||
unsigned char *pt2;
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
pt1 = (unsigned char *)ptr1;
|
|
||||||
pt2 = (unsigned char *)ptr2;
|
|
||||||
i = 0;
|
|
||||||
while (i < num)
|
|
||||||
{
|
|
||||||
if (pt1[i] != pt2[i])
|
|
||||||
return (pt1[i] - pt2[i]);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
@ -1,32 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_memcpy.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: tordner <tordner@student.42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2024/05/21 01:08:31 by lfirmin #+# #+# */
|
|
||||||
/* Updated: 2025/06/02 00:40:39 by tordner ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void *ft_memcpy(void *dest, const void *src, size_t len)
|
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
unsigned char *r;
|
|
||||||
unsigned char *s;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
r = (unsigned char *)dest;
|
|
||||||
s = (unsigned char *)src;
|
|
||||||
if (dest == (void *)0 && src == (void *)0)
|
|
||||||
return (dest);
|
|
||||||
while (i < len)
|
|
||||||
{
|
|
||||||
r[i] = s[i];
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return (dest);
|
|
||||||
}
|
|
||||||
|
|
@ -1,39 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_memmov.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: lfirmin <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2024/05/21 01:26:13 by lfirmin #+# #+# */
|
|
||||||
/* Updated: 2024/05/22 09:59:44 by lfirmin ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void *ft_memmove(void *s1, const void *s2, size_t len)
|
|
||||||
{
|
|
||||||
unsigned char *dest;
|
|
||||||
unsigned char *src;
|
|
||||||
unsigned int i;
|
|
||||||
|
|
||||||
dest = (unsigned char *)s1;
|
|
||||||
src = (unsigned char *)s2;
|
|
||||||
i = 0;
|
|
||||||
if (dest == NULL && src == NULL)
|
|
||||||
return (NULL);
|
|
||||||
if (dest < src)
|
|
||||||
{
|
|
||||||
while (i < len)
|
|
||||||
{
|
|
||||||
dest[i] = src[i];
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
while (0 < len--)
|
|
||||||
dest[len] = src[len];
|
|
||||||
}
|
|
||||||
return (dest);
|
|
||||||
}
|
|
||||||
|
|
@ -1,24 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_memset.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2024/05/20 02:42:40 by lfirmin #+# #+# */
|
|
||||||
/* Updated: 2024/05/22 09:59:44 by lfirmin ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void *ft_memset(void *b, int c, size_t len)
|
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
unsigned char *r;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
r = (unsigned char *)b;
|
|
||||||
while (i < len)
|
|
||||||
r[i++] = (unsigned char)c;
|
|
||||||
return (b);
|
|
||||||
}
|
|
||||||
|
|
@ -1,17 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_putchar_fd.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2024/05/29 11:17:45 by lfirmin #+# #+# */
|
|
||||||
/* Updated: 2024/05/29 11:20:42 by lfirmin ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void ft_putchar_fd(char c, int fd)
|
|
||||||
{
|
|
||||||
write(fd, &c, 1);
|
|
||||||
}
|
|
||||||
|
|
@ -1,18 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_putendl_fd.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2024/05/29 11:35:44 by lfirmin #+# #+# */
|
|
||||||
/* Updated: 2024/05/29 11:38:36 by lfirmin ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void ft_putendl_fd(char *s, int fd)
|
|
||||||
{
|
|
||||||
ft_putstr_fd(s, fd);
|
|
||||||
ft_putchar_fd('\n', fd);
|
|
||||||
}
|
|
||||||
|
|
@ -1,31 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_putnbr_fd.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2024/05/29 11:42:38 by lfirmin #+# #+# */
|
|
||||||
/* Updated: 2024/05/29 11:56:04 by lfirmin ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void ft_putnbr_fd(int n, int fd)
|
|
||||||
{
|
|
||||||
long int nb;
|
|
||||||
|
|
||||||
nb = n;
|
|
||||||
if (nb < 0)
|
|
||||||
{
|
|
||||||
nb = -nb;
|
|
||||||
ft_putchar_fd('-', fd);
|
|
||||||
}
|
|
||||||
if (nb >= 10)
|
|
||||||
{
|
|
||||||
ft_putnbr_fd(nb / 10, fd);
|
|
||||||
ft_putnbr_fd(nb % 10, fd);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
ft_putchar_fd(nb + '0', fd);
|
|
||||||
}
|
|
||||||
|
|
@ -1,24 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_putstr_fd.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2024/05/29 11:27:05 by lfirmin #+# #+# */
|
|
||||||
/* Updated: 2024/05/29 11:33:18 by lfirmin ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void ft_putstr_fd(char *s, int fd)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
while (s[i])
|
|
||||||
{
|
|
||||||
ft_putchar_fd(s[i], fd);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,95 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_split.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2024/05/22 05:56:37 by lfirmin #+# #+# */
|
|
||||||
/* Updated: 2024/06/04 12:08:51 by lfirmin ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
static int ft_c(char const *s, char c)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
int count;
|
|
||||||
|
|
||||||
count = 0;
|
|
||||||
i = 0;
|
|
||||||
while (s[i])
|
|
||||||
{
|
|
||||||
if (s[i] != c && (i == 0 || s[i - 1] == c))
|
|
||||||
count++;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return (count);
|
|
||||||
}
|
|
||||||
|
|
||||||
void init_split_struct(t_split_struct *v, char const *s, char c)
|
|
||||||
{
|
|
||||||
if (!s)
|
|
||||||
return ;
|
|
||||||
v->array = (char **)malloc((ft_c(s, c) + 1) * sizeof(char *));
|
|
||||||
if (!s || !v->array)
|
|
||||||
return ;
|
|
||||||
v->i = 0;
|
|
||||||
v->j = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static char *ft_strncpy(char *dest, const 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
char **free_split(char **array, size_t j)
|
|
||||||
{
|
|
||||||
while (j > 0)
|
|
||||||
{
|
|
||||||
free(array[--j]);
|
|
||||||
}
|
|
||||||
free(array);
|
|
||||||
return (NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
char **ft_split(char const *s, char c)
|
|
||||||
{
|
|
||||||
t_split_struct v;
|
|
||||||
|
|
||||||
init_split_struct(&v, s, c);
|
|
||||||
if (!s || !v.array)
|
|
||||||
return (NULL);
|
|
||||||
while (s[v.i])
|
|
||||||
{
|
|
||||||
while (s[v.i] == c && s[v.i])
|
|
||||||
v.i++;
|
|
||||||
v.start = v.i;
|
|
||||||
while (s[v.i] != c && s[v.i])
|
|
||||||
v.i++;
|
|
||||||
if (v.i > v.start)
|
|
||||||
{
|
|
||||||
v.array[v.j] = (char *)malloc(v.i - v.start + 1);
|
|
||||||
if (!v.array[v.j])
|
|
||||||
return (free_split(v.array, v.j));
|
|
||||||
ft_strncpy(v.array[v.j], &s[v.start], v.i - v.start);
|
|
||||||
v.array[v.j][v.i - v.start] = '\0';
|
|
||||||
v.j++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
v.array[v.j] = NULL;
|
|
||||||
return (v.array);
|
|
||||||
}
|
|
||||||
|
|
@ -1,37 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_straddchar.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2024/11/08 06:02:17 by lfirmin #+# #+# */
|
|
||||||
/* Updated: 2024/11/08 06:02:17 by lfirmin ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
char *ft_straddchar(char *str, char c)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
char *res;
|
|
||||||
|
|
||||||
if (!str)
|
|
||||||
return (NULL);
|
|
||||||
i = 0;
|
|
||||||
while (str[i])
|
|
||||||
i++;
|
|
||||||
res = (char *)malloc(sizeof(char) * (i + 2));
|
|
||||||
if (!res)
|
|
||||||
return (NULL);
|
|
||||||
i = 0;
|
|
||||||
while (str[i])
|
|
||||||
{
|
|
||||||
res[i] = str[i];
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
res[i] = c;
|
|
||||||
res[i + 1] = '\0';
|
|
||||||
return (res);
|
|
||||||
}
|
|
||||||
|
|
@ -1,26 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_strchr.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: lfirmin <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2024/05/21 06:46:40 by lfirmin #+# #+# */
|
|
||||||
/* Updated: 2024/05/24 08:51:25 by lfirmin ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
char *ft_strchr(char const *str, int c)
|
|
||||||
{
|
|
||||||
while (*str)
|
|
||||||
{
|
|
||||||
if (*str == (char)c)
|
|
||||||
return ((char *)str);
|
|
||||||
str++;
|
|
||||||
}
|
|
||||||
if (*str == (char)c)
|
|
||||||
return ((char *)str);
|
|
||||||
else
|
|
||||||
return (NULL);
|
|
||||||
}
|
|
||||||
|
|
@ -1,22 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_strcmp.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2024/10/19 21:01:26 by lfirmin #+# #+# */
|
|
||||||
/* Updated: 2024/10/19 21:01:26 by lfirmin ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
int ft_strcmp(char *s1, char *s2)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
while (s1[i] == s2[i] && s1[i] != '\0' && s2[i] != '\0')
|
|
||||||
i++;
|
|
||||||
return (s1[i] - s2[i]);
|
|
||||||
}
|
|
||||||
|
|
@ -1,27 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_strcpy.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2025/04/19 11:53:24 by lfirmin #+# #+# */
|
|
||||||
/* Updated: 2025/04/19 11:58:04 by lfirmin ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
char *ft_strcpy(char *dest, char *src)
|
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
while (src[i] != '\0')
|
|
||||||
{
|
|
||||||
dest[i] = src[i];
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
dest[i] = '\0';
|
|
||||||
return (dest);
|
|
||||||
}
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue