mirror of
https://github.com/KeyZox71/ft_minipowershell.git
synced 2025-03-15 03:16:51 +01:00
「✨」 feat(libft): added a very cool feature !
This commit is contained in:
102
libft/Makefile
Normal file
102
libft/Makefile
Normal file
@ -0,0 +1,102 @@
|
||||
# **************************************************************************** #
|
||||
# #
|
||||
# ::: :::::::: #
|
||||
# Makefile :+: :+: :+: #
|
||||
# +:+ +:+ +:+ #
|
||||
# By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2023/11/01 11:03:22 by adjoly #+# #+# #
|
||||
# Updated: 2024/03/18 14:33:40 by adjoly ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
NAME = libft.a
|
||||
|
||||
CC = cc
|
||||
|
||||
OBJSDIR = obj/
|
||||
|
||||
SRCS = is/ft_isalnum.c \
|
||||
is/ft_isalpha.c \
|
||||
is/ft_isascii.c \
|
||||
is/ft_isdigit.c \
|
||||
is/ft_isprint.c \
|
||||
lst/ft_lstadd_back.c \
|
||||
lst/ft_lstadd_front.c \
|
||||
lst/ft_lstclear.c \
|
||||
lst/ft_lstdelone.c \
|
||||
lst/ft_lstiter.c \
|
||||
lst/ft_lstlast.c \
|
||||
lst/ft_lstmap.c \
|
||||
lst/ft_lstnew.c \
|
||||
lst/ft_lstsize.c \
|
||||
mem/ft_bzero.c \
|
||||
mem/ft_calloc.c \
|
||||
mem/ft_memchr.c \
|
||||
mem/ft_memcmp.c \
|
||||
mem/ft_memcpy.c \
|
||||
mem/ft_memmove.c \
|
||||
mem/ft_memset.c \
|
||||
print/ft_putchar.c \
|
||||
print/ft_putchar_fd.c \
|
||||
print/ft_putendl_fd.c \
|
||||
print/ft_putnbrbase.c \
|
||||
print/ft_putnbrbase_fd.c \
|
||||
print/ft_putnbr.c \
|
||||
print/ft_putnbr_fd.c \
|
||||
print/ft_putstr.c \
|
||||
print/ft_putstr_fd.c \
|
||||
str/ft_atoi.c \
|
||||
str/ft_atoll.c \
|
||||
str/ft_itoa.c \
|
||||
str/ft_split.c \
|
||||
str/ft_strchr.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 \
|
||||
str/ft_tolower.c \
|
||||
str/ft_toupper.c \
|
||||
print/printf/ft_printf.c \
|
||||
print/printf/ft_putchar.c \
|
||||
print/printf/ft_putnbrbase.c \
|
||||
print/printf/ft_putnbr.c \
|
||||
print/printf/ft_putstr.c \
|
||||
|
||||
OBJS = $(addprefix $(OBJSDIR),$(SRCS:.c=.o))
|
||||
|
||||
FLAGS = -Werror -Wall -Wextra -g
|
||||
|
||||
LIB = io/get_next_line/get_next_line.a
|
||||
|
||||
$(NAME): $(OBJS)
|
||||
@make -s -C io/get_next_line/
|
||||
@ar -rcs $(NAME) $(OBJS) $(LIB)
|
||||
@echo "[✔] Libft compiled"
|
||||
|
||||
$(OBJSDIR)%.o: %.c
|
||||
@mkdir -p $(@D)
|
||||
@$(CC) $(FLAGS) $< -c -o $@
|
||||
|
||||
all: $(NAME)
|
||||
|
||||
clean:
|
||||
@make -s -C io/get_next_line/ clean
|
||||
@rm -f $(OBJS)
|
||||
|
||||
fclean: clean
|
||||
@make -s -C io/get_next_line/ fclean
|
||||
@rm -f $(NAME)
|
||||
@echo "[X] Libft cleaned"
|
||||
|
||||
re: fclean all
|
||||
|
||||
.PHONY: clean all re fclean
|
44
libft/io/get_next_line/Makefile
Normal file
44
libft/io/get_next_line/Makefile
Normal file
@ -0,0 +1,44 @@
|
||||
# **************************************************************************** #
|
||||
# #
|
||||
# ::: :::::::: #
|
||||
# Makefile :+: :+: :+: #
|
||||
# +:+ +:+ +:+ #
|
||||
# By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2023/11/01 11:03:22 by adjoly #+# #+# #
|
||||
# Updated: 2024/03/04 13:30:36 by adjoly ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
NAME = get_next_line.a
|
||||
|
||||
CC = clang
|
||||
|
||||
SRCS = get_next_line.c \
|
||||
get_next_line_utils.c \
|
||||
../../mem/ft_calloc.c \
|
||||
../../str/ft_strlen.c \
|
||||
|
||||
OBJS = $(SRCS:.c=.o)
|
||||
|
||||
FLAGS = -Werror -Wall -Wextra
|
||||
|
||||
HEADER = get_next_line.h
|
||||
|
||||
$(NAME): $(OBJS)
|
||||
@ar -rcs $(NAME) $(OBJS)
|
||||
|
||||
%.o: %.c
|
||||
@$(CC) $(FLAGS) -I $(HEADER) $< -c -o $@
|
||||
|
||||
all: $(NAME)
|
||||
|
||||
clean:
|
||||
@rm -f $(OBJS)
|
||||
|
||||
fclean: clean
|
||||
@rm -f $(NAME)
|
||||
|
||||
re: fclean all
|
||||
|
||||
.PHONY: clean all re fclean
|
74
libft/io/get_next_line/get_next_line.c
Normal file
74
libft/io/get_next_line/get_next_line.c
Normal file
@ -0,0 +1,74 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* get_next_line.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/12/01 17:11:59 by adjoly #+# #+# */
|
||||
/* Updated: 2024/02/04 14:23:07 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "get_next_line.h"
|
||||
|
||||
char check_line(char *res, char *buf)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
|
||||
i = 0;
|
||||
j = 0;
|
||||
while (res[i] && res[i] != '\n')
|
||||
i++;
|
||||
if (res[i] == '\n')
|
||||
{
|
||||
i++;
|
||||
while (res[i])
|
||||
{
|
||||
buf[j] = res[i];
|
||||
i++;
|
||||
j++;
|
||||
}
|
||||
buf[j] = 0;
|
||||
res[i - j] = 0;
|
||||
return (1);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
char *ft_read_error(char **buf, char *res)
|
||||
{
|
||||
free(*buf);
|
||||
*buf = NULL;
|
||||
if (res[0] != 0)
|
||||
return (res);
|
||||
free(res);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
char *get_next_line(int fd)
|
||||
{
|
||||
static char *buf;
|
||||
char *res;
|
||||
ssize_t bytes_read;
|
||||
|
||||
if (BUFFER_SIZE <= 0 || fd < 0 || fd > 1023)
|
||||
return (NULL);
|
||||
if (!buf)
|
||||
buf = ft_calloc(sizeof(char), BUFFER_SIZE + 1);
|
||||
res = ft_calloc(1, 1);
|
||||
while (buf)
|
||||
{
|
||||
res = ft_strjoin_gnl(res, buf);
|
||||
if (!res)
|
||||
return (NULL);
|
||||
if (check_line(res, buf))
|
||||
return (res);
|
||||
bytes_read = read(fd, buf, BUFFER_SIZE);
|
||||
if (bytes_read < 1)
|
||||
return (ft_read_error(&buf, res));
|
||||
buf[bytes_read] = 0;
|
||||
}
|
||||
return (NULL);
|
||||
}
|
28
libft/io/get_next_line/get_next_line.h
Normal file
28
libft/io/get_next_line/get_next_line.h
Normal file
@ -0,0 +1,28 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* get_next_line.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/12/01 17:12:00 by adjoly #+# #+# */
|
||||
/* Updated: 2024/02/04 15:24:21 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef GET_NEXT_LINE_H
|
||||
# define GET_NEXT_LINE_H
|
||||
|
||||
# include <unistd.h>
|
||||
# include <stdlib.h>
|
||||
|
||||
# ifndef BUFFER_SIZE
|
||||
# define BUFFER_SIZE 1
|
||||
# endif
|
||||
|
||||
char *get_next_line(int fd);
|
||||
char *ft_strjoin_gnl(char *s1, char *s2);
|
||||
void *ft_calloc(size_t nmemb, size_t size);
|
||||
size_t ft_strlen(const char *s);
|
||||
|
||||
#endif
|
42
libft/io/get_next_line/get_next_line_utils.c
Normal file
42
libft/io/get_next_line/get_next_line_utils.c
Normal file
@ -0,0 +1,42 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* get_next_line_utils.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/12/01 17:12:02 by adjoly #+# #+# */
|
||||
/* Updated: 2024/03/16 21:45:27 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "get_next_line.h"
|
||||
|
||||
char *ft_strjoin_gnl(char *s1, char *s2)
|
||||
{
|
||||
char *result;
|
||||
size_t i;
|
||||
size_t j;
|
||||
|
||||
i = 0;
|
||||
j = 0;
|
||||
if (!s2)
|
||||
return (NULL);
|
||||
result = ft_calloc((ft_strlen(s1) + ft_strlen(s2) + 1), sizeof(char));
|
||||
if (result == NULL)
|
||||
return (NULL);
|
||||
while (s1[i])
|
||||
{
|
||||
result[i] = s1[i];
|
||||
i++;
|
||||
}
|
||||
while (s2[j])
|
||||
{
|
||||
result[i] = s2[j];
|
||||
i++;
|
||||
j++;
|
||||
}
|
||||
free(s1);
|
||||
result[i] = '\0';
|
||||
return (result);
|
||||
}
|
BIN
libft/io/get_next_line/objget_next_line.o
Normal file
BIN
libft/io/get_next_line/objget_next_line.o
Normal file
Binary file not shown.
BIN
libft/io/get_next_line/objget_next_line_utils.o
Normal file
BIN
libft/io/get_next_line/objget_next_line_utils.o
Normal file
Binary file not shown.
19
libft/is/ft_isalnum.c
Normal file
19
libft/is/ft_isalnum.c
Normal file
@ -0,0 +1,19 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_isalnum.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/10/31 08:31:10 by adjoly #+# #+# */
|
||||
/* Updated: 2023/11/03 11:49:58 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_isalnum(int c)
|
||||
{
|
||||
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')
|
||||
|| (c >= '0' && c <= '9'))
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
18
libft/is/ft_isalpha.c
Normal file
18
libft/is/ft_isalpha.c
Normal file
@ -0,0 +1,18 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_isalpha.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/10/31 08:31:10 by adjoly #+# #+# */
|
||||
/* Updated: 2023/11/03 11:52:37 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_isalpha(int c)
|
||||
{
|
||||
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
18
libft/is/ft_isascii.c
Normal file
18
libft/is/ft_isascii.c
Normal file
@ -0,0 +1,18 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_isascii.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/10/31 08:31:10 by adjoly #+# #+# */
|
||||
/* Updated: 2023/10/31 08:46:18 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_isascii(int c)
|
||||
{
|
||||
if (c >= 0 && c <= 127)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
18
libft/is/ft_isdigit.c
Normal file
18
libft/is/ft_isdigit.c
Normal file
@ -0,0 +1,18 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_isdigit.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/10/31 08:50:01 by adjoly #+# #+# */
|
||||
/* Updated: 2023/11/03 11:53:33 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_isdigit(int c)
|
||||
{
|
||||
if (c >= '0' && c <= '9')
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
18
libft/is/ft_isprint.c
Normal file
18
libft/is/ft_isprint.c
Normal file
@ -0,0 +1,18 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_isprint.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/05 14:47:49 by adjoly #+# #+# */
|
||||
/* Updated: 2023/11/05 14:51:51 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_isprint(int c)
|
||||
{
|
||||
if (c >= 32 && c <= 126)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
104
libft/libft.h
Normal file
104
libft/libft.h
Normal file
@ -0,0 +1,104 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* libft.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/01 10:06:03 by adjoly #+# #+# */
|
||||
/* Updated: 2024/03/16 21:45:08 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef LIBFT_H
|
||||
# define LIBFT_H
|
||||
|
||||
# include <stddef.h>
|
||||
# include <stdlib.h>
|
||||
# include <unistd.h>
|
||||
|
||||
# include "print/printf/ft_printf.h"
|
||||
# include "io/get_next_line/get_next_line.h"
|
||||
|
||||
# define INT_MAX 2147483647
|
||||
# define INT_MIN -2147483648
|
||||
|
||||
typedef struct s_list
|
||||
{
|
||||
void *content;
|
||||
struct s_list *next;
|
||||
} t_list;
|
||||
|
||||
typedef enum s_boolean
|
||||
{
|
||||
ERROR = -1,
|
||||
FALSE,
|
||||
TRUE,
|
||||
} t_boolean;
|
||||
|
||||
long long ft_atoll(const char *nptr);
|
||||
int ft_atoi(const char *nptr);
|
||||
void *ft_calloc(size_t nmemb, size_t size);
|
||||
int ft_isalnum(int c);
|
||||
int ft_isalpha(int c);
|
||||
int ft_isascii(int c);
|
||||
int ft_isdigit(int c);
|
||||
void ft_bzero(void *s, size_t n);
|
||||
void *ft_memset(void *s, int c, size_t n);
|
||||
void *ft_memmove(void *dest, const void *src, size_t n);
|
||||
void *ft_memcpy(void *dest, const void *src, size_t n);
|
||||
void ft_putchar_fd(char c, int fd);
|
||||
void ft_putnbr_fd(int n, int fd);
|
||||
char *ft_strdup(const char *s);
|
||||
void ft_putstr_fd(char *s, int fd);
|
||||
char *ft_strchr(const char *s, int c);
|
||||
size_t ft_strlcpy(char *dst, const char *src, size_t size);
|
||||
size_t ft_strlen(const char *s);
|
||||
char *ft_substr(char const *s, unsigned int start, size_t len);
|
||||
int ft_tolower(int c);
|
||||
int ft_toupper(int c);
|
||||
size_t ft_strlcat(char *dst, const char *src, size_t size);
|
||||
char *ft_strjoin(char const *s1, char const *s2);
|
||||
int ft_strncmp(const char *s1, const char *s2, size_t n);
|
||||
int ft_isprint(int c);
|
||||
void *ft_memchr(const void *s, int c, size_t n);
|
||||
char *ft_itoa(int n);
|
||||
void *ft_memmove(void *dest, const void *src, size_t n);
|
||||
void *ft_memchr(const void *s, int c, size_t n);
|
||||
int ft_memcmp(const void *s1, const void *s2, size_t n);
|
||||
char *ft_strrchr(const char *s, int c);
|
||||
char *ft_strnstr(const char *big, const char *little, size_t len);
|
||||
void ft_putendl_fd(char *s, int fd);
|
||||
char *ft_strtrim(char const *s1, char const *set);
|
||||
char **ft_split(char const *s, char c);
|
||||
char *ft_strmapi(char const *s, char (*f)(unsigned int, char));
|
||||
void ft_striteri(char *s, void (*f)(unsigned int, char *));
|
||||
|
||||
t_list *ft_lstnew(void *content);
|
||||
void ft_lstadd_front(t_list **lst, t_list *new);
|
||||
int ft_lstsize(t_list *lst);
|
||||
t_list *ft_lstlast(t_list *lst);
|
||||
void ft_lstadd_back(t_list **lst, t_list *new);
|
||||
void ft_lstdelone(t_list *lst, void (*del)(void *));
|
||||
void ft_lstclear(t_list **lst, void (*del)(void *));
|
||||
void ft_lstiter(t_list *lst, void (*f)(void *));
|
||||
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *));
|
||||
|
||||
void ft_putchar(char c);
|
||||
void ft_putstr(char *s);
|
||||
void ft_putnbrbase_fd(int n, char *base, int fd);
|
||||
void ft_putnbrbase(int n, char *base);
|
||||
void ft_putnbr(int n);
|
||||
|
||||
int ft_printf(const char *format, ...);
|
||||
int ft_printconversion(char conversion, va_list args);
|
||||
int ft_putnbrulong(unsigned int n);
|
||||
int ft_putaddr(void *ptr);
|
||||
int ft_putstr_p(char *s);
|
||||
int ft_putnbrbase_p(unsigned long int n, char *base);
|
||||
int ft_putnbrbase_pf(unsigned int n, char *base);
|
||||
int ft_putchar_p(char c);
|
||||
int ft_putnbr_p(int n);
|
||||
size_t ft_strlen(const char *s);
|
||||
|
||||
#endif
|
25
libft/lst/ft_lstadd_back.c
Normal file
25
libft/lst/ft_lstadd_back.c
Normal file
@ -0,0 +1,25 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstadd_back.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/11 16:37:42 by adjoly #+# #+# */
|
||||
/* Updated: 2024/02/04 14:56:37 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../libft.h"
|
||||
|
||||
void ft_lstadd_back(t_list **lst, t_list *new)
|
||||
{
|
||||
if (!lst)
|
||||
return ;
|
||||
if (!*lst)
|
||||
{
|
||||
(*lst) = new;
|
||||
return ;
|
||||
}
|
||||
ft_lstlast((*lst))->next = new;
|
||||
}
|
23
libft/lst/ft_lstadd_front.c
Normal file
23
libft/lst/ft_lstadd_front.c
Normal file
@ -0,0 +1,23 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstadd_front.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/11 15:39:25 by adjoly #+# #+# */
|
||||
/* Updated: 2024/02/04 14:57:01 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../libft.h"
|
||||
|
||||
void ft_lstadd_front(t_list **lst, t_list *new)
|
||||
{
|
||||
if (!lst)
|
||||
return ;
|
||||
if (!new)
|
||||
return ;
|
||||
new->next = *lst;
|
||||
*lst = new;
|
||||
}
|
26
libft/lst/ft_lstclear.c
Normal file
26
libft/lst/ft_lstclear.c
Normal file
@ -0,0 +1,26 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstclear.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/11 18:05:14 by adjoly #+# #+# */
|
||||
/* Updated: 2024/02/04 13:55:17 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../libft.h"
|
||||
|
||||
void ft_lstclear(t_list **lst, void (*del)(void *))
|
||||
{
|
||||
t_list *tmp;
|
||||
|
||||
tmp = NULL;
|
||||
while (lst && *lst && del)
|
||||
{
|
||||
tmp = (*lst)->next;
|
||||
ft_lstdelone((*lst), del);
|
||||
*lst = tmp;
|
||||
}
|
||||
}
|
21
libft/lst/ft_lstdelone.c
Normal file
21
libft/lst/ft_lstdelone.c
Normal file
@ -0,0 +1,21 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstdelone.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/11 17:59:39 by adjoly #+# #+# */
|
||||
/* Updated: 2024/02/04 13:55:19 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../libft.h"
|
||||
|
||||
void ft_lstdelone(t_list *lst, void (*del)(void *))
|
||||
{
|
||||
if (lst == NULL || del == NULL)
|
||||
return ;
|
||||
del(lst->content);
|
||||
free(lst);
|
||||
}
|
24
libft/lst/ft_lstiter.c
Normal file
24
libft/lst/ft_lstiter.c
Normal file
@ -0,0 +1,24 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstiter.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/11 18:20:25 by adjoly #+# #+# */
|
||||
/* Updated: 2024/02/04 14:58:16 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../libft.h"
|
||||
|
||||
void ft_lstiter(t_list *lst, void (*f)(void *))
|
||||
{
|
||||
if (!lst || !f)
|
||||
return ;
|
||||
while (lst)
|
||||
{
|
||||
f(lst->content);
|
||||
lst = lst->next;
|
||||
}
|
||||
}
|
22
libft/lst/ft_lstlast.c
Normal file
22
libft/lst/ft_lstlast.c
Normal file
@ -0,0 +1,22 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstlast.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/11 16:03:12 by adjoly #+# #+# */
|
||||
/* Updated: 2024/02/04 14:57:50 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../libft.h"
|
||||
|
||||
t_list *ft_lstlast(t_list *lst)
|
||||
{
|
||||
if (!lst)
|
||||
return (NULL);
|
||||
while (lst->next)
|
||||
lst = lst->next;
|
||||
return (lst);
|
||||
}
|
35
libft/lst/ft_lstmap.c
Normal file
35
libft/lst/ft_lstmap.c
Normal file
@ -0,0 +1,35 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstmap.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/11 18:24:49 by adjoly #+# #+# */
|
||||
/* Updated: 2024/02/04 14:58:45 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../libft.h"
|
||||
|
||||
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *))
|
||||
{
|
||||
t_list *res;
|
||||
t_list *tmp;
|
||||
|
||||
if (!lst || !f || !del)
|
||||
return (NULL);
|
||||
res = NULL;
|
||||
while (lst)
|
||||
{
|
||||
tmp = ft_lstnew(f(lst->content));
|
||||
if (tmp == NULL)
|
||||
{
|
||||
ft_lstclear(&tmp, del);
|
||||
return (NULL);
|
||||
}
|
||||
ft_lstadd_back(&res, tmp);
|
||||
lst = lst->next;
|
||||
}
|
||||
return (res);
|
||||
}
|
25
libft/lst/ft_lstnew.c
Normal file
25
libft/lst/ft_lstnew.c
Normal file
@ -0,0 +1,25 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstnew.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/11 15:30:32 by adjoly #+# #+# */
|
||||
/* Updated: 2024/02/04 14:58:59 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../libft.h"
|
||||
|
||||
t_list *ft_lstnew(void *content)
|
||||
{
|
||||
t_list *lst;
|
||||
|
||||
lst = malloc(sizeof(t_list));
|
||||
if (!lst)
|
||||
return (NULL);
|
||||
lst[0].content = content;
|
||||
lst[0].next = NULL;
|
||||
return (lst);
|
||||
}
|
26
libft/lst/ft_lstsize.c
Normal file
26
libft/lst/ft_lstsize.c
Normal file
@ -0,0 +1,26 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstsize.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/11 15:53:01 by adjoly #+# #+# */
|
||||
/* Updated: 2024/02/04 14:59:13 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../libft.h"
|
||||
|
||||
int ft_lstsize(t_list *lst)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (lst)
|
||||
{
|
||||
lst = lst->next;
|
||||
i++;
|
||||
}
|
||||
return (i);
|
||||
}
|
18
libft/mem/ft_bzero.c
Normal file
18
libft/mem/ft_bzero.c
Normal file
@ -0,0 +1,18 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_bzero.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/03 11:58:03 by adjoly #+# #+# */
|
||||
/* Updated: 2024/02/04 13:55:51 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../libft.h"
|
||||
|
||||
void ft_bzero(void *s, size_t n)
|
||||
{
|
||||
ft_memset(s, '\0', n);
|
||||
}
|
36
libft/mem/ft_calloc.c
Normal file
36
libft/mem/ft_calloc.c
Normal file
@ -0,0 +1,36 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_calloc.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/01 16:02:26 by adjoly #+# #+# */
|
||||
/* Updated: 2024/03/04 10:10:58 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../libft.h"
|
||||
|
||||
void *ft_calloc(size_t nmemb, size_t size)
|
||||
{
|
||||
void *result;
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
if (nmemb == 0 || size == 0)
|
||||
return (malloc(1));
|
||||
if (((unsigned long long)(size * nmemb) > 4294967295))
|
||||
return (NULL);
|
||||
if ((int)size < 0 && (int)nmemb < 0)
|
||||
return (NULL);
|
||||
result = malloc(size * nmemb);
|
||||
if (!result)
|
||||
return (NULL);
|
||||
while (i < (size * nmemb))
|
||||
{
|
||||
*(unsigned char *)(result + i) = '\0';
|
||||
i++;
|
||||
}
|
||||
return (result);
|
||||
}
|
27
libft/mem/ft_memchr.c
Normal file
27
libft/mem/ft_memchr.c
Normal file
@ -0,0 +1,27 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memchr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/05 14:52:53 by adjoly #+# #+# */
|
||||
/* Updated: 2024/02/04 14:36:28 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../libft.h"
|
||||
|
||||
void *ft_memchr(const void *s, int c, size_t n)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
while (i < n)
|
||||
{
|
||||
if (((unsigned char *)s)[i] == (unsigned char)c)
|
||||
return (((void *)s + i));
|
||||
i++;
|
||||
}
|
||||
return (NULL);
|
||||
}
|
25
libft/mem/ft_memcmp.c
Normal file
25
libft/mem/ft_memcmp.c
Normal file
@ -0,0 +1,25 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memcmp.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/08 12:04:48 by adjoly #+# #+# */
|
||||
/* Updated: 2024/02/04 14:36:46 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../libft.h"
|
||||
|
||||
int ft_memcmp(const void *s1, const void *s2, size_t n)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
if (n == 0)
|
||||
return (0);
|
||||
while (((unsigned char *)s1)[i] == ((unsigned char *)s2)[i] && i < n - 1)
|
||||
i++;
|
||||
return (((unsigned char *)s1)[i] - ((unsigned char *)s2)[i]);
|
||||
}
|
30
libft/mem/ft_memcpy.c
Normal file
30
libft/mem/ft_memcpy.c
Normal file
@ -0,0 +1,30 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memcpy.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/02 10:21:55 by adjoly #+# #+# */
|
||||
/* Updated: 2024/02/04 15:00:19 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../libft.h"
|
||||
|
||||
void *ft_memcpy(void *dest, const void *src, size_t n)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
if (!src && !dest)
|
||||
{
|
||||
return (dest);
|
||||
}
|
||||
while (i < n)
|
||||
{
|
||||
((unsigned char *)dest)[i] = ((unsigned char *)src)[i];
|
||||
i++;
|
||||
}
|
||||
return (dest);
|
||||
}
|
27
libft/mem/ft_memmove.c
Normal file
27
libft/mem/ft_memmove.c
Normal file
@ -0,0 +1,27 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memmove.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/03 15:04:04 by adjoly #+# #+# */
|
||||
/* Updated: 2024/02/04 14:38:10 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../libft.h"
|
||||
|
||||
void *ft_memmove(void *dest, const void *src, size_t n)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
i = -1;
|
||||
if (dest > src)
|
||||
while (n-- > 0)
|
||||
((unsigned char *)dest)[n] = ((unsigned char *)src)[n];
|
||||
else if (dest < src)
|
||||
while (++i < n)
|
||||
((unsigned char *)dest)[i] = ((unsigned char *)src)[i];
|
||||
return (dest);
|
||||
}
|
26
libft/mem/ft_memset.c
Normal file
26
libft/mem/ft_memset.c
Normal file
@ -0,0 +1,26 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memset.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/10/31 17:40:22 by adjoly #+# #+# */
|
||||
/* Updated: 2024/02/04 14:37:55 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../libft.h"
|
||||
|
||||
void *ft_memset(void *s, int c, size_t n)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
while (i < n)
|
||||
{
|
||||
((char *)(s))[i] = c;
|
||||
i++;
|
||||
}
|
||||
return (s);
|
||||
}
|
18
libft/print/ft_putchar.c
Normal file
18
libft/print/ft_putchar.c
Normal file
@ -0,0 +1,18 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putchar.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/18 10:49:00 by adjoly #+# #+# */
|
||||
/* Updated: 2024/02/04 15:00:50 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../libft.h"
|
||||
|
||||
void ft_putchar(char c)
|
||||
{
|
||||
write(1, &c, 1);
|
||||
}
|
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: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/10/31 11:42:17 by adjoly #+# #+# */
|
||||
/* Updated: 2024/02/04 14:39:21 by adjoly ### ########.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: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/09 19:12:00 by adjoly #+# #+# */
|
||||
/* Updated: 2024/02/04 14:40:09 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../libft.h"
|
||||
|
||||
void ft_putendl_fd(char *s, int fd)
|
||||
{
|
||||
ft_putstr_fd(s, fd);
|
||||
ft_putchar_fd('\n', fd);
|
||||
}
|
18
libft/print/ft_putnbr.c
Normal file
18
libft/print/ft_putnbr.c
Normal file
@ -0,0 +1,18 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putnbr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/18 11:14:22 by adjoly #+# #+# */
|
||||
/* Updated: 2024/02/04 14:41:11 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../libft.h"
|
||||
|
||||
void ft_putnbr(int n)
|
||||
{
|
||||
ft_putnbr_fd(n, 1);
|
||||
}
|
33
libft/print/ft_putnbr_fd.c
Normal file
33
libft/print/ft_putnbr_fd.c
Normal file
@ -0,0 +1,33 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putnbr_fd.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/10/31 11:52:46 by adjoly #+# #+# */
|
||||
/* Updated: 2024/02/04 14:42:15 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../libft.h"
|
||||
|
||||
void ft_putnbr_fd(int n, int fd)
|
||||
{
|
||||
unsigned int nbr;
|
||||
|
||||
if (n < 0)
|
||||
{
|
||||
write(fd, "-", 1);
|
||||
nbr = -n;
|
||||
}
|
||||
else
|
||||
nbr = n;
|
||||
if (nbr < 10)
|
||||
write(fd, &(char){nbr + '0'}, 1);
|
||||
else
|
||||
{
|
||||
ft_putnbr_fd(nbr / 10, fd);
|
||||
write(fd, &(char){nbr % 10 + '0'}, 1);
|
||||
}
|
||||
}
|
18
libft/print/ft_putnbrbase.c
Normal file
18
libft/print/ft_putnbrbase.c
Normal file
@ -0,0 +1,18 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putnbrbase.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/18 11:13:15 by adjoly #+# #+# */
|
||||
/* Updated: 2024/02/04 15:01:31 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../libft.h"
|
||||
|
||||
void ft_putnbrbase(int n, char *base)
|
||||
{
|
||||
ft_putnbrbase_fd(n, base, 1);
|
||||
}
|
35
libft/print/ft_putnbrbase_fd.c
Normal file
35
libft/print/ft_putnbrbase_fd.c
Normal file
@ -0,0 +1,35 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putnbrbase_fd.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/18 10:57:44 by adjoly #+# #+# */
|
||||
/* Updated: 2024/02/04 14:41:30 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../libft.h"
|
||||
|
||||
void ft_putnbrbase_fd(int n, char *base, int fd)
|
||||
{
|
||||
unsigned int nbr;
|
||||
size_t base_len;
|
||||
|
||||
base_len = ft_strlen(base);
|
||||
if (n < 0)
|
||||
{
|
||||
write(fd, "-", 1);
|
||||
nbr = -n;
|
||||
}
|
||||
else
|
||||
nbr = n;
|
||||
if (nbr < base_len)
|
||||
write(fd, &base[nbr % base_len], 1);
|
||||
else
|
||||
{
|
||||
ft_putnbrbase_fd(nbr / base_len, base, fd);
|
||||
write(fd, &base[nbr % base_len], 1);
|
||||
}
|
||||
}
|
18
libft/print/ft_putstr.c
Normal file
18
libft/print/ft_putstr.c
Normal file
@ -0,0 +1,18 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putstr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/18 18:35:32 by adjoly #+# #+# */
|
||||
/* Updated: 2024/03/16 21:45:41 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../libft.h"
|
||||
|
||||
void ft_putstr(char *s)
|
||||
{
|
||||
write(1, s, ft_strlen(s));
|
||||
}
|
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: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/10/31 11:45:55 by adjoly #+# #+# */
|
||||
/* Updated: 2024/02/04 15:08:44 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../libft.h"
|
||||
|
||||
void ft_putstr_fd(char *s, int fd)
|
||||
{
|
||||
write(fd, s, ft_strlen(s));
|
||||
}
|
46
libft/print/printf/Makefile
Normal file
46
libft/print/printf/Makefile
Normal file
@ -0,0 +1,46 @@
|
||||
# **************************************************************************** #
|
||||
# #
|
||||
# ::: :::::::: #
|
||||
# Makefile :+: :+: :+: #
|
||||
# +:+ +:+ +:+ #
|
||||
# By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2023/11/17 12:35:27 by adjoly #+# #+# #
|
||||
# Updated: 2024/02/04 15:18:46 by adjoly ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
NAME = libftprintf.a
|
||||
|
||||
CC = cc
|
||||
|
||||
SRCS = ft_printf.c \
|
||||
ft_putchar.c \
|
||||
ft_putnbr.c \
|
||||
ft_putnbrbase.c \
|
||||
ft_putstr.c \
|
||||
../../str/ft_strlen.c \
|
||||
|
||||
OBJS = $(SRCS:.c=.o)
|
||||
|
||||
FLAGS = -Werror -Wall -Wextra
|
||||
|
||||
HEADER = libftprintf.h
|
||||
|
||||
$(NAME): $(OBJS)
|
||||
ar -rcs $(NAME) $(OBJS)
|
||||
|
||||
%.o: %.c
|
||||
$(CC) $(FLAGS) -I $(HEADER) $< -c -o $@
|
||||
|
||||
all: $(NAME)
|
||||
|
||||
clean:
|
||||
rm -f $(OBJS)
|
||||
|
||||
fclean: clean
|
||||
rm -f $(NAME)
|
||||
|
||||
re: fclean all
|
||||
|
||||
.PHONY: clean all re fclean
|
92
libft/print/printf/ft_printf.c
Normal file
92
libft/print/printf/ft_printf.c
Normal file
@ -0,0 +1,92 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_printf.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/17 16:48:37 by adjoly #+# #+# */
|
||||
/* Updated: 2024/03/16 21:46:36 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_printf.h"
|
||||
|
||||
int ft_putaddr(void *ptr)
|
||||
{
|
||||
int r;
|
||||
|
||||
if (ptr == NULL)
|
||||
return (write(1, "(nil)", 5));
|
||||
write(1, "0x", 2);
|
||||
r = ft_putnbrbase_p((long unsigned int)ptr, "0123456789abcdef");
|
||||
return (2 + r);
|
||||
}
|
||||
|
||||
int ft_putnbrulong(unsigned int n)
|
||||
{
|
||||
int len;
|
||||
|
||||
len = 0;
|
||||
if (n < 10)
|
||||
len += write(1, &(char){n + '0'}, 1);
|
||||
else
|
||||
{
|
||||
len += ft_putnbrulong(n / 10);
|
||||
len += write(1, &(char){n % 10 + '0'}, 1);
|
||||
}
|
||||
return (len);
|
||||
}
|
||||
|
||||
int ft_printconversion(char conversion, va_list args)
|
||||
{
|
||||
int count;
|
||||
|
||||
count = 0;
|
||||
if (conversion == '%')
|
||||
count = ft_putchar_p('%');
|
||||
else if (conversion == 's')
|
||||
count = ft_putstr_p(va_arg(args, char *));
|
||||
else if (conversion == 'c')
|
||||
count = ft_putchar_p(va_arg(args, int));
|
||||
else if (conversion == 'i' || conversion == 'd')
|
||||
count = ft_putnbr_p(va_arg(args, int));
|
||||
else if (conversion == 'u')
|
||||
count = ft_putnbrulong(va_arg(args, unsigned int));
|
||||
else if (conversion == 'p')
|
||||
count = ft_putaddr(va_arg(args, void *));
|
||||
else if (conversion == 'x')
|
||||
count = ft_pputnbrbase(va_arg(args, unsigned long), "0123456789abcdef");
|
||||
else if (conversion == 'X')
|
||||
count = ft_pputnbrbase(va_arg(args, unsigned long), "0123456789ABCDEF");
|
||||
return (count);
|
||||
}
|
||||
|
||||
int ft_printf(const char *format, ...)
|
||||
{
|
||||
int i;
|
||||
va_list args;
|
||||
int count;
|
||||
|
||||
va_start(args, format);
|
||||
count = 0;
|
||||
i = 0;
|
||||
if (format == NULL)
|
||||
return (-1);
|
||||
while (format[i])
|
||||
{
|
||||
if (format[i] == '%')
|
||||
{
|
||||
i++;
|
||||
if (format[i])
|
||||
count += ft_printconversion(format[i], args);
|
||||
else
|
||||
return (-1);
|
||||
}
|
||||
else
|
||||
count += ft_putchar_p(format[i]);
|
||||
i++;
|
||||
}
|
||||
va_end(args);
|
||||
return (count);
|
||||
}
|
33
libft/print/printf/ft_printf.h
Normal file
33
libft/print/printf/ft_printf.h
Normal file
@ -0,0 +1,33 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_printf.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/17 16:50:36 by adjoly #+# #+# */
|
||||
/* Updated: 2024/03/16 21:47:28 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef FT_PRINTF_H
|
||||
# define FT_PRINTF_H
|
||||
|
||||
# include <stdlib.h>
|
||||
# include <stdarg.h>
|
||||
# include <unistd.h>
|
||||
|
||||
int ft_printf(const char *format, ...);
|
||||
int ft_printconversion(char conversion, va_list args);
|
||||
int ft_putnbrulong(unsigned int n);
|
||||
int ft_putaddr(void *ptr);
|
||||
|
||||
int ft_putstr_p(char *s);
|
||||
|
||||
int ft_putnbrbase_p(unsigned long int n, char *base);
|
||||
int ft_pputnbrbase(unsigned int n, char *base);
|
||||
int ft_putchar_p(char c);
|
||||
int ft_putnbr_p(int n);
|
||||
size_t ft_strlen(const char *s);
|
||||
|
||||
#endif
|
19
libft/print/printf/ft_putchar.c
Normal file
19
libft/print/printf/ft_putchar.c
Normal file
@ -0,0 +1,19 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putchar.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/18 10:49:00 by adjoly #+# #+# */
|
||||
/* Updated: 2024/02/04 15:17:42 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_printf.h"
|
||||
|
||||
int ft_putchar_p(char c)
|
||||
{
|
||||
write(1, &c, 1);
|
||||
return (1);
|
||||
}
|
36
libft/print/printf/ft_putnbr.c
Normal file
36
libft/print/printf/ft_putnbr.c
Normal file
@ -0,0 +1,36 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putnbr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/10/31 11:52:46 by adjoly #+# #+# */
|
||||
/* Updated: 2024/02/04 15:20:26 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_printf.h"
|
||||
|
||||
int ft_putnbr_p(int n)
|
||||
{
|
||||
unsigned int nbr;
|
||||
int len;
|
||||
|
||||
len = 0;
|
||||
if (n < 0)
|
||||
{
|
||||
len += write(1, "-", 1);
|
||||
nbr = -n;
|
||||
}
|
||||
else
|
||||
nbr = n;
|
||||
if (nbr < 10)
|
||||
len += write(1, &(char){nbr + '0'}, 1);
|
||||
else
|
||||
{
|
||||
len += ft_putnbr_p(nbr / 10);
|
||||
len += write(1, &(char){nbr % 10 + '0'}, 1);
|
||||
}
|
||||
return (len);
|
||||
}
|
47
libft/print/printf/ft_putnbrbase.c
Normal file
47
libft/print/printf/ft_putnbrbase.c
Normal file
@ -0,0 +1,47 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putnbrbase.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/18 10:57:44 by adjoly #+# #+# */
|
||||
/* Updated: 2024/02/04 15:21:56 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_printf.h"
|
||||
|
||||
int ft_putnbrbase_pf(unsigned int n, char *base)
|
||||
{
|
||||
unsigned int base_len;
|
||||
int len;
|
||||
|
||||
len = 0;
|
||||
base_len = (int)ft_strlen(base);
|
||||
if (n < base_len)
|
||||
len += write(1, &base[n % base_len], 1);
|
||||
else
|
||||
{
|
||||
len += ft_putnbrbase_pf(n / base_len, base);
|
||||
len += write(1, &base[n % base_len], 1);
|
||||
}
|
||||
return (len);
|
||||
}
|
||||
|
||||
int ft_putnbrbase_p(unsigned long int n, char *base)
|
||||
{
|
||||
unsigned long int base_len;
|
||||
int len;
|
||||
|
||||
len = 0;
|
||||
base_len = (int)ft_strlen(base);
|
||||
if (n < base_len)
|
||||
len += write(1, &base[n % base_len], 1);
|
||||
else
|
||||
{
|
||||
len += ft_putnbrbase_p(n / base_len, base);
|
||||
len += write(1, &base[n % base_len], 1);
|
||||
}
|
||||
return (len);
|
||||
}
|
23
libft/print/printf/ft_putstr.c
Normal file
23
libft/print/printf/ft_putstr.c
Normal file
@ -0,0 +1,23 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putstr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/10/31 11:45:55 by adjoly #+# #+# */
|
||||
/* Updated: 2024/03/12 15:05:16 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_printf.h"
|
||||
|
||||
int ft_putstr_p(char *s)
|
||||
{
|
||||
if (s == NULL)
|
||||
{
|
||||
write(1, "(null)", 6);
|
||||
return (6);
|
||||
}
|
||||
return (write(1, s, ft_strlen(s)));
|
||||
}
|
37
libft/str/ft_atoi.c
Normal file
37
libft/str/ft_atoi.c
Normal file
@ -0,0 +1,37 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_atoi.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/10/31 09:00:27 by adjoly #+# #+# */
|
||||
/* Updated: 2023/11/05 15:27:36 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_atoi(const char *nptr)
|
||||
{
|
||||
int i;
|
||||
int sign;
|
||||
int nbr;
|
||||
|
||||
i = 0;
|
||||
sign = 1;
|
||||
nbr = 0;
|
||||
while ((nptr[i] >= 7 && nptr[i] <= 13) || nptr[i] == 32)
|
||||
i++;
|
||||
if (nptr[i] == '-')
|
||||
{
|
||||
sign *= -1;
|
||||
i++;
|
||||
}
|
||||
else if (nptr[i] == '+')
|
||||
i++;
|
||||
while (nptr[i] >= '0' && nptr[i] <= '9')
|
||||
{
|
||||
nbr = nbr * 10 + (nptr[i] - '0');
|
||||
i++;
|
||||
}
|
||||
return (nbr * sign);
|
||||
}
|
35
libft/str/ft_atoll.c
Normal file
35
libft/str/ft_atoll.c
Normal file
@ -0,0 +1,35 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_atoll.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/10/31 09:00:27 by adjoly #+# #+# */
|
||||
/* Updated: 2024/02/15 13:49:15 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
long long ft_atoll(const char *nptr)
|
||||
{
|
||||
char sign;
|
||||
long long nbr;
|
||||
|
||||
sign = 1;
|
||||
nbr = 0;
|
||||
while ((*nptr >= 7 && *nptr <= 13) || *nptr == 32)
|
||||
nptr++;
|
||||
if (*nptr == '-')
|
||||
{
|
||||
sign *= -1;
|
||||
nptr++;
|
||||
}
|
||||
else if (*nptr == '+')
|
||||
nptr++;
|
||||
while (*nptr >= '0' && *nptr <= '9')
|
||||
{
|
||||
nbr = nbr * 10 + (*nptr - '0');
|
||||
nptr++;
|
||||
}
|
||||
return (nbr * sign);
|
||||
}
|
58
libft/str/ft_itoa.c
Normal file
58
libft/str/ft_itoa.c
Normal file
@ -0,0 +1,58 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_itoa.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/05 16:26:26 by adjoly #+# #+# */
|
||||
/* Updated: 2024/02/04 14:45:39 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../libft.h"
|
||||
|
||||
static int ft_count_digit(int n)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
if (n < 0)
|
||||
i++;
|
||||
if (n == 0)
|
||||
return (1);
|
||||
while (n)
|
||||
{
|
||||
n /= 10;
|
||||
i++;
|
||||
}
|
||||
return (i);
|
||||
}
|
||||
|
||||
char *ft_itoa(int n)
|
||||
{
|
||||
char *result;
|
||||
int i;
|
||||
|
||||
i = ft_count_digit(n);
|
||||
if (n == 0)
|
||||
return (ft_strdup("0"));
|
||||
if (n == -2147483648)
|
||||
return (ft_strdup("-2147483648"));
|
||||
result = malloc(sizeof(char) * (i + 1));
|
||||
if (result == NULL)
|
||||
return (NULL);
|
||||
result[i--] = '\0';
|
||||
if (n < 0)
|
||||
{
|
||||
result[0] = '-';
|
||||
n = -n;
|
||||
}
|
||||
while (n)
|
||||
{
|
||||
result[i] = n % 10 + '0';
|
||||
n /= 10;
|
||||
i--;
|
||||
}
|
||||
return (result);
|
||||
}
|
94
libft/str/ft_split.c
Normal file
94
libft/str/ft_split.c
Normal file
@ -0,0 +1,94 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_split.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/12 09:14:19 by adjoly #+# #+# */
|
||||
/* Updated: 2024/02/04 14:43:50 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../libft.h"
|
||||
|
||||
static int ft_countword(char const *s, char sep)
|
||||
{
|
||||
int i;
|
||||
int w_count;
|
||||
|
||||
i = 0;
|
||||
w_count = 0;
|
||||
while (s[i])
|
||||
{
|
||||
if (s[i] != sep && (i == 0 || s[i - 1] == sep))
|
||||
w_count++;
|
||||
i++;
|
||||
}
|
||||
return (w_count);
|
||||
}
|
||||
|
||||
static int ft_countletter(char const *s, char sep)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (s[i] != sep && s[i] != '\0')
|
||||
i++;
|
||||
return (i);
|
||||
}
|
||||
|
||||
static void *ft_freearr(char **arr)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (arr[i])
|
||||
{
|
||||
free(arr[i]);
|
||||
i++;
|
||||
}
|
||||
free(arr);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
char **ft_split_to_result(char **tab, char const *s, char c)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
int k;
|
||||
|
||||
i = 0;
|
||||
j = 0;
|
||||
while (s[i])
|
||||
{
|
||||
if (s[i] != c)
|
||||
{
|
||||
k = 0;
|
||||
tab[j] = ft_calloc(ft_countletter(&s[i], c) + 1, sizeof(char));
|
||||
if (!tab[j])
|
||||
return (ft_freearr(tab));
|
||||
while (s[i] && s[i] != c)
|
||||
tab[j][k++] = s [i++];
|
||||
tab[j][k] = '\0';
|
||||
j++;
|
||||
}
|
||||
else
|
||||
i++;
|
||||
}
|
||||
tab[j] = NULL;
|
||||
return (tab);
|
||||
}
|
||||
|
||||
char **ft_split(char const *s, char c)
|
||||
{
|
||||
char **result;
|
||||
|
||||
if (s == NULL)
|
||||
return (NULL);
|
||||
result = ft_calloc(ft_countword(s, c) + 1, sizeof(char *));
|
||||
if (!result)
|
||||
return (NULL);
|
||||
result = ft_split_to_result(result, s, c);
|
||||
return (result);
|
||||
}
|
25
libft/str/ft_strchr.c
Normal file
25
libft/str/ft_strchr.c
Normal file
@ -0,0 +1,25 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strchr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/01 15:45:18 by adjoly #+# #+# */
|
||||
/* Updated: 2024/02/04 14:44:11 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../libft.h"
|
||||
|
||||
char *ft_strchr(const char *s, int c)
|
||||
{
|
||||
size_t len_s;
|
||||
char *result;
|
||||
|
||||
len_s = ft_strlen(s);
|
||||
result = ft_memchr(s, c, len_s);
|
||||
if (c == 0)
|
||||
return ((char *)s + len_s);
|
||||
return (result);
|
||||
}
|
33
libft/str/ft_strdup.c
Normal file
33
libft/str/ft_strdup.c
Normal file
@ -0,0 +1,33 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strdup.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/03 22:57:39 by adjoly #+# #+# */
|
||||
/* Updated: 2024/02/04 14:44:58 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../libft.h"
|
||||
|
||||
char *ft_strdup(const char *s)
|
||||
{
|
||||
int i;
|
||||
char *result;
|
||||
int len;
|
||||
|
||||
i = 0;
|
||||
len = ft_strlen(s);
|
||||
result = malloc(sizeof(char) * (len + 1));
|
||||
if (result == NULL)
|
||||
return (NULL);
|
||||
while (s[i])
|
||||
{
|
||||
result[i] = s[i];
|
||||
i++;
|
||||
}
|
||||
result[i] = '\0';
|
||||
return (result);
|
||||
}
|
27
libft/str/ft_striteri.c
Normal file
27
libft/str/ft_striteri.c
Normal file
@ -0,0 +1,27 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_striteri.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/11 14:15:30 by adjoly #+# #+# */
|
||||
/* Updated: 2024/02/04 14:45:11 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../libft.h"
|
||||
|
||||
void ft_striteri(char *s, void (*f)(unsigned int, char *))
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
if (s == NULL || f == NULL)
|
||||
return ;
|
||||
while (s[i])
|
||||
{
|
||||
f(i, &s[i]);
|
||||
i++;
|
||||
}
|
||||
}
|
41
libft/str/ft_strjoin.c
Normal file
41
libft/str/ft_strjoin.c
Normal file
@ -0,0 +1,41 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strjoin.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/04 13:44:09 by adjoly #+# #+# */
|
||||
/* Updated: 2024/02/04 14:45:30 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../libft.h"
|
||||
|
||||
char *ft_strjoin(char const *s1, char const *s2)
|
||||
{
|
||||
char *result;
|
||||
size_t i;
|
||||
size_t j;
|
||||
|
||||
i = 0;
|
||||
j = 0;
|
||||
if (s1 == NULL || s2 == NULL)
|
||||
return (NULL);
|
||||
result = ft_calloc((ft_strlen(s1) + ft_strlen(s2) + 1), sizeof(char));
|
||||
if (result == NULL)
|
||||
return (NULL);
|
||||
while (s1[i])
|
||||
{
|
||||
result[i] = s1[i];
|
||||
i++;
|
||||
}
|
||||
while (s2[j])
|
||||
{
|
||||
result[i] = s2[j];
|
||||
i++;
|
||||
j++;
|
||||
}
|
||||
result[i] = '\0';
|
||||
return (result);
|
||||
}
|
38
libft/str/ft_strlcat.c
Normal file
38
libft/str/ft_strlcat.c
Normal file
@ -0,0 +1,38 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strlcat.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/03 15:59:31 by adjoly #+# #+# */
|
||||
/* Updated: 2024/02/04 14:47:03 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../libft.h"
|
||||
|
||||
size_t ft_strlcat(char *dst, const char *src, size_t size)
|
||||
{
|
||||
size_t i;
|
||||
size_t j;
|
||||
size_t len_dst;
|
||||
size_t len_src;
|
||||
|
||||
if (dst == NULL && size == 0)
|
||||
return (0);
|
||||
i = 0;
|
||||
j = ft_strlen(dst);
|
||||
len_src = ft_strlen(src);
|
||||
len_dst = ft_strlen(dst);
|
||||
if (size <= j)
|
||||
return (len_src + size);
|
||||
while (j < size - 1 && src[i])
|
||||
{
|
||||
dst[j] = src[i];
|
||||
i++;
|
||||
j++;
|
||||
}
|
||||
dst[j] = '\0';
|
||||
return (len_src + len_dst);
|
||||
}
|
30
libft/str/ft_strlcpy.c
Normal file
30
libft/str/ft_strlcpy.c
Normal file
@ -0,0 +1,30 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strlcpy.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/01 09:52:45 by adjoly #+# #+# */
|
||||
/* Updated: 2024/02/04 14:47:41 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../libft.h"
|
||||
|
||||
size_t ft_strlcpy(char *dst, const char *src, size_t size)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
if (size == 0)
|
||||
return (ft_strlen(src));
|
||||
while (i < size - 1 && src[i])
|
||||
{
|
||||
dst[i] = src[i];
|
||||
i++;
|
||||
}
|
||||
if (i < size)
|
||||
dst[i] = '\0';
|
||||
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: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/10/30 18:15:57 by adjoly #+# #+# */
|
||||
/* Updated: 2024/03/12 15:07:08 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../libft.h"
|
||||
|
||||
size_t ft_strlen(const char *s)
|
||||
{
|
||||
const char *tmp;
|
||||
|
||||
tmp = s;
|
||||
while (*tmp)
|
||||
tmp++;
|
||||
return (tmp - s);
|
||||
}
|
33
libft/str/ft_strmapi.c
Normal file
33
libft/str/ft_strmapi.c
Normal file
@ -0,0 +1,33 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strmapi.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/11 11:44:24 by adjoly #+# #+# */
|
||||
/* Updated: 2024/02/04 14:48:02 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../libft.h"
|
||||
|
||||
char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
|
||||
{
|
||||
int i;
|
||||
char *res;
|
||||
|
||||
i = 0;
|
||||
if (!s || !f)
|
||||
return (NULL);
|
||||
res = ft_calloc((ft_strlen(s) + 1), sizeof(char));
|
||||
if (res == NULL)
|
||||
return (NULL);
|
||||
while (s[i])
|
||||
{
|
||||
res[i] = f(i, s[i]);
|
||||
i++;
|
||||
}
|
||||
res[i] = '\0';
|
||||
return (res);
|
||||
}
|
25
libft/str/ft_strncmp.c
Normal file
25
libft/str/ft_strncmp.c
Normal file
@ -0,0 +1,25 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strncmp.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/05 10:40:45 by adjoly #+# #+# */
|
||||
/* Updated: 2024/02/04 14:48:12 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../libft.h"
|
||||
|
||||
int ft_strncmp(const char *s1, const char *s2, size_t n)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
if (n == 0)
|
||||
return (0);
|
||||
while (s1[i] == s2[i] && s1[i] && i < n - 1)
|
||||
i++;
|
||||
return ((unsigned char)s1[i] - (unsigned char)s2[i]);
|
||||
}
|
35
libft/str/ft_strnstr.c
Normal file
35
libft/str/ft_strnstr.c
Normal file
@ -0,0 +1,35 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strnstr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/08 16:02:17 by adjoly #+# #+# */
|
||||
/* Updated: 2024/02/04 14:48:22 by adjoly ### ########.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 (!big && len == 0)
|
||||
return (NULL);
|
||||
if (*little == '\0' || little == big)
|
||||
return ((char *)big);
|
||||
while (i < len && big[i])
|
||||
{
|
||||
j = 0;
|
||||
while (big[i + j] == little[j] && little[j] && big[i] && i + j < len)
|
||||
j++;
|
||||
if (little[j] == 0)
|
||||
return ((char *)big + i);
|
||||
i++;
|
||||
}
|
||||
return (NULL);
|
||||
}
|
33
libft/str/ft_strrchr.c
Normal file
33
libft/str/ft_strrchr.c
Normal file
@ -0,0 +1,33 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strrchr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/08 14:44:26 by adjoly #+# #+# */
|
||||
/* Updated: 2024/02/04 14:48:34 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../libft.h"
|
||||
|
||||
char *ft_strrchr(const char *s, int c)
|
||||
{
|
||||
size_t i;
|
||||
size_t len_s;
|
||||
|
||||
len_s = ft_strlen(s);
|
||||
i = len_s;
|
||||
if (c == 0)
|
||||
return (&((char *)s)[len_s]);
|
||||
while (i > 0)
|
||||
{
|
||||
if (s[i] == (char)c)
|
||||
return (&((char *)s)[i]);
|
||||
i--;
|
||||
}
|
||||
if (s[0] == (char)c)
|
||||
return (&((char *)s)[0]);
|
||||
return (NULL);
|
||||
}
|
31
libft/str/ft_strtrim.c
Normal file
31
libft/str/ft_strtrim.c
Normal file
@ -0,0 +1,31 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strtrim.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/11 00:37:37 by adjoly #+# #+# */
|
||||
/* Updated: 2024/02/04 14:48:45 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../libft.h"
|
||||
|
||||
char *ft_strtrim(char const *s1, char const *set)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
char *result;
|
||||
|
||||
i = 0;
|
||||
if (s1 == NULL || set == NULL)
|
||||
return (NULL);
|
||||
j = ft_strlen(s1);
|
||||
while (ft_strchr(set, s1[i]) != 0)
|
||||
i++;
|
||||
while (ft_strrchr(set, s1[j]) != 0)
|
||||
j--;
|
||||
result = ft_substr(s1, i, (j - i) + 1);
|
||||
return (result);
|
||||
}
|
37
libft/str/ft_substr.c
Normal file
37
libft/str/ft_substr.c
Normal file
@ -0,0 +1,37 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_substr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/02 17:59:58 by adjoly #+# #+# */
|
||||
/* Updated: 2024/02/04 14:48:54 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../libft.h"
|
||||
|
||||
char *ft_substr(char const *s, unsigned int start, size_t len)
|
||||
{
|
||||
size_t i;
|
||||
char *result;
|
||||
|
||||
i = 0;
|
||||
if (s == NULL)
|
||||
return (0);
|
||||
if (len >= ft_strlen(s))
|
||||
len = ft_strlen(s) - start;
|
||||
if (len == 0 || start >= ft_strlen(s))
|
||||
return (ft_calloc(1, 1));
|
||||
result = malloc((len + 1) * sizeof(char));
|
||||
if (result == NULL)
|
||||
return (NULL);
|
||||
while (i < len && s[start + i])
|
||||
{
|
||||
result[i] = s[start + i];
|
||||
i++;
|
||||
}
|
||||
result[i] = '\0';
|
||||
return (result);
|
||||
}
|
18
libft/str/ft_tolower.c
Normal file
18
libft/str/ft_tolower.c
Normal file
@ -0,0 +1,18 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_tolower.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/10/31 17:15:28 by adjoly #+# #+# */
|
||||
/* Updated: 2023/10/31 17:26:10 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_tolower(int c)
|
||||
{
|
||||
if (c >= 'A' && c <= 'Z')
|
||||
return (c + 32);
|
||||
return (c);
|
||||
}
|
18
libft/str/ft_toupper.c
Normal file
18
libft/str/ft_toupper.c
Normal file
@ -0,0 +1,18 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_toupper.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/10/31 17:15:28 by adjoly #+# #+# */
|
||||
/* Updated: 2023/10/31 17:26:15 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_toupper(int c)
|
||||
{
|
||||
if (c >= 'a' && c <= 'z')
|
||||
return (c - 32);
|
||||
return (c);
|
||||
}
|
Reference in New Issue
Block a user