Added memorybook to parsing and cleaned most of the files
This commit is contained in:
5
Makefile
5
Makefile
@@ -37,7 +37,8 @@ SRCS += init_parsing.c \
|
|||||||
check_extension.c \
|
check_extension.c \
|
||||||
check_path.c \
|
check_path.c \
|
||||||
check_rgb.c \
|
check_rgb.c \
|
||||||
check_map.c
|
check_map_borders.c \
|
||||||
|
check_map_content.c
|
||||||
# hook/
|
# hook/
|
||||||
SRCS += keyhook.c \
|
SRCS += keyhook.c \
|
||||||
key_action_1.c \
|
key_action_1.c \
|
||||||
@@ -79,7 +80,7 @@ RM_OBJS = rm -rf $(D_OBJS)
|
|||||||
|
|
||||||
# flags
|
# flags
|
||||||
CFLAGS = -Wall -Wextra -Werror $(INCLUDES)
|
CFLAGS = -Wall -Wextra -Werror $(INCLUDES)
|
||||||
CFLAGS += -g3
|
CFLAGS += -g3 -fsanitize=address
|
||||||
LFLAGS = -L$(D_LFT) -lft
|
LFLAGS = -L$(D_LFT) -lft
|
||||||
LFLAGS += -L$(D_LMLX) -lm -lmlx -lXext -lX11
|
LFLAGS += -L$(D_LMLX) -lm -lmlx -lXext -lX11
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,15 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* colors.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: pblagoje <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2022/05/04 13:34:26 by pblagoje #+# #+# */
|
||||||
|
/* Updated: 2022/05/04 13:35:12 by pblagoje ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#ifndef COLORS_H
|
#ifndef COLORS_H
|
||||||
# define COLORS_H
|
# define COLORS_H
|
||||||
|
|
||||||
@@ -22,4 +34,3 @@
|
|||||||
# define RESET "\e[0m"
|
# define RESET "\e[0m"
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,15 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* cube3d.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: pblagoje <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2022/05/04 13:34:54 by pblagoje #+# #+# */
|
||||||
|
/* Updated: 2022/05/04 13:35:31 by pblagoje ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#ifndef CUBE3D_H
|
#ifndef CUBE3D_H
|
||||||
# define CUBE3D_H
|
# define CUBE3D_H
|
||||||
|
|
||||||
@@ -10,7 +22,6 @@
|
|||||||
# include <sys/stat.h> // for open()
|
# include <sys/stat.h> // for open()
|
||||||
# include <fcntl.h> // for open flags
|
# include <fcntl.h> // for open flags
|
||||||
|
|
||||||
|
|
||||||
# include "colors.h"
|
# include "colors.h"
|
||||||
# include "memorybook.h"
|
# include "memorybook.h"
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,15 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* cube3d_macro.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: pblagoje <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2022/05/04 13:34:39 by pblagoje #+# #+# */
|
||||||
|
/* Updated: 2022/05/04 13:34:46 by pblagoje ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#ifndef CUBE3D_MACRO_H
|
#ifndef CUBE3D_MACRO_H
|
||||||
# define CUBE3D_MACRO_H
|
# define CUBE3D_MACRO_H
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,15 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* cube3d_proto.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: pblagoje <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2022/05/04 13:36:55 by pblagoje #+# #+# */
|
||||||
|
/* Updated: 2022/05/04 13:38:53 by pblagoje ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#ifndef CUBE3D_PROTO_H
|
#ifndef CUBE3D_PROTO_H
|
||||||
# define CUBE3D_PROTO_H
|
# define CUBE3D_PROTO_H
|
||||||
|
|
||||||
@@ -6,8 +18,7 @@
|
|||||||
// -------------------------------
|
// -------------------------------
|
||||||
// cube3d.c
|
// cube3d.c
|
||||||
void destroy_mlx(void *param);
|
void destroy_mlx(void *param);
|
||||||
int shut_down();
|
int shut_down(void);
|
||||||
|
|
||||||
|
|
||||||
// -------------------------------
|
// -------------------------------
|
||||||
// SRC/INIT
|
// SRC/INIT
|
||||||
@@ -19,14 +30,12 @@ void init_game(t_game *game);
|
|||||||
// init_textures.c
|
// init_textures.c
|
||||||
void init_txtr(t_txt *txt, void *mlx_ptr);
|
void init_txtr(t_txt *txt, void *mlx_ptr);
|
||||||
|
|
||||||
|
|
||||||
// -------------------------------
|
// -------------------------------
|
||||||
// SRC/GNL
|
// SRC/GNL
|
||||||
// -------------------------------
|
// -------------------------------
|
||||||
// get_next_line.c
|
// get_next_line.c
|
||||||
int get_next_line(int fd, char **line);
|
int get_next_line(int fd, char **line);
|
||||||
|
|
||||||
|
|
||||||
// -------------------------------
|
// -------------------------------
|
||||||
// SRC/PARSING
|
// SRC/PARSING
|
||||||
// -------------------------------
|
// -------------------------------
|
||||||
@@ -38,9 +47,10 @@ int check_extension(char *filename, char *ext);
|
|||||||
int check_elements(t_game *game, char *file);
|
int check_elements(t_game *game, char *file);
|
||||||
// check_rgb.c
|
// check_rgb.c
|
||||||
int check_rgb(t_txt *txt, char *element, char identifier);
|
int check_rgb(t_txt *txt, char *element, char identifier);
|
||||||
// check_map.c
|
// check_map_borders.c
|
||||||
int check_map(t_map *map);
|
int check_map(t_map *map);
|
||||||
|
// check_map_content.c
|
||||||
|
int check_content(t_map *map);
|
||||||
|
|
||||||
// -------------------------------
|
// -------------------------------
|
||||||
// SRC/HOOK
|
// SRC/HOOK
|
||||||
@@ -59,7 +69,6 @@ int is_go_backward(int *k_hook, int *is_action);
|
|||||||
int is_turn_left(int *k_hook, int *is_action);
|
int is_turn_left(int *k_hook, int *is_action);
|
||||||
int is_turn_right(int *k_hook, int *is_action);
|
int is_turn_right(int *k_hook, int *is_action);
|
||||||
|
|
||||||
|
|
||||||
// -------------------------------
|
// -------------------------------
|
||||||
// SRC/PLAYER
|
// SRC/PLAYER
|
||||||
// -------------------------------
|
// -------------------------------
|
||||||
|
|||||||
@@ -1,3 +1,15 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* cube3d_struct.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: pblagoje <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2022/05/04 13:31:38 by pblagoje #+# #+# */
|
||||||
|
/* Updated: 2022/05/04 13:34:07 by pblagoje ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#ifndef CUBE3D_STRUCT_H
|
#ifndef CUBE3D_STRUCT_H
|
||||||
# define CUBE3D_STRUCT_H
|
# define CUBE3D_STRUCT_H
|
||||||
|
|
||||||
@@ -134,10 +146,8 @@ typedef struct s_map
|
|||||||
|
|
||||||
typedef struct s_plr
|
typedef struct s_plr
|
||||||
{
|
{
|
||||||
// player
|
|
||||||
t_d_coord exact;
|
t_d_coord exact;
|
||||||
t_coord pos;
|
t_coord pos;
|
||||||
// rot
|
|
||||||
int rot;
|
int rot;
|
||||||
int deg;
|
int deg;
|
||||||
double cosi;
|
double cosi;
|
||||||
@@ -153,29 +163,13 @@ typedef struct s_plr
|
|||||||
typedef struct s_game
|
typedef struct s_game
|
||||||
{
|
{
|
||||||
void *mlx_ptr;
|
void *mlx_ptr;
|
||||||
// game window
|
|
||||||
t_win win;
|
t_win win;
|
||||||
t_img img;
|
t_img img;
|
||||||
// player
|
|
||||||
t_plr plr;
|
t_plr plr;
|
||||||
// rays
|
|
||||||
t_rcast rcast;
|
t_rcast rcast;
|
||||||
// textures and colors
|
|
||||||
t_txt txt;
|
t_txt txt;
|
||||||
// map
|
|
||||||
t_map map;
|
t_map map;
|
||||||
|
|
||||||
//tmp draw map
|
|
||||||
// // map window
|
|
||||||
// t_win map_win;
|
|
||||||
// t_img map_img;
|
|
||||||
// // rays
|
|
||||||
// int ray_highlight;
|
|
||||||
// int ray_activ;
|
|
||||||
// t_vec ray;
|
|
||||||
// tmp end
|
|
||||||
|
|
||||||
// key hook
|
|
||||||
int k_hook[MAX_NB_KEY];
|
int k_hook[MAX_NB_KEY];
|
||||||
} t_game;
|
} t_game;
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,15 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* memorybook.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: pblagoje <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2022/05/04 13:35:47 by pblagoje #+# #+# */
|
||||||
|
/* Updated: 2022/05/04 13:36:44 by pblagoje ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#ifndef MEMORYBOOK_H
|
#ifndef MEMORYBOOK_H
|
||||||
# define MEMORYBOOK_H
|
# define MEMORYBOOK_H
|
||||||
|
|
||||||
|
|||||||
Submodule libs/libft deleted from 8fe843722b
964
libs/libft/Makefile
Normal file
964
libs/libft/Makefile
Normal file
@@ -0,0 +1,964 @@
|
|||||||
|
# - - - - - - - - - #
|
||||||
|
# variables names #
|
||||||
|
# - - - - - - - - - #
|
||||||
|
|
||||||
|
NAME = libft.a
|
||||||
|
CC = gcc
|
||||||
|
VPATH = srcs/ \
|
||||||
|
srcs/ft_printf_files/
|
||||||
|
|
||||||
|
IDIR = ./includes
|
||||||
|
_DEP = libft.h
|
||||||
|
DEPS = $(_DEP:%.h=$(IDIR)/%.h)
|
||||||
|
|
||||||
|
CFLAGS = -I$(IDIR)
|
||||||
|
CFLAGS += -Wall -Wextra -Werror -g3
|
||||||
|
|
||||||
|
SRCS = ft_memset.c \
|
||||||
|
ft_bzero.c \
|
||||||
|
ft_memcpy.c \
|
||||||
|
ft_memccpy.c \
|
||||||
|
ft_memmove.c \
|
||||||
|
ft_memchr.c \
|
||||||
|
ft_memcmp.c \
|
||||||
|
ft_memalloc.c \
|
||||||
|
ft_memdel.c \
|
||||||
|
ft_calloc.c \
|
||||||
|
\
|
||||||
|
ft_isalpha.c \
|
||||||
|
ft_isdigit.c \
|
||||||
|
ft_isalnum.c \
|
||||||
|
ft_isnumber.c \
|
||||||
|
ft_isascii.c \
|
||||||
|
ft_isprint.c \
|
||||||
|
ft_toupper.c \
|
||||||
|
ft_tolower.c \
|
||||||
|
\
|
||||||
|
ft_strlen.c \
|
||||||
|
ft_strchr.c \
|
||||||
|
ft_strrchr.c \
|
||||||
|
ft_strchrset.c \
|
||||||
|
ft_strncmp.c \
|
||||||
|
ft_strlcpy.c \
|
||||||
|
ft_strlcat.c \
|
||||||
|
ft_strnstr.c \
|
||||||
|
ft_strdup.c \
|
||||||
|
ft_strjoin.c \
|
||||||
|
ft_strtrim.c \
|
||||||
|
ft_strmapi.c \
|
||||||
|
ft_strcat.c \
|
||||||
|
ft_strcmp.c \
|
||||||
|
ft_strcpy.c \
|
||||||
|
ft_strncat.c \
|
||||||
|
ft_strncpy.c \
|
||||||
|
ft_strstr.c \
|
||||||
|
ft_strjoinfree.c \
|
||||||
|
ft_strclr.c \
|
||||||
|
ft_strdel.c \
|
||||||
|
ft_strequ.c \
|
||||||
|
ft_striter.c \
|
||||||
|
ft_striteri.c \
|
||||||
|
ft_strmap.c \
|
||||||
|
ft_strnequ.c \
|
||||||
|
ft_strnew.c \
|
||||||
|
ft_substr.c \
|
||||||
|
ft_split.c \
|
||||||
|
\
|
||||||
|
ft_atoi.c \
|
||||||
|
ft_atol.c \
|
||||||
|
ft_itoa.c \
|
||||||
|
ft_utoa.c \
|
||||||
|
\
|
||||||
|
ft_putchar_fd.c \
|
||||||
|
ft_putstr_fd.c \
|
||||||
|
ft_putnbr_fd.c \
|
||||||
|
ft_putnbrbase.c \
|
||||||
|
\
|
||||||
|
ft_lstcreate.c \
|
||||||
|
ft_lstpush_back.c \
|
||||||
|
ft_lstpush_front.c \
|
||||||
|
ft_lstloop.c \
|
||||||
|
ft_lstloop_back.c \
|
||||||
|
ft_lstbegin.c \
|
||||||
|
ft_lstend.c \
|
||||||
|
ft_lstfind.c \
|
||||||
|
ft_lstinsert.c \
|
||||||
|
ft_lsterase.c \
|
||||||
|
ft_lstfree.c \
|
||||||
|
ft_lstlen.c \
|
||||||
|
ft_lstcopy.c \
|
||||||
|
\
|
||||||
|
ft_any.c \
|
||||||
|
ft_atoibase.c \
|
||||||
|
ft_convertbase.c \
|
||||||
|
ft_convertbase_free.c \
|
||||||
|
ft_foreach.c \
|
||||||
|
ft_issort.c \
|
||||||
|
ft_arraymap.c \
|
||||||
|
ft_strmultisplit.c \
|
||||||
|
\
|
||||||
|
ft_gnl.c \
|
||||||
|
ft_concat_free.c \
|
||||||
|
\
|
||||||
|
ft_printf.c \
|
||||||
|
ft_next_word.c \
|
||||||
|
ft_convert.c \
|
||||||
|
ft_flag_transform.c \
|
||||||
|
ft_flag_transform_bonus.c \
|
||||||
|
ft_abs.c \
|
||||||
|
ft_greater.c \
|
||||||
|
ft_smaller.c \
|
||||||
|
ft_sign.c \
|
||||||
|
ft_sqrt.c \
|
||||||
|
ft_free_tab.c \
|
||||||
|
\
|
||||||
|
ft_arrint.c
|
||||||
|
|
||||||
|
# deleted : \
|
||||||
|
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_lstmap.c \
|
||||||
|
\
|
||||||
|
ft_putstr.c \
|
||||||
|
ft_putchar.c \
|
||||||
|
ft_putendl.c \
|
||||||
|
ft_putnbr.c \
|
||||||
|
ft_putnbrendl.c \
|
||||||
|
ft_putnbrendl_fd.c \
|
||||||
|
ft_putendl_fd.c \
|
||||||
|
|
||||||
|
|
||||||
|
ODIR = ./builds
|
||||||
|
OBJS = $(SRCS:%.c=$(ODIR)/%.o)
|
||||||
|
|
||||||
|
|
||||||
|
# - - - - - - - - - - - #
|
||||||
|
# rules to execute #
|
||||||
|
# - - - - - - - - - - - #
|
||||||
|
|
||||||
|
|
||||||
|
all: $(NAME)
|
||||||
|
|
||||||
|
$(ODIR):
|
||||||
|
@printf "\033[35m"
|
||||||
|
mkdir -p $(ODIR)
|
||||||
|
@printf "\033[0m"
|
||||||
|
|
||||||
|
$(NAME): $(ODIR) $(OBJS) $(DEPS)
|
||||||
|
@printf "\033[33m"
|
||||||
|
ar -rc $@ $(OBJS)
|
||||||
|
ranlib $@
|
||||||
|
@printf "\033[0m"
|
||||||
|
|
||||||
|
$(ODIR)/%.o: %.c
|
||||||
|
@printf "\033[36m"
|
||||||
|
$(CC) $(CFLAGS) -c -o $@ $<
|
||||||
|
|
||||||
|
clean:
|
||||||
|
@printf "\033[31m"
|
||||||
|
/bin/rm -rf $(ODIR)
|
||||||
|
@printf "\033[0m"
|
||||||
|
|
||||||
|
fclean: clean
|
||||||
|
@printf "\033[31m"
|
||||||
|
/bin/rm -f $(NAME)
|
||||||
|
@printf "\033[0m"
|
||||||
|
|
||||||
|
re: fclean all
|
||||||
|
|
||||||
|
.PHONY: clean fclean re all
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# ------------------------------------------------------ #
|
||||||
|
# explication complete etapes par etapes depuis le debut #
|
||||||
|
# ------------------------------------------------------ #
|
||||||
|
|
||||||
|
## 1 - compiler avec gcc [25 gj]
|
||||||
|
# compiler un programme [29 gj]
|
||||||
|
# compiler en plusieurs fichiers [54 gj]
|
||||||
|
# les .o : compiler et linker [102 gj]
|
||||||
|
|
||||||
|
## 2 - creer une librairie [135 gj]
|
||||||
|
# ar rc [139 gj]
|
||||||
|
# ar rc en plusieurs fois [164 gj]
|
||||||
|
# ranlib [185 gj]
|
||||||
|
|
||||||
|
## 3 - fichiers .h [198 gj]
|
||||||
|
# a quoi sert un header [202 gj]
|
||||||
|
# ecrire un header [229 gj]
|
||||||
|
# comment ca se compile [273 gj]
|
||||||
|
|
||||||
|
## 4 - ecrire un make file [305 gj]
|
||||||
|
# basic makefile [309 gj]
|
||||||
|
# makefile with subdirectories [462 gj]
|
||||||
|
# makefile making another makefile [583 gj]
|
||||||
|
# makefile for a library [690 gj]
|
||||||
|
|
||||||
|
## ----------------------
|
||||||
|
## 1 - compiler avec gcc
|
||||||
|
## ----------------------
|
||||||
|
|
||||||
|
# - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
# compiler un programme qui contient un main
|
||||||
|
# - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
|
||||||
|
# quand on ecrit un programme il contient un main et les
|
||||||
|
# fonctions dont le main a besoin (ex ft_putchar) :
|
||||||
|
#
|
||||||
|
# # #include <unistd.h>
|
||||||
|
# #
|
||||||
|
# # void ft_putchar(char c)
|
||||||
|
# # {
|
||||||
|
# # write(1, &c, 1);
|
||||||
|
# # }
|
||||||
|
# #
|
||||||
|
# # int main()
|
||||||
|
# # {
|
||||||
|
# # ft_putchar('0');
|
||||||
|
# # return (0);
|
||||||
|
# # }
|
||||||
|
#
|
||||||
|
# on peut compiler ce fichier avec gcc en faisant :
|
||||||
|
# gcc file.c
|
||||||
|
# et ca sort un executable a.out
|
||||||
|
# si on l'execute "./a.out" ca ecrit 0 dans la console
|
||||||
|
|
||||||
|
# - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
# compiler un programme en plusieurs fichiers
|
||||||
|
# - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
|
||||||
|
# on va vite vouloir mettre chaque fonctions utilisee
|
||||||
|
# dans un fichier a part afin de mieux gerer les modules
|
||||||
|
# d'un programme. donc si on sort ft_putchar du fichier :
|
||||||
|
#
|
||||||
|
# # int main()
|
||||||
|
# # {
|
||||||
|
# # ft_putchar('0');
|
||||||
|
# # return (0);
|
||||||
|
# # }
|
||||||
|
#
|
||||||
|
# et qu'on execute "gcc file.c" on va avoir une erreur
|
||||||
|
# car file.c utilise ft_putchar mais gcc ne sait pas ce
|
||||||
|
# que c'est, donc il faut faire deux choses :
|
||||||
|
#
|
||||||
|
# 1 - d'une part indiquer a main() que ft_putchar()
|
||||||
|
# existe, en ecrivant au dessus non pas toute la fonction
|
||||||
|
# (puisqu'on veut la mettre dans un fichier a part) mais
|
||||||
|
# uniquement son prototype :
|
||||||
|
#
|
||||||
|
# # void ft_putchar(char c);
|
||||||
|
#
|
||||||
|
# 2 - et d'autre part qu'on rajoute le fichier contenant
|
||||||
|
# la fonction ft_putchar a la compilation :
|
||||||
|
#
|
||||||
|
# [ft_putchar.c]
|
||||||
|
# # #include <unistd.h>
|
||||||
|
# #
|
||||||
|
# # void ft_putchar(char c)
|
||||||
|
# # {
|
||||||
|
# # write(1, &c, 1);
|
||||||
|
# # }
|
||||||
|
#
|
||||||
|
# [main.c]
|
||||||
|
# # void ft_putchar(char c);
|
||||||
|
# #
|
||||||
|
# # int main()
|
||||||
|
# # {
|
||||||
|
# # ft_putchar('0');
|
||||||
|
# # return (0);
|
||||||
|
# # }
|
||||||
|
#
|
||||||
|
# si on compile les deux ca marche :
|
||||||
|
# gcc main.c ft_putchar.c
|
||||||
|
|
||||||
|
# - - - - - - - - - - - - - - -
|
||||||
|
# les .o : compiler et linker
|
||||||
|
# - - - - - - - - - - - - - - -
|
||||||
|
|
||||||
|
# ca fonctionne mais gcc doit a chaque fois recompiler
|
||||||
|
# ft_putchar.c alors qu'il n'est pas modifie, donc on peut
|
||||||
|
# le compiler une bonne fois pour toute et l'ajouter a la
|
||||||
|
# compilation finale quand on en a besoin sans que l'ordi
|
||||||
|
# ait a tout retraduire dans son langage
|
||||||
|
#
|
||||||
|
# mais si on essaye de compiler ft_putchar seul
|
||||||
|
#
|
||||||
|
# # gcc ft_putchar.c
|
||||||
|
#
|
||||||
|
# ca nous donne une erreur car pour compiler, gcc a besoin
|
||||||
|
# de trouver un main !
|
||||||
|
#
|
||||||
|
# on va donc utiliser l'option -c pour creer un fichier
|
||||||
|
# objet .o qui est deja traduit en langue d'ordinateur
|
||||||
|
# et pret a etre rajoute a la compilation :
|
||||||
|
#
|
||||||
|
# # gcc -c ft_putchar.c --> donne ft_putchar.o
|
||||||
|
# # gcc -c main.c --> donne main.o
|
||||||
|
#
|
||||||
|
# cette etape qui consiste a transformer les fichiers en
|
||||||
|
# objets .o s'appelle la compilation, il faut ensuite
|
||||||
|
# linker les objets, ce qui avec gcc se fait simplement :
|
||||||
|
#
|
||||||
|
# # gcc main.o ft_putchar.o
|
||||||
|
#
|
||||||
|
# on va maintenant voir comment faire une libraire qui
|
||||||
|
# contient tous nos fichiers objets
|
||||||
|
|
||||||
|
## ------------------------
|
||||||
|
## 2 - creer une librairie
|
||||||
|
## ------------------------
|
||||||
|
|
||||||
|
# - - - -
|
||||||
|
# ar rc
|
||||||
|
# - - - -
|
||||||
|
|
||||||
|
# pour mettre tous les fichiers .o dans un seul fichier .a
|
||||||
|
# on utilise un programme d'archive ar avec les options rc
|
||||||
|
# - r indique d'inserer les .o en remplacant si necessaire
|
||||||
|
# - c de creer une nouvelle archive
|
||||||
|
#
|
||||||
|
# le nom de l'archive doit commencer par lib et
|
||||||
|
# finir par .a :
|
||||||
|
#
|
||||||
|
# # ar rc libtest.a ft_putchar.o
|
||||||
|
#
|
||||||
|
# on obtient un fichier libtest.a qui contient les
|
||||||
|
# fichiers objets .o
|
||||||
|
#
|
||||||
|
# on peut l'utiliser a la compilation de cette manniere :
|
||||||
|
#
|
||||||
|
# # gcc main.c -L. -ltest
|
||||||
|
#
|
||||||
|
# -L indique ou est la librairie (ici elle est dans le
|
||||||
|
# dossier courant .)
|
||||||
|
# -l indique son nom (TEST car on n'indique pas lib et .a)
|
||||||
|
|
||||||
|
# - - - - - - - - - - - - -
|
||||||
|
# ar rc en plusieurs fois
|
||||||
|
# - - - - - - - - - - - - -
|
||||||
|
|
||||||
|
# on n'est pas oblige de creer une librairie en une seule
|
||||||
|
# fois, ce qui est bien pratique nottament pour les
|
||||||
|
# makefiles, on verra ca apres.
|
||||||
|
#
|
||||||
|
# ca signifie que si notre librairie contient plusieurs
|
||||||
|
# fonctions, par exmple la librairie libfruits.a contient
|
||||||
|
# banane.o et orange.o, on peut creer la librairie
|
||||||
|
# avec banane.o puis y ajouter orange.o, sans auncune
|
||||||
|
# manipulation speciale :
|
||||||
|
#
|
||||||
|
# # ar rc libfruits.a banane.o
|
||||||
|
# # ar rc libfruits.a orange.o
|
||||||
|
#
|
||||||
|
# revient au meme qu'ecrire :
|
||||||
|
#
|
||||||
|
# # ar rc libfruits.a banane.o orange.o
|
||||||
|
|
||||||
|
# - - - -
|
||||||
|
# ranlib
|
||||||
|
# - - - -
|
||||||
|
|
||||||
|
# ranlib creer un index du contenu de la librairie et le
|
||||||
|
# place dedans, c'est utile des que la librairie est tres
|
||||||
|
# grande afin que gcc sache acceder rapidement aux
|
||||||
|
# fonctions dont il a besoin dedans
|
||||||
|
#
|
||||||
|
# # ranlib libtest.a
|
||||||
|
#
|
||||||
|
# ranlib s'utilise apres avoir creer la lib avec ar rc
|
||||||
|
|
||||||
|
## ----------------
|
||||||
|
## 3 - fichiers .h
|
||||||
|
## ----------------
|
||||||
|
|
||||||
|
# - - - - - - - - - - - -
|
||||||
|
# a quoi sert un header
|
||||||
|
# - - - - - - - - - - - -
|
||||||
|
# si on utilise une librairie c'est parce qu'on peut avoir
|
||||||
|
# souvent besoin des memes fonctions dans un programme
|
||||||
|
# mais si a chaque fois qu'on utilise une fonction de la
|
||||||
|
# librairie on doit ecrire son prototype, ca va poser deux
|
||||||
|
# problemes :
|
||||||
|
#
|
||||||
|
# le prototype d'une seule fonction peut etre ecrit a
|
||||||
|
# pleins d'endroits, donc si la fonction change un peu on
|
||||||
|
# doit retrouver tous les emplacements des prototypes et
|
||||||
|
# les modifier un par un
|
||||||
|
#
|
||||||
|
# et d'autre part, si on utilise pleins de fonctions dans
|
||||||
|
# l'ecriture d'un programme on va devoir reecrire a chaque
|
||||||
|
# fois son prototype et c'est tres relou
|
||||||
|
#
|
||||||
|
# afin d'eviter ca on ecrit tous les prototypes, ainsi que
|
||||||
|
# les includes, et les structures, les defines, et autres,
|
||||||
|
# dans un seul fichier pour tout un programme, ou dans le
|
||||||
|
# cas present pour toute la librairie, et on l'inclus
|
||||||
|
# systematiquement au debut d'un fichier contenant des
|
||||||
|
# fonctions de la librairie, gcc s'occupera de l'expandre
|
||||||
|
# a la precompilation
|
||||||
|
#
|
||||||
|
|
||||||
|
# - - - - - - - - -
|
||||||
|
# ecrire un header
|
||||||
|
# - - - - - - - - -
|
||||||
|
|
||||||
|
# [ft_putchar.c]
|
||||||
|
# # #include "libtest.h"
|
||||||
|
# #
|
||||||
|
# # void ft_putchar(char c)
|
||||||
|
# # {
|
||||||
|
# # write(1, &c, 1);
|
||||||
|
# # }
|
||||||
|
#
|
||||||
|
# [main.c]
|
||||||
|
# # #include "libtest.h"
|
||||||
|
# #
|
||||||
|
# # int main()
|
||||||
|
# # {
|
||||||
|
# # ft_putchar('0');
|
||||||
|
# # return (0);
|
||||||
|
# # }
|
||||||
|
#
|
||||||
|
# [libetest.h]
|
||||||
|
# # # ifndef LIBTEST_H
|
||||||
|
# # # define LIBTEST_H
|
||||||
|
# #
|
||||||
|
# # #include <unistd.h>
|
||||||
|
# #
|
||||||
|
# # void ft_putchar(char c);
|
||||||
|
# #
|
||||||
|
# # # endif
|
||||||
|
#
|
||||||
|
# en tete de chaque fichier de fonctions on ecrit
|
||||||
|
# l'include de la librairie, comme un include classique,
|
||||||
|
# precede d'un #, mais avec le nom de la librairie entre
|
||||||
|
# guillemets et non pas entre signes comparateurs
|
||||||
|
#
|
||||||
|
# dans le fichier de la librairie on ajoute les includes
|
||||||
|
# dont on peut avoir besoin pour que la librairie ou des
|
||||||
|
# fonctions auont besoin, et les prototypes des fonctions
|
||||||
|
#
|
||||||
|
# on entoure toutes ces infos par une definition, afin
|
||||||
|
# de proteger le .h d'etre expand plusieurs fois dans
|
||||||
|
# un fichier
|
||||||
|
|
||||||
|
# - - - - - - - - - - - -
|
||||||
|
# comment ca se compile
|
||||||
|
# - - - - - - - - - - - -
|
||||||
|
|
||||||
|
# au moment de la compilation il faut indiquer a gcc ou
|
||||||
|
# se trouve le fichier .h avec le flag -I
|
||||||
|
#
|
||||||
|
# par exemple pour l'architecture de dossier suivante :
|
||||||
|
#
|
||||||
|
# # file/
|
||||||
|
# # main.c
|
||||||
|
# # ft_putchar.c
|
||||||
|
# # libtest.h
|
||||||
|
#
|
||||||
|
# il faut ecrire :
|
||||||
|
#
|
||||||
|
# # gcc main.c ft_putchar.c -I.
|
||||||
|
#
|
||||||
|
# et si la compilation utilise une librairie, par exemple
|
||||||
|
# si on met la fonction ft_putchar.c dans une librairie :
|
||||||
|
#
|
||||||
|
# # gcc -c ft_putchar.c
|
||||||
|
# # (donne ft_putchar.o)
|
||||||
|
# # ar rc libtest.a ft_putchar.o
|
||||||
|
#
|
||||||
|
# on peut alors compiler avec la librairie .a et le
|
||||||
|
# fichier .h :
|
||||||
|
#
|
||||||
|
# # gcc main.c -I. -L. -ltest -o test
|
||||||
|
#
|
||||||
|
# qui sort l'executable "test"
|
||||||
|
|
||||||
|
## ----------------------------------------------------
|
||||||
|
## 4 - ecrire un make file pour aider a la compilation
|
||||||
|
## ----------------------------------------------------
|
||||||
|
|
||||||
|
# - - - - - - - - -
|
||||||
|
# makefile basique
|
||||||
|
# - - - - - - - - -
|
||||||
|
|
||||||
|
# exemple for a basic makefile :
|
||||||
|
#
|
||||||
|
# [architecture]
|
||||||
|
# # main.c
|
||||||
|
# # function01.c
|
||||||
|
# # function02.c
|
||||||
|
# # header.h
|
||||||
|
# # libtest.a
|
||||||
|
# # Makefile
|
||||||
|
#
|
||||||
|
# [Makefile]
|
||||||
|
# # #-------------#
|
||||||
|
# # # VARIABLES #
|
||||||
|
# # #-------------#
|
||||||
|
# # NAME = program_test
|
||||||
|
# # CC = gcc
|
||||||
|
# # CFLAGS = -I.
|
||||||
|
# # LFLAGS = -L. -ltest
|
||||||
|
# # DEPS = header.h
|
||||||
|
# # SRCS = main.c \
|
||||||
|
# # function01.c \
|
||||||
|
# # function02.c
|
||||||
|
# # ODIR = ./builds
|
||||||
|
# # OBJS = $(SRCS:%.c=%.o)
|
||||||
|
# #
|
||||||
|
# # #---------#
|
||||||
|
# # # RULES #
|
||||||
|
# # #---------#
|
||||||
|
# # all: $(ODIR) $(NAME)
|
||||||
|
# # $(NAME): $(OBJS) $(DEPS)
|
||||||
|
# # $(CC) $(CFLAGS) -o $@ $(OBJS) $(LFLAGS)
|
||||||
|
# # %.o: %.c
|
||||||
|
# # $(CC) $(CFLAGS) -c -o $@ $<
|
||||||
|
# # clean:
|
||||||
|
# # /bin/rm -rf $(ODIR)
|
||||||
|
# # fclean: clean
|
||||||
|
# # /bin/rm -f $(NAME)
|
||||||
|
# # re: fclean all
|
||||||
|
# # .PHONY: all clean fclean re
|
||||||
|
#
|
||||||
|
# # prompt "make" execute the first rule ("all")
|
||||||
|
#
|
||||||
|
# [architecture]
|
||||||
|
# # main.c
|
||||||
|
# # main.o
|
||||||
|
# # function01.c
|
||||||
|
# # function01.o ++
|
||||||
|
# # function02.c
|
||||||
|
# # function02.o ++
|
||||||
|
# # header.h
|
||||||
|
# # libtest.a
|
||||||
|
# # Makefile
|
||||||
|
# # program_test ++
|
||||||
|
#
|
||||||
|
# -----
|
||||||
|
#
|
||||||
|
# shape of a rule :
|
||||||
|
#
|
||||||
|
# target: prerequisites ...
|
||||||
|
# recipe ...
|
||||||
|
#
|
||||||
|
# when a target is called, its execution depends of the
|
||||||
|
# prerequisites, if they have been more recently modify
|
||||||
|
# than the target the makefile execute the recipe
|
||||||
|
#
|
||||||
|
# to execute a rull you have to call it's name with make :
|
||||||
|
# "make rule", and by default the first rule is execute
|
||||||
|
#
|
||||||
|
# -----
|
||||||
|
#
|
||||||
|
# "automatic variables"
|
||||||
|
#
|
||||||
|
# $@ is the name of the target that called the rule
|
||||||
|
# $< is the name of the first prerequisite
|
||||||
|
# $^ is the name of all the prerequisites
|
||||||
|
#
|
||||||
|
# -----
|
||||||
|
#
|
||||||
|
# $(SRCS:%.c=%.o)
|
||||||
|
#
|
||||||
|
# is a built-in function called a "substitute reference",
|
||||||
|
# an abbreviation for the expansion function "patsubst" :
|
||||||
|
#
|
||||||
|
# $(patsubst pattern,replacement,text)
|
||||||
|
# $(text:pattern=replacement)
|
||||||
|
#
|
||||||
|
# $() is a variable which expand in its value
|
||||||
|
#
|
||||||
|
# % match everything, the value of the first % in
|
||||||
|
# "replacement" is replaced with the text matched by the
|
||||||
|
# first % in "pattern", it only works for the firsts
|
||||||
|
#
|
||||||
|
# -----
|
||||||
|
#
|
||||||
|
# all: $(ODIR) $(NAME)
|
||||||
|
#
|
||||||
|
# ALL depends on ODIR and NAME, so if ODIR doesn't exist
|
||||||
|
# it will be created, and then NAME is called
|
||||||
|
#
|
||||||
|
# -----
|
||||||
|
#
|
||||||
|
# $(NAME): $(OBJS) $(DEPS)
|
||||||
|
# $(CC) $(CFLAGS) -o $@ $(OBJS) $(LFLAGS)
|
||||||
|
#
|
||||||
|
# NAME depends on OBJS and DEPS, so if any .o or any .h
|
||||||
|
# have more recent date of modification NAME will execute
|
||||||
|
# only for them
|
||||||
|
#
|
||||||
|
# -----
|
||||||
|
#
|
||||||
|
# %.o: %.c
|
||||||
|
# $(CC) $(CFLAGS) -c -o $@ $<
|
||||||
|
#
|
||||||
|
# when $(OBJS) expand in the list of .o files at the call
|
||||||
|
# of the NAME rule, each of them call the rule "%.o" wich
|
||||||
|
# depends on the equivalent .c, so if one has been
|
||||||
|
# modified since last execution of ALL, it's recompiled in
|
||||||
|
# object file with use of automatic variables $@ and $<
|
||||||
|
#
|
||||||
|
# -----
|
||||||
|
#
|
||||||
|
# #clean:
|
||||||
|
# /bin/rm -rf $(ODIR)
|
||||||
|
#
|
||||||
|
# "make clean" suppress all the .o files
|
||||||
|
#
|
||||||
|
# -----
|
||||||
|
#
|
||||||
|
# fclean: clean
|
||||||
|
# /bin/rm -f $(NAME)
|
||||||
|
#
|
||||||
|
# "make fclean" call CLEAN and suppress the executable
|
||||||
|
#
|
||||||
|
# -----
|
||||||
|
#
|
||||||
|
# re: fclean all
|
||||||
|
#
|
||||||
|
# "make fclean" basically rerun make
|
||||||
|
#
|
||||||
|
# -----
|
||||||
|
#
|
||||||
|
# .PHONY: all clean fclean re
|
||||||
|
#
|
||||||
|
# a phony target is one that is not the name of a file
|
||||||
|
# if a file called "clean" for instance exist, the rule
|
||||||
|
# CLEAN will never be executed when prompt "make clean"
|
||||||
|
# because it will be considered up to date, but if it's
|
||||||
|
# declared to be phony it will be executed in any case
|
||||||
|
|
||||||
|
# - - - - - - - - - - - - - - -
|
||||||
|
# makefile with subdirectories
|
||||||
|
# - - - - - - - - - - - - - - -
|
||||||
|
|
||||||
|
# put the .o in a "builds/" directory
|
||||||
|
#
|
||||||
|
# have the .c in a "srcs/" directory
|
||||||
|
#
|
||||||
|
# have the .h in an "includes" directory
|
||||||
|
#
|
||||||
|
# have multiples .a files
|
||||||
|
#
|
||||||
|
# [architecture]
|
||||||
|
# # srcs/
|
||||||
|
# # main.c
|
||||||
|
# # function01.c
|
||||||
|
# # function02.c
|
||||||
|
# # includes/
|
||||||
|
# # header01.h
|
||||||
|
# # header02.h
|
||||||
|
# # libtest.a
|
||||||
|
# # liboption.a
|
||||||
|
# # Makefile
|
||||||
|
#
|
||||||
|
# # #-------------#
|
||||||
|
# # # VARIABLES #
|
||||||
|
# # #-------------#
|
||||||
|
# # NAME = program_test
|
||||||
|
# # CC = gcc
|
||||||
|
# # VPATH = srcs
|
||||||
|
# #
|
||||||
|
# # IDIR = includes
|
||||||
|
# # _DEPS = header01.h \
|
||||||
|
# # header02.h
|
||||||
|
# # DEPS = $(_DEPS:%.h=$(IDIR)/%.h)
|
||||||
|
# #
|
||||||
|
# # LDIR = ./
|
||||||
|
# # _LIBS = libtest.a \
|
||||||
|
# # liboption.a
|
||||||
|
# # LIBS = $(_LIBS:lib%.a=%)
|
||||||
|
# #
|
||||||
|
# # SRCS = main.c \
|
||||||
|
# # function01.c
|
||||||
|
# # function02.c
|
||||||
|
# # ODIR = ./builds
|
||||||
|
# # OBJS = $(SRCS:%.c=$(ODIR)/%.o)
|
||||||
|
# #
|
||||||
|
# # CFLAGS = -I$(IDIR)
|
||||||
|
# # LFLAGS = -L$(LDIR) -l$(LIBS)
|
||||||
|
# #
|
||||||
|
# # #---------#
|
||||||
|
# # # RULES #
|
||||||
|
# # #---------#
|
||||||
|
# # all: $(ODIR) $(NAME)
|
||||||
|
# # $(NAME): $(OBJS) $(DEPS)
|
||||||
|
# # $(CC) $(CFLAGS) -o $@ $(OBJS) $(LFLAGS)
|
||||||
|
# # $(ODIR):
|
||||||
|
# # mkdir -p $@
|
||||||
|
# # $(ODIR)/%.o: %.c
|
||||||
|
# # $(CC) $(CFLAGS) -c -o $@ $<
|
||||||
|
# # clean:
|
||||||
|
# # /bin/rm -rf $(ODIR)
|
||||||
|
# # fclean: clean
|
||||||
|
# # /bin/rm -f $(NAME)
|
||||||
|
# # re: fclean all
|
||||||
|
# # .PHONY: all clean fclean re
|
||||||
|
#
|
||||||
|
# # prompt "make" execute the first rule ("all")
|
||||||
|
#
|
||||||
|
# [architecture]
|
||||||
|
# # srcs/
|
||||||
|
# # main.c
|
||||||
|
# # function01.c
|
||||||
|
# # function02.c
|
||||||
|
# # includes/
|
||||||
|
# # header01.h
|
||||||
|
# # header02.h
|
||||||
|
# # builds/ ++
|
||||||
|
# # main.o ++
|
||||||
|
# # function01.o ++
|
||||||
|
# # function02.o ++
|
||||||
|
# # libtest.a
|
||||||
|
# # liboption.a
|
||||||
|
# # Makefile
|
||||||
|
# # program_test ++
|
||||||
|
#
|
||||||
|
# -----
|
||||||
|
#
|
||||||
|
# VPATH = srcs
|
||||||
|
#
|
||||||
|
# build-in variable VPATH is a list of directories where
|
||||||
|
# makefile looks for files that it doesn't find in the
|
||||||
|
# first place, so it let you easily put .c files into
|
||||||
|
# subdirectories
|
||||||
|
#
|
||||||
|
# -----
|
||||||
|
#
|
||||||
|
# LIBS = $(_LIBS:lib%.a=%)
|
||||||
|
#
|
||||||
|
# from "libtest.a" and "liboption.a" it creates "test"
|
||||||
|
# and "option"
|
||||||
|
#
|
||||||
|
# as said, the value of the % in "replacement" is
|
||||||
|
# replaced with the text matched by the % in "pattern"
|
||||||
|
#
|
||||||
|
# -----
|
||||||
|
#
|
||||||
|
# OBJS = $(SRCS:%.c=$(ODIR)/%.o)
|
||||||
|
#
|
||||||
|
# creates the list of .o from the .c with addition of the
|
||||||
|
# path directory "builds/main.o"
|
||||||
|
#
|
||||||
|
# it could be :
|
||||||
|
# $(patsubst %.c,$(ODIR)/%.o,$(SRCS))
|
||||||
|
# or :
|
||||||
|
# $(addprefix $(ODIR)/, $(SRCS:.c=.o))
|
||||||
|
#
|
||||||
|
# -----
|
||||||
|
#
|
||||||
|
# $(NAME): $(OBJS) $(DEPS)
|
||||||
|
# $(CC) $(CFLAGS) -o $@ $(OBJS) $(LFLAGS)
|
||||||
|
#
|
||||||
|
# NAME depends on OBJS and DEPS, so if any .o or any .h
|
||||||
|
# have more recent date of modification NAME will execute
|
||||||
|
# again only for them
|
||||||
|
|
||||||
|
# - - - - - - - - - - - - - - - - -
|
||||||
|
# makefile making another makefile
|
||||||
|
# - - - - - - - - - - - - - - - - -
|
||||||
|
|
||||||
|
# compiling a makefile with compiling another makefile in
|
||||||
|
# a subdirectory wich contain the library used by the
|
||||||
|
# roots makefile
|
||||||
|
#
|
||||||
|
# [architecture]
|
||||||
|
# # srcs/
|
||||||
|
# # main.c
|
||||||
|
# # function01.c
|
||||||
|
# # function02.c
|
||||||
|
# # includes/
|
||||||
|
# # header01.h
|
||||||
|
# # header02.h
|
||||||
|
# # libtest/
|
||||||
|
# # Makefile
|
||||||
|
# # header_lib.h
|
||||||
|
# # function_lib01.c
|
||||||
|
# # function_lib02.c
|
||||||
|
# # libtest.a
|
||||||
|
# # Makefile
|
||||||
|
#
|
||||||
|
# # #-------------#
|
||||||
|
# # # VARIABLES #
|
||||||
|
# # #-------------#
|
||||||
|
# # NAME = program_test
|
||||||
|
# # CC = gcc
|
||||||
|
# # VPATH = srcs
|
||||||
|
# #
|
||||||
|
# # IDIR = includes
|
||||||
|
# # _DEPS = header01.h \
|
||||||
|
# # header02.h
|
||||||
|
# # DEPS = $(_DEPS:%.h=$(IDIR)/%.h)
|
||||||
|
# #
|
||||||
|
# # LDIR = ./libtest/
|
||||||
|
# # _LIBS = libtest.a \
|
||||||
|
# # LIBS = $(_LIBS:lib%.a=%)
|
||||||
|
# #
|
||||||
|
# # SRCS = main.c \
|
||||||
|
# # function01.c
|
||||||
|
# # function02.c
|
||||||
|
# # ODIR = ./builds
|
||||||
|
# # OBJS = $(SRCS:%.c=$(ODIR)/%.o)
|
||||||
|
# #
|
||||||
|
# # CFLAGS = -I$(IDIR)
|
||||||
|
# # LFLAGS = -L$(LDIR) -l$(LIBS)
|
||||||
|
# #
|
||||||
|
# # #---------#
|
||||||
|
# # # RULES #
|
||||||
|
# # #---------#
|
||||||
|
# # all: $(ODIR) $(NAME)
|
||||||
|
# # $(NAME): $(OBJS) $(DEPS)
|
||||||
|
# # make -C $(LDIR)
|
||||||
|
# # $(CC) $(CFLAGS) -o $@ $(OBJS) $(LFLAGS)
|
||||||
|
# # $(ODIR):
|
||||||
|
# # mkdir -p $@
|
||||||
|
# # $(ODIR)/%.o: %.c
|
||||||
|
# # $(CC) $(CFLAGS) -c -o $@ $<
|
||||||
|
# # clean:
|
||||||
|
# # make clean -C $(LDIR)
|
||||||
|
# # /bin/rm -rf $(ODIR)
|
||||||
|
# # fclean: clean
|
||||||
|
# # make fclean -C $(LDIR)
|
||||||
|
# # /bin/rm -f $(NAME)
|
||||||
|
# # re: fclean all
|
||||||
|
# # .PHONY: all clean fclean re
|
||||||
|
#
|
||||||
|
# # prompt "make" execute the first rule ("all")
|
||||||
|
#
|
||||||
|
# [archtecture]
|
||||||
|
# # srcs/
|
||||||
|
# # main.c
|
||||||
|
# # function01.c
|
||||||
|
# # function02.c
|
||||||
|
# # includes/
|
||||||
|
# # header01.h
|
||||||
|
# # header02.h
|
||||||
|
# # builds/ ++
|
||||||
|
# # main.o ++
|
||||||
|
# # function01.o ++
|
||||||
|
# # function02.o ++
|
||||||
|
# # libtest/
|
||||||
|
# # Makefile
|
||||||
|
# # header_lib.h
|
||||||
|
# # function_lib01.c
|
||||||
|
# # function_lib02.c
|
||||||
|
# # libtest.a
|
||||||
|
# # Makefile
|
||||||
|
# # program_test ++
|
||||||
|
#
|
||||||
|
# -----
|
||||||
|
#
|
||||||
|
# make -C $(LDIR)
|
||||||
|
#
|
||||||
|
# make -C <path>
|
||||||
|
#
|
||||||
|
# the -C option says to makefile it should first go to the
|
||||||
|
# path location and then do "make"
|
||||||
|
#
|
||||||
|
# it's similar to :
|
||||||
|
#
|
||||||
|
# rule:
|
||||||
|
# cd $(LDIR) && make
|
||||||
|
#
|
||||||
|
|
||||||
|
# - - - - - - - - - - - -
|
||||||
|
# makefile for a library
|
||||||
|
# - - - - - - - - - - - -
|
||||||
|
|
||||||
|
#
|
||||||
|
# exemple of a makefile used not for a compilation into a
|
||||||
|
# binary executable, but to create a library
|
||||||
|
#
|
||||||
|
# [architecture]
|
||||||
|
# # srcs/
|
||||||
|
# # function01.c
|
||||||
|
# # function02.c
|
||||||
|
# # includes/
|
||||||
|
# # header.h
|
||||||
|
# # Makefile
|
||||||
|
#
|
||||||
|
# # #-------------#
|
||||||
|
# # # VARIABLES #
|
||||||
|
# # #-------------#
|
||||||
|
# # NAME = libtest.a
|
||||||
|
# # CC = gcc
|
||||||
|
# # VPATH = srcs
|
||||||
|
# #
|
||||||
|
# # IDIR = includes
|
||||||
|
# # _DEPS = header.h
|
||||||
|
# # DEPS = $(_DEPS:%.h=$(IDIR)/%.h)
|
||||||
|
# #
|
||||||
|
# # SRCS = function01.c \
|
||||||
|
# # function02.c
|
||||||
|
# # ODIR = ./builds
|
||||||
|
# # OBJS = $(SRCS:%.c=$(ODIR)/%.o)
|
||||||
|
# #
|
||||||
|
# # CFLAGS = -I$(IDIR)
|
||||||
|
# #
|
||||||
|
# # #---------#
|
||||||
|
# # # RULES #
|
||||||
|
# # #---------#
|
||||||
|
# # all: $(ODIR) $(NAME)
|
||||||
|
# # $(NAME): $(OBJS) $(DEP)
|
||||||
|
# # ar -rc $@ $(OBJS)
|
||||||
|
# # @ranlib $@
|
||||||
|
# # $(ODIR):
|
||||||
|
# # mkdir -p $@
|
||||||
|
# # $(ODIR)/%.o: %.c
|
||||||
|
# # $(CC) $(CFLAGS) -c -o $@ $<
|
||||||
|
# # clean:
|
||||||
|
# # /bin/rm -rf $(ODIR)
|
||||||
|
# # fclean: clean
|
||||||
|
# # /bin/rm -f $(NAME)
|
||||||
|
# # re: fclean all
|
||||||
|
# # .PHONY: all clean fclean re
|
||||||
|
#
|
||||||
|
# # prompt "make" execute the first rule ("all")
|
||||||
|
#
|
||||||
|
# [archtecture]
|
||||||
|
# # srcs/
|
||||||
|
# # function01.c
|
||||||
|
# # function02.c
|
||||||
|
# # includes/
|
||||||
|
# # header.h
|
||||||
|
# # builds/
|
||||||
|
# # function01.o
|
||||||
|
# # function02.o
|
||||||
|
# # libtest.a
|
||||||
|
# # Makefile
|
||||||
|
#
|
||||||
|
# -----
|
||||||
|
#
|
||||||
|
# NAME = libtest.a
|
||||||
|
#
|
||||||
|
# name is now the name of the library to be built
|
||||||
|
#
|
||||||
|
# -----
|
||||||
|
#
|
||||||
|
# @ranlib $@
|
||||||
|
#
|
||||||
|
# @ tells makefile not to show the line in prompt
|
||||||
|
#
|
||||||
|
|
||||||
|
#
|
||||||
|
# THE END
|
||||||
|
# enjoy, futur me
|
||||||
|
#
|
||||||
24
libs/libft/deleted/ft_lst_find.bak
Normal file
24
libs/libft/deleted/ft_lst_find.bak
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_lstfind.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: simplonco <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2022/03/23 22:48:47 by simplonco #+# #+# */
|
||||||
|
/* Updated: 2022/03/23 22:49:16 by simplonco ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* find an element with the comp function, and return a pointer to it
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
t_list *ft_lstfind(t_list *lst, void *to_find, int (*comp)(void*, void *))
|
||||||
|
{
|
||||||
|
while (lst && (!comp(to_find, lst->content)))
|
||||||
|
lst = lst->next;
|
||||||
|
return (lst);
|
||||||
|
}
|
||||||
94
libs/libft/deleted/ft_lstadd_back.bak
Normal file
94
libs/libft/deleted/ft_lstadd_back.bak
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_lstadd_back.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2019/11/25 14:11:53 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2022/03/23 21:50:42 by simplonco ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
/*
|
||||||
|
** add an element to the end of a list, or first if list has no element yet
|
||||||
|
** return NULL if element is NULL (eg, it returned from ft_lstnew and failed)
|
||||||
|
** or else address to the element added
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
** #include <libc.h>
|
||||||
|
**
|
||||||
|
** typedef struct s_list
|
||||||
|
** {
|
||||||
|
** void *content;
|
||||||
|
** struct s_list *next;
|
||||||
|
** } t_list;
|
||||||
|
**
|
||||||
|
** t_list *ft_lstnew(void *content)
|
||||||
|
** {
|
||||||
|
** t_list *lst;
|
||||||
|
**
|
||||||
|
** if (!(lst = (t_list *)malloc(sizeof(*lst))))
|
||||||
|
** return (NULL);
|
||||||
|
** if (!content)
|
||||||
|
** lst->content = NULL;
|
||||||
|
** else
|
||||||
|
** lst->content = content;
|
||||||
|
** lst->next = NULL;
|
||||||
|
** return (lst);
|
||||||
|
** }
|
||||||
|
**
|
||||||
|
** void ft_lstadd_back(t_list **alst, t_list *new);
|
||||||
|
**
|
||||||
|
** int main(void)
|
||||||
|
** {
|
||||||
|
** char tresor;
|
||||||
|
** char matos;
|
||||||
|
** char friends;
|
||||||
|
** t_list *toto;
|
||||||
|
** t_list *tmp;
|
||||||
|
**
|
||||||
|
** tresor = 'a';
|
||||||
|
** matos = 'b';
|
||||||
|
** friends = 'c';
|
||||||
|
** toto = ft_lstnew(&tresor);
|
||||||
|
** printf("toto->data :%c\n",*(char*)(toto->content));
|
||||||
|
** tmp = ft_lstnew(&matos);
|
||||||
|
** ft_lstadd_back(&toto, tmp);
|
||||||
|
** printf("----------------------\n");
|
||||||
|
** printf("toto->data :%c\n",*(char*)(toto->content));
|
||||||
|
** printf("toto->nxt->data :%c\n",*(char*)(toto->next->content));
|
||||||
|
** tmp = ft_lstnew(&friends);
|
||||||
|
** ft_lstadd_back(&toto, tmp);
|
||||||
|
** printf("----------------------\n");
|
||||||
|
** printf("toto->data :%c\n",*(char*)(toto->content));
|
||||||
|
** printf("toto->nxt->data :%c\n",*(char*)(toto->next->content));
|
||||||
|
** printf("toto->nxt->nxt->data:%c\n",*(char*)(toto->next->next->content));
|
||||||
|
** printf("toto->nxt->nxt->nxt :%s\n",(char*)(toto->next->next->next));
|
||||||
|
** return (0);
|
||||||
|
** }
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void *ft_lstadd_back(t_list **alst, t_list *new)
|
||||||
|
{
|
||||||
|
t_list *tmp;
|
||||||
|
|
||||||
|
if (!new)
|
||||||
|
return (NULL);
|
||||||
|
if (alst)
|
||||||
|
{
|
||||||
|
tmp = *alst;
|
||||||
|
if (!tmp)
|
||||||
|
*alst = new;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
while (tmp->next)
|
||||||
|
tmp = tmp->next;
|
||||||
|
tmp->next = new;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (tmp);
|
||||||
|
}
|
||||||
94
libs/libft/deleted/ft_lstadd_front.bak
Normal file
94
libs/libft/deleted/ft_lstadd_front.bak
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_lstadd_front.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2019/11/25 14:12:02 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2019/11/25 14:36:54 by hulamy ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
/*
|
||||||
|
** add an element to the begining of a list
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
** #include <libc.h>
|
||||||
|
**
|
||||||
|
** typedef struct s_list
|
||||||
|
** {
|
||||||
|
** void *content;
|
||||||
|
** struct s_list *next;
|
||||||
|
** } t_list;
|
||||||
|
**
|
||||||
|
** void *ft_memcpy(void *dst, const void *src, size_t n)
|
||||||
|
** {
|
||||||
|
** size_t i;
|
||||||
|
** char *ptr;
|
||||||
|
** char *ptr2;
|
||||||
|
**
|
||||||
|
** ptr = (char *)dst;
|
||||||
|
** ptr2 = (char *)src;
|
||||||
|
** i = -1;
|
||||||
|
** while (++i < n)
|
||||||
|
** ptr[i] = ptr2[i];
|
||||||
|
** return (dst);
|
||||||
|
** }
|
||||||
|
**
|
||||||
|
** t_list *ft_lstnew(void *content)
|
||||||
|
** {
|
||||||
|
** t_list *lst;
|
||||||
|
**
|
||||||
|
** if (!(lst = (t_list *)malloc(sizeof(*lst))))
|
||||||
|
** return (NULL);
|
||||||
|
** if (!content)
|
||||||
|
** lst->content = NULL;
|
||||||
|
** else
|
||||||
|
** {
|
||||||
|
** if (!(lst->content = malloc(sizeof(content))))
|
||||||
|
** return (NULL);
|
||||||
|
** ft_memcpy(lst->content, content, sizeof(content));
|
||||||
|
** }
|
||||||
|
** lst->next = NULL;
|
||||||
|
** return (lst);
|
||||||
|
** }
|
||||||
|
**
|
||||||
|
** void ft_lstadd_front(t_list **alst, t_list *new);
|
||||||
|
**
|
||||||
|
** int main(void)
|
||||||
|
** {
|
||||||
|
** char tresor;
|
||||||
|
** char matos;
|
||||||
|
** char friends;
|
||||||
|
** t_list *toto;
|
||||||
|
** t_list *tmp;
|
||||||
|
**
|
||||||
|
** tresor = 'a';
|
||||||
|
** matos = 'b';
|
||||||
|
** friends = 'c';
|
||||||
|
** toto = ft_lstnew(&tresor);
|
||||||
|
** printf("toto->data :%c\n",*(char*)(toto->content));
|
||||||
|
** tmp = ft_lstnew(&matos);
|
||||||
|
** ft_lstadd_front(&toto, tmp);
|
||||||
|
** printf("----------------------\n");
|
||||||
|
** printf("toto->data :%c\n",*(char*)(toto->content));
|
||||||
|
** printf("toto->nxt->data :%c\n",*(char*)(toto->next->content));
|
||||||
|
** tmp = ft_lstnew(&friends);
|
||||||
|
** ft_lstadd_front(&toto, tmp);
|
||||||
|
** printf("----------------------\n");
|
||||||
|
** printf("toto->data :%c\n",*(char*)(toto->content));
|
||||||
|
** printf("toto->nxt->data :%c\n",*(char*)(toto->next->content));
|
||||||
|
** printf("toto->nxt->nxt->dqta:%c\n",*(char*)(toto->next->next->content));
|
||||||
|
** return (0);
|
||||||
|
** }
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_lstadd_front(t_list **alst, t_list *new)
|
||||||
|
{
|
||||||
|
new->next = *alst;
|
||||||
|
*alst = new;
|
||||||
|
}
|
||||||
107
libs/libft/deleted/ft_lstclear.bak
Normal file
107
libs/libft/deleted/ft_lstclear.bak
Normal file
@@ -0,0 +1,107 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_lstclear.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2019/11/25 14:13:30 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2019/11/28 17:06:48 by hulamy ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
/*
|
||||||
|
** delete and free an element of the list and all the followings
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
** #include <libc.h>
|
||||||
|
**
|
||||||
|
** typedef struct s_list
|
||||||
|
** {
|
||||||
|
** void *content;
|
||||||
|
** struct s_list *next;
|
||||||
|
** } t_list;
|
||||||
|
**
|
||||||
|
** t_list *ft_lstnew(void *content)
|
||||||
|
** {
|
||||||
|
** t_list *lst;
|
||||||
|
**
|
||||||
|
** if (!(lst = (t_list *)malloc(sizeof(*lst))))
|
||||||
|
** return (NULL);
|
||||||
|
** if (!content)
|
||||||
|
** lst->content = NULL;
|
||||||
|
** else
|
||||||
|
** lst->content = content;
|
||||||
|
** lst->next = NULL;
|
||||||
|
** return (lst);
|
||||||
|
** }
|
||||||
|
**
|
||||||
|
** void ft_lstadd_back(t_list **alst, t_list *new)
|
||||||
|
** {
|
||||||
|
** t_list *tmp;
|
||||||
|
**
|
||||||
|
** if (alst)
|
||||||
|
** {
|
||||||
|
** tmp = *alst;
|
||||||
|
** if (!tmp)
|
||||||
|
** *alst = new;
|
||||||
|
** else
|
||||||
|
** {
|
||||||
|
** while (tmp->next)
|
||||||
|
** tmp = tmp->next;
|
||||||
|
** tmp->next = new;
|
||||||
|
** }
|
||||||
|
** new->next = NULL;
|
||||||
|
** }
|
||||||
|
** }
|
||||||
|
**
|
||||||
|
** void ft_delete(void *element)
|
||||||
|
** {
|
||||||
|
** *(char*)element = '\0';
|
||||||
|
** }
|
||||||
|
**
|
||||||
|
** void ft_lstdelone(t_list *lst, void (*del)(void *))
|
||||||
|
** {
|
||||||
|
** del(lst->content);
|
||||||
|
** free(lst);
|
||||||
|
** lst = NULL;
|
||||||
|
** }
|
||||||
|
**
|
||||||
|
** void ft_lstclear(t_list **lst, void (*del)(void *));
|
||||||
|
**
|
||||||
|
** int main(void)
|
||||||
|
** {
|
||||||
|
** t_list *toto;
|
||||||
|
** void (ft_delete)(void*);
|
||||||
|
**
|
||||||
|
** printf("sizeof(t_list)%lu\n",sizeof(t_list));
|
||||||
|
** toto = ft_lstnew("a");
|
||||||
|
** toto->next = ft_lstnew("b");
|
||||||
|
** toto->next->next = ft_lstnew("c");
|
||||||
|
** printf("toto->data :%c\n",*(char*)(toto->content));
|
||||||
|
** printf("toto->nxt->data :%c\n",*(char*)(toto->next->content));
|
||||||
|
** printf("toto->nxt->nxt->data:%c\n",*(char*)(toto->next->next->content));
|
||||||
|
** printf("toto->nxt->nxt->nxt :%s\n",(char*)(toto->next->next->next));
|
||||||
|
** ft_lstclear(&(toto->next), ft_delete);
|
||||||
|
** printf("----------------------\n");
|
||||||
|
** printf("toto->data :%c\n",*(char*)(toto->content));
|
||||||
|
** printf("toto->nxt->data :%c\n",*(char*)(toto->next->content));
|
||||||
|
** printf("toto->nxt->nxt :%s\n",(char*)(toto->next->next));
|
||||||
|
** return (0);
|
||||||
|
** }
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_lstclear(t_list **lst, void (*del)(void *))
|
||||||
|
{
|
||||||
|
t_list *next;
|
||||||
|
|
||||||
|
while (*lst != NULL)
|
||||||
|
{
|
||||||
|
next = (*lst)->next;
|
||||||
|
ft_lstdelone(*lst, del);
|
||||||
|
*lst = next;
|
||||||
|
}
|
||||||
|
}
|
||||||
97
libs/libft/deleted/ft_lstdelone.bak
Normal file
97
libs/libft/deleted/ft_lstdelone.bak
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_lstdelone.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2019/11/25 14:14:03 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2019/11/25 14:35:53 by hulamy ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
/*
|
||||||
|
** free an element and delete its content with del
|
||||||
|
** next is not free
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
** #include <libc.h>
|
||||||
|
**
|
||||||
|
** typedef struct s_list
|
||||||
|
** {
|
||||||
|
** void *content;
|
||||||
|
** struct s_list *next;
|
||||||
|
** } t_list;
|
||||||
|
**
|
||||||
|
** t_list *ft_lstnew(void *content)
|
||||||
|
** {
|
||||||
|
** t_list *lst;
|
||||||
|
**
|
||||||
|
** if (!(lst = (t_list *)malloc(sizeof(*lst))))
|
||||||
|
** return (NULL);
|
||||||
|
** if (!content)
|
||||||
|
** lst->content = NULL;
|
||||||
|
** else
|
||||||
|
** lst->content = content;
|
||||||
|
** lst->next = NULL;
|
||||||
|
** return (lst);
|
||||||
|
** }
|
||||||
|
**
|
||||||
|
** void ft_lstadd_back(t_list **alst, t_list *new)
|
||||||
|
** {
|
||||||
|
** t_list *tmp;
|
||||||
|
**
|
||||||
|
** if (alst)
|
||||||
|
** {
|
||||||
|
** tmp = *alst;
|
||||||
|
** if (!tmp)
|
||||||
|
** *alst = new;
|
||||||
|
** else
|
||||||
|
** {
|
||||||
|
** while (tmp->next)
|
||||||
|
** tmp = tmp->next;
|
||||||
|
** tmp->next = new;
|
||||||
|
** }
|
||||||
|
** new->next = NULL;
|
||||||
|
** }
|
||||||
|
** }
|
||||||
|
**
|
||||||
|
** void ft_delete(void *element)
|
||||||
|
** {
|
||||||
|
** *(char*)element = '\0';
|
||||||
|
** }
|
||||||
|
**
|
||||||
|
** void ft_lstdelone(t_list *lst, void (*del)(void *));
|
||||||
|
**
|
||||||
|
** int main(void)
|
||||||
|
** {
|
||||||
|
** t_list *toto;
|
||||||
|
** void (ft_delete)(void*);
|
||||||
|
**
|
||||||
|
** toto = ft_lstnew("a");
|
||||||
|
** toto->next = ft_lstnew("b");
|
||||||
|
** toto->next->next = ft_lstnew("c");
|
||||||
|
** printf("toto->data :%c\n",*(char*)(toto->content));
|
||||||
|
** printf("toto->nxt->data :%c\n",*(char*)(toto->next->content));
|
||||||
|
** printf("toto->nxt->nxt->data:%c\n",*(char*)(toto->next->next->content));
|
||||||
|
** printf("toto->nxt->nxt->nxt :%s\n",(char*)(toto->next->next->next));
|
||||||
|
** ft_lstdelone(toto->next, ft_delete);
|
||||||
|
** printf("----------------------\n");
|
||||||
|
** printf("toto->data :%c\n",*(char*)(toto->content));
|
||||||
|
** printf("toto->nxt->data :%c\n",*(char*)(toto->next->content));
|
||||||
|
** printf("toto->nxt->nxt->data:%c\n",*(char*)(toto->next->next->content));
|
||||||
|
** printf("toto->nxt->nxt->nxt :%s\n",(char*)(toto->next->next->next));
|
||||||
|
** return (0);
|
||||||
|
** }
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_lstdelone(t_list *lst, void (*del)(void *))
|
||||||
|
{
|
||||||
|
if (lst->content && del)
|
||||||
|
del(lst->content);
|
||||||
|
free(lst);
|
||||||
|
lst = NULL;
|
||||||
|
}
|
||||||
85
libs/libft/deleted/ft_lstiter.bak
Normal file
85
libs/libft/deleted/ft_lstiter.bak
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_lstiter.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2019/11/25 14:14:11 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2019/12/01 16:03:40 by hulamy ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
/*
|
||||||
|
** go through all elements of the list and apply the function f to each of them
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
** #include <libc.h>
|
||||||
|
**
|
||||||
|
** typedef struct s_list
|
||||||
|
** {
|
||||||
|
** void *content;
|
||||||
|
** struct s_list *next;
|
||||||
|
** } t_list;
|
||||||
|
**
|
||||||
|
** t_list *ft_lstnew(void *content)
|
||||||
|
** {
|
||||||
|
** t_list *lst;
|
||||||
|
**
|
||||||
|
** if (!(lst = (t_list *)malloc(sizeof(*lst))))
|
||||||
|
** return (NULL);
|
||||||
|
** if (!content)
|
||||||
|
** lst->content = NULL;
|
||||||
|
** else
|
||||||
|
** lst->content = content;
|
||||||
|
** lst->next = NULL;
|
||||||
|
** return (lst);
|
||||||
|
** }
|
||||||
|
**
|
||||||
|
** void ft_lstiter(t_list *lst, void (*f)(void*));
|
||||||
|
**
|
||||||
|
** void to_uppercase(void *element)
|
||||||
|
** {
|
||||||
|
** // *(char*)(((t_list*)element)->content) -= 32;
|
||||||
|
** // or :
|
||||||
|
** t_list *tmp;
|
||||||
|
**
|
||||||
|
** tmp = (t_list*)element;
|
||||||
|
** *(char*)(tmp->content) -= 32;
|
||||||
|
** }
|
||||||
|
**
|
||||||
|
** int main(void)
|
||||||
|
** {
|
||||||
|
** t_list *toto;
|
||||||
|
** void to_uppercase(void*);
|
||||||
|
**
|
||||||
|
** toto = ft_lstnew("a");
|
||||||
|
** toto->next = ft_lstnew("b");
|
||||||
|
** toto->next->next = ft_lstnew("c");
|
||||||
|
** printf("toto->data :%c\n",*(char*)(toto->content));
|
||||||
|
** printf("toto->nxt->data :%c\n",*(char*)(toto->next->content));
|
||||||
|
** printf("toto->nxt->nxt->data:%c\n",*(char*)(toto->next->next->content));
|
||||||
|
** printf("toto->nxt->nxt->nxt :%s\n",(char*)(toto->next->next->next));
|
||||||
|
** printf("---------------------------\n");
|
||||||
|
** ft_lstiter(toto, to_uppercase);
|
||||||
|
** printf("toto->data :%c\n",*(char*)(toto->content));
|
||||||
|
** printf("toto->nxt->data :%c\n",*(char*)(toto->next->content));
|
||||||
|
** printf("toto->nxt->nxt->data:%c\n",*(char*)(toto->next->next->content));
|
||||||
|
** printf("toto->nxt->nxt->nxt :%s\n",(char*)(toto->next->next->next));
|
||||||
|
** return (0);
|
||||||
|
** }
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_lstiter(t_list *lst, void (*f)(void *))
|
||||||
|
{
|
||||||
|
if (!f)
|
||||||
|
return ;
|
||||||
|
while (lst)
|
||||||
|
{
|
||||||
|
f(lst->content);
|
||||||
|
lst = lst->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
100
libs/libft/deleted/ft_lstlast.bak
Normal file
100
libs/libft/deleted/ft_lstlast.bak
Normal file
@@ -0,0 +1,100 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_lstlast.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2019/11/25 14:14:49 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2019/11/28 16:43:18 by hulamy ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
/*
|
||||||
|
** return a pointer to the last element of a list
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
** #include <libc.h>
|
||||||
|
**
|
||||||
|
** typedef struct s_list
|
||||||
|
** {
|
||||||
|
** void *content;
|
||||||
|
** struct s_list *next;
|
||||||
|
** } t_list;
|
||||||
|
**
|
||||||
|
** void *ft_memcpy(void *dst, const void *src, size_t n)
|
||||||
|
** {
|
||||||
|
** size_t i;
|
||||||
|
** char *ptr;
|
||||||
|
** char *ptr2;
|
||||||
|
**
|
||||||
|
** ptr = (char *)dst;
|
||||||
|
** ptr2 = (char *)src;
|
||||||
|
** i = -1;
|
||||||
|
** while (++i < n)
|
||||||
|
** ptr[i] = ptr2[i];
|
||||||
|
** return (dst);
|
||||||
|
** }
|
||||||
|
**
|
||||||
|
** t_list *ft_lstnew(void *content)
|
||||||
|
** {
|
||||||
|
** t_list *lst;
|
||||||
|
**
|
||||||
|
** if (!(lst = (t_list *)malloc(sizeof(*lst))))
|
||||||
|
** return (NULL);
|
||||||
|
** if (!content)
|
||||||
|
** lst->content = NULL;
|
||||||
|
** else
|
||||||
|
** {
|
||||||
|
** if (!(lst->content = malloc(sizeof(content))))
|
||||||
|
** return (NULL);
|
||||||
|
** ft_memcpy(lst->content, content, sizeof(content));
|
||||||
|
** }
|
||||||
|
** lst->next = NULL;
|
||||||
|
** return (lst);
|
||||||
|
** }
|
||||||
|
**
|
||||||
|
** void ft_lstadd_front(t_list **alst, t_list *new)
|
||||||
|
** {
|
||||||
|
** new->next = *alst;
|
||||||
|
** *alst = new;
|
||||||
|
** }
|
||||||
|
**
|
||||||
|
** t_list *ft_lstlast(t_list *lst);
|
||||||
|
**
|
||||||
|
** int main(void)
|
||||||
|
** {
|
||||||
|
** char tresor;
|
||||||
|
** t_list *toto;
|
||||||
|
** t_list *tmp;
|
||||||
|
**
|
||||||
|
** tresor = 'a';
|
||||||
|
** toto = ft_lstnew(&tresor);
|
||||||
|
** tresor = 'b';
|
||||||
|
** tmp = ft_lstnew(&tresor);
|
||||||
|
** ft_lstadd_front(&toto, tmp);
|
||||||
|
** tresor = 'c';
|
||||||
|
** tmp = ft_lstnew(&tresor);
|
||||||
|
** ft_lstadd_front(&toto, tmp);
|
||||||
|
** printf("toto->data :%c\n",*(char*)(toto->content));
|
||||||
|
** printf("toto->nxt->data :%c\n",*(char*)(toto->next->content));
|
||||||
|
** printf("toto->nxt->nxt->data:%c\n",*(char*)(toto->next->next->content));
|
||||||
|
** tmp = ft_lstlast(toto);
|
||||||
|
** printf("%c\n",*(char*)(tmp->content));
|
||||||
|
** printf("toto->data :%c\n",*(char*)(toto->content));
|
||||||
|
** printf("toto->nxt->data :%c\n",*(char*)(toto->next->content));
|
||||||
|
** printf("toto->nxt->nxt->data:%c\n",*(char*)(toto->next->next->content));
|
||||||
|
** return (0);
|
||||||
|
** }
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
t_list *ft_lstlast(t_list *lst)
|
||||||
|
{
|
||||||
|
if (lst)
|
||||||
|
while (lst->next)
|
||||||
|
lst = lst->next;
|
||||||
|
return (lst);
|
||||||
|
}
|
||||||
145
libs/libft/deleted/ft_lstmap.bak
Normal file
145
libs/libft/deleted/ft_lstmap.bak
Normal file
@@ -0,0 +1,145 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_lstmap.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2019/11/25 14:15:42 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2019/12/01 16:02:13 by hulamy ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
/*
|
||||||
|
** iterate trhough linked list and apply to each element a function f
|
||||||
|
** if necessary the function del is used to delete an element
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
** #include <stdlib.h>
|
||||||
|
** #include <unistd.h>
|
||||||
|
** #include <stdio.h>
|
||||||
|
**
|
||||||
|
** typedef struct s_list
|
||||||
|
** {
|
||||||
|
** void *content;
|
||||||
|
** struct s_list *next;
|
||||||
|
** } t_list;
|
||||||
|
**
|
||||||
|
** t_list *ft_lstnew(void *content)
|
||||||
|
** {
|
||||||
|
** t_list *lst;
|
||||||
|
**
|
||||||
|
** if (!(lst = (t_list *)malloc(sizeof(*lst))))
|
||||||
|
** return (NULL);
|
||||||
|
** if (!content)
|
||||||
|
** lst->content = NULL;
|
||||||
|
** else
|
||||||
|
** lst->content = content;
|
||||||
|
** lst->next = NULL;
|
||||||
|
** return (lst);
|
||||||
|
** }
|
||||||
|
**
|
||||||
|
** void ft_lstadd_back(t_list **alst, t_list *new)
|
||||||
|
** {
|
||||||
|
** t_list *tmp;
|
||||||
|
**
|
||||||
|
** if (alst)
|
||||||
|
** {
|
||||||
|
** tmp = *alst;
|
||||||
|
** if (!tmp)
|
||||||
|
** *alst = new;
|
||||||
|
** else
|
||||||
|
** {
|
||||||
|
** while (tmp->next)
|
||||||
|
** tmp = tmp->next;
|
||||||
|
** tmp->next = new;
|
||||||
|
** }
|
||||||
|
** new->next = NULL;
|
||||||
|
** }
|
||||||
|
** }
|
||||||
|
**
|
||||||
|
** char *ft_strdup(const char *src)
|
||||||
|
** {
|
||||||
|
** int i;
|
||||||
|
** char *str;
|
||||||
|
**
|
||||||
|
** i = 0;
|
||||||
|
** while (src[i] != '\0')
|
||||||
|
** i++;
|
||||||
|
** if (!(str = (char*)malloc(sizeof(*str) * (i + 1))))
|
||||||
|
** return (NULL);
|
||||||
|
** while (i-- >= 0)
|
||||||
|
** str[i + 1] = src[i + 1];
|
||||||
|
** return (str);
|
||||||
|
** }
|
||||||
|
**
|
||||||
|
** void *to_uppercase(void *element)
|
||||||
|
** {
|
||||||
|
** char *i;
|
||||||
|
**
|
||||||
|
** if (!(i = ft_strdup((char*)element)))
|
||||||
|
** return (NULL);
|
||||||
|
** *i -= 32;
|
||||||
|
** return ((void *)i);
|
||||||
|
** }
|
||||||
|
**
|
||||||
|
** void ft_delete(void *element)
|
||||||
|
** {
|
||||||
|
** *(char*)element = '\0';
|
||||||
|
** }
|
||||||
|
**
|
||||||
|
** t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *));
|
||||||
|
**
|
||||||
|
** int main(void)
|
||||||
|
** {
|
||||||
|
** t_list *toto;
|
||||||
|
** void *(to_uppercase)(void *);
|
||||||
|
** void (ft_delete)(void*);
|
||||||
|
**
|
||||||
|
** toto = ft_lstnew("aa");
|
||||||
|
** toto->next = ft_lstnew("b");
|
||||||
|
** toto->next->next = ft_lstnew("c");
|
||||||
|
** printf("toto->data :%s\n",(char*)(toto->content));
|
||||||
|
** printf("toto->nxt->data :%s\n",(char*)(toto->next->content));
|
||||||
|
** printf("toto->nxt->nxt->data:%s\n",(char*)(toto->next->next->content));
|
||||||
|
** printf("toto->nxt->nxt->nxt :%s\n",(char*)(toto->next->next->next));
|
||||||
|
** toto = ft_lstmap(toto, to_uppercase, ft_delete);
|
||||||
|
** printf("----------------------\n");
|
||||||
|
** printf("toto->data :%s\n",(char*)(toto->content));
|
||||||
|
** printf("toto->nxt->data :%s\n",(char*)(toto->next->content));
|
||||||
|
** printf("toto->nxt->nxt->data:%s\n",(char*)(toto->next->next->content));
|
||||||
|
** printf("toto->nxt->nxt->nxt :%s\n",(char*)(toto->next->next->next));
|
||||||
|
** return (0);
|
||||||
|
** }
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *))
|
||||||
|
{
|
||||||
|
t_list *new;
|
||||||
|
t_list *tmp;
|
||||||
|
|
||||||
|
if (!lst)
|
||||||
|
return (NULL);
|
||||||
|
if (!(tmp = ft_lstnew(f(lst->content))))
|
||||||
|
{
|
||||||
|
del(tmp->content);
|
||||||
|
free(tmp);
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
new = tmp;
|
||||||
|
while (lst->next)
|
||||||
|
{
|
||||||
|
lst = lst->next;
|
||||||
|
if (!(tmp->next = ft_lstnew(f(lst->content))))
|
||||||
|
{
|
||||||
|
del(tmp->next->content);
|
||||||
|
free(tmp->next);
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
tmp = tmp->next;
|
||||||
|
}
|
||||||
|
return (new);
|
||||||
|
}
|
||||||
57
libs/libft/deleted/ft_lstnew.bak
Normal file
57
libs/libft/deleted/ft_lstnew.bak
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_lstnew.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2019/11/25 14:16:20 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2022/03/23 20:24:40 by simplonco ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
/*
|
||||||
|
** create a new list
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
** #include <libc.h>
|
||||||
|
**
|
||||||
|
** typedef struct s_list
|
||||||
|
** {
|
||||||
|
** void *content;
|
||||||
|
** struct s_list *next;
|
||||||
|
** } t_list;
|
||||||
|
**
|
||||||
|
** t_list *ft_lstnew(void *content);
|
||||||
|
**
|
||||||
|
** int main(void)
|
||||||
|
** {
|
||||||
|
** char tresor;
|
||||||
|
** t_list *toto;
|
||||||
|
**
|
||||||
|
** tresor = 'd';
|
||||||
|
** printf("tresor : %c\n",tresor);
|
||||||
|
** toto = ft_lstnew(&tresor);
|
||||||
|
** //toto->content was alocated as void* so it need cast
|
||||||
|
** printf("toto->content : %c\n",*(char*)(toto->content));
|
||||||
|
** tresor = 'D';
|
||||||
|
** printf("transform tresor : %c\n",tresor);
|
||||||
|
** printf("and also toto->content: %c\n",*(char*)(toto->content));
|
||||||
|
** return (0);
|
||||||
|
** }
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
t_list *ft_lstnew(void *content)
|
||||||
|
{
|
||||||
|
t_list *lst;
|
||||||
|
|
||||||
|
lst = (t_list *)malloc(sizeof(*lst));
|
||||||
|
if (!lst)
|
||||||
|
return (NULL);
|
||||||
|
lst->content = content;
|
||||||
|
lst->next = NULL;
|
||||||
|
return (lst);
|
||||||
|
}
|
||||||
86
libs/libft/deleted/ft_lstsize.bak
Normal file
86
libs/libft/deleted/ft_lstsize.bak
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_lstsize.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2019/11/25 14:31:48 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2019/11/25 16:06:41 by hulamy ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
/*
|
||||||
|
** return the size of the linked list
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
** #include <libc.h>
|
||||||
|
**
|
||||||
|
** typedef struct s_list
|
||||||
|
** {
|
||||||
|
** void *content;
|
||||||
|
** struct s_list *next;
|
||||||
|
** } t_list;
|
||||||
|
**
|
||||||
|
** t_list *ft_lstnew(void *content)
|
||||||
|
** {
|
||||||
|
** t_list *lst;
|
||||||
|
**
|
||||||
|
** if (!(lst = (t_list *)malloc(sizeof(*lst))))
|
||||||
|
** return (NULL);
|
||||||
|
** if (!content)
|
||||||
|
** lst->content = NULL;
|
||||||
|
** else
|
||||||
|
** lst->content = content;
|
||||||
|
** lst->next = NULL;
|
||||||
|
** return (lst);
|
||||||
|
** }
|
||||||
|
**
|
||||||
|
** void ft_lstadd_front(t_list **alst, t_list *new)
|
||||||
|
** {
|
||||||
|
** new->next = *alst;
|
||||||
|
** *alst = new;
|
||||||
|
** }
|
||||||
|
**
|
||||||
|
** int ft_lstsize(t_list *lst);
|
||||||
|
**
|
||||||
|
** int main(void)
|
||||||
|
** {
|
||||||
|
** char tresor;
|
||||||
|
** t_list *toto;
|
||||||
|
** t_list *tmp;
|
||||||
|
**
|
||||||
|
** tresor = 'a';
|
||||||
|
** toto = ft_lstnew(&tresor);
|
||||||
|
** tresor = 'b';
|
||||||
|
** tmp = ft_lstnew(&tresor);
|
||||||
|
** ft_lstadd_front(&toto, tmp);
|
||||||
|
** tresor = 'c';
|
||||||
|
** tmp = ft_lstnew(&tresor);
|
||||||
|
** ft_lstadd_front(&toto, tmp);
|
||||||
|
** printf("toto->data :%c\n",*(char*)(toto->content));
|
||||||
|
** printf("toto->nxt->data :%c\n",*(char*)(toto->next->content));
|
||||||
|
** printf("toto->nxt->nxt->dqta:%c\n",*(char*)(toto->next->next->content));
|
||||||
|
** printf("%i\n",ft_lstsize(toto));
|
||||||
|
** printf("toto->data :%c\n",*(char*)(toto->content));
|
||||||
|
** printf("toto->nxt->data :%c\n",*(char*)(toto->next->content));
|
||||||
|
** printf("toto->nxt->nxt->dqta:%c\n",*(char*)(toto->next->next->content));
|
||||||
|
** return (0);
|
||||||
|
** }
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
int ft_lstsize(t_list *lst)
|
||||||
|
{
|
||||||
|
int size;
|
||||||
|
|
||||||
|
size = 0;
|
||||||
|
while (lst)
|
||||||
|
{
|
||||||
|
size++;
|
||||||
|
lst = lst->next;
|
||||||
|
}
|
||||||
|
return (size);
|
||||||
|
}
|
||||||
18
libs/libft/deleted/ft_putchar.c
Normal file
18
libs/libft/deleted/ft_putchar.c
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_putchar.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2018/11/14 21:14:00 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2018/11/14 21:14:01 by hulamy ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_putchar(char c)
|
||||||
|
{
|
||||||
|
write(1, &c, 1);
|
||||||
|
}
|
||||||
19
libs/libft/deleted/ft_putendl.c
Normal file
19
libs/libft/deleted/ft_putendl.c
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_putendl.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2018/11/14 21:14:32 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2018/11/14 21:14:33 by hulamy ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_putendl(char const *s)
|
||||||
|
{
|
||||||
|
ft_putstr(s);
|
||||||
|
ft_putchar('\n');
|
||||||
|
}
|
||||||
23
libs/libft/deleted/ft_putendl_fd.c
Normal file
23
libs/libft/deleted/ft_putendl_fd.c
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_putendl_fd.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2019/11/25 13:59:47 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2019/11/25 13:59:48 by hulamy ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
/*
|
||||||
|
** write the string s on the given file descriptor fd, followed by a newline
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_putendl_fd(char *s, int fd)
|
||||||
|
{
|
||||||
|
ft_putstr_fd(s, fd);
|
||||||
|
ft_putchar_fd('\n', fd);
|
||||||
|
}
|
||||||
18
libs/libft/deleted/ft_putnbr.c
Normal file
18
libs/libft/deleted/ft_putnbr.c
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_putnbr.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2018/11/14 21:14:57 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2018/11/14 21:14:58 by hulamy ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_putnbr(int n)
|
||||||
|
{
|
||||||
|
ft_putnbr_fd(n, 1);
|
||||||
|
}
|
||||||
18
libs/libft/deleted/ft_putnbrendl.c
Normal file
18
libs/libft/deleted/ft_putnbrendl.c
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_putnbrendl.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2019/02/19 10:38:07 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2019/02/19 10:42:46 by hulamy ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_putnbrendl(int n)
|
||||||
|
{
|
||||||
|
ft_putnbrendl_fd(n, 1);
|
||||||
|
}
|
||||||
29
libs/libft/deleted/ft_putnbrendl_fd.c
Normal file
29
libs/libft/deleted/ft_putnbrendl_fd.c
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_putnbrendl_fd.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2019/02/19 10:37:58 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2019/02/19 10:42:48 by hulamy ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_putnbrendl_fd(int n, int fd)
|
||||||
|
{
|
||||||
|
long l;
|
||||||
|
|
||||||
|
l = n;
|
||||||
|
if (l < 0)
|
||||||
|
{
|
||||||
|
ft_putchar_fd('-', fd);
|
||||||
|
l *= -1;
|
||||||
|
}
|
||||||
|
if (l >= 10)
|
||||||
|
ft_putnbr_fd(l / 10, fd);
|
||||||
|
ft_putchar_fd((l % 10) + '0', fd);
|
||||||
|
ft_putchar_fd('\n', fd);
|
||||||
|
}
|
||||||
22
libs/libft/deleted/ft_putstr.c
Normal file
22
libs/libft/deleted/ft_putstr.c
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_putstr.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2018/11/14 21:15:19 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2018/11/14 21:15:19 by hulamy ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_putstr(char const *s)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while (s && s[i])
|
||||||
|
ft_putchar(s[i++]);
|
||||||
|
}
|
||||||
31
libs/libft/includes/ft_gnl.h
Normal file
31
libs/libft/includes/ft_gnl.h
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* get_next_line.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2019/01/29 10:19:37 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2020/02/25 18:48:49 by hulamy ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef GET_NEXT_LINE_H
|
||||||
|
# define GET_NEXT_LINE_H
|
||||||
|
|
||||||
|
# ifndef BUFFER_SIZE
|
||||||
|
# define BUFFER_SIZE 1000
|
||||||
|
# endif
|
||||||
|
|
||||||
|
typedef struct s_gnlist
|
||||||
|
{
|
||||||
|
int lfd;
|
||||||
|
char *str;
|
||||||
|
struct s_gnlist *next;
|
||||||
|
} t_gnlist;
|
||||||
|
|
||||||
|
int ft_gnl(const int fd, char **line);
|
||||||
|
int multi_fd(int fd, t_gnlist **lst);
|
||||||
|
int free_lst(t_gnlist **lst, int ret);
|
||||||
|
|
||||||
|
#endif
|
||||||
62
libs/libft/includes/ft_printf.h
Normal file
62
libs/libft/includes/ft_printf.h
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_printf.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2020/02/27 12:07:47 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2020/03/12 20:35:10 by hulamy ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef FT_PRINTF_H
|
||||||
|
# define FT_PRINTF_H
|
||||||
|
# include <stdarg.h> // to use va_arg
|
||||||
|
|
||||||
|
/*
|
||||||
|
** ft_printf.c
|
||||||
|
*/
|
||||||
|
|
||||||
|
char *specifier(char *s);
|
||||||
|
int ft_expand_star(int nbr, char **string);
|
||||||
|
int ft_put_word(char *s, char *type, int size);
|
||||||
|
char *convert_with_flags(char *s, va_list ap, char *type, int *size);
|
||||||
|
int ft_printf(char *string, ...);
|
||||||
|
|
||||||
|
/*
|
||||||
|
** ft_next_word.c
|
||||||
|
*/
|
||||||
|
|
||||||
|
int width_precision(char *s);
|
||||||
|
int word_length(char *s);
|
||||||
|
char *next_word(char **s);
|
||||||
|
|
||||||
|
/*
|
||||||
|
** ft_convert.c
|
||||||
|
*/
|
||||||
|
|
||||||
|
char *conv_i(char c, long int i);
|
||||||
|
char *conv_u(char c, unsigned long int i);
|
||||||
|
char *ft_convert(va_list ap, char *type, char **s);
|
||||||
|
|
||||||
|
/*
|
||||||
|
** ft_flag_transform.c
|
||||||
|
*/
|
||||||
|
|
||||||
|
char *precision_int(char *print, int precision);
|
||||||
|
char *ft_precision(char *s, char *print, char *type);
|
||||||
|
char *width_flags(char *print, char *s, int width, int zero);
|
||||||
|
char *ft_width(char *s, char *print, int *size, char *type);
|
||||||
|
char *ft_flag_transform(char *s, char *print, char *type, int *size);
|
||||||
|
|
||||||
|
/*
|
||||||
|
** ft_flag_transform_bonus.c
|
||||||
|
*/
|
||||||
|
|
||||||
|
char *ft_plus(char *s, char *print, char *type);
|
||||||
|
char *ft_sharp(char *s, char *print, char *type);
|
||||||
|
char *ft_sharp_again(char *s, char *print, char *type);
|
||||||
|
char *ft_space(char *s, char *print, char *type, int *size);
|
||||||
|
|
||||||
|
#endif
|
||||||
140
libs/libft/includes/libft.h
Normal file
140
libs/libft/includes/libft.h
Normal file
@@ -0,0 +1,140 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* libft.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2019/11/25 14:45:53 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2022/04/21 19:31:18 by simplonco ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef LIBFT_H
|
||||||
|
# define LIBFT_H
|
||||||
|
# include <unistd.h> // for write
|
||||||
|
# include <stdlib.h> // for malloc and free
|
||||||
|
# include "ft_gnl.h"
|
||||||
|
# include "ft_printf.h"
|
||||||
|
|
||||||
|
void *ft_memset(void *b, int c, size_t len);
|
||||||
|
void ft_bzero(void *s, size_t n);
|
||||||
|
void *ft_memcpy(void *dst, const void *src, size_t n);
|
||||||
|
void *ft_memccpy(void *dst, const void *src, int c, size_t n);
|
||||||
|
void *ft_memmove(void *dst, const void *src, size_t len);
|
||||||
|
void *ft_memchr(const void *s, int c, size_t n);
|
||||||
|
int ft_memcmp(const void *s1, const void *s2, size_t n);
|
||||||
|
size_t ft_strlen(const char *str);
|
||||||
|
int ft_isalpha(int c);
|
||||||
|
int ft_isdigit(int c);
|
||||||
|
int ft_isnumber(char *nb);
|
||||||
|
int ft_isalnum(int c);
|
||||||
|
int ft_isascii(int c);
|
||||||
|
int ft_isprint(int c);
|
||||||
|
int ft_toupper(int c);
|
||||||
|
int ft_tolower(int c);
|
||||||
|
char *ft_strchr(const char *s, int c);
|
||||||
|
char *ft_strrchr(const char *s, int c);
|
||||||
|
char *ft_strchrset(const char *s, const char *set);
|
||||||
|
int ft_strncmp(const char *s1, const char *s2, size_t n);
|
||||||
|
size_t ft_strlcpy(char *dst, const char *src, size_t size);
|
||||||
|
size_t ft_strlcat(char *dst, const char *src, size_t size);
|
||||||
|
char *ft_strnstr(const char *b, const char *l, size_t s);
|
||||||
|
int ft_atoi(const char *str);
|
||||||
|
long ft_atol(const char *str);
|
||||||
|
void *ft_calloc(size_t count, size_t size);
|
||||||
|
char *ft_strdup(const char *s1);
|
||||||
|
|
||||||
|
char *ft_substr(char const *s, unsigned int start, size_t len);
|
||||||
|
char *ft_strjoin(char const *s1, char const *s2);
|
||||||
|
char *ft_strtrim(char const *s1, char const *set);
|
||||||
|
char **ft_split(char const *s, char c);
|
||||||
|
char *ft_itoa(long int n);
|
||||||
|
char *ft_utoa(unsigned long int n);
|
||||||
|
char *ft_strmapi(char const *s, char (*f)(unsigned int, char));
|
||||||
|
|
||||||
|
void ft_putchar_fd(char c, int fd);
|
||||||
|
void ft_putstr_fd(char *s, int fd);
|
||||||
|
void ft_putnbr_fd(int n, int fd);
|
||||||
|
void ft_putnbrbase(int nbr, char *base);
|
||||||
|
|
||||||
|
/*
|
||||||
|
void ft_putchar(char c);
|
||||||
|
void ft_putendl(char const *str);
|
||||||
|
void ft_putnbr(int nbr);
|
||||||
|
void ft_putstr(char const *str);
|
||||||
|
void ft_putendl_fd(char *s, int fd);
|
||||||
|
*/
|
||||||
|
|
||||||
|
typedef struct s_list
|
||||||
|
{
|
||||||
|
void *content;
|
||||||
|
struct s_list *prev;
|
||||||
|
struct s_list *next;
|
||||||
|
} t_list;
|
||||||
|
|
||||||
|
/*
|
||||||
|
t_list *ft_lstnew(void *content);
|
||||||
|
void ft_lstadd_front(t_list **alst, t_list *n);
|
||||||
|
void *ft_lstadd_back(t_list **alst, t_list *n);
|
||||||
|
int ft_lstsize(t_list *lst);
|
||||||
|
t_list *ft_lstlast(t_list *lst);
|
||||||
|
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 *));
|
||||||
|
t_list *ft_lstmap(t_list *l, void *(*f)(void*), void (*d)(void*));
|
||||||
|
*/
|
||||||
|
//void ft_lstremove(t_list *lst, void (*del)(void *));
|
||||||
|
//t_list *ft_lstfind(t_list *lst, void *to_find, int (*comp)(void*, void *));
|
||||||
|
t_list *ft_lstcreate(void *content);
|
||||||
|
void *ft_lstpush_back(t_list **lst, t_list *new);
|
||||||
|
void ft_lstpush_front(t_list **alst, t_list *new);
|
||||||
|
void ft_lstloop(t_list *lst, void (*f)(void *));
|
||||||
|
void ft_lstloop_back(t_list *lst, void (*f)(void *));
|
||||||
|
t_list *ft_lstbegin(t_list *lst);
|
||||||
|
t_list *ft_lstend(t_list *lst);
|
||||||
|
t_list *ft_lstfind(t_list *lst, void *to_find, int (*comp)(void*, void *));
|
||||||
|
void ft_lstinsert(t_list *lst, t_list *new);
|
||||||
|
void ft_lsterase(t_list *lst, void (*del)(void *));
|
||||||
|
void ft_lstfree(t_list *lst, void (*del)(void *));
|
||||||
|
int ft_lstlen(t_list *lst);
|
||||||
|
t_list *ft_lstcopy(t_list *lst, void *(*cpy)(void *));
|
||||||
|
|
||||||
|
char *ft_strcat(char *s1, const char *s2);
|
||||||
|
int ft_strcmp(const char *s1, const char *s2);
|
||||||
|
char *ft_strcpy(char *dst, const char *src);
|
||||||
|
char *ft_strncat(char *s1, const char *s2, size_t n);
|
||||||
|
char *ft_strncpy(char *dst, const char *src, size_t len);
|
||||||
|
char *ft_strstr(const char *big, const char *little);
|
||||||
|
void ft_strclr(char *s);
|
||||||
|
void ft_strdel(char **as);
|
||||||
|
int ft_strequ(char const *s1, char const *s2);
|
||||||
|
void ft_striter(char *s, void (*f)(char *));
|
||||||
|
void ft_striteri(char *s, void (*f)(unsigned int, char *));
|
||||||
|
char *ft_strjoinfree(char *s1, char *s2);
|
||||||
|
char *ft_strmap(char const *s, char (*f)(char));
|
||||||
|
int ft_strnequ(char const *s1, char const *s2, size_t n);
|
||||||
|
char *ft_strnew(size_t size);
|
||||||
|
void *ft_memalloc(size_t size);
|
||||||
|
void ft_memdel(void **ap);
|
||||||
|
int ft_atoibase(char *str, char *base);
|
||||||
|
char *ft_convertbase(char *nbr, char *base_from, char *base_to);
|
||||||
|
char *ft_convertbase_free(char *nbr, char *b_from, char *b_to);
|
||||||
|
char **ft_strmultisplit(char *str, char *charset);
|
||||||
|
int ft_any(char **tab, int (*f)(char*));
|
||||||
|
void ft_foreach(int *tab, int length, void (*f)(int));
|
||||||
|
int ft_issort(int *tab, int length, int (*f)(int, int));
|
||||||
|
int *ft_arraymap(int *tab, int length, int(*f)(int));
|
||||||
|
void ft_putnbrendl(int n);
|
||||||
|
void ft_putnbrendl_fd(int n, int fd);
|
||||||
|
char *ft_concat_free(char *str1, char *str2);
|
||||||
|
int ft_abs(int n);
|
||||||
|
int ft_greater(int a, int b);
|
||||||
|
int ft_smaller(int a, int b);
|
||||||
|
int ft_sign(int i);
|
||||||
|
int ft_sqrt(int i);
|
||||||
|
void ft_free_tab(char **tab);
|
||||||
|
|
||||||
|
int ft_arrint(int * intarr, int comp, size_t size);
|
||||||
|
|
||||||
|
#endif
|
||||||
20
libs/libft/srcs/ft_abs.c
Normal file
20
libs/libft/srcs/ft_abs.c
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_abs.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: pblagoje <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2022/05/04 14:13:33 by pblagoje #+# #+# */
|
||||||
|
/* Updated: 2022/05/04 14:13:41 by pblagoje ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
int ft_abs(int n)
|
||||||
|
{
|
||||||
|
if (n < 0)
|
||||||
|
n *= -1;
|
||||||
|
return (n);
|
||||||
|
}
|
||||||
32
libs/libft/srcs/ft_any.c
Normal file
32
libs/libft/srcs/ft_any.c
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_any.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2018/11/16 15:14:49 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2018/11/16 15:14:53 by hulamy ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
/*
|
||||||
|
** i don't understand the purpose of this function...
|
||||||
|
** it takes a 2D array, and for each array it checks
|
||||||
|
** if a function given in parameters is true or false
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
int ft_any(char **tab, int (*f)(char*))
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = -1;
|
||||||
|
if (!tab)
|
||||||
|
return (0);
|
||||||
|
while (tab[++i])
|
||||||
|
if (f(tab[i]) == 1)
|
||||||
|
return (1);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
28
libs/libft/srcs/ft_arraymap.c
Normal file
28
libs/libft/srcs/ft_arraymap.c
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_arraymap.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2018/11/16 15:17:24 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2018/11/16 15:17:27 by hulamy ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
int *ft_arraymap(int *tab, int length, int (*f)(int))
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
int *newtab;
|
||||||
|
|
||||||
|
i = -1;
|
||||||
|
if (!tab)
|
||||||
|
return (NULL);
|
||||||
|
if (!(newtab = (int*)malloc(sizeof(*newtab) * (length + 1))))
|
||||||
|
return (NULL);
|
||||||
|
while (++i < length)
|
||||||
|
newtab[i] = (*f)(tab[i]);
|
||||||
|
return (newtab);
|
||||||
|
}
|
||||||
31
libs/libft/srcs/ft_arrint.c
Normal file
31
libs/libft/srcs/ft_arrint.c
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_arrint.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: simplonco <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2022/04/21 19:30:25 by simplonco #+# #+# */
|
||||||
|
/* Updated: 2022/05/04 14:04:53 by pblagoje ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* search through an arr of int if it contains the int comp
|
||||||
|
* return 0 if found, 1 otherwise
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
int ft_arrint(int *intarr, int comp, size_t size)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
if (!intarr)
|
||||||
|
return (1);
|
||||||
|
i = -1;
|
||||||
|
while (++i < size)
|
||||||
|
if (intarr[i] == comp)
|
||||||
|
return (0);
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
33
libs/libft/srcs/ft_atoi.c
Normal file
33
libs/libft/srcs/ft_atoi.c
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_atoi.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2019/11/25 13:54:29 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2022/05/04 14:09:01 by pblagoje ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
int ft_atoi(const char *str)
|
||||||
|
{
|
||||||
|
long nbr;
|
||||||
|
int i;
|
||||||
|
int negatif;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
negatif = 1;
|
||||||
|
nbr = 0;
|
||||||
|
while ((str[i] == ' ') || (str[i] > 8 && str[i] < 14))
|
||||||
|
i++;
|
||||||
|
if (str[i] == '-')
|
||||||
|
negatif = -1;
|
||||||
|
if (str[i] == '+' || str[i] == '-')
|
||||||
|
i++;
|
||||||
|
while (str[i] >= '0' && str[i] <= '9')
|
||||||
|
nbr = nbr * 10 + (str[i++] - '0');
|
||||||
|
return (nbr * negatif);
|
||||||
|
}
|
||||||
75
libs/libft/srcs/ft_atoibase.c
Normal file
75
libs/libft/srcs/ft_atoibase.c
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_atoibase.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2018/11/16 15:15:31 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2018/11/16 15:22:34 by hulamy ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
static int is_valid_base(char *base, int i, int j)
|
||||||
|
{
|
||||||
|
while (base[i])
|
||||||
|
{
|
||||||
|
j = i + 1;
|
||||||
|
while (base[j])
|
||||||
|
{
|
||||||
|
if (base[i] == base[j])
|
||||||
|
return (0);
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
if (base[i] == '-' || base[i] == '+')
|
||||||
|
return (0);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
if (i >= 2)
|
||||||
|
return (1);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int skip(int i, char *str, int *n)
|
||||||
|
{
|
||||||
|
while ((str[i] == 32) || (str[i] > 8 && str[i] < 14))
|
||||||
|
i++;
|
||||||
|
if (str[i] == '+' || str[i] == '-')
|
||||||
|
{
|
||||||
|
if (str[i] == '-')
|
||||||
|
*n = -1;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (i);
|
||||||
|
}
|
||||||
|
|
||||||
|
int ft_atoibase(char *str, char *base)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
int j;
|
||||||
|
int length;
|
||||||
|
int res;
|
||||||
|
int n;
|
||||||
|
|
||||||
|
length = 0;
|
||||||
|
res = 0;
|
||||||
|
n = 1;
|
||||||
|
if (!is_valid_base(base, 0, 0))
|
||||||
|
return (0);
|
||||||
|
while (base[length])
|
||||||
|
length++;
|
||||||
|
i = skip(0, str, &n);
|
||||||
|
while (str[i] && str[i] > 32 && str[i] != '-' && str[i] != '+')
|
||||||
|
{
|
||||||
|
j = 0;
|
||||||
|
while (str[i] != base[j] && base[j])
|
||||||
|
j++;
|
||||||
|
if (base[j] == '\0')
|
||||||
|
return (0);
|
||||||
|
res = (res * length) + j;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (res * n);
|
||||||
|
}
|
||||||
22
libs/libft/srcs/ft_atol.c
Normal file
22
libs/libft/srcs/ft_atol.c
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
long ft_atol(const char *str)
|
||||||
|
{
|
||||||
|
long long nbr;
|
||||||
|
int i;
|
||||||
|
int negatif;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
negatif = 1;
|
||||||
|
nbr = 0;
|
||||||
|
while ((str[i] == ' ') || (str[i] > 8 && str[i] < 14))
|
||||||
|
i++;
|
||||||
|
if (str[i] == '-')
|
||||||
|
negatif = -1;
|
||||||
|
if (str[i] == '+' || str[i] == '-')
|
||||||
|
i++;
|
||||||
|
while (str[i] >= '0' && str[i] <= '9')
|
||||||
|
nbr = nbr * 10 + (str[i++] - '0');
|
||||||
|
return (nbr * negatif);
|
||||||
|
}
|
||||||
27
libs/libft/srcs/ft_bzero.c
Normal file
27
libs/libft/srcs/ft_bzero.c
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_bzero.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2019/11/25 13:54:43 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2019/11/25 13:54:44 by hulamy ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_bzero(void *s, size_t n)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
unsigned char *ptr;
|
||||||
|
|
||||||
|
if (n)
|
||||||
|
{
|
||||||
|
ptr = (unsigned char *)s;
|
||||||
|
i = 0;
|
||||||
|
while (i < n)
|
||||||
|
ptr[i++] = '\0';
|
||||||
|
}
|
||||||
|
}
|
||||||
64
libs/libft/srcs/ft_calloc.c
Normal file
64
libs/libft/srcs/ft_calloc.c
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_calloc.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2019/11/25 13:54:53 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2019/12/01 16:04:12 by hulamy ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
/*
|
||||||
|
** allocate count * size byte of memory and
|
||||||
|
** return a pointer to the allocated memory
|
||||||
|
**
|
||||||
|
** exemple allocation for 5 integers with malloc then calloc :
|
||||||
|
** a = (int *)malloc(5 * sizeof(int)); //5*4bytes = 20 bytes
|
||||||
|
** free(a);
|
||||||
|
** a = (int *)calloc(5, sizeof(int));
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
** #include <libc.h>
|
||||||
|
**
|
||||||
|
** void ft_bzero(void *s, size_t n)
|
||||||
|
** {
|
||||||
|
** size_t i;
|
||||||
|
** unsigned char *ptr;
|
||||||
|
**
|
||||||
|
** if (n)
|
||||||
|
** {
|
||||||
|
** ptr = (unsigned char *)s;
|
||||||
|
** i = 0;
|
||||||
|
** while (i < n)
|
||||||
|
** ptr[i++] = '\0';
|
||||||
|
** }
|
||||||
|
** }
|
||||||
|
**
|
||||||
|
** void *ft_calloc(size_t count, size_t size);
|
||||||
|
**
|
||||||
|
** int main(void)
|
||||||
|
** {
|
||||||
|
** void *str;
|
||||||
|
**
|
||||||
|
** str = ft_calloc(0, 0);
|
||||||
|
** if (str == ((void *)0))
|
||||||
|
** printf("failed\n");
|
||||||
|
** free(str);
|
||||||
|
** return (0);
|
||||||
|
** }
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void *ft_calloc(size_t count, size_t size)
|
||||||
|
{
|
||||||
|
void *tmp;
|
||||||
|
|
||||||
|
if (!(tmp = malloc(count * size)))
|
||||||
|
return (NULL);
|
||||||
|
ft_bzero(tmp, count * size);
|
||||||
|
return (tmp);
|
||||||
|
}
|
||||||
53
libs/libft/srcs/ft_concat_free.c
Normal file
53
libs/libft/srcs/ft_concat_free.c
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_concat_free.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2020/02/27 18:04:09 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2020/02/27 18:06:44 by hulamy ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
/*
|
||||||
|
** create a new string size of str1 + str2
|
||||||
|
** fill it with concated str1 and str2m as "str1str2"
|
||||||
|
** free the received strings str1 and str2
|
||||||
|
** return the new string
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
** #include <stdio.h>
|
||||||
|
** #include "libft.h"
|
||||||
|
**
|
||||||
|
** char *ft_concat_free(char *str1, char *str2);
|
||||||
|
**
|
||||||
|
** int main(int ac, char **av)
|
||||||
|
** {
|
||||||
|
** if (ac != 3)
|
||||||
|
** return (0);
|
||||||
|
** printf("%s\n", ft_concat_free(ft_strdup(av[1]), ft_strdup(av[2])));
|
||||||
|
** return (0);
|
||||||
|
** }
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
char *ft_concat_free(char *str1, char *str2)
|
||||||
|
{
|
||||||
|
char *cat;
|
||||||
|
int i;
|
||||||
|
int j;
|
||||||
|
|
||||||
|
cat = ft_memalloc(sizeof(char) * (ft_strlen(str1) + ft_strlen(str2) + 1));
|
||||||
|
i = -1;
|
||||||
|
j = 0;
|
||||||
|
while (str1[++i])
|
||||||
|
cat[i] = str1[i];
|
||||||
|
while (str2[j])
|
||||||
|
cat[i++] = str2[j++];
|
||||||
|
free(str1);
|
||||||
|
free(str2);
|
||||||
|
return (cat);
|
||||||
|
}
|
||||||
196
libs/libft/srcs/ft_convertbase.c
Normal file
196
libs/libft/srcs/ft_convertbase.c
Normal file
@@ -0,0 +1,196 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_convertbase.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2020/02/26 20:19:54 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2020/02/26 20:20:14 by hulamy ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
/*
|
||||||
|
** take a string that is a number in a certain base
|
||||||
|
** and convert it in another base
|
||||||
|
** it works with unsigned long int
|
||||||
|
** return the new string
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
** #include <stdio.h> // for printf
|
||||||
|
** #include <stdlib.h> // for atoi
|
||||||
|
**
|
||||||
|
** char *ft_convertbase(char *nbr, char *base_from, char *base_to);
|
||||||
|
**
|
||||||
|
** int main(int ac, char **av)
|
||||||
|
** {
|
||||||
|
** if (ac != 4)
|
||||||
|
** {
|
||||||
|
** printf("usage:\nchar *nbr, char *base_from, char *base_to\n");
|
||||||
|
** printf("try the max long unsigned int : 18446744073709551615\n");
|
||||||
|
** }
|
||||||
|
** else
|
||||||
|
** printf("[%s]\n",ft_convertbase(av[1], av[2], av[3]));
|
||||||
|
** return (0);
|
||||||
|
** }
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
** check :
|
||||||
|
** -if the base has no characters that appear more than one time
|
||||||
|
** -if the signes '-' and '+' are not part of the set
|
||||||
|
** -if there are no invisible characters (inferior to 32 or equal to 127)
|
||||||
|
*/
|
||||||
|
|
||||||
|
int
|
||||||
|
is_valid_base(char *base)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
int j;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while (base[i])
|
||||||
|
{
|
||||||
|
j = i + 1;
|
||||||
|
while (base[j])
|
||||||
|
if (base[i] == base[j++])
|
||||||
|
return (0);
|
||||||
|
if (base[i] == '-' || base[i] == '+' || base[i] < 33 || base[i] == 127)
|
||||||
|
return (0);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
if (i >= 2)
|
||||||
|
return (1);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** check :
|
||||||
|
** -if base is valid
|
||||||
|
** -if nbr contain characters
|
||||||
|
** -if nbr is made of elements of base only
|
||||||
|
*/
|
||||||
|
|
||||||
|
int
|
||||||
|
is_valid_nbr(char *nbr, char *base)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
int j;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
if (!is_valid_base(base))
|
||||||
|
return (0);
|
||||||
|
while (nbr[i])
|
||||||
|
{
|
||||||
|
j = 0;
|
||||||
|
while (base[j] && nbr[i] != base[j])
|
||||||
|
j++;
|
||||||
|
if (base[j] == '\0')
|
||||||
|
return (0);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
if (i == 0)
|
||||||
|
return (0);
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** -transform a nbr written as a string into a decimal nbr
|
||||||
|
** -it's an unsigned nbr because the negativity is managed elsewhere
|
||||||
|
** -if the number is bigger than the max unsigned long int it's false
|
||||||
|
** as it's impossible to verify if a number is bigger than the biggest
|
||||||
|
** unsigned, we verify the difference before the multiplication
|
||||||
|
*/
|
||||||
|
|
||||||
|
unsigned long int
|
||||||
|
base_to_decimal(char *nbr, char *base, int *error)
|
||||||
|
{
|
||||||
|
unsigned long int decimal;
|
||||||
|
int i;
|
||||||
|
int j;
|
||||||
|
int length;
|
||||||
|
|
||||||
|
decimal = 0;
|
||||||
|
i = 0;
|
||||||
|
length = 0;
|
||||||
|
while (base[length])
|
||||||
|
length++;
|
||||||
|
while (nbr[i])
|
||||||
|
{
|
||||||
|
j = 0;
|
||||||
|
while (nbr[i] != base[j] && base[j])
|
||||||
|
j++;
|
||||||
|
if ((18446744073709551615U - j) / length < decimal)
|
||||||
|
return (*error = 1);
|
||||||
|
decimal = (decimal * length) + j;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (decimal);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** -it counts the size needed to be allocated
|
||||||
|
** -if the given nbr was a negative one it add the place for the '-'
|
||||||
|
** -then convert the nbr from decimal base to destination base
|
||||||
|
** into the string allocated
|
||||||
|
*/
|
||||||
|
|
||||||
|
char
|
||||||
|
*decimal_to_base(unsigned long int decimal, char *base, int malloc_size)
|
||||||
|
{
|
||||||
|
int base_size;
|
||||||
|
int neg;
|
||||||
|
char *result;
|
||||||
|
unsigned long int nb;
|
||||||
|
|
||||||
|
neg = malloc_size;
|
||||||
|
base_size = 0;
|
||||||
|
while (base[base_size])
|
||||||
|
base_size++;
|
||||||
|
nb = decimal;
|
||||||
|
while (nb /= base_size)
|
||||||
|
malloc_size++;
|
||||||
|
result = (char *)malloc(sizeof(char) * (malloc_size + 2));
|
||||||
|
result[malloc_size + 1] = '\0';
|
||||||
|
if (neg)
|
||||||
|
result[0] = '-';
|
||||||
|
while (malloc_size >= 0)
|
||||||
|
{
|
||||||
|
result[malloc_size--] = base[decimal % base_size];
|
||||||
|
decimal /= base_size;
|
||||||
|
}
|
||||||
|
return (result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** -main function to convert from one base to another
|
||||||
|
** -function base_to_decimal has an awfull int *error because it cannot
|
||||||
|
** return -1 in case of error, since it's an unsigned, and it cannot
|
||||||
|
** return 0 to check the error since it would be confusing with an actual
|
||||||
|
** return of 0 if the number to convert is 0
|
||||||
|
*/
|
||||||
|
|
||||||
|
char
|
||||||
|
*ft_convertbase(char *nbr, char *base_from, char *base_to)
|
||||||
|
{
|
||||||
|
int length;
|
||||||
|
unsigned long int decimal;
|
||||||
|
int error;
|
||||||
|
|
||||||
|
error = 0;
|
||||||
|
length = 0;
|
||||||
|
if (nbr[0] == '-')
|
||||||
|
{
|
||||||
|
nbr++;
|
||||||
|
length = 1;
|
||||||
|
}
|
||||||
|
if (!is_valid_nbr(nbr, base_from) || !is_valid_base(base_to))
|
||||||
|
return (NULL);
|
||||||
|
decimal = base_to_decimal(nbr, base_from, &error);
|
||||||
|
if (error == 1)
|
||||||
|
return (NULL);
|
||||||
|
return (decimal_to_base(decimal, base_to, length));
|
||||||
|
}
|
||||||
198
libs/libft/srcs/ft_convertbase_free.c
Normal file
198
libs/libft/srcs/ft_convertbase_free.c
Normal file
@@ -0,0 +1,198 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_convertbase_free.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2020/02/26 20:19:54 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2020/02/27 20:23:22 by hulamy ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
/*
|
||||||
|
** (just like ft_convert, but free the string it receive)
|
||||||
|
** take a string that is a number in a certain base
|
||||||
|
** and convert it in another base
|
||||||
|
** it works with unsigned long int
|
||||||
|
** return the new string
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
** #include <stdio.h> // for printf
|
||||||
|
** #include <stdlib.h> // for atoi
|
||||||
|
**
|
||||||
|
** char *ft_convertbase_free(char *nbr, char *base_from, char *base_to);
|
||||||
|
**
|
||||||
|
** int main(int ac, char **av)
|
||||||
|
** {
|
||||||
|
** if (ac != 4)
|
||||||
|
** {
|
||||||
|
** printf("usage:\nchar *nbr, char *base_from, char *base_to\n");
|
||||||
|
** printf("try the max long unsigned int : 18446744073709551615\n");
|
||||||
|
** }
|
||||||
|
** else
|
||||||
|
** printf("[%s]\n",ft_convertbase_free(av[1], av[2], av[3]));
|
||||||
|
** return (0);
|
||||||
|
** }
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
** check :
|
||||||
|
** -if the base has no characters that appear more than one time
|
||||||
|
** -if the signes '-' and '+' are not part of the set
|
||||||
|
** -if there are no invisible characters (inferior to 32 or equal to 127)
|
||||||
|
*/
|
||||||
|
|
||||||
|
int
|
||||||
|
is_base_valid(char *base)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
int j;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while (base[i])
|
||||||
|
{
|
||||||
|
j = i + 1;
|
||||||
|
while (base[j])
|
||||||
|
if (base[i] == base[j++])
|
||||||
|
return (0);
|
||||||
|
if (base[i] == '-' || base[i] == '+' || base[i] < 33 || base[i] == 127)
|
||||||
|
return (0);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
if (i >= 2)
|
||||||
|
return (1);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** check :
|
||||||
|
** -if base is valid
|
||||||
|
** -if nbr contain characters
|
||||||
|
** -if nbr is made of elements of base only
|
||||||
|
*/
|
||||||
|
|
||||||
|
int
|
||||||
|
is_nbr_valid(char *nbr, char *base)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
int j;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
if (!is_base_valid(base))
|
||||||
|
return (0);
|
||||||
|
while (nbr[i])
|
||||||
|
{
|
||||||
|
j = 0;
|
||||||
|
while (base[j] && nbr[i] != base[j])
|
||||||
|
j++;
|
||||||
|
if (base[j] == '\0')
|
||||||
|
return (0);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
if (i == 0)
|
||||||
|
return (0);
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** -transform a nbr written as a string into a decimal nbr
|
||||||
|
** -it's an unsigned nbr because the negativity is managed elsewhere
|
||||||
|
** -if the number is bigger than the max unsigned long int it's false
|
||||||
|
** as it's impossible to verify if a number is bigger than the biggest
|
||||||
|
** unsigned, we verify the difference before the multiplication
|
||||||
|
*/
|
||||||
|
|
||||||
|
unsigned long int
|
||||||
|
base_2_decimal(char *nbr, char *base, int *error)
|
||||||
|
{
|
||||||
|
unsigned long int decimal;
|
||||||
|
int i;
|
||||||
|
int j;
|
||||||
|
int length;
|
||||||
|
|
||||||
|
decimal = 0;
|
||||||
|
i = 0;
|
||||||
|
length = 0;
|
||||||
|
while (base[length])
|
||||||
|
length++;
|
||||||
|
while (nbr[i])
|
||||||
|
{
|
||||||
|
j = 0;
|
||||||
|
while (nbr[i] != base[j] && base[j])
|
||||||
|
j++;
|
||||||
|
if ((18446744073709551615U - j) / length < decimal)
|
||||||
|
return (*error = 1);
|
||||||
|
decimal = (decimal * length) + j;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (decimal);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** -it counts the size needed to be allocated
|
||||||
|
** -if the given nbr was a negative one it add the place for the '-'
|
||||||
|
** -then convert the nbr from decimal base to destination base
|
||||||
|
** into the string allocated
|
||||||
|
*/
|
||||||
|
|
||||||
|
char
|
||||||
|
*decimal_2_base(unsigned long int decimal, char *base, int malloc_size)
|
||||||
|
{
|
||||||
|
int base_size;
|
||||||
|
int neg;
|
||||||
|
char *result;
|
||||||
|
unsigned long int nb;
|
||||||
|
|
||||||
|
neg = malloc_size;
|
||||||
|
base_size = 0;
|
||||||
|
while (base[base_size])
|
||||||
|
base_size++;
|
||||||
|
nb = decimal;
|
||||||
|
while (nb /= base_size)
|
||||||
|
malloc_size++;
|
||||||
|
result = (char *)malloc(sizeof(char) * (malloc_size + 2));
|
||||||
|
result[malloc_size + 1] = '\0';
|
||||||
|
if (neg)
|
||||||
|
result[0] = '-';
|
||||||
|
while (malloc_size >= 0)
|
||||||
|
{
|
||||||
|
result[malloc_size--] = base[decimal % base_size];
|
||||||
|
decimal /= base_size;
|
||||||
|
}
|
||||||
|
return (result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** -main function to convert from one base to another
|
||||||
|
** -function base_to_decimal has an awfull int *error because it cannot
|
||||||
|
** return -1 in case of error, since it's an unsigned, and it cannot
|
||||||
|
** return 0 to check the error since it would be confusing with an actual
|
||||||
|
** return of 0 if the number to convert is 0
|
||||||
|
*/
|
||||||
|
|
||||||
|
char
|
||||||
|
*ft_convertbase_free(char *nbr, char *base_from, char *base_to)
|
||||||
|
{
|
||||||
|
int length;
|
||||||
|
unsigned long int decimal;
|
||||||
|
int error;
|
||||||
|
|
||||||
|
error = 0;
|
||||||
|
length = 0;
|
||||||
|
if (nbr[0] == '-')
|
||||||
|
{
|
||||||
|
nbr++;
|
||||||
|
length = 1;
|
||||||
|
}
|
||||||
|
if (!is_nbr_valid(nbr, base_from) || !is_base_valid(base_to))
|
||||||
|
return (NULL);
|
||||||
|
decimal = base_2_decimal(nbr, base_from, &error);
|
||||||
|
if (error == 1)
|
||||||
|
return (NULL);
|
||||||
|
free(nbr);
|
||||||
|
return (decimal_2_base(decimal, base_to, length));
|
||||||
|
}
|
||||||
22
libs/libft/srcs/ft_foreach.c
Normal file
22
libs/libft/srcs/ft_foreach.c
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_foreach.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2018/11/16 15:16:10 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2018/11/16 15:16:11 by hulamy ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_foreach(int *tab, int length, void (*f)(int))
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while (i < length && tab && tab[i])
|
||||||
|
(*f)(tab[i++]);
|
||||||
|
}
|
||||||
15
libs/libft/srcs/ft_free_tab.c
Normal file
15
libs/libft/srcs/ft_free_tab.c
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_free_tab(char **tab)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while (tab[i] != NULL)
|
||||||
|
{
|
||||||
|
free(tab[i]);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
free(tab);
|
||||||
|
}
|
||||||
138
libs/libft/srcs/ft_gnl.c
Normal file
138
libs/libft/srcs/ft_gnl.c
Normal file
@@ -0,0 +1,138 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_gnl.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2019/12/31 17:05:53 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2022/05/04 12:15:32 by pblagoje ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
** #include <fcntl.h> //for open
|
||||||
|
**
|
||||||
|
** int main(int ac, char **av)
|
||||||
|
** {
|
||||||
|
** int *fd;
|
||||||
|
** int i = 0;
|
||||||
|
** int j = 0;
|
||||||
|
** int ret;
|
||||||
|
** char *line = NULL;
|
||||||
|
**
|
||||||
|
** fd = (int *)ft_calloc(ac, sizeof(int));
|
||||||
|
** while (++i <= ac - 1)
|
||||||
|
** fd[i - 1] = open(av[i], O_RDONLY);
|
||||||
|
** i = 0;
|
||||||
|
** while (j < ac - 1)
|
||||||
|
** {
|
||||||
|
** if ((ret = ft_gnl(fd[i], &line)) > 0)
|
||||||
|
** {
|
||||||
|
** ft_printf(" [fd%i-%i] %s\n", fd[i], ret, line);
|
||||||
|
** free(line);
|
||||||
|
** j = 0;
|
||||||
|
** }
|
||||||
|
** else if (ret == -1)
|
||||||
|
** {
|
||||||
|
** ft_printf("[fd%i-%i] *ERROR*\n", fd[i], ret);
|
||||||
|
** free(line);
|
||||||
|
** j++;
|
||||||
|
** }
|
||||||
|
** else if (*line != '\0')
|
||||||
|
** ft_printf(" [fd%i-%i] %s\n", fd[i], ret, line);
|
||||||
|
** else
|
||||||
|
** {
|
||||||
|
** ft_printf("[fd%i-%i] %s *FINI*\n", fd[i], ret, line);
|
||||||
|
** free(line);
|
||||||
|
** j++;
|
||||||
|
** }
|
||||||
|
** i++;
|
||||||
|
** if (i >= ac - 1)
|
||||||
|
** i = 0;
|
||||||
|
** }
|
||||||
|
** free(fd);
|
||||||
|
** //while (1);
|
||||||
|
** return (0);
|
||||||
|
** }
|
||||||
|
*/
|
||||||
|
|
||||||
|
int free_lst(t_gnlist **lst, int ret)
|
||||||
|
{
|
||||||
|
t_gnlist *tmp;
|
||||||
|
|
||||||
|
tmp = *lst;
|
||||||
|
while (tmp->next != *lst)
|
||||||
|
tmp = tmp->next;
|
||||||
|
tmp->next = (*lst)->next;
|
||||||
|
free((*lst)->str);
|
||||||
|
if (*lst == (*lst)->next)
|
||||||
|
{
|
||||||
|
free(*lst);
|
||||||
|
*lst = NULL;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
free(*lst);
|
||||||
|
*lst = tmp;
|
||||||
|
}
|
||||||
|
return (ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
int multi_fd(int fd, t_gnlist **lst)
|
||||||
|
{
|
||||||
|
t_gnlist *tmp;
|
||||||
|
|
||||||
|
tmp = *lst;
|
||||||
|
while (*lst && (*lst)->lfd != fd && (*lst)->next != tmp)
|
||||||
|
*lst = (*lst)->next;
|
||||||
|
if (!tmp || ((*lst)->next == tmp && (*lst)->lfd != fd))
|
||||||
|
{
|
||||||
|
tmp = (t_gnlist *)malloc(sizeof(*tmp));
|
||||||
|
if (!tmp)
|
||||||
|
return (0);
|
||||||
|
tmp->lfd = fd;
|
||||||
|
tmp->str = ft_strdup("");
|
||||||
|
if (!tmp->str)
|
||||||
|
return (0);
|
||||||
|
if (*lst)
|
||||||
|
{
|
||||||
|
tmp->next = (*lst)->next;
|
||||||
|
(*lst)->next = tmp;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
tmp->next = tmp;
|
||||||
|
*lst = tmp;
|
||||||
|
}
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int ft_gnl(const int fd, char **line)
|
||||||
|
{
|
||||||
|
char buf[BUFFER_SIZE + 1];
|
||||||
|
int ret;
|
||||||
|
static t_gnlist *lst = NULL;
|
||||||
|
char *str;
|
||||||
|
|
||||||
|
ret = 1;
|
||||||
|
if (!(multi_fd(fd, &lst)) || !line || BUFFER_SIZE < 1)
|
||||||
|
return (free_lst(&lst, -1));
|
||||||
|
while (!(str = ft_strchr(lst->str, '\n')) && ret != 0)
|
||||||
|
{
|
||||||
|
if ((ret = read(fd, buf, BUFFER_SIZE)) < 0)
|
||||||
|
return (free_lst(&lst, -1));
|
||||||
|
buf[ret] = '\0';
|
||||||
|
lst->str = ft_strjoinfree(lst->str, ft_strdup(buf));
|
||||||
|
if (!lst->str)
|
||||||
|
return (free_lst(&lst, -1));
|
||||||
|
}
|
||||||
|
if (str != NULL)
|
||||||
|
str[0] = '\0';
|
||||||
|
if (!(*line = ft_strdup(lst->str)))
|
||||||
|
return (free_lst(&lst, -1));
|
||||||
|
if (str != NULL)
|
||||||
|
return (ft_memmove(lst->str, str + 1, ft_strlen(str + 1) + 1) != NULL);
|
||||||
|
return (free_lst(&lst, 0));
|
||||||
|
}
|
||||||
8
libs/libft/srcs/ft_greater.c
Normal file
8
libs/libft/srcs/ft_greater.c
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
int ft_greater(int a, int b)
|
||||||
|
{
|
||||||
|
if (a < b)
|
||||||
|
return (b);
|
||||||
|
return (a);
|
||||||
|
}
|
||||||
18
libs/libft/srcs/ft_isalnum.c
Normal file
18
libs/libft/srcs/ft_isalnum.c
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_isalnum.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2019/11/25 13:55:05 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2019/11/25 13:55:06 by hulamy ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
int ft_isalnum(int c)
|
||||||
|
{
|
||||||
|
return (ft_isalpha(c) || ft_isdigit(c));
|
||||||
|
}
|
||||||
18
libs/libft/srcs/ft_isalpha.c
Normal file
18
libs/libft/srcs/ft_isalpha.c
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_isalpha.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2019/11/25 13:55:15 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2019/11/25 13:55:17 by hulamy ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
int ft_isalpha(int c)
|
||||||
|
{
|
||||||
|
return ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z'));
|
||||||
|
}
|
||||||
18
libs/libft/srcs/ft_isascii.c
Normal file
18
libs/libft/srcs/ft_isascii.c
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_isascii.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2019/11/25 13:55:24 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2019/11/25 13:55:25 by hulamy ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
int ft_isascii(int c)
|
||||||
|
{
|
||||||
|
return (c >= 0 && c <= 127);
|
||||||
|
}
|
||||||
18
libs/libft/srcs/ft_isdigit.c
Normal file
18
libs/libft/srcs/ft_isdigit.c
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_isdigit.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2019/11/25 13:55:32 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2019/11/25 13:55:33 by hulamy ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
int ft_isdigit(int c)
|
||||||
|
{
|
||||||
|
return (c >= '0' && c <= '9');
|
||||||
|
}
|
||||||
19
libs/libft/srcs/ft_isnumber.c
Normal file
19
libs/libft/srcs/ft_isnumber.c
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
int ft_isnumber(char *nb)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
if (nb[i] == '+' || nb[i] == '-')
|
||||||
|
i++;
|
||||||
|
while (nb[i] != '\0')
|
||||||
|
{
|
||||||
|
if (ft_isdigit(nb[i]) == 0)
|
||||||
|
return (0);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
18
libs/libft/srcs/ft_isprint.c
Normal file
18
libs/libft/srcs/ft_isprint.c
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_isprint.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2019/11/25 13:55:43 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2019/11/25 13:55:44 by hulamy ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
int ft_isprint(int c)
|
||||||
|
{
|
||||||
|
return (c >= 32 && c < 127);
|
||||||
|
}
|
||||||
26
libs/libft/srcs/ft_issort.c
Normal file
26
libs/libft/srcs/ft_issort.c
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_issort.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2018/11/16 15:18:14 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2018/11/16 15:18:15 by hulamy ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
int ft_issort(int *tab, int length, int (*f)(int, int))
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = -1;
|
||||||
|
if (!tab)
|
||||||
|
return (0);
|
||||||
|
while (++i < length - 1)
|
||||||
|
if (f(tab[i], tab[i + 1]) > 0)
|
||||||
|
return (0);
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
91
libs/libft/srcs/ft_itoa.c
Normal file
91
libs/libft/srcs/ft_itoa.c
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_itoa.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2019/11/25 13:59:01 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2020/02/19 15:44:04 by hulamy ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
/*
|
||||||
|
** take an integer and give a string
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
** #include <stdio.h> // for printf
|
||||||
|
** #include <stdlib.h> // for atoi
|
||||||
|
**
|
||||||
|
** char *ft_itoa(long int n);
|
||||||
|
**
|
||||||
|
** int main(int ac, char **av)
|
||||||
|
** {
|
||||||
|
** if (ac == 0)
|
||||||
|
** return (0);
|
||||||
|
** else if (ac == 2)
|
||||||
|
** printf("%s\n",ft_itoa(atoi(av[1])));
|
||||||
|
** else
|
||||||
|
** {
|
||||||
|
** long int i;
|
||||||
|
** i = 0;
|
||||||
|
** printf(" %li\n %s\n\n",i,ft_itoa(i));
|
||||||
|
** i = 1234567;
|
||||||
|
** printf(" %li\n %s\n\n",i,ft_itoa(i));
|
||||||
|
** i = -1234567;
|
||||||
|
** printf(" %li\n %s\n\n",i,ft_itoa(i));
|
||||||
|
** i = 237683;
|
||||||
|
** printf(" %li\n %s\n\n",i,ft_itoa(i));
|
||||||
|
** i = 2147483647;
|
||||||
|
** printf("| %li\n| %s\n\n",i,ft_itoa(i));
|
||||||
|
** i = i ^ 0; // create the opposite of a signed '0', which
|
||||||
|
** // is 0 followed by 31 '1', the signed int max
|
||||||
|
** printf("* %li\n* %s\n\n",i,ft_itoa(i));
|
||||||
|
** i = i ^ 0;
|
||||||
|
** i = 1 << 31; // change the most lefted bit from '0' (positive)
|
||||||
|
** // to '1' (negative), the signed int min
|
||||||
|
** printf("* %li\n* %s\n\n",i,ft_itoa(i));
|
||||||
|
** i = 2147483646;
|
||||||
|
** printf(" %li\n %s\n\n",i,ft_itoa(i));
|
||||||
|
** i = -2147483648;
|
||||||
|
** printf("| %li\n| %s\n\n",i,ft_itoa(i));
|
||||||
|
** i = -2147483647;
|
||||||
|
** printf(" %li\n %s\n\n",i,ft_itoa(i));
|
||||||
|
** i = 2147483648;
|
||||||
|
** printf(" %li\n %s\n\n",i,ft_itoa(i));
|
||||||
|
** i = -2147483649;
|
||||||
|
** printf(" %li\n %s\n\n",i,ft_itoa(i));
|
||||||
|
** i = 9223372036854775807;
|
||||||
|
** printf("| %li\n| %s\n\n",i,ft_itoa(i));
|
||||||
|
** i = -9223372036854775807;
|
||||||
|
** printf("| %li\n| %s\n\n",i,ft_itoa(i));
|
||||||
|
** }
|
||||||
|
** return 0;
|
||||||
|
** }
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
char *ft_itoa(long int n)
|
||||||
|
{
|
||||||
|
char *str;
|
||||||
|
int len;
|
||||||
|
long int cpy;
|
||||||
|
char rgt;
|
||||||
|
|
||||||
|
cpy = (n < 0) ? (n / 10) * -10 : (n / 10) * 10;
|
||||||
|
len = (n < 0) ? 2 : 1;
|
||||||
|
rgt = (n < 0) ? (n % 10) * -1 + '0' : n % 10 + '0';
|
||||||
|
while (n /= 10)
|
||||||
|
len++;
|
||||||
|
if (!(str = (char *)malloc(sizeof(char) * (len + 1))))
|
||||||
|
return (NULL);
|
||||||
|
str[len] = '\0';
|
||||||
|
str[--len] = rgt;
|
||||||
|
while (cpy /= 10)
|
||||||
|
str[--len] = cpy % 10 + '0';
|
||||||
|
if (len)
|
||||||
|
str[0] = '-';
|
||||||
|
return (str);
|
||||||
|
}
|
||||||
24
libs/libft/srcs/ft_lstbegin.c
Normal file
24
libs/libft/srcs/ft_lstbegin.c
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_lstbegin.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: simplonco <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2022/03/24 15:05:21 by simplonco #+# #+# */
|
||||||
|
/* Updated: 2022/05/04 14:17:27 by pblagoje ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* return a pointer to the first element of a two-way list
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
t_list *ft_lstbegin(t_list *lst)
|
||||||
|
{
|
||||||
|
while (lst->prev)
|
||||||
|
lst = lst->prev;
|
||||||
|
return (lst);
|
||||||
|
}
|
||||||
33
libs/libft/srcs/ft_lstcopy.c
Normal file
33
libs/libft/srcs/ft_lstcopy.c
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_lstcopy.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: simplonco <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2022/03/24 16:26:27 by simplonco #+# #+# */
|
||||||
|
/* Updated: 2022/05/04 14:17:37 by pblagoje ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* copy a two-way list with the copy function for the content
|
||||||
|
* and return pointer to the begining of the new list
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
t_list *ft_lstcopy(t_list *lst, void *(*cpy)(void *))
|
||||||
|
{
|
||||||
|
t_list *lst_copy;
|
||||||
|
|
||||||
|
if (!lst || !cpy)
|
||||||
|
return (NULL);
|
||||||
|
lst_copy = NULL;
|
||||||
|
while (lst)
|
||||||
|
{
|
||||||
|
ft_lstpush_back(&lst_copy, ft_lstcreate(cpy(lst->content)));
|
||||||
|
lst = lst->next;
|
||||||
|
}
|
||||||
|
return (ft_lstbegin(lst_copy));
|
||||||
|
}
|
||||||
30
libs/libft/srcs/ft_lstcreate.c
Normal file
30
libs/libft/srcs/ft_lstcreate.c
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_lstcreate.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: simplonco <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2022/03/24 13:12:50 by simplonco #+# #+# */
|
||||||
|
/* Updated: 2022/05/04 14:17:46 by pblagoje ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* create a new two-way list
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
t_list *ft_lstcreate(void *content)
|
||||||
|
{
|
||||||
|
t_list *lst;
|
||||||
|
|
||||||
|
lst = (t_list *)malloc(sizeof(*lst));
|
||||||
|
if (!lst)
|
||||||
|
return (NULL);
|
||||||
|
lst->content = content;
|
||||||
|
lst->prev = NULL;
|
||||||
|
lst->next = NULL;
|
||||||
|
return (lst);
|
||||||
|
}
|
||||||
24
libs/libft/srcs/ft_lstend.c
Normal file
24
libs/libft/srcs/ft_lstend.c
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_lstend.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: simplonco <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2022/03/24 15:11:41 by simplonco #+# #+# */
|
||||||
|
/* Updated: 2022/03/24 15:12:17 by simplonco ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* return a pointer to the last element of a two-way list
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
t_list *ft_lstend(t_list *lst)
|
||||||
|
{
|
||||||
|
while (lst->next)
|
||||||
|
lst = lst->next;
|
||||||
|
return (lst);
|
||||||
|
}
|
||||||
31
libs/libft/srcs/ft_lsterase.c
Normal file
31
libs/libft/srcs/ft_lsterase.c
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_lsterase.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: simplonco <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2022/03/24 15:31:16 by simplonco #+# #+# */
|
||||||
|
/* Updated: 2022/05/04 14:17:57 by pblagoje ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* erase an element in two-way list
|
||||||
|
* and rejoin the list
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_lsterase(t_list *lst, void (*del)(void *))
|
||||||
|
{
|
||||||
|
if (!lst || !del)
|
||||||
|
return ;
|
||||||
|
del(lst->content);
|
||||||
|
if (lst->prev)
|
||||||
|
lst->prev->next = lst->next;
|
||||||
|
if (lst->next)
|
||||||
|
lst->next->prev = lst->prev;
|
||||||
|
free(lst);
|
||||||
|
lst = NULL;
|
||||||
|
}
|
||||||
25
libs/libft/srcs/ft_lstfind.c
Normal file
25
libs/libft/srcs/ft_lstfind.c
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_lstfind.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: simplonco <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2022/03/23 22:48:47 by simplonco #+# #+# */
|
||||||
|
/* Updated: 2022/03/24 15:23:22 by simplonco ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* find an element in two-way list with the comp function
|
||||||
|
* return a pointer to it
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
t_list *ft_lstfind(t_list *lst, void *to_find, int (*comp)(void*, void *))
|
||||||
|
{
|
||||||
|
while (lst && (!comp(to_find, lst->content)))
|
||||||
|
lst = lst->next;
|
||||||
|
return (lst);
|
||||||
|
}
|
||||||
32
libs/libft/srcs/ft_lstfree.c
Normal file
32
libs/libft/srcs/ft_lstfree.c
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_lstfree.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: simplonco <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2022/03/24 15:49:35 by simplonco #+# #+# */
|
||||||
|
/* Updated: 2022/05/04 14:18:07 by pblagoje ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* delete and free an element of a two-way list and all the followings
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_lstfree(t_list *lst, void (*del)(void *))
|
||||||
|
{
|
||||||
|
t_list *next;
|
||||||
|
|
||||||
|
if (lst && lst->prev)
|
||||||
|
lst->prev->next = NULL;
|
||||||
|
while (lst != NULL)
|
||||||
|
{
|
||||||
|
next = lst->next;
|
||||||
|
del(lst->content);
|
||||||
|
free(lst);
|
||||||
|
lst = next;
|
||||||
|
}
|
||||||
|
}
|
||||||
26
libs/libft/srcs/ft_lstinsert.c
Normal file
26
libs/libft/srcs/ft_lstinsert.c
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_lstinsert.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: simplonco <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2022/03/24 15:22:46 by simplonco #+# #+# */
|
||||||
|
/* Updated: 2022/05/04 14:18:19 by pblagoje ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* insert an element in two-way list just after the one in parameter
|
||||||
|
* and rejoin the list
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_lstinsert(t_list *lst, t_list *new)
|
||||||
|
{
|
||||||
|
new->next = lst->next;
|
||||||
|
lst->next = new;
|
||||||
|
new->next->prev = new;
|
||||||
|
new->prev = lst;
|
||||||
|
}
|
||||||
30
libs/libft/srcs/ft_lstlen.c
Normal file
30
libs/libft/srcs/ft_lstlen.c
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_lstlen.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: simplonco <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2022/03/24 16:20:25 by simplonco #+# #+# */
|
||||||
|
/* Updated: 2022/05/04 14:18:36 by pblagoje ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* return the len of the two-way list
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
int ft_lstlen(t_list *lst)
|
||||||
|
{
|
||||||
|
int size;
|
||||||
|
|
||||||
|
size = 0;
|
||||||
|
while (lst)
|
||||||
|
{
|
||||||
|
size++;
|
||||||
|
lst = lst->next;
|
||||||
|
}
|
||||||
|
return (size);
|
||||||
|
}
|
||||||
29
libs/libft/srcs/ft_lstloop.c
Normal file
29
libs/libft/srcs/ft_lstloop.c
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_lstloop.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: simplonco <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2022/03/24 14:37:15 by simplonco #+# #+# */
|
||||||
|
/* Updated: 2022/05/04 14:18:55 by pblagoje ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* go forward through all elements of a two-way list
|
||||||
|
* and apply the function f to each of them
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_lstloop(t_list *lst, void (*f)(void *))
|
||||||
|
{
|
||||||
|
if (!f)
|
||||||
|
return ;
|
||||||
|
while (lst)
|
||||||
|
{
|
||||||
|
f(lst->content);
|
||||||
|
lst = lst->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
29
libs/libft/srcs/ft_lstloop_back.c
Normal file
29
libs/libft/srcs/ft_lstloop_back.c
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_lstloop_back.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: simplonco <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2022/03/24 15:01:37 by simplonco #+# #+# */
|
||||||
|
/* Updated: 2022/05/04 14:18:50 by pblagoje ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* go backward through all elements of a two-way list
|
||||||
|
* and apply the function f to each of them
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_lstloop_back(t_list *lst, void (*f)(void *))
|
||||||
|
{
|
||||||
|
if (!f)
|
||||||
|
return ;
|
||||||
|
while (lst)
|
||||||
|
{
|
||||||
|
f(lst->content);
|
||||||
|
lst = lst->prev;
|
||||||
|
}
|
||||||
|
}
|
||||||
41
libs/libft/srcs/ft_lstpush_back.c
Normal file
41
libs/libft/srcs/ft_lstpush_back.c
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_lstpush_back.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: simplonco <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2022/03/24 13:37:11 by simplonco #+# #+# */
|
||||||
|
/* Updated: 2022/03/24 14:28:49 by simplonco ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* add an element to the end of a two-way list, or first if list has no element
|
||||||
|
* return NULL if element is NULL (eg it returned from ft_lstcreate and failed)
|
||||||
|
* or else address to the element added
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void *ft_lstpush_back(t_list **lst, t_list *new)
|
||||||
|
{
|
||||||
|
t_list *tmp;
|
||||||
|
|
||||||
|
if (!new)
|
||||||
|
return (NULL);
|
||||||
|
if (lst)
|
||||||
|
{
|
||||||
|
tmp = *lst;
|
||||||
|
if (!tmp)
|
||||||
|
*lst = new;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
while (tmp->next)
|
||||||
|
tmp = tmp->next;
|
||||||
|
tmp->next = new;
|
||||||
|
new->prev = tmp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (new);
|
||||||
|
}
|
||||||
24
libs/libft/srcs/ft_lstpush_front.c
Normal file
24
libs/libft/srcs/ft_lstpush_front.c
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_lstpush_front.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: simplonco <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2022/03/24 14:25:25 by simplonco #+# #+# */
|
||||||
|
/* Updated: 2022/03/24 14:32:14 by simplonco ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* add an element to the begining of a two-way list
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_lstpush_front(t_list **alst, t_list *new)
|
||||||
|
{
|
||||||
|
new->next = *alst;
|
||||||
|
(*alst)->prev = new;
|
||||||
|
*alst = new;
|
||||||
|
}
|
||||||
28
libs/libft/srcs/ft_memalloc.c
Normal file
28
libs/libft/srcs/ft_memalloc.c
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_memalloc.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2019/11/19 15:21:44 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2022/05/04 14:15:38 by pblagoje ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
/*
|
||||||
|
** allocate size byte of memory and return a pointer to the allocated memory
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void *ft_memalloc(size_t size)
|
||||||
|
{
|
||||||
|
void *tmp;
|
||||||
|
|
||||||
|
tmp = malloc(size);
|
||||||
|
if (!size || !tmp)
|
||||||
|
return (NULL);
|
||||||
|
ft_bzero(tmp, size);
|
||||||
|
return (tmp);
|
||||||
|
}
|
||||||
36
libs/libft/srcs/ft_memccpy.c
Normal file
36
libs/libft/srcs/ft_memccpy.c
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_memccpy.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2019/11/25 15:24:51 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2019/11/25 15:25:09 by hulamy ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
/*
|
||||||
|
** copy string until character is found and place cursor in dst
|
||||||
|
** after last byte copied
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void *ft_memccpy(void *dst, const void *src, int c, size_t n)
|
||||||
|
{
|
||||||
|
unsigned char *dest;
|
||||||
|
unsigned char *sourc;
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
i = -1;
|
||||||
|
dest = (unsigned char *)dst;
|
||||||
|
sourc = (unsigned char *)src;
|
||||||
|
while (++i < n)
|
||||||
|
{
|
||||||
|
dest[i] = sourc[i];
|
||||||
|
if (sourc[i] == (unsigned char)c)
|
||||||
|
return (dst + i + 1);
|
||||||
|
}
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
51
libs/libft/srcs/ft_memchr.c
Normal file
51
libs/libft/srcs/ft_memchr.c
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_memchr.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2019/11/25 13:55:51 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2019/12/12 21:50:32 by hulamy ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
/*
|
||||||
|
** locate character in string and return its position
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
** #include <libc.h>
|
||||||
|
**
|
||||||
|
** void *ft_memchr(const void *s, int c, size_t n);
|
||||||
|
**
|
||||||
|
** int main(void)
|
||||||
|
** {
|
||||||
|
** const char *str;
|
||||||
|
**
|
||||||
|
** char *pouet = "z";
|
||||||
|
** char *lolzer = (char *)&pouet[2];
|
||||||
|
** lolzer = "aaaaaaaaaa";
|
||||||
|
** str = ft_memchr(pouet, 'a', 50);
|
||||||
|
** if (!str)
|
||||||
|
** printf("NULL");
|
||||||
|
** else
|
||||||
|
** printf("%s\n", str);
|
||||||
|
** return (0);
|
||||||
|
** }
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void *ft_memchr(const void *s, int c, size_t n)
|
||||||
|
{
|
||||||
|
unsigned char *sbis;
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
sbis = (unsigned char *)s;
|
||||||
|
i = -1;
|
||||||
|
while (++i < n)
|
||||||
|
if (sbis[i] == (unsigned char)c)
|
||||||
|
return ((void *)sbis + i);
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
32
libs/libft/srcs/ft_memcmp.c
Normal file
32
libs/libft/srcs/ft_memcmp.c
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_memcmp.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2019/11/25 13:56:05 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2019/11/25 13:56:07 by hulamy ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
/*
|
||||||
|
** compare two bytes strings (doesnt recognize a null terminated string)
|
||||||
|
** and return value of difference between first two different character
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
int ft_memcmp(const void *s1, const void *s2, size_t n)
|
||||||
|
{
|
||||||
|
unsigned char *frst;
|
||||||
|
unsigned char *scnd;
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
frst = (unsigned char *)s1;
|
||||||
|
scnd = (unsigned char *)s2;
|
||||||
|
while (i < n && frst[i] == scnd[i])
|
||||||
|
i++;
|
||||||
|
return ((i == n) ? 0 : frst[i] - scnd[i]);
|
||||||
|
}
|
||||||
46
libs/libft/srcs/ft_memcpy.c
Normal file
46
libs/libft/srcs/ft_memcpy.c
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_memcpy.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2019/11/25 13:56:16 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2019/12/01 14:54:14 by hulamy ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
/*
|
||||||
|
** copy n characters from src to dst and return dst
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
** #include <libc.h>
|
||||||
|
**
|
||||||
|
** void *ft_memcpy(void *dst, const void *src, size_t n);
|
||||||
|
**
|
||||||
|
** int main(int ac, char **av)
|
||||||
|
** {
|
||||||
|
** if (ac == 4)
|
||||||
|
** printf("%s\n", ft_memcpy(av[1], av[2], atoi(av[3])));
|
||||||
|
** return (0);
|
||||||
|
** }
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void *ft_memcpy(void *dst, const void *src, size_t n)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
char *ptr;
|
||||||
|
char *ptr2;
|
||||||
|
|
||||||
|
i = -1;
|
||||||
|
ptr = (char *)dst;
|
||||||
|
ptr2 = (char *)src;
|
||||||
|
if (dst == src)
|
||||||
|
return (dst);
|
||||||
|
while (++i < (int)n)
|
||||||
|
ptr[i] = ptr2[i];
|
||||||
|
return (dst);
|
||||||
|
}
|
||||||
26
libs/libft/srcs/ft_memdel.c
Normal file
26
libs/libft/srcs/ft_memdel.c
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_memdel.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2018/11/14 21:13:26 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2019/04/03 15:44:12 by hulamy ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
/*
|
||||||
|
** free memory
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_memdel(void **ap)
|
||||||
|
{
|
||||||
|
if (ap && *ap)
|
||||||
|
{
|
||||||
|
free(*ap);
|
||||||
|
*ap = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
68
libs/libft/srcs/ft_memmove.c
Normal file
68
libs/libft/srcs/ft_memmove.c
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_memmove.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2019/11/25 13:56:25 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2019/12/10 23:53:40 by hulamy ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
/*
|
||||||
|
** copy n characters from src to dst in a non destructive way and return dst
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
** #include <libc.h>
|
||||||
|
**
|
||||||
|
** size_t ft_strlen(const char *str)
|
||||||
|
** {
|
||||||
|
** size_t i;
|
||||||
|
**
|
||||||
|
** i = 0;
|
||||||
|
** while (str[i])
|
||||||
|
** i++;
|
||||||
|
** return (i);
|
||||||
|
** }
|
||||||
|
**
|
||||||
|
** void *ft_memmove(void *dst, const void *src, size_t len);
|
||||||
|
**
|
||||||
|
** //int main(int ac, char **av)
|
||||||
|
** int main(void)
|
||||||
|
** {
|
||||||
|
** char *src = "this is a good nyancat !\r\n";
|
||||||
|
** char dst[0xF0];
|
||||||
|
** int size = strlen(src);
|
||||||
|
**
|
||||||
|
** // if (ac == 4)
|
||||||
|
** // printf("%s\n", ft_memmove(av[1], av[2], atoi(av[3])));
|
||||||
|
**
|
||||||
|
** ft_memmove(dst, src, size);
|
||||||
|
** printf("%s", dst);
|
||||||
|
** return (0);
|
||||||
|
** }
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void *ft_memmove(void *dst, const void *src, size_t len)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
char *cpsrc;
|
||||||
|
char *cpdst;
|
||||||
|
|
||||||
|
i = -1;
|
||||||
|
cpsrc = (char *)src;
|
||||||
|
cpdst = (char *)dst;
|
||||||
|
if (dst == src)
|
||||||
|
return (dst);
|
||||||
|
if (cpsrc < cpdst)
|
||||||
|
while (len--)
|
||||||
|
cpdst[len] = cpsrc[len];
|
||||||
|
else
|
||||||
|
while (++i < len)
|
||||||
|
cpdst[i] = cpsrc[i];
|
||||||
|
return (dst);
|
||||||
|
}
|
||||||
29
libs/libft/srcs/ft_memset.c
Normal file
29
libs/libft/srcs/ft_memset.c
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_memset.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2019/11/25 13:56:37 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2019/11/25 13:56:38 by hulamy ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
/*
|
||||||
|
** copy n time a character in a string and return the string
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void *ft_memset(void *b, int c, size_t len)
|
||||||
|
{
|
||||||
|
char *ptr;
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
ptr = (char *)b;
|
||||||
|
i = 0;
|
||||||
|
while (i < len)
|
||||||
|
ptr[i++] = c;
|
||||||
|
return (b);
|
||||||
|
}
|
||||||
105
libs/libft/srcs/ft_printf_files/ft_convert.c
Normal file
105
libs/libft/srcs/ft_printf_files/ft_convert.c
Normal file
@@ -0,0 +1,105 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_convert.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2020/03/12 22:30:05 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2020/06/30 00:40:49 by hulamy ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
** -convert the next argument into a string according to the following
|
||||||
|
** correspondances for diuxXcspefgn :
|
||||||
|
** [char] [hhd, hhi, c] [int] [d i c]
|
||||||
|
** [short] [hd, hi] [int]
|
||||||
|
** [int] [d, i] [int]
|
||||||
|
** [long] [ld, li] [long] [ld li]
|
||||||
|
** [long long] [lld, lli] [long]
|
||||||
|
** [unsigned char] [hhu, hhx, hhX] [unsigned int] [u x X p s]
|
||||||
|
** [unsigned short] [hu, hx, hX] [unsigned int]
|
||||||
|
** [unsigned int] [u, x, X, p] [unsigned int]
|
||||||
|
** [unsigned long] [lu, lx, lX] [unsigned long] [lu lx lX]
|
||||||
|
** [unsigned long long][llu, llx, llX] [unsigned long]
|
||||||
|
** [char *] [s, hhn]
|
||||||
|
** [double] [e, le, f, lf, g, lg]
|
||||||
|
** [wint_t] [lc]
|
||||||
|
** [wchar_t] [ls]
|
||||||
|
** [short *] [hn]
|
||||||
|
** [int *] [n]
|
||||||
|
** [long *] [ln]
|
||||||
|
** [long long *] [lln]
|
||||||
|
** -'h' and 'hh', are traited just like regular size because of
|
||||||
|
** default promotion, that promote smaller type than int into int
|
||||||
|
*/
|
||||||
|
|
||||||
|
char *conv_i(char c, long int i)
|
||||||
|
{
|
||||||
|
char *s;
|
||||||
|
|
||||||
|
if (c == 'c')
|
||||||
|
{
|
||||||
|
s = ft_strdup("0");
|
||||||
|
s[0] = i;
|
||||||
|
return (s);
|
||||||
|
}
|
||||||
|
if (c == 'd' || c == 'i')
|
||||||
|
return (ft_itoa(i));
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
char *conv_u(char c, unsigned long int i)
|
||||||
|
{
|
||||||
|
char *s;
|
||||||
|
|
||||||
|
if (c == 's')
|
||||||
|
return (i == 0 ? ft_strdup("(null)") : ft_strdup((char *)i));
|
||||||
|
s = ft_utoa(i);
|
||||||
|
if (c == 'u')
|
||||||
|
return (s);
|
||||||
|
if (c == 'x' || c == 'p')
|
||||||
|
return (ft_convertbase_free(s, "0123456789", "0123456789abcdef"));
|
||||||
|
if (c == 'X')
|
||||||
|
return (ft_convertbase_free(s, "0123456789", "0123456789ABCDEF"));
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** -first a loop to expand all the stars from width and .precision
|
||||||
|
** they always expand into int type
|
||||||
|
** it's done first because those are the first next args on the va_list
|
||||||
|
** -for each kind of specifier there is finally four kinds of conversion :
|
||||||
|
** int / long int / unsigned int / unsingned long int
|
||||||
|
** -the conversion 'uxX' associated with 'l' are converted with lu, but
|
||||||
|
** also are 'p' and 's', without an 'l' flag, that's why there is this little
|
||||||
|
** trick on line the line for unsigned int :
|
||||||
|
** -'uxXps' && 'lps' will make it looks for 'uxX' and for 'l'
|
||||||
|
** (because it will never find a 'p' or a 's' if there are 'uxX' already)
|
||||||
|
** or for 'p' and again for 'p', or 's' twice similarly
|
||||||
|
*/
|
||||||
|
|
||||||
|
char *ft_convert(va_list ap, char *type, char **s)
|
||||||
|
{
|
||||||
|
char *tmp;
|
||||||
|
|
||||||
|
while (ft_strchr(*s, '*'))
|
||||||
|
if (!(ft_expand_star(va_arg(ap, int), s)))
|
||||||
|
return (NULL);
|
||||||
|
if ((tmp = ft_strchrset(type, "dic")) && ft_strchr(type, 'l'))
|
||||||
|
return (conv_i(tmp[0], va_arg(ap, long int)));
|
||||||
|
if ((tmp = ft_strchrset(type, "dic")))
|
||||||
|
return (conv_i(tmp[0], va_arg(ap, int)));
|
||||||
|
if ((tmp = ft_strchrset(type, "uxXps")) && ft_strchrset(type, "lps"))
|
||||||
|
return (conv_u(tmp[0], va_arg(ap, unsigned long int)));
|
||||||
|
if ((tmp = ft_strchrset(type, "uxX")))
|
||||||
|
return (conv_u(tmp[0], va_arg(ap, unsigned int)));
|
||||||
|
if (ft_strchr(type, '%'))
|
||||||
|
return (ft_strdup("%"));
|
||||||
|
if (ft_strchrset(type, "efgn"))
|
||||||
|
return (NULL);
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
199
libs/libft/srcs/ft_printf_files/ft_flag_transform.c
Normal file
199
libs/libft/srcs/ft_printf_files/ft_flag_transform.c
Normal file
@@ -0,0 +1,199 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_flag_transform.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2020/03/12 22:30:28 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2020/03/12 22:30:41 by hulamy ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
** -function that modify the string 'print' according to the precision flag :
|
||||||
|
** if length(s) < precision, add x '0' bfr nbr, but after '-' if negative
|
||||||
|
*/
|
||||||
|
|
||||||
|
char *precision_int(char *print, int precision)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
char *tmp;
|
||||||
|
|
||||||
|
i = ft_strlen(print);
|
||||||
|
if (print[0] == '-')
|
||||||
|
precision++;
|
||||||
|
if (precision > i)
|
||||||
|
{
|
||||||
|
if (!(tmp = (char *)malloc(sizeof(char) * (precision + 1))))
|
||||||
|
return (NULL);
|
||||||
|
tmp[precision] = '\0';
|
||||||
|
if (print[0] == '-')
|
||||||
|
tmp[0] = '-';
|
||||||
|
while (i)
|
||||||
|
tmp[--precision] = print[--i];
|
||||||
|
if (print[0] == '-')
|
||||||
|
precision++;
|
||||||
|
while (precision)
|
||||||
|
tmp[--precision] = '0';
|
||||||
|
if (print[0] == '-')
|
||||||
|
tmp[0] = '-';
|
||||||
|
free(print);
|
||||||
|
print = tmp;
|
||||||
|
}
|
||||||
|
return (print);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** -it first verify if there is a precision point, and if so, it execute a
|
||||||
|
** serie of action listed below, otherwise return print as it is
|
||||||
|
** ACTIONS :
|
||||||
|
** -look for a '.'
|
||||||
|
** -if followed by numbers, extract an int version of those numbers
|
||||||
|
** -if the '.' is alone, gives value '0' to the int
|
||||||
|
** -then removes the '.' and the numbers from the %string
|
||||||
|
** -if flag '0' is present in %string, removes it (actually turn each occurence
|
||||||
|
** in a '.')
|
||||||
|
** -and transform 'print' according to the precision :
|
||||||
|
** -0 if .precision is 0 && print is "0": print nothing
|
||||||
|
** -1 if type is s: if length(s) > precision, removes end of 'print' to print
|
||||||
|
** only x chars, with x = precision
|
||||||
|
** -2 if type is "diouxX": call fonction 'precision_int' that return :
|
||||||
|
** if length(s) < precision, add x '0' bfr nbr, but after '-' if negative
|
||||||
|
** -3 if type is "aAeEfF": not covered
|
||||||
|
** -4 if type is "gG": not covered
|
||||||
|
** -5 else: error
|
||||||
|
*/
|
||||||
|
|
||||||
|
char *ft_precision(char *s, char *print, char *type)
|
||||||
|
{
|
||||||
|
char *tmp;
|
||||||
|
int precision;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
if ((tmp = ft_strchr(s, '.')))
|
||||||
|
{
|
||||||
|
precision = ft_atoi(tmp + 1);
|
||||||
|
while (*s && ft_strchr("#- +'0", *(++s)))
|
||||||
|
if (*s == '0')
|
||||||
|
*s = '/';
|
||||||
|
i = 0;
|
||||||
|
if (precision == 0 && !ft_strcmp(print, "0"))
|
||||||
|
print[0] = '\0';
|
||||||
|
else if (ft_strchr(type, 's'))
|
||||||
|
{
|
||||||
|
while (i < precision && print[i])
|
||||||
|
i++;
|
||||||
|
if (print[i])
|
||||||
|
print[i] = '\0';
|
||||||
|
}
|
||||||
|
else if (ft_strchrset(type, "diouxX"))
|
||||||
|
print = precision_int(print, precision);
|
||||||
|
}
|
||||||
|
return (print);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** -if flag '-' is present, put extra width as ' ' to right of 'print'
|
||||||
|
** -if flag '0' is present, put extra width as '0' to left of 'print'
|
||||||
|
** -else, put extra width as ' ' to left of 'print'
|
||||||
|
*/
|
||||||
|
|
||||||
|
char *width_flags(char *print, char *s, int width, int zero)
|
||||||
|
{
|
||||||
|
char *tmp;
|
||||||
|
char *minus;
|
||||||
|
int len;
|
||||||
|
|
||||||
|
len = ft_strlen(print) + zero;
|
||||||
|
if (!(tmp = ft_strnew(width)))
|
||||||
|
return (NULL);
|
||||||
|
if (ft_strchr(s, '-'))
|
||||||
|
{
|
||||||
|
ft_memmove(tmp, print, len);
|
||||||
|
ft_memset(tmp + len, ' ', width - len);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ft_memset(tmp, (ft_strchr(s, '0')) ? '0' : ' ', width - len);
|
||||||
|
ft_memmove(ft_strchr(tmp, '\0') + zero, print, ft_strlen(print));
|
||||||
|
if (ft_strchr(s, '0') && (minus = ft_strchrset("+-", tmp)))
|
||||||
|
{
|
||||||
|
tmp[0] = (minus[0] == '+') ? '+' : '-';
|
||||||
|
minus[0] = '0';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
free(print);
|
||||||
|
return (tmp);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** -if there is a minimal width field, calculate it and add it to print
|
||||||
|
** according to the flags '-' and '0' if present
|
||||||
|
** -in details :
|
||||||
|
** 0 if print[0] value 0, as it happens for type c with (char)0, save it for
|
||||||
|
** later in 'zero'
|
||||||
|
** 1 loop through s, the string starting by '%' and ending by a converter,
|
||||||
|
** until it has passed all the flags that are not a potentiel width field
|
||||||
|
** 2 then if it's the end of s, there is no width and print isn't changed,
|
||||||
|
** otherwise the int 'size' take the value returned by atoi
|
||||||
|
** in case print isn't changed, 'size' is the length of 'print'
|
||||||
|
** 3 then if the size of the width shield is bigger than the size of print
|
||||||
|
** (plus zero in case print is a (char)0), call 'width_flags' that will
|
||||||
|
** create a new char* to contain the string to print after transformation
|
||||||
|
** 4 otherwise 'size' is the length of print + zero
|
||||||
|
*/
|
||||||
|
|
||||||
|
char *ft_width(char *s, char *print, int *size, char *type)
|
||||||
|
{
|
||||||
|
char *tmp;
|
||||||
|
int zero;
|
||||||
|
|
||||||
|
tmp = s;
|
||||||
|
zero = 0;
|
||||||
|
if (print[0] == '\0' && ft_strchr(type, 'c'))
|
||||||
|
zero = 1;
|
||||||
|
while (*tmp != '\0' && ft_strchr("%#- +'0/", *tmp))
|
||||||
|
tmp++;
|
||||||
|
if (*tmp == '\0' || *tmp == '.')
|
||||||
|
{
|
||||||
|
*size = ft_strlen(print) + zero;
|
||||||
|
return (print);
|
||||||
|
}
|
||||||
|
*size = ft_atoi(tmp);
|
||||||
|
tmp[0] = '\0';
|
||||||
|
if ((unsigned int)*size > ft_strlen(print) + zero)
|
||||||
|
print = width_flags(print, s, *size, zero);
|
||||||
|
else
|
||||||
|
*size = ft_strlen(print) + zero;
|
||||||
|
tmp[0] = '1';
|
||||||
|
return (print);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** -go through all the transformation flags needs
|
||||||
|
** -first the precision
|
||||||
|
** -then if type is int and nbr is positive, add a + to the left, it's flag '+'
|
||||||
|
** -third the flag "#"
|
||||||
|
** -fourth, the width
|
||||||
|
** -then p
|
||||||
|
** -the case of 'p' is treated without any subtelness because i don't care
|
||||||
|
*/
|
||||||
|
|
||||||
|
char *ft_flag_transform(char *s, char *print, char *type, int *size)
|
||||||
|
{
|
||||||
|
print = ft_precision(s, print, type);
|
||||||
|
print = ft_plus(s, print, type);
|
||||||
|
print = ft_sharp(s, print, type);
|
||||||
|
if (ft_strchr(type, 'p'))
|
||||||
|
{
|
||||||
|
print = ft_concat_free(ft_strdup("0x"), print);
|
||||||
|
*size += 2;
|
||||||
|
}
|
||||||
|
print = ft_width(s, print, size, type);
|
||||||
|
print = ft_sharp_again(s, print, type);
|
||||||
|
print = ft_space(s, print, type, size);
|
||||||
|
return (print);
|
||||||
|
}
|
||||||
75
libs/libft/srcs/ft_printf_files/ft_flag_transform_bonus.c
Normal file
75
libs/libft/srcs/ft_printf_files/ft_flag_transform_bonus.c
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_flag_transform_bonus.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2020/03/12 22:30:50 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2020/03/12 22:30:57 by hulamy ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
char *ft_plus(char *s, char *print, char *type)
|
||||||
|
{
|
||||||
|
if (!ft_strchrset(type, "di"))
|
||||||
|
return (print);
|
||||||
|
if (ft_strchr(s, '+') && !ft_strchr(print, '-'))
|
||||||
|
print = ft_concat_free(ft_strdup("+"), print);
|
||||||
|
return (print);
|
||||||
|
}
|
||||||
|
|
||||||
|
char *ft_sharp(char *s, char *print, char *type)
|
||||||
|
{
|
||||||
|
if (ft_strchr(s, '#'))
|
||||||
|
{
|
||||||
|
if (ft_strchr(type, 'x'))
|
||||||
|
print = ft_concat_free(ft_strdup("0x"), print);
|
||||||
|
else
|
||||||
|
print = ft_concat_free(ft_strdup("0X"), print);
|
||||||
|
}
|
||||||
|
return (print);
|
||||||
|
}
|
||||||
|
|
||||||
|
char *ft_sharp_again(char *s, char *print, char *type)
|
||||||
|
{
|
||||||
|
char *tmp;
|
||||||
|
|
||||||
|
if (!ft_strchr(s, '#'))
|
||||||
|
return (print);
|
||||||
|
if (print[0] == '0' && print[1] == '0' && ft_strchrset(type, "xX"))
|
||||||
|
{
|
||||||
|
tmp = ft_strchrset("xX", print);
|
||||||
|
print[1] = tmp[0];
|
||||||
|
tmp[0] = '0';
|
||||||
|
}
|
||||||
|
return (print);
|
||||||
|
}
|
||||||
|
|
||||||
|
char *ft_space(char *s, char *print, char *type, int *size)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
if (print[0] == ' ' || !ft_strchr(s, ' ') || !ft_strchrset(type, "diuxX"))
|
||||||
|
return (print);
|
||||||
|
while (print[i] == ' ')
|
||||||
|
i++;
|
||||||
|
if (print[i] == '-' || print[i] == '+')
|
||||||
|
return (print);
|
||||||
|
if (ft_strchr(s, '.') || (i == 0 && print[i] != '0'))
|
||||||
|
{
|
||||||
|
print = ft_concat_free(ft_strdup(" "), print);
|
||||||
|
*size += 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
print[i] = ' ';
|
||||||
|
if (ft_strchr(s, '-') && print[*size - 1] == ' ')
|
||||||
|
{
|
||||||
|
print[*size] = '\0';
|
||||||
|
*size -= 1;
|
||||||
|
}
|
||||||
|
return (print);
|
||||||
|
}
|
||||||
98
libs/libft/srcs/ft_printf_files/ft_next_word.c
Normal file
98
libs/libft/srcs/ft_printf_files/ft_next_word.c
Normal file
@@ -0,0 +1,98 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* next_word.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2020/02/10 13:58:30 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2020/02/26 18:24:04 by hulamy ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
** -placed outside of "word_length" for lake of space
|
||||||
|
** -check if there is a '*' or a number
|
||||||
|
** -usefull as such for the 'width', and after a check
|
||||||
|
** for a '.' for the 'precision' flag
|
||||||
|
*/
|
||||||
|
|
||||||
|
int width_precision(char *s)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
if (ft_strchr("*", s[i]) != NULL)
|
||||||
|
i++;
|
||||||
|
while (ft_strchr("0123456789", s[i]) != NULL)
|
||||||
|
i++;
|
||||||
|
return (i);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** -return the length of the next word to print
|
||||||
|
** -for that it got through the characters expecting
|
||||||
|
** in the following order :
|
||||||
|
** [%][flags][width][.precision][length][specifier]
|
||||||
|
** knowing that 'flags' can repeat themselves
|
||||||
|
** -a single '%' is treated as a word of length 1
|
||||||
|
** (unlike the real printf)
|
||||||
|
** -it's written :
|
||||||
|
** i += width_precision(s + i + 1) + 1;
|
||||||
|
** instead of :
|
||||||
|
** i++;
|
||||||
|
** i += width_precision(s + i);
|
||||||
|
** to save a line (3 with the brackets)
|
||||||
|
*/
|
||||||
|
|
||||||
|
int word_length(char *s)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = 1;
|
||||||
|
if (s[0] == '\0')
|
||||||
|
return (0);
|
||||||
|
if (s[0] != '%')
|
||||||
|
{
|
||||||
|
while (s[i] != '%' && s[i] != '\0')
|
||||||
|
i++;
|
||||||
|
return (i);
|
||||||
|
}
|
||||||
|
while (ft_strchr("#0- +'", s[i]) != NULL)
|
||||||
|
i++;
|
||||||
|
i += width_precision(s + i);
|
||||||
|
if (ft_strchr(".", s[i]) != NULL)
|
||||||
|
i += width_precision(s + i + 1) + 1;
|
||||||
|
while (ft_strchr("hl", s[i]) != NULL)
|
||||||
|
i++;
|
||||||
|
if (ft_strchr("diuxXcspefgn%", s[i]) != NULL)
|
||||||
|
i++;
|
||||||
|
return (i);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** -return the next sequence to be print
|
||||||
|
** (either a string, or a conversion)
|
||||||
|
** -a single '%' is an error in real printf
|
||||||
|
** but is treated as a '%' here
|
||||||
|
*/
|
||||||
|
|
||||||
|
char *next_word(char **string)
|
||||||
|
{
|
||||||
|
char *s;
|
||||||
|
char *word;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
s = *string;
|
||||||
|
if (*s == '\0')
|
||||||
|
return (NULL);
|
||||||
|
if ((i = word_length(s)) < 0)
|
||||||
|
return (NULL);
|
||||||
|
word = (char *)malloc(sizeof(char) * (i + 1));
|
||||||
|
word[i] = '\0';
|
||||||
|
ft_memmove(word, s, i);
|
||||||
|
*string += i;
|
||||||
|
return (word);
|
||||||
|
}
|
||||||
162
libs/libft/srcs/ft_printf_files/ft_printf.c
Normal file
162
libs/libft/srcs/ft_printf_files/ft_printf.c
Normal file
@@ -0,0 +1,162 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_printf.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2020/03/12 22:31:29 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2020/06/30 00:41:35 by hulamy ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
** SPECIFIER :
|
||||||
|
** receive a word as a string, check if it start by '%', and return the
|
||||||
|
** specifier (diuxXspefgn) and the length (h hh l ll)
|
||||||
|
** -if s is a string, or is a single '%'
|
||||||
|
** return NULL (to print is as a string)
|
||||||
|
** -if s is a double '%%', remove one '%', and
|
||||||
|
** return NULL (to print is as a string)
|
||||||
|
** -then s is a conversion, go to the length and specifier
|
||||||
|
** -copy them in 'string'
|
||||||
|
** -and remove them from s
|
||||||
|
** -return the length and specifier in a string
|
||||||
|
*/
|
||||||
|
|
||||||
|
char *specifier(char *s)
|
||||||
|
{
|
||||||
|
char *string;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
if (s[0] != '%' || s[1] == '\0')
|
||||||
|
return (NULL);
|
||||||
|
if (s[1] == '%')
|
||||||
|
{
|
||||||
|
s[1] = '\0';
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
i = 1;
|
||||||
|
while (ft_strchr("#0- +'0123456789.*", s[i]) != NULL)
|
||||||
|
i++;
|
||||||
|
string = ft_strdup(s + i);
|
||||||
|
while (s[i] != '\0')
|
||||||
|
{
|
||||||
|
s[i] = '\0';
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (string);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** -receive 'i' the number in which '*' will expand
|
||||||
|
** -turn it into a string
|
||||||
|
** -calculate the total lentgh of the string '%...' for nbr replacing '*'
|
||||||
|
** -allocate a new string with this length
|
||||||
|
** -copy the original str with first '*' expanded into it's corresponding nbr
|
||||||
|
*/
|
||||||
|
|
||||||
|
int ft_expand_star(int nbr, char **string)
|
||||||
|
{
|
||||||
|
char *s;
|
||||||
|
char *n;
|
||||||
|
int i;
|
||||||
|
int j;
|
||||||
|
int k;
|
||||||
|
|
||||||
|
n = ft_itoa(nbr);
|
||||||
|
if (!(s = ft_memalloc(sizeof(char) * (ft_strlen(n) + ft_strlen(*string)))))
|
||||||
|
return (0);
|
||||||
|
i = -1;
|
||||||
|
j = 0;
|
||||||
|
k = 0;
|
||||||
|
while ((*string)[++i] != '\0')
|
||||||
|
{
|
||||||
|
s[j] = (*string)[i];
|
||||||
|
if (s[j] == '*')
|
||||||
|
while (n[k] != '\0')
|
||||||
|
s[j++] = n[k++];
|
||||||
|
else
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
free(n);
|
||||||
|
free(*string);
|
||||||
|
*string = s;
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** print the string
|
||||||
|
** because of lake of space, it also free 'type'
|
||||||
|
*/
|
||||||
|
|
||||||
|
int ft_put_word(char *s, char *type, int size)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while (i < size)
|
||||||
|
write(1, &(s[i++]), 1);
|
||||||
|
free(type);
|
||||||
|
free(s);
|
||||||
|
return (i);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** because of lake of space...
|
||||||
|
** -1 expand the specifier according to its type and its length
|
||||||
|
** and put in a string 'print'
|
||||||
|
** -2 transform 'print' according to the flags
|
||||||
|
*/
|
||||||
|
|
||||||
|
char *convert_with_flags(char *s, va_list ap, char *type, int *size)
|
||||||
|
{
|
||||||
|
char *print;
|
||||||
|
|
||||||
|
if (!(print = ft_convert(ap, type, &s)))
|
||||||
|
return (NULL);
|
||||||
|
if (!(print = ft_flag_transform(s, print, type, size)))
|
||||||
|
return (NULL);
|
||||||
|
free(s);
|
||||||
|
return (print);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** -printf receive a string to print with a variadic number of arguments
|
||||||
|
** -it will go in a loop through each 'words'
|
||||||
|
** -a word is either a string containing no '%' or a conversion starting by '%'
|
||||||
|
** -if it's a string it's printed right away
|
||||||
|
** -if it's a conversion it will call convert_with_flags for some actions :
|
||||||
|
** -1 expand the specifier according to its type and its length
|
||||||
|
** and put in a string 'print'
|
||||||
|
** -2 transform 'print' according to the flags
|
||||||
|
*/
|
||||||
|
|
||||||
|
int ft_printf(char *string, ...)
|
||||||
|
{
|
||||||
|
char *s;
|
||||||
|
char *type;
|
||||||
|
int length;
|
||||||
|
int size;
|
||||||
|
va_list ap;
|
||||||
|
|
||||||
|
length = 0;
|
||||||
|
va_start(ap, string);
|
||||||
|
while ((s = next_word(&string)) != NULL)
|
||||||
|
{
|
||||||
|
if ((type = specifier(s)) == NULL)
|
||||||
|
length += ft_put_word(s, type, ft_strlen(s));
|
||||||
|
else
|
||||||
|
{
|
||||||
|
size = 0;
|
||||||
|
if (!(s = convert_with_flags(s, ap, type, &size)))
|
||||||
|
return (-1);
|
||||||
|
length += ft_put_word(s, type, size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
free(s);
|
||||||
|
va_end(ap);
|
||||||
|
return (length);
|
||||||
|
}
|
||||||
18
libs/libft/srcs/ft_putchar_fd.c
Normal file
18
libs/libft/srcs/ft_putchar_fd.c
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_putchar_fd.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2019/11/25 13:59:40 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2019/11/25 13:59:42 by hulamy ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_putchar_fd(char c, int fd)
|
||||||
|
{
|
||||||
|
write(fd, &c, 1);
|
||||||
|
}
|
||||||
28
libs/libft/srcs/ft_putnbr_fd.c
Normal file
28
libs/libft/srcs/ft_putnbr_fd.c
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_putnbr_fd.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2019/11/25 13:59:56 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2019/11/25 13:59:57 by hulamy ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_putnbr_fd(int n, int fd)
|
||||||
|
{
|
||||||
|
long l;
|
||||||
|
|
||||||
|
l = n;
|
||||||
|
if (l < 0)
|
||||||
|
{
|
||||||
|
ft_putchar_fd('-', fd);
|
||||||
|
l *= -1;
|
||||||
|
}
|
||||||
|
if (l >= 10)
|
||||||
|
ft_putnbr_fd(l / 10, fd);
|
||||||
|
ft_putchar_fd((l % 10) + '0', fd);
|
||||||
|
}
|
||||||
59
libs/libft/srcs/ft_putnbrbase.c
Normal file
59
libs/libft/srcs/ft_putnbrbase.c
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_putnbrbase.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2018/11/16 15:17:00 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2022/03/24 17:01:57 by simplonco ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
static int check(char *base)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
int j;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while (base[i])
|
||||||
|
{
|
||||||
|
j = i + 1;
|
||||||
|
while (base[j])
|
||||||
|
{
|
||||||
|
if (base[i] == base[j])
|
||||||
|
return (0);
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
if (base[i] == '-' || base[i] == '+')
|
||||||
|
return (0);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
if (i >= 2)
|
||||||
|
return (1);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ft_putnbrbase(int nbr, char *base)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
long n;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
n = nbr;
|
||||||
|
if (check(base))
|
||||||
|
{
|
||||||
|
if (n < 0)
|
||||||
|
{
|
||||||
|
ft_putchar_fd('-', 1);
|
||||||
|
n = -n;
|
||||||
|
}
|
||||||
|
while (base[i])
|
||||||
|
i++;
|
||||||
|
if (n >= i)
|
||||||
|
ft_putnbrbase(n / i, base);
|
||||||
|
ft_putchar_fd(base[n % i], 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
23
libs/libft/srcs/ft_putstr_fd.c
Normal file
23
libs/libft/srcs/ft_putstr_fd.c
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_putstr_fd.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2019/11/25 14:00:04 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2019/11/25 14:00:05 by hulamy ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
/*
|
||||||
|
** write the string s on the given file descritor fd
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_putstr_fd(char *s, int fd)
|
||||||
|
{
|
||||||
|
while (s && *s)
|
||||||
|
ft_putchar_fd(*s++, fd);
|
||||||
|
}
|
||||||
20
libs/libft/srcs/ft_sign.c
Normal file
20
libs/libft/srcs/ft_sign.c
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_sign.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: pblagoje <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2022/05/04 14:14:19 by pblagoje #+# #+# */
|
||||||
|
/* Updated: 2022/05/04 14:14:25 by pblagoje ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
int ft_sign(int i)
|
||||||
|
{
|
||||||
|
if (i < 0)
|
||||||
|
return (-1);
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
8
libs/libft/srcs/ft_smaller.c
Normal file
8
libs/libft/srcs/ft_smaller.c
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
int ft_smaller(int a, int b)
|
||||||
|
{
|
||||||
|
if (a > b)
|
||||||
|
return (b);
|
||||||
|
return (a);
|
||||||
|
}
|
||||||
139
libs/libft/srcs/ft_split.c
Normal file
139
libs/libft/srcs/ft_split.c
Normal file
@@ -0,0 +1,139 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_split.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2019/12/12 22:41:54 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2022/05/04 14:11:07 by pblagoje ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
/*
|
||||||
|
** return an array of string with each word found in str, with c as separator
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
** #include <stdio.h>
|
||||||
|
** #include <stdlib.h>
|
||||||
|
** #include <unistd.h>
|
||||||
|
**
|
||||||
|
** size_t ft_strlen(const char *str)
|
||||||
|
** {
|
||||||
|
** size_t i;
|
||||||
|
**
|
||||||
|
** i = 0;
|
||||||
|
** while (str[i])
|
||||||
|
** i++;
|
||||||
|
** return (i);
|
||||||
|
** }
|
||||||
|
**
|
||||||
|
** char *ft_substr(char const *s, unsigned int start, size_t len)
|
||||||
|
** {
|
||||||
|
** char *str;
|
||||||
|
** size_t i;
|
||||||
|
**
|
||||||
|
** if (!s)
|
||||||
|
** return (NULL);
|
||||||
|
** if (ft_strlen(s) < start)
|
||||||
|
** return ("");
|
||||||
|
** if (!(str = (char *)malloc(sizeof(char) * (len + 1))))
|
||||||
|
** return (NULL);
|
||||||
|
** i = 0;
|
||||||
|
** while (i < len && s[start])
|
||||||
|
** str[i++] = s[start++];
|
||||||
|
** str[i] = '\0';
|
||||||
|
** return (str);
|
||||||
|
** }
|
||||||
|
**
|
||||||
|
** char **ft_split(char const *s, char c);
|
||||||
|
** char **ft_strsplit(char const *s, char c);
|
||||||
|
**
|
||||||
|
** int main(void)
|
||||||
|
** {
|
||||||
|
** char **str;
|
||||||
|
** int i;
|
||||||
|
**
|
||||||
|
** char *s;
|
||||||
|
** char c;
|
||||||
|
**
|
||||||
|
** i = -1;
|
||||||
|
** s = NULL;
|
||||||
|
** c = ' ';
|
||||||
|
** str = ft_split(s, c);
|
||||||
|
** //if (str)
|
||||||
|
** //{
|
||||||
|
** printf("s : '%s'\n", s);
|
||||||
|
** printf("*str : '%p'\n", str[0]);
|
||||||
|
** while (str[++i])
|
||||||
|
** printf("str[%i] : '%s'\n", i, str[i]);
|
||||||
|
** //}
|
||||||
|
** return (0);
|
||||||
|
** }
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
static int count(char const *s, char c)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
int words;
|
||||||
|
|
||||||
|
i = -1;
|
||||||
|
words = 0;
|
||||||
|
while (s[++i] != '\0')
|
||||||
|
if (s[i] != c && ++words)
|
||||||
|
while (s[i + 1] != '\0' && s[i + 1] != c)
|
||||||
|
i++;
|
||||||
|
return (words);
|
||||||
|
}
|
||||||
|
|
||||||
|
void *ft_free(char **array, int w)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while (array[i] != NULL && i < w)
|
||||||
|
free(array[i++]);
|
||||||
|
free(array);
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
char **empty_s(char **empty)
|
||||||
|
{
|
||||||
|
empty = (char **)malloc(sizeof(char *) * 1);
|
||||||
|
if (!empty)
|
||||||
|
return (NULL);
|
||||||
|
empty[0] = NULL;
|
||||||
|
return (empty);
|
||||||
|
}
|
||||||
|
|
||||||
|
char **ft_split(char const *s, char c)
|
||||||
|
{
|
||||||
|
char **array;
|
||||||
|
int w;
|
||||||
|
int len;
|
||||||
|
|
||||||
|
if (!s)
|
||||||
|
return (empty_s(NULL));
|
||||||
|
array = (char **)malloc(sizeof(char *) * (count(s, c) + 1));
|
||||||
|
if (!array)
|
||||||
|
return (NULL);
|
||||||
|
w = 0;
|
||||||
|
while (*s != '\0')
|
||||||
|
{
|
||||||
|
len = 0;
|
||||||
|
if (*s != c)
|
||||||
|
{
|
||||||
|
while (s[len] != '\0' && s[len] != c)
|
||||||
|
len++;
|
||||||
|
if (!(array[w++] = ft_substr(s, 0, len)))
|
||||||
|
return (ft_free(array, w));
|
||||||
|
s += len - 1;
|
||||||
|
}
|
||||||
|
s++;
|
||||||
|
}
|
||||||
|
array[w] = NULL;
|
||||||
|
return (array);
|
||||||
|
}
|
||||||
15
libs/libft/srcs/ft_sqrt.c
Normal file
15
libs/libft/srcs/ft_sqrt.c
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
** return the square root of nb
|
||||||
|
** or the integer value of it
|
||||||
|
*/
|
||||||
|
int ft_sqrt(int nb)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while ((i*i) < nb)
|
||||||
|
i++;
|
||||||
|
return (i);
|
||||||
|
}
|
||||||
32
libs/libft/srcs/ft_strcat.c
Normal file
32
libs/libft/srcs/ft_strcat.c
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_strcat.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2018/11/14 21:15:40 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2019/03/25 15:12:58 by hulamy ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
/*
|
||||||
|
** append src to dest (dest must have sufficient space) and return dest
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
char *ft_strcat(char *dest, const char *src)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
int j;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
j = 0;
|
||||||
|
while (dest[i])
|
||||||
|
i++;
|
||||||
|
while (src[j])
|
||||||
|
dest[i++] = src[j++];
|
||||||
|
dest[i] = '\0';
|
||||||
|
return (dest);
|
||||||
|
}
|
||||||
33
libs/libft/srcs/ft_strchr.c
Normal file
33
libs/libft/srcs/ft_strchr.c
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_strchr.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2019/11/25 13:56:46 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2019/11/25 13:56:47 by hulamy ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
/*
|
||||||
|
** locate the first occurence of character c in string s
|
||||||
|
** and return pointer to its location
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
char *ft_strchr(const char *s, int c)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
int j;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
j = -1;
|
||||||
|
while (s[i])
|
||||||
|
i++;
|
||||||
|
while (++j < i + 1)
|
||||||
|
if (s[j] == c)
|
||||||
|
return ((char *)s + j);
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
32
libs/libft/srcs/ft_strchrset.c
Normal file
32
libs/libft/srcs/ft_strchrset.c
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_strchrset.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2020/02/16 15:07:11 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2020/03/10 15:24:14 by hulamy ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
/*
|
||||||
|
** if any character of the character set is found in s
|
||||||
|
** return a pointer to the first found, else return 0
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
char *ft_strchrset(const char *s, const char *set)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while (set[i] != '\0')
|
||||||
|
{
|
||||||
|
if (ft_strchr(s, set[i]) != NULL)
|
||||||
|
return ((char *)set + i);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
23
libs/libft/srcs/ft_strclr.c
Normal file
23
libs/libft/srcs/ft_strclr.c
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_strclr.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2018/11/14 21:15:58 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2019/03/25 15:17:42 by hulamy ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
/*
|
||||||
|
** fill string with zeros
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_strclr(char *s)
|
||||||
|
{
|
||||||
|
if (s)
|
||||||
|
ft_bzero(s, ft_strlen(s));
|
||||||
|
}
|
||||||
28
libs/libft/srcs/ft_strcmp.c
Normal file
28
libs/libft/srcs/ft_strcmp.c
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_strcmp.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2018/11/14 21:16:08 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2022/05/04 14:08:35 by pblagoje ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
/*
|
||||||
|
** compare two null terminated strings and return value
|
||||||
|
** of difference between first two different character
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
int ft_strcmp(const char *s1, const char *s2)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while (s1[i] && s1[i] == s2[i])
|
||||||
|
i++;
|
||||||
|
return ((unsigned char)s1[i] - (unsigned char)s2[i]);
|
||||||
|
}
|
||||||
28
libs/libft/srcs/ft_strcpy.c
Normal file
28
libs/libft/srcs/ft_strcpy.c
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_strcpy.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2018/11/14 21:16:17 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2019/03/25 15:19:19 by hulamy ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
/*
|
||||||
|
** copy string src to dst including '\0' and return dst
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
char *ft_strcpy(char *dest, const char *src)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = -1;
|
||||||
|
while (src[++i])
|
||||||
|
dest[i] = src[i];
|
||||||
|
dest[i] = '\0';
|
||||||
|
return (dest);
|
||||||
|
}
|
||||||
26
libs/libft/srcs/ft_strdel.c
Normal file
26
libs/libft/srcs/ft_strdel.c
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_strdel.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2018/11/14 21:16:25 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2019/03/25 15:19:54 by hulamy ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
/*
|
||||||
|
** free memory
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_strdel(char **as)
|
||||||
|
{
|
||||||
|
if (as && *as)
|
||||||
|
{
|
||||||
|
free(*as);
|
||||||
|
*as = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
33
libs/libft/srcs/ft_strdup.c
Normal file
33
libs/libft/srcs/ft_strdup.c
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_strdup.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2019/11/25 13:56:54 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2022/05/04 14:05:57 by pblagoje ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
/*
|
||||||
|
** save a copy of string src by allocating memory and return pointer to copy
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
char *ft_strdup(const char *src)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
char *str;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while (src[i] != '\0')
|
||||||
|
i++;
|
||||||
|
str = (char *)malloc(sizeof(*str) * (i + 1));
|
||||||
|
if (!str)
|
||||||
|
return (NULL);
|
||||||
|
while (i-- >= 0)
|
||||||
|
str[i + 1] = src[i + 1];
|
||||||
|
return (str);
|
||||||
|
}
|
||||||
24
libs/libft/srcs/ft_strequ.c
Normal file
24
libs/libft/srcs/ft_strequ.c
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_strequ.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2018/11/14 21:16:44 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2019/03/25 15:21:02 by hulamy ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
/*
|
||||||
|
** return 0 if strings s1 and s2 are identical and 1 if not
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
int ft_strequ(char const *s1, char const *s2)
|
||||||
|
{
|
||||||
|
if (!s1 || !s2)
|
||||||
|
return (0);
|
||||||
|
return (ft_strcmp(s1, s2) == 0);
|
||||||
|
}
|
||||||
23
libs/libft/srcs/ft_striter.c
Normal file
23
libs/libft/srcs/ft_striter.c
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_striter.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2018/11/14 21:16:53 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2019/03/25 15:21:14 by hulamy ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
/*
|
||||||
|
** apply function f to each element of string s
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_striter(char *s, void (*f)(char *))
|
||||||
|
{
|
||||||
|
while (s && *s && f)
|
||||||
|
f(s++);
|
||||||
|
}
|
||||||
26
libs/libft/srcs/ft_striteri.c
Normal file
26
libs/libft/srcs/ft_striteri.c
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_striteri.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2018/11/14 21:17:04 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2019/03/25 15:21:27 by hulamy ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
/*
|
||||||
|
** apply function f to each element of string s with index specified
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_striteri(char *s, void (*f)(unsigned int, char *))
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while (s && *s && f)
|
||||||
|
f(i++, s++);
|
||||||
|
}
|
||||||
79
libs/libft/srcs/ft_strjoin.c
Normal file
79
libs/libft/srcs/ft_strjoin.c
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_strjoin.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2019/11/25 14:01:26 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2019/12/09 21:38:35 by hulamy ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
/*
|
||||||
|
** create a new string by concatenating the two strings s1 and s2
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
** #include <libc.h>
|
||||||
|
**
|
||||||
|
** size_t ft_strlen(const char *str)
|
||||||
|
** {
|
||||||
|
** size_t i;
|
||||||
|
**
|
||||||
|
** i = 0;
|
||||||
|
** while (str[i])
|
||||||
|
** i++;
|
||||||
|
** return (i);
|
||||||
|
** }
|
||||||
|
**
|
||||||
|
** char *ft_strjoin(char const *s1, char const *s2);
|
||||||
|
**
|
||||||
|
** int main(int ac, char **av)
|
||||||
|
** {
|
||||||
|
** char *s1;
|
||||||
|
** char *s2;
|
||||||
|
** char *str;
|
||||||
|
**
|
||||||
|
** if (ac == 0)
|
||||||
|
** return (0);
|
||||||
|
** else if (ac == 3)
|
||||||
|
** {
|
||||||
|
** s1 = strdup(av[1]);
|
||||||
|
** s2 = strdup(av[2]);
|
||||||
|
** }
|
||||||
|
** else
|
||||||
|
** {
|
||||||
|
** s1 = malloc(sizeof(char*) * 100);
|
||||||
|
** s1 = "sdf";
|
||||||
|
** s2 = "tref";
|
||||||
|
** }
|
||||||
|
** str = ft_strjoin(s1, s2);
|
||||||
|
** printf("%s\n", str);
|
||||||
|
** return (0);
|
||||||
|
** }
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
char *ft_strjoin(char const *s1, char const *s2)
|
||||||
|
{
|
||||||
|
char *str;
|
||||||
|
int len;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
if (!s1 || !s2)
|
||||||
|
return (NULL);
|
||||||
|
len = ft_strlen(s1) + ft_strlen(s2);
|
||||||
|
if (!(str = (char *)malloc(sizeof(char) * (len + 1))))
|
||||||
|
return (NULL);
|
||||||
|
len = 0;
|
||||||
|
i = 0;
|
||||||
|
while (s1[i] != '\0')
|
||||||
|
str[len++] = s1[i++];
|
||||||
|
i = 0;
|
||||||
|
while (s2[i] != '\0')
|
||||||
|
str[len++] = s2[i++];
|
||||||
|
str[len] = '\0';
|
||||||
|
return (str);
|
||||||
|
}
|
||||||
29
libs/libft/srcs/ft_strjoinfree.c
Normal file
29
libs/libft/srcs/ft_strjoinfree.c
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_strjoinfree.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2019/03/05 15:05:28 by hulamy #+# #+# */
|
||||||
|
/* Updated: 2019/03/25 15:22:28 by hulamy ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
/*
|
||||||
|
** create a new string by concatenating the two strings s1 and s2
|
||||||
|
** then free s1 and s2
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
char *ft_strjoinfree(char *s1, char *s2)
|
||||||
|
{
|
||||||
|
char *str;
|
||||||
|
|
||||||
|
if (!(str = ft_strjoin(s1, s2)))
|
||||||
|
return (NULL);
|
||||||
|
free(s1);
|
||||||
|
free(s2);
|
||||||
|
return (str);
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user