From 0ea04b92f97b436b3e2a4af044ae45e7732f205d Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Fri, 4 Nov 2016 12:43:19 +0100 Subject: [PATCH] norm for lst functions done --- libftasm/src/lst/ft_lst_delif.c | 6 ++--- libftasm/src/lst/ft_lst_delsub.c | 34 ++++++++--------------- libftasm/src/lst/ft_lst_order_delsub.c | 37 +++++++++++--------------- libftasm/src/lst/ft_lst_removeif.c | 26 ++++++------------ libftasm/src/misc/ft_debug.c | 14 +++++++++- libftasm/src/path/ft_path_notdir.c | 12 +++++++++ 6 files changed, 62 insertions(+), 67 deletions(-) diff --git a/libftasm/src/lst/ft_lst_delif.c b/libftasm/src/lst/ft_lst_delif.c index 7319abc9..03fe045e 100644 --- a/libftasm/src/lst/ft_lst_delif.c +++ b/libftasm/src/lst/ft_lst_delif.c @@ -6,15 +6,15 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/04 11:09:12 by jhalford #+# #+# */ -/* Updated: 2016/11/04 11:11:54 by jhalford ### ########.fr */ +/* Updated: 2016/11/04 11:47:22 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" void ft_lst_delif( - t_list **alst, - void *data_ref, int (*cmp)(), + t_list **alst, + void *data_ref, int (*cmp)(), void (*del)(void *, size_t)) { t_list *last; diff --git a/libftasm/src/lst/ft_lst_delsub.c b/libftasm/src/lst/ft_lst_delsub.c index 568bb767..baa77125 100644 --- a/libftasm/src/lst/ft_lst_delsub.c +++ b/libftasm/src/lst/ft_lst_delsub.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/04 11:09:15 by jhalford #+# #+# */ -/* Updated: 2016/11/04 11:12:28 by jhalford ### ########.fr */ +/* Updated: 2016/11/04 12:00:41 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,35 +14,23 @@ void ft_lst_delsub( t_list **alst, - t_list *sub, int (*cmp)(), + t_list *sub, + int (*cmp)(), void (*del)(void *, size_t)) { - t_list *last; - t_list *current; t_list *tmp; + t_list **indirect; - last = NULL; - current = *alst; - tmp = NULL; - while (current && sub) + indirect = alst; + while (*indirect) { - if ((*cmp)(current->content, sub->content) == 0) + if ((*cmp)((*indirect)->content, sub->content) == 0) { - if (current == *alst) - *alst = current->next; - else - last->next = current->next; - tmp = current; - current = current->next; - sub = sub->next; + tmp = *indirect; + (*indirect) = (*indirect)->next; ft_lstdelone(&tmp, del); + sub = sub->next; } - else - { - last = current; - current = current->next; - } - if (!current && sub) - current = *alst; + indirect = &(*indirect)->next; } } diff --git a/libftasm/src/lst/ft_lst_order_delsub.c b/libftasm/src/lst/ft_lst_order_delsub.c index 53e9a079..5bf2067c 100644 --- a/libftasm/src/lst/ft_lst_order_delsub.c +++ b/libftasm/src/lst/ft_lst_order_delsub.c @@ -6,43 +6,36 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/04 11:09:25 by jhalford #+# #+# */ -/* Updated: 2016/11/04 11:09:26 by jhalford ### ########.fr */ +/* Updated: 2016/11/04 12:01:47 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" -void ft_lst_delsub(t_list **alst, t_list *sub, int (*cmp)(), void (*del)(void *, size_t)) +void ft_lst_order_delsub( + t_list **alst, + t_list *sub, + int (*cmp)(), + void (*del)(void *, size_t)) { - t_list *last; - t_list *current; t_list *tmp; + t_list **indirect; - last = NULL; - current = *alst; - tmp = NULL; - while (current && sub) + indirect = alst; + while (*indirect) { - if ((*cmp)(current->content, sub->content) > 0) + if ((*cmp)((*indirect)->content, sub->content) > 0) { sub = sub->next; continue ; } - if ((*cmp)(current->content, sub->content) == 0) + if ((*cmp)((*indirect)->content, sub->content) == 0) { - if (current == *alst) - *alst = current->next; - else - last->next = current->next; - tmp = current; - current = current->next; - sub = sub->next; + tmp = *indirect; + (*indirect) = (*indirect)->next; ft_lstdelone(&tmp, del); + sub = sub->next; } - else - { - last = current; - current = current->next; - } + indirect = &(*indirect)->next; } } diff --git a/libftasm/src/lst/ft_lst_removeif.c b/libftasm/src/lst/ft_lst_removeif.c index bf757b81..39303b32 100644 --- a/libftasm/src/lst/ft_lst_removeif.c +++ b/libftasm/src/lst/ft_lst_removeif.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/04 11:09:30 by jhalford #+# #+# */ -/* Updated: 2016/11/04 11:09:31 by jhalford ### ########.fr */ +/* Updated: 2016/11/04 11:59:13 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,31 +14,21 @@ t_list *ft_lst_removeif(t_list **alst, void *data_ref, int (*cmp)()) { - t_list *last; - t_list *current; t_list *tmp; + t_list **indirect; - last = NULL; tmp = NULL; - current = *alst; + indirect = alst; while (current) { - if ((*cmp)(current->content, data_ref) == 0) + if ((*cmp)((*indirect)->content, data_ref) == 0) { - if (current == *alst) - *alst = current->next; - else - last->next = current->next; - tmp = current; - current = current->next; + tmp = (*indirect); + tmp->next = NULL; + (*indirect) = (*indirect)->next; return (tmp); } - else - { - last = current; - current = current->next; - } + indirect = &(*indirect)->next; } return (NULL); } - diff --git a/libftasm/src/misc/ft_debug.c b/libftasm/src/misc/ft_debug.c index 4e9b18ee..552a7632 100644 --- a/libftasm/src/misc/ft_debug.c +++ b/libftasm/src/misc/ft_debug.c @@ -1,3 +1,15 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_debug.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/04 11:45:16 by jhalford #+# #+# */ +/* Updated: 2016/11/04 11:45:51 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + #include "libft.h" #include @@ -6,6 +18,6 @@ void ft_debug(void) static int n = 0; n++; - printf("----------\n check %02i\n----------\n", n); + ft_printf("----------\n check %02i\n----------\n", n); fflush(stdout); } diff --git a/libftasm/src/path/ft_path_notdir.c b/libftasm/src/path/ft_path_notdir.c index 8d788ddb..14342adf 100644 --- a/libftasm/src/path/ft_path_notdir.c +++ b/libftasm/src/path/ft_path_notdir.c @@ -1,3 +1,15 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_path_notdir.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/04 11:45:07 by jhalford #+# #+# */ +/* Updated: 2016/11/04 11:45:08 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + #include "libft.h" char *ft_path_notdir(char *path)