diff --git a/libftasm/includes/btree.h b/libftasm/includes/btree.h index c31ca5a2..d328eed8 100644 --- a/libftasm/includes/btree.h +++ b/libftasm/includes/btree.h @@ -1,7 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* btree.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/16 11:13:15 by jhalford #+# #+# */ +/* Updated: 2016/11/16 11:14:02 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + #ifndef BTREE_H # define BTREE_H -#include "libft.h" +# include "libft.h" typedef struct s_btree t_btree; @@ -28,6 +40,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)); +void btree_print(t_btree *tree, void (*printer)(t_btree *tree)); #endif diff --git a/libftasm/src/btree/btree_apply_by_level.c b/libftasm/src/btree/btree_apply_by_level.c index 0cb2c4bd..09619fee 100644 --- a/libftasm/src/btree/btree_apply_by_level.c +++ b/libftasm/src/btree/btree_apply_by_level.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/08/19 12:06:15 by jhalford #+# #+# */ -/* Updated: 2016/08/23 17:49:17 by jhalford ### ########.fr */ +/* Updated: 2016/11/16 11:14:28 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -31,9 +31,9 @@ static void btree_apply_to_level( 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)) +void btree_apply_by_level( + t_btree *root, + void (*applyf)(void *item, int current_level, int is_first_elem)) { int height; diff --git a/libftasm/src/btree/btree_print.c b/libftasm/src/btree/btree_print.c index c236a5d2..748a94c5 100644 --- a/libftasm/src/btree/btree_print.c +++ b/libftasm/src/btree/btree_print.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/14 18:06:24 by jhalford #+# #+# */ -/* Updated: 2016/11/14 18:26:32 by jhalford ### ########.fr */ +/* Updated: 2016/11/16 11:24:32 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,25 +15,26 @@ static void print_offset(int offset) { int i; - for (i = 0; i < offset; ++i) + + i = 0; + while (i < offset) { ft_putstr(" "); + i++; } } -void btree_print(t_btree* tree, void (*printer)(t_btree *tree)) +void btree_print(t_btree *tree, void (*printer)(t_btree *tree)) { static int offset = 0; print_offset(offset); - if (tree == NULL) { ft_putendl("-"); - return; + return ; } (*printer)(tree); - offset += 3; btree_print(tree->right, printer); btree_print(tree->left, printer); diff --git a/libftasm/src/dlst/ft_dlstdel.c b/libftasm/src/dlst/ft_dlstdel.c index 24adc231..43d0eb63 100644 --- a/libftasm/src/dlst/ft_dlstdel.c +++ b/libftasm/src/dlst/ft_dlstdel.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/14 17:55:40 by jhalford #+# #+# */ -/* Updated: 2016/11/14 17:57:46 by jhalford ### ########.fr */ +/* Updated: 2016/11/16 11:15:40 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -30,7 +30,7 @@ static void ft_dlstdelfront(t_dlist **alst, void (*del)(void *, size_t)) } } -void ft_dlstdel(t_dlist **alst, void (*del)(void *, size_t)) +void ft_dlstdel(t_dlist **alst, void (*del)(void *, size_t)) { if (alst && *alst && del) { diff --git a/libftasm/src/env/ft_getenv.c b/libftasm/src/env/ft_getenv.c index 3c733605..65ff27a7 100644 --- a/libftasm/src/env/ft_getenv.c +++ b/libftasm/src/env/ft_getenv.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/10 14:30:00 by jhalford #+# #+# */ -/* Updated: 2016/11/10 14:30:27 by jhalford ### ########.fr */ +/* Updated: 2016/11/16 11:24:52 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,7 +18,6 @@ char *ft_getenv(char **env, char *key) return (NULL); while (*env) { - /* ft_printf("%s\n", env[i]); */ if (ft_strcmp(*env, key) == '=') return (*env + ft_strlen(key) + 1); env++; diff --git a/libftasm/src/ft_printf/ft_conversion.c b/libftasm/src/ft_printf/ft_conversion.c index e1908f19..f8844a94 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/10 12:59:25 by jhalford ### ########.fr */ +/* Updated: 2016/11/16 18:30:20 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -33,9 +33,9 @@ char *ft_unsigned_conversion(t_fmt *fmt, va_list ap) while (fmt->conversion != g_convs[i].id) i++; if (!*fmt->modifier - || ft_strcmp(fmt->modifier, "hh") == 0 - || ft_strcmp(fmt->modifier, "h") == 0 - || ft_strcmp(fmt->modifier, "z") == 0) + || ft_strequ(fmt->modifier, "hh") + || ft_strequ(fmt->modifier, "h") + || ft_strequ(fmt->modifier, "z")) { uiarg = va_arg(ap, int); return (ft_uitoa_base(uiarg, g_convs[i].base)); diff --git a/libftasm/src/ft_printf/ft_fmt_validate_flags.c b/libftasm/src/ft_printf/ft_fmt_validate_flags.c index cba3f389..3f5892e1 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/10 13:02:07 by jhalford ### ########.fr */ +/* Updated: 2016/11/16 11:15:55 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -46,7 +46,6 @@ static void ft_fmt_validate_flag_conv(t_fmt *fmt) 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 = '.'; } diff --git a/libftasm/src/ft_printf/ft_printf.c b/libftasm/src/ft_printf/ft_printf.c index d58717e0..ca094456 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/16 10:58:04 by jhalford ### ########.fr */ +/* Updated: 2016/11/16 18:30:10 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -30,7 +30,7 @@ int ft_printf(const char *format, ...) va_list ap; va_start(ap, format); - return(ft_vdprintf(0, format, ap)); + return (ft_vdprintf(1, format, ap)); } int ft_dprintf(int fd, const char *format, ...) @@ -38,16 +38,17 @@ int ft_dprintf(int fd, const char *format, ...) va_list ap; va_start(ap, format); - return(ft_vdprintf(fd, format, ap)); + return (ft_vdprintf(fd, format, ap)); } int ft_vdprintf(int fd, const char *format, va_list ap) { char *str; + char *transform; char final[1000]; t_fmt *fmt; - str = ft_strdup(format); + str = (char *)format; ft_bzero(final, 1000); while (*str) { @@ -59,12 +60,16 @@ int ft_vdprintf(int fd, const char *format, va_list ap) if (!fmt->valid) ft_strncat(final, &fmt->conversion, 1); else - ft_strcat(final, ft_transform(fmt, ap)); + { + transform = ft_transform(fmt, ap); + ft_strcat(final, transform); + free(transform); + } + free(fmt); } else ft_strncat(final, str++, 1); } ft_putstr_fd(final, fd); - ft_strdel(&str); return (0); } diff --git a/libftasm/src/ft_printf/ft_transform.c b/libftasm/src/ft_printf/ft_transform.c index cfdcd863..edadbed2 100644 --- a/libftasm/src/ft_printf/ft_transform.c +++ b/libftasm/src/ft_printf/ft_transform.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 13:33:32 by jhalford #+# #+# */ -/* Updated: 2016/11/07 16:40:15 by jhalford ### ########.fr */ +/* Updated: 2016/11/16 17:56:37 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,7 +14,6 @@ char *ft_transform(t_fmt *fmt, va_list ap) { - char *buf; char *ret; int i; @@ -24,11 +23,7 @@ char *ft_transform(t_fmt *fmt, va_list ap) fmt->conv = g_convs[i]; ret = (*fmt->conv.converter)(fmt, ap); if (fmt->width > (int)ft_strlen(ret)) - { - buf = ret; - ret = (char *)malloc(sizeof(char) * (fmt->width + 5)); - ft_strcpy(ret, buf); - } + ret = ft_realloc(ret, fmt->width + 5); if (ft_strchr(fmt->flags, '-')) ft_pad_right(ret, fmt); else diff --git a/libftasm/src/ft_printf/lib_fmt.c b/libftasm/src/ft_printf/lib_fmt.c index 5cb86398..5865af59 100644 --- a/libftasm/src/ft_printf/lib_fmt.c +++ b/libftasm/src/ft_printf/lib_fmt.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 13:33:35 by jhalford #+# #+# */ -/* Updated: 2016/11/07 17:22:26 by jhalford ### ########.fr */ +/* Updated: 2016/11/16 17:46:16 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libftasm/src/ft_printf/lib_pad.c b/libftasm/src/ft_printf/lib_pad.c index f2efe4b8..20919955 100644 --- a/libftasm/src/ft_printf/lib_pad.c +++ b/libftasm/src/ft_printf/lib_pad.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 13:33:45 by jhalford #+# #+# */ -/* Updated: 2016/11/08 10:18:08 by jhalford ### ########.fr */ +/* Updated: 2016/11/16 18:13:08 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -24,7 +24,7 @@ void ft_pad_left(char *str, t_fmt *fmt) { char sign; - sign = '\0'; + sign = 0; if (str[0] == '-' || str[0] == '+' || str[0] == ' ') { sign = str[0]; diff --git a/libftasm/src/ft_printf/lib_pad_sharp.c b/libftasm/src/ft_printf/lib_pad_sharp.c index e6d57063..bca9add2 100644 --- a/libftasm/src/ft_printf/lib_pad_sharp.c +++ b/libftasm/src/ft_printf/lib_pad_sharp.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 13:33:48 by jhalford #+# #+# */ -/* Updated: 2016/11/08 10:18:20 by jhalford ### ########.fr */ +/* Updated: 2016/11/16 17:56:42 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libftasm/src/lst/ft_lst_delif.c b/libftasm/src/lst/ft_lst_delif.c index b1d11a0a..62a76754 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/14 16:55:27 by jhalford ### ########.fr */ +/* Updated: 2016/11/16 18:23:24 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -28,6 +28,7 @@ void ft_lst_delif( { tmp = (*indirect); (*indirect) = (*indirect)->next; + ft_printf("free'd at %p\n", tmp); (*del)(tmp->content, tmp->content_size); } else diff --git a/libftasm/src/lst/ft_lst_removeif.c b/libftasm/src/lst/ft_lst_removeif.c index 747c15dc..2cf2d53d 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/08 11:52:33 by jhalford ### ########.fr */ +/* Updated: 2016/11/16 14:00:07 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libftasm/src/lst/ft_lstdel.c b/libftasm/src/lst/ft_lstdel.c index 4d4e1312..5a97607e 100644 --- a/libftasm/src/lst/ft_lstdel.c +++ b/libftasm/src/lst/ft_lstdel.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/03 15:18:57 by jhalford #+# #+# */ -/* Updated: 2016/11/08 13:36:19 by jhalford ### ########.fr */ +/* Updated: 2016/11/16 18:24:38 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,7 +14,11 @@ void ft_lstdel(t_list **alst, void (*del)(void *, size_t)) { - if (alst && *alst && (*alst)->next) + if (alst && *alst && del) + { + ft_printf("free'd at %p\n", *alst); ft_lstdel(&(*alst)->next, del); - ft_lstdelone(alst, del); + ft_lstdelone(alst, del); + *alst = NULL; + } } diff --git a/libftasm/src/lst/ft_lstdelone.c b/libftasm/src/lst/ft_lstdelone.c index a360b486..fe144be3 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/14 15:50:00 by jhalford ### ########.fr */ +/* Updated: 2016/11/16 18:22:47 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,6 +19,6 @@ void ft_lstdelone(t_list **alst, void (*del)(void *, size_t)) if (del) (*del)((*alst)->content, (*alst)->content_size); free(*alst); + *alst = NULL; } - *alst = NULL; } diff --git a/libftasm/src/mem/ft_memdel.c b/libftasm/src/mem/ft_memdel.c index 7745391e..52e6508b 100644 --- a/libftasm/src/mem/ft_memdel.c +++ b/libftasm/src/mem/ft_memdel.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/03 14:57:33 by jhalford #+# #+# */ -/* Updated: 2016/11/03 14:57:33 by jhalford ### ########.fr */ +/* Updated: 2016/11/16 12:23:13 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,6 +14,9 @@ void ft_memdel(void **ap) { - free(*ap); - *ap = NULL; + if (ap && *ap) + { + free(*ap); + *ap = NULL; + } } diff --git a/libftasm/src/mem/ft_realloc.c b/libftasm/src/mem/ft_realloc.c index f64a50d0..1f57254d 100644 --- a/libftasm/src/mem/ft_realloc.c +++ b/libftasm/src/mem/ft_realloc.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/11 17:37:53 by jhalford #+# #+# */ -/* Updated: 2016/11/11 17:41:30 by jhalford ### ########.fr */ +/* Updated: 2016/11/16 17:56:17 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,10 +16,8 @@ void *ft_realloc(void *data, int size) { void *new; - ft_printf("realloc befor: '%s'\n", data); new = ft_memalloc(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_notdir.c b/libftasm/src/path/ft_path_notdir.c index 14342adf..d85fe56b 100644 --- a/libftasm/src/path/ft_path_notdir.c +++ b/libftasm/src/path/ft_path_notdir.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/04 11:45:07 by jhalford #+# #+# */ -/* Updated: 2016/11/04 11:45:08 by jhalford ### ########.fr */ +/* Updated: 2016/11/16 12:07:21 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libftasm/src/str/ft_strcatf.c b/libftasm/src/str/ft_strcatf.c index 12bf4de0..c4520d64 100644 --- a/libftasm/src/str/ft_strcatf.c +++ b/libftasm/src/str/ft_strcatf.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 15:46:03 by jhalford #+# #+# */ -/* Updated: 2016/11/07 15:46:11 by jhalford ### ########.fr */ +/* Updated: 2016/11/16 17:58:02 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libftasm/src/str/ft_strsub.c b/libftasm/src/str/ft_strsub.c index bf883507..67e74782 100644 --- a/libftasm/src/str/ft_strsub.c +++ b/libftasm/src/str/ft_strsub.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/03 14:58:43 by jhalford #+# #+# */ -/* Updated: 2016/11/03 14:58:43 by jhalford ### ########.fr */ +/* Updated: 2016/11/16 17:52:01 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,8 +17,7 @@ char *ft_strsub(char const *s, unsigned int start, size_t len) char *out; size_t i; - out = (char *)malloc(sizeof(char) * (len + 1)); - if (!out) + if (!(out = (char *)malloc(sizeof(char) * (len + 1)))) return (NULL); i = -1; while (++i < len)