Adding the libft
This commit is contained in:
parent
1b98b537b7
commit
c947e43e51
62 changed files with 2098 additions and 19 deletions
4
libft/.clangd
Normal file
4
libft/.clangd
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
CompilerFlags:
|
||||
Add:
|
||||
- "-xc"
|
||||
- "-I/Users/raphael/Documents/42_cursus/circle0/libft/includes"
|
||||
170
libft/Makefile
Normal file
170
libft/Makefile
Normal file
|
|
@ -0,0 +1,170 @@
|
|||
# **************************************************************************** #
|
||||
# #
|
||||
# ::: :::::::: #
|
||||
# Makefile :+: :+: :+: #
|
||||
# +:+ +:+ +:+ #
|
||||
# By: rparodi <marvin@42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2023/11/12 11:05:05 by rparodi #+# #+# #
|
||||
# Updated: 2024/10/31 17:19:36 by rparodi ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
# Variables
|
||||
|
||||
# Name
|
||||
NAME=../build/libft.a
|
||||
|
||||
# Commands
|
||||
CC = cc
|
||||
RM = rm -rf
|
||||
|
||||
# Flags
|
||||
CFLAGS = -Werror -Wextra -Wall
|
||||
CFLAGS += -g3 -MMD
|
||||
# CFLAGS += -lm
|
||||
|
||||
# CFLAGS += -fsanitize=address
|
||||
# CFLAGS += -fsanitize=thread
|
||||
|
||||
LDFLAGS = -L.
|
||||
LDLIBS = -lft
|
||||
|
||||
INCLUDES = ./includes/libft/
|
||||
|
||||
SRC = char/ft_isdigit.c \
|
||||
char/ft_isalnum.c \
|
||||
char/ft_isalpha.c \
|
||||
char/ft_isascii.c \
|
||||
char/ft_isprint.c \
|
||||
char/ft_tolower.c \
|
||||
char/ft_toupper.c \
|
||||
convert/ft_atoi.c \
|
||||
convert/ft_atoll.c \
|
||||
convert/ft_itoa.c \
|
||||
list/ft_lstadd_back.c \
|
||||
list/ft_lstadd_front.c \
|
||||
list/ft_lstclear.c \
|
||||
list/ft_lstdelone.c \
|
||||
list/ft_lstiter.c \
|
||||
list/ft_lstlast.c \
|
||||
list/ft_lstmap.c \
|
||||
list/ft_lstnew.c \
|
||||
list/ft_lstsize.c \
|
||||
memory/ft_bzero.c \
|
||||
memory/ft_calloc.c \
|
||||
memory/ft_memchr.c \
|
||||
memory/ft_memcmp.c \
|
||||
memory/ft_memcpy.c \
|
||||
memory/ft_memmove.c \
|
||||
memory/ft_memset.c \
|
||||
print/ft_printf.c \
|
||||
print/ft_put.c \
|
||||
print/ft_putchar_fd.c \
|
||||
print/ft_putendl_fd.c \
|
||||
print/ft_putnbr_fd.c \
|
||||
print/ft_putstr_fd.c \
|
||||
str/ft_split.c \
|
||||
str/ft_strchr.c \
|
||||
str/ft_strcmp.c \
|
||||
str/ft_strcpy.c \
|
||||
str/ft_strdup.c \
|
||||
str/ft_striteri.c \
|
||||
str/ft_strjoin.c \
|
||||
str/ft_strlcat.c \
|
||||
str/ft_strlcpy.c \
|
||||
str/ft_strlen.c \
|
||||
str/ft_strmapi.c \
|
||||
str/ft_strncmp.c \
|
||||
str/ft_strnstr.c \
|
||||
str/ft_strrchr.c \
|
||||
str/ft_strtrim.c \
|
||||
str/ft_substr.c
|
||||
|
||||
# Objects
|
||||
OBJDIRNAME = ../build
|
||||
OBJ = $(addprefix $(OBJDIRNAME)/,$(SRC:.c=.o))
|
||||
|
||||
# Colors
|
||||
GREEN = \033[32m
|
||||
GREY = \033[0;90m
|
||||
RED = \033[0;31m
|
||||
GOLD = \033[38;5;220m
|
||||
END = \033[0m
|
||||
|
||||
# Rules
|
||||
|
||||
# All (make all)
|
||||
all: header $(NAME) footer
|
||||
|
||||
lib: $(NAME)
|
||||
|
||||
# Bonus (make bonus)
|
||||
bonus: header $(OBJ) $(LIB_OBJ) footer
|
||||
@mkdir -p $(OBJDIRNAME)
|
||||
@mkdir -p $(OBJDIRNAME)/$(SRCDIRNAME)
|
||||
@printf '$(GREY) Be Carefull ur in $(END)$(GREEN)Debug Mode$(END)\n'
|
||||
@cc $(CFLAGS) -D BONUS=1 -o $(NAME) $(OBJ) $(LIB_OBJ)
|
||||
|
||||
# Clean (make clean)
|
||||
clean:
|
||||
@printf '$(GREY) Removing $(END)$(RED)Objects$(END)\n'
|
||||
@printf '$(GREY) Removing $(END)$(RED)Objects Folder$(END)\n'
|
||||
@$(RM) $(OBJDIRNAME)
|
||||
|
||||
# Clean (make fclean)
|
||||
fclean: clean
|
||||
@printf '$(GREY) Removing $(END)$(RED)Program$(END)\n'
|
||||
@$(RM) $(NAME)
|
||||
@echo ""
|
||||
|
||||
# Restart (make re)
|
||||
re: header fclean all
|
||||
|
||||
# Dependences for all
|
||||
$(NAME): $(OBJ)
|
||||
@mkdir -p $(OBJDIRNAME)
|
||||
@ar rc $(NAME) $(OBJ)
|
||||
@ranlib $(NAME)
|
||||
|
||||
# Creating the objects
|
||||
$(OBJDIRNAME)/%.o: %.c
|
||||
@mkdir -p $(dir $@)
|
||||
@printf '$(GREY) Compiling $(END)$(GREEN)$<$(END)\n'
|
||||
@cc $(CFLAGS) -o $@ -c $< -I$(INCLUDES)
|
||||
|
||||
# Header
|
||||
header:
|
||||
@clear
|
||||
@printf '\n\n'
|
||||
@printf '$(GOLD) ******* ****** ******* $(END)\n'
|
||||
@printf '$(GOLD) ****** *** ******* $(END)\n'
|
||||
@printf '$(GOLD) ******* * ******* $(END)\n'
|
||||
@printf '$(GOLD) ****** ******* $(END)\n'
|
||||
@printf '$(GOLD) ******* ******* $(END)\n'
|
||||
@printf '$(GOLD) ******************* ******* * $(END)\n'
|
||||
@printf '$(GOLD) ******************* ******* *** $(END)\n'
|
||||
@printf '$(GOLD) ****** ******* ****** $(END)\n'
|
||||
@printf '$(GOLD) ****** $(END)\n'
|
||||
@printf '$(GOLD) ****** $(END)\n'
|
||||
@printf '$(GREY) Made by rparodi$(END)\n\n'
|
||||
|
||||
# Footer
|
||||
footer:
|
||||
@printf "\n"
|
||||
@printf "$(GOLD) ,_ _,$(END)\n"
|
||||
@printf "$(GOLD) | \\___//|$(END)\n"
|
||||
@printf "$(GOLD) |=6 6=|$(END)\n"
|
||||
@printf "$(GOLD) \\=._Y_.=/$(END)\n"
|
||||
@printf "$(GOLD) ) \` ( ,$(END)\n"
|
||||
@printf "$(GOLD) / \\ (('$(END)\n"
|
||||
@printf "$(GOLD) | | ))$(END)\n"
|
||||
@printf "$(GOLD) /| | | |\\_//$(END)\n"
|
||||
@printf "$(GOLD) \\| |._.| |/-\`$(END)\n"
|
||||
@printf "$(GOLD) '\"' '\"'$(END)\n"
|
||||
@printf ' $(GREY)The compilation is$(END) $(GOLD)finish$(END)\n $(GREY)Have a good $(END)$(GOLD)correction !$(END)\n'
|
||||
|
||||
# Phony
|
||||
.PHONY: all bonus clean fclean re
|
||||
|
||||
-include ${OBJ:.o=.d}
|
||||
26
libft/char/ft_isalnum.c
Normal file
26
libft/char/ft_isalnum.c
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_isalnum.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/06 12:47:28 by rparodi #+# #+# */
|
||||
/* Updated: 2024/10/31 12:54:42 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
/**
|
||||
* @brief Check if the character is alpha-numeric
|
||||
*
|
||||
* @param c the character
|
||||
* @return the character if alphanumeric or 0 if not
|
||||
*/
|
||||
int ft_isalnum(int c)
|
||||
{
|
||||
if (ft_isalpha(c) || ft_isdigit(c))
|
||||
return (c);
|
||||
return (0);
|
||||
}
|
||||
26
libft/char/ft_isalpha.c
Normal file
26
libft/char/ft_isalpha.c
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_isalpha.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/06 11:58:37 by rparodi #+# #+# */
|
||||
/* Updated: 2024/10/31 12:54:40 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
/**
|
||||
* @brief Check if the character is alpha
|
||||
*
|
||||
* @param c the character
|
||||
* @return the character if alpha or 0 if not
|
||||
*/
|
||||
int ft_isalpha(int c)
|
||||
{
|
||||
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
|
||||
return (c);
|
||||
return (0);
|
||||
}
|
||||
28
libft/char/ft_isascii.c
Normal file
28
libft/char/ft_isascii.c
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_isascii.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/06 14:04:26 by rparodi #+# #+# */
|
||||
/* Updated: 2024/10/31 12:49:55 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
/**
|
||||
* @brief Check if the character is in the ascii table
|
||||
*
|
||||
* @param c the character
|
||||
* @return the character if in the ascii table or 0 if not
|
||||
*/
|
||||
int ft_isascii(int c)
|
||||
{
|
||||
if (c == 0)
|
||||
return (1);
|
||||
if (c > 0 && c <= 127)
|
||||
return (c);
|
||||
return (0);
|
||||
}
|
||||
26
libft/char/ft_isdigit.c
Normal file
26
libft/char/ft_isdigit.c
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_isdigit.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/06 12:44:28 by rparodi #+# #+# */
|
||||
/* Updated: 2024/10/31 12:49:05 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
/**
|
||||
* @brief Check if the character is alpha numeric
|
||||
*
|
||||
* @param c the character
|
||||
* @return the character if numeric or 0 if not
|
||||
*/
|
||||
int ft_isdigit(int c)
|
||||
{
|
||||
if (c >= '0' && c <= '9')
|
||||
return (c);
|
||||
return (0);
|
||||
}
|
||||
26
libft/char/ft_isprint.c
Normal file
26
libft/char/ft_isprint.c
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_isprint.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/06 14:06:53 by rparodi #+# #+# */
|
||||
/* Updated: 2024/10/31 12:50:37 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
/**
|
||||
* @brief Check if the character is printable
|
||||
*
|
||||
* @param c the character
|
||||
* @return the character if can be print or 0 if not
|
||||
*/
|
||||
int ft_isprint(int c)
|
||||
{
|
||||
if (c >= 32 && c <= 126)
|
||||
return (c);
|
||||
return (0);
|
||||
}
|
||||
26
libft/char/ft_tolower.c
Normal file
26
libft/char/ft_tolower.c
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_tolower.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/07 10:38:54 by rparodi #+# #+# */
|
||||
/* Updated: 2024/10/31 12:55:28 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
/**
|
||||
* @brief convert the upper case to lower case
|
||||
*
|
||||
* @param c the character
|
||||
* @return the character to lower case if is on upper
|
||||
*/
|
||||
int ft_tolower(int c)
|
||||
{
|
||||
if (c >= 'A' && c <= 'Z')
|
||||
c += 32;
|
||||
return (c);
|
||||
}
|
||||
26
libft/char/ft_toupper.c
Normal file
26
libft/char/ft_toupper.c
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_toupper.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/07 10:44:26 by rparodi #+# #+# */
|
||||
/* Updated: 2024/10/31 12:55:14 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
/**
|
||||
* @brief convert the lower case to upper case
|
||||
*
|
||||
* @param c the character
|
||||
* @return the character to upper case if is on lower
|
||||
*/
|
||||
int ft_toupper(int c)
|
||||
{
|
||||
if (c >= 'a' && c <= 'z')
|
||||
c -= 32;
|
||||
return (c);
|
||||
}
|
||||
60
libft/convert/ft_atoi.c
Normal file
60
libft/convert/ft_atoi.c
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_atoi.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/08 17:22:41 by rparodi #+# #+# */
|
||||
/* Updated: 2024/10/31 15:16:10 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
static int ft_check_space(int c)
|
||||
{
|
||||
if (c == 32 || (c >= 9 && c <= 13))
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int ft_check_sign(const char *nptr, int *i)
|
||||
{
|
||||
while (ft_check_space(nptr[*i]))
|
||||
(*i)++;
|
||||
if (nptr[*i] == '-')
|
||||
{
|
||||
(*i)++;
|
||||
return (-1);
|
||||
}
|
||||
else if (nptr[*i] == '+')
|
||||
(*i)++;
|
||||
return (1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Converts string to integer
|
||||
*
|
||||
* @param nptr the string that will be converted
|
||||
* @return The integer on the string
|
||||
*/
|
||||
int ft_atoi(const char *nptr)
|
||||
{
|
||||
int i;
|
||||
int sign;
|
||||
int number;
|
||||
|
||||
i = 0;
|
||||
sign = ft_check_sign(nptr, &i);
|
||||
number = 0;
|
||||
while (nptr[i])
|
||||
{
|
||||
if (nptr[i] >= '0' && nptr[i] <= '9')
|
||||
number = (number * 10) + nptr[i] - '0';
|
||||
else
|
||||
break ;
|
||||
i++;
|
||||
}
|
||||
return (sign * number);
|
||||
}
|
||||
60
libft/convert/ft_atoll.c
Normal file
60
libft/convert/ft_atoll.c
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_atoll.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/31 15:12:07 by rparodi #+# #+# */
|
||||
/* Updated: 2024/10/31 15:14:50 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
static int ft_check_space(int c)
|
||||
{
|
||||
if (c == 32 || (c >= 9 && c <= 13))
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int ft_check_sign(const char *nptr, size_t *i)
|
||||
{
|
||||
while (ft_check_space(nptr[*i]))
|
||||
(*i)++;
|
||||
if (nptr[*i] == '-')
|
||||
{
|
||||
(*i)++;
|
||||
return (-1);
|
||||
}
|
||||
else if (nptr[*i] == '+')
|
||||
(*i)++;
|
||||
return (1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Converts string to long long integer
|
||||
*
|
||||
* @param nptr the string that will be converted
|
||||
* @return The long long int on the string
|
||||
*/
|
||||
long long int ft_atoll(const char *nptr)
|
||||
{
|
||||
size_t i;
|
||||
int sign;
|
||||
long long int number;
|
||||
|
||||
i = 0;
|
||||
sign = ft_check_sign(nptr, &i);
|
||||
number = 0;
|
||||
while (nptr[i])
|
||||
{
|
||||
if (nptr[i] >= '0' && nptr[i] <= '9')
|
||||
number = (number * 10) + nptr[i] - '0';
|
||||
else
|
||||
break ;
|
||||
i++;
|
||||
}
|
||||
return (sign * number);
|
||||
}
|
||||
58
libft/convert/ft_itoa.c
Normal file
58
libft/convert/ft_itoa.c
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_itoa.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/09 13:56:30 by rparodi #+# #+# */
|
||||
/* Updated: 2024/10/31 13:02:55 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
static size_t ft_check_sign(char *str, long *nb)
|
||||
{
|
||||
if ((*nb) == 0)
|
||||
str[0] = '0';
|
||||
if ((*nb) < 0)
|
||||
{
|
||||
str[0] = '-';
|
||||
*nb = -*nb;
|
||||
return (1);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Converts integer to string
|
||||
*
|
||||
* @param n the integer that will be converted
|
||||
* @return The string with this integer
|
||||
*/
|
||||
char *ft_itoa(int n)
|
||||
{
|
||||
size_t i;
|
||||
size_t modulus;
|
||||
short int maiboyerlpb;
|
||||
char str[13];
|
||||
long nb;
|
||||
|
||||
nb = n;
|
||||
maiboyerlpb = 0;
|
||||
modulus = 1000000000;
|
||||
ft_bzero(str, 13);
|
||||
i = ft_check_sign(str, &nb);
|
||||
while (modulus != 0)
|
||||
{
|
||||
if (nb / modulus != 0 || maiboyerlpb != 0)
|
||||
{
|
||||
str[i++] = (nb / modulus) + 48;
|
||||
maiboyerlpb++;
|
||||
}
|
||||
nb %= modulus;
|
||||
modulus /= 10;
|
||||
}
|
||||
return (ft_strdup(str));
|
||||
}
|
||||
31
libft/includes/libft/char.h
Normal file
31
libft/includes/libft/char.h
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* char.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/31 14:54:04 by rparodi #+# #+# */
|
||||
/* Updated: 2024/10/31 15:22:26 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef CHAR_H
|
||||
# define CHAR_H
|
||||
|
||||
# include <stdio.h>
|
||||
# include <string.h>
|
||||
# include <stdlib.h>
|
||||
# include <unistd.h>
|
||||
# include <limits.h>
|
||||
# include <fcntl.h>
|
||||
|
||||
int ft_isalnum(int c);
|
||||
int ft_isalpha(int c);
|
||||
int ft_isascii(int c);
|
||||
int ft_isdigit(int c);
|
||||
int ft_isprint(int c);
|
||||
int ft_tolower(int c);
|
||||
int ft_toupper(int c);
|
||||
|
||||
#endif
|
||||
27
libft/includes/libft/convert.h
Normal file
27
libft/includes/libft/convert.h
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* convert.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/31 14:57:24 by rparodi #+# #+# */
|
||||
/* Updated: 2024/10/31 15:27:40 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef CONVERT_H
|
||||
# define CONVERT_H
|
||||
|
||||
# include <stdio.h>
|
||||
# include <string.h>
|
||||
# include <stdlib.h>
|
||||
# include <unistd.h>
|
||||
# include <limits.h>
|
||||
# include <fcntl.h>
|
||||
|
||||
char *ft_itoa(int n);
|
||||
int ft_atoi(const char *nptr);
|
||||
long long int ft_atoll(const char *nptr);
|
||||
|
||||
#endif
|
||||
23
libft/includes/libft/libft.h
Normal file
23
libft/includes/libft/libft.h
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* libft.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/06 11:14:57 by rparodi #+# #+# */
|
||||
/* Updated: 2024/10/31 15:27:14 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef LIBFT_H
|
||||
# define LIBFT_H
|
||||
|
||||
# include "char.h"
|
||||
# include "convert.h"
|
||||
# include "list.h"
|
||||
# include "memory.h"
|
||||
# include "print.h"
|
||||
# include "str.h"
|
||||
|
||||
#endif
|
||||
39
libft/includes/libft/list.h
Normal file
39
libft/includes/libft/list.h
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* list.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/31 15:00:12 by rparodi #+# #+# */
|
||||
/* Updated: 2024/10/31 15:27:20 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef LIST_H
|
||||
# define LIST_H
|
||||
|
||||
# include <stdio.h>
|
||||
# include <string.h>
|
||||
# include <stdlib.h>
|
||||
# include <unistd.h>
|
||||
# include <limits.h>
|
||||
# include <fcntl.h>
|
||||
|
||||
typedef struct s_list
|
||||
{
|
||||
void *content;
|
||||
struct s_list *next;
|
||||
} t_list;
|
||||
|
||||
int ft_lstsize(t_list *lst);
|
||||
t_list *ft_lstlast(t_list *lst);
|
||||
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *));
|
||||
t_list *ft_lstnew(void *content);
|
||||
void ft_lstadd_back(t_list **lst, t_list *new);
|
||||
void ft_lstadd_front(t_list **lst, t_list *new);
|
||||
void ft_lstclear(t_list **lst, void (*del)(void *));
|
||||
void ft_lstdelone(t_list *lst, void (*del)(void *));
|
||||
void ft_lstiter(t_list *lst, void (*f)(void *));
|
||||
|
||||
#endif
|
||||
31
libft/includes/libft/memory.h
Normal file
31
libft/includes/libft/memory.h
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* memory.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/31 15:18:17 by rparodi #+# #+# */
|
||||
/* Updated: 2024/10/31 15:21:00 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef MEMORY_H
|
||||
# define MEMORY_H
|
||||
|
||||
# include <stdio.h>
|
||||
# include <string.h>
|
||||
# include <stdlib.h>
|
||||
# include <unistd.h>
|
||||
# include <limits.h>
|
||||
# include <fcntl.h>
|
||||
|
||||
int ft_memcmp(const void *s1, const void *s2, size_t n);
|
||||
void *ft_calloc(size_t nmemb, size_t size);
|
||||
void *ft_memchr(const void *s, int c, size_t n);
|
||||
void *ft_memcpy(void *dest, const void *src, size_t n);
|
||||
void *ft_memmove(void *dest, const void *src, size_t n);
|
||||
void *ft_memset(void *s, int c, size_t n);
|
||||
void ft_bzero(void *s, size_t n);
|
||||
|
||||
#endif
|
||||
31
libft/includes/libft/print.h
Normal file
31
libft/includes/libft/print.h
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* print.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/31 15:07:30 by rparodi #+# #+# */
|
||||
/* Updated: 2024/10/31 15:41:54 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef PRINT_H
|
||||
# define PRINT_H
|
||||
|
||||
# include <fcntl.h>
|
||||
# include <limits.h>
|
||||
# include <stdarg.h>
|
||||
# include <stdio.h>
|
||||
# include <stdlib.h>
|
||||
# include <string.h>
|
||||
# include <unistd.h>
|
||||
|
||||
int ft_dprintf(int fd, const char *s, ...);
|
||||
int ft_printf(const char *s, ...);
|
||||
void ft_putchar_fd(char c, int fd);
|
||||
void ft_putendl_fd(char *s, int fd);
|
||||
void ft_putnbr_fd(int n, int fd);
|
||||
void ft_putstr_fd(char *s, int fd);
|
||||
|
||||
#endif
|
||||
40
libft/includes/libft/str.h
Normal file
40
libft/includes/libft/str.h
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* str.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/31 15:04:59 by rparodi #+# #+# */
|
||||
/* Updated: 2024/10/31 17:06:53 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef STR_H
|
||||
# define STR_H
|
||||
|
||||
# include <stdio.h>
|
||||
# include <string.h>
|
||||
# include <stdlib.h>
|
||||
# include <unistd.h>
|
||||
# include <limits.h>
|
||||
# include <fcntl.h>
|
||||
|
||||
char **ft_split(char const *s, char c);
|
||||
char *ft_strchr(const char *s, int c);
|
||||
char *ft_strcpy(char *dst, const char *src);
|
||||
char *ft_strdup(const char *s);
|
||||
char *ft_strjoin(char const *s1, char const *s2);
|
||||
char *ft_strmapi(char const *s, char (*f)(unsigned int, char));
|
||||
char *ft_strnstr(const char *big, const char *little, size_t len);
|
||||
char *ft_strrchr(const char *s, int c);
|
||||
char *ft_strtrim(char const *s1, char const *set);
|
||||
char *ft_substr(char const *s, unsigned int start, size_t len);
|
||||
int ft_strcmp(const char *s1, const char *s2);
|
||||
int ft_strncmp(const char *s1, const char *s2, size_t n);
|
||||
size_t ft_strlcat(char *dst, const char *src, size_t size);
|
||||
size_t ft_strlcpy(char *dst, const char *src, size_t size);
|
||||
size_t ft_strlen(const char *s);
|
||||
void ft_striteri(char *s, void (*f)(unsigned int, char*));
|
||||
|
||||
#endif
|
||||
28
libft/list/ft_lstadd_back.c
Normal file
28
libft/list/ft_lstadd_back.c
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstadd_back.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/12 11:39:56 by rparodi #+# #+# */
|
||||
/* Updated: 2023/11/12 17:11:53 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_lstadd_back(t_list **lst, t_list *new)
|
||||
{
|
||||
t_list *tempo;
|
||||
|
||||
if (*lst == NULL)
|
||||
{
|
||||
*lst = new;
|
||||
return ;
|
||||
}
|
||||
tempo = *lst;
|
||||
while (tempo->next != NULL)
|
||||
tempo = tempo->next;
|
||||
tempo->next = new;
|
||||
}
|
||||
24
libft/list/ft_lstadd_front.c
Normal file
24
libft/list/ft_lstadd_front.c
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstadd_front.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/12 11:40:16 by rparodi #+# #+# */
|
||||
/* Updated: 2023/11/12 17:14:33 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_lstadd_front(t_list **lst, t_list *new)
|
||||
{
|
||||
if (*lst == NULL)
|
||||
{
|
||||
*lst = new;
|
||||
return ;
|
||||
}
|
||||
new->next = *lst;
|
||||
*lst = new;
|
||||
}
|
||||
25
libft/list/ft_lstclear.c
Normal file
25
libft/list/ft_lstclear.c
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstclear.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/12 11:40:37 by rparodi #+# #+# */
|
||||
/* Updated: 2023/11/12 19:34:19 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_lstclear(t_list **lst, void (*del)(void *))
|
||||
{
|
||||
t_list *tempo;
|
||||
|
||||
while (*lst)
|
||||
{
|
||||
tempo = (*lst)->next;
|
||||
ft_lstdelone(*lst, del);
|
||||
(*lst) = tempo;
|
||||
}
|
||||
}
|
||||
19
libft/list/ft_lstdelone.c
Normal file
19
libft/list/ft_lstdelone.c
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstdelone.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/12 11:42:11 by rparodi #+# #+# */
|
||||
/* Updated: 2023/11/12 18:10:40 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_lstdelone(t_list *lst, void (*del)(void *))
|
||||
{
|
||||
del(lst->content);
|
||||
free(lst);
|
||||
}
|
||||
22
libft/list/ft_lstiter.c
Normal file
22
libft/list/ft_lstiter.c
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstiter.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/12 11:42:24 by rparodi #+# #+# */
|
||||
/* Updated: 2023/11/12 18:07:02 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_lstiter(t_list *lst, void (*f)(void *))
|
||||
{
|
||||
while (lst != NULL)
|
||||
{
|
||||
f(lst->content);
|
||||
lst = lst->next;
|
||||
}
|
||||
}
|
||||
22
libft/list/ft_lstlast.c
Normal file
22
libft/list/ft_lstlast.c
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstlast.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/12 11:42:54 by rparodi #+# #+# */
|
||||
/* Updated: 2023/11/12 17:25:48 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
t_list *ft_lstlast(t_list *lst)
|
||||
{
|
||||
if (lst == NULL)
|
||||
return (lst);
|
||||
while (lst->next != NULL)
|
||||
lst = lst->next;
|
||||
return (lst);
|
||||
}
|
||||
37
libft/list/ft_lstmap.c
Normal file
37
libft/list/ft_lstmap.c
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstmap.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/12 11:43:28 by rparodi #+# #+# */
|
||||
/* Updated: 2023/11/12 19:28:02 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *))
|
||||
{
|
||||
t_list *tempo;
|
||||
t_list *tempo_content;
|
||||
|
||||
tempo_content = ft_lstnew(f(lst->content));
|
||||
if (!tempo_content)
|
||||
return (NULL);
|
||||
tempo = tempo_content;
|
||||
lst = lst->next;
|
||||
while (lst)
|
||||
{
|
||||
tempo_content = ft_lstnew(f(lst->content));
|
||||
if (!tempo_content)
|
||||
{
|
||||
ft_lstclear(&tempo, del);
|
||||
return (NULL);
|
||||
}
|
||||
ft_lstadd_back(&tempo, tempo_content);
|
||||
lst = lst->next;
|
||||
}
|
||||
return (tempo);
|
||||
}
|
||||
26
libft/list/ft_lstnew.c
Normal file
26
libft/list/ft_lstnew.c
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstnew.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/12 11:44:02 by rparodi #+# #+# */
|
||||
/* Updated: 2023/11/12 14:25:12 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
t_list *ft_lstnew(void *content)
|
||||
{
|
||||
t_list *to_return;
|
||||
|
||||
to_return = NULL;
|
||||
to_return = (t_list *)malloc(sizeof(t_list));
|
||||
if (!to_return)
|
||||
return (NULL);
|
||||
to_return->content = content;
|
||||
to_return->next = NULL;
|
||||
return (to_return);
|
||||
}
|
||||
26
libft/list/ft_lstsize.c
Normal file
26
libft/list/ft_lstsize.c
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstsize.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/12 11:44:24 by rparodi #+# #+# */
|
||||
/* Updated: 2023/11/13 12:22:02 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_lstsize(t_list *lst)
|
||||
{
|
||||
int count;
|
||||
|
||||
count = 0;
|
||||
while (lst != NULL)
|
||||
{
|
||||
lst = lst->next;
|
||||
count++;
|
||||
}
|
||||
return (count);
|
||||
}
|
||||
18
libft/memory/ft_bzero.c
Normal file
18
libft/memory/ft_bzero.c
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_bzero.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/07 16:43:13 by rparodi #+# #+# */
|
||||
/* Updated: 2023/11/07 17:25:28 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_bzero(void *s, size_t n)
|
||||
{
|
||||
ft_memset(s, 0, n);
|
||||
}
|
||||
31
libft/memory/ft_calloc.c
Normal file
31
libft/memory/ft_calloc.c
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_calloc.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/07 16:47:17 by rparodi #+# #+# */
|
||||
/* Updated: 2023/11/13 14:47:17 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void *ft_calloc(size_t nmemb, size_t size)
|
||||
{
|
||||
size_t total;
|
||||
char *to_return;
|
||||
|
||||
if (nmemb == 0 || size == 0)
|
||||
return ((void *)malloc(1));
|
||||
total = nmemb * size;
|
||||
if (total / nmemb != size && total / size != nmemb)
|
||||
return (NULL);
|
||||
to_return = (char *)malloc(total);
|
||||
if (to_return == NULL)
|
||||
to_return = NULL;
|
||||
else
|
||||
ft_bzero(to_return, total);
|
||||
return (to_return);
|
||||
}
|
||||
29
libft/memory/ft_memchr.c
Normal file
29
libft/memory/ft_memchr.c
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memchr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/07 16:48:30 by rparodi #+# #+# */
|
||||
/* Updated: 2023/11/07 18:45:57 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void *ft_memchr(const void *s, int c, size_t n)
|
||||
{
|
||||
size_t i;
|
||||
char *str;
|
||||
|
||||
i = 0;
|
||||
str = (char *)s;
|
||||
while (i < n)
|
||||
{
|
||||
if ((char)c == str[i])
|
||||
return ((void *)str + i);
|
||||
i++;
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
31
libft/memory/ft_memcmp.c
Normal file
31
libft/memory/ft_memcmp.c
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memcmp.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/07 16:49:04 by rparodi #+# #+# */
|
||||
/* Updated: 2023/11/07 18:46:15 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_memcmp(const void *s1, const void *s2, size_t n)
|
||||
{
|
||||
size_t i;
|
||||
unsigned char *str1;
|
||||
unsigned char *str2;
|
||||
|
||||
i = 0;
|
||||
str1 = (unsigned char *)s1;
|
||||
str2 = (unsigned char *)s2;
|
||||
while (i < n)
|
||||
{
|
||||
if (str1[i] != str2[i])
|
||||
return (str1[i] - str2[i]);
|
||||
i++;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
32
libft/memory/ft_memcpy.c
Normal file
32
libft/memory/ft_memcpy.c
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memcpy.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/07 16:49:46 by rparodi #+# #+# */
|
||||
/* Updated: 2023/11/13 19:14:23 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void *ft_memcpy(void *dest, const void *src, size_t n)
|
||||
{
|
||||
char *d;
|
||||
const char *s;
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
if (!dest && !src)
|
||||
return (NULL);
|
||||
d = (char *)dest;
|
||||
s = (char *)src;
|
||||
while (i < n)
|
||||
{
|
||||
d[i] = s[i];
|
||||
i++;
|
||||
}
|
||||
return ((void *)d);
|
||||
}
|
||||
51
libft/memory/ft_memmove.c
Normal file
51
libft/memory/ft_memmove.c
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memmove.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/07 16:51:35 by rparodi #+# #+# */
|
||||
/* Updated: 2023/11/13 19:55:40 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_checks(char *s, char *d, size_t n)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
if (d < s)
|
||||
{
|
||||
while (i < n)
|
||||
{
|
||||
d[i] = s[i];
|
||||
i++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
i = n;
|
||||
while (i > 0)
|
||||
{
|
||||
i--;
|
||||
d[i] = s[i];
|
||||
}
|
||||
}
|
||||
return (d);
|
||||
}
|
||||
|
||||
void *ft_memmove(void *dest, const void *src, size_t n)
|
||||
{
|
||||
char *d;
|
||||
char *s;
|
||||
|
||||
if (!dest && !src)
|
||||
return (NULL);
|
||||
d = (char *)dest;
|
||||
s = (char *)src;
|
||||
ft_checks(s, d, n);
|
||||
return (dest);
|
||||
}
|
||||
28
libft/memory/ft_memset.c
Normal file
28
libft/memory/ft_memset.c
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memset.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/07 16:50:29 by rparodi #+# #+# */
|
||||
/* Updated: 2023/11/07 18:58:02 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void *ft_memset(void *s, int c, size_t n)
|
||||
{
|
||||
char *str;
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
str = (char *)s;
|
||||
while (i < n)
|
||||
{
|
||||
str[i] = c;
|
||||
i++;
|
||||
}
|
||||
return (str);
|
||||
}
|
||||
96
libft/print/ft_printf.c
Normal file
96
libft/print/ft_printf.c
Normal file
|
|
@ -0,0 +1,96 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_printf.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/14 17:27:44 by rparodi #+# #+# */
|
||||
/* Updated: 2024/10/31 16:12:37 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void _print_char(int fd, char c, int *ret_value);
|
||||
void _print_nbr(int fd, int nb, int *ret_value);
|
||||
void _print_base(\
|
||||
int fd, unsigned long long nbr, int *ret_value, char c);
|
||||
void _print_unsigned(int fd, unsigned int nb, int *ret_value);
|
||||
void _print_str(int fd, char *str, int *ret_value);
|
||||
|
||||
int _check_args(int fd, char c, va_list args, int *ret_value)
|
||||
{
|
||||
if (c == 'c')
|
||||
_print_char(fd, (char)va_arg(args, int), ret_value);
|
||||
else if (c == 's')
|
||||
_print_str(fd, (char *)va_arg(args, char *), ret_value);
|
||||
else if (c == 'i' || c == 'd')
|
||||
_print_nbr(fd, (int)va_arg(args, int), ret_value);
|
||||
else if (c == '%')
|
||||
_print_char(fd, '%', ret_value);
|
||||
else if (c == 'u')
|
||||
_print_unsigned(\
|
||||
fd, (unsigned int)va_arg(args, unsigned int), ret_value);
|
||||
else if (c == 'x')
|
||||
_print_base(fd, (unsigned int)va_arg(args, unsigned int), ret_value, c);
|
||||
else if (c == 'X')
|
||||
_print_base(fd, (unsigned int)va_arg(args, unsigned int), ret_value, c);
|
||||
else if (c == 'p')
|
||||
_print_base(fd, (unsigned long long)va_arg(args, unsigned long long), \
|
||||
ret_value, c);
|
||||
va_end(args);
|
||||
return (1);
|
||||
}
|
||||
|
||||
int ft_dprintf(int fd, const char *s, ...)
|
||||
{
|
||||
size_t i;
|
||||
va_list args;
|
||||
char *str;
|
||||
int ret_value;
|
||||
|
||||
ret_value = 0;
|
||||
str = ft_strdup(s);
|
||||
va_start(args, s);
|
||||
i = 0;
|
||||
while (str[i])
|
||||
{
|
||||
if (str[i] == '%')
|
||||
{
|
||||
_check_args(fd, str[i + 1], args, &ret_value);
|
||||
i++;
|
||||
}
|
||||
else
|
||||
_print_char(fd, str[i], &ret_value);
|
||||
i++;
|
||||
}
|
||||
free(str);
|
||||
return (ret_value);
|
||||
}
|
||||
|
||||
int ft_printf(const char *s, ...)
|
||||
{
|
||||
size_t i;
|
||||
va_list args;
|
||||
char *str;
|
||||
int ret_value;
|
||||
|
||||
ret_value = 0;
|
||||
str = ft_strdup(s);
|
||||
va_start(args, s);
|
||||
i = 0;
|
||||
while (str[i])
|
||||
{
|
||||
if (str[i] == '%')
|
||||
{
|
||||
_check_args(1, str[i + 1], args, &ret_value);
|
||||
i++;
|
||||
}
|
||||
else
|
||||
_print_char(1, str[i], &ret_value);
|
||||
i++;
|
||||
}
|
||||
free(str);
|
||||
return (ret_value);
|
||||
}
|
||||
97
libft/print/ft_put.c
Normal file
97
libft/print/ft_put.c
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_put.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/16 12:13:14 by rparodi #+# #+# */
|
||||
/* Updated: 2024/10/31 16:16:45 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void _print_char(int fd, char c, int *ret_value);
|
||||
void _print_nbr(int fd, int nb, int *ret_value);
|
||||
void _print_base(\
|
||||
int fd, unsigned long long nbr, int *ret_value, char c);
|
||||
void _print_unsigned(int fd, unsigned int nb, int *ret_value);
|
||||
void _print_str(int fd, char *str, int *ret_value);
|
||||
|
||||
void _print_char(int fd, char c, int *ret_value)
|
||||
{
|
||||
write(fd, &c, 1);
|
||||
(*ret_value)++;
|
||||
}
|
||||
|
||||
void _print_nbr(int fd, int nb, int *ret_value)
|
||||
{
|
||||
if (nb < 0)
|
||||
{
|
||||
if (nb == INT_MIN)
|
||||
{
|
||||
write(1, "-2147483648", 11);
|
||||
*ret_value += 11;
|
||||
return ;
|
||||
}
|
||||
nb = -nb;
|
||||
_print_char(fd, '-', ret_value);
|
||||
}
|
||||
if (nb >= 10)
|
||||
{
|
||||
_print_nbr(fd, nb / 10, ret_value);
|
||||
nb = nb % 10;
|
||||
}
|
||||
if (nb < 10)
|
||||
_print_char(fd, nb + 48, ret_value);
|
||||
}
|
||||
|
||||
void _print_base(\
|
||||
int fd, unsigned long long nbr, int *ret_value, char c)
|
||||
{
|
||||
char base[16];
|
||||
|
||||
if (c == 'x' || c == 'q')
|
||||
ft_strcpy(base, "0123456789abcdef");
|
||||
else if (c == 'X')
|
||||
ft_strcpy(base, "0123456789ABCDEF");
|
||||
else if (c == 'p')
|
||||
{
|
||||
if (nbr != 0)
|
||||
_print_str(fd, "0x", ret_value);
|
||||
else if (nbr == 0)
|
||||
{
|
||||
_print_str(fd, "(nil)", ret_value);
|
||||
return ;
|
||||
}
|
||||
else
|
||||
ft_strcpy(base, "0123456789abcdef");
|
||||
c++;
|
||||
}
|
||||
if (c != 'p')
|
||||
{
|
||||
if (nbr >= 16)
|
||||
_print_base(fd, nbr / 16, ret_value, c);
|
||||
_print_char(fd, base[nbr % 16], ret_value);
|
||||
}
|
||||
}
|
||||
|
||||
void _print_unsigned(int fd, unsigned int nb, int *ret_value)
|
||||
{
|
||||
if (nb >= 10)
|
||||
{
|
||||
_print_unsigned(fd, nb / 10, ret_value);
|
||||
nb = nb % 10;
|
||||
}
|
||||
if (nb < 10)
|
||||
_print_char(fd, nb + 48, ret_value);
|
||||
}
|
||||
|
||||
void _print_str(int fd, char *str, int *ret_value)
|
||||
{
|
||||
if (!str)
|
||||
*ret_value += write(fd, "(null)", 6);
|
||||
else
|
||||
*ret_value += write(fd, str, ft_strlen(str));
|
||||
}
|
||||
18
libft/print/ft_putchar_fd.c
Normal file
18
libft/print/ft_putchar_fd.c
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putchar_fd.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/09 13:58:22 by rparodi #+# #+# */
|
||||
/* Updated: 2023/11/10 15:31:57 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_putchar_fd(char c, int fd)
|
||||
{
|
||||
write(fd, &c, 1);
|
||||
}
|
||||
19
libft/print/ft_putendl_fd.c
Normal file
19
libft/print/ft_putendl_fd.c
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putendl_fd.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/09 13:59:01 by rparodi #+# #+# */
|
||||
/* Updated: 2023/11/10 15:57:53 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_putendl_fd(char *s, int fd)
|
||||
{
|
||||
ft_putstr_fd(s, fd);
|
||||
ft_putchar_fd('\n', fd);
|
||||
}
|
||||
55
libft/print/ft_putnbr_fd.c
Normal file
55
libft/print/ft_putnbr_fd.c
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putnbr_fd.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/09 13:59:18 by rparodi #+# #+# */
|
||||
/* Updated: 2023/11/13 20:13:20 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
static int ft_check_sign(int n, char *str, size_t *i, int fd)
|
||||
{
|
||||
size_t modulus;
|
||||
short int maiboyerlpb;
|
||||
|
||||
maiboyerlpb = 0;
|
||||
modulus = 1000000000;
|
||||
if (n < 0)
|
||||
{
|
||||
n = -n;
|
||||
str[(*i)] = '-';
|
||||
(*i)++;
|
||||
}
|
||||
while (modulus != 0)
|
||||
{
|
||||
if (n / modulus != 0 || maiboyerlpb != 0)
|
||||
{
|
||||
str[(*i)++] = (n / modulus) + 48;
|
||||
maiboyerlpb++;
|
||||
}
|
||||
n %= modulus;
|
||||
modulus /= 10;
|
||||
}
|
||||
ft_putstr_fd(str, fd);
|
||||
return (n);
|
||||
}
|
||||
|
||||
void ft_putnbr_fd(int n, int fd)
|
||||
{
|
||||
size_t i;
|
||||
char str[13];
|
||||
|
||||
i = 0;
|
||||
ft_bzero(str, 13);
|
||||
if (n == 0)
|
||||
ft_putstr_fd("0", fd);
|
||||
else if (n == -2147483648)
|
||||
ft_putstr_fd("-2147483648", fd);
|
||||
else
|
||||
ft_check_sign(n, str, &i, fd);
|
||||
}
|
||||
18
libft/print/ft_putstr_fd.c
Normal file
18
libft/print/ft_putstr_fd.c
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putstr_fd.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/09 13:58:46 by rparodi #+# #+# */
|
||||
/* Updated: 2023/11/10 15:57:46 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_putstr_fd(char *s, int fd)
|
||||
{
|
||||
write(fd, s, ft_strlen(s));
|
||||
}
|
||||
93
libft/str/ft_split.c
Normal file
93
libft/str/ft_split.c
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_split.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/09 13:56:02 by rparodi #+# #+# */
|
||||
/* Updated: 2023/11/13 12:14:57 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
static int count_words(const char *str, char sep)
|
||||
{
|
||||
int i;
|
||||
int count;
|
||||
|
||||
i = 0;
|
||||
count = 0;
|
||||
while (str[i])
|
||||
{
|
||||
while (str[i] == sep && str[i])
|
||||
i++;
|
||||
if (str[i] != sep && str[i])
|
||||
{
|
||||
while (str[i] != sep && str[i])
|
||||
i++;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return (count);
|
||||
}
|
||||
|
||||
static char *ft_strndup(const char *s, int j)
|
||||
{
|
||||
int i;
|
||||
char *str;
|
||||
|
||||
i = 0;
|
||||
str = (char *)malloc((j + 1));
|
||||
if (!str)
|
||||
return (NULL);
|
||||
while (s[i] && i < j)
|
||||
{
|
||||
str[i] = s[i];
|
||||
i++;
|
||||
}
|
||||
str[i] = '\0';
|
||||
return (str);
|
||||
}
|
||||
|
||||
static char **ext_w(char **words_array, const char *str, char sep, int size)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
|
||||
i = 0;
|
||||
j = 0;
|
||||
while (j < size)
|
||||
{
|
||||
while (str[i] == sep && str[i])
|
||||
i++;
|
||||
str = str + i;
|
||||
i = 0;
|
||||
while (str[i] != sep && str[i])
|
||||
i++;
|
||||
words_array[j++] = ft_strndup(str, i);
|
||||
str = str + i;
|
||||
i = 0;
|
||||
}
|
||||
words_array[j] = 0;
|
||||
return (words_array);
|
||||
}
|
||||
|
||||
char **ft_split(char const *s, char c)
|
||||
{
|
||||
int size;
|
||||
char **words_array;
|
||||
|
||||
size = count_words(s, c);
|
||||
words_array = (char **)malloc(sizeof(char *) * (size + 1));
|
||||
if (!words_array)
|
||||
return (NULL);
|
||||
if (size == 0)
|
||||
{
|
||||
words_array[0] = NULL;
|
||||
return (words_array);
|
||||
}
|
||||
words_array = ext_w(words_array, s, c, size);
|
||||
return (words_array);
|
||||
}
|
||||
29
libft/str/ft_strchr.c
Normal file
29
libft/str/ft_strchr.c
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strchr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/07 16:32:19 by rparodi #+# #+# */
|
||||
/* Updated: 2023/11/09 12:08:01 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strchr(const char *s, int c)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
i = 0;
|
||||
if (c == 0)
|
||||
return ((char *)s + ft_strlen(s));
|
||||
while (s[i] != '\0')
|
||||
{
|
||||
if (s[i] == (char)c)
|
||||
return ((char *)s + i);
|
||||
i++;
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
31
libft/str/ft_strcmp.c
Normal file
31
libft/str/ft_strcmp.c
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* strcmp.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/07 16:56:56 by rparodi #+# #+# */
|
||||
/* Updated: 2024/10/31 17:05:03 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_strcmp(const char *s1, const char *s2)
|
||||
{
|
||||
size_t i;
|
||||
int diff;
|
||||
|
||||
i = 0;
|
||||
while ((s1[i] || s2[i]))
|
||||
{
|
||||
if (s1[i] != s2[i])
|
||||
{
|
||||
diff = (unsigned char)s1[i] - (unsigned char)s2[i];
|
||||
return (diff);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
27
libft/str/ft_strcpy.c
Normal file
27
libft/str/ft_strcpy.c
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strcpy.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/31 16:14:10 by rparodi #+# #+# */
|
||||
/* Updated: 2024/10/31 16:15:46 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strcpy(char *dst, const char *src)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
while (src[i])
|
||||
{
|
||||
dst[i] = src[i];
|
||||
i++;
|
||||
}
|
||||
dst[i] = '\0';
|
||||
return (dst);
|
||||
}
|
||||
26
libft/str/ft_strdup.c
Normal file
26
libft/str/ft_strdup.c
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strdup.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/07 16:53:59 by rparodi #+# #+# */
|
||||
/* Updated: 2023/11/13 20:02:09 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strdup(const char *s)
|
||||
{
|
||||
size_t len;
|
||||
char *to_return;
|
||||
|
||||
len = ft_strlen(s) + 1;
|
||||
to_return = (char *)malloc(sizeof(char) * len);
|
||||
if (!to_return)
|
||||
return (NULL);
|
||||
ft_strlcpy(to_return, s, len);
|
||||
return (to_return);
|
||||
}
|
||||
25
libft/str/ft_striteri.c
Normal file
25
libft/str/ft_striteri.c
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_striteri.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/09 13:57:34 by rparodi #+# #+# */
|
||||
/* Updated: 2023/11/11 17:26:00 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_striteri(char *s, void (*f)(unsigned int, char*))
|
||||
{
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
while (s[i] != '\0')
|
||||
{
|
||||
f(i, s + i);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
39
libft/str/ft_strjoin.c
Normal file
39
libft/str/ft_strjoin.c
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strjoin.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/09 13:55:15 by rparodi #+# #+# */
|
||||
/* Updated: 2023/11/09 17:47:46 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strjoin(char const *s1, char const *s2)
|
||||
{
|
||||
size_t i;
|
||||
size_t save_i;
|
||||
char *str;
|
||||
|
||||
i = 0;
|
||||
str = (char *)malloc((ft_strlen(s1) + ft_strlen(s2)) + 1);
|
||||
if (!str)
|
||||
return (NULL);
|
||||
while (s1[i] != '\0')
|
||||
{
|
||||
str[i] = s1[i];
|
||||
i++;
|
||||
}
|
||||
save_i = i;
|
||||
i = 0;
|
||||
while (s2[i] != '\0')
|
||||
{
|
||||
str[save_i + i] = s2[i];
|
||||
i++;
|
||||
}
|
||||
str[i + save_i] = '\0';
|
||||
return (str);
|
||||
}
|
||||
49
libft/str/ft_strlcat.c
Normal file
49
libft/str/ft_strlcat.c
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strlcat.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/08 22:28:26 by rparodi #+# #+# */
|
||||
/* Updated: 2023/11/12 11:45:52 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
static size_t ft_strnlen(char *dest, size_t size)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
while (i < size && dest[i] != '\0')
|
||||
i++;
|
||||
return (i);
|
||||
}
|
||||
|
||||
size_t ft_strlcat(char *dest, const char *src, size_t size)
|
||||
{
|
||||
size_t i;
|
||||
size_t j;
|
||||
size_t destlen;
|
||||
|
||||
i = 0;
|
||||
j = 0;
|
||||
destlen = ft_strnlen(dest, size);
|
||||
while (i < size && dest[i])
|
||||
i++;
|
||||
if (i == size)
|
||||
return (i + ft_strlen(src));
|
||||
while (src[j])
|
||||
{
|
||||
if (j < size - destlen - 1)
|
||||
{
|
||||
dest[i] = src[j];
|
||||
i++;
|
||||
}
|
||||
j++;
|
||||
}
|
||||
dest[i] = '\0';
|
||||
return (destlen + j);
|
||||
}
|
||||
31
libft/str/ft_strlcpy.c
Normal file
31
libft/str/ft_strlcpy.c
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strlcpy.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/07 16:55:25 by rparodi #+# #+# */
|
||||
/* Updated: 2023/11/13 19:16:30 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
size_t ft_strlcpy(char *dst, const char *src, size_t size)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
while (src[i] && i + 1 < size)
|
||||
{
|
||||
dst[i] = src[i];
|
||||
i++;
|
||||
}
|
||||
if (size > 0)
|
||||
{
|
||||
dst[i] = '\0';
|
||||
i++;
|
||||
}
|
||||
return (ft_strlen(src));
|
||||
}
|
||||
23
libft/str/ft_strlen.c
Normal file
23
libft/str/ft_strlen.c
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strlen.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/07 16:56:24 by rparodi #+# #+# */
|
||||
/* Updated: 2023/11/08 12:37:09 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
size_t ft_strlen(const char *s)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
while (s[i] != '\0')
|
||||
i++;
|
||||
return (i);
|
||||
}
|
||||
34
libft/str/ft_strmapi.c
Normal file
34
libft/str/ft_strmapi.c
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strmapi.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/09 13:56:57 by rparodi #+# #+# */
|
||||
/* Updated: 2023/11/13 19:49:30 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
|
||||
{
|
||||
size_t i;
|
||||
size_t len;
|
||||
char *str;
|
||||
|
||||
i = 0;
|
||||
len = ft_strlen(s);
|
||||
str = (char *)malloc(len + 1);
|
||||
if (!str)
|
||||
return (NULL);
|
||||
else
|
||||
ft_bzero((char *)str, len + 1);
|
||||
while (i < len)
|
||||
{
|
||||
str[i] = f(i, s[i]);
|
||||
i++;
|
||||
}
|
||||
return (str);
|
||||
}
|
||||
31
libft/str/ft_strncmp.c
Normal file
31
libft/str/ft_strncmp.c
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strncmp.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/07 16:56:56 by rparodi #+# #+# */
|
||||
/* Updated: 2023/11/09 13:16:39 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_strncmp(const char *s1, const char *s2, size_t n)
|
||||
{
|
||||
size_t i;
|
||||
int diff;
|
||||
|
||||
i = 0;
|
||||
while ((s1[i] || s2[i]) && i < n)
|
||||
{
|
||||
if (s1[i] != s2[i])
|
||||
{
|
||||
diff = (unsigned char)s1[i] - (unsigned char)s2[i];
|
||||
return (diff);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
37
libft/str/ft_strnstr.c
Normal file
37
libft/str/ft_strnstr.c
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strnstr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/07 16:57:44 by rparodi #+# #+# */
|
||||
/* Updated: 2023/11/13 19:17:49 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strnstr(const char *big, const char *little, size_t len)
|
||||
{
|
||||
size_t i;
|
||||
size_t j;
|
||||
|
||||
i = 0;
|
||||
if (len == 0 && (!big || !little))
|
||||
return (NULL);
|
||||
if (!little[i])
|
||||
return ((char *)big);
|
||||
while (big[i] && i < len)
|
||||
{
|
||||
j = 0;
|
||||
while (i + j < len && little[j] == big[i + j])
|
||||
{
|
||||
j++;
|
||||
if (little[j] == '\0')
|
||||
return ((char *)(big + i));
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
29
libft/str/ft_strrchr.c
Normal file
29
libft/str/ft_strrchr.c
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strrchr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/07 16:58:22 by rparodi #+# #+# */
|
||||
/* Updated: 2023/11/11 18:46:54 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strrchr(const char *s, int c)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
i = ft_strlen(s);
|
||||
while (i > 0)
|
||||
{
|
||||
if (s[i] == c % 256)
|
||||
return ((char *)s + i);
|
||||
i--;
|
||||
}
|
||||
if (s[i] == c % 256)
|
||||
return ((char *)s + i);
|
||||
return (NULL);
|
||||
}
|
||||
40
libft/str/ft_strtrim.c
Normal file
40
libft/str/ft_strtrim.c
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strtrim.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/09 13:55:44 by rparodi #+# #+# */
|
||||
/* Updated: 2023/11/13 20:08:51 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strtrim(char const *s1, char const *set)
|
||||
{
|
||||
size_t i;
|
||||
size_t j;
|
||||
size_t k;
|
||||
char *str;
|
||||
|
||||
if (!s1)
|
||||
return (NULL);
|
||||
i = 0;
|
||||
while (ft_strchr(set, s1[i]) != NULL && s1[i])
|
||||
i++;
|
||||
if (i == ft_strlen(s1))
|
||||
return (ft_strdup(""));
|
||||
j = ft_strlen(s1);
|
||||
while (ft_strrchr(set, s1[j - 1]) != NULL && j > i)
|
||||
j--;
|
||||
str = (char *)malloc(j - i + 1);
|
||||
if (!str)
|
||||
return (NULL);
|
||||
k = 0;
|
||||
while (i < j)
|
||||
str[k++] = s1[i++];
|
||||
str[k] = '\0';
|
||||
return (str);
|
||||
}
|
||||
28
libft/str/ft_substr.c
Normal file
28
libft/str/ft_substr.c
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_substr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/09 13:54:42 by rparodi #+# #+# */
|
||||
/* Updated: 2023/11/13 20:08:02 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_substr(char const *s, unsigned int start, size_t len)
|
||||
{
|
||||
char *str;
|
||||
|
||||
if (start >= ft_strlen(s))
|
||||
return (ft_strdup(""));
|
||||
if (len + start > (ft_strlen(s)))
|
||||
len = ft_strlen(s) - start;
|
||||
str = (char *)malloc(len + 1);
|
||||
if (!str || !s)
|
||||
return (free(str), ft_strdup(""));
|
||||
ft_strlcpy(str, s + start, len + 1);
|
||||
return (str);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue