some stuff

This commit is contained in:
Jack Halford 2016-11-28 19:30:59 +01:00
parent 4902ceeac0
commit 1e93f8327a
9 changed files with 51 additions and 33 deletions

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/16 11:13:15 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_prefix(t_btree *root, void (*applyf)(void *));
void btree_apply_infix(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_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 #endif

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/07 13:49:04 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_MAX(a, b) ((a) > (b) ? (a) : (b))
# define FT_DIST(a, b) (FT_ABS((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; typedef struct s_stof t_stof;
struct s_stof struct s_stof
@ -125,6 +131,7 @@ int ft_addrcmp(void *a, void *b);
char **ft_sstradd(char **list, char *new); char **ft_sstradd(char **list, char *new);
void ft_sstrsort(char **list, int (*cmp)()); void ft_sstrsort(char **list, int (*cmp)());
void ft_sstrprint(char **list, char sep); void ft_sstrprint(char **list, char sep);
void ft_sstrprint_fd(int fd, char **list, char sep);
char **ft_sstrdup(char **list); char **ft_sstrdup(char **list);
void ft_sstrdel(char **sstr, int index); void ft_sstrdel(char **sstr, int index);
void ft_sstrfree(char **sstr); void ft_sstrfree(char **sstr);

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/14 18:06:24 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)); 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 s[20][255];
char empty[255]; char empty[255];
@ -75,6 +75,6 @@ void btree_print(t_btree *tree, char *(*printer)(void *))
{ {
if (ft_strcmp(s[i], empty) == 0) if (ft_strcmp(s[i], empty) == 0)
break ; break ;
printf("%s\n", s[i]); ft_dprintf(fd, "%s\n", s[i]);
} }
} }

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/03 14:57:15 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/03 14:57:24 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)))) if (!(new = (t_list *)malloc(sizeof(*new))))
return (NULL); return (NULL);
new->next = NULL; new->next = NULL;
if (!content)
{
new->content_size = 0;
new->content = NULL;
}
else
{
new->content_size = content_size; new->content_size = content_size;
new->content = ft_memalloc(content_size + 1); new->content = ft_memalloc(content_size + 1);
if (content)
ft_memcpy(new->content, content, content_size); ft_memcpy(new->content, content, content_size);
}
return (new); return (new);
} }

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/04 11:09:56 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; t_list *top;
top = *lst; top = *lst;
if (*lst) if (lst && *lst)
*lst = (*lst)->next; *lst = (*lst)->next;
return (top); return (top);
} }

View file

@ -3,10 +3,10 @@
/* ::: :::::::: */ /* ::: :::::::: */
/* ft_sstrprint.c :+: :+: :+: */ /* ft_sstrprint.c :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/03 18:04:15 by jhalford #+# #+# */ /* Created: 2016/11/28 15:17:33 by jhalford #+# #+# */
/* Updated: 2016/11/03 18:04:15 by jhalford ### ########.fr */ /* Updated: 2016/11/28 15:18:12 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -14,13 +14,5 @@
void ft_sstrprint(char **list, char sep) void ft_sstrprint(char **list, char sep)
{ {
int i; ft_sstrprint_fd(STDOUT, list, sep);
i = 0;
while (list[i])
{
ft_putstr(list[i++]);
if (list[i])
ft_putchar(sep);
}
} }

View file

@ -0,0 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_sstrprint_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);
}
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/03 14:58:22 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */