From 8960d5445562bf3de045afd3d75f4f7fc5310c8f Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Mon, 21 Nov 2016 15:51:08 +0100 Subject: [PATCH] norm stuff and delif now dels pointer to lst also...... --- libft/src/btree/btree_print.c | 103 +++++++++++++++++++------------- libft/src/ft_printf/ft_printf.c | 2 +- libft/src/lst/ft_lst_delif.c | 4 +- libft/src/lst/ft_lst_filter.c | 2 +- libft/src/lst/ft_lstdel.c | 2 +- libft/src/lst/ft_lstdelone.c | 2 +- libft/src/printing/ft_putaddr.c | 12 ++++ libft/src/str/ft_strinsert.c | 2 +- 8 files changed, 81 insertions(+), 48 deletions(-) diff --git a/libft/src/btree/btree_print.c b/libft/src/btree/btree_print.c index 793479c8..757fa330 100644 --- a/libft/src/btree/btree_print.c +++ b/libft/src/btree/btree_print.c @@ -6,68 +6,89 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/14 18:06:24 by jhalford #+# #+# */ -/* Updated: 2016/11/16 11:24:32 by jhalford ### ########.fr */ +/* Updated: 2016/11/21 15:13:44 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "btree.h" -int _print_t(t_btree *tree, int is_left, int offset, int depth, char s[20][255], char *(*printer)(void *)) -{ - char b[20]; - int width = 5; +enum e_data +{ + is_left, + offset, + depth, +}; + +static int print_t(t_btree *tree, + int data[3], char s[20][255], char *(*printer)(void *)) +{ + char b[20]; + int width; + int left; + int right; + int i; + + width = 5; if (!tree) - return 0; - /* ft_printf("new tree elem: %s\n", printer(tree)); */ + return (0); sprintf(b, "%5s", printer(tree->item)); - int left = _print_t(tree->left, 1, offset, depth + 1, s, printer); - int right = _print_t(tree->right, 0, offset + left + width, depth + 1, s, printer); -#ifdef COMPACT - for (int i = 0; i < width; i++) - s[depth][offset + left + i] = b[i]; - if (depth && is_left) + left = print_t(tree->left, (int[3]){ + 1, data[offset], data[depth] + 1}, s, printer); + right = print_t(tree->right, (int[3]){ + 0, data[offset] + left + width, data[depth] + 1}, s, printer); + i = -1; + while (++i < width) + s[data[depth]][data[offset] + left + i] = b[i]; + if (data[depth] && data[is_left]) { - for (int i = 0; i < width + right; i++) - s[depth - 1][offset + left + width/2 + i] = '-'; - s[depth - 1][offset + left + width/2] = '.'; + i = -1; + while (++i < width) + s[data[depth] - 1][data[offset] + left + width / 2 + i] = '-'; + s[data[depth] - 1][data[offset] + left + width / 2] = '.'; } - else if (depth && !is_left) + else if (data[depth] && !data[is_left]) { - for (int i = 0; i < left + width; i++) - s[depth - 1][offset - width/2 + i] = '-'; - s[depth - 1][offset + left + width/2] = '.'; + i = -1; + while (++i < width) + s[data[depth] - 1][data[offset] - width / 2 + i] = '-'; + s[data[depth] - 1][data[offset] + left + width / 2] = '.'; } -#else - for (int i = 0; i < width; i++) - s[2 * depth][offset + left + i] = b[i]; - if (depth && is_left) + i = -1; + while (++i < width) + s[2 * data[depth]][data[offset] + left + i] = b[i]; + if (data[depth] && data[is_left]) { - for (int i = 0; i < width + right; i++) - s[2 * depth - 1][offset + left + width/2 + i] = '-'; - s[2 * depth - 1][offset + left + width/2] = '+'; - s[2 * depth - 1][offset + left + width + right + width/2] = '+'; + i = -1; + while (++i < width) + s[2 * data[depth] - 1][data[offset] + left + width / 2 + i] = '-'; + s[2 * data[depth] - 1][data[offset] + left + width / 2] = '+'; + s[2 * data[depth] - 1][ + data[offset] + left + right + 3 * width / 2] = '+'; } - else if (depth && !is_left) { - for (int i = 0; i < left + width; i++) - s[2 * depth - 1][offset - width/2 + i] = '-'; - s[2 * depth - 1][offset + left + width/2] = '+'; - s[2 * depth - 1][offset - width/2 - 1] = '+'; + else if (data[depth] && !data[is_left]) + { + i = -1; + while (++i < width) + s[2 * data[depth] - 1][data[offset] - width / 2 + i] = '-'; + s[2 * data[depth] - 1][data[offset] + left + width / 2] = '+'; + s[2 * data[depth] - 1][data[offset] - width / 2 - 1] = '+'; } -#endif return (left + width + right); } void btree_print(t_btree *tree, char *(*printer)(void *)) { - char s[20][255]; - char empty[255]; - /* for (int i = 0; i < 20; i++) */ - /* s[i][1] = 0; */ - for (int i = 0; i < 20; i++) + char s[20][255]; + char empty[255]; + int i; + + i = -1; + while (++i < 20) sprintf(s[i], "%80s", " "); sprintf(empty, "%80s", " "); - _print_t(tree, 0, 0, 0, s, printer); - for (int i = 0; i < 20; i++) + print_t(tree, (int[3]){0, 0, 0}, s, printer); + i = -1; + while (++i < 20) { if (ft_strcmp(s[i], empty) == 0) break ; diff --git a/libft/src/ft_printf/ft_printf.c b/libft/src/ft_printf/ft_printf.c index ca094456..f3989d5e 100644 --- a/libft/src/ft_printf/ft_printf.c +++ b/libft/src/ft_printf/ft_printf.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 13:33:27 by jhalford #+# #+# */ -/* Updated: 2016/11/16 18:30:10 by jhalford ### ########.fr */ +/* Updated: 2016/11/21 15:15:04 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libft/src/lst/ft_lst_delif.c b/libft/src/lst/ft_lst_delif.c index 1acf6fd4..091b813d 100644 --- a/libft/src/lst/ft_lst_delif.c +++ b/libft/src/lst/ft_lst_delif.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/04 11:09:12 by jhalford #+# #+# */ -/* Updated: 2016/11/16 18:23:24 by jhalford ### ########.fr */ +/* Updated: 2016/11/21 14:22:51 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -28,7 +28,7 @@ void ft_lst_delif( { tmp = (*indirect); (*indirect) = (*indirect)->next; - (*del)(tmp->content, tmp->content_size); + ft_lstdelone(&tmp, del); } else indirect = &(*indirect)->next; diff --git a/libft/src/lst/ft_lst_filter.c b/libft/src/lst/ft_lst_filter.c index 8676c5f1..2df3a067 100644 --- a/libft/src/lst/ft_lst_filter.c +++ b/libft/src/lst/ft_lst_filter.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/04 11:09:17 by jhalford #+# #+# */ -/* Updated: 2016/11/04 11:11:30 by jhalford ### ########.fr */ +/* Updated: 2016/11/21 12:36:08 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libft/src/lst/ft_lstdel.c b/libft/src/lst/ft_lstdel.c index 1e1ce39c..584c25c6 100644 --- a/libft/src/lst/ft_lstdel.c +++ b/libft/src/lst/ft_lstdel.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/03 15:18:57 by jhalford #+# #+# */ -/* Updated: 2016/11/16 18:24:38 by jhalford ### ########.fr */ +/* Updated: 2016/11/21 14:02:16 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libft/src/lst/ft_lstdelone.c b/libft/src/lst/ft_lstdelone.c index fe144be3..8c200615 100644 --- a/libft/src/lst/ft_lstdelone.c +++ b/libft/src/lst/ft_lstdelone.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/03 14:57:15 by jhalford #+# #+# */ -/* Updated: 2016/11/16 18:22:47 by jhalford ### ########.fr */ +/* Updated: 2016/11/21 14:02:31 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libft/src/printing/ft_putaddr.c b/libft/src/printing/ft_putaddr.c index 5e74f4e2..2ba4028b 100644 --- a/libft/src/printing/ft_putaddr.c +++ b/libft/src/printing/ft_putaddr.c @@ -1,3 +1,15 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putaddr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/21 15:13:34 by jhalford #+# #+# */ +/* Updated: 2016/11/21 15:13:35 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + #include "libft.h" void ft_putaddr(void *a) diff --git a/libft/src/str/ft_strinsert.c b/libft/src/str/ft_strinsert.c index 685d0834..3548469a 100644 --- a/libft/src/str/ft_strinsert.c +++ b/libft/src/str/ft_strinsert.c @@ -7,6 +7,6 @@ char *ft_strinsert(char *str, char c, int n) ft_strcpy(tmp, str + n); str[n] = 0; - out = ft_str3join(str, (char []){c, 0}, tmp); + out = ft_str3join(str, (char[]){c, 0}, tmp); return (out); }