diff --git a/libft/includes/btree.h b/libft/includes/btree.h index 153bbf84..f8a24f4d 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/25 20:37:02 by jhalford ### ########.fr */ +/* Updated: 2016/11/28 14:44:55 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -51,6 +51,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, char *(*printer)(void *)); +void btree_print(int fd, t_btree *tree, char *(*printer)(void *)); #endif diff --git a/libft/includes/libft.h b/libft/includes/libft.h index 5af9a166..d93751e6 100644 --- a/libft/includes/libft.h +++ b/libft/includes/libft.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 13:49:04 by jhalford #+# #+# */ -/* Updated: 2016/11/25 16:02:22 by jhalford ### ########.fr */ +/* Updated: 2016/11/28 15:20:11 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -36,6 +36,12 @@ # define FT_MAX(a, b) ((a) > (b) ? (a) : (b)) # define FT_DIST(a, b) (FT_ABS((a) - (b))) +# define STDIN 0 +# define STDOUT 1 +# define STDERR 2 + +typedef long long t_type; + typedef struct s_stof t_stof; struct s_stof @@ -125,6 +131,7 @@ int ft_addrcmp(void *a, void *b); char **ft_sstradd(char **list, char *new); void ft_sstrsort(char **list, int (*cmp)()); void ft_sstrprint(char **list, char sep); +void ft_sstrprint_fd(int fd, char **list, char sep); char **ft_sstrdup(char **list); void ft_sstrdel(char **sstr, int index); void ft_sstrfree(char **sstr); diff --git a/libft/src/btree/btree_print.c b/libft/src/btree/btree_print.c index 2db652b8..52992dcb 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/25 20:44:56 by jhalford ### ########.fr */ +/* Updated: 2016/11/28 14:53:46 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -59,7 +59,7 @@ static int print_t(t_btree *tree, return (print_t2(data, s, b)); } -void btree_print(t_btree *tree, char *(*printer)(void *)) +void btree_print(int fd, t_btree *tree, char *(*printer)(void *)) { char s[20][255]; char empty[255]; @@ -75,6 +75,6 @@ void btree_print(t_btree *tree, char *(*printer)(void *)) { if (ft_strcmp(s[i], empty) == 0) break ; - printf("%s\n", s[i]); + ft_dprintf(fd, "%s\n", s[i]); } } diff --git a/libft/src/lst/ft_lstdelone.c b/libft/src/lst/ft_lstdelone.c index 8c200615..3313efff 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/21 14:02:31 by jhalford ### ########.fr */ +/* Updated: 2016/11/28 19:13:36 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/libft/src/lst/ft_lstnew.c b/libft/src/lst/ft_lstnew.c index 302aff27..bee43729 100644 --- a/libft/src/lst/ft_lstnew.c +++ b/libft/src/lst/ft_lstnew.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/03 14:57:24 by jhalford #+# #+# */ -/* Updated: 2016/11/03 14:57:24 by jhalford ### ########.fr */ +/* Updated: 2016/11/28 19:25:25 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,16 +19,9 @@ t_list *ft_lstnew(void const *content, size_t content_size) if (!(new = (t_list *)malloc(sizeof(*new)))) return (NULL); new->next = NULL; - if (!content) - { - new->content_size = 0; - new->content = NULL; - } - else - { - new->content_size = content_size; - new->content = ft_memalloc(content_size + 1); + new->content_size = content_size; + new->content = ft_memalloc(content_size + 1); + if (content) ft_memcpy(new->content, content, content_size); - } return (new); } diff --git a/libft/src/lst/ft_lstpop.c b/libft/src/lst/ft_lstpop.c index 2b0ac748..bc2d42f5 100644 --- a/libft/src/lst/ft_lstpop.c +++ b/libft/src/lst/ft_lstpop.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/04 11:09:56 by jhalford #+# #+# */ -/* Updated: 2016/11/04 11:09:56 by jhalford ### ########.fr */ +/* Updated: 2016/11/28 19:14:40 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,7 +17,7 @@ t_list *ft_lstpop(t_list **lst) t_list *top; top = *lst; - if (*lst) + if (lst && *lst) *lst = (*lst)->next; return (top); } diff --git a/libft/src/sstr/ft_sstrprint.c b/libft/src/sstr/ft_sstrprint.c index a6b5f248..1ebc0f5e 100644 --- a/libft/src/sstr/ft_sstrprint.c +++ b/libft/src/sstr/ft_sstrprint.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* ft_sstrprint.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2016/11/03 18:04:15 by jhalford #+# #+# */ -/* Updated: 2016/11/03 18:04:15 by jhalford ### ########.fr */ +/* Created: 2016/11/28 15:17:33 by jhalford #+# #+# */ +/* Updated: 2016/11/28 15:18:12 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,13 +14,5 @@ void ft_sstrprint(char **list, char sep) { - int i; - - i = 0; - while (list[i]) - { - ft_putstr(list[i++]); - if (list[i]) - ft_putchar(sep); - } + ft_sstrprint_fd(STDOUT, list, sep); } diff --git a/libft/src/sstr/ft_sstrprint_fd.c b/libft/src/sstr/ft_sstrprint_fd.c new file mode 100644 index 00000000..dd427ca3 --- /dev/null +++ b/libft/src/sstr/ft_sstrprint_fd.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_sstrprint_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/28 15:17:29 by jhalford #+# #+# */ +/* Updated: 2016/11/28 15:23:52 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_sstrprint_fd(int fd, char **list, char sep) +{ + int i; + + i = 0; + while (list[i]) + { + ft_putstr_fd(list[i++], fd); + if (list[i]) + ft_putchar_fd(sep, fd); + } +} diff --git a/libft/src/str/ft_strlen.c b/libft/src/str/ft_strlen.c index 536f2bcf..04ee783c 100644 --- a/libft/src/str/ft_strlen.c +++ b/libft/src/str/ft_strlen.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/03 14:58:22 by jhalford #+# #+# */ -/* Updated: 2016/11/10 10:14:18 by jhalford ### ########.fr */ +/* Updated: 2016/11/28 15:35:58 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */