add libft
This commit is contained in:
parent
3a5a4a5435
commit
e9262b7fdd
69
libft/Makefile
Normal file
69
libft/Makefile
Normal file
@ -0,0 +1,69 @@
|
||||
NAME = libft.a
|
||||
SRCS = ft_memset.c \
|
||||
ft_bzero.c \
|
||||
ft_memcpy.c \
|
||||
ft_memccpy.c \
|
||||
ft_memmove.c \
|
||||
ft_memchr.c \
|
||||
ft_memcmp.c \
|
||||
ft_strlen.c \
|
||||
ft_isalpha.c \
|
||||
ft_isdigit.c \
|
||||
ft_isalnum.c \
|
||||
ft_isascii.c \
|
||||
ft_isprint.c \
|
||||
ft_toupper.c \
|
||||
ft_tolower.c \
|
||||
ft_strchr.c \
|
||||
ft_strrchr.c \
|
||||
ft_strncmp.c \
|
||||
ft_strlcpy.c \
|
||||
ft_strlcat.c \
|
||||
ft_strnstr.c \
|
||||
ft_atoi.c \
|
||||
ft_calloc.c \
|
||||
ft_strdup.c \
|
||||
ft_substr.c \
|
||||
ft_strtrim.c \
|
||||
ft_split.c \
|
||||
ft_strjoin.c \
|
||||
ft_itoa.c \
|
||||
ft_strmapi.c \
|
||||
ft_putchar_fd.c \
|
||||
ft_putstr_fd.c \
|
||||
ft_putendl_fd.c \
|
||||
ft_putnbr_fd.c \
|
||||
get_next_line.c \
|
||||
get_next_line_utils.c \
|
||||
double_utils.c
|
||||
OBJS = ${SRCS:.c=.o}
|
||||
BONUS_C = ft_lstnew.c ft_lstadd_front.c ft_lstsize.c ft_lstlast.c ft_lstadd_back.c \
|
||||
ft_lstdelone.c ft_lstclear.c ft_lstiter.c ft_lstmap.c ft_lstbeforelast.c
|
||||
BONUS_O = ${BONUS_C:.c=.o}
|
||||
CC = gcc
|
||||
CFLAGS = -Wall -Wextra
|
||||
RM = rm -rf
|
||||
|
||||
.c.o:
|
||||
@${CC} ${CFLAGS} -c $< -o ${<:.c=.o}
|
||||
|
||||
${NAME}:${OBJS}
|
||||
@ar -rcs ${NAME} ${OBJS}
|
||||
|
||||
all: ${NAME}
|
||||
|
||||
bonus: all
|
||||
@${CC} ${CFLAGS} -c ${BONUS_C}
|
||||
@ar -rcs ${NAME} ${BONUS_O}
|
||||
|
||||
clean:
|
||||
@${RM} ${OBJS}
|
||||
@${RM} ${BONUS_O}
|
||||
|
||||
fclean: clean
|
||||
@${RM} ${NAME}
|
||||
|
||||
re: fclean all
|
||||
|
||||
.PHONY: all clean fclean re bonus
|
||||
|
||||
54
libft/double_utils.c
Normal file
54
libft/double_utils.c
Normal file
@ -0,0 +1,54 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* double_utils.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/05/02 18:16:18 by apommier #+# #+# */
|
||||
/* Updated: 2022/05/02 18:16:28 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int double_size(char **tab)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
if (tab == 0)
|
||||
return (0);
|
||||
while (tab[i])
|
||||
i++;
|
||||
return (i);
|
||||
}
|
||||
|
||||
void free_double(char **tab)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
if (tab)
|
||||
{
|
||||
while (tab[i])
|
||||
free(tab[i++]);
|
||||
free(tab);
|
||||
}
|
||||
}
|
||||
|
||||
void print_double_fd(char **tab, int fd)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
if (tab)
|
||||
{
|
||||
while (tab[i])
|
||||
{
|
||||
ft_putstr_fd(tab[i], fd);
|
||||
ft_putstr_fd("\n", fd);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
39
libft/ft_atoi.c
Normal file
39
libft/ft_atoi.c
Normal file
@ -0,0 +1,39 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_atoi.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2020/11/29 00:09:17 by apommier #+# #+# */
|
||||
/* Updated: 2022/01/18 06:50:22 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
long ft_atoi(const char *nptr)
|
||||
{
|
||||
int i;
|
||||
long nbr;
|
||||
long minus;
|
||||
|
||||
minus = 1;
|
||||
nbr = 0;
|
||||
i = 0;
|
||||
while ((nptr[i] >= 9 && nptr[i] <= 13) || nptr[i] == 32)
|
||||
i++;
|
||||
if (nptr[i] == '+')
|
||||
i++;
|
||||
else if (nptr[i] == '-')
|
||||
{
|
||||
i++;
|
||||
minus = -1;
|
||||
}
|
||||
while (nptr[i] >= '0' && nptr[i] <= '9')
|
||||
{
|
||||
nbr = nbr * 10 + nptr[i] - '0';
|
||||
i++;
|
||||
}
|
||||
return (minus * nbr);
|
||||
}
|
||||
28
libft/ft_bzero.c
Normal file
28
libft/ft_bzero.c
Normal file
@ -0,0 +1,28 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_bzero.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2020/11/29 00:09:48 by apommier #+# #+# */
|
||||
/* Updated: 2022/01/17 11:26:30 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_bzero(void *s, size_t n)
|
||||
{
|
||||
char *p;
|
||||
int i;
|
||||
|
||||
p = (char *)s;
|
||||
i = 0;
|
||||
while (n != 0)
|
||||
{
|
||||
p[i] = 0;
|
||||
i++;
|
||||
n--;
|
||||
}
|
||||
}
|
||||
31
libft/ft_calloc.c
Normal file
31
libft/ft_calloc.c
Normal file
@ -0,0 +1,31 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_calloc.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2020/11/29 00:09:57 by apommier #+# #+# */
|
||||
/* Updated: 2022/01/17 21:18:04 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void *ft_calloc(size_t nmemb, size_t size)
|
||||
{
|
||||
char *new;
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
new = malloc(size * nmemb);
|
||||
if (new)
|
||||
{
|
||||
while (size * nmemb - i)
|
||||
{
|
||||
new[i] = 0;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
return ((void *)new);
|
||||
}
|
||||
23
libft/ft_isalnum.c
Normal file
23
libft/ft_isalnum.c
Normal file
@ -0,0 +1,23 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_isalnum.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2020/11/29 00:10:08 by apommier #+# #+# */
|
||||
/* Updated: 2020/12/12 09:26:43 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_isalnum(int c)
|
||||
{
|
||||
if (c <= '9' && c >= '0')
|
||||
return (1);
|
||||
else if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z'))
|
||||
return (1);
|
||||
else
|
||||
return (0);
|
||||
}
|
||||
21
libft/ft_isalpha.c
Normal file
21
libft/ft_isalpha.c
Normal file
@ -0,0 +1,21 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_isalpha.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2020/11/29 00:10:17 by apommier #+# #+# */
|
||||
/* Updated: 2020/12/12 09:28:12 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_isalpha(int c)
|
||||
{
|
||||
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
|
||||
return (1);
|
||||
else
|
||||
return (0);
|
||||
}
|
||||
21
libft/ft_isascii.c
Normal file
21
libft/ft_isascii.c
Normal file
@ -0,0 +1,21 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_isascii.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2020/11/29 00:10:30 by apommier #+# #+# */
|
||||
/* Updated: 2020/12/11 18:11:18 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_isascii(int c)
|
||||
{
|
||||
if (c >= 0 && c <= 127)
|
||||
return (1);
|
||||
else
|
||||
return (0);
|
||||
}
|
||||
21
libft/ft_isdigit.c
Normal file
21
libft/ft_isdigit.c
Normal file
@ -0,0 +1,21 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_isdigit.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2020/11/29 00:10:39 by apommier #+# #+# */
|
||||
/* Updated: 2020/12/12 09:27:06 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_isdigit(int c)
|
||||
{
|
||||
if (c <= '9' && c >= '0')
|
||||
return (1);
|
||||
else
|
||||
return (0);
|
||||
}
|
||||
21
libft/ft_isprint.c
Normal file
21
libft/ft_isprint.c
Normal file
@ -0,0 +1,21 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_isprint.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2020/11/29 00:10:55 by apommier #+# #+# */
|
||||
/* Updated: 2020/12/11 18:11:43 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_isprint(int c)
|
||||
{
|
||||
if (c > 31 && c < 127)
|
||||
return (1);
|
||||
else
|
||||
return (0);
|
||||
}
|
||||
59
libft/ft_itoa.c
Normal file
59
libft/ft_itoa.c
Normal file
@ -0,0 +1,59 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_itoa.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2020/12/08 18:20:19 by apommier #+# #+# */
|
||||
/* Updated: 2022/01/17 11:28:01 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
static char *fill(long n, int j, int minus)
|
||||
{
|
||||
char *dest;
|
||||
|
||||
j += minus;
|
||||
dest = (char *)malloc(sizeof(char) * (j + 1));
|
||||
if (dest == 0)
|
||||
return (0);
|
||||
dest[j] = 0;
|
||||
if (n == 0)
|
||||
dest[j - 1] = '0';
|
||||
while (n)
|
||||
{
|
||||
dest[j - 1] = n % 10 + '0';
|
||||
j--;
|
||||
n /= 10;
|
||||
}
|
||||
if (minus)
|
||||
dest[j - 1] = '-';
|
||||
return (dest);
|
||||
}
|
||||
|
||||
char *ft_itoa(int n)
|
||||
{
|
||||
long i;
|
||||
long k;
|
||||
int j;
|
||||
int minus;
|
||||
|
||||
k = n;
|
||||
minus = 0;
|
||||
j = 1;
|
||||
if (k < 0)
|
||||
{
|
||||
minus = 1;
|
||||
k = k * -1;
|
||||
}
|
||||
i = k;
|
||||
while (k >= 10)
|
||||
{
|
||||
k /= 10;
|
||||
j++;
|
||||
}
|
||||
return (fill(i, j, minus));
|
||||
}
|
||||
21
libft/ft_lstadd_back.c
Normal file
21
libft/ft_lstadd_back.c
Normal file
@ -0,0 +1,21 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstadd_back.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <alexpomms@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2020/12/09 19:30:14 by apommier #+# #+# */
|
||||
/* Updated: 2020/12/11 15:32:53 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_lstadd_back(t_list **alst, t_list *new)
|
||||
{
|
||||
if (*alst == 0)
|
||||
*alst = new;
|
||||
else
|
||||
ft_lstlast(*alst)->next = new;
|
||||
}
|
||||
19
libft/ft_lstadd_front.c
Normal file
19
libft/ft_lstadd_front.c
Normal file
@ -0,0 +1,19 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstadd_front.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <alexpomms@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2020/12/09 01:31:45 by apommier #+# #+# */
|
||||
/* Updated: 2020/12/11 17:34:24 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_lstadd_front(t_list **alst, t_list *new)
|
||||
{
|
||||
new->next = *alst;
|
||||
*alst = new;
|
||||
}
|
||||
28
libft/ft_lstbeforelast.c
Normal file
28
libft/ft_lstbeforelast.c
Normal file
@ -0,0 +1,28 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstbeforelast.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/12/09 19:16:55 by apommier #+# #+# */
|
||||
/* Updated: 2022/01/17 11:28:22 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
t_list *ft_lstbeforelast(t_list *lst)
|
||||
{
|
||||
t_list *save;
|
||||
|
||||
save = 0;
|
||||
if (!lst)
|
||||
return (0);
|
||||
while (lst->next)
|
||||
{
|
||||
save = lst;
|
||||
lst = lst->next;
|
||||
}
|
||||
return (save);
|
||||
}
|
||||
28
libft/ft_lstclear.c
Normal file
28
libft/ft_lstclear.c
Normal file
@ -0,0 +1,28 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstclear.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2020/12/09 19:58:04 by apommier #+# #+# */
|
||||
/* Updated: 2022/01/17 11:28:39 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_lstclear(t_list **lst, void (*del)(void*))
|
||||
{
|
||||
t_list *chr;
|
||||
|
||||
chr = *lst;
|
||||
while (*lst)
|
||||
{
|
||||
chr = (*lst)->next;
|
||||
del((*lst)->nbr);
|
||||
free(*lst);
|
||||
*lst = chr;
|
||||
}
|
||||
lst = 0;
|
||||
}
|
||||
21
libft/ft_lstdelone.c
Normal file
21
libft/ft_lstdelone.c
Normal file
@ -0,0 +1,21 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstdelone.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <alexpomms@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2020/12/09 19:54:40 by apommier #+# #+# */
|
||||
/* Updated: 2020/12/12 09:10:11 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_lstdelone(t_list *lst, void (*del)(void*))
|
||||
{
|
||||
if (!lst)
|
||||
return ;
|
||||
del(lst->nbr);
|
||||
free(lst);
|
||||
}
|
||||
22
libft/ft_lstiter.c
Normal file
22
libft/ft_lstiter.c
Normal file
@ -0,0 +1,22 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstiter.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <alexpomms@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2020/12/09 20:14:47 by apommier #+# #+# */
|
||||
/* Updated: 2020/12/11 17:47:39 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_lstiter(t_list *lst, void (*f)(void *))
|
||||
{
|
||||
while (lst)
|
||||
{
|
||||
f(lst->nbr);
|
||||
lst = lst->next;
|
||||
}
|
||||
}
|
||||
22
libft/ft_lstlast.c
Normal file
22
libft/ft_lstlast.c
Normal file
@ -0,0 +1,22 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstlast.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2020/12/09 19:16:55 by apommier #+# #+# */
|
||||
/* Updated: 2021/11/26 01:21:39 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
t_list *ft_lstlast(t_list *lst)
|
||||
{
|
||||
if (!lst)
|
||||
return (0);
|
||||
while (lst->next)
|
||||
lst = lst->next;
|
||||
return (lst);
|
||||
}
|
||||
33
libft/ft_lstmap.c
Normal file
33
libft/ft_lstmap.c
Normal file
@ -0,0 +1,33 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstmap.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <alexpomms@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2020/12/11 00:10:12 by apommier #+# #+# */
|
||||
/* Updated: 2020/12/13 22:37:30 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *))
|
||||
{
|
||||
t_list *new;
|
||||
t_list *begin;
|
||||
|
||||
begin = 0;
|
||||
while (lst)
|
||||
{
|
||||
new = ft_lstnew(f(lst->nbr));
|
||||
if (!new)
|
||||
{
|
||||
ft_lstclear(&begin, *del);
|
||||
return (0);
|
||||
}
|
||||
ft_lstadd_back(&begin, new);
|
||||
lst = lst->next;
|
||||
}
|
||||
return (begin);
|
||||
}
|
||||
26
libft/ft_lstnew.c
Normal file
26
libft/ft_lstnew.c
Normal file
@ -0,0 +1,26 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstnew.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2020/12/09 01:06:20 by apommier #+# #+# */
|
||||
/* Updated: 2022/01/17 11:29:09 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
t_list *ft_lstnew(void *content)
|
||||
{
|
||||
t_list *new;
|
||||
|
||||
new = (t_list *)malloc(sizeof(t_list));
|
||||
if (!new)
|
||||
return (0);
|
||||
new->swap = 0;
|
||||
new->nbr = content;
|
||||
new->next = 0;
|
||||
return (new);
|
||||
}
|
||||
26
libft/ft_lstsize.c
Normal file
26
libft/ft_lstsize.c
Normal file
@ -0,0 +1,26 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstsize.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <alexpomms@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2020/12/09 03:24:50 by apommier #+# #+# */
|
||||
/* Updated: 2020/12/11 15:33:49 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_lstsize(t_list *lst)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (lst)
|
||||
{
|
||||
lst = lst->next;
|
||||
i++;
|
||||
}
|
||||
return (i);
|
||||
}
|
||||
32
libft/ft_memccpy.c
Normal file
32
libft/ft_memccpy.c
Normal file
@ -0,0 +1,32 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memccpy.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2020/11/29 00:11:04 by apommier #+# #+# */
|
||||
/* Updated: 2022/01/17 11:29:38 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void *ft_memccpy(void *dest, const void *src, int c, size_t n)
|
||||
{
|
||||
char *p;
|
||||
const char *p1;
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
p = (char *)dest;
|
||||
p1 = (const char *)src;
|
||||
while (i < n)
|
||||
{
|
||||
p[i] = p1[i];
|
||||
if ((unsigned char)p[i] == (unsigned char)c)
|
||||
return (dest + i + 1);
|
||||
i++;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
28
libft/ft_memchr.c
Normal file
28
libft/ft_memchr.c
Normal file
@ -0,0 +1,28 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memchr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2020/11/29 00:11:39 by apommier #+# #+# */
|
||||
/* Updated: 2022/01/17 11:29:51 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void *ft_memchr(const void *s, int c, size_t n)
|
||||
{
|
||||
unsigned char *str;
|
||||
|
||||
str = (unsigned char *)s;
|
||||
while (n)
|
||||
{
|
||||
if ((unsigned char)c == *str)
|
||||
return (str);
|
||||
n--;
|
||||
str++;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
28
libft/ft_memcmp.c
Normal file
28
libft/ft_memcmp.c
Normal file
@ -0,0 +1,28 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memcmp.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2020/11/29 00:11:51 by apommier #+# #+# */
|
||||
/* Updated: 2022/01/17 11:30:32 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_memcmp(const void *s1, const void *s2, size_t n)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (n)
|
||||
{
|
||||
if (((unsigned char *)s1)[i] != ((unsigned char *)s2)[i])
|
||||
return (((unsigned char *)s1)[i] - ((unsigned char *)s2)[i]);
|
||||
n--;
|
||||
i++;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
32
libft/ft_memcpy.c
Normal file
32
libft/ft_memcpy.c
Normal file
@ -0,0 +1,32 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memcpy.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2020/11/29 00:12:03 by apommier #+# #+# */
|
||||
/* Updated: 2022/01/17 11:30:43 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void *ft_memcpy(void *dest, const void *src, size_t n)
|
||||
{
|
||||
size_t i;
|
||||
char *p;
|
||||
const char *p1;
|
||||
|
||||
if (!dest && !src)
|
||||
return (dest);
|
||||
p = (char *)dest;
|
||||
p1 = (const char *)src;
|
||||
i = 0;
|
||||
while (i < n)
|
||||
{
|
||||
p[i] = p1[i];
|
||||
i++;
|
||||
}
|
||||
return (dest);
|
||||
}
|
||||
39
libft/ft_memmove.c
Normal file
39
libft/ft_memmove.c
Normal file
@ -0,0 +1,39 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memmove.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2020/11/29 00:12:14 by apommier #+# #+# */
|
||||
/* Updated: 2022/01/17 11:31:05 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void *ft_memmove(void *dest, const void *src, size_t n)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
if (!dest && !src)
|
||||
return (dest);
|
||||
if (dest > src)
|
||||
{
|
||||
while (n)
|
||||
{
|
||||
((unsigned char *)dest)[n - 1] = ((unsigned char *)src)[n - 1];
|
||||
n--;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
while (i < n)
|
||||
{
|
||||
((unsigned char *)dest)[i] = ((unsigned char *)src)[i];
|
||||
i++;
|
||||
}
|
||||
}
|
||||
return (dest);
|
||||
}
|
||||
29
libft/ft_memset.c
Normal file
29
libft/ft_memset.c
Normal file
@ -0,0 +1,29 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memset.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2020/11/29 00:12:24 by apommier #+# #+# */
|
||||
/* Updated: 2022/01/17 11:31:28 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void *ft_memset(void *s, int c, size_t n)
|
||||
{
|
||||
int i;
|
||||
unsigned char *p;
|
||||
|
||||
i = 0;
|
||||
p = (unsigned char *)s;
|
||||
while (n > 0)
|
||||
{
|
||||
p[i] = (unsigned char)c;
|
||||
i++;
|
||||
n--;
|
||||
}
|
||||
return (s);
|
||||
}
|
||||
18
libft/ft_putchar_fd.c
Normal file
18
libft/ft_putchar_fd.c
Normal file
@ -0,0 +1,18 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putchar_fd.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <alexpomms@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2020/12/08 23:11:29 by apommier #+# #+# */
|
||||
/* Updated: 2020/12/11 17:02:13 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_putchar_fd(char c, int fd)
|
||||
{
|
||||
write(fd, &c, 1);
|
||||
}
|
||||
21
libft/ft_putendl_fd.c
Normal file
21
libft/ft_putendl_fd.c
Normal file
@ -0,0 +1,21 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putendl_fd.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <alexpomms@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2020/12/08 23:22:10 by apommier #+# #+# */
|
||||
/* Updated: 2020/12/11 17:14:52 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_putendl_fd(char *s, int fd)
|
||||
{
|
||||
if (s == 0)
|
||||
return ;
|
||||
write(fd, s, ft_strlen(s));
|
||||
ft_putchar_fd('\n', fd);
|
||||
}
|
||||
28
libft/ft_putnbr_fd.c
Normal file
28
libft/ft_putnbr_fd.c
Normal file
@ -0,0 +1,28 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putnbr_fd.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2020/12/08 23:25:57 by apommier #+# #+# */
|
||||
/* Updated: 2022/01/17 11:31:56 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_putnbr_fd(int n, int fd)
|
||||
{
|
||||
long nbr;
|
||||
|
||||
nbr = n;
|
||||
if (nbr < 0)
|
||||
{
|
||||
ft_putchar_fd('-', fd);
|
||||
nbr *= -1;
|
||||
}
|
||||
if (nbr >= 10)
|
||||
ft_putnbr_fd(nbr / 10, fd);
|
||||
ft_putchar_fd(nbr % 10 + '0', fd);
|
||||
}
|
||||
20
libft/ft_putstr_fd.c
Normal file
20
libft/ft_putstr_fd.c
Normal file
@ -0,0 +1,20 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putstr_fd.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <alexpomms@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2020/12/08 23:15:25 by apommier #+# #+# */
|
||||
/* Updated: 2020/12/11 17:15:10 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_putstr_fd(char *s, int fd)
|
||||
{
|
||||
if (s == 0)
|
||||
return ;
|
||||
write(fd, s, ft_strlen(s));
|
||||
}
|
||||
80
libft/ft_split.c
Normal file
80
libft/ft_split.c
Normal file
@ -0,0 +1,80 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_split.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2020/12/07 00:54:12 by apommier #+# #+# */
|
||||
/* Updated: 2022/01/21 08:09:38 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
static int fill_tab(char *s, char c, char **dest, size_t index)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (s[i] != c && s[i])
|
||||
i++;
|
||||
dest[index] = (char *)ft_calloc(i + 1, sizeof(char));
|
||||
if (dest[index] == 0)
|
||||
return (0);
|
||||
i = 0;
|
||||
while (s[i] != c && s[i])
|
||||
{
|
||||
dest[index][i] = s[i];
|
||||
i++;
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
|
||||
static void call(char *s, char c, char **dest, int j)
|
||||
{
|
||||
int index;
|
||||
int k;
|
||||
|
||||
k = 0;
|
||||
index = 0;
|
||||
while (j > index)
|
||||
{
|
||||
while (s[k] == c && s[k])
|
||||
k++;
|
||||
if (!s[k])
|
||||
return ;
|
||||
fill_tab(s + k, c, dest, index);
|
||||
index++;
|
||||
while (s[k] != c && s[k])
|
||||
k++;
|
||||
}
|
||||
}
|
||||
|
||||
char **ft_split(char const *s, char c)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
char **dest;
|
||||
|
||||
j = 0;
|
||||
i = 0;
|
||||
if (!s)
|
||||
return (0);
|
||||
while (s[i] == c && s[i])
|
||||
i++;
|
||||
while (s[i])
|
||||
{
|
||||
while (s[i] != c && s[i])
|
||||
i++;
|
||||
j++;
|
||||
while (s[i] == c && s[i])
|
||||
i++;
|
||||
}
|
||||
dest = (char **)ft_calloc(sizeof(char *), (i + j));
|
||||
if (!dest)
|
||||
return (0);
|
||||
dest[j] = 0;
|
||||
call((char *)s, c, dest, j);
|
||||
return (dest);
|
||||
}
|
||||
28
libft/ft_strchr.c
Normal file
28
libft/ft_strchr.c
Normal file
@ -0,0 +1,28 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strchr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2020/12/12 13:57:59 by apommier #+# #+# */
|
||||
/* Updated: 2022/01/17 21:18:59 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strchr(const char *s, int c)
|
||||
{
|
||||
char *str;
|
||||
|
||||
if (!s)
|
||||
return ("no s");
|
||||
str = (char *)s;
|
||||
while ((*str != c) && (*str != 0))
|
||||
str++;
|
||||
if (*str == c)
|
||||
return ((char *)str);
|
||||
else
|
||||
return (0);
|
||||
}
|
||||
34
libft/ft_strdup.c
Normal file
34
libft/ft_strdup.c
Normal file
@ -0,0 +1,34 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strdup.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2020/11/29 00:12:43 by apommier #+# #+# */
|
||||
/* Updated: 2020/12/11 18:35:10 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strdup(const char *s)
|
||||
{
|
||||
int i;
|
||||
char *sdup;
|
||||
|
||||
i = 0;
|
||||
while (s[i])
|
||||
i++;
|
||||
sdup = malloc(sizeof(char) * (i + 1));
|
||||
if (sdup == 0)
|
||||
return (0);
|
||||
i = 0;
|
||||
while (s[i])
|
||||
{
|
||||
sdup[i] = s[i];
|
||||
i++;
|
||||
}
|
||||
sdup[i] = 0;
|
||||
return (sdup);
|
||||
}
|
||||
41
libft/ft_strjoin.c
Normal file
41
libft/ft_strjoin.c
Normal file
@ -0,0 +1,41 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strjoin.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/01/20 21:44:01 by apommier #+# #+# */
|
||||
/* Updated: 2022/01/21 08:07:04 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strjoin(char *save, char *s2)
|
||||
{
|
||||
char *dest;
|
||||
int i;
|
||||
int j;
|
||||
|
||||
i = 0;
|
||||
j = 0;
|
||||
if (!save && !s2)
|
||||
return (0);
|
||||
dest = malloc(ft_strlen(save) + ft_strlen(s2) + 1);
|
||||
while (save && save[i])
|
||||
{
|
||||
dest[j] = save[i];
|
||||
j++;
|
||||
i++;
|
||||
}
|
||||
i = 0;
|
||||
while (s2 && s2[i])
|
||||
{
|
||||
dest[j] = s2[i];
|
||||
j++;
|
||||
i++;
|
||||
}
|
||||
dest[j] = 0;
|
||||
return (dest);
|
||||
}
|
||||
34
libft/ft_strlcat.c
Normal file
34
libft/ft_strlcat.c
Normal file
@ -0,0 +1,34 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strlcat.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2020/11/29 00:12:57 by apommier #+# #+# */
|
||||
/* Updated: 2020/12/12 15:40:58 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
size_t ft_strlcat(char *dst, const char *src, size_t size)
|
||||
{
|
||||
size_t i;
|
||||
size_t k;
|
||||
|
||||
if (!size)
|
||||
return (ft_strlen(src));
|
||||
i = 0;
|
||||
k = ft_strlen(dst);
|
||||
if (k >= size)
|
||||
return (ft_strlen(src) + size);
|
||||
while (size - k - 1 && src[i])
|
||||
{
|
||||
dst[k + i] = src[i];
|
||||
i++;
|
||||
size--;
|
||||
}
|
||||
dst[k + i] = 0;
|
||||
return (k + ft_strlen(src));
|
||||
}
|
||||
36
libft/ft_strlcpy.c
Normal file
36
libft/ft_strlcpy.c
Normal file
@ -0,0 +1,36 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strlcpy.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2020/11/29 00:13:07 by apommier #+# #+# */
|
||||
/* Updated: 2022/01/17 11:38:48 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
size_t ft_strlcpy(char *dst, const char *src, size_t size)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
|
||||
j = 0;
|
||||
i = 0;
|
||||
if (!src || !dst)
|
||||
return (0);
|
||||
while (src[i])
|
||||
i++;
|
||||
if (!size)
|
||||
return (i);
|
||||
while (size - 1 && src[j] != 0)
|
||||
{
|
||||
dst[j] = src[j];
|
||||
j++;
|
||||
size--;
|
||||
}
|
||||
dst[j] = 0;
|
||||
return (i);
|
||||
}
|
||||
25
libft/ft_strlen.c
Normal file
25
libft/ft_strlen.c
Normal file
@ -0,0 +1,25 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strlen.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2020/11/29 00:13:19 by apommier #+# #+# */
|
||||
/* Updated: 2022/01/17 21:12:05 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
size_t ft_strlen(const char *s)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
if (!s)
|
||||
return (0);
|
||||
while (s[i] != 0)
|
||||
i++;
|
||||
return (i);
|
||||
}
|
||||
32
libft/ft_strmapi.c
Normal file
32
libft/ft_strmapi.c
Normal file
@ -0,0 +1,32 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strmapi.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2020/12/08 19:03:09 by apommier #+# #+# */
|
||||
/* Updated: 2022/01/17 11:39:05 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
|
||||
{
|
||||
char *dest;
|
||||
int i;
|
||||
|
||||
if (!s)
|
||||
return (0);
|
||||
i = 0;
|
||||
dest = (char *)ft_calloc(ft_strlen(s) + 1, sizeof(char));
|
||||
if (!dest)
|
||||
return (0);
|
||||
while (s[i])
|
||||
{
|
||||
dest[i] = f(i, s[i]);
|
||||
i++;
|
||||
}
|
||||
return (dest);
|
||||
}
|
||||
44
libft/ft_strncmp.c
Normal file
44
libft/ft_strncmp.c
Normal file
@ -0,0 +1,44 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strncmp.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2020/11/29 00:13:31 by apommier #+# #+# */
|
||||
/* Updated: 2022/02/14 00:27:01 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_strncmp(const char *s1, const char *s2, size_t n)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (n && (s1[i] || s2[i]))
|
||||
{
|
||||
if (s1[i] != s2[i])
|
||||
return ((unsigned char)s1[i] - (unsigned char)s2[i]);
|
||||
n--;
|
||||
i++;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
int ft_strcmp(const char *s1, const char *s2)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
if (!s1 || !s2)
|
||||
return (1);
|
||||
while (s1[i] || s2[i])
|
||||
{
|
||||
if (s1[i] != s2[i])
|
||||
return ((unsigned char)s1[i] - (unsigned char)s2[i]);
|
||||
i++;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
41
libft/ft_strnstr.c
Normal file
41
libft/ft_strnstr.c
Normal file
@ -0,0 +1,41 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strnstr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2020/11/29 00:13:42 by apommier #+# #+# */
|
||||
/* Updated: 2022/01/17 11:39:28 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strnstr(const char *big, const char *little, size_t len)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
|
||||
i = 0;
|
||||
if (!little[i])
|
||||
return ((char *)big);
|
||||
if (!little[i])
|
||||
return ((char *)big);
|
||||
while (big[i] && len - i)
|
||||
{
|
||||
j = 0;
|
||||
if (little[j] != big[i])
|
||||
i++;
|
||||
else
|
||||
{
|
||||
while (little[j] == big[i + j] && little[j] && len - i - j)
|
||||
j++;
|
||||
if (little[j] == 0)
|
||||
return ((char *)&big[i]);
|
||||
else
|
||||
i++;
|
||||
}
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
35
libft/ft_strrchr.c
Normal file
35
libft/ft_strrchr.c
Normal file
@ -0,0 +1,35 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strrchr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2020/11/29 00:13:52 by apommier #+# #+# */
|
||||
/* Updated: 2022/01/17 11:39:37 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strrchr(const char *s, int c)
|
||||
{
|
||||
char *str;
|
||||
char *last;
|
||||
|
||||
str = (char *)s;
|
||||
if (c == 0)
|
||||
{
|
||||
while (*str)
|
||||
str++;
|
||||
return (str);
|
||||
}
|
||||
last = 0;
|
||||
while (*str)
|
||||
{
|
||||
if (*str == c)
|
||||
last = str;
|
||||
str++;
|
||||
}
|
||||
return (last);
|
||||
}
|
||||
72
libft/ft_strtrim.c
Normal file
72
libft/ft_strtrim.c
Normal file
@ -0,0 +1,72 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strtrim.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2020/11/29 23:52:05 by apommier #+# #+# */
|
||||
/* Updated: 2022/01/17 11:40:17 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
static int is_set(char const *set, char c)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (set[i])
|
||||
{
|
||||
if (set[i] == c)
|
||||
return (1);
|
||||
i++;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int len_dest(const char *s1, char const *set)
|
||||
{
|
||||
int len;
|
||||
int j;
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
j = 0;
|
||||
len = ft_strlen(s1);
|
||||
while (is_set(set, s1[i]))
|
||||
i++;
|
||||
while (is_set(set, s1[len - j - 1]))
|
||||
j++;
|
||||
len = len - j - i;
|
||||
if (len < 0)
|
||||
len = 0;
|
||||
return (len);
|
||||
}
|
||||
|
||||
char *ft_strtrim(char const *s1, char const *set)
|
||||
{
|
||||
int j;
|
||||
int i;
|
||||
int len;
|
||||
char *dest;
|
||||
|
||||
i = 0;
|
||||
j = 0;
|
||||
if (!s1)
|
||||
return (0);
|
||||
len = len_dest(s1, set);
|
||||
dest = ft_calloc(len + 1, 1);
|
||||
if (!dest)
|
||||
return (0);
|
||||
while (is_set(set, s1[i]))
|
||||
i++;
|
||||
while (s1[i] && len - j && len > 0)
|
||||
{
|
||||
dest[j] = s1[i];
|
||||
i++;
|
||||
j++;
|
||||
}
|
||||
return (dest);
|
||||
}
|
||||
39
libft/ft_substr.c
Normal file
39
libft/ft_substr.c
Normal file
@ -0,0 +1,39 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_substr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2020/11/29 22:54:40 by apommier #+# #+# */
|
||||
/* Updated: 2020/12/16 16:45:34 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_substr(char const *s, unsigned int start, size_t len)
|
||||
{
|
||||
char *dest;
|
||||
unsigned int i;
|
||||
|
||||
if (!s)
|
||||
return (0);
|
||||
i = 0;
|
||||
dest = malloc(1 * len + 1);
|
||||
if (dest == 0)
|
||||
return (0);
|
||||
if (start > ft_strlen(s) || len == 0)
|
||||
{
|
||||
dest[i] = 0;
|
||||
return (dest);
|
||||
}
|
||||
while (len && s[i + start])
|
||||
{
|
||||
dest[i] = s[i + start];
|
||||
len--;
|
||||
i++;
|
||||
}
|
||||
dest[i] = 0;
|
||||
return (dest);
|
||||
}
|
||||
20
libft/ft_tolower.c
Normal file
20
libft/ft_tolower.c
Normal file
@ -0,0 +1,20 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_tolower.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2020/11/29 00:14:05 by apommier #+# #+# */
|
||||
/* Updated: 2020/11/29 17:20:51 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_tolower(int c)
|
||||
{
|
||||
if (c >= 65 && c <= 90)
|
||||
c = c + 32;
|
||||
return (c);
|
||||
}
|
||||
20
libft/ft_toupper.c
Normal file
20
libft/ft_toupper.c
Normal file
@ -0,0 +1,20 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_toupper.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2020/11/29 00:14:15 by apommier #+# #+# */
|
||||
/* Updated: 2020/11/29 17:21:12 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_toupper(int c)
|
||||
{
|
||||
if (c >= 'a' && c <= 'z')
|
||||
c = c - 32;
|
||||
return (c);
|
||||
}
|
||||
100
libft/get_next_line.c
Normal file
100
libft/get_next_line.c
Normal file
@ -0,0 +1,100 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* get_next_line.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: kinou <alexpomms@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/10/23 07:55:17 by kinou #+# #+# */
|
||||
/* Updated: 2021/11/01 10:21:35 by kinou ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_free(char *save, int *end)
|
||||
{
|
||||
if (!*end)
|
||||
{
|
||||
free(save);
|
||||
free(end);
|
||||
return (0);
|
||||
}
|
||||
free(end);
|
||||
return (save);
|
||||
}
|
||||
|
||||
char *set_line(char *line, char *save)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
line = ft_strjoin(save, 0);
|
||||
while (line[i] && line[i] != '\n')
|
||||
i++;
|
||||
if (line[i] == '\n')
|
||||
{
|
||||
while (line[i++])
|
||||
line[i] = '\0';
|
||||
}
|
||||
return (line);
|
||||
}
|
||||
|
||||
char *set_save(char *save)
|
||||
{
|
||||
char *delete;
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
delete = save;
|
||||
while (save[i] && save[i] != '\n')
|
||||
i++;
|
||||
if (save[i] != '\n')
|
||||
i = 0;
|
||||
save = ft_strjoin((save + i + 1), 0);
|
||||
free(delete);
|
||||
return (save);
|
||||
}
|
||||
|
||||
char *next_line(char *save, int *end, int fd)
|
||||
{
|
||||
char *delete;
|
||||
char *dest;
|
||||
|
||||
while (!ft_strchr(save, '\n') && *end > 0)
|
||||
{
|
||||
dest = ft_calloc(1, 1 + 1);
|
||||
*end = read(fd, dest, 1);
|
||||
delete = save;
|
||||
save = ft_strjoin(save, dest);
|
||||
free(delete);
|
||||
free(dest);
|
||||
}
|
||||
return (save);
|
||||
}
|
||||
|
||||
char *get_next_line(int fd)
|
||||
{
|
||||
static char *save = NULL;
|
||||
int *end;
|
||||
char *line;
|
||||
|
||||
line = 0;
|
||||
if (fd < 0)
|
||||
return (0);
|
||||
end = malloc(sizeof(int *));
|
||||
*end = 1;
|
||||
if (save == NULL)
|
||||
save = ft_calloc(1, 1);
|
||||
save = next_line(save, end, fd);
|
||||
line = set_line(line, save);
|
||||
if (ft_strlen(line) > 0)
|
||||
{
|
||||
save = set_save(save);
|
||||
save = ft_free(save, end);
|
||||
return (line);
|
||||
}
|
||||
free(line);
|
||||
save = ft_free(save, end);
|
||||
return (0);
|
||||
}
|
||||
19
libft/get_next_line.h
Normal file
19
libft/get_next_line.h
Normal file
@ -0,0 +1,19 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* get_next_line.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2020/12/14 05:58:49 by apommier #+# #+# */
|
||||
/* Updated: 2022/01/17 21:45:15 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef GET_NEXT_LINE_H
|
||||
# define GET_NEXT_LINE_H
|
||||
|
||||
char *get_next_line(int fd);
|
||||
char *ft_strjoin(char *save, char *s2);
|
||||
|
||||
#endif
|
||||
41
libft/get_next_line_utils.c
Normal file
41
libft/get_next_line_utils.c
Normal file
@ -0,0 +1,41 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* get_next_line_utils.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2020/12/14 06:05:54 by apommier #+# #+# */
|
||||
/* Updated: 2022/01/20 21:58:39 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strjoin(char *save, char *s2)
|
||||
{
|
||||
char *dest;
|
||||
int i;
|
||||
int j;
|
||||
|
||||
i = 0;
|
||||
j = 0;
|
||||
if (!save && !s2)
|
||||
return (0);
|
||||
dest = malloc(ft_strlen(save) + ft_strlen(s2) + 1);
|
||||
while (save && save[i])
|
||||
{
|
||||
dest[j] = save[i];
|
||||
j++;
|
||||
i++;
|
||||
}
|
||||
i = 0;
|
||||
while (s2 && s2[i])
|
||||
{
|
||||
dest[j] = s2[i];
|
||||
j++;
|
||||
i++;
|
||||
}
|
||||
dest[j] = 0;
|
||||
return (dest);
|
||||
}
|
||||
80
libft/libft.h
Normal file
80
libft/libft.h
Normal file
@ -0,0 +1,80 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* libft.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2020/12/11 03:21:27 by apommier #+# #+# */
|
||||
/* Updated: 2022/05/02 18:17:12 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef LIBFT_H
|
||||
# define LIBFT_H
|
||||
|
||||
# include <stdlib.h>
|
||||
# include <unistd.h>
|
||||
# include "get_next_line.h"
|
||||
|
||||
typedef struct t_slist
|
||||
{
|
||||
void *nbr;
|
||||
int index;
|
||||
int swap;
|
||||
struct t_slist *next;
|
||||
} t_list;
|
||||
|
||||
int double_size(char **tab);
|
||||
void print_double_fd(char **tab, int fd);
|
||||
void free_double(char **tab);
|
||||
void *ft_memset(void *s, int c, size_t n);
|
||||
void ft_bzero(void *s, size_t n);
|
||||
void *ft_memcpy(void *dest, const void *src, size_t n);
|
||||
void *ft_memccpy(void *dest, const void *src, int c, size_t 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);
|
||||
size_t ft_strlen(const char *s);
|
||||
int ft_isalpha(int c);
|
||||
int ft_isdigit(int c);
|
||||
int ft_isalnum(int c);
|
||||
int ft_isascii(int c);
|
||||
int ft_isprint(int c);
|
||||
int ft_toupper(int c);
|
||||
int ft_tolower(int c);
|
||||
char *ft_strchr(const char *s, int c);
|
||||
char *ft_strrchr(const char *s, int c);
|
||||
int ft_strcmp(const char *s1, const char *s2);
|
||||
int ft_strncmp(const char *s1, const char *s2, size_t n);
|
||||
size_t ft_strlcpy(char *dst, const char *src, size_t size);
|
||||
size_t ft_strlcat(char *dst, const char *src, size_t size);
|
||||
char *ft_strjoin(char *save, char *s2);
|
||||
char *ft_strnstr(const char *big, const char *little, size_t len);
|
||||
long ft_atoi(const char *nptr);
|
||||
void *ft_calloc(size_t nmenb, size_t size);
|
||||
char *ft_strdup(const char *s);
|
||||
|
||||
char *ft_substr(char const *s, unsigned int start, size_t len);
|
||||
char *ft_strtrim(char const *s1, char const *set);
|
||||
char **ft_split(char const *s, char c);
|
||||
char *ft_itoa(int n);
|
||||
char *ft_strmapi(char const *s, char (*f)(unsigned int, char));
|
||||
void ft_putchar_fd(char c, int fd);
|
||||
void ft_putstr_fd(char *s, int fd);
|
||||
void ft_putendl_fd(char *s, int fd);
|
||||
void ft_putnbr_fd(int n, int fd);
|
||||
|
||||
t_list *ft_lstnew(void *content);
|
||||
void ft_lstadd_front(t_list **alst, t_list *new);
|
||||
int ft_lstsize(t_list *lst);
|
||||
t_list *ft_lstlast(t_list *lst);
|
||||
void ft_lstadd_back(t_list **alst, 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 *));
|
||||
t_list *ft_lstbeforelast(t_list *lst);
|
||||
|
||||
#endif
|
||||
Loading…
Reference in New Issue
Block a user