libft changed name to readd submodule
This commit is contained in:
parent
031045fbe3
commit
a983057653
151 changed files with 0 additions and 4894 deletions
1
ls/libft/.gitignore
vendored
1
ls/libft/.gitignore
vendored
|
|
@ -1 +0,0 @@
|
||||||
libft.a
|
|
||||||
|
|
@ -1,39 +0,0 @@
|
||||||
NAME = libft.a
|
|
||||||
CC = gcc
|
|
||||||
AR = ar -rc
|
|
||||||
|
|
||||||
D_SRC = src
|
|
||||||
D_OBJ = obj
|
|
||||||
|
|
||||||
O_FLAGS =
|
|
||||||
W_FLAGS = -Wall -Wextra -Werror
|
|
||||||
DEBUG =
|
|
||||||
MKDIR = mkdir -p
|
|
||||||
RM = /bin/rm -rf
|
|
||||||
|
|
||||||
D_INC = includes
|
|
||||||
|
|
||||||
F_SRC := $(shell find $(D_SRC) -type f -regex ".*\.c$$")
|
|
||||||
F_OBJ := $(addprefix $(D_OBJ)/, $(notdir $(F_SRC:.c=.o)))
|
|
||||||
|
|
||||||
.PHONY: all clean fclean re
|
|
||||||
|
|
||||||
all: $(NAME)
|
|
||||||
|
|
||||||
$(D_OBJ)/%.o: $(D_SRC)/*/%.c
|
|
||||||
@$(MKDIR) $(D_OBJ)
|
|
||||||
@$(CC) -I$(D_INC) $(W_FLAGS) -c $< -o $@ $(DEBUG)
|
|
||||||
@echo "(libft) Compiling "$<"..."
|
|
||||||
|
|
||||||
$(NAME): $(F_OBJ)
|
|
||||||
@$(AR) $(NAME) $(F_OBJ)
|
|
||||||
@echo "(libft) Linking "$@"..."
|
|
||||||
@ranlib $(NAME)
|
|
||||||
|
|
||||||
clean:
|
|
||||||
$(RM) $(D_OBJ)
|
|
||||||
|
|
||||||
fclean: clean
|
|
||||||
$(RM) $(NAME)
|
|
||||||
|
|
||||||
re: fclean all
|
|
||||||
|
|
@ -1,45 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* btree.h :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* 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"
|
|
||||||
|
|
||||||
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, char *(*printer)(void *));
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
@ -1,35 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* dlst.h :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/11/07 13:21:04 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2016/11/07 13:21:52 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#ifndef DLST_H
|
|
||||||
# define DLST_H
|
|
||||||
|
|
||||||
struct s_dlist
|
|
||||||
{
|
|
||||||
void *content;
|
|
||||||
size_t content_size;
|
|
||||||
struct s_dlist *next;
|
|
||||||
struct s_dlist *prev;
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef struct s_dlist t_dlist;
|
|
||||||
|
|
||||||
void ft_dlstadd_after(t_dlist **alst, t_dlist *new);
|
|
||||||
void ft_dlstadd_before(t_dlist **alst, t_dlist *new);
|
|
||||||
void ft_dlstdel(t_dlist **alst, void (*del)(void *, size_t));
|
|
||||||
void ft_dlstdelone(t_dlist **alst, void (*del)(void *, size_t));
|
|
||||||
int ft_dlstsize(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);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
@ -1,80 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ftprintf.h :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/11/07 13:22:54 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2016/11/21 18:20:10 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#ifndef FT_PRINTF_H
|
|
||||||
# define FT_PRINTF_H
|
|
||||||
# include "libft.h"
|
|
||||||
# include <stdarg.h>
|
|
||||||
# define ALL_FLAGS "#0- +"
|
|
||||||
# define ALL_CONVERSIONS "sSpdDioOuUxXcCb"
|
|
||||||
|
|
||||||
typedef struct s_fmt t_fmt;
|
|
||||||
typedef struct s_conv t_conv;
|
|
||||||
typedef char *(t_converter)(t_fmt *fmt, va_list ap);
|
|
||||||
typedef void (t_pad_func)(char *str, t_fmt *fmt);
|
|
||||||
|
|
||||||
struct s_conv
|
|
||||||
{
|
|
||||||
char id;
|
|
||||||
char allowed_flags[6];
|
|
||||||
char base[20];
|
|
||||||
t_converter *converter;
|
|
||||||
t_pad_func *sharp_func;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct s_fmt
|
|
||||||
{
|
|
||||||
char flags[6];
|
|
||||||
int width;
|
|
||||||
int precision;
|
|
||||||
char modifier[3];
|
|
||||||
char conversion;
|
|
||||||
int valid;
|
|
||||||
t_conv conv;
|
|
||||||
};
|
|
||||||
|
|
||||||
int ft_vdprintf(int fd, const char *format, va_list ap);
|
|
||||||
int ft_fmtcalc(char **final, char **str, va_list ap);
|
|
||||||
|
|
||||||
extern t_conv g_convs[];
|
|
||||||
|
|
||||||
t_fmt *ft_fmt_init(void);
|
|
||||||
void ft_fmt_print(t_fmt *fmt);
|
|
||||||
|
|
||||||
t_fmt *ft_printf_parse(char **format, va_list ap);
|
|
||||||
void ft_printf_parse_flags(t_fmt *fmt, char **format);
|
|
||||||
void ft_printf_parse_width(t_fmt *fmt, char **format, va_list ap);
|
|
||||||
void ft_printf_parse_precision(t_fmt *fmt, char **format, va_list ap);
|
|
||||||
void ft_printf_parse_modifiers(t_fmt *fmt, char **format);
|
|
||||||
|
|
||||||
char *ft_transform(t_fmt *fmt, va_list ap);
|
|
||||||
|
|
||||||
void ft_fmt_error_conv(char conv);
|
|
||||||
void ft_fmt_error_mod_conv(char *mod, char conv);
|
|
||||||
void ft_fmt_error_flag_conv(char flag, char conv);
|
|
||||||
void ft_fmt_error_flag_flag(char flag1, char flag2);
|
|
||||||
|
|
||||||
void ft_fmt_simplify(t_fmt *fmt);
|
|
||||||
int ft_fmt_validate_conv(t_fmt *fmt);
|
|
||||||
void ft_fmt_validate_flags(t_fmt *fmt);
|
|
||||||
void ft_fmt_validate_mod(t_fmt *fmt);
|
|
||||||
|
|
||||||
char *ft_signed_conversion(t_fmt *fmt, va_list ap);
|
|
||||||
char *ft_unsigned_conversion(t_fmt *fmt, va_list ap);
|
|
||||||
char *ft_str_conversion(t_fmt *fmt, va_list ap);
|
|
||||||
char *ft_char_conversion(t_fmt *fmt, va_list ap);
|
|
||||||
|
|
||||||
void ft_pad_sharp_o(char *str, t_fmt *fmt);
|
|
||||||
void ft_pad_sharp_xb(char *str, t_fmt *fmt);
|
|
||||||
void ft_pad_left(char *str, t_fmt *fmt);
|
|
||||||
void ft_pad_right(char *str, t_fmt *fmt);
|
|
||||||
#endif
|
|
||||||
|
|
@ -1,21 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ftxattr.h :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/11/07 13:24:05 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2016/11/07 13:24:05 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#ifndef FT_XATTR_H
|
|
||||||
# define FT_XATTR_H
|
|
||||||
# define FT_XATTR_SIZE 10000
|
|
||||||
# include <sys/types.h>
|
|
||||||
# include <sys/xattr.h>
|
|
||||||
|
|
||||||
int ft_xattr_print(char *path);
|
|
||||||
int ft_xattr_count(char *path);
|
|
||||||
#endif
|
|
||||||
|
|
@ -1,31 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* get_next_line.h :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/11/05 12:21:36 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2016/11/17 13:18:28 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#ifndef GET_NEXT_LINE_H
|
|
||||||
# define GET_NEXT_LINE_H
|
|
||||||
# define BUFF_SIZE 32
|
|
||||||
|
|
||||||
# include "libft.h"
|
|
||||||
# include <sys/types.h>
|
|
||||||
# include <sys/uio.h>
|
|
||||||
|
|
||||||
typedef struct s_save t_save;
|
|
||||||
|
|
||||||
struct s_save
|
|
||||||
{
|
|
||||||
int fd;
|
|
||||||
char *str;
|
|
||||||
};
|
|
||||||
|
|
||||||
int get_next_line(int const fd, char **line);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
@ -1,138 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* libft.h :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/11/07 13:49:04 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2016/11/23 13:56:46 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#ifndef LIBFT_H
|
|
||||||
# define LIBFT_H
|
|
||||||
|
|
||||||
# include "ft_xattr.h"
|
|
||||||
# include "lst.h"
|
|
||||||
# include "dlst.h"
|
|
||||||
# include "btree.h"
|
|
||||||
|
|
||||||
# include <string.h>
|
|
||||||
# include <unistd.h>
|
|
||||||
# include <stdio.h>
|
|
||||||
# include <stdlib.h>
|
|
||||||
# include <time.h>
|
|
||||||
|
|
||||||
# define FT_WS(x) (x == ' ' || x == '\t' || x == '\n')
|
|
||||||
# define FT_ABS(x) (((x) < 0) ? -(x) : (x))
|
|
||||||
# define FT_NEG(x) (((x) < 0) ? 1 : 0)
|
|
||||||
# define FT_POS(x) (((x) > 0) ? 1 : 0)
|
|
||||||
# define FT_MIN(a, b) ((a) < (b) ? (a) : (b))
|
|
||||||
# define FT_MAX(a, b) ((a) > (b) ? (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_memset(void *b, int c, size_t len);
|
|
||||||
void ft_bzero(void *s, size_t n);
|
|
||||||
void *ft_memcpy(void *dst, const void *src, size_t n);
|
|
||||||
void *ft_memccpy(void *dst, const void *src, int c, size_t n);
|
|
||||||
void *ft_memmove(void *dst, const void *src, size_t len);
|
|
||||||
void *ft_memchr(const void *s, int c, size_t n);
|
|
||||||
int ft_memcmp(const void *s1, const void *s2, size_t n);
|
|
||||||
size_t ft_strlen(const char *s);
|
|
||||||
char *ft_strdup(const char *s1);
|
|
||||||
char *ft_strcpy(char *dst, const char *src);
|
|
||||||
char *ft_strncpy(char *dst, const char *src, size_t len);
|
|
||||||
char *ft_strcat(char *s1, const char *s2);
|
|
||||||
char *ft_strncat(char *s1, const char *s2, size_t n);
|
|
||||||
size_t ft_strlcat(char *dst, const char *src, size_t size);
|
|
||||||
char *ft_strchr(const char *s, int c);
|
|
||||||
char *ft_strrchr(const char *s, int c);
|
|
||||||
char *ft_strstr(const char *big, const char *little);
|
|
||||||
char *ft_strnstr(const char *big, const char *little, size_t len);
|
|
||||||
int ft_strcmp(const char *s1, const char *s2);
|
|
||||||
int ft_strncmp(const char *s1, const char *s2, size_t n);
|
|
||||||
int ft_atoi(const char *str);
|
|
||||||
int ft_isalpha(int c);
|
|
||||||
int ft_isdigit(int c);
|
|
||||||
int ft_isalnum(int c);
|
|
||||||
int ft_isascii(int c);
|
|
||||||
int ft_isprint(int c);
|
|
||||||
int ft_toupper(int c);
|
|
||||||
int ft_tolower(int c);
|
|
||||||
|
|
||||||
void *ft_memalloc(size_t size);
|
|
||||||
void ft_memdel(void **ap);
|
|
||||||
char *ft_strnew(size_t size);
|
|
||||||
void ft_strdel(char **as);
|
|
||||||
void ft_strclr(char *s);
|
|
||||||
void ft_striter(char *s, void (*f)(char *));
|
|
||||||
void ft_striteri(char *s, void (*f)(unsigned int, char *));
|
|
||||||
char *ft_strmap(char const *s, char (*f)(char));
|
|
||||||
char *ft_strmapi(char const *s, char (*f)(unsigned int, char));
|
|
||||||
int ft_strequ(char const *s1, char const *s2);
|
|
||||||
int ft_strnequ(char const *s1, char const *s2, size_t n);
|
|
||||||
char *ft_strsub(char const *s, unsigned int start, size_t len);
|
|
||||||
char *ft_strjoin(char const *s1, char const *s2);
|
|
||||||
char *ft_strtrim(char const *s);
|
|
||||||
char **ft_strsplit(char const *s, char c);
|
|
||||||
char *ft_itoa(int n);
|
|
||||||
int ft_putchar(int c);
|
|
||||||
void ft_putstr(char const *s);
|
|
||||||
void ft_putendl(char const *s);
|
|
||||||
void ft_putnbr(int n);
|
|
||||||
void ft_putchar_fd(char c, int fd);
|
|
||||||
void ft_putstr_fd(char const *s, int fd);
|
|
||||||
void ft_putendl_fd(char const *s, int fd);
|
|
||||||
void ft_putnbr_fd(int n, int fd);
|
|
||||||
void ft_putaddr(void *a);
|
|
||||||
|
|
||||||
char *ft_strrev(char *str);
|
|
||||||
char **ft_strsplit(char const *s, char c);
|
|
||||||
char *ft_str3join(char const *s1, char const *s2, char const *s3);
|
|
||||||
char *ft_strcut(char *str, char *cut);
|
|
||||||
char **ft_split_whitespaces(char *str);
|
|
||||||
char *ft_convert_base(
|
|
||||||
char *str, char *base_from, char *base_to, char *flags);
|
|
||||||
char *ft_strcatf(char *s1, const char *s2);
|
|
||||||
char *ft_strinsert(char *str, char c, int n);
|
|
||||||
|
|
||||||
char *ft_itoa_base(int nbr, char *base, char *flags);
|
|
||||||
char *ft_lltoa_base(long long nbr, char *base, char *flags);
|
|
||||||
char *ft_ulltoa_base(unsigned long long nbr, char *base);
|
|
||||||
char *ft_uitoa_base(unsigned int nbr, char *base);
|
|
||||||
size_t ft_ilen(int n);
|
|
||||||
size_t ft_ilen_base(int n, int base);
|
|
||||||
size_t ft_uilen(unsigned int n);
|
|
||||||
size_t ft_lllen(long long n);
|
|
||||||
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 (*cmp)());
|
|
||||||
void ft_sstrprint(char **list, char sep);
|
|
||||||
char **ft_sstrdup(char **list);
|
|
||||||
void ft_sstrdel(char **sstr, int index);
|
|
||||||
void ft_sstrfree(char **sstr);
|
|
||||||
|
|
||||||
int ft_time_isrecent(time_t event);
|
|
||||||
|
|
||||||
char *ft_path_notdir(char *path);
|
|
||||||
|
|
||||||
int ft_printf(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
|
|
||||||
|
|
@ -1,76 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* lst.h :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/11/07 13:27:46 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2016/11/23 14:50:54 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#ifndef LST_H
|
|
||||||
# define LST_H
|
|
||||||
|
|
||||||
struct s_list
|
|
||||||
{
|
|
||||||
void *content;
|
|
||||||
size_t content_size;
|
|
||||||
struct s_list *next;
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef struct s_list t_list;
|
|
||||||
|
|
||||||
t_list *ft_lstnew(void const *content, size_t content_size);
|
|
||||||
void ft_lstdel(t_list **alst, void (*del)(void *, size_t));
|
|
||||||
void ft_lstdelone(t_list **alst, void (*del)(void *, size_t));
|
|
||||||
void ft_lstadd(t_list **alst, t_list *new);
|
|
||||||
void ft_lstiter(t_list *lst, void (*f)(t_list *elem));
|
|
||||||
t_list *ft_lstmap(t_list *lst, t_list *(*f)(t_list *elem));
|
|
||||||
|
|
||||||
t_list *ft_lstnew_range(int a, int b);
|
|
||||||
void ft_lsteadd(t_list **alst, t_list *new);
|
|
||||||
void ft_lstnadd(t_list **alst, t_list *new, int n);
|
|
||||||
void ft_lstsort(t_list **begin_list, int (*cmp)());
|
|
||||||
void ft_lst_print(t_list *list, void (*printer)());
|
|
||||||
int ft_lstsize(t_list *lst);
|
|
||||||
t_list *ft_lstlast(t_list *lst);
|
|
||||||
void ft_lst_sorted_merge(
|
|
||||||
t_list **begin_list1,
|
|
||||||
t_list *begin_list2,
|
|
||||||
int (*cmp)());
|
|
||||||
void ft_lst_sorted_insert(
|
|
||||||
t_list **begin_list,
|
|
||||||
t_list *insert,
|
|
||||||
int (*cmp)());
|
|
||||||
void ft_lst_delif(
|
|
||||||
t_list **alist,
|
|
||||||
void *data_ref,
|
|
||||||
int (*cmp)(),
|
|
||||||
void (*del)(void *, size_t));
|
|
||||||
void ft_lst_delsub(
|
|
||||||
t_list **alst,
|
|
||||||
t_list *sub, int (*cmp)(),
|
|
||||||
void (*del)(void *, size_t));
|
|
||||||
void ft_lst_cfree(void *ptr, size_t size);
|
|
||||||
t_list *ft_lst_filter(
|
|
||||||
t_list *lst,
|
|
||||||
void const *data_ref,
|
|
||||||
t_list *(*f)(t_list *elem, void const *));
|
|
||||||
t_list *ft_lst_removeif(
|
|
||||||
t_list **alst,
|
|
||||||
void *data_ref,
|
|
||||||
int (*cmp)());
|
|
||||||
t_list *ft_lst_find(
|
|
||||||
t_list *begin_list,
|
|
||||||
void *data_ref,
|
|
||||||
int (*cmp)());
|
|
||||||
t_list *ft_lstpop(t_list **lst);
|
|
||||||
void ft_lst_merge(t_list **begin_list1, t_list *begin_list2);
|
|
||||||
void ft_lst_reverse(t_list **begin_list);
|
|
||||||
|
|
||||||
int ft_diff(void *a, void *b);
|
|
||||||
t_list *ft_id(t_list *a);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -1,46 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* btree_apply_by_level.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/08/19 12:06:15 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2016/11/16 11:14:28 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++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,23 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* 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 ;
|
|
||||||
}
|
|
||||||
|
|
@ -1,22 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* 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);
|
|
||||||
}
|
|
||||||
|
|
@ -1,23 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* 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 ;
|
|
||||||
}
|
|
||||||
|
|
@ -1,35 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* 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);
|
|
||||||
}
|
|
||||||
|
|
@ -1,43 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,21 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* 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);
|
|
||||||
}
|
|
||||||
|
|
@ -1,30 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* 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);
|
|
||||||
}
|
|
||||||
|
|
@ -1,22 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_isalnum.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/11/03 14:56:18 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2016/11/03 15:31:33 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
int ft_isalnum(int c)
|
|
||||||
{
|
|
||||||
if ((c >= 'a' && c <= 'z')
|
|
||||||
|| (c >= 'A' && c <= 'Z')
|
|
||||||
|| (c >= '0' && c <= '9'))
|
|
||||||
return (c);
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
@ -1,20 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_isalpha.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/11/03 14:56:24 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2016/11/03 15:32:00 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
int ft_isalpha(int c)
|
|
||||||
{
|
|
||||||
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
|
|
||||||
return (c);
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
@ -1,20 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_isascii.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/11/03 14:56:28 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2016/11/03 15:35:42 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
int ft_isascii(int c)
|
|
||||||
{
|
|
||||||
if (c >= 0 && c <= 127)
|
|
||||||
return (1);
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
@ -1,23 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_isdigit.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/11/03 14:56:33 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2016/11/03 14:56:34 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
int ft_isdigit(int c)
|
|
||||||
{
|
|
||||||
unsigned char a;
|
|
||||||
|
|
||||||
a = (unsigned char)c;
|
|
||||||
if (a >= '0' && a <= '9')
|
|
||||||
return (a);
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
@ -1,20 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_isprint.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/11/03 14:56:38 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2016/11/03 15:32:40 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
int ft_isprint(int c)
|
|
||||||
{
|
|
||||||
if (c >= 32 && c <= 126)
|
|
||||||
return (c);
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
@ -1,20 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_tolower.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/11/03 14:58:46 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2016/11/03 15:24:09 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
int ft_tolower(int c)
|
|
||||||
{
|
|
||||||
if (c >= 'A' && c <= 'Z')
|
|
||||||
return (c + 32);
|
|
||||||
return (c);
|
|
||||||
}
|
|
||||||
|
|
@ -1,20 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_toupper.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/11/03 14:53:58 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2016/11/03 15:24:40 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
int ft_toupper(int c)
|
|
||||||
{
|
|
||||||
if (c >= 'a' && c <= 'z')
|
|
||||||
return (c - 32);
|
|
||||||
return (c);
|
|
||||||
}
|
|
||||||
|
|
@ -1,30 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_dlst_add_after.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/11/07 13:27:04 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2016/11/07 13:27:36 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void ft_dlstadd_after(t_dlist **alst, t_dlist *new)
|
|
||||||
{
|
|
||||||
if (new)
|
|
||||||
{
|
|
||||||
new->prev = (*alst);
|
|
||||||
if (*alst)
|
|
||||||
new->next = (*alst)->next;
|
|
||||||
else
|
|
||||||
new->next = NULL;
|
|
||||||
if (new->next)
|
|
||||||
new->next->prev = new;
|
|
||||||
if (new->prev)
|
|
||||||
new->prev->next = new;
|
|
||||||
*alst = new;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,28 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_dlst_add_before.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/11/07 13:27:09 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2016/11/07 13:27:10 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void ft_dlstadd_before(t_dlist **alst, t_dlist *new)
|
|
||||||
{
|
|
||||||
if (new)
|
|
||||||
{
|
|
||||||
new->next = (*alst);
|
|
||||||
if (*alst)
|
|
||||||
new->prev = (*alst)->prev;
|
|
||||||
if (new->next)
|
|
||||||
new->next->prev = new;
|
|
||||||
if (new->prev)
|
|
||||||
new->prev->next = new;
|
|
||||||
*alst = new;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,41 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_dlstdel.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/11/14 17:55:40 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2016/11/16 11:15:40 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,34 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_dlst_delone.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/11/07 13:27:13 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2016/11/14 17:52:58 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void ft_dlstdelone(t_dlist **alst, void (*del)(void *, size_t))
|
|
||||||
{
|
|
||||||
t_dlist *tmp;
|
|
||||||
|
|
||||||
tmp = *alst;
|
|
||||||
if (tmp)
|
|
||||||
{
|
|
||||||
if (del)
|
|
||||||
(*del)(tmp->content, tmp->content_size);
|
|
||||||
if (tmp->next)
|
|
||||||
tmp->next->prev = tmp->prev;
|
|
||||||
if (tmp->prev)
|
|
||||||
tmp->prev->next = tmp->next;
|
|
||||||
if (tmp->prev)
|
|
||||||
*alst = tmp->prev;
|
|
||||||
else
|
|
||||||
*alst = tmp->next;
|
|
||||||
free(tmp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,20 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_dlst_last.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/11/07 13:27:15 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2016/11/07 13:27:15 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
t_dlist *ft_dlstlast(t_dlist *list)
|
|
||||||
{
|
|
||||||
while (list && list->next)
|
|
||||||
list = list->next;
|
|
||||||
return (list);
|
|
||||||
}
|
|
||||||
|
|
@ -1,39 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_dlst_new.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/11/07 13:27:20 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2016/11/07 13:27:20 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
t_dlist *ft_dlstnew(void const *content, size_t content_size)
|
|
||||||
{
|
|
||||||
t_dlist *new;
|
|
||||||
|
|
||||||
if (!content)
|
|
||||||
{
|
|
||||||
new = malloc(sizeof(*new));
|
|
||||||
if (!new)
|
|
||||||
return (NULL);
|
|
||||||
new->content_size = 0;
|
|
||||||
new->content = NULL;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
new = (t_dlist *)malloc(sizeof(*new));
|
|
||||||
if (!new)
|
|
||||||
return (NULL);
|
|
||||||
new->content_size = content_size;
|
|
||||||
new->content = ft_memalloc(content_size + 1);
|
|
||||||
ft_memcpy(new->content, content, content_size);
|
|
||||||
}
|
|
||||||
new->next = NULL;
|
|
||||||
new->prev = NULL;
|
|
||||||
return (new);
|
|
||||||
}
|
|
||||||
|
|
@ -1,30 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_dlstrtostr.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/11/07 13:27:29 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2016/11/14 16:13:24 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
char *ft_dlsttostr(t_dlist *list)
|
|
||||||
{
|
|
||||||
char *str;
|
|
||||||
|
|
||||||
if (!list)
|
|
||||||
return (NULL);
|
|
||||||
while (list->prev)
|
|
||||||
list = list->prev;
|
|
||||||
str = (char *)ft_strnew(sizeof(char) * (ft_dlstsize(list) + 2));
|
|
||||||
while (list)
|
|
||||||
{
|
|
||||||
ft_strcat(str, (char *)list->content);
|
|
||||||
list = list->next;
|
|
||||||
}
|
|
||||||
return (str);
|
|
||||||
}
|
|
||||||
|
|
@ -1,36 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_dlst_size.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/11/07 13:27:23 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2016/11/07 13:27:23 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
int ft_dlstsize(t_dlist *list)
|
|
||||||
{
|
|
||||||
int size;
|
|
||||||
t_dlist *tmp;
|
|
||||||
|
|
||||||
size = 0;
|
|
||||||
if (list)
|
|
||||||
size++;
|
|
||||||
tmp = list;
|
|
||||||
while (tmp->next)
|
|
||||||
{
|
|
||||||
size++;
|
|
||||||
tmp = tmp->next;
|
|
||||||
}
|
|
||||||
tmp = list;
|
|
||||||
while (tmp->prev)
|
|
||||||
{
|
|
||||||
size++;
|
|
||||||
tmp = tmp->prev;
|
|
||||||
}
|
|
||||||
return (size);
|
|
||||||
}
|
|
||||||
26
ls/libft/src/env/ft_getenv.c
vendored
26
ls/libft/src/env/ft_getenv.c
vendored
|
|
@ -1,26 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_getenv.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/11/10 14:30:00 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2016/11/16 11:24:52 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
char *ft_getenv(char **env, char *key)
|
|
||||||
{
|
|
||||||
if (!env)
|
|
||||||
return (NULL);
|
|
||||||
while (*env)
|
|
||||||
{
|
|
||||||
if (ft_strcmp(*env, key) == '=')
|
|
||||||
return (*env + ft_strlen(key) + 1);
|
|
||||||
env++;
|
|
||||||
}
|
|
||||||
return (NULL);
|
|
||||||
}
|
|
||||||
|
|
@ -1,67 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_conversion.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/11/07 13:31:48 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2016/11/16 18:30:20 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "ft_printf.h"
|
|
||||||
|
|
||||||
char *ft_signed_conversion(t_fmt *fmt, va_list ap)
|
|
||||||
{
|
|
||||||
char base10[11];
|
|
||||||
long long arg;
|
|
||||||
|
|
||||||
arg = va_arg(ap, int);
|
|
||||||
ft_strcpy(base10, "0123456789");
|
|
||||||
(void)fmt;
|
|
||||||
return (ft_lltoa_base(arg, base10, fmt->flags));
|
|
||||||
}
|
|
||||||
|
|
||||||
char *ft_unsigned_conversion(t_fmt *fmt, va_list ap)
|
|
||||||
{
|
|
||||||
unsigned int uiarg;
|
|
||||||
unsigned long long ullarg;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
while (fmt->conversion != g_convs[i].id)
|
|
||||||
i++;
|
|
||||||
if (!*fmt->modifier
|
|
||||||
|| 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));
|
|
||||||
}
|
|
||||||
ullarg = va_arg(ap, long long);
|
|
||||||
return (ft_ulltoa_base(ullarg, g_convs[i].base));
|
|
||||||
}
|
|
||||||
|
|
||||||
char *ft_char_conversion(t_fmt *fmt, va_list ap)
|
|
||||||
{
|
|
||||||
char *ret;
|
|
||||||
|
|
||||||
(void)fmt;
|
|
||||||
ret = (char *)malloc(sizeof(char) + 1);
|
|
||||||
ret[0] = (char)va_arg(ap, int);
|
|
||||||
ret[1] = '\0';
|
|
||||||
return (ret);
|
|
||||||
}
|
|
||||||
|
|
||||||
char *ft_str_conversion(t_fmt *fmt, va_list ap)
|
|
||||||
{
|
|
||||||
char *ret;
|
|
||||||
|
|
||||||
(void)fmt;
|
|
||||||
ret = ft_strdup(va_arg(ap, char *));
|
|
||||||
if (fmt->precision && fmt->precision < (int)ft_strlen(ret))
|
|
||||||
ret[fmt->precision] = '\0';
|
|
||||||
return (ret);
|
|
||||||
}
|
|
||||||
|
|
@ -1,31 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* lib_fmt_validate.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/11/07 13:33:43 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2016/11/07 16:53:54 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "ft_printf.h"
|
|
||||||
|
|
||||||
void ft_fmt_simplify(t_fmt *fmt)
|
|
||||||
{
|
|
||||||
char hashtag;
|
|
||||||
|
|
||||||
hashtag = '#';
|
|
||||||
if (fmt->conversion == 'p')
|
|
||||||
{
|
|
||||||
fmt->conversion = 'x';
|
|
||||||
if (!ft_strchr(fmt->flags, '#'))
|
|
||||||
ft_strncat(fmt->flags, &hashtag, 1);
|
|
||||||
}
|
|
||||||
if (ft_strchr("DOUCS", fmt->conversion))
|
|
||||||
{
|
|
||||||
fmt->conversion += 32;
|
|
||||||
ft_strcpy(fmt->modifier, "l");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,24 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_fmt_validate_conv.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/11/07 16:55:36 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2016/11/07 16:55:37 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "ft_printf.h"
|
|
||||||
|
|
||||||
int ft_fmt_validate_conv(t_fmt *fmt)
|
|
||||||
{
|
|
||||||
if (!ft_strchr(ALL_CONVERSIONS, fmt->conversion))
|
|
||||||
{
|
|
||||||
if (fmt->conversion != '%')
|
|
||||||
ft_fmt_error_conv(fmt->conversion);
|
|
||||||
return (1);
|
|
||||||
}
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
@ -1,63 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_fmt_validate_flags.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/11/07 16:53:07 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2016/11/16 11:15:55 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "ft_printf.h"
|
|
||||||
|
|
||||||
static void ft_fmt_validate_flag_flag(t_fmt *fmt)
|
|
||||||
{
|
|
||||||
char *flag_ptr;
|
|
||||||
|
|
||||||
if (ft_strchr(fmt->flags, '+') && (flag_ptr = ft_strchr(fmt->flags, ' ')))
|
|
||||||
{
|
|
||||||
ft_fmt_error_flag_flag(' ', '+');
|
|
||||||
*flag_ptr = '.';
|
|
||||||
}
|
|
||||||
if (ft_strchr(fmt->flags, '-') && (flag_ptr = ft_strchr(fmt->flags, '0')))
|
|
||||||
{
|
|
||||||
ft_fmt_error_flag_flag('0', '-');
|
|
||||||
*flag_ptr = '.';
|
|
||||||
}
|
|
||||||
if (fmt->precision && (flag_ptr = ft_strchr(fmt->flags, '0')))
|
|
||||||
*flag_ptr = '.';
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ft_fmt_validate_flag_conv(t_fmt *fmt)
|
|
||||||
{
|
|
||||||
char *flag_ptr;
|
|
||||||
char flag;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
flag_ptr = fmt->flags;
|
|
||||||
while (fmt->conversion != g_convs[i].id)
|
|
||||||
i++;
|
|
||||||
while (*flag_ptr)
|
|
||||||
{
|
|
||||||
flag = *flag_ptr;
|
|
||||||
if (!ft_strchr(g_convs[i].allowed_flags, flag))
|
|
||||||
{
|
|
||||||
ft_fmt_error_flag_conv(flag, fmt->conversion);
|
|
||||||
if (flag == '#')
|
|
||||||
*flag_ptr = '.';
|
|
||||||
}
|
|
||||||
flag_ptr++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ft_fmt_validate_flags(t_fmt *fmt)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
ft_fmt_validate_flag_conv(fmt);
|
|
||||||
ft_fmt_validate_flag_flag(fmt);
|
|
||||||
}
|
|
||||||
|
|
@ -1,20 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_fmt_validate_conv.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/11/07 16:53:42 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2016/11/07 16:53:52 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "ft_printf.h"
|
|
||||||
|
|
||||||
void ft_fmt_validate_mod(t_fmt *fmt)
|
|
||||||
{
|
|
||||||
if (fmt->conversion == 's' || fmt->conversion == 'c')
|
|
||||||
if (fmt->modifier[0] && ft_strcmp(fmt->modifier, "l"))
|
|
||||||
ft_fmt_error_mod_conv(fmt->modifier, fmt->conversion);
|
|
||||||
}
|
|
||||||
|
|
@ -1,87 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_printf.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/11/07 13:33:27 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2016/11/21 18:22:26 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "ft_printf.h"
|
|
||||||
|
|
||||||
t_conv g_convs[] =
|
|
||||||
{
|
|
||||||
{'d', "0- +", "0123456789", &ft_signed_conversion, NULL},
|
|
||||||
{'i', "0- +", "0123456789", &ft_signed_conversion, NULL},
|
|
||||||
{'u', "0-", "0123456789", &ft_unsigned_conversion, NULL},
|
|
||||||
{'o', "#0-", "01234567", &ft_unsigned_conversion, &ft_pad_sharp_o},
|
|
||||||
{'x', "#0-", "0123456789abcdef", &ft_unsigned_conversion, &ft_pad_sharp_xb},
|
|
||||||
{'X', "#0-", "0123456789ABCDEF", &ft_unsigned_conversion, &ft_pad_sharp_xb},
|
|
||||||
{'b', "#0-", "01", &ft_unsigned_conversion, &ft_pad_sharp_xb},
|
|
||||||
{'s', "-", "", &ft_str_conversion, NULL},
|
|
||||||
{'c', "-", "", &ft_char_conversion, NULL},
|
|
||||||
};
|
|
||||||
|
|
||||||
int ft_printf(const char *format, ...)
|
|
||||||
{
|
|
||||||
va_list ap;
|
|
||||||
|
|
||||||
va_start(ap, format);
|
|
||||||
return (ft_vdprintf(1, format, ap));
|
|
||||||
}
|
|
||||||
|
|
||||||
int ft_dprintf(int fd, const char *format, ...)
|
|
||||||
{
|
|
||||||
va_list ap;
|
|
||||||
|
|
||||||
va_start(ap, format);
|
|
||||||
return (ft_vdprintf(fd, format, ap));
|
|
||||||
}
|
|
||||||
|
|
||||||
int ft_vdprintf(int fd, const char *format, va_list ap)
|
|
||||||
{
|
|
||||||
char *str;
|
|
||||||
char *tmp;
|
|
||||||
char *final;
|
|
||||||
|
|
||||||
str = (char *)format;
|
|
||||||
final = ft_strnew(1);
|
|
||||||
while (*str)
|
|
||||||
{
|
|
||||||
tmp = final;
|
|
||||||
if (*str == '%')
|
|
||||||
{
|
|
||||||
if (ft_fmtcalc(&final, &str, ap))
|
|
||||||
return (1);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
final = ft_strjoin(final, (char[]){*str++, 0});
|
|
||||||
ft_strdel(&tmp);
|
|
||||||
}
|
|
||||||
ft_putstr_fd(final, fd);
|
|
||||||
ft_strdel(&final);
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
int ft_fmtcalc(char **final, char **str, va_list ap)
|
|
||||||
{
|
|
||||||
t_fmt *fmt;
|
|
||||||
char *transform;
|
|
||||||
|
|
||||||
*str += 1;
|
|
||||||
if (!(fmt = ft_printf_parse(str, ap)))
|
|
||||||
return (1);
|
|
||||||
if (!fmt->valid)
|
|
||||||
ft_strncat(*final, &fmt->conversion, 1);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
transform = ft_transform(fmt, ap);
|
|
||||||
*final = ft_strjoin(*final, transform);
|
|
||||||
ft_strdel(&transform);
|
|
||||||
}
|
|
||||||
free(fmt);
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
@ -1,123 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_parse.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/11/07 13:33:24 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2016/11/10 12:59:50 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "ft_printf.h"
|
|
||||||
|
|
||||||
t_fmt *ft_printf_parse(char **format, va_list ap)
|
|
||||||
{
|
|
||||||
t_fmt *fmt;
|
|
||||||
|
|
||||||
fmt = ft_fmt_init();
|
|
||||||
ft_printf_parse_flags(fmt, format);
|
|
||||||
ft_printf_parse_width(fmt, format, ap);
|
|
||||||
ft_printf_parse_precision(fmt, format, ap);
|
|
||||||
ft_printf_parse_modifiers(fmt, format);
|
|
||||||
fmt->conversion = **format;
|
|
||||||
(*format)++;
|
|
||||||
ft_fmt_validate_mod(fmt);
|
|
||||||
ft_fmt_validate_flags(fmt);
|
|
||||||
ft_fmt_simplify(fmt);
|
|
||||||
fmt->valid = ft_fmt_validate_conv(fmt) ? 0 : 1;
|
|
||||||
return (fmt);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ft_printf_parse_flags(t_fmt *fmt, char **format)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
char *str;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
str = *format;
|
|
||||||
while (str[i])
|
|
||||||
{
|
|
||||||
if (ft_strchr(ALL_FLAGS, (int)str[i]))
|
|
||||||
{
|
|
||||||
if (!ft_strchr(fmt->flags, (int)str[i]))
|
|
||||||
ft_strncat(fmt->flags, str + i, 1);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
break ;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
*format += i;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ft_printf_parse_width(t_fmt *fmt, char **format, va_list ap)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
char buf[10];
|
|
||||||
char *str;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
str = *format;
|
|
||||||
if (str[i] == '*')
|
|
||||||
{
|
|
||||||
i++;
|
|
||||||
fmt->width = va_arg(ap, int);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ft_strcpy(buf, "0");
|
|
||||||
while (ft_isdigit((int)(str[i])))
|
|
||||||
ft_strncat(buf, str + i++, 1);
|
|
||||||
fmt->width = ft_atoi(buf);
|
|
||||||
}
|
|
||||||
*format += i;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ft_printf_parse_precision(t_fmt *fmt, char **format, va_list ap)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
char buf[10];
|
|
||||||
char *str;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
str = *format;
|
|
||||||
if (str[i] == '.')
|
|
||||||
{
|
|
||||||
if (str[++i] == '*')
|
|
||||||
{
|
|
||||||
i++;
|
|
||||||
fmt->precision = va_arg(ap, int);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ft_strcpy(buf, "0");
|
|
||||||
while (ft_isdigit(str[i]))
|
|
||||||
ft_strncat(buf, str + i++, 1);
|
|
||||||
fmt->precision = ft_atoi(buf);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*format += i;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ft_printf_parse_modifiers(t_fmt *fmt, char **format)
|
|
||||||
{
|
|
||||||
char *str;
|
|
||||||
|
|
||||||
str = *format;
|
|
||||||
if (str[0] == 'h' && str[1] == 'h')
|
|
||||||
ft_strcpy(fmt->modifier, "hh");
|
|
||||||
else if (str[0] == 'h' && str[1] != 'h')
|
|
||||||
ft_strcpy(fmt->modifier, "h");
|
|
||||||
else if (str[0] == 'l' && str[1] == 'l')
|
|
||||||
ft_strcpy(fmt->modifier, "ll");
|
|
||||||
else if (str[0] == 'l' && str[1] != 'l')
|
|
||||||
ft_strcpy(fmt->modifier, "l");
|
|
||||||
else if (str[0] == 'j')
|
|
||||||
ft_strcpy(fmt->modifier, "j");
|
|
||||||
else if (str[0] == 'z')
|
|
||||||
ft_strcpy(fmt->modifier, "z");
|
|
||||||
else
|
|
||||||
ft_strcpy(fmt->modifier, "");
|
|
||||||
*format += ft_strlen(fmt->modifier);
|
|
||||||
}
|
|
||||||
|
|
@ -1,32 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_transform.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/11/07 13:33:32 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2016/11/16 17:56:37 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "ft_printf.h"
|
|
||||||
|
|
||||||
char *ft_transform(t_fmt *fmt, va_list ap)
|
|
||||||
{
|
|
||||||
char *ret;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
while (fmt->conversion != g_convs[i].id)
|
|
||||||
i++;
|
|
||||||
fmt->conv = g_convs[i];
|
|
||||||
ret = (*fmt->conv.converter)(fmt, ap);
|
|
||||||
if (fmt->width > (int)ft_strlen(ret))
|
|
||||||
ret = ft_realloc(ret, fmt->width + 5);
|
|
||||||
if (ft_strchr(fmt->flags, '-'))
|
|
||||||
ft_pad_right(ret, fmt);
|
|
||||||
else
|
|
||||||
ft_pad_left(ret, fmt);
|
|
||||||
return (ret);
|
|
||||||
}
|
|
||||||
|
|
@ -1,49 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* lib_fmt.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/11/07 13:33:35 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2016/11/16 17:46:16 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "ft_printf.h"
|
|
||||||
|
|
||||||
t_fmt *ft_fmt_init(void)
|
|
||||||
{
|
|
||||||
t_fmt *fmt;
|
|
||||||
|
|
||||||
fmt = (t_fmt *)malloc(sizeof(t_fmt) + 1);
|
|
||||||
ft_bzero(fmt->flags, 6);
|
|
||||||
ft_bzero(fmt->modifier, 3);
|
|
||||||
fmt->conversion = '\0';
|
|
||||||
fmt->width = 0;
|
|
||||||
fmt->precision = 0;
|
|
||||||
fmt->valid = 0;
|
|
||||||
return (fmt);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ft_fmt_print(t_fmt *fmt)
|
|
||||||
{
|
|
||||||
ft_putendl("\n---");
|
|
||||||
ft_putstr("valid: ");
|
|
||||||
ft_putnbr(fmt->valid);
|
|
||||||
ft_putendl("");
|
|
||||||
ft_putstr("conv.: ");
|
|
||||||
ft_putchar(fmt->conversion);
|
|
||||||
ft_putendl("");
|
|
||||||
ft_putstr("flags: ");
|
|
||||||
ft_putendl(fmt->flags);
|
|
||||||
ft_putstr("width: ");
|
|
||||||
ft_putnbr(fmt->width);
|
|
||||||
ft_putendl("");
|
|
||||||
ft_putstr("prec.: ");
|
|
||||||
ft_putnbr(fmt->precision);
|
|
||||||
ft_putendl("");
|
|
||||||
ft_putstr("modifier: ");
|
|
||||||
ft_putendl(fmt->modifier);
|
|
||||||
ft_putendl("---");
|
|
||||||
}
|
|
||||||
|
|
@ -1,47 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* lib_fmt_error.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/11/07 13:33:38 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2016/11/07 17:22:41 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "ft_printf.h"
|
|
||||||
|
|
||||||
void ft_fmt_error_conv(char conv)
|
|
||||||
{
|
|
||||||
ft_putstr("Warning: invalid or unsupported conversion specifier '");
|
|
||||||
ft_putchar(conv);
|
|
||||||
ft_putendl("'");
|
|
||||||
}
|
|
||||||
|
|
||||||
void ft_fmt_error_mod_conv(char *mod, char conv)
|
|
||||||
{
|
|
||||||
ft_putstr("warning: length modifier '");
|
|
||||||
ft_putstr(mod);
|
|
||||||
ft_putstr("' results in undefined behaviour or no effect with '");
|
|
||||||
ft_putchar(conv);
|
|
||||||
ft_putendl("' conversion specifier");
|
|
||||||
}
|
|
||||||
|
|
||||||
void ft_fmt_error_flag_conv(char flag, char conv)
|
|
||||||
{
|
|
||||||
ft_putstr("warning: flag '");
|
|
||||||
ft_putchar(flag);
|
|
||||||
ft_putstr("' results in undefined behaviour with '");
|
|
||||||
ft_putchar(conv);
|
|
||||||
ft_putendl("' conversion specifier");
|
|
||||||
}
|
|
||||||
|
|
||||||
void ft_fmt_error_flag_flag(char flag1, char flag2)
|
|
||||||
{
|
|
||||||
ft_putstr("warning: flag '");
|
|
||||||
ft_putchar(flag1);
|
|
||||||
ft_putstr("' is ignored when flag '");
|
|
||||||
ft_putchar(flag2);
|
|
||||||
ft_putendl("' is present");
|
|
||||||
}
|
|
||||||
|
|
@ -1,42 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* lib_pad.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/11/07 13:33:45 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2016/11/16 18:13:08 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "ft_printf.h"
|
|
||||||
|
|
||||||
void ft_pad_right(char *str, t_fmt *fmt)
|
|
||||||
{
|
|
||||||
if (ft_strchr(fmt->flags, '#'))
|
|
||||||
(fmt->conv.sharp_func)(str, fmt);
|
|
||||||
while ((int)ft_strlen(str) < fmt->width)
|
|
||||||
ft_strcat(str, " ");
|
|
||||||
}
|
|
||||||
|
|
||||||
void ft_pad_left(char *str, t_fmt *fmt)
|
|
||||||
{
|
|
||||||
char sign;
|
|
||||||
|
|
||||||
sign = 0;
|
|
||||||
if (str[0] == '-' || str[0] == '+' || str[0] == ' ')
|
|
||||||
{
|
|
||||||
sign = str[0];
|
|
||||||
str++;
|
|
||||||
}
|
|
||||||
if (ft_strchr(fmt->flags, '0'))
|
|
||||||
while ((int)ft_strlen(str) < fmt->width - (sign ? 1 : 0))
|
|
||||||
ft_strcatf(str, "0");
|
|
||||||
if (sign)
|
|
||||||
str--;
|
|
||||||
if (ft_strchr(fmt->flags, '#'))
|
|
||||||
(fmt->conv.sharp_func)(str, fmt);
|
|
||||||
while ((int)ft_strlen(str) < fmt->width)
|
|
||||||
ft_strcatf(str, " ");
|
|
||||||
}
|
|
||||||
|
|
@ -1,40 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* lib_pad_sharp.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/11/07 13:33:48 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2016/11/16 17:56:42 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "ft_printf.h"
|
|
||||||
|
|
||||||
void ft_pad_sharp_o(char *str, t_fmt *fmt)
|
|
||||||
{
|
|
||||||
char buf[100];
|
|
||||||
|
|
||||||
(void)fmt;
|
|
||||||
ft_bzero(buf, 100);
|
|
||||||
if (str[0] != '0')
|
|
||||||
ft_strcatf(buf, "0");
|
|
||||||
}
|
|
||||||
|
|
||||||
void ft_pad_sharp_xb(char *str, t_fmt *fmt)
|
|
||||||
{
|
|
||||||
char buf[100];
|
|
||||||
int i;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
ft_bzero(buf, 100);
|
|
||||||
ft_strcpy(buf, "0");
|
|
||||||
ft_strcat(buf, &fmt->conversion);
|
|
||||||
if (*str == '0')
|
|
||||||
i++;
|
|
||||||
if (*str == '0')
|
|
||||||
i++;
|
|
||||||
ft_strcat(buf, str + i);
|
|
||||||
ft_strcpy(str, buf);
|
|
||||||
}
|
|
||||||
|
|
@ -1,79 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* get_next_line.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/11/15 13:12:06 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2016/11/17 13:12:08 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "get_next_line.h"
|
|
||||||
|
|
||||||
static int ft_fdcmp(t_save *a, int *b)
|
|
||||||
{
|
|
||||||
return (a->fd - *b);
|
|
||||||
}
|
|
||||||
|
|
||||||
static t_list *ft_newfd(t_list **head, int fd)
|
|
||||||
{
|
|
||||||
t_save new;
|
|
||||||
|
|
||||||
new.fd = fd;
|
|
||||||
new.str = ft_memalloc((BUFF_SIZE > 0 ? BUFF_SIZE : 0) + 1);
|
|
||||||
ft_lstadd(head, ft_lstnew(&new, sizeof(t_save)));
|
|
||||||
return (*head);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int ft_loop_read(int fd, char **line, char *save)
|
|
||||||
{
|
|
||||||
char buf[BUFF_SIZE + 1];
|
|
||||||
char *pos;
|
|
||||||
char *tmp;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
while ((ret = read(fd, buf, BUFF_SIZE)) > 0)
|
|
||||||
{
|
|
||||||
buf[ret] = 0;
|
|
||||||
tmp = *line;
|
|
||||||
if ((pos = ft_strchr(buf, '\n')))
|
|
||||||
{
|
|
||||||
ft_strcpy(save, pos + 1);
|
|
||||||
*pos = 0;
|
|
||||||
}
|
|
||||||
if (!(*line = ft_strjoin(*line, buf)))
|
|
||||||
return (-1);
|
|
||||||
ft_strdel(&tmp);
|
|
||||||
if (pos)
|
|
||||||
return (1);
|
|
||||||
}
|
|
||||||
if (ret < 0)
|
|
||||||
return (-1);
|
|
||||||
return (**line ? 1 : 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
int get_next_line(int const fd, char **line)
|
|
||||||
{
|
|
||||||
static t_list *head;
|
|
||||||
t_list *tmp;
|
|
||||||
char *pos;
|
|
||||||
char *save;
|
|
||||||
|
|
||||||
if (fd < 0 || !line)
|
|
||||||
return (-1);
|
|
||||||
if (!(tmp = ft_lst_find(head, (void *)&fd, &ft_fdcmp)))
|
|
||||||
tmp = ft_newfd(&head, fd);
|
|
||||||
save = ((t_save*)tmp->content)->str;
|
|
||||||
if (!(*line = ft_strdup(save)))
|
|
||||||
return (-1);
|
|
||||||
ft_bzero(save, BUFF_SIZE + 1);
|
|
||||||
if ((pos = ft_strchr(*line, '\n')))
|
|
||||||
{
|
|
||||||
ft_strcpy(save, pos + 1);
|
|
||||||
*pos = 0;
|
|
||||||
return (1);
|
|
||||||
}
|
|
||||||
return (ft_loop_read(fd, line, save));
|
|
||||||
}
|
|
||||||
|
|
@ -1,18 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_id.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/11/04 11:08:55 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2016/11/04 11:10:25 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
t_list *ft_id(t_list *a)
|
|
||||||
{
|
|
||||||
return (a);
|
|
||||||
}
|
|
||||||
|
|
@ -1,20 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_lst_cfree.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/11/04 11:09:10 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2016/11/08 11:09:49 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void ft_lst_cfree(void *ptr, size_t size)
|
|
||||||
{
|
|
||||||
(void)size;
|
|
||||||
if (ptr)
|
|
||||||
free(ptr);
|
|
||||||
}
|
|
||||||
|
|
@ -1,36 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_lst_delif.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/11/04 11:09:12 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2016/11/21 14:22:51 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void ft_lst_delif(
|
|
||||||
t_list **alst,
|
|
||||||
void *data_ref,
|
|
||||||
int (*cmp)(),
|
|
||||||
void (*del)(void *, size_t))
|
|
||||||
{
|
|
||||||
t_list *tmp;
|
|
||||||
t_list **indirect;
|
|
||||||
|
|
||||||
indirect = alst;
|
|
||||||
while (*indirect)
|
|
||||||
{
|
|
||||||
if ((*cmp)((*indirect)->content, data_ref) == 0)
|
|
||||||
{
|
|
||||||
tmp = (*indirect);
|
|
||||||
(*indirect) = (*indirect)->next;
|
|
||||||
ft_lstdelone(&tmp, del);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
indirect = &(*indirect)->next;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,36 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_lst_delsub.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/11/04 11:09:15 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2016/11/08 13:36:17 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void ft_lst_delsub(
|
|
||||||
t_list **alst,
|
|
||||||
t_list *sub,
|
|
||||||
int (*cmp)(),
|
|
||||||
void (*del)(void *, size_t))
|
|
||||||
{
|
|
||||||
t_list *tmp;
|
|
||||||
t_list **indirect;
|
|
||||||
|
|
||||||
indirect = alst;
|
|
||||||
while (*indirect)
|
|
||||||
{
|
|
||||||
if ((*cmp)((*indirect)->content, sub->content) == 0)
|
|
||||||
{
|
|
||||||
tmp = *indirect;
|
|
||||||
(*indirect) = (*indirect)->next;
|
|
||||||
ft_lstdelone(&tmp, del);
|
|
||||||
sub = sub->next;
|
|
||||||
}
|
|
||||||
indirect = &(*indirect)->next;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,32 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_lst_filter.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/11/04 11:09:17 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2016/11/21 12:36:08 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
t_list *ft_lst_filter(
|
|
||||||
t_list *lst,
|
|
||||||
void const *data_ref,
|
|
||||||
t_list *(*f)(t_list *elem, void const *))
|
|
||||||
{
|
|
||||||
t_list *out;
|
|
||||||
t_list *elem;
|
|
||||||
|
|
||||||
out = NULL;
|
|
||||||
while (lst)
|
|
||||||
{
|
|
||||||
elem = (*f)(lst, data_ref);
|
|
||||||
elem = ft_lstnew(elem->content, elem->content_size);
|
|
||||||
ft_lsteadd(&out, elem);
|
|
||||||
lst = lst->next;
|
|
||||||
}
|
|
||||||
return (out);
|
|
||||||
}
|
|
||||||
|
|
@ -1,27 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_lst_find.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/11/04 11:09:20 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2016/11/04 11:09:20 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
t_list *ft_lst_find(t_list *begin_list, void *data_ref, int (*cmp)())
|
|
||||||
{
|
|
||||||
t_list *list_ptr;
|
|
||||||
|
|
||||||
list_ptr = begin_list;
|
|
||||||
while (list_ptr)
|
|
||||||
{
|
|
||||||
if ((*cmp)(list_ptr->content, data_ref) == 0)
|
|
||||||
return (list_ptr);
|
|
||||||
list_ptr = list_ptr->next;
|
|
||||||
}
|
|
||||||
return (list_ptr);
|
|
||||||
}
|
|
||||||
|
|
@ -1,28 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_list_merge.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/08/14 13:50:32 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2016/11/04 11:09:24 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void ft_lst_merge(t_list **begin_list1, t_list *begin_list2)
|
|
||||||
{
|
|
||||||
t_list *list_ptr;
|
|
||||||
|
|
||||||
if (*begin_list1)
|
|
||||||
{
|
|
||||||
list_ptr = *begin_list1;
|
|
||||||
while (list_ptr->next)
|
|
||||||
list_ptr = list_ptr->next;
|
|
||||||
list_ptr->next = begin_list2;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
*begin_list1 = begin_list2;
|
|
||||||
}
|
|
||||||
|
|
@ -1,41 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_lst_order_delsub.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/11/04 11:09:25 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2016/11/04 12:01:47 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void ft_lst_order_delsub(
|
|
||||||
t_list **alst,
|
|
||||||
t_list *sub,
|
|
||||||
int (*cmp)(),
|
|
||||||
void (*del)(void *, size_t))
|
|
||||||
{
|
|
||||||
t_list *tmp;
|
|
||||||
t_list **indirect;
|
|
||||||
|
|
||||||
indirect = alst;
|
|
||||||
while (*indirect)
|
|
||||||
{
|
|
||||||
if ((*cmp)((*indirect)->content, sub->content) > 0)
|
|
||||||
{
|
|
||||||
sub = sub->next;
|
|
||||||
continue ;
|
|
||||||
}
|
|
||||||
if ((*cmp)((*indirect)->content, sub->content) == 0)
|
|
||||||
{
|
|
||||||
tmp = *indirect;
|
|
||||||
(*indirect) = (*indirect)->next;
|
|
||||||
ft_lstdelone(&tmp, del);
|
|
||||||
sub = sub->next;
|
|
||||||
}
|
|
||||||
indirect = &(*indirect)->next;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,25 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_lst_print.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/11/04 11:09:27 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2016/11/04 11:09:28 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void ft_lst_print(t_list *list, void (*printer)())
|
|
||||||
{
|
|
||||||
while (list)
|
|
||||||
{
|
|
||||||
ft_putstr("[");
|
|
||||||
(*printer)(list->content);
|
|
||||||
ft_putstr("]->");
|
|
||||||
list = list->next;
|
|
||||||
}
|
|
||||||
ft_putendl("X\n");
|
|
||||||
}
|
|
||||||
|
|
@ -1,37 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_lst_print2.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/11/04 11:09:29 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2016/11/04 11:09:29 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void ft_lst_print2(t_list *list, void (*printer)())
|
|
||||||
{
|
|
||||||
t_list *list2;
|
|
||||||
|
|
||||||
while (list)
|
|
||||||
{
|
|
||||||
ft_putendl("---");
|
|
||||||
list2 = *(t_list**)list->content;
|
|
||||||
while (list2)
|
|
||||||
{
|
|
||||||
ft_putstr("[");
|
|
||||||
(*printer)(*(int *)list2->content);
|
|
||||||
ft_putstr("]->");
|
|
||||||
list2 = list2->next;
|
|
||||||
}
|
|
||||||
ft_putendl("X");
|
|
||||||
ft_putendl("---");
|
|
||||||
ft_putendl(" |");
|
|
||||||
ft_putendl(" V");
|
|
||||||
list = list->next;
|
|
||||||
}
|
|
||||||
ft_putendl(" X\n");
|
|
||||||
}
|
|
||||||
|
|
@ -1,33 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_lst_removeif.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/11/04 11:09:30 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2016/11/16 14:00:07 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
t_list *ft_lst_removeif(t_list **alst, void *data_ref, int (*cmp)())
|
|
||||||
{
|
|
||||||
t_list *tmp;
|
|
||||||
t_list **indirect;
|
|
||||||
|
|
||||||
indirect = alst;
|
|
||||||
while (*indirect)
|
|
||||||
{
|
|
||||||
if ((*cmp)((*indirect)->content, data_ref) == 0)
|
|
||||||
{
|
|
||||||
tmp = (*indirect);
|
|
||||||
(*indirect) = (*indirect)->next;
|
|
||||||
tmp->next = NULL;
|
|
||||||
return (tmp);
|
|
||||||
}
|
|
||||||
indirect = &(*indirect)->next;
|
|
||||||
}
|
|
||||||
return (NULL);
|
|
||||||
}
|
|
||||||
|
|
@ -1,29 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_list_reverse.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/08/14 13:20:13 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2016/11/04 11:09:34 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void ft_lst_reverse(t_list **begin_list)
|
|
||||||
{
|
|
||||||
t_list *new_start;
|
|
||||||
t_list *tmp;
|
|
||||||
|
|
||||||
new_start = NULL;
|
|
||||||
while (*begin_list)
|
|
||||||
{
|
|
||||||
tmp = (*begin_list)->next;
|
|
||||||
(*begin_list)->next = new_start;
|
|
||||||
new_start = *begin_list;
|
|
||||||
*begin_list = tmp;
|
|
||||||
}
|
|
||||||
*begin_list = new_start;
|
|
||||||
}
|
|
||||||
|
|
@ -1,30 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_lst_size.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/11/04 11:09:35 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2016/11/04 11:09:36 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
int ft_lstsize(t_list *lst)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
if (lst)
|
|
||||||
{
|
|
||||||
i = 1;
|
|
||||||
while (lst->next)
|
|
||||||
{
|
|
||||||
lst = lst->next;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return (i);
|
|
||||||
}
|
|
||||||
|
|
@ -1,39 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_lst_sorted_insert.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/11/04 11:09:39 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2016/11/04 11:09:39 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void ft_lst_sorted_insert(t_list **begin_list, t_list *insert, int (*cmp)())
|
|
||||||
{
|
|
||||||
t_list *link;
|
|
||||||
|
|
||||||
link = *begin_list;
|
|
||||||
if (!link || (*cmp)(insert->content, link->content) < 0)
|
|
||||||
{
|
|
||||||
*begin_list = insert;
|
|
||||||
insert->next = link ? link : NULL;
|
|
||||||
return ;
|
|
||||||
}
|
|
||||||
while (link->next)
|
|
||||||
{
|
|
||||||
if ((*cmp)(insert->content, link->content) > 0
|
|
||||||
&& (*cmp)(insert->content, link->next->content) <= 0)
|
|
||||||
{
|
|
||||||
insert->next = link->next;
|
|
||||||
link->next = insert;
|
|
||||||
return ;
|
|
||||||
}
|
|
||||||
link = link->next;
|
|
||||||
}
|
|
||||||
link->next = insert;
|
|
||||||
insert->next = NULL;
|
|
||||||
}
|
|
||||||
|
|
@ -1,44 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_lst_sorted_merge.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/11/04 11:09:40 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2016/11/04 11:09:40 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void ft_lst_sorted_merge(
|
|
||||||
t_list **begin_list1,
|
|
||||||
t_list *begin_list2,
|
|
||||||
int (*cmp)())
|
|
||||||
{
|
|
||||||
t_list *tail;
|
|
||||||
t_list *head1;
|
|
||||||
t_list *head2;
|
|
||||||
int comp;
|
|
||||||
|
|
||||||
if (!*begin_list1 || !begin_list2)
|
|
||||||
{
|
|
||||||
*begin_list1 = begin_list2 ? begin_list2 : *begin_list1;
|
|
||||||
return ;
|
|
||||||
}
|
|
||||||
comp = (*cmp)(begin_list2->content, (*begin_list1)->content);
|
|
||||||
head1 = (comp < 0) ? *begin_list1 : (*begin_list1)->next;
|
|
||||||
head2 = (comp < 0) ? begin_list2->next : begin_list2;
|
|
||||||
*begin_list1 = (comp < 0) ? begin_list2 : *begin_list1;
|
|
||||||
tail = *begin_list1;
|
|
||||||
while (head1 && head2)
|
|
||||||
{
|
|
||||||
comp = (*cmp)(head2->content, head1->content);
|
|
||||||
tail->next = (comp < 0 ? head2 : head1);
|
|
||||||
head1 = comp < 0 ? head1 : head1->next;
|
|
||||||
head2 = comp < 0 ? head2->next : head2;
|
|
||||||
tail = tail->next;
|
|
||||||
}
|
|
||||||
tail->next = head2 ? head2 : head1;
|
|
||||||
}
|
|
||||||
|
|
@ -1,22 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_lstadd.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/11/03 14:57:13 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2016/11/04 11:09:44 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void ft_lstadd(t_list **alst, t_list *new)
|
|
||||||
{
|
|
||||||
if (new)
|
|
||||||
{
|
|
||||||
new->next = *alst;
|
|
||||||
*alst = new;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,23 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_lstdel.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/11/03 15:18:57 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2016/11/21 14:02:16 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void ft_lstdel(t_list **alst, void (*del)(void *, size_t))
|
|
||||||
{
|
|
||||||
if (alst && *alst && del)
|
|
||||||
{
|
|
||||||
ft_lstdel(&(*alst)->next, del);
|
|
||||||
ft_lstdelone(alst, del);
|
|
||||||
*alst = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,24 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_lstdelone.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/11/03 14:57:15 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2016/11/21 14:02:31 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void ft_lstdelone(t_list **alst, void (*del)(void *, size_t))
|
|
||||||
{
|
|
||||||
if (alst && *alst)
|
|
||||||
{
|
|
||||||
if (del)
|
|
||||||
(*del)((*alst)->content, (*alst)->content_size);
|
|
||||||
free(*alst);
|
|
||||||
*alst = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,28 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_lsteadd.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/11/03 14:57:17 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2016/11/04 13:11:05 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void ft_lsteadd(t_list **alst, t_list *new)
|
|
||||||
{
|
|
||||||
t_list *lst;
|
|
||||||
|
|
||||||
lst = *alst;
|
|
||||||
if (lst)
|
|
||||||
{
|
|
||||||
while (lst->next)
|
|
||||||
lst = lst->next;
|
|
||||||
lst->next = new;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
*alst = new;
|
|
||||||
}
|
|
||||||
|
|
@ -1,22 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_lstiter.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/11/03 14:57:19 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2016/11/03 14:57:19 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void ft_lstiter(t_list *lst, void (*f)(t_list *elem))
|
|
||||||
{
|
|
||||||
while (lst)
|
|
||||||
{
|
|
||||||
(*f)(lst);
|
|
||||||
lst = lst->next;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,21 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_lstlast.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/11/04 11:09:48 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2016/11/04 11:09:49 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
t_list *ft_lstlast(t_list *lst)
|
|
||||||
{
|
|
||||||
if (lst)
|
|
||||||
while (lst->next)
|
|
||||||
lst = lst->next;
|
|
||||||
return (lst);
|
|
||||||
}
|
|
||||||
|
|
@ -1,29 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_lstmap.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/11/03 14:57:21 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2016/11/04 13:11:19 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
t_list *ft_lstmap(t_list *lst, t_list *(*f)(t_list *elem))
|
|
||||||
{
|
|
||||||
t_list *out;
|
|
||||||
t_list *elem;
|
|
||||||
|
|
||||||
out = NULL;
|
|
||||||
while (lst)
|
|
||||||
{
|
|
||||||
elem = (*f)(lst);
|
|
||||||
elem = ft_lstnew(elem->content, elem->content_size);
|
|
||||||
ft_lsteadd(&out, elem);
|
|
||||||
lst = lst->next;
|
|
||||||
}
|
|
||||||
return (out);
|
|
||||||
}
|
|
||||||
|
|
@ -1,35 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_lstnadd.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/11/04 11:09:51 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2016/11/04 11:09:52 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void ft_lstnadd(t_list **alst, t_list *new, int n)
|
|
||||||
{
|
|
||||||
t_list *lst;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
lst = *alst;
|
|
||||||
if (lst)
|
|
||||||
{
|
|
||||||
i = 0;
|
|
||||||
while (lst->next && i < n)
|
|
||||||
{
|
|
||||||
lst = lst->next;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
while (lst->next)
|
|
||||||
lst = lst->next;
|
|
||||||
lst->next = new;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
*alst = new;
|
|
||||||
}
|
|
||||||
|
|
@ -1,34 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_lstnew.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/11/03 14:57:24 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2016/11/03 14:57:24 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
t_list *ft_lstnew(void const *content, size_t content_size)
|
|
||||||
{
|
|
||||||
t_list *new;
|
|
||||||
|
|
||||||
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);
|
|
||||||
ft_memcpy(new->content, content, content_size);
|
|
||||||
}
|
|
||||||
return (new);
|
|
||||||
}
|
|
||||||
|
|
@ -1,28 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_lstnew_range.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/11/04 11:09:54 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2016/11/04 11:09:54 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
t_list *ft_lstnew_range(int a, int b)
|
|
||||||
{
|
|
||||||
t_list *lst;
|
|
||||||
|
|
||||||
if (a >= b)
|
|
||||||
return (NULL);
|
|
||||||
lst = NULL;
|
|
||||||
while (a < b)
|
|
||||||
{
|
|
||||||
b--;
|
|
||||||
ft_lstadd(&lst, ft_lstnew(&b, sizeof(int)));
|
|
||||||
}
|
|
||||||
return (lst);
|
|
||||||
}
|
|
||||||
|
|
@ -1,23 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_lstpop.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/11/04 11:09:56 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2016/11/04 11:09:56 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
t_list *ft_lstpop(t_list **lst)
|
|
||||||
{
|
|
||||||
t_list *top;
|
|
||||||
|
|
||||||
top = *lst;
|
|
||||||
if (*lst)
|
|
||||||
*lst = (*lst)->next;
|
|
||||||
return (top);
|
|
||||||
}
|
|
||||||
|
|
@ -1,38 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_lstsort.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/11/04 11:09:58 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2016/11/23 15:43:48 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void ft_lstsort(t_list **begin_list, int (*cmp)())
|
|
||||||
{
|
|
||||||
t_list **indirect;
|
|
||||||
t_list *tmp;
|
|
||||||
t_list *tmp2;
|
|
||||||
|
|
||||||
indirect = begin_list;
|
|
||||||
if (!*begin_list)
|
|
||||||
return ;
|
|
||||||
while (*indirect && (*indirect)->next)
|
|
||||||
{
|
|
||||||
if ((*cmp)((*indirect)->content, (*indirect)->next->content) > 0)
|
|
||||||
{
|
|
||||||
tmp = *indirect;
|
|
||||||
tmp2 = (*indirect)->next;
|
|
||||||
(*indirect)->next = (*indirect)->next->next;
|
|
||||||
*indirect = tmp2;
|
|
||||||
(*indirect)->next = tmp;
|
|
||||||
indirect = begin_list;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
indirect = &(*indirect)->next;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,18 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* 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);
|
|
||||||
}
|
|
||||||
|
|
@ -1,23 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_ilen.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/11/07 13:53:53 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2016/11/07 14:44:35 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
size_t ft_ilen(int n)
|
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
i = 1;
|
|
||||||
while (n /= 10)
|
|
||||||
i++;
|
|
||||||
return (i);
|
|
||||||
}
|
|
||||||
|
|
@ -1,23 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_ilen_base.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/11/07 13:53:53 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2016/11/07 14:45:28 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
size_t ft_ilen_base(int n, int base)
|
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
i = 1;
|
|
||||||
while (n /= base)
|
|
||||||
i++;
|
|
||||||
return (i);
|
|
||||||
}
|
|
||||||
|
|
@ -1,49 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_itoa.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/11/03 14:57:10 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2016/11/04 13:11:28 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
static size_t ft_size(int n)
|
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
i = 1;
|
|
||||||
while (n /= 10)
|
|
||||||
i++;
|
|
||||||
return (i);
|
|
||||||
}
|
|
||||||
|
|
||||||
char *ft_itoa(int n)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
char *str;
|
|
||||||
int neg;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
str = ft_strnew(ft_size(n) + 1);
|
|
||||||
neg = FT_NEG(n) ? 1 : 0;
|
|
||||||
if (n == 0)
|
|
||||||
{
|
|
||||||
str[i++] = '0';
|
|
||||||
str[i] = '\0';
|
|
||||||
return (str);
|
|
||||||
}
|
|
||||||
while (n)
|
|
||||||
{
|
|
||||||
str[i++] = FT_ABS(n % 10) + '0';
|
|
||||||
n /= 10;
|
|
||||||
}
|
|
||||||
if (neg)
|
|
||||||
str[i++] = '-';
|
|
||||||
str[i] = '\0';
|
|
||||||
return (ft_strrev(str));
|
|
||||||
}
|
|
||||||
|
|
@ -1,51 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_itoa_base.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/11/07 13:52:51 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2016/11/07 14:45:15 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
static char *ft_flags(char *str, int *i, char *flags, int neg)
|
|
||||||
{
|
|
||||||
if (neg)
|
|
||||||
str[*i++] = '-';
|
|
||||||
else if (ft_strchr(flags, '+'))
|
|
||||||
str[*i++] = '+';
|
|
||||||
else if (ft_strchr(flags, ' '))
|
|
||||||
str[*i++] = ' ';
|
|
||||||
return (str);
|
|
||||||
}
|
|
||||||
|
|
||||||
char *ft_itoa_base(int nbr, char *base, char *flags)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
int neg;
|
|
||||||
int base_size;
|
|
||||||
char *str;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
base_size = ft_strlen(base);
|
|
||||||
str = ft_strnew(ft_ilen_base(nbr, base_size) + 1);
|
|
||||||
neg = FT_NEG(nbr);
|
|
||||||
if (nbr == 0)
|
|
||||||
{
|
|
||||||
str[i++] = '0';
|
|
||||||
str[i] = '\0';
|
|
||||||
return (str);
|
|
||||||
}
|
|
||||||
while (nbr)
|
|
||||||
{
|
|
||||||
str[i++] = base[FT_ABS(nbr % base_size)];
|
|
||||||
nbr = nbr / base_size;
|
|
||||||
}
|
|
||||||
str = ft_flags(str, &i, flags, neg);
|
|
||||||
str[i] = '\0';
|
|
||||||
return (ft_strrev(str));
|
|
||||||
}
|
|
||||||
|
|
@ -1,23 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_lllen.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/11/07 13:52:35 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2016/11/07 14:45:40 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
size_t ft_lllen(long long n)
|
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
i = 1;
|
|
||||||
while (n /= 10)
|
|
||||||
i++;
|
|
||||||
return (i);
|
|
||||||
}
|
|
||||||
|
|
@ -1,23 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_lllen_base.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/11/07 13:52:35 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2016/11/07 14:46:15 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
size_t ft_lllen_base(long long n, int base)
|
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
i = 1;
|
|
||||||
while (n /= base)
|
|
||||||
i++;
|
|
||||||
return (i);
|
|
||||||
}
|
|
||||||
|
|
@ -1,52 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_lltoa_base.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/11/07 13:10:42 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2016/11/07 16:30:42 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
static char *ft_flags(char *str, int *i, char *flags, int neg)
|
|
||||||
{
|
|
||||||
if (neg)
|
|
||||||
str[*i++] = '-';
|
|
||||||
else if (ft_strchr(flags, '+'))
|
|
||||||
str[*i++] = '+';
|
|
||||||
else if (ft_strchr(flags, ' '))
|
|
||||||
str[*i++] = ' ';
|
|
||||||
return (str);
|
|
||||||
}
|
|
||||||
|
|
||||||
char *ft_lltoa_base(long long nbr, char *base, char *flags)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
int neg;
|
|
||||||
int base_size;
|
|
||||||
char *str;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
base_size = ft_strlen(base);
|
|
||||||
str = ft_strnew(ft_lllen_base(nbr, base_size) + 1);
|
|
||||||
neg = FT_NEG(nbr);
|
|
||||||
if (nbr == 0)
|
|
||||||
{
|
|
||||||
str[i++] = '0';
|
|
||||||
str[i] = '\0';
|
|
||||||
return (str);
|
|
||||||
}
|
|
||||||
while (nbr)
|
|
||||||
{
|
|
||||||
str[i++] = base[FT_ABS(nbr % base_size)];
|
|
||||||
nbr = nbr / base_size;
|
|
||||||
}
|
|
||||||
str = ft_flags(str, &i, flags, neg);
|
|
||||||
str[i] = '\0';
|
|
||||||
ft_strrev(str);
|
|
||||||
return (str);
|
|
||||||
}
|
|
||||||
|
|
@ -1,23 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_uilen.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/11/07 13:52:35 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2016/11/07 13:54:41 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
size_t ft_uilen(unsigned int n)
|
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
i = 1;
|
|
||||||
while (n /= 10)
|
|
||||||
i++;
|
|
||||||
return (i);
|
|
||||||
}
|
|
||||||
|
|
@ -1,47 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_uitoa_base.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/11/07 13:08:10 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2016/11/07 13:10:35 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
static size_t ft_size(unsigned int n, int base)
|
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
i = 1;
|
|
||||||
while (n /= base)
|
|
||||||
i++;
|
|
||||||
return (i);
|
|
||||||
}
|
|
||||||
|
|
||||||
char *ft_uitoa_base(unsigned int nbr, char *base)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
int base_size;
|
|
||||||
char *str;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
base_size = ft_strlen(base);
|
|
||||||
str = ft_strnew(ft_size(nbr, base_size) + 1);
|
|
||||||
if (nbr == 0)
|
|
||||||
{
|
|
||||||
str[i++] = '0';
|
|
||||||
str[i] = '\0';
|
|
||||||
return (str);
|
|
||||||
}
|
|
||||||
while (nbr)
|
|
||||||
{
|
|
||||||
str[i++] = base[nbr % base_size];
|
|
||||||
nbr = nbr / base_size;
|
|
||||||
}
|
|
||||||
str[i] = '\0';
|
|
||||||
return (ft_strrev(str));
|
|
||||||
}
|
|
||||||
|
|
@ -1,47 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_ulltoa_base.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/11/07 13:07:50 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2016/11/07 13:12:41 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
static size_t ft_size(unsigned long long n, int base)
|
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
i = 1;
|
|
||||||
while (n /= base)
|
|
||||||
i++;
|
|
||||||
return (i);
|
|
||||||
}
|
|
||||||
|
|
||||||
char *ft_ulltoa_base(unsigned long long nbr, char *base)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
int base_size;
|
|
||||||
char *str;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
base_size = ft_strlen(base);
|
|
||||||
str = ft_strnew(ft_size(nbr, base_size) + 1);
|
|
||||||
if (nbr == 0)
|
|
||||||
{
|
|
||||||
str[i++] = '0';
|
|
||||||
str[i] = '\0';
|
|
||||||
return (str);
|
|
||||||
}
|
|
||||||
while (nbr)
|
|
||||||
{
|
|
||||||
str[i++] = base[nbr % base_size];
|
|
||||||
nbr = nbr / base_size;
|
|
||||||
}
|
|
||||||
str[i] = '\0';
|
|
||||||
return (ft_strrev(str));
|
|
||||||
}
|
|
||||||
|
|
@ -1,22 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_bzero.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/11/03 14:56:08 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2016/11/03 14:56:09 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void ft_bzero(void *s, size_t n)
|
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
i = -1;
|
|
||||||
while (++i < n)
|
|
||||||
*(char *)s++ = 0;
|
|
||||||
}
|
|
||||||
|
|
@ -1,27 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_memalloc.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/11/03 14:57:25 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2016/11/11 17:40:57 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void *ft_memalloc(size_t size)
|
|
||||||
{
|
|
||||||
void *addr;
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
addr = malloc(size);
|
|
||||||
if (addr == NULL)
|
|
||||||
return (NULL);
|
|
||||||
i = -1;
|
|
||||||
while (++i < size)
|
|
||||||
((char *)addr)[i] = 0;
|
|
||||||
return (addr);
|
|
||||||
}
|
|
||||||
|
|
@ -1,27 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_memccpy.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/11/03 14:57:26 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2016/11/03 15:36:05 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void *ft_memccpy(void *dst, const void *src, int c, size_t n)
|
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
i = -1;
|
|
||||||
while (++i < n)
|
|
||||||
{
|
|
||||||
*(char *)dst++ = *(char *)src;
|
|
||||||
if (*(char *)src++ == c)
|
|
||||||
return (dst);
|
|
||||||
}
|
|
||||||
return (NULL);
|
|
||||||
}
|
|
||||||
|
|
@ -1,29 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_memchr.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/11/03 14:57:28 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2016/11/11 17:41:21 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void *ft_memchr(const void *s, int c, size_t n)
|
|
||||||
{
|
|
||||||
void *a;
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
i = -1;
|
|
||||||
a = (unsigned char *)s;
|
|
||||||
while (++i < n)
|
|
||||||
{
|
|
||||||
if (*(unsigned char *)a == (unsigned char)c)
|
|
||||||
return (a);
|
|
||||||
a++;
|
|
||||||
}
|
|
||||||
return (NULL);
|
|
||||||
}
|
|
||||||
|
|
@ -1,28 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_memcmp.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/11/03 14:57:30 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2016/11/03 15:44:21 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
int ft_memcmp(const void *s1, const void *s2, size_t n)
|
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
int cmp;
|
|
||||||
|
|
||||||
i = -1;
|
|
||||||
while (++i < n)
|
|
||||||
{
|
|
||||||
cmp = *(unsigned char *)s1++ - *(unsigned char *)s2++;
|
|
||||||
if (cmp)
|
|
||||||
return (cmp);
|
|
||||||
}
|
|
||||||
return (cmp);
|
|
||||||
}
|
|
||||||
|
|
@ -1,28 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_memcpy.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/11/03 14:57:31 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2016/11/11 17:39:00 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void *ft_memcpy(void *dst, const void *src, size_t n)
|
|
||||||
{
|
|
||||||
char *c1;
|
|
||||||
char *c2;
|
|
||||||
|
|
||||||
if (n == 0 || dst == src)
|
|
||||||
return (dst);
|
|
||||||
c1 = (char *)dst;
|
|
||||||
c2 = (char *)src;
|
|
||||||
while (--n)
|
|
||||||
*c1++ = *c2++;
|
|
||||||
*c1 = *c2;
|
|
||||||
return (dst);
|
|
||||||
}
|
|
||||||
|
|
@ -1,22 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_memdel.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/11/03 14:57:33 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2016/11/16 12:23:13 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void ft_memdel(void **ap)
|
|
||||||
{
|
|
||||||
if (ap && *ap)
|
|
||||||
{
|
|
||||||
free(*ap);
|
|
||||||
*ap = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,31 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_memmove.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/11/03 14:57:34 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2016/11/11 17:41:14 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void *ft_memmove(void *dst, const void *src, size_t len)
|
|
||||||
{
|
|
||||||
char *srcc;
|
|
||||||
char *dstc;
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
i = -1;
|
|
||||||
srcc = (char *)src;
|
|
||||||
dstc = (char *)dst;
|
|
||||||
if (srcc < dstc)
|
|
||||||
while ((int)(--len) >= 0)
|
|
||||||
*(dstc + len) = *(srcc + len);
|
|
||||||
else
|
|
||||||
while (++i < len)
|
|
||||||
*(dstc + i) = *(srcc + i);
|
|
||||||
return (dst);
|
|
||||||
}
|
|
||||||
|
|
@ -1,23 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_memset.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/11/03 14:57:36 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2016/11/03 14:57:36 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void *ft_memset(void *b, int c, size_t len)
|
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
i = -1;
|
|
||||||
while (++i < len)
|
|
||||||
((unsigned char *)b)[i] = (unsigned char)c;
|
|
||||||
return (b);
|
|
||||||
}
|
|
||||||
|
|
@ -1,23 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_realloc.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/11/11 17:37:53 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2016/11/16 17:56:17 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void *ft_realloc(void *data, int size)
|
|
||||||
{
|
|
||||||
void *new;
|
|
||||||
|
|
||||||
new = ft_memalloc(size);
|
|
||||||
ft_memcpy(new, data, ft_strlen(data));
|
|
||||||
ft_memdel(&data);
|
|
||||||
return (new);
|
|
||||||
}
|
|
||||||
|
|
@ -1,21 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_debug.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/11/04 11:45:16 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2016/11/07 15:43:41 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void ft_debug(void)
|
|
||||||
{
|
|
||||||
static int n = 0;
|
|
||||||
|
|
||||||
n++;
|
|
||||||
ft_printf("----------\n check %02i\n----------\n", n);
|
|
||||||
}
|
|
||||||
|
|
@ -1,24 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_path_notdir.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/11/04 11:45:07 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2016/11/23 15:46:28 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
char *ft_path_notdir(char *path)
|
|
||||||
{
|
|
||||||
char *slash;
|
|
||||||
char *ret;
|
|
||||||
|
|
||||||
ret = path;
|
|
||||||
if ((slash = ft_strrchr(path, '/')) && slash != path)
|
|
||||||
ret = slash + 1;
|
|
||||||
return (ret);
|
|
||||||
}
|
|
||||||
|
|
@ -1,18 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_putaddr.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/11/21 15:13:34 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2016/11/21 15:13:35 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void ft_putaddr(void *a)
|
|
||||||
{
|
|
||||||
ft_printf("%p", a);
|
|
||||||
}
|
|
||||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue