mergeuhhh

This commit is contained in:
Jack Halford 2016-11-16 10:57:45 +01:00
commit 12f6e233a2
40 changed files with 519 additions and 43 deletions

33
libft/includes/btree.h Normal file
View file

@ -0,0 +1,33 @@
#ifndef BTREE_H
# define BTREE_H
#include "libft.h"
typedef struct s_btree t_btree;
struct s_btree
{
void *item;
size_t content_size;
struct s_btree *left;
struct s_btree *right;
};
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(t_btree* tree, void (*printer)(t_btree *tree));
#endif

View file

@ -23,12 +23,13 @@ struct s_dlist
typedef struct s_dlist t_dlist; typedef struct s_dlist t_dlist;
void ft_dlst_add_after(t_dlist **alst, t_dlist *new); void ft_dlstadd_after(t_dlist **alst, t_dlist *new);
void ft_dlst_add_before(t_dlist **alst, t_dlist *new); void ft_dlstadd_before(t_dlist **alst, t_dlist *new);
void ft_dlst_delone(t_dlist **alst, void (*del)(void *, size_t)); void ft_dlstdel(t_dlist **alst, void (*del)(void *, size_t));
int ft_dlst_size(t_dlist *list); void ft_dlstdelone(t_dlist **alst, void (*del)(void *, size_t));
t_dlist *ft_dlst_new(void const *content, size_t content_size); int ft_dlstsize(t_dlist *list);
t_dlist *ft_dlst_last(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); char *ft_dlsttostr(t_dlist *list);
#endif #endif

View file

@ -6,7 +6,11 @@
/* 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 #+# #+# */
<<<<<<< HEAD
/* Updated: 2016/11/16 10:53:34 by jhalford ### ########.fr */ /* Updated: 2016/11/16 10:53:34 by jhalford ### ########.fr */
=======
/* Updated: 2016/11/14 16:31:04 by jhalford ### ########.fr */
>>>>>>> a3f7d30e3fc482af179207682b48ae052d422bdf
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -16,6 +20,7 @@
# include "ft_xattr.h" # include "ft_xattr.h"
# include "lst.h" # include "lst.h"
# include "dlst.h" # include "dlst.h"
# include "btree.h"
# include <string.h> # include <string.h>
# include <unistd.h> # include <unistd.h>
@ -31,6 +36,14 @@
# 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)))
typedef struct s_stof t_stof;
struct s_stof
{
char *name;
int (*f)();
};
void ft_debug(void); void ft_debug(void);
void *ft_memset(void *b, int c, size_t len); void *ft_memset(void *b, int c, size_t len);
@ -105,12 +118,14 @@ size_t ft_ilen_base(int n, int base);
size_t ft_uilen(unsigned int n); size_t ft_uilen(unsigned int n);
size_t ft_lllen(long long n); size_t ft_lllen(long long n);
size_t ft_lllen_base(long long n, int base); 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)()); void ft_sstrsort(char **list, int size, int (*cmp)());
void ft_sstrprint(char **list, char sep); void ft_sstrprint(char **list, char sep);
char **ft_sstrdup(char **list); char **ft_sstrdup(char **list);
char **ft_sstradd(char **list, char *new);
void ft_sstrdel(char **sstr, int index); void ft_sstrdel(char **sstr, int index);
void ft_sstrfree(char **sstr);
int ft_time_isrecent(time_t event); int ft_time_isrecent(time_t event);
@ -118,4 +133,8 @@ char *ft_path_notdir(char *path);
int ft_printf(const char *format, ...); int ft_printf(const char *format, ...);
int ft_dprintf(int fd, const char *format, ...); int ft_dprintf(int fd, const char *format, ...);
char *ft_getenv(char **env, char *key);
void *ft_realloc(void *data, int size);
#endif #endif

View file

@ -0,0 +1,46 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* btree_apply_by_level.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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++;
}
}

View file

@ -0,0 +1,23 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* btree_create_node.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/08/16 13:43:51 by jhalford #+# #+# */
/* Updated: 2016/11/14 11:58:47 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 ;
}

View file

@ -0,0 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* btree_create_node.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);
}

View file

@ -0,0 +1,23 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* btree_create_node.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/08/16 13:43:51 by jhalford #+# #+# */
/* Updated: 2016/11/14 16:08:23 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 ;
}

View file

@ -0,0 +1,35 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* btree_create_node.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/08/16 13:43:51 by jhalford #+# #+# */
/* Updated: 2016/11/14 16:11:49 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "btree.h"
t_btree *btree_create_node(void const *item, size_t content_size)
{
t_btree *new;
if (!(new = (t_btree *)malloc(sizeof(t_btree))))
return (NULL);
new->left = 0;
new->right = 0;
if (!item)
{
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);
}
return (new);
}

View file

@ -0,0 +1,43 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* btree_create_node.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/08/16 13:43:51 by jhalford #+# #+# */
/* Updated: 2016/11/14 16:12:47 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "btree.h"
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, content_size);
return ;
}
node = *root;
if ((*cmpf)(item, node->item) < 0)
{
if (node->left)
btree_insert_data(&node->left, item, content_size, cmpf);
else
node->left = btree_create_node(item, content_size);
}
else
{
if (node->right)
btree_insert_data(&node->right, item, content_size, cmpf);
else
node->right = btree_create_node(item, content_size);
}
}

View file

@ -0,0 +1,21 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* btree_create_node.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);
}

View file

@ -0,0 +1,41 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* btree_print.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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;
}

View file

@ -0,0 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* btree_create_node.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);
}

View file

@ -12,7 +12,7 @@
#include "libft.h" #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) if (new)
{ {

View file

@ -12,7 +12,7 @@
#include "libft.h" #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) if (new)
{ {

View file

@ -0,0 +1,41 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_dlstdel.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 && del)
{
ft_dlstdelback(&(*alst)->prev, del);
ft_dlstdelfront(&(*alst)->next, del);
ft_dlstdelone(alst, del);
}
}

View file

@ -6,13 +6,13 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/07 13:27:13 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "libft.h" #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; t_dlist *tmp;

View file

@ -12,7 +12,7 @@
#include "libft.h" #include "libft.h"
t_dlist *ft_dlst_last(t_dlist *list) t_dlist *ft_dlstlast(t_dlist *list)
{ {
while (list && list->next) while (list && list->next)
list = list->next; list = list->next;

View file

@ -12,7 +12,7 @@
#include "libft.h" #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; t_dlist *new;

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/07 13:27:29 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); return (NULL);
while (list->prev) while (list->prev)
list = 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) while (list)
{ {
ft_strcat(str, (char *)list->content); ft_strcat(str, (char *)list->content);

View file

@ -12,7 +12,7 @@
#include "libft.h" #include "libft.h"
int ft_dlst_size(t_dlist *list) int ft_dlstsize(t_dlist *list)
{ {
int size; int size;
t_dlist *tmp; t_dlist *tmp;

27
libft/src/env/ft_getenv.c vendored Normal file
View file

@ -0,0 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_getenv.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/07 13:31:48 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/07 16:53:07 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; i = 0;
flag_ptr = fmt->flags; flag_ptr = fmt->flags;
while (fmt->conversion != g_convs[i].id)
i++;
while (*flag_ptr) while (*flag_ptr)
{ {
flag = *flag_ptr; flag = *flag_ptr;
if (!ft_strchr(g_convs[i].allowed_flags, flag)) if (!ft_strchr(g_convs[i].allowed_flags, flag))
{ {
ft_fmt_error_flag_conv(flag, fmt->conversion); ft_fmt_error_flag_conv(flag, fmt->conversion);
/* ft_printf("allowed flags:%s\n", g_convs[i].allowed_flags); */
if (flag == '#') if (flag == '#')
*flag_ptr = '.'; *flag_ptr = '.';
} }
@ -56,8 +59,6 @@ void ft_fmt_validate_flags(t_fmt *fmt)
int i; int i;
i = 0; i = 0;
while (fmt->conversion != g_convs[i].id)
i++;
ft_fmt_validate_flag_conv(fmt); ft_fmt_validate_flag_conv(fmt);
ft_fmt_validate_flag_flag(fmt); ft_fmt_validate_flag_flag(fmt);
} }

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/07 13:33:27 by jhalford #+# #+# */ /* Created: 2016/11/07 13:33:27 by jhalford #+# #+# */
/* Updated: 2016/11/16 10:55:16 by jhalford ### ########.fr */ /* Updated: 2016/11/16 10:57:25 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/07 13:33:24 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -13,7 +13,7 @@
#include "libft.h" #include "libft.h"
#define BUFF_SIZE 32 #define BUFF_SIZE 32
static char *ft_realloc(char *line, int size) static char *ft_strrealloc(char *line, int size)
{ {
char *str; char *str;
@ -41,7 +41,7 @@ static int ft_loop_read(int fd, char **line, char (*save)[])
ft_strcat(*line, buf); ft_strcat(*line, buf);
return (1); return (1);
} }
if ((*line = ft_realloc(*line, ret)) == NULL) if ((*line = ft_strrealloc(*line, ret)) == NULL)
return (-1); return (-1);
ft_strcat(*line, buf); ft_strcat(*line, buf);
} }

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/04 11:09:12 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

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/08 13:45:13 by jhalford ### ########.fr */ /* Updated: 2016/11/14 15:50:00 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -16,23 +16,19 @@ t_list *ft_lstnew(void const *content, size_t content_size)
{ {
t_list *new; t_list *new;
if (!(new = (t_list *)malloc(sizeof(*new))))
return (NULL);
new->next = NULL;
if (!content) if (!content)
{ {
new = malloc(sizeof(*new));
if (!new)
return (NULL);
new->content_size = 0; new->content_size = 0;
new->content = NULL; new->content = NULL;
} }
else else
{ {
new = (t_list *)malloc(sizeof(*new));
if (!new)
return (NULL);
new->content_size = content_size; new->content_size = content_size;
new->content = ft_memalloc(content_size + 1); new->content = ft_memalloc(content_size + 1);
ft_memcpy(new->content, content, content_size); ft_memcpy(new->content, content, content_size);
} }
new->next = NULL;
return (new); return (new);
} }

View file

@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_addrcmp.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);
}

View file

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

View file

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

View file

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

View file

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

View file

@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_realloc.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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;
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);
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/03 18:03:58 by jhalford #+# #+# */ /* Created: 2016/11/03 18:03:58 by jhalford #+# #+# */
/* Updated: 2016/11/03 18:04:23 by jhalford ### ########.fr */ /* Updated: 2016/11/14 16:31:02 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -22,7 +22,8 @@ char **ft_sstradd(char **sstr, char *new)
size = 0; size = 0;
while (sstr && sstr[size]) while (sstr && sstr[size])
size++; size++;
newlist = (char **)malloc(sizeof(char *) * (size + 3)); if (!(newlist = (char **)malloc(sizeof(char *) * (size + 2))))
return (NULL);
while (sstr && *sstr) while (sstr && *sstr)
newlist[i++] = *sstr++; newlist[i++] = *sstr++;
newlist[i++] = new; newlist[i++] = new;

View file

@ -0,0 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_sstrfree.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/08 17:01:24 by jhalford #+# #+# */
/* Updated: 2016/11/14 11:08:19 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_sstrfree(char **sstr)
{
int i;
i = 0;
if (sstr)
{
while (sstr[i])
{
ft_strdel(sstr + i);
i++;
}
ft_strdel(sstr + i);
free(sstr);
}
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/08/07 10:56:53 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); size = ft_strlen(s1);
j = 0; j = 0;
while (s2[j] != '\0') while (s2 && s2[j])
{ {
s1[size + j] = s2[j]; s1[size + j] = s2[j];
j++; j++;

View file

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

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/03 14:58:23 by jhalford ### ########.fr */ /* Updated: 2016/11/10 10:14:18 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */