1
0

finished libfttttttttttttttttttttttttttttttttttttt

This commit is contained in:
2023-11-11 18:45:48 +01:00
parent 6f104fc7bc
commit 42f67cc750
20 changed files with 262 additions and 4 deletions

View File

@ -6,7 +6,7 @@
# By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ # # By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ # # +#+#+#+#+#+ +#+ #
# Created: 2023/11/01 11:03:22 by adjoly #+# #+# # # Created: 2023/11/01 11:03:22 by adjoly #+# #+# #
# Updated: 2023/11/11 15:10:24 by adjoly ### ########.fr # # Updated: 2023/11/11 18:38:12 by adjoly ### ########.fr #
# # # #
# **************************************************************************** # # **************************************************************************** #
@ -49,8 +49,20 @@ SRCS = ft_atoi.c \
ft_strmapi.c \ ft_strmapi.c \
ft_striteri.c \ ft_striteri.c \
SRCS_BONUS= 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 \
OBJS = $(SRCS:.c=.o) OBJS = $(SRCS:.c=.o)
OBJS_BONUS = $(SRCS_BONUS:.c=.o)
FLAGS = -Werror -Wall -Wextra FLAGS = -Werror -Wall -Wextra
HEADER = libft.h HEADER = libft.h
@ -59,14 +71,17 @@ $(NAME): $(OBJS)
ar -rcs $(NAME) $(OBJS) ar -rcs $(NAME) $(OBJS)
# so: # so:
# $(CC) -nostartfiles -fPIC $(CFLAGS) $(SRCS) # $(CC) -nostartfiles -fPIC $(CFLAGS) $(SRCS) $(SRCS_BONUS)
# gcc -nostartfiles -shared -o libft.so $(OBJS) # gcc -nostartfiles -shared -o libft.so $(OBJS) $(OBJS_BONUS)
%.o: %.c %.o: %.c
$(CC) $(FLAGS) -I $(HEADER) $< -c -o $@ $(CC) $(FLAGS) -I $(HEADER) $< -c -o $@
all: $(NAME) all: $(NAME)
bonus: $(OBJS_BONUS)
ar -rcs $(NAME) $(OBJS_BONUS)
clean: clean:
rm -f $(OBJS) rm -f $(OBJS)

25
ft_lstadd_back.c Normal file
View File

@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstadd_back.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/11 16:37:42 by adjoly #+# #+# */
/* Updated: 2023/11/11 17:56:48 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_lstadd_back(t_list **lst, t_list *new)
{
if (lst == NULL)
return ;
if (*lst == NULL)
{
(*lst) = new;
return ;
}
ft_lstlast((*lst))->next = new;
}

BIN
ft_lstadd_back.o Normal file

Binary file not shown.

23
ft_lstadd_front.c Normal file
View File

@ -0,0 +1,23 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstadd_front.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/11 15:39:25 by adjoly #+# #+# */
/* Updated: 2023/11/11 15:50:06 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_lstadd_front(t_list **lst, t_list *new)
{
if (lst == NULL)
return ;
if (new == NULL)
return ;
new->next = *lst;
*lst = new;
}

BIN
ft_lstadd_front.o Normal file

Binary file not shown.

26
ft_lstclear.c Normal file
View File

@ -0,0 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstclear.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/11 18:05:14 by adjoly #+# #+# */
/* Updated: 2023/11/11 18:19:34 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_lstclear(t_list **lst, void (*del)(void *))
{
t_list *tmp;
tmp = NULL;
while (*lst && lst)
{
tmp = (*lst)->next;
ft_lstdelone((*lst), del);
*lst = tmp;
}
}

BIN
ft_lstclear.o Normal file

Binary file not shown.

21
ft_lstdelone.c Normal file
View File

@ -0,0 +1,21 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstdelone.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/11 17:59:39 by adjoly #+# #+# */
/* Updated: 2023/11/11 18:17:04 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_lstdelone(t_list *lst, void (*del)(void *))
{
if (lst == NULL)
return ;
del(lst->content);
free(lst);
}

BIN
ft_lstdelone.o Normal file

Binary file not shown.

24
ft_lstiter.c Normal file
View File

@ -0,0 +1,24 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstiter.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/11 18:20:25 by adjoly #+# #+# */
/* Updated: 2023/11/11 18:23:58 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_lstiter(t_list *lst, void (*f)(void *))
{
if (lst == NULL || f == NULL)
return ;
while (lst)
{
f(lst->content);
lst = lst->next;
}
}

BIN
ft_lstiter.o Normal file

Binary file not shown.

22
ft_lstlast.c Normal file
View File

@ -0,0 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstlast.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/11 16:03:12 by adjoly #+# #+# */
/* Updated: 2023/11/11 16:37:10 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
t_list *ft_lstlast(t_list *lst)
{
if (lst == NULL)
return (NULL);
while (lst->next)
lst = lst->next;
return (lst);
}

BIN
ft_lstlast.o Normal file

Binary file not shown.

35
ft_lstmap.c Normal file
View File

@ -0,0 +1,35 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstmap.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/11 18:24:49 by adjoly #+# #+# */
/* Updated: 2023/11/11 18:38:51 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 == NULL || f == NULL || del == NULL)
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);
}

BIN
ft_lstmap.o Normal file

Binary file not shown.

25
ft_lstnew.c Normal file
View File

@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstnew.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/11 15:30:32 by adjoly #+# #+# */
/* Updated: 2023/11/11 15:51:49 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
t_list *ft_lstnew(void *content)
{
t_list *lst;
lst = malloc(sizeof(t_list));
if (lst == NULL)
return (NULL);
lst[0].content = content;
lst[0].next = NULL;
return (lst);
}

BIN
ft_lstnew.o Normal file

Binary file not shown.

26
ft_lstsize.c Normal file
View File

@ -0,0 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstsize.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/11 15:53:01 by adjoly #+# #+# */
/* Updated: 2023/11/11 15:59:03 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_lstsize(t_list *lst)
{
int i;
i = 0;
while (lst != NULL)
{
lst = lst->next;
i++;
}
return (i);
}

BIN
ft_lstsize.o Normal file

Binary file not shown.

18
libft.h
View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */ /* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/01 10:06:03 by adjoly #+# #+# */ /* Created: 2023/11/01 10:06:03 by adjoly #+# #+# */
/* Updated: 2023/11/11 14:22:48 by adjoly ### ########.fr */ /* Updated: 2023/11/11 18:37:56 by adjoly ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -17,6 +17,12 @@
# include <stdlib.h> # include <stdlib.h>
# include <unistd.h> # include <unistd.h>
typedef struct s_list
{
void *content;
struct s_list *next;
} t_list;
int ft_atoi(const char *nptr); int ft_atoi(const char *nptr);
void *ft_calloc(size_t nmemb, size_t size); void *ft_calloc(size_t nmemb, size_t size);
int ft_isalnum(int c); int ft_isalnum(int c);
@ -54,4 +60,14 @@ char **ft_split(char const *s, char c);
char *ft_strmapi(char const *s, char (*f)(unsigned int, char)); char *ft_strmapi(char const *s, char (*f)(unsigned int, char));
void ft_striteri(char *s, void (*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 *));
#endif #endif