From ece5c61bea5cc8ec61ed548cbb4ed03ba0f19b8c Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Thu, 10 Nov 2016 12:28:45 +0100 Subject: [PATCH 1/6] sstrfree --- libftasm/includes/libft.h | 5 +++-- libftasm/src/sstr/ft_sstradd.c | 5 +++-- libftasm/src/sstr/ft_sstrfree.c | 25 +++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 libftasm/src/sstr/ft_sstrfree.c diff --git a/libftasm/includes/libft.h b/libftasm/includes/libft.h index c6e8c0b6..b51bd194 100644 --- a/libftasm/includes/libft.h +++ b/libftasm/includes/libft.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 13:49:04 by jhalford #+# #+# */ -/* Updated: 2016/11/08 11:25:08 by jhalford ### ########.fr */ +/* Updated: 2016/11/10 12:14:04 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -106,11 +106,12 @@ size_t ft_uilen(unsigned int n); size_t ft_lllen(long long n); size_t ft_lllen_base(long long n, int base); +char **ft_sstradd(char **list, char *new); void ft_sstrsort(char **list, int size, int (*cmp)()); void ft_sstrprint(char **list, char sep); char **ft_sstrdup(char **list); -char **ft_sstradd(char **list, char *new); void ft_sstrdel(char **sstr, int index); +void ft_sstrfree(char **sstr); int ft_time_isrecent(time_t event); diff --git a/libftasm/src/sstr/ft_sstradd.c b/libftasm/src/sstr/ft_sstradd.c index 4ec7bac9..e88b1651 100644 --- a/libftasm/src/sstr/ft_sstradd.c +++ b/libftasm/src/sstr/ft_sstradd.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/03 18:03:58 by jhalford #+# #+# */ -/* Updated: 2016/11/03 18:04:23 by jhalford ### ########.fr */ +/* Updated: 2016/11/10 12:15:23 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,7 +22,8 @@ char **ft_sstradd(char **sstr, char *new) size = 0; while (sstr && sstr[size]) size++; - newlist = (char **)malloc(sizeof(char *) * (size + 3)); + if (!(newlist = (char **)malloc(sizeof(char *) * (size + 2)))) + return (NULL); while (sstr && *sstr) newlist[i++] = *sstr++; newlist[i++] = new; diff --git a/libftasm/src/sstr/ft_sstrfree.c b/libftasm/src/sstr/ft_sstrfree.c new file mode 100644 index 00000000..05686e2b --- /dev/null +++ b/libftasm/src/sstr/ft_sstrfree.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_sstrfree.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/08 17:01:24 by jhalford #+# #+# */ +/* Updated: 2016/11/10 12:11:20 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_sstrfree(char **sstr) +{ + int i; + + i = 0; + while (sstr[i]) + { + ft_strdel(sstr + i); + i++; + } +} From b3e78bb758f4771dbb888673ea3a2c077218404c Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Thu, 10 Nov 2016 17:07:05 +0100 Subject: [PATCH 2/6] env subdir for getenv --- libftasm/includes/libft.h | 12 ++++++++- libftasm/src/env/ft_getenv.c | 27 +++++++++++++++++++ libftasm/src/ft_printf/ft_conversion.c | 2 +- .../src/ft_printf/ft_fmt_validate_flags.c | 7 ++--- libftasm/src/ft_printf/ft_printf.c | 2 +- libftasm/src/ft_printf/ft_printf_parse.c | 2 +- libftasm/src/str/ft_strcat.c | 4 +-- libftasm/src/str/ft_strjoin.c | 2 +- libftasm/src/str/ft_strlen.c | 2 +- 9 files changed, 49 insertions(+), 11 deletions(-) create mode 100644 libftasm/src/env/ft_getenv.c diff --git a/libftasm/includes/libft.h b/libftasm/includes/libft.h index b51bd194..37fc15c2 100644 --- a/libftasm/includes/libft.h +++ b/libftasm/includes/libft.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 13:49:04 by jhalford #+# #+# */ -/* Updated: 2016/11/10 12:14:04 by jhalford ### ########.fr */ +/* Updated: 2016/11/10 14:40:54 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -31,6 +31,14 @@ # define FT_MAX(a, b) ((a) > (b) ? (a) : (b)) # define FT_DIST(a, b) (FT_ABS((a) - (b))) +typedef struct s_stof t_stof; + +struct s_stof +{ + char *name; + int (*f)(); +}; + void ft_debug(void); void *ft_memset(void *b, int c, size_t len); @@ -118,4 +126,6 @@ int ft_time_isrecent(time_t event); char *ft_path_notdir(char *path); int ft_printf(const char *format, ...); + +char *ft_getenv(char **env, char *key); #endif diff --git a/libftasm/src/env/ft_getenv.c b/libftasm/src/env/ft_getenv.c new file mode 100644 index 00000000..3c733605 --- /dev/null +++ b/libftasm/src/env/ft_getenv.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_getenv.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/10 14:30:00 by jhalford #+# #+# */ +/* Updated: 2016/11/10 14:30:27 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_getenv(char **env, char *key) +{ + if (!env) + return (NULL); + while (*env) + { + /* ft_printf("%s\n", env[i]); */ + if (ft_strcmp(*env, key) == '=') + return (*env + ft_strlen(key) + 1); + env++; + } + return (NULL); +} diff --git a/libftasm/src/ft_printf/ft_conversion.c b/libftasm/src/ft_printf/ft_conversion.c index 3dbd8429..e1908f19 100644 --- a/libftasm/src/ft_printf/ft_conversion.c +++ b/libftasm/src/ft_printf/ft_conversion.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 13:31:48 by jhalford #+# #+# */ -/* Updated: 2016/11/07 16:56:28 by jhalford ### ########.fr */ +/* Updated: 2016/11/10 12:59:25 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libftasm/src/ft_printf/ft_fmt_validate_flags.c b/libftasm/src/ft_printf/ft_fmt_validate_flags.c index 82962cf4..cba3f389 100644 --- a/libftasm/src/ft_printf/ft_fmt_validate_flags.c +++ b/libftasm/src/ft_printf/ft_fmt_validate_flags.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 16:53:07 by jhalford #+# #+# */ -/* Updated: 2016/11/07 17:25:47 by jhalford ### ########.fr */ +/* Updated: 2016/11/10 13:02:07 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -38,12 +38,15 @@ static void ft_fmt_validate_flag_conv(t_fmt *fmt) i = 0; flag_ptr = fmt->flags; + while (fmt->conversion != g_convs[i].id) + i++; while (*flag_ptr) { flag = *flag_ptr; if (!ft_strchr(g_convs[i].allowed_flags, flag)) { ft_fmt_error_flag_conv(flag, fmt->conversion); + /* ft_printf("allowed flags:%s\n", g_convs[i].allowed_flags); */ if (flag == '#') *flag_ptr = '.'; } @@ -56,8 +59,6 @@ void ft_fmt_validate_flags(t_fmt *fmt) int i; i = 0; - while (fmt->conversion != g_convs[i].id) - i++; ft_fmt_validate_flag_conv(fmt); ft_fmt_validate_flag_flag(fmt); } diff --git a/libftasm/src/ft_printf/ft_printf.c b/libftasm/src/ft_printf/ft_printf.c index 3f37644a..5c79a190 100644 --- a/libftasm/src/ft_printf/ft_printf.c +++ b/libftasm/src/ft_printf/ft_printf.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 13:33:27 by jhalford #+# #+# */ -/* Updated: 2016/11/07 16:20:10 by jhalford ### ########.fr */ +/* Updated: 2016/11/10 12:59:41 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libftasm/src/ft_printf/ft_printf_parse.c b/libftasm/src/ft_printf/ft_printf_parse.c index 86a6cf74..fe3d2674 100644 --- a/libftasm/src/ft_printf/ft_printf_parse.c +++ b/libftasm/src/ft_printf/ft_printf_parse.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 13:33:24 by jhalford #+# #+# */ -/* Updated: 2016/11/07 16:56:47 by jhalford ### ########.fr */ +/* Updated: 2016/11/10 12:59:50 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libftasm/src/str/ft_strcat.c b/libftasm/src/str/ft_strcat.c index b2947ea8..f376d850 100644 --- a/libftasm/src/str/ft_strcat.c +++ b/libftasm/src/str/ft_strcat.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/08/07 10:56:53 by jhalford #+# #+# */ -/* Updated: 2016/08/20 23:16:44 by jhalford ### ########.fr */ +/* Updated: 2016/11/10 12:18:00 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,7 +19,7 @@ char *ft_strcat(char *s1, const char *s2) size = ft_strlen(s1); j = 0; - while (s2[j] != '\0') + while (s2 && s2[j]) { s1[size + j] = s2[j]; j++; diff --git a/libftasm/src/str/ft_strjoin.c b/libftasm/src/str/ft_strjoin.c index 58a57d14..943ded51 100644 --- a/libftasm/src/str/ft_strjoin.c +++ b/libftasm/src/str/ft_strjoin.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/03 14:58:18 by jhalford #+# #+# */ -/* Updated: 2016/11/03 14:58:18 by jhalford ### ########.fr */ +/* Updated: 2016/11/10 10:14:09 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libftasm/src/str/ft_strlen.c b/libftasm/src/str/ft_strlen.c index 4075825e..536f2bcf 100644 --- a/libftasm/src/str/ft_strlen.c +++ b/libftasm/src/str/ft_strlen.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/03 14:58:22 by jhalford #+# #+# */ -/* Updated: 2016/11/03 14:58:23 by jhalford ### ########.fr */ +/* Updated: 2016/11/10 10:14:18 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ From 3eef8e3f7b3439406cca5caa52059dcdd5842dec Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Fri, 11 Nov 2016 20:57:21 +0100 Subject: [PATCH 3/6] realloc, havent tested it yet :OOOO --- libftasm/includes/libft.h | 4 +++- libftasm/src/mem/ft_memalloc.c | 2 +- libftasm/src/mem/ft_memchr.c | 2 +- libftasm/src/mem/ft_memcpy.c | 2 +- libftasm/src/mem/ft_memmove.c | 2 +- libftasm/src/mem/ft_realloc.c | 23 +++++++++++++++++++++++ 6 files changed, 30 insertions(+), 5 deletions(-) create mode 100644 libftasm/src/mem/ft_realloc.c diff --git a/libftasm/includes/libft.h b/libftasm/includes/libft.h index 37fc15c2..311a94f2 100644 --- a/libftasm/includes/libft.h +++ b/libftasm/includes/libft.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 13:49:04 by jhalford #+# #+# */ -/* Updated: 2016/11/10 14:40:54 by jhalford ### ########.fr */ +/* Updated: 2016/11/11 17:47:12 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -128,4 +128,6 @@ char *ft_path_notdir(char *path); int ft_printf(const char *format, ...); char *ft_getenv(char **env, char *key); + +void *ft_realloc(void *data, int size) #endif diff --git a/libftasm/src/mem/ft_memalloc.c b/libftasm/src/mem/ft_memalloc.c index bb1bd18d..505043f8 100644 --- a/libftasm/src/mem/ft_memalloc.c +++ b/libftasm/src/mem/ft_memalloc.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/03 14:57:25 by jhalford #+# #+# */ -/* Updated: 2016/11/08 13:15:50 by jhalford ### ########.fr */ +/* Updated: 2016/11/11 17:40:57 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libftasm/src/mem/ft_memchr.c b/libftasm/src/mem/ft_memchr.c index 47eccf3b..96ddf009 100644 --- a/libftasm/src/mem/ft_memchr.c +++ b/libftasm/src/mem/ft_memchr.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/03 14:57:28 by jhalford #+# #+# */ -/* Updated: 2016/11/03 14:57:29 by jhalford ### ########.fr */ +/* Updated: 2016/11/11 17:41:21 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libftasm/src/mem/ft_memcpy.c b/libftasm/src/mem/ft_memcpy.c index 37e9051f..0b95291e 100644 --- a/libftasm/src/mem/ft_memcpy.c +++ b/libftasm/src/mem/ft_memcpy.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/03 14:57:31 by jhalford #+# #+# */ -/* Updated: 2016/11/08 13:17:29 by jhalford ### ########.fr */ +/* Updated: 2016/11/11 17:39:00 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libftasm/src/mem/ft_memmove.c b/libftasm/src/mem/ft_memmove.c index 996c5cb3..904d1aca 100644 --- a/libftasm/src/mem/ft_memmove.c +++ b/libftasm/src/mem/ft_memmove.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/03 14:57:34 by jhalford #+# #+# */ -/* Updated: 2016/11/07 13:46:42 by jhalford ### ########.fr */ +/* Updated: 2016/11/11 17:41:14 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libftasm/src/mem/ft_realloc.c b/libftasm/src/mem/ft_realloc.c new file mode 100644 index 00000000..33f6c10c --- /dev/null +++ b/libftasm/src/mem/ft_realloc.c @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_realloc.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/11 17:37:53 by jhalford #+# #+# */ +/* Updated: 2016/11/11 17:41:30 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void *ft_realloc(void *data, int size) +{ + void *new; + + new = ft_memalloc(size); + ft_memcpy(new, data, size); + ft_memdel(&data); + return (new); +} From 50f9e3d0d0bd427f8ac8b7eb2d0a8da888674ce8 Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Sat, 12 Nov 2016 23:54:09 +0100 Subject: [PATCH 4/6] naming convention change for dlst, btree functions --- libftasm/includes/btree.h | 30 ++++++++++++ libftasm/includes/dlst.h | 13 +++--- libftasm/includes/libft.h | 3 +- libftasm/src/btree/btree_apply_by_level.c | 46 +++++++++++++++++++ libftasm/src/btree/btree_apply_infix.c | 23 ++++++++++ libftasm/src/btree/btree_apply_prefix.c | 22 +++++++++ libftasm/src/btree/btree_apply_suffix.c | 23 ++++++++++ libftasm/src/btree/btree_create_node.c | 24 ++++++++++ libftasm/src/btree/btree_insert_data.c | 42 +++++++++++++++++ libftasm/src/btree/btree_level_count.c | 21 +++++++++ libftasm/src/btree/btree_search_item.c | 30 ++++++++++++ ...ft_dlst_add_after.c => ft_dlstadd_after.c} | 2 +- ..._dlst_add_before.c => ft_dlstadd_before.c} | 2 +- libftasm/src/dlst/ft_dlstdel.c | 11 +++++ .../{ft_dlst_delone.c => ft_dlstdelone.c} | 2 +- .../dlst/{ft_dlst_last.c => ft_dlstlast.c} | 2 +- .../src/dlst/{ft_dlst_new.c => ft_dlstnew.c} | 2 +- .../dlst/{ft_dlst_size.c => ft_dlstsize.c} | 2 +- libftasm/src/get_next_line/get_next_line.c | 4 +- libftasm/src/mem/ft_realloc.c | 4 +- libftasm/src/path/ft_path_findfile.c | 0 21 files changed, 292 insertions(+), 16 deletions(-) create mode 100644 libftasm/includes/btree.h create mode 100644 libftasm/src/btree/btree_apply_by_level.c create mode 100644 libftasm/src/btree/btree_apply_infix.c create mode 100644 libftasm/src/btree/btree_apply_prefix.c create mode 100644 libftasm/src/btree/btree_apply_suffix.c create mode 100644 libftasm/src/btree/btree_create_node.c create mode 100644 libftasm/src/btree/btree_insert_data.c create mode 100644 libftasm/src/btree/btree_level_count.c create mode 100644 libftasm/src/btree/btree_search_item.c rename libftasm/src/dlst/{ft_dlst_add_after.c => ft_dlstadd_after.c} (95%) rename libftasm/src/dlst/{ft_dlst_add_before.c => ft_dlstadd_before.c} (95%) create mode 100644 libftasm/src/dlst/ft_dlstdel.c rename libftasm/src/dlst/{ft_dlst_delone.c => ft_dlstdelone.c} (94%) rename libftasm/src/dlst/{ft_dlst_last.c => ft_dlstlast.c} (96%) rename libftasm/src/dlst/{ft_dlst_new.c => ft_dlstnew.c} (95%) rename libftasm/src/dlst/{ft_dlst_size.c => ft_dlstsize.c} (97%) create mode 100644 libftasm/src/path/ft_path_findfile.c diff --git a/libftasm/includes/btree.h b/libftasm/includes/btree.h new file mode 100644 index 00000000..ab5b587e --- /dev/null +++ b/libftasm/includes/btree.h @@ -0,0 +1,30 @@ +#ifndef BTREE_H +# define BTREE_H + +#include "libft.h" + +typedef struct s_btree t_btree; + +struct s_btree +{ + struct s_btree *left; + struct s_btree *right; + void *item; +}; + +t_btree *btree_create_node(void *item); + +void btree_insert_data( + t_btree **root, + void *item, + int (*cmpf)(void *, void *)); + +void *btree_search_item(t_btree *root, + void *data_ref, int (*cmpf)(void *, void *)); + +int btree_level_count(t_btree *root); +void btree_apply_prefix(t_btree *root, void (*applyf)(void *)); +void btree_apply_infix(t_btree *root, void (*applyf)(void *)); +void btree_apply_suffix(t_btree *root, void (*applyf)(void *)); + +#endif diff --git a/libftasm/includes/dlst.h b/libftasm/includes/dlst.h index ffcf518f..42d73729 100644 --- a/libftasm/includes/dlst.h +++ b/libftasm/includes/dlst.h @@ -23,12 +23,13 @@ struct s_dlist typedef struct s_dlist t_dlist; -void ft_dlst_add_after(t_dlist **alst, t_dlist *new); -void ft_dlst_add_before(t_dlist **alst, t_dlist *new); -void ft_dlst_delone(t_dlist **alst, void (*del)(void *, size_t)); -int ft_dlst_size(t_dlist *list); -t_dlist *ft_dlst_new(void const *content, size_t content_size); -t_dlist *ft_dlst_last(t_dlist *list); +void ft_dlstadd_after(t_dlist **alst, t_dlist *new); +void ft_dlstadd_before(t_dlist **alst, t_dlist *new); +void ft_dlstdel(t_dlist **alst, void (*del)(void *, size_t)); +void ft_dlstdelone(t_dlist **alst, void (*del)(void *, size_t)); +int ft_dlstsize(t_dlist *list); +t_dlist *ft_dlstnew(void const *content, size_t content_size); +t_dlist *ft_dlstlast(t_dlist *list); char *ft_dlsttostr(t_dlist *list); #endif diff --git a/libftasm/includes/libft.h b/libftasm/includes/libft.h index 311a94f2..39f21ec7 100644 --- a/libftasm/includes/libft.h +++ b/libftasm/includes/libft.h @@ -16,6 +16,7 @@ # include "ft_xattr.h" # include "lst.h" # include "dlst.h" +# include "btree.h" # include # include @@ -129,5 +130,5 @@ int ft_printf(const char *format, ...); char *ft_getenv(char **env, char *key); -void *ft_realloc(void *data, int size) +void *ft_realloc(void *data, int size); #endif diff --git a/libftasm/src/btree/btree_apply_by_level.c b/libftasm/src/btree/btree_apply_by_level.c new file mode 100644 index 00000000..0cb2c4bd --- /dev/null +++ b/libftasm/src/btree/btree_apply_by_level.c @@ -0,0 +1,46 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* btree_apply_by_level.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/08/19 12:06:15 by jhalford #+# #+# */ +/* Updated: 2016/08/23 17:49:17 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "btree.h" + +int g_level = 0; + +static void btree_apply_to_level( + t_btree *root, + int level, + int is_first_elem, + void (*applyf)(void *item, int current_level, int is_first_elem)) +{ + if (level == g_level) + { + (*applyf)(root->item, level, is_first_elem); + return ; + } + if (root->left) + btree_apply_to_level(root->left, level + 1, is_first_elem, applyf); + if (root->right) + btree_apply_to_level(root->right, level + 1, 0, applyf); +} + +void btree_apply_by_level( + t_btree *root, + void (*applyf)(void *item, int current_level, int is_first_elem)) +{ + int height; + + height = btree_level_count(root); + while (g_level < height) + { + btree_apply_to_level(root, 0, 1, applyf); + g_level++; + } +} diff --git a/libftasm/src/btree/btree_apply_infix.c b/libftasm/src/btree/btree_apply_infix.c new file mode 100644 index 00000000..65d2b5d6 --- /dev/null +++ b/libftasm/src/btree/btree_apply_infix.c @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* btree_create_node.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/08/16 13:43:51 by jhalford #+# #+# */ +/* Updated: 2016/08/18 21:10:05 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "btree.h" + +void btree_apply_infix(t_btree *root, void (*applyf)(void *)) +{ + if (root->left) + btree_apply_infix(root->left, applyf); + (*applyf)(root->item); + if (root->right) + btree_apply_infix(root->right, applyf); + return ; +} diff --git a/libftasm/src/btree/btree_apply_prefix.c b/libftasm/src/btree/btree_apply_prefix.c new file mode 100644 index 00000000..e7e4332c --- /dev/null +++ b/libftasm/src/btree/btree_apply_prefix.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* btree_create_node.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/08/16 13:43:51 by jhalford #+# #+# */ +/* Updated: 2016/08/18 21:06:44 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "btree.h" + +void btree_apply_prefix(t_btree *root, void (*applyf)(void *)) +{ + (*applyf)(root->item); + if (root->left) + btree_apply_prefix(root->left, applyf); + if (root->right) + btree_apply_prefix(root->right, applyf); +} diff --git a/libftasm/src/btree/btree_apply_suffix.c b/libftasm/src/btree/btree_apply_suffix.c new file mode 100644 index 00000000..9cf8b4ea --- /dev/null +++ b/libftasm/src/btree/btree_apply_suffix.c @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* btree_create_node.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/08/16 13:43:51 by jhalford #+# #+# */ +/* Updated: 2016/08/18 21:11:19 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "btree.h" + +void btree_apply_suffix(t_btree *root, void (*applyf)(void *)) +{ + if (root->left) + btree_apply_suffix(root->left, applyf); + if (root->right) + btree_apply_suffix(root->right, applyf); + (*applyf)(root->item); + return ; +} diff --git a/libftasm/src/btree/btree_create_node.c b/libftasm/src/btree/btree_create_node.c new file mode 100644 index 00000000..b50c4be4 --- /dev/null +++ b/libftasm/src/btree/btree_create_node.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* btree_create_node.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/08/16 13:43:51 by jhalford #+# #+# */ +/* Updated: 2016/08/19 23:32:10 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "btree.h" + +t_btree *btree_create_node(void *item) +{ + t_btree *node; + + node = (t_btree *)malloc(sizeof(t_btree)); + node->left = 0; + node->right = 0; + node->item = item; + return (node); +} diff --git a/libftasm/src/btree/btree_insert_data.c b/libftasm/src/btree/btree_insert_data.c new file mode 100644 index 00000000..1c88672e --- /dev/null +++ b/libftasm/src/btree/btree_insert_data.c @@ -0,0 +1,42 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* btree_create_node.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/08/16 13:43:51 by jhalford #+# #+# */ +/* Updated: 2016/08/19 14:12:59 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "btree.h" + +void btree_insert_data( + t_btree **root, + void *item, + int (*cmpf)(void *, void *)) +{ + t_btree *node; + + if (!*root) + { + *root = btree_create_node(item); + return ; + } + node = *root; + if ((*cmpf)(item, node->item) < 0) + { + if (node->left) + btree_insert_data(&node->left, item, cmpf); + else + node->left = btree_create_node(item); + } + else + { + if (node->right) + btree_insert_data(&node->right, item, cmpf); + else + node->right = btree_create_node(item); + } +} diff --git a/libftasm/src/btree/btree_level_count.c b/libftasm/src/btree/btree_level_count.c new file mode 100644 index 00000000..41248654 --- /dev/null +++ b/libftasm/src/btree/btree_level_count.c @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* btree_create_node.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/08/16 13:43:51 by jhalford #+# #+# */ +/* Updated: 2016/08/25 17:46:00 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "btree.h" + +int btree_level_count(t_btree *root) +{ + return (root + ? 1 + FT_MAX(btree_level_count(root->left), + btree_level_count(root->right)) + : 0); +} diff --git a/libftasm/src/btree/btree_search_item.c b/libftasm/src/btree/btree_search_item.c new file mode 100644 index 00000000..a7a1eb68 --- /dev/null +++ b/libftasm/src/btree/btree_search_item.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* btree_create_node.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/08/16 13:43:51 by jhalford #+# #+# */ +/* Updated: 2016/08/23 19:04:56 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "btree.h" + +void *btree_search_item(t_btree *root, + void *data_ref, int (*cmpf)(void *, void *)) +{ + void *out; + + out = NULL; + if (root) + { + out = btree_search_item(root->left, data_ref, cmpf); + if (!out && ((*cmpf)(root->item, data_ref) == 0)) + out = root->item; + if (!out) + out = btree_search_item(root->right, data_ref, cmpf); + } + return (out); +} diff --git a/libftasm/src/dlst/ft_dlst_add_after.c b/libftasm/src/dlst/ft_dlstadd_after.c similarity index 95% rename from libftasm/src/dlst/ft_dlst_add_after.c rename to libftasm/src/dlst/ft_dlstadd_after.c index c1fa36eb..caec607d 100644 --- a/libftasm/src/dlst/ft_dlst_add_after.c +++ b/libftasm/src/dlst/ft_dlstadd_after.c @@ -12,7 +12,7 @@ #include "libft.h" -void ft_dlst_add_after(t_dlist **alst, t_dlist *new) +void ft_dlstadd_after(t_dlist **alst, t_dlist *new) { if (new) { diff --git a/libftasm/src/dlst/ft_dlst_add_before.c b/libftasm/src/dlst/ft_dlstadd_before.c similarity index 95% rename from libftasm/src/dlst/ft_dlst_add_before.c rename to libftasm/src/dlst/ft_dlstadd_before.c index 5025986c..e2d6b2e8 100644 --- a/libftasm/src/dlst/ft_dlst_add_before.c +++ b/libftasm/src/dlst/ft_dlstadd_before.c @@ -12,7 +12,7 @@ #include "libft.h" -void ft_dlst_add_before(t_dlist **alst, t_dlist *new) +void ft_dlstadd_before(t_dlist **alst, t_dlist *new) { if (new) { diff --git a/libftasm/src/dlst/ft_dlstdel.c b/libftasm/src/dlst/ft_dlstdel.c new file mode 100644 index 00000000..43131fb7 --- /dev/null +++ b/libftasm/src/dlst/ft_dlstdel.c @@ -0,0 +1,11 @@ +#include "libft.h" + +void ft_dlstdel(t_dlist **alst, void (*del)(void *, size_t)) +{ + if (alst && *alst) + { + ft_dlstdel(&(*alst)->next, del); + ft_dlstdel(&(*alst)->prev, del); + } + ft_dlstdelone(alst, del); +} diff --git a/libftasm/src/dlst/ft_dlst_delone.c b/libftasm/src/dlst/ft_dlstdelone.c similarity index 94% rename from libftasm/src/dlst/ft_dlst_delone.c rename to libftasm/src/dlst/ft_dlstdelone.c index ff83b296..a83bf62e 100644 --- a/libftasm/src/dlst/ft_dlst_delone.c +++ b/libftasm/src/dlst/ft_dlstdelone.c @@ -12,7 +12,7 @@ #include "libft.h" -void ft_dlst_delone(t_dlist **alst, void (*del)(void *, size_t)) +void ft_dlstdelone(t_dlist **alst, void (*del)(void *, size_t)) { t_dlist *tmp; diff --git a/libftasm/src/dlst/ft_dlst_last.c b/libftasm/src/dlst/ft_dlstlast.c similarity index 96% rename from libftasm/src/dlst/ft_dlst_last.c rename to libftasm/src/dlst/ft_dlstlast.c index 9772cc0c..1286c32c 100644 --- a/libftasm/src/dlst/ft_dlst_last.c +++ b/libftasm/src/dlst/ft_dlstlast.c @@ -12,7 +12,7 @@ #include "libft.h" -t_dlist *ft_dlst_last(t_dlist *list) +t_dlist *ft_dlstlast(t_dlist *list) { while (list && list->next) list = list->next; diff --git a/libftasm/src/dlst/ft_dlst_new.c b/libftasm/src/dlst/ft_dlstnew.c similarity index 95% rename from libftasm/src/dlst/ft_dlst_new.c rename to libftasm/src/dlst/ft_dlstnew.c index 8725382f..dfe32bdc 100644 --- a/libftasm/src/dlst/ft_dlst_new.c +++ b/libftasm/src/dlst/ft_dlstnew.c @@ -12,7 +12,7 @@ #include "libft.h" -t_dlist *ft_dlst_new(void const *content, size_t content_size) +t_dlist *ft_dlstnew(void const *content, size_t content_size) { t_dlist *new; diff --git a/libftasm/src/dlst/ft_dlst_size.c b/libftasm/src/dlst/ft_dlstsize.c similarity index 97% rename from libftasm/src/dlst/ft_dlst_size.c rename to libftasm/src/dlst/ft_dlstsize.c index 9777bb11..b536efa2 100644 --- a/libftasm/src/dlst/ft_dlst_size.c +++ b/libftasm/src/dlst/ft_dlstsize.c @@ -12,7 +12,7 @@ #include "libft.h" -int ft_dlst_size(t_dlist *list) +int ft_dlstsize(t_dlist *list) { int size; t_dlist *tmp; diff --git a/libftasm/src/get_next_line/get_next_line.c b/libftasm/src/get_next_line/get_next_line.c index 3263c520..cc8d1cdf 100644 --- a/libftasm/src/get_next_line/get_next_line.c +++ b/libftasm/src/get_next_line/get_next_line.c @@ -13,7 +13,7 @@ #include "libft.h" #define BUFF_SIZE 32 -static char *ft_realloc(char *line, int size) +static char *ft_strrealloc(char *line, int size) { char *str; @@ -41,7 +41,7 @@ static int ft_loop_read(int fd, char **line, char (*save)[]) ft_strcat(*line, buf); return (1); } - if ((*line = ft_realloc(*line, ret)) == NULL) + if ((*line = ft_strrealloc(*line, ret)) == NULL) return (-1); ft_strcat(*line, buf); } diff --git a/libftasm/src/mem/ft_realloc.c b/libftasm/src/mem/ft_realloc.c index 33f6c10c..f64a50d0 100644 --- a/libftasm/src/mem/ft_realloc.c +++ b/libftasm/src/mem/ft_realloc.c @@ -16,8 +16,10 @@ void *ft_realloc(void *data, int size) { void *new; + ft_printf("realloc befor: '%s'\n", data); new = ft_memalloc(size); - ft_memcpy(new, data, size); + ft_memcpy(new, data, ft_strlen(data)); ft_memdel(&data); + ft_printf("realloc after: '%s'\n", new); return (new); } diff --git a/libftasm/src/path/ft_path_findfile.c b/libftasm/src/path/ft_path_findfile.c new file mode 100644 index 00000000..e69de29b From 3c58cb010ddd29041ff3a48e90524fdf9e3f92d8 Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Sun, 13 Nov 2016 23:59:19 +0100 Subject: [PATCH 5/6] btree new nodes now mallocs and memcpy --- libftasm/includes/btree.h | 5 +++-- libftasm/src/btree/btree_create_node.c | 17 ++++++++++++++--- libftasm/src/lst/ft_lstnew.c | 10 +++------- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/libftasm/includes/btree.h b/libftasm/includes/btree.h index ab5b587e..6e6d4215 100644 --- a/libftasm/includes/btree.h +++ b/libftasm/includes/btree.h @@ -7,12 +7,13 @@ typedef struct s_btree t_btree; struct s_btree { + void *item; + size_t content_size; struct s_btree *left; struct s_btree *right; - void *item; }; -t_btree *btree_create_node(void *item); +t_btree *btree_create_node(void const *item, size_t content_size); void btree_insert_data( t_btree **root, diff --git a/libftasm/src/btree/btree_create_node.c b/libftasm/src/btree/btree_create_node.c index b50c4be4..83170a7f 100644 --- a/libftasm/src/btree/btree_create_node.c +++ b/libftasm/src/btree/btree_create_node.c @@ -12,13 +12,24 @@ #include "btree.h" -t_btree *btree_create_node(void *item) +t_btree *btree_create_node(void const *item, size_t content_size) { t_btree *node; - node = (t_btree *)malloc(sizeof(t_btree)); + if (!(node = (t_btree *)malloc(sizeof(t_btree)))) + return (NULL); node->left = 0; node->right = 0; - node->item = item; return (node); + if (!content) + { + new->content_size = 0; + new->item = NULL; + } + else + { + new->content_size = content_size; + new->item = ft_memalloc(content_size + 1); + ft_memcpy(new->item, item, content_size); + } } diff --git a/libftasm/src/lst/ft_lstnew.c b/libftasm/src/lst/ft_lstnew.c index 1ad8c10a..302aff27 100644 --- a/libftasm/src/lst/ft_lstnew.c +++ b/libftasm/src/lst/ft_lstnew.c @@ -16,23 +16,19 @@ t_list *ft_lstnew(void const *content, size_t content_size) { t_list *new; + if (!(new = (t_list *)malloc(sizeof(*new)))) + return (NULL); + new->next = NULL; if (!content) { - new = malloc(sizeof(*new)); - if (!new) - return (NULL); new->content_size = 0; new->content = NULL; } else { - new = (t_list *)malloc(sizeof(*new)); - if (!new) - return (NULL); new->content_size = content_size; new->content = ft_memalloc(content_size + 1); ft_memcpy(new->content, content, content_size); } - new->next = NULL; return (new); } From 23cf5a7972f67aad17146436b3084c7ac48887b5 Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Tue, 15 Nov 2016 20:21:15 +0100 Subject: [PATCH 6/6] btree stuff --- libftasm/includes/btree.h | 2 ++ libftasm/includes/libft.h | 3 +- libftasm/src/btree/btree_apply_infix.c | 2 +- libftasm/src/btree/btree_apply_suffix.c | 2 +- libftasm/src/btree/btree_create_node.c | 14 ++++----- libftasm/src/btree/btree_insert_data.c | 13 ++++---- libftasm/src/btree/btree_print.c | 41 +++++++++++++++++++++++++ libftasm/src/dlst/ft_dlstdel.c | 38 ++++++++++++++++++++--- libftasm/src/dlst/ft_dlstdelone.c | 2 +- libftasm/src/dlst/ft_dlstrtostr.c | 4 +-- libftasm/src/lst/ft_lst_delif.c | 2 +- libftasm/src/lst/ft_lstdelone.c | 2 +- libftasm/src/math/ft_addrcmp.c | 18 +++++++++++ libftasm/src/path/ft_path_findfile.c | 0 libftasm/src/sstr/ft_sstradd.c | 2 +- libftasm/src/sstr/ft_sstrfree.c | 11 +++++-- 16 files changed, 127 insertions(+), 29 deletions(-) create mode 100644 libftasm/src/btree/btree_print.c create mode 100644 libftasm/src/math/ft_addrcmp.c delete mode 100644 libftasm/src/path/ft_path_findfile.c diff --git a/libftasm/includes/btree.h b/libftasm/includes/btree.h index 6e6d4215..c31ca5a2 100644 --- a/libftasm/includes/btree.h +++ b/libftasm/includes/btree.h @@ -18,6 +18,7 @@ t_btree *btree_create_node(void const *item, size_t content_size); void btree_insert_data( t_btree **root, void *item, + size_t content_size, int (*cmpf)(void *, void *)); void *btree_search_item(t_btree *root, @@ -27,5 +28,6 @@ int btree_level_count(t_btree *root); void btree_apply_prefix(t_btree *root, void (*applyf)(void *)); void btree_apply_infix(t_btree *root, void (*applyf)(void *)); void btree_apply_suffix(t_btree *root, void (*applyf)(void *)); +void btree_print(t_btree* tree, void (*printer)(t_btree *tree)); #endif diff --git a/libftasm/includes/libft.h b/libftasm/includes/libft.h index 39f21ec7..f3714ec2 100644 --- a/libftasm/includes/libft.h +++ b/libftasm/includes/libft.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 13:49:04 by jhalford #+# #+# */ -/* Updated: 2016/11/11 17:47:12 by jhalford ### ########.fr */ +/* Updated: 2016/11/14 16:31:04 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -114,6 +114,7 @@ size_t ft_ilen_base(int n, int base); size_t ft_uilen(unsigned int n); size_t ft_lllen(long long n); size_t ft_lllen_base(long long n, int base); +int ft_addrcmp(void *a, void *b); char **ft_sstradd(char **list, char *new); void ft_sstrsort(char **list, int size, int (*cmp)()); diff --git a/libftasm/src/btree/btree_apply_infix.c b/libftasm/src/btree/btree_apply_infix.c index 65d2b5d6..f4b95302 100644 --- a/libftasm/src/btree/btree_apply_infix.c +++ b/libftasm/src/btree/btree_apply_infix.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/08/16 13:43:51 by jhalford #+# #+# */ -/* Updated: 2016/08/18 21:10:05 by jhalford ### ########.fr */ +/* Updated: 2016/11/14 11:58:47 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libftasm/src/btree/btree_apply_suffix.c b/libftasm/src/btree/btree_apply_suffix.c index 9cf8b4ea..08f01881 100644 --- a/libftasm/src/btree/btree_apply_suffix.c +++ b/libftasm/src/btree/btree_apply_suffix.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/08/16 13:43:51 by jhalford #+# #+# */ -/* Updated: 2016/08/18 21:11:19 by jhalford ### ########.fr */ +/* Updated: 2016/11/14 16:08:23 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libftasm/src/btree/btree_create_node.c b/libftasm/src/btree/btree_create_node.c index 83170a7f..18f50233 100644 --- a/libftasm/src/btree/btree_create_node.c +++ b/libftasm/src/btree/btree_create_node.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/08/16 13:43:51 by jhalford #+# #+# */ -/* Updated: 2016/08/19 23:32:10 by jhalford ### ########.fr */ +/* Updated: 2016/11/14 16:11:49 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,14 +14,13 @@ t_btree *btree_create_node(void const *item, size_t content_size) { - t_btree *node; + t_btree *new; - if (!(node = (t_btree *)malloc(sizeof(t_btree)))) + if (!(new = (t_btree *)malloc(sizeof(t_btree)))) return (NULL); - node->left = 0; - node->right = 0; - return (node); - if (!content) + new->left = 0; + new->right = 0; + if (!item) { new->content_size = 0; new->item = NULL; @@ -32,4 +31,5 @@ t_btree *btree_create_node(void const *item, size_t content_size) new->item = ft_memalloc(content_size + 1); ft_memcpy(new->item, item, content_size); } + return (new); } diff --git a/libftasm/src/btree/btree_insert_data.c b/libftasm/src/btree/btree_insert_data.c index 1c88672e..a6e262fc 100644 --- a/libftasm/src/btree/btree_insert_data.c +++ b/libftasm/src/btree/btree_insert_data.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/08/16 13:43:51 by jhalford #+# #+# */ -/* Updated: 2016/08/19 14:12:59 by jhalford ### ########.fr */ +/* Updated: 2016/11/14 16:12:47 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,28 +15,29 @@ void btree_insert_data( t_btree **root, void *item, + size_t content_size, int (*cmpf)(void *, void *)) { t_btree *node; if (!*root) { - *root = btree_create_node(item); + *root = btree_create_node(item, content_size); return ; } node = *root; if ((*cmpf)(item, node->item) < 0) { if (node->left) - btree_insert_data(&node->left, item, cmpf); + btree_insert_data(&node->left, item, content_size, cmpf); else - node->left = btree_create_node(item); + node->left = btree_create_node(item, content_size); } else { if (node->right) - btree_insert_data(&node->right, item, cmpf); + btree_insert_data(&node->right, item, content_size, cmpf); else - node->right = btree_create_node(item); + node->right = btree_create_node(item, content_size); } } diff --git a/libftasm/src/btree/btree_print.c b/libftasm/src/btree/btree_print.c new file mode 100644 index 00000000..c236a5d2 --- /dev/null +++ b/libftasm/src/btree/btree_print.c @@ -0,0 +1,41 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* btree_print.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/14 18:06:24 by jhalford #+# #+# */ +/* Updated: 2016/11/14 18:26:32 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "btree.h" + +static void print_offset(int offset) +{ + int i; + for (i = 0; i < offset; ++i) + { + ft_putstr(" "); + } +} + +void btree_print(t_btree* tree, void (*printer)(t_btree *tree)) +{ + static int offset = 0; + + print_offset(offset); + + if (tree == NULL) + { + ft_putendl("-"); + return; + } + (*printer)(tree); + + offset += 3; + btree_print(tree->right, printer); + btree_print(tree->left, printer); + offset -= 3; +} diff --git a/libftasm/src/dlst/ft_dlstdel.c b/libftasm/src/dlst/ft_dlstdel.c index 43131fb7..24adc231 100644 --- a/libftasm/src/dlst/ft_dlstdel.c +++ b/libftasm/src/dlst/ft_dlstdel.c @@ -1,11 +1,41 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_dlstdel.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/14 17:55:40 by jhalford #+# #+# */ +/* Updated: 2016/11/14 17:57:46 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + #include "libft.h" +static void ft_dlstdelback(t_dlist **alst, void (*del)(void *, size_t)) +{ + if (alst && *alst && del) + { + ft_dlstdelback(&(*alst)->prev, del); + ft_dlstdelone(alst, del); + } +} + +static void ft_dlstdelfront(t_dlist **alst, void (*del)(void *, size_t)) +{ + if (alst && *alst && del) + { + ft_dlstdelfront(&(*alst)->next, del); + ft_dlstdelone(alst, del); + } +} + void ft_dlstdel(t_dlist **alst, void (*del)(void *, size_t)) { - if (alst && *alst) + if (alst && *alst && del) { - ft_dlstdel(&(*alst)->next, del); - ft_dlstdel(&(*alst)->prev, del); + ft_dlstdelback(&(*alst)->prev, del); + ft_dlstdelfront(&(*alst)->next, del); + ft_dlstdelone(alst, del); } - ft_dlstdelone(alst, del); } diff --git a/libftasm/src/dlst/ft_dlstdelone.c b/libftasm/src/dlst/ft_dlstdelone.c index a83bf62e..55826853 100644 --- a/libftasm/src/dlst/ft_dlstdelone.c +++ b/libftasm/src/dlst/ft_dlstdelone.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 13:27:13 by jhalford #+# #+# */ -/* Updated: 2016/11/07 13:27:13 by jhalford ### ########.fr */ +/* Updated: 2016/11/14 17:52:58 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libftasm/src/dlst/ft_dlstrtostr.c b/libftasm/src/dlst/ft_dlstrtostr.c index be96ba71..e92e4d8a 100644 --- a/libftasm/src/dlst/ft_dlstrtostr.c +++ b/libftasm/src/dlst/ft_dlstrtostr.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 13:27:29 by jhalford #+# #+# */ -/* Updated: 2016/11/07 13:31:08 by jhalford ### ########.fr */ +/* Updated: 2016/11/14 16:13:24 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,7 +20,7 @@ char *ft_dlsttostr(t_dlist *list) return (NULL); while (list->prev) list = list->prev; - str = (char *)ft_strnew(sizeof(char) * (ft_dlst_size(list) + 2)); + str = (char *)ft_strnew(sizeof(char) * (ft_dlstsize(list) + 2)); while (list) { ft_strcat(str, (char *)list->content); diff --git a/libftasm/src/lst/ft_lst_delif.c b/libftasm/src/lst/ft_lst_delif.c index 2e319aa9..b1d11a0a 100644 --- a/libftasm/src/lst/ft_lst_delif.c +++ b/libftasm/src/lst/ft_lst_delif.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/04 11:09:12 by jhalford #+# #+# */ -/* Updated: 2016/11/08 15:00:24 by jhalford ### ########.fr */ +/* Updated: 2016/11/14 16:55:27 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libftasm/src/lst/ft_lstdelone.c b/libftasm/src/lst/ft_lstdelone.c index d9b05960..a360b486 100644 --- a/libftasm/src/lst/ft_lstdelone.c +++ b/libftasm/src/lst/ft_lstdelone.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/03 14:57:15 by jhalford #+# #+# */ -/* Updated: 2016/11/08 13:45:13 by jhalford ### ########.fr */ +/* Updated: 2016/11/14 15:50:00 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libftasm/src/math/ft_addrcmp.c b/libftasm/src/math/ft_addrcmp.c new file mode 100644 index 00000000..f3b4f790 --- /dev/null +++ b/libftasm/src/math/ft_addrcmp.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_addrcmp.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/14 15:59:10 by jhalford #+# #+# */ +/* Updated: 2016/11/14 15:59:39 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_addrcmp(void *a, void *b) +{ + return (a - b); +} diff --git a/libftasm/src/path/ft_path_findfile.c b/libftasm/src/path/ft_path_findfile.c deleted file mode 100644 index e69de29b..00000000 diff --git a/libftasm/src/sstr/ft_sstradd.c b/libftasm/src/sstr/ft_sstradd.c index e88b1651..55cad1f1 100644 --- a/libftasm/src/sstr/ft_sstradd.c +++ b/libftasm/src/sstr/ft_sstradd.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/03 18:03:58 by jhalford #+# #+# */ -/* Updated: 2016/11/10 12:15:23 by jhalford ### ########.fr */ +/* Updated: 2016/11/14 16:31:02 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libftasm/src/sstr/ft_sstrfree.c b/libftasm/src/sstr/ft_sstrfree.c index 05686e2b..14a833eb 100644 --- a/libftasm/src/sstr/ft_sstrfree.c +++ b/libftasm/src/sstr/ft_sstrfree.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/08 17:01:24 by jhalford #+# #+# */ -/* Updated: 2016/11/10 12:11:20 by jhalford ### ########.fr */ +/* Updated: 2016/11/14 11:08:19 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,9 +17,14 @@ void ft_sstrfree(char **sstr) int i; i = 0; - while (sstr[i]) + if (sstr) { + while (sstr[i]) + { + ft_strdel(sstr + i); + i++; + } ft_strdel(sstr + i); - i++; + free(sstr); } }