AHHHHHHHHHHHHHHHHHHHHHHHHHHHHH

This commit is contained in:
cubernetes 2023-06-26 20:46:24 +02:00
parent d21e3a9025
commit 01b559a96f
14 changed files with 215 additions and 48 deletions

View File

@ -48,13 +48,13 @@ _SRC += ft_strmapi.c
_SRC += ft_lstnew.c
_SRC += ft_lstadd_front.c
# _SRC += ft_lstadd_back.c
# _SRC += ft_lstclear
# _SRC += ft_lstdelone.c
# _SRC += ft_lstiter.c
# _SRC += ft_lstlast.c
# _SRC += ft_lstmap.c
# _SRC += ft_lstsize.c
_SRC += ft_lstsize.c
_SRC += ft_lstlast.c
_SRC += ft_lstadd_back.c
_SRC += ft_lstclear.c
_SRC += ft_lstdelone.c
_SRC += ft_lstiter.c
_SRC += ft_lstmap.c
_SRC += ft_char_in_charset.c
_SRC += ft_isspace.c

BIN
a.out Executable file

Binary file not shown.

View File

@ -0,0 +1,28 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstadd_back.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tosuman <timo42@proton.me> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/06/24 16:29:20 by tosuman #+# #+# */
/* Updated: 2023/06/24 16:38:53 by tosuman ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_lstadd_back(t_list **lst, t_list *new)
{
t_list *last;
if (!lst)
return ;
if (!*lst)
{
*lst = new;
return ;
}
last = ft_lstlast(*lst);
last->next = new;
}

View File

@ -6,7 +6,7 @@
/* By: tosuman <timo42@proton.me> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/06/14 11:57:15 by tosuman #+# #+# */
/* Updated: 2023/06/14 11:57:15 by tosuman ### ########.fr */
/* Updated: 2023/06/24 16:38:36 by tosuman ### ########.fr */
/* */
/* ************************************************************************** */
@ -14,10 +14,8 @@
void ft_lstadd_front(t_list **lst, t_list *new)
{
if (lst)
{
if (*lst)
new->next = *lst;
*lst = new;
}
if (!lst)
return ;
new->next = *lst;
*lst = new;
}

View File

29
ft_lstclear.c Normal file
View File

@ -0,0 +1,29 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstclear.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tosuman <timo42@proton.me> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/06/24 16:47:41 by tosuman #+# #+# */
/* Updated: 2023/06/24 17:06:04 by tosuman ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include <stdlib.h>
void ft_lstclear(t_list **lst, void (*del)(void *))
{
t_list *tmp;
if (!lst || !del)
return ;
tmp = *lst;
while (tmp)
{
*lst = tmp->next;
ft_lstdelone(tmp, del);
tmp = *lst;
}
}

View File

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstdelone.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tosuman <timo42@proton.me> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/06/24 16:44:13 by tosuman #+# #+# */
/* Updated: 2023/06/24 16:45:34 by tosuman ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include <stdlib.h>
void ft_lstdelone(t_list *lst, void (*del)(void *))
{
del(lst->content);
free(lst);
}

View File

@ -0,0 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstiter.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tosuman <timo42@proton.me> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/06/24 16:57:28 by tosuman #+# #+# */
/* Updated: 2023/06/24 17:26:38 by tosuman ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_lstiter(t_list *lst, void (*f)(void *))
{
while (lst)
{
(*f)(lst->content);
lst = lst->next;
}
}

View File

@ -0,0 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstlast.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tosuman <timo42@proton.me> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/06/24 16:26:09 by tosuman #+# #+# */
/* Updated: 2023/06/24 16:28:25 by tosuman ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
t_list *ft_lstlast(t_list *lst)
{
if (!lst)
return (lst);
while (lst->next)
lst = lst->next;
return (lst);
}

View File

@ -0,0 +1,42 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstmap.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tosuman <timo42@proton.me> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/06/24 17:10:04 by tosuman #+# #+# */
/* Updated: 2023/06/26 20:32:34 by tosuman ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include <stdlib.h>
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *))
{
t_list *new_lst;
t_list *new_elem;
if (!lst || !f)
return (0);
new_lst = (void *)0;
while (lst)
{
new_elem = ft_lstnew(f(lst->content));
if (!new_elem)
{
while (new_lst)
{
new_elem = new_lst->next;
del(new_lst->content);
free(new_lst);
new_lst = new_elem;
}
return (0);
}
ft_lstadd_back(&new_lst, new_elem);
lst = lst->next;
}
return (new_lst);
}

View File

@ -6,12 +6,13 @@
/* By: tosuman <timo42@proton.me> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/06/09 14:55:31 by tosuman #+# #+# */
/* Updated: 2023/06/09 14:55:31 by tosuman ### ########.fr */
/* Updated: 2023/06/24 17:36:37 by tosuman ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include <stdlib.h>
#include <stdio.h>
t_list *ft_lstnew(void *content)
{
@ -21,6 +22,6 @@ t_list *ft_lstnew(void *content)
if (!new)
return (0);
new->content = content;
new->next = 0;
new->next = (void *)0;
return (new);
}

View File

@ -0,0 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstsize.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tosuman <timo42@proton.me> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/06/24 15:46:41 by tosuman #+# #+# */
/* Updated: 2023/06/24 16:25:28 by tosuman ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_lstsize(t_list *lst)
{
int i;
i = 0;
while (lst)
{
lst = lst -> next;
i++;
}
return (i);
}

View File

@ -6,7 +6,7 @@
/* By: tosuman <timo42@proton.me> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/05/11 16:55:00 by tosuman #+# #+# */
/* Updated: 2023/06/02 20:02:14 by tischmid ### ########.fr */
/* Updated: 2023/06/26 20:41:08 by tosuman ### ########.fr */
/* */
/* ************************************************************************** */
@ -23,10 +23,10 @@ size_t ft_strlcat(char *dst, char const *src, size_t size)
while (src[slen])
++slen;
idx = 0;
while (dst[idx])
while (dst[idx] && idx < size)
++idx;
dlen = idx;
if (dlen > size)
if (dlen == size)
return (slen + size);
sidx = 0;
size -= dlen;
@ -35,31 +35,3 @@ size_t ft_strlcat(char *dst, char const *src, size_t size)
dst[idx] = 0;
return (dlen + slen);
}
/*
Alternative implementation
size_t ft_strlcat(char *dst, char const *src, size_t size)
{
size_t dst_len;
size_t src_len;
if ((!dst || !src) && size == 0)
return (0);
dst_len = 0;
src_len = -1;
while (*dst++)
++dst_len;
while (src[++src_len])
;
if (size <= dst_len)
return (size + src_len);
if (--dst && dst_len > size)
return (size + dst_len);
while (src_len-- && ++dst_len < size)
*dst++ = *src++;
if (dst_len-- == size)
--dst_len;
*dst = 0;
return (dst_len + src_len);
}
*/

View File

@ -6,7 +6,7 @@
/* By: tosuman <timo42@proton.me> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/05/11 11:31:44 by tosuman #+# #+# */
/* Updated: 2023/06/02 21:25:33 by tischmid ### ########.fr */
/* Updated: 2023/06/24 17:16:29 by tosuman ### ########.fr */
/* */
/* ************************************************************************** */
@ -61,5 +61,12 @@ int ft_char_in_charset(char c, char const *charset);
UINT ft_abs(int n);
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