mirror of
https://github.com/KeyZox71/ft_minipowershell.git
synced 2025-05-14 00:08:47 +02:00
「🔨」 fix(libft): replaced libft by a better one :D
This commit is contained in:
29
libft/src/linked_lists/ft_lstadd_back.c
Normal file
29
libft/src/linked_lists/ft_lstadd_back.c
Normal file
@ -0,0 +1,29 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstadd_back.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: mmoussou <mmoussou@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/08 17:42:57 by mmoussou #+# #+# */
|
||||
/* Updated: 2023/11/08 20:39:15 by mmoussou ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_lstadd_back(t_list **lst, t_list *new)
|
||||
{
|
||||
t_list *tmp;
|
||||
|
||||
if (!lst || !new)
|
||||
return ;
|
||||
if (!*lst)
|
||||
{
|
||||
*lst = new;
|
||||
return ;
|
||||
}
|
||||
tmp = *lst;
|
||||
tmp = ft_lstlast(*lst);
|
||||
tmp->next = new;
|
||||
}
|
26
libft/src/linked_lists/ft_lstadd_front.c
Normal file
26
libft/src/linked_lists/ft_lstadd_front.c
Normal file
@ -0,0 +1,26 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstadd_front.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: mmoussou <mmoussou@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/08 17:03:15 by mmoussou #+# #+# */
|
||||
/* Updated: 2023/11/13 19:31:32 by mmoussou ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_lstadd_front(t_list **lst, t_list *new)
|
||||
{
|
||||
t_list *tmp;
|
||||
|
||||
tmp = *lst;
|
||||
*lst = new;
|
||||
if (!new || !lst)
|
||||
return ;
|
||||
while (new->next)
|
||||
new = new->next;
|
||||
new->next = tmp;
|
||||
}
|
27
libft/src/linked_lists/ft_lstclear.c
Normal file
27
libft/src/linked_lists/ft_lstclear.c
Normal file
@ -0,0 +1,27 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstclear.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: mmoussou <mmoussou@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/08 21:44:04 by mmoussou #+# #+# */
|
||||
/* Updated: 2023/11/13 19:31:49 by mmoussou ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_lstclear(t_list **lst, void (*del)(void *))
|
||||
{
|
||||
t_list *tmp;
|
||||
|
||||
if (!lst || !del)
|
||||
return ;
|
||||
while (*lst)
|
||||
{
|
||||
tmp = (*lst)->next;
|
||||
ft_lstdelone(*lst, del);
|
||||
*lst = tmp;
|
||||
}
|
||||
}
|
22
libft/src/linked_lists/ft_lstdelone.c
Normal file
22
libft/src/linked_lists/ft_lstdelone.c
Normal file
@ -0,0 +1,22 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstdelone.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: mmoussou <mmoussou@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/08 20:40:46 by mmoussou #+# #+# */
|
||||
/* Updated: 2023/11/13 19:32:04 by mmoussou ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_lstdelone(t_list *lst, void (*del)(void *))
|
||||
{
|
||||
if (!lst || !del)
|
||||
return ;
|
||||
del(lst->content);
|
||||
free(lst);
|
||||
lst = NULL;
|
||||
}
|
25
libft/src/linked_lists/ft_lstiter.c
Normal file
25
libft/src/linked_lists/ft_lstiter.c
Normal file
@ -0,0 +1,25 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstiter.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: yosyo <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/09 12:49:19 by yosyo #+# #+# */
|
||||
/* Updated: 2023/11/13 19:32:17 by mmoussou ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_lstiter(t_list *lst, void (*f)(void *))
|
||||
{
|
||||
if (!lst || !f)
|
||||
return ;
|
||||
while (lst->next)
|
||||
{
|
||||
f(lst->content);
|
||||
lst = lst->next;
|
||||
}
|
||||
f(lst->content);
|
||||
}
|
22
libft/src/linked_lists/ft_lstlast.c
Normal file
22
libft/src/linked_lists/ft_lstlast.c
Normal file
@ -0,0 +1,22 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstlast.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: mmoussou <mmoussou@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/08 17:38:47 by mmoussou #+# #+# */
|
||||
/* Updated: 2023/11/08 20:09:47 by mmoussou ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
t_list *ft_lstlast(t_list *lst)
|
||||
{
|
||||
if (!lst)
|
||||
return (NULL);
|
||||
while (lst->next)
|
||||
lst = lst->next;
|
||||
return (lst);
|
||||
}
|
33
libft/src/linked_lists/ft_lstmap.c
Normal file
33
libft/src/linked_lists/ft_lstmap.c
Normal file
@ -0,0 +1,33 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstmap.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: yosyo <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/09 12:53:23 by yosyo #+# #+# */
|
||||
/* Updated: 2023/11/13 19:33:20 by mmoussou ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *))
|
||||
{
|
||||
t_list *r;
|
||||
t_list *tmp;
|
||||
|
||||
r = NULL;
|
||||
while (lst && f && del)
|
||||
{
|
||||
tmp = ft_lstnew(f(lst->content));
|
||||
if (!tmp)
|
||||
{
|
||||
ft_lstclear(&tmp, del);
|
||||
return (NULL);
|
||||
}
|
||||
ft_lstadd_back(&r, tmp);
|
||||
lst = lst->next;
|
||||
}
|
||||
return (r);
|
||||
}
|
25
libft/src/linked_lists/ft_lstnew.c
Normal file
25
libft/src/linked_lists/ft_lstnew.c
Normal file
@ -0,0 +1,25 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstnew.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: mmoussou <mmoussou@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/07 16:02:40 by mmoussou #+# #+# */
|
||||
/* Updated: 2023/11/08 17:02:57 by mmoussou ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
t_list *ft_lstnew(void *content)
|
||||
{
|
||||
t_list *r;
|
||||
|
||||
r = malloc(sizeof(t_list));
|
||||
if (!r)
|
||||
return (NULL);
|
||||
r->content = content;
|
||||
r->next = NULL;
|
||||
return (r);
|
||||
}
|
28
libft/src/linked_lists/ft_lstsize.c
Normal file
28
libft/src/linked_lists/ft_lstsize.c
Normal file
@ -0,0 +1,28 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstsize.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/08 17:33:51 by mmoussou #+# #+# */
|
||||
/* Updated: 2024/04/11 14:33:42 by mmoussou ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
uint ft_lstsize(t_list *lst)
|
||||
{
|
||||
uint i;
|
||||
|
||||
i = 1;
|
||||
if (!lst)
|
||||
return (0);
|
||||
while (lst->next)
|
||||
{
|
||||
lst = lst->next;
|
||||
i++;
|
||||
}
|
||||
return (i);
|
||||
}
|
Reference in New Issue
Block a user