diff --git a/libft/includes/btree.h b/libft/includes/btree.h index f8a24f4d..5839155c 100644 --- a/libft/includes/btree.h +++ b/libft/includes/btree.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/16 11:13:15 by jhalford #+# #+# */ -/* Updated: 2016/11/28 14:44:55 by jhalford ### ########.fr */ +/* Updated: 2016/12/05 11:53:30 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,8 +15,6 @@ # include "libft.h" -typedef struct s_btree t_btree; - struct s_btree { void *item; @@ -34,23 +32,23 @@ struct s_printdata int right; }; +typedef struct s_btree t_btree; typedef struct s_printdata t_printdata; 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, 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 *)); -void btree_print(int fd, t_btree *tree, char *(*printer)(void *)); +void btree_print(int fd, t_btree *tree, char *(*printer)(void *)); +void btree_del(t_btree **root, void (*del)(void *, size_t)); +void btree_delone(t_btree **root, void (*del)(void *, size_t)); #endif diff --git a/libft/includes/color.h b/libft/includes/color.h index 2c7b09e7..0555f3b5 100644 --- a/libft/includes/color.h +++ b/libft/includes/color.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/25 13:36:48 by jhalford #+# #+# */ -/* Updated: 2016/11/25 18:27:28 by jhalford ### ########.fr */ +/* Updated: 2016/12/06 20:15:42 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,6 +14,14 @@ # define COLOR_H # include "libft.h" +struct s_color +{ + char fg[7]; + char bg[7]; +}; + +typedef struct s_color t_color; + # define FG_BLACK "\x1b[30m" # define FG_RED "\x1b[31m" # define FG_GREEN "\x1b[32m" @@ -32,7 +40,12 @@ # define BG_CYAN "\x1b[46m" # define BG_DEFAULT "\x1b[49m" +# define FBG_DEFAULT "\x1b[49m\x1b[20m" + void ft_color_reset(void); -void ft_color_set(char *fg, char *bg); +void ft_color_set(t_color color); + +void ft_color_mk(t_color *color, char fg[7], char bg[7]); +void ft_color_mkif(t_color *color, int cond, char fg[7], char bg[7]); #endif diff --git a/libft/includes/ft_printf.h b/libft/includes/ft_printf.h index 0cef383e..1434cb83 100644 --- a/libft/includes/ft_printf.h +++ b/libft/includes/ft_printf.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 13:22:54 by jhalford #+# #+# */ -/* Updated: 2016/11/21 18:20:10 by jhalford ### ########.fr */ +/* Updated: 2016/12/06 19:12:15 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -49,6 +49,7 @@ extern t_conv g_convs[]; t_fmt *ft_fmt_init(void); void ft_fmt_print(t_fmt *fmt); +void ft_printf_color(int fd, char **final, char **str); t_fmt *ft_printf_parse(char **format, va_list ap); void ft_printf_parse_flags(t_fmt *fmt, char **format); diff --git a/libft/includes/get_next_line.h b/libft/includes/get_next_line.h index b2e6ba42..8036a06e 100644 --- a/libft/includes/get_next_line.h +++ b/libft/includes/get_next_line.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/05 12:21:36 by jhalford #+# #+# */ -/* Updated: 2016/11/17 13:18:28 by jhalford ### ########.fr */ +/* Updated: 2016/12/06 15:33:20 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libft/includes/libft.h b/libft/includes/libft.h index d93751e6..70e22716 100644 --- a/libft/includes/libft.h +++ b/libft/includes/libft.h @@ -6,13 +6,18 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 13:49:04 by jhalford #+# #+# */ -/* Updated: 2016/11/28 15:20:11 by jhalford ### ########.fr */ +/* Updated: 2016/12/07 16:54:11 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef LIBFT_H # define LIBFT_H +# define DG_MSG0 "{yel}%13s:{blu}%-3d{eoc} |" +# define DG_MSG1 ft_path_notdir(__FILE__), __LINE__ +# define DG(f, ...) ft_dprintf(2, DG_MSG0 f "{eoc}\n", DG_MSG1, ##__VA_ARGS__) + +# include "get_next_line.h" # include "ft_xattr.h" # include "mytime.h" # include "lst.h" @@ -40,9 +45,14 @@ # define STDOUT 1 # define STDERR 2 -typedef long long t_type; - typedef struct s_stof t_stof; +typedef struct s_stos t_stos; + +struct s_stos +{ + char *key; + char *val; +}; struct s_stof { diff --git a/libft/includes/lst.h b/libft/includes/lst.h index bff4ef8e..2d7fcdce 100644 --- a/libft/includes/lst.h +++ b/libft/includes/lst.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 13:27:46 by jhalford #+# #+# */ -/* Updated: 2016/11/23 14:50:54 by jhalford ### ########.fr */ +/* Updated: 2016/12/07 16:54:25 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -54,6 +54,7 @@ void ft_lst_delsub( t_list *sub, int (*cmp)(), void (*del)(void *, size_t)); void ft_lst_cfree(void *ptr, size_t size); +void ft_lst_bfree(void *ptr, size_t size); t_list *ft_lst_filter( t_list *lst, void const *data_ref, diff --git a/libft/src/btree/btree_apply_suffix.c b/libft/src/btree/btree_apply_suffix.c index 08f01881..ae103242 100644 --- a/libft/src/btree/btree_apply_suffix.c +++ b/libft/src/btree/btree_apply_suffix.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* btree_create_node.c :+: :+: :+: */ +/* btree_apply_suffix.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2016/08/16 13:43:51 by jhalford #+# #+# */ -/* Updated: 2016/11/14 16:08:23 by jhalford ### ########.fr */ +/* Created: 2016/12/05 11:43:08 by jhalford #+# #+# */ +/* Updated: 2016/12/05 11:43:13 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libft/src/btree/btree_del.c b/libft/src/btree/btree_del.c new file mode 100644 index 00000000..f9abecb6 --- /dev/null +++ b/libft/src/btree/btree_del.c @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* btree_del.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/12/05 11:43:03 by jhalford #+# #+# */ +/* Updated: 2016/12/05 11:53:24 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "btree.h" + +void btree_del(t_btree **root, void (*del)(void *, size_t)) +{ + if (root && *root && del) + { + btree_del(&(*root)->left, del); + btree_del(&(*root)->right, del); + btree_delone(root, del); + } +} diff --git a/libft/src/btree/btree_delone.c b/libft/src/btree/btree_delone.c new file mode 100644 index 00000000..6994e405 --- /dev/null +++ b/libft/src/btree/btree_delone.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* btree_delone.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/12/05 11:45:51 by jhalford #+# #+# */ +/* Updated: 2016/12/05 14:07:12 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "btree.h" + +void btree_delone(t_btree **root, void (*del)(void *, size_t)) +{ + if (root && *root) + { + if (del) + (*del)((*root)->item, (*root)->content_size); + free(*root); + *root = NULL; + } +} diff --git a/libft/src/btree/btree_print.c b/libft/src/btree/btree_print.c index 52992dcb..b7422a99 100644 --- a/libft/src/btree/btree_print.c +++ b/libft/src/btree/btree_print.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/14 18:06:24 by jhalford #+# #+# */ -/* Updated: 2016/11/28 14:53:46 by jhalford ### ########.fr */ +/* Updated: 2016/12/06 20:10:51 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -75,6 +75,8 @@ void btree_print(int fd, t_btree *tree, char *(*printer)(void *)) { if (ft_strcmp(s[i], empty) == 0) break ; + if (i == 0 && ft_strcmp(s[1], empty) == 0) + break ; ft_dprintf(fd, "%s\n", s[i]); } } diff --git a/libft/src/color/ft_color_mk.c b/libft/src/color/ft_color_mk.c new file mode 100644 index 00000000..910748ed --- /dev/null +++ b/libft/src/color/ft_color_mk.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_color_mk.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/27 11:35:18 by jhalford #+# #+# */ +/* Updated: 2016/12/03 12:16:59 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_color_mk(t_color *color, char fg[7], char bg[7]) +{ + ft_strcpy(color->fg, fg); + ft_strcpy(color->bg, bg); +} diff --git a/libft/src/color/ft_color_mkif.c b/libft/src/color/ft_color_mkif.c new file mode 100644 index 00000000..707a5c8c --- /dev/null +++ b/libft/src/color/ft_color_mkif.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_color_mk.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/27 11:35:18 by jhalford #+# #+# */ +/* Updated: 2016/12/03 12:17:14 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_color_mkif(t_color *color, int cond, char fg[7], char bg[7]) +{ + if (cond) + ft_color_mk(color, fg, bg); +} diff --git a/libft/src/color/ft_color_set.c b/libft/src/color/ft_color_set.c index 55313cfc..103bd39f 100644 --- a/libft/src/color/ft_color_set.c +++ b/libft/src/color/ft_color_set.c @@ -6,14 +6,17 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/25 13:53:46 by jhalford #+# #+# */ -/* Updated: 2016/11/25 14:05:39 by jhalford ### ########.fr */ +/* Updated: 2016/12/03 12:16:38 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" -void ft_color_set(char *fg, char *bg) +void ft_color_set(t_color color) { - ft_putstr(fg); - ft_putstr(bg); + char out[20]; + + ft_strcpy(out, color.fg); + ft_strcat(out, color.bg); + ft_putstr(out); } diff --git a/libft/src/dlst/ft_dlstdel.c b/libft/src/dlst/ft_dlstdel.c index 43d0eb63..94b43f6b 100644 --- a/libft/src/dlst/ft_dlstdel.c +++ b/libft/src/dlst/ft_dlstdel.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/14 17:55:40 by jhalford #+# #+# */ -/* Updated: 2016/11/16 11:15:40 by jhalford ### ########.fr */ +/* Updated: 2016/12/07 17:29:54 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libft/src/dlst/ft_dlstnew.c b/libft/src/dlst/ft_dlstnew.c index dfe32bdc..f97ab6fb 100644 --- a/libft/src/dlst/ft_dlstnew.c +++ b/libft/src/dlst/ft_dlstnew.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 13:27:20 by jhalford #+# #+# */ -/* Updated: 2016/11/07 13:27:20 by jhalford ### ########.fr */ +/* Updated: 2016/12/07 17:35:12 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libft/src/ft_printf/ft_printf.c b/libft/src/ft_printf/ft_printf.c index 79a78e4f..4247f327 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/21 18:22:26 by jhalford ### ########.fr */ +/* Updated: 2016/12/07 17:14:27 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -52,7 +52,9 @@ int ft_vdprintf(int fd, const char *format, va_list ap) while (*str) { tmp = final; - if (*str == '%') + if (*str == '{') + ft_printf_color(fd, &final, &str); + else if (*str == '%') { if (ft_fmtcalc(&final, &str, ap)) return (1); diff --git a/libft/src/ft_printf/ft_printf_color.c b/libft/src/ft_printf/ft_printf_color.c new file mode 100644 index 00000000..b4cace7a --- /dev/null +++ b/libft/src/ft_printf/ft_printf_color.c @@ -0,0 +1,45 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_printf_color.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/12/06 18:07:39 by jhalford #+# #+# */ +/* Updated: 2016/12/07 13:48:34 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_printf.h" + +t_stos g_colors[] = +{ + {"{bla}", FG_BLACK}, + {"{red}", FG_RED}, + {"{gre}", FG_GREEN}, + {"{yel}", FG_YELLOW}, + {"{blu}", FG_BLUE}, + {"{mag}", FG_MAGENTA}, + {"{cya}", FG_CYAN}, + {"{eoc}", FG_DEFAULT}, + {NULL, NULL}, +}; + +void ft_printf_color(int fd, char **final, char **str) +{ + int i; + + i = 0; + while(g_colors[i].key) + { + if (ft_strncmp(*str, g_colors[i].key, 5) == 0) + { + (void)fd; + /* if (isatty(fd)) */ + *final = ft_strjoin(*final, g_colors[i].val); + *str += 5; + return ; + } + i++; + } +} diff --git a/libft/src/lst/ft_lst_bfree.c b/libft/src/lst/ft_lst_bfree.c new file mode 100644 index 00000000..67a308ae --- /dev/null +++ b/libft/src/lst/ft_lst_bfree.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lst_bfree.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/12/07 16:55:04 by jhalford #+# #+# */ +/* Updated: 2016/12/07 18:07:31 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_lst_bfree(void *ptr, size_t size) +{ + t_list *lst; + + lst = ptr; + (void)size; + if (lst) + { + ft_strdel((char **)&lst->content); + free(lst); + } +} diff --git a/libft/src/lst/ft_lst_cfree.c b/libft/src/lst/ft_lst_cfree.c index 3297a219..e9b8b1dc 100644 --- a/libft/src/lst/ft_lst_cfree.c +++ b/libft/src/lst/ft_lst_cfree.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/04 11:09:10 by jhalford #+# #+# */ -/* Updated: 2016/11/08 11:09:49 by jhalford ### ########.fr */ +/* Updated: 2016/12/07 16:55:43 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libft/src/lst/ft_lst_delif.c b/libft/src/lst/ft_lst_delif.c index 091b813d..e67bd72a 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/21 14:22:51 by jhalford ### ########.fr */ +/* Updated: 2016/12/05 13:39:09 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libft/src/lst/ft_lstdel.c b/libft/src/lst/ft_lstdel.c index 584c25c6..ecebf830 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/21 14:02:16 by jhalford ### ########.fr */ +/* Updated: 2016/12/05 13:39:14 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,6 +18,5 @@ void ft_lstdel(t_list **alst, void (*del)(void *, size_t)) { ft_lstdel(&(*alst)->next, del); ft_lstdelone(alst, del); - *alst = NULL; } } diff --git a/libft/src/lst/ft_lstdelone.c b/libft/src/lst/ft_lstdelone.c index 3313efff..405991a3 100644 --- a/libft/src/lst/ft_lstdelone.c +++ b/libft/src/lst/ft_lstdelone.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* ft_lstdelone.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2016/11/03 14:57:15 by jhalford #+# #+# */ -/* Updated: 2016/11/28 19:13:36 by jhalford ### ########.fr */ +/* Created: 2016/12/05 13:39:33 by jhalford #+# #+# */ +/* Updated: 2016/12/05 13:43:03 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libft/src/mem/ft_memalloc.c b/libft/src/mem/ft_memalloc.c index 505043f8..432ed9ac 100644 --- a/libft/src/mem/ft_memalloc.c +++ b/libft/src/mem/ft_memalloc.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/03 14:57:25 by jhalford #+# #+# */ -/* Updated: 2016/11/11 17:40:57 by jhalford ### ########.fr */ +/* Updated: 2016/12/07 16:23:30 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libft/src/mem/ft_memcpy.c b/libft/src/mem/ft_memcpy.c index 0b95291e..cc5b3efc 100644 --- a/libft/src/mem/ft_memcpy.c +++ b/libft/src/mem/ft_memcpy.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/03 14:57:31 by jhalford #+# #+# */ -/* Updated: 2016/11/11 17:39:00 by jhalford ### ########.fr */ +/* Updated: 2016/12/07 15:34:47 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libft/src/misc/ft_debug.c b/libft/src/misc/ft_debug.c index c3a5341f..a7a25779 100644 --- a/libft/src/misc/ft_debug.c +++ b/libft/src/misc/ft_debug.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/04 11:45:16 by jhalford #+# #+# */ -/* Updated: 2016/11/07 15:43:41 by jhalford ### ########.fr */ +/* Updated: 2016/12/07 15:22:06 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libft/src/path/ft_path_notdir.c b/libft/src/path/ft_path_notdir.c index b00d21fe..e02c836e 100644 --- a/libft/src/path/ft_path_notdir.c +++ b/libft/src/path/ft_path_notdir.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/04 11:45:07 by jhalford #+# #+# */ -/* Updated: 2016/11/23 15:46:28 by jhalford ### ########.fr */ +/* Updated: 2016/12/07 15:22:09 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libft/src/sstr/ft_sstradd.c b/libft/src/sstr/ft_sstradd.c index f0ba213b..e01e4f61 100644 --- a/libft/src/sstr/ft_sstradd.c +++ b/libft/src/sstr/ft_sstradd.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/03 18:03:58 by jhalford #+# #+# */ -/* Updated: 2016/11/14 16:31:02 by jhalford ### ########.fr */ +/* Updated: 2016/12/07 17:39:37 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -23,16 +23,12 @@ char **ft_sstradd(char **sstr, char *new) if (sstr) while (sstr[size]) size++; - if (!(newlist = (char **)malloc(sizeof(char *) * (size + 2)))) + if (!(newlist = (char **)ft_memalloc(sizeof(char *) * (size + 2)))) return (NULL); if (sstr) - while (sstr[i]) - { - newlist[i] = sstr[i]; - i++; - } - newlist[i++] = ft_strdup(new); - newlist[i] = NULL; + ft_memcpy(newlist, sstr, sizeof(char*) * size); + newlist[size++] = ft_strdup(new); + newlist[size] = NULL; free(sstr); return (newlist); } diff --git a/libft/src/sstr/ft_sstrdup.c b/libft/src/sstr/ft_sstrdup.c index 1ac68da3..4704b22d 100644 --- a/libft/src/sstr/ft_sstrdup.c +++ b/libft/src/sstr/ft_sstrdup.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* ft_sstrdup.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2016/11/03 18:04:13 by jhalford #+# #+# */ -/* Updated: 2016/12/01 12:29:27 by jhalford ### ########.fr */ +/* Created: 2016/12/07 14:25:45 by jhalford #+# #+# */ +/* Updated: 2016/12/07 16:29:08 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,6 +20,7 @@ char **ft_sstrdup(char **list) i = 0; size = 0; + DG("sstrdup call now"); while (list[size]) size++; cpy = (char **)malloc(sizeof(char *) * (size + 1)); @@ -28,6 +29,7 @@ char **ft_sstrdup(char **list) cpy[i++] = ft_strdup(*list); list++; } + DG("sstrdup i=%i, size=%i (should be equal)", i, size); cpy[i] = NULL; return (cpy); } diff --git a/libft/src/sstr/ft_sstrfree.c b/libft/src/sstr/ft_sstrfree.c index 14a833eb..ef3708fd 100644 --- a/libft/src/sstr/ft_sstrfree.c +++ b/libft/src/sstr/ft_sstrfree.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* ft_sstrfree.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2016/11/08 17:01:24 by jhalford #+# #+# */ -/* Updated: 2016/11/14 11:08:19 by jhalford ### ########.fr */ +/* Created: 2016/12/05 11:53:36 by jhalford #+# #+# */ +/* Updated: 2016/12/05 16:38:33 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libft/src/str/ft_strcpy.c b/libft/src/str/ft_strcpy.c index 95818fff..64176338 100644 --- a/libft/src/str/ft_strcpy.c +++ b/libft/src/str/ft_strcpy.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/08/07 10:48:12 by jhalford #+# #+# */ -/* Updated: 2016/08/20 23:37:18 by jhalford ### ########.fr */ +/* Updated: 2016/12/07 15:23:05 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,7 +17,7 @@ char *ft_strcpy(char *dst, const char *src) int i; i = 0; - while (src[i] != '\0') + while (src[i]) { dst[i] = src[i]; i++; diff --git a/libft/src/str/ft_strdel.c b/libft/src/str/ft_strdel.c index 19df79fe..d7753703 100644 --- a/libft/src/str/ft_strdel.c +++ b/libft/src/str/ft_strdel.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/03 14:58:00 by jhalford #+# #+# */ -/* Updated: 2016/11/21 18:03:21 by jhalford ### ########.fr */ +/* Updated: 2016/12/07 17:14:22 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,7 +14,7 @@ void ft_strdel(char **as) { - if (as) + if (as && *as) { free(*as); *as = NULL; diff --git a/libft/src/str/ft_strdup.c b/libft/src/str/ft_strdup.c index dba3557f..c891ac20 100644 --- a/libft/src/str/ft_strdup.c +++ b/libft/src/str/ft_strdup.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* ft_strdup.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2016/11/03 14:58:01 by jhalford #+# #+# */ -/* Updated: 2016/12/01 12:27:28 by jhalford ### ########.fr */ +/* Created: 2016/12/07 14:25:41 by jhalford #+# #+# */ +/* Updated: 2016/12/07 15:29:38 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,17 +15,10 @@ char *ft_strdup(const char *s1) { char *dup; - int size; int i; i = 0; - size = ft_strlen(s1); - dup = (char*)malloc(sizeof(*dup) * (size + 1)); - while (s1[i]) - { - dup[i] = s1[i]; - i++; - } - dup[i] = '\0'; + dup = (char*)malloc(sizeof(*dup) * (ft_strlen(s1) + 1)); + ft_strcpy(dup, s1); return (dup); } diff --git a/libft/src/str/ft_strjoin.c b/libft/src/str/ft_strjoin.c index ece5a205..1bd59d22 100644 --- a/libft/src/str/ft_strjoin.c +++ b/libft/src/str/ft_strjoin.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/03 14:58:18 by jhalford #+# #+# */ -/* Updated: 2016/11/21 18:10:22 by jhalford ### ########.fr */ +/* Updated: 2016/12/05 14:24:31 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,7 +17,9 @@ char *ft_strjoin(char const *s1, char const *s2) char *join; join = ft_strnew(ft_strlen(s1) + ft_strlen(s2) + 1); - ft_strcpy(join, s1); - ft_strcat(join, s2); + if (s1) + ft_strcpy(join, s1); + if (s2) + ft_strcat(join, s2); return (join); } diff --git a/libft/src/str/ft_strsplit.c b/libft/src/str/ft_strsplit.c index 9264c2ee..a44c4ca1 100644 --- a/libft/src/str/ft_strsplit.c +++ b/libft/src/str/ft_strsplit.c @@ -6,13 +6,13 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/03 14:58:40 by jhalford #+# #+# */ -/* Updated: 2016/11/07 13:07:01 by jhalford ### ########.fr */ +/* Updated: 2016/12/05 17:20:45 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" -static int countwords(char const *s, char c) +static int ft_countwords(char const *s, char c) { if (c == '\0') return ((*s == '\0') ? 0 : 1); @@ -22,34 +22,49 @@ static int countwords(char const *s, char c) return (0); while (*s != c && *s != '\0') s++; - return (1 + countwords(s, c)); + return (1 + ft_countwords(s, c)); } -char **ft_strsplit(char const *s, char c) +static int get_word_len(char const *str, char c) +{ + int i; + int len; + + i = 0; + len = 0; + while (str[i] == c) + i++; + while (str[i] != c && str[i] != '\0') + { + i++; + len++; + } + return (len); +} + +char **ft_strsplit(char const *s, char c) { - char **arr; int i; int j; - int w; + int k; + char **str2; - if (!s) - return (0); - w = countwords(s, c); - if ((arr = (char **)malloc((w + 1) * sizeof(char *)))) + if (!s || !(str2 = (char **)malloc(sizeof(*str2) * + (ft_countwords(s, c) + 1)))) + return (NULL); + i = -1; + j = 0; + while (++i < ft_countwords(s, c)) { - i = 0; - while (i < w) - { - while (*s == c) - ++s; - j = 0; - while (*(s + j) != c) - ++j; - if ((arr[i] = ft_strnew(j))) - ft_strncpy(arr[i++], s, j); - s += j; + k = 0; + if (!(str2[i] = ft_strnew(get_word_len(&s[j], c) + 1))) + str2[i] = NULL; + while (s[j] == c) + j++; + while (s[j] != c && s[j]) + str2[i][k++] = s[j++]; + str2[i][k] = '\0'; } - arr[i] = 0; - } - return (arr); + str2[i] = 0; + return (str2); } diff --git a/libft/src/time/ft_mytime_get.c b/libft/src/time/ft_mytime_get.c index 29d26941..f222530e 100644 --- a/libft/src/time/ft_mytime_get.c +++ b/libft/src/time/ft_mytime_get.c @@ -6,13 +6,12 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/25 11:34:56 by jhalford #+# #+# */ -/* Updated: 2016/11/25 11:55:18 by jhalford ### ########.fr */ +/* Updated: 2016/12/03 11:54:16 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" - t_mytime *ft_mytime_get(time_t epoch) { char *date; @@ -30,4 +29,3 @@ t_mytime *ft_mytime_get(time_t epoch) time->sec = ft_strsub(date, 17, 2); return (time); } -