From 9354b6e1ee401547ac5db0db8310e3d553999fb1 Mon Sep 17 00:00:00 2001 From: narnaud Date: Fri, 25 Mar 2022 15:01:44 +0100 Subject: [PATCH] updated --- Makefile | 25 ++-- conv/ft_atoi.c | 12 +- dlist/ft_add.c | 27 +++++ dlist/ft_n.c | 20 ++++ dlist/ft_to_arr.c | 41 +++++++ i_slist/ft_first.c | 32 +++++ i_slist/ft_free.c | 25 ++++ i_slist/ft_is_in.c | 27 +++++ libft.h | 52 ++++++--- mem/ft_free_split.c | 26 +++++ nbr/ft_croissant.c | 18 +++ nbr/ft_decroissant.c | 18 +++ lst/ft_lstadd_back.c => slist/ft_add_back.c | 10 +- lst/ft_lstadd_front.c => slist/ft_add_front.c | 6 +- lst/ft_lstclear.c => slist/ft_clear.c | 10 +- lst/ft_lstdelone.c => slist/ft_delone.c | 6 +- lst/ft_lstiter.c => slist/ft_iter.c | 8 +- lst/ft_lstlast.c => slist/ft_last.c | 6 +- lst/ft_lstmap.c => slist/ft_map.c | 14 +-- lst/ft_lstnew.c => slist/ft_new.c | 10 +- lst/ft_lstsize.c => slist/ft_size.c | 6 +- str/{ft_strchr.c => ft_chr.c} | 0 str/{ft_strdup.c => ft_dup.c} | 0 str/{ft_striteri.c => ft_iteri.c} | 0 str/{ft_strjoin.c => ft_join.c} | 0 str/{ft_strlcat.c => ft_lcat.c} | 0 str/{ft_strlcpy.c => ft_lcpy.c} | 0 str/{ft_strlen.c => ft_len.c} | 20 +++- str/{ft_strmapi.c => ft_mapi.c} | 0 str/{ft_strncmp.c => ft_ncmp.c} | 0 str/{ft_strnstr.c => ft_nstr.c} | 0 str/{ft_strrchr.c => ft_rchr.c} | 0 str/{ft_strrev.c => ft_rev.c} | 0 str/ft_split.c | 109 ++++-------------- str/{ft_substr.c => ft_sub.c} | 0 str/{ft_strtrim.c => ft_trim.c} | 0 36 files changed, 371 insertions(+), 157 deletions(-) create mode 100644 dlist/ft_add.c create mode 100644 dlist/ft_n.c create mode 100644 dlist/ft_to_arr.c create mode 100644 i_slist/ft_first.c create mode 100644 i_slist/ft_free.c create mode 100644 i_slist/ft_is_in.c create mode 100644 mem/ft_free_split.c create mode 100644 nbr/ft_croissant.c create mode 100644 nbr/ft_decroissant.c rename lst/ft_lstadd_back.c => slist/ft_add_back.c (79%) rename lst/ft_lstadd_front.c => slist/ft_add_front.c (82%) rename lst/ft_lstclear.c => slist/ft_clear.c (79%) rename lst/ft_lstdelone.c => slist/ft_delone.c (82%) rename lst/ft_lstiter.c => slist/ft_iter.c (80%) rename lst/ft_lstlast.c => slist/ft_last.c (84%) rename lst/ft_lstmap.c => slist/ft_map.c (71%) rename lst/ft_lstnew.c => slist/ft_new.c (79%) rename lst/ft_lstsize.c => slist/ft_size.c (84%) rename str/{ft_strchr.c => ft_chr.c} (100%) rename str/{ft_strdup.c => ft_dup.c} (100%) rename str/{ft_striteri.c => ft_iteri.c} (100%) rename str/{ft_strjoin.c => ft_join.c} (100%) rename str/{ft_strlcat.c => ft_lcat.c} (100%) rename str/{ft_strlcpy.c => ft_lcpy.c} (100%) rename str/{ft_strlen.c => ft_len.c} (72%) rename str/{ft_strmapi.c => ft_mapi.c} (100%) rename str/{ft_strncmp.c => ft_ncmp.c} (100%) rename str/{ft_strnstr.c => ft_nstr.c} (100%) rename str/{ft_strrchr.c => ft_rchr.c} (100%) rename str/{ft_strrev.c => ft_rev.c} (100%) rename str/{ft_substr.c => ft_sub.c} (100%) rename str/{ft_strtrim.c => ft_trim.c} (100%) diff --git a/Makefile b/Makefile index 56009b5..08b2fe0 100755 --- a/Makefile +++ b/Makefile @@ -3,24 +3,29 @@ NAME = libft.a SRCS = is/ft_isalpha.c is/ft_isdigit.c is/ft_isascii.c is/ft_isprint.c \ is/ft_isalnum.c -SRCS += str/ft_strlen.c str/ft_strlcpy.c str/ft_strlcat.c str/ft_strchr.c \ - str/ft_strrchr.c str/ft_strncmp.c str/ft_strnstr.c str/ft_strdup.c \ - str/ft_substr.c str/ft_strjoin.c str/ft_strtrim.c str/ft_split.c \ - str/ft_strrev.c str/ft_strmapi.c str/ft_striteri.c +SRCS += str/ft_len.c str/ft_lcpy.c str/ft_lcat.c str/ft_chr.c \ + str/ft_rchr.c str/ft_ncmp.c str/ft_nstr.c str/ft_dup.c \ + str/ft_sub.c str/ft_join.c str/ft_trim.c str/ft_split.c \ + str/ft_rev.c str/ft_mapi.c str/ft_iteri.c SRCS += conv/ft_toupper.c conv/ft_tolower.c conv/ft_atoi.c conv/ft_itoa.c \ conv/ft_itox.c conv/ft_utoa.c SRCS += mem/ft_bzero.c mem/ft_memset.c mem/ft_memchr.c mem/ft_memcpy.c \ - mem/ft_memcmp.c mem/ft_memmove.c mem/ft_calloc.c + mem/ft_memcmp.c mem/ft_memmove.c mem/ft_calloc.c mem/ft_free_split.c -SRCS += put/ft_putchar_fd.c put/ft_putnbr_fd.c put/ft_putendl_fd.c put/ft_putstr_fd.c +SRCS += put/ft_putchar_fd.c put/ft_putnbr_fd.c put/ft_putendl_fd.c \ + put/ft_putstr_fd.c -SRCS += nbr/ft_nbrlen.c +SRCS += nbr/ft_nbrlen.c nbr/ft_croissant.c nbr/ft_decroissant.c -SRCS += lst/ft_lstsize.c lst/ft_lstnew.c lst/ft_lstlast.c \ - lst/ft_lstadd_back.c lst/ft_lstadd_front.c lst/ft_lstdelone.c \ - lst/ft_lstclear.c lst/ft_lstiter.c lst/ft_lstmap.c +SRCS += slist/ft_size.c slist/ft_new.c slist/ft_last.c \ + slist/ft_add_back.c slist/ft_add_front.c slist/ft_delone.c \ + slist/ft_clear.c slist/ft_iter.c slist/ft_map.c + +SRCS += i_slist/ft_free.c i_slist/ft_first.c i_slist/ft_is_in.c + +SRCS += dlist/ft_add.c dlist/ft_n.c dlist/ft_to_arr.c OBJS = $(SRCS:.c=.o) diff --git a/conv/ft_atoi.c b/conv/ft_atoi.c index 3e85290..3364615 100755 --- a/conv/ft_atoi.c +++ b/conv/ft_atoi.c @@ -6,7 +6,7 @@ /* By: narnaud +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2021/10/18 17:06:25 by narnaud #+# #+# */ -/* Updated: 2022/03/24 09:22:48 by narnaud ### ########.fr */ +/* Updated: 2022/03/25 14:14:45 by narnaud ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,10 +15,12 @@ int ft_atoi(const char *str) { int sign; - int nb; + double nb; nb = 0; sign = 1; + if (!ft_strncmp(str, "-2147483648", 11)) + return (-2147483648); while (*str == ' ' || (*str >= '\t' && *str <= '\r')) str++; if (*str == '-' && ++str) @@ -27,11 +29,11 @@ int ft_atoi(const char *str) str++; while (*str >= '0' && *str <= '9') { - if (nb < 0 && sign > 0) + nb = nb * 10 + (*str - '0') % 10; + if (nb > 2147483647 && sign > 0) return (-1); - else if (nb < 0 && sign < 0) + else if (nb > 2147486648 && sign < 0) return (0); - nb = nb * 10 + (*str - '0') % 10; str++; } return ((int)(sign * nb)); diff --git a/dlist/ft_add.c b/dlist/ft_add.c new file mode 100644 index 0000000..f138840 --- /dev/null +++ b/dlist/ft_add.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_add.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: narnaud +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/03/24 10:46:25 by narnaud #+# #+# */ +/* Updated: 2022/03/25 14:15:13 by narnaud ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../libft.h" + +t_dlist *ft_dlst_add(t_dlist *prev, void *content) +{ + t_dlist *new; + + if (!content) + return (prev); + new = ft_calloc(1, sizeof(t_dlist)); + if (prev) + prev->next = new; + new->previous = prev; + new->content = content; + return (new); +} diff --git a/dlist/ft_n.c b/dlist/ft_n.c new file mode 100644 index 0000000..920e07c --- /dev/null +++ b/dlist/ft_n.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_dlst_n.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: narnaud +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/03/24 10:51:20 by narnaud #+# #+# */ +/* Updated: 2022/03/24 11:27:40 by narnaud ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../libft.h" + +t_dlist *ft_dlst_n(t_dlist *lst, size_t n) +{ + while (n-- && lst) + lst = lst->next; + return (lst); +} diff --git a/dlist/ft_to_arr.c b/dlist/ft_to_arr.c new file mode 100644 index 0000000..8eb7752 --- /dev/null +++ b/dlist/ft_to_arr.c @@ -0,0 +1,41 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_dlst_to_arr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: narnaud +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/03/24 10:50:10 by narnaud #+# #+# */ +/* Updated: 2022/03/24 11:33:57 by narnaud ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../libft.h" + +char **ft_dlst_to_arr(t_dlist *ptr) +{ + char **ret; + t_dlist *last; + t_dlist *tmp; + size_t count; + + last = ptr; + count = 1; + if (!ptr) + return (ft_calloc(1, sizeof(char *))); + while (ptr->previous) + { + ptr = ptr->previous; + count++; + } + ret = ft_calloc(count + 1, sizeof(char *)); + ret[count] = NULL; + while (count--) + { + ret[count] = last->content; + tmp = last; + free(last); + last = tmp->previous; + } + return (ret); +} diff --git a/i_slist/ft_first.c b/i_slist/ft_first.c new file mode 100644 index 0000000..91f6dc8 --- /dev/null +++ b/i_slist/ft_first.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_first.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: narnaud +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/03/25 09:06:44 by narnaud #+# #+# */ +/* Updated: 2022/03/25 13:26:04 by narnaud ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../libft.h" + +size_t ft_ilst_first(t_i_slist *lst, int (*fct)(int a, int b)) +{ + int previous; + size_t i; + + i = 1; + if (!lst) + return (0); + while (lst) + { + previous = lst->nb; + lst = lst->next; + if (lst && fct(previous, lst->nb)) + return (i); + i++; + } + return (-1); +} diff --git a/i_slist/ft_free.c b/i_slist/ft_free.c new file mode 100644 index 0000000..c088a74 --- /dev/null +++ b/i_slist/ft_free.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_free.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: narnaud +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/03/25 09:27:41 by narnaud #+# #+# */ +/* Updated: 2022/03/25 14:18:37 by narnaud ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../libft.h" + +void ft_ilst_free(t_i_slist *list) +{ + t_i_slist *next; + + while (list) + { + next = list->next; + free(list); + list = next; + } +} diff --git a/i_slist/ft_is_in.c b/i_slist/ft_is_in.c new file mode 100644 index 0000000..7f8f7b7 --- /dev/null +++ b/i_slist/ft_is_in.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_is_in.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: narnaud +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/03/25 13:22:49 by narnaud #+# #+# */ +/* Updated: 2022/03/25 14:19:02 by narnaud ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../libft.h" + +int ft_ilst_is_in(int value, t_i_slist lst) +{ + if (lst.nb == value && lst.next) + return (1); + while (lst.next) + { + if (lst.nb == value) + return (1); + else + lst = *(lst.next); + } + return (0); +} diff --git a/libft.h b/libft.h index 6a28c66..91a6acc 100755 --- a/libft.h +++ b/libft.h @@ -6,7 +6,7 @@ /* By: narnaud +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2021/10/19 14:42:45 by narnaud #+# #+# */ -/* Updated: 2021/12/21 10:02:24 by narnaud ### ########.fr */ +/* Updated: 2022/03/25 13:31:43 by narnaud ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,11 +17,24 @@ # include # include -typedef struct s_list +typedef struct s_slist { void *content; - struct s_list *next; -} t_list; + struct s_slist *next; +} t_slist; + +typedef struct s_i_slist +{ + int nb; + struct s_i_slist *next; +} t_i_slist; + +typedef struct s_dlist +{ + void *content; + struct s_dlist *next; + struct s_dlist *previous; +} t_dlist; int ft_atoi(const char *str); void ft_bzero(void *s, size_t n); @@ -35,15 +48,21 @@ void *ft_memchr(const void *b, int c, size_t n); int ft_memcmp(const void *s1, const void *s2, size_t n); void *ft_memcpy(void *dst, const void *src, size_t n); void *ft_memmove(void *dst, const void *src, size_t n); +void ft_free_split(char **split); + size_t ft_ilen(int nbr); size_t ft_ulen(unsigned int nbr); size_t ft_longbaselen(long nbr, size_t base); +int ft_croissant(int a, int b); +int ft_decroissant(int a, int b); + void *ft_memset(void *b, int c, size_t len); char *ft_strchr(const char *s, int c); char *ft_strdup(const char *src); size_t ft_strlcat(char *dst, const char *src, size_t dstsize); size_t ft_strlcpy(char *dst, const char *src, size_t dstsize); size_t ft_strlen(const char *s); +size_t ft_strlen_to(const char *str, char ch); int ft_strncmp(const char *s1, const char *s2, size_t n); char *ft_strnstr(const char *haystack, const char *needle, size_t len); char *ft_strrchr(const char *s, int c); @@ -64,14 +83,21 @@ 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_slist *ft_slst_new(void *content); +void ft_slst_add_front(t_slist **alst, t_slist *new); +int ft_slst_size(t_slist *lst); +t_slist *ft_slst_last(t_slist *lst); +void ft_slst_add_back(t_slist **alst, t_slist *new); +void ft_slst_delone(t_slist *lst, void (*del)(void *)); +void ft_slst_clear(t_slist **lst, void (*del)(void *)); +void ft_slst_iter(t_slist *lst, void (*f)(void *)); +t_slist *ft_slst_map(t_slist *lst, void *(*f)(void *), void (*del)(void *)); + +size_t ft_ilst_first(t_i_slist *lst, int (*fct)(int a, int b)); +void ft_ilst_free(t_i_slist *list); +int ft_ilst_is_in(int value, t_i_slist lst); +t_dlist *ft_dlst_add(t_dlist *prev, void *content); +t_dlist *ft_dlst_n(t_dlist *lst, size_t n); +char **ft_dlst_to_arr(t_dlist *ptr); #endif diff --git a/mem/ft_free_split.c b/mem/ft_free_split.c new file mode 100644 index 0000000..86149d7 --- /dev/null +++ b/mem/ft_free_split.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_free_split.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: narnaud +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/03/25 08:55:20 by narnaud #+# #+# */ +/* Updated: 2022/03/25 08:57:26 by narnaud ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../libft.h" + +void ft_free_split(char **split) +{ + int i; + + i = 0; + while (split[i]) + { + free(split[i]); + i++; + } + free(split); +} diff --git a/nbr/ft_croissant.c b/nbr/ft_croissant.c new file mode 100644 index 0000000..5a91ff0 --- /dev/null +++ b/nbr/ft_croissant.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_croissant.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: narnaud +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/03/25 09:14:45 by narnaud #+# #+# */ +/* Updated: 2022/03/25 09:15:32 by narnaud ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../libft.h" + +int ft_croissant(int a, int b) +{ + return (a <= b); +} diff --git a/nbr/ft_decroissant.c b/nbr/ft_decroissant.c new file mode 100644 index 0000000..061c0ea --- /dev/null +++ b/nbr/ft_decroissant.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_decroissant.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: narnaud +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/03/25 09:14:45 by narnaud #+# #+# */ +/* Updated: 2022/03/25 10:53:14 by narnaud ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../libft.h" + +int ft_decroissant(int a, int b) +{ + return (a > b); +} diff --git a/lst/ft_lstadd_back.c b/slist/ft_add_back.c similarity index 79% rename from lst/ft_lstadd_back.c rename to slist/ft_add_back.c index 34db8fa..5311366 100755 --- a/lst/ft_lstadd_back.c +++ b/slist/ft_add_back.c @@ -1,26 +1,26 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* ft_lstadd_back_bonus.c :+: :+: :+: */ +/* ft_lstadd_back.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: narnaud +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2021/10/22 14:51:11 by narnaud #+# #+# */ -/* Updated: 2022/03/24 09:22:48 by narnaud ### ########.fr */ +/* Updated: 2022/03/24 11:31:05 by narnaud ### ########.fr */ /* */ /* ************************************************************************** */ #include "../libft.h" -void ft_lstadd_back(t_list **alst, t_list *new) +void ft_slst_add_back(t_slist **alst, t_slist *new) { - t_list *i_cell; + t_slist *i_cell; if (!alst || !new) return ; if (*alst) { - i_cell = ft_lstlast(*alst); + i_cell = ft_slst_last(*alst); i_cell->next = new; } else diff --git a/lst/ft_lstadd_front.c b/slist/ft_add_front.c similarity index 82% rename from lst/ft_lstadd_front.c rename to slist/ft_add_front.c index 6b98704..32fcb60 100755 --- a/lst/ft_lstadd_front.c +++ b/slist/ft_add_front.c @@ -1,18 +1,18 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* ft_lstadd_front_bonus.c :+: :+: :+: */ +/* ft_lstadd_front.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: narnaud +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2021/10/22 14:48:11 by narnaud #+# #+# */ -/* Updated: 2022/03/24 09:22:48 by narnaud ### ########.fr */ +/* Updated: 2022/03/24 11:31:05 by narnaud ### ########.fr */ /* */ /* ************************************************************************** */ #include "../libft.h" -void ft_lstadd_front(t_list **alst, t_list *new) +void ft_slst_add_front(t_slist **alst, t_slist *new) { if (!alst || !new) return ; diff --git a/lst/ft_lstclear.c b/slist/ft_clear.c similarity index 79% rename from lst/ft_lstclear.c rename to slist/ft_clear.c index 5265738..0e9c5fe 100755 --- a/lst/ft_lstclear.c +++ b/slist/ft_clear.c @@ -1,27 +1,27 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* ft_lstclear_bonus.c :+: :+: :+: */ +/* ft_lstclear.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: narnaud +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2021/10/22 14:53:04 by narnaud #+# #+# */ -/* Updated: 2022/03/24 09:22:49 by narnaud ### ########.fr */ +/* Updated: 2022/03/24 11:31:05 by narnaud ### ########.fr */ /* */ /* ************************************************************************** */ #include "../libft.h" -void ft_lstclear(t_list **lst, void (*del)(void *)) +void ft_slst_clear(t_slist **lst, void (*del)(void *)) { - t_list *next_cell; + t_slist *next_cell; if (!del) return ; while (lst && *lst) { next_cell = (*lst)->next; - ft_lstdelone(*lst, del); + ft_slst_delone(*lst, del); *lst = next_cell; } } diff --git a/lst/ft_lstdelone.c b/slist/ft_delone.c similarity index 82% rename from lst/ft_lstdelone.c rename to slist/ft_delone.c index 21b556f..9e882aa 100755 --- a/lst/ft_lstdelone.c +++ b/slist/ft_delone.c @@ -1,18 +1,18 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* ft_lstdelone_bonus.c :+: :+: :+: */ +/* ft_lstdelone.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: narnaud +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2021/10/22 14:51:53 by narnaud #+# #+# */ -/* Updated: 2022/03/24 09:22:49 by narnaud ### ########.fr */ +/* Updated: 2022/03/24 11:31:05 by narnaud ### ########.fr */ /* */ /* ************************************************************************** */ #include "../libft.h" -void ft_lstdelone(t_list *lst, void (*del)(void *)) +void ft_slst_delone(t_slist *lst, void (*del)(void *)) { if (!lst || !del) return ; diff --git a/lst/ft_lstiter.c b/slist/ft_iter.c similarity index 80% rename from lst/ft_lstiter.c rename to slist/ft_iter.c index 426182c..21a601d 100755 --- a/lst/ft_lstiter.c +++ b/slist/ft_iter.c @@ -1,22 +1,22 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* ft_lstiter_bonus.c :+: :+: :+: */ +/* ft_lstiter.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: narnaud +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2021/10/22 14:54:03 by narnaud #+# #+# */ -/* Updated: 2022/03/24 09:22:49 by narnaud ### ########.fr */ +/* Updated: 2022/03/24 11:31:05 by narnaud ### ########.fr */ /* */ /* ************************************************************************** */ #include "../libft.h" -void ft_lstiter(t_list *lst, void (*f)(void *)) +void ft_slst_iter(t_slist *lst, void (*f)(void *)) { if (!lst || !f) return ; (*f)(lst->content); if (lst->next) - ft_lstiter(lst->next, f); + ft_slst_iter(lst->next, f); } diff --git a/lst/ft_lstlast.c b/slist/ft_last.c similarity index 84% rename from lst/ft_lstlast.c rename to slist/ft_last.c index e7cdbf0..d15a275 100755 --- a/lst/ft_lstlast.c +++ b/slist/ft_last.c @@ -1,18 +1,18 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* ft_lstlast_bonus.c :+: :+: :+: */ +/* ft_lstlast.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: narnaud +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2021/10/22 14:50:21 by narnaud #+# #+# */ -/* Updated: 2022/03/24 09:22:49 by narnaud ### ########.fr */ +/* Updated: 2022/03/24 11:31:05 by narnaud ### ########.fr */ /* */ /* ************************************************************************** */ #include "../libft.h" -t_list *ft_lstlast(t_list *lst) +t_slist *ft_slst_last(t_slist *lst) { if (!lst) return (NULL); diff --git a/lst/ft_lstmap.c b/slist/ft_map.c similarity index 71% rename from lst/ft_lstmap.c rename to slist/ft_map.c index aee025c..236583d 100755 --- a/lst/ft_lstmap.c +++ b/slist/ft_map.c @@ -1,29 +1,29 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* ft_lstmap_bonus.c :+: :+: :+: */ +/* ft_lstmap.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: narnaud +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2021/10/22 14:54:31 by narnaud #+# #+# */ -/* Updated: 2022/03/24 09:22:49 by narnaud ### ########.fr */ +/* Updated: 2022/03/24 11:31:05 by narnaud ### ########.fr */ /* */ /* ************************************************************************** */ #include "../libft.h" -t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *)) +t_slist *ft_slst_map(t_slist *lst, void *(*f)(void *), void (*del)(void *)) { - t_list *new_lst; + t_slist *new_lst; if (!lst || !f) return (NULL); - new_lst = ft_lstnew((*f)(lst->content)); + new_lst = ft_slst_new((*f)(lst->content)); if (!new_lst) { - ft_lstclear(&new_lst, del); + ft_slst_clear(&new_lst, del); return (NULL); } - new_lst->next = ft_lstmap(lst->next, f, del); + new_lst->next = ft_slst_map(lst->next, f, del); return (new_lst); } diff --git a/lst/ft_lstnew.c b/slist/ft_new.c similarity index 79% rename from lst/ft_lstnew.c rename to slist/ft_new.c index 1ed7040..eb32842 100755 --- a/lst/ft_lstnew.c +++ b/slist/ft_new.c @@ -1,22 +1,22 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* ft_lstnew_bonus.c :+: :+: :+: */ +/* ft_lstnew.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: narnaud +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2021/10/20 17:36:09 by narnaud #+# #+# */ -/* Updated: 2022/03/24 09:22:49 by narnaud ### ########.fr */ +/* Updated: 2022/03/24 11:31:05 by narnaud ### ########.fr */ /* */ /* ************************************************************************** */ #include "../libft.h" -t_list *ft_lstnew(void *content) +t_slist *ft_slst_new(void *content) { - t_list *i_cell; + t_slist *i_cell; - i_cell = (t_list *)malloc(sizeof(*i_cell)); + i_cell = (t_slist *)malloc(sizeof(*i_cell)); if (!i_cell) return (NULL); i_cell->content = content; diff --git a/lst/ft_lstsize.c b/slist/ft_size.c similarity index 84% rename from lst/ft_lstsize.c rename to slist/ft_size.c index 195acf7..c2df369 100755 --- a/lst/ft_lstsize.c +++ b/slist/ft_size.c @@ -1,18 +1,18 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* ft_lstsize_bonus.c :+: :+: :+: */ +/* ft_lstsize.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: narnaud +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2021/10/22 14:49:32 by narnaud #+# #+# */ -/* Updated: 2022/03/24 09:22:49 by narnaud ### ########.fr */ +/* Updated: 2022/03/24 11:31:05 by narnaud ### ########.fr */ /* */ /* ************************************************************************** */ #include "../libft.h" -int ft_lstsize(t_list *lst) +int ft_slst_size(t_slist *lst) { size_t lst_size; diff --git a/str/ft_strchr.c b/str/ft_chr.c similarity index 100% rename from str/ft_strchr.c rename to str/ft_chr.c diff --git a/str/ft_strdup.c b/str/ft_dup.c similarity index 100% rename from str/ft_strdup.c rename to str/ft_dup.c diff --git a/str/ft_striteri.c b/str/ft_iteri.c similarity index 100% rename from str/ft_striteri.c rename to str/ft_iteri.c diff --git a/str/ft_strjoin.c b/str/ft_join.c similarity index 100% rename from str/ft_strjoin.c rename to str/ft_join.c diff --git a/str/ft_strlcat.c b/str/ft_lcat.c similarity index 100% rename from str/ft_strlcat.c rename to str/ft_lcat.c diff --git a/str/ft_strlcpy.c b/str/ft_lcpy.c similarity index 100% rename from str/ft_strlcpy.c rename to str/ft_lcpy.c diff --git a/str/ft_strlen.c b/str/ft_len.c similarity index 72% rename from str/ft_strlen.c rename to str/ft_len.c index 8e753e7..4ae6aa9 100755 --- a/str/ft_strlen.c +++ b/str/ft_len.c @@ -1,25 +1,33 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* ft_strlen.c :+: :+: :+: */ +/* ft_len.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: narnaud +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2021/10/18 16:04:47 by narnaud #+# #+# */ -/* Updated: 2022/03/24 09:22:49 by narnaud ### ########.fr */ +/* Updated: 2022/03/25 11:57:59 by narnaud ### ########.fr */ /* */ /* ************************************************************************** */ #include "../libft.h" -size_t ft_strlen(const char *s) +size_t ft_strlen_to(const char *str, char ch) { size_t i; i = 0; - while (s[i] != '\0') - { + while (str[i] && str[i] != ch) + i++; + return (i); +} + +size_t ft_strlen(const char *str) +{ + size_t i; + + i = 0; + while (str[i] != '\0') i++; - } return (i); } diff --git a/str/ft_strmapi.c b/str/ft_mapi.c similarity index 100% rename from str/ft_strmapi.c rename to str/ft_mapi.c diff --git a/str/ft_strncmp.c b/str/ft_ncmp.c similarity index 100% rename from str/ft_strncmp.c rename to str/ft_ncmp.c diff --git a/str/ft_strnstr.c b/str/ft_nstr.c similarity index 100% rename from str/ft_strnstr.c rename to str/ft_nstr.c diff --git a/str/ft_strrchr.c b/str/ft_rchr.c similarity index 100% rename from str/ft_strrchr.c rename to str/ft_rchr.c diff --git a/str/ft_strrev.c b/str/ft_rev.c similarity index 100% rename from str/ft_strrev.c rename to str/ft_rev.c diff --git a/str/ft_split.c b/str/ft_split.c index 8c39fd3..026999f 100755 --- a/str/ft_split.c +++ b/str/ft_split.c @@ -6,98 +6,37 @@ /* By: narnaud +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2021/10/20 15:43:48 by narnaud #+# #+# */ -/* Updated: 2022/03/24 09:22:49 by narnaud ### ########.fr */ +/* Updated: 2022/03/25 14:56:37 by narnaud ### ########.fr */ /* */ /* ************************************************************************** */ #include "../libft.h" -static int ft_strlen_to(char const *str, int i, char ch, int lf_not) +char **ft_split(const char *str, char c) { - if (!str[i]) - return (i); - if ((!lf_not && str[i] == ch) || (lf_not && !(str[i] == ch))) - return (i); - return (ft_strlen_to(str, ++i, ch, lf_not)); -} - -static int goto_cur_word(char const *str, char ch, int *words_len, int j_word) -{ - int i_word; - int i; - - i_word = 0; - i = 0; - i += ft_strlen_to(str, i, ch, 1) - i; - while (i_word < j_word) - { - i += words_len[i_word++]; - i += ft_strlen_to(str, i, ch, 1) - i; - } - return (i); -} - -static char *ft_get_word(char const *str, char ch, int *words_len, int j_word) -{ - int i; - int j; - char *output; - - output = ft_calloc((words_len[j_word] + 1), sizeof(char)); - if (output == NULL) - return (output); - i = goto_cur_word(str, ch, words_len, j_word); - j = 0; - while (j < words_len[j_word]) - { - i += ft_strlen_to(str, i, ch, 1) - i; - output[j] = str[i + j]; - j++; - } - output[j] = '\0'; - return (output); -} - -int get_words_len(int **words_len, char const *str, char ch) -{ - int i; - int strlen; - int words_count; - - i = 0; - words_count = 0; - strlen = ft_strlen_to(str, 0, '\0', 0); - while (i < strlen) - { - (*words_len)[words_count] = ft_strlen_to(str, i, ch, 0) - i; - i += (*words_len)[words_count] + 1; - if ((*words_len)[words_count] && ++words_count) - (*words_len)[words_count] = 0; - } - return (words_count); -} - -char **ft_split(char const *str, char ch) -{ - int i; - int words_count; - int *words_len; - char **output; + t_dlist *words; + char *word; + int i; + int j; - if (!str) - return (NULL); i = -1; - words_len = ft_calloc(200, sizeof(int)); - if (!words_len) - return (NULL); - words_count = get_words_len(&words_len, str, ch); - output = ft_calloc(words_count + 1, sizeof(char *)); - if (!output) + word = NULL; + words = NULL; + if (!str) return (NULL); - i = -1; - while (++i < words_count) - output[i] = ft_get_word(str, ch, words_len, i); - output[i] = NULL; - free(words_len); - return (output); + while (str[++i]) + { + if (!word && str[i] != c) + j = 0; + if (!word && str[i] != c) + word = ft_calloc((int)ft_strlen_to(str + i, c) + 1, sizeof(char)); + if (word && str[i] == c) + words = ft_dlst_add(words, word); + if (word && str[i] == c) + word = NULL; + if (str[i] != c) + word[j++] = str[i]; + } + words = ft_dlst_add(words, word); + return ((char **)ft_dlst_to_arr(words)); } diff --git a/str/ft_substr.c b/str/ft_sub.c similarity index 100% rename from str/ft_substr.c rename to str/ft_sub.c diff --git a/str/ft_strtrim.c b/str/ft_trim.c similarity index 100% rename from str/ft_strtrim.c rename to str/ft_trim.c