summaryrefslogtreecommitdiffstats
path: root/libft
diff options
context:
space:
mode:
Diffstat (limited to 'libft')
-rw-r--r--libft/Makefile253
-rw-r--r--libft/inc/libft.h158
-rw-r--r--libft/src/ft_atoi.c19
-rw-r--r--libft/src/ft_bzero.c19
-rw-r--r--libft/src/ft_calloc.c19
-rw-r--r--libft/src/ft_dprintf.c56
-rw-r--r--libft/src/ft_intlen.c21
-rw-r--r--libft/src/ft_intlen_base.c21
-rw-r--r--libft/src/ft_isalnum.c19
-rw-r--r--libft/src/ft_isalpha.c19
-rw-r--r--libft/src/ft_isascii.c19
-rw-r--r--libft/src/ft_ischarset.c19
-rw-r--r--libft/src/ft_isdigit.c19
-rw-r--r--libft/src/ft_isprint.c19
-rw-r--r--libft/src/ft_isspace.c19
-rw-r--r--libft/src/ft_itoa.c27
-rw-r--r--libft/src/ft_itoa_base.c22
-rw-r--r--libft/src/ft_kernel_panic.c21
-rw-r--r--libft/src/ft_lstadd_back.c19
-rw-r--r--libft/src/ft_lstadd_front.c19
-rw-r--r--libft/src/ft_lstclear.c19
-rw-r--r--libft/src/ft_lstdelone.c19
-rw-r--r--libft/src/ft_lstiter.c19
-rw-r--r--libft/src/ft_lstlast.c19
-rw-r--r--libft/src/ft_lstmap.c19
-rw-r--r--libft/src/ft_lstnew.c19
-rw-r--r--libft/src/ft_lstsize.c19
-rw-r--r--libft/src/ft_memccpy.c19
-rw-r--r--libft/src/ft_memchr.c19
-rw-r--r--libft/src/ft_memcmp.c19
-rw-r--r--libft/src/ft_memcpy.c19
-rw-r--r--libft/src/ft_memdel.c20
-rw-r--r--libft/src/ft_memlchr.c19
-rw-r--r--libft/src/ft_memmove.c44
-rw-r--r--libft/src/ft_memset.c19
-rw-r--r--libft/src/ft_nrealloc.c38
-rw-r--r--libft/src/ft_nstr.c19
-rw-r--r--libft/src/ft_printf.c56
-rw-r--r--libft/src/ft_printf_cat_output.c29
-rw-r--r--libft/src/ft_printf_flag_to_atoi.c33
-rw-r--r--libft/src/ft_printf_get_flags.c42
-rw-r--r--libft/src/ft_printf_get_s_putlen.c28
-rw-r--r--libft/src/ft_printf_get_width_nstr.c56
-rw-r--r--libft/src/ft_printf_init_struct.c52
-rw-r--r--libft/src/ft_printf_parts.c42
-rw-r--r--libft/src/ft_printf_process.c45
-rw-r--r--libft/src/ft_printf_put_char.c41
-rw-r--r--libft/src/ft_printf_put_hex.c85
-rw-r--r--libft/src/ft_printf_put_int.c114
-rw-r--r--libft/src/ft_printf_put_none.c20
-rw-r--r--libft/src/ft_printf_put_precision.c66
-rw-r--r--libft/src/ft_printf_put_ptr.c42
-rw-r--r--libft/src/ft_printf_put_str.c39
-rw-r--r--libft/src/ft_printf_put_width.c104
-rw-r--r--libft/src/ft_printf_treat_flags.c146
-rw-r--r--libft/src/ft_printf_use_flags.c67
-rw-r--r--libft/src/ft_putchar.c19
-rw-r--r--libft/src/ft_putchar_fd.c19
-rw-r--r--libft/src/ft_putendl.c19
-rw-r--r--libft/src/ft_putendl_fd.c19
-rw-r--r--libft/src/ft_putnbr.c23
-rw-r--r--libft/src/ft_putnbr_base.c23
-rw-r--r--libft/src/ft_putnbr_fd.c19
-rw-r--r--libft/src/ft_putnchar.c19
-rw-r--r--libft/src/ft_putstr.c19
-rw-r--r--libft/src/ft_putstr_fd.c19
-rw-r--r--libft/src/ft_realloc.c26
-rw-r--r--libft/src/ft_split.c84
-rw-r--r--libft/src/ft_sprintf.c57
-rw-r--r--libft/src/ft_sqrt.c19
-rw-r--r--libft/src/ft_strcat.c19
-rw-r--r--libft/src/ft_strchr.c33
-rw-r--r--libft/src/ft_strcmp.c21
-rw-r--r--libft/src/ft_strdup.c19
-rw-r--r--libft/src/ft_strjoin.c19
-rw-r--r--libft/src/ft_strlcat.c19
-rw-r--r--libft/src/ft_strlchr.c25
-rw-r--r--libft/src/ft_strlcpy.c19
-rw-r--r--libft/src/ft_strlen.c19
-rw-r--r--libft/src/ft_strmapi.c19
-rw-r--r--libft/src/ft_strncmp.c19
-rw-r--r--libft/src/ft_strnlen.c19
-rw-r--r--libft/src/ft_strnstr.c19
-rw-r--r--libft/src/ft_strrchr.c19
-rw-r--r--libft/src/ft_strtrim.c19
-rw-r--r--libft/src/ft_substr.c19
-rw-r--r--libft/src/ft_tolower.c19
-rw-r--r--libft/src/ft_toupper.c19
-rw-r--r--libft/src/ft_uintlen.c29
-rw-r--r--libft/src/ft_uintlen_base.c32
-rw-r--r--libft/src/ft_uitoa.c38
-rw-r--r--libft/src/ft_uitoa_base.c39
-rw-r--r--libft/src/get_next_line.c154
-rw-r--r--libft/src/get_next_line_utils.c118
94 files changed, 2517 insertions, 923 deletions
diff --git a/libft/Makefile b/libft/Makefile
index d5d6e5d..2bd6342 100644
--- a/libft/Makefile
+++ b/libft/Makefile
@@ -1,16 +1,3 @@
-# **************************************************************************** #
-# LE - / #
-# / #
-# Makefile .:: .:/ . .:: #
-# +:+:+ +: +: +:+:+ #
-# By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ #
-# #+# #+ #+ #+# #
-# Created: 2019/12/11 13:14:43 by rbousset #+# ## ## #+# #
-# Updated: 2019/12/11 18:34:05 by rbousset ### #+. /#+ ###.fr #
-# / #
-# / #
-# **************************************************************************** #
-
default: all
#==============================================================================#
#--------------------------------- Shell --------------------------------------#
@@ -27,83 +14,136 @@ OBJS_DIR = obj/
#==============================================================================#
INCS = libft.h
#------------------------------------------------------------------------------#
-OBJS = $(patsubst ${SRCS_DIR}%.c,${OBJS_DIR}%.o,${SRCS})
+SRCS_NAME = ft_memset.c
+SRCS_NAME += ft_bzero.c
+SRCS_NAME += ft_memcpy.c
+SRCS_NAME += ft_memccpy.c
+SRCS_NAME += ft_memmove.c
+SRCS_NAME += ft_memchr.c
+SRCS_NAME += ft_memlchr.c
+SRCS_NAME += ft_memcmp.c
+SRCS_NAME += ft_strlen.c
+SRCS_NAME += ft_isalpha.c
+SRCS_NAME += ft_isdigit.c
+SRCS_NAME += ft_isalnum.c
+SRCS_NAME += ft_isascii.c
+SRCS_NAME += ft_isprint.c
+SRCS_NAME += ft_ischarset.c
+SRCS_NAME += ft_tolower.c
+SRCS_NAME += ft_toupper.c
+SRCS_NAME += ft_strchr.c
+SRCS_NAME += ft_strrchr.c
+SRCS_NAME += ft_strlchr.c
+SRCS_NAME += ft_strncmp.c
+SRCS_NAME += ft_strlcpy.c
+SRCS_NAME += ft_strlcat.c
+SRCS_NAME += ft_strnstr.c
+SRCS_NAME += ft_atoi.c
+SRCS_NAME += ft_calloc.c
+SRCS_NAME += ft_nrealloc.c
+SRCS_NAME += ft_strdup.c
+SRCS_NAME += ft_substr.c
+SRCS_NAME += ft_strjoin.c
+SRCS_NAME += ft_strtrim.c
+SRCS_NAME += ft_split.c
+SRCS_NAME += ft_itoa.c
+SRCS_NAME += ft_itoa_base.c
+SRCS_NAME += ft_uitoa.c
+SRCS_NAME += ft_uitoa_base.c
+SRCS_NAME += ft_strmapi.c
+SRCS_NAME += ft_putchar_fd.c
+SRCS_NAME += ft_putstr_fd.c
+SRCS_NAME += ft_putendl_fd.c
+SRCS_NAME += ft_putnbr_fd.c
+SRCS_NAME += ft_lstnew.c
+SRCS_NAME += ft_lstadd_front.c
+SRCS_NAME += ft_lstsize.c
+SRCS_NAME += ft_lstlast.c
+SRCS_NAME += ft_lstadd_back.c
+SRCS_NAME += ft_lstdelone.c
+SRCS_NAME += ft_lstclear.c
+SRCS_NAME += ft_lstiter.c
+SRCS_NAME += ft_lstmap.c
+SRCS_NAME += ft_putchar.c
+SRCS_NAME += ft_putnchar.c
+SRCS_NAME += ft_putstr.c
+SRCS_NAME += ft_putendl.c
+SRCS_NAME += ft_putnbr.c
+SRCS_NAME += ft_putnbr_base.c
+SRCS_NAME += ft_strnlen.c
+SRCS_NAME += ft_strcat.c
+SRCS_NAME += ft_strcmp.c
+SRCS_NAME += ft_isspace.c
+SRCS_NAME += ft_sqrt.c
+SRCS_NAME += ft_intlen.c
+SRCS_NAME += ft_intlen_base.c
+SRCS_NAME += ft_uintlen.c
+SRCS_NAME += ft_uintlen_base.c
+SRCS_NAME += ft_nstr.c
+SRCS_NAME += ft_memdel.c
+SRCS_NAME += ft_kernel_panic.c
+SRCS_NAME += get_next_line.c
+SRCS_NAME += get_next_line_utils.c
+SRCS_NAME += ft_printf.c
+SRCS_NAME += ft_dprintf.c
+SRCS_NAME += ft_sprintf.c
+SRCS_NAME += ft_printf_init_struct.c
+SRCS_NAME += ft_printf_get_flags.c
+SRCS_NAME += ft_printf_use_flags.c
+SRCS_NAME += ft_printf_get_width_nstr.c
+SRCS_NAME += ft_printf_treat_flags.c
+SRCS_NAME += ft_printf_parts.c
+SRCS_NAME += ft_printf_put_width.c
+SRCS_NAME += ft_printf_put_precision.c
+SRCS_NAME += ft_printf_put_char.c
+SRCS_NAME += ft_printf_put_str.c
+SRCS_NAME += ft_printf_put_ptr.c
+SRCS_NAME += ft_printf_put_int.c
+SRCS_NAME += ft_printf_put_hex.c
+SRCS_NAME += ft_printf_put_none.c
+SRCS_NAME += ft_printf_get_s_putlen.c
+SRCS_NAME += ft_printf_process.c
+SRCS_NAME += ft_printf_cat_output.c
+SRCS_NAME += ft_printf_flag_to_atoi.c
+#------------------------------------------------------------------------------#
+SRCS = $(addprefix ${SRCS_DIR},${SRCS_NAME})
#------------------------------------------------------------------------------#
-SRCS = ${SRCS_DIR}ft_memset.c
-SRCS += ${SRCS_DIR}ft_bzero.c
-SRCS += ${SRCS_DIR}ft_memcpy.c
-SRCS += ${SRCS_DIR}ft_memccpy.c
-SRCS += ${SRCS_DIR}ft_memmove.c
-SRCS += ${SRCS_DIR}ft_memchr.c
-SRCS += ${SRCS_DIR}ft_memlchr.c
-SRCS += ${SRCS_DIR}ft_memcmp.c
-SRCS += ${SRCS_DIR}ft_strlen.c
-SRCS += ${SRCS_DIR}ft_isalpha.c
-SRCS += ${SRCS_DIR}ft_isdigit.c
-SRCS += ${SRCS_DIR}ft_isalnum.c
-SRCS += ${SRCS_DIR}ft_isascii.c
-SRCS += ${SRCS_DIR}ft_isprint.c
-SRCS += ${SRCS_DIR}ft_ischarset.c
-SRCS += ${SRCS_DIR}ft_tolower.c
-SRCS += ${SRCS_DIR}ft_toupper.c
-SRCS += ${SRCS_DIR}ft_strchr.c
-SRCS += ${SRCS_DIR}ft_strrchr.c
-SRCS += ${SRCS_DIR}ft_strncmp.c
-SRCS += ${SRCS_DIR}ft_strlcpy.c
-SRCS += ${SRCS_DIR}ft_strlcat.c
-SRCS += ${SRCS_DIR}ft_strnstr.c
-SRCS += ${SRCS_DIR}ft_atoi.c
-SRCS += ${SRCS_DIR}ft_calloc.c
-SRCS += ${SRCS_DIR}ft_realloc.c
-SRCS += ${SRCS_DIR}ft_strdup.c
-SRCS += ${SRCS_DIR}ft_substr.c
-SRCS += ${SRCS_DIR}ft_strjoin.c
-SRCS += ${SRCS_DIR}ft_strtrim.c
-SRCS += ${SRCS_DIR}ft_split.c
-SRCS += ${SRCS_DIR}ft_itoa.c
-SRCS += ${SRCS_DIR}ft_itoa_base.c
-SRCS += ${SRCS_DIR}ft_strmapi.c
-SRCS += ${SRCS_DIR}ft_putchar_fd.c
-SRCS += ${SRCS_DIR}ft_putstr_fd.c
-SRCS += ${SRCS_DIR}ft_putendl_fd.c
-SRCS += ${SRCS_DIR}ft_putnbr_fd.c
-SRCS += ${SRCS_DIR}ft_lstnew.c
-SRCS += ${SRCS_DIR}ft_lstadd_front.c
-SRCS += ${SRCS_DIR}ft_lstsize.c
-SRCS += ${SRCS_DIR}ft_lstlast.c
-SRCS += ${SRCS_DIR}ft_lstadd_back.c
-SRCS += ${SRCS_DIR}ft_lstdelone.c
-SRCS += ${SRCS_DIR}ft_lstclear.c
-SRCS += ${SRCS_DIR}ft_lstiter.c
-SRCS += ${SRCS_DIR}ft_lstmap.c
-SRCS += ${SRCS_DIR}ft_putchar.c
-SRCS += ${SRCS_DIR}ft_putnchar.c
-SRCS += ${SRCS_DIR}ft_putstr.c
-SRCS += ${SRCS_DIR}ft_putendl.c
-SRCS += ${SRCS_DIR}ft_putnbr.c
-SRCS += ${SRCS_DIR}ft_putnbr_base.c
-SRCS += ${SRCS_DIR}ft_strnlen.c
-SRCS += ${SRCS_DIR}ft_strcat.c
-SRCS += ${SRCS_DIR}ft_strcmp.c
-SRCS += ${SRCS_DIR}ft_isspace.c
-SRCS += ${SRCS_DIR}ft_sqrt.c
-SRCS += ${SRCS_DIR}ft_intlen.c
-SRCS += ${SRCS_DIR}ft_intlen_base.c
-SRCS += ${SRCS_DIR}ft_nstr.c
-SRCS += ${SRCS_DIR}ft_kernel_panic.c
-SRCS += ${SRCS_DIR}get_next_line.c
+OBJS = $(patsubst ${SRCS_DIR}%.c,${OBJS_DIR}%.o,${SRCS})
+#==============================================================================#
+#--------------------------------- UNIX ---------------------------------------#
+#==============================================================================#
+MKDIR = mkdir -p
+RM = rm -rf
+OS = $(shell uname)
#==============================================================================#
#-------------------------------- Compiler ------------------------------------#
#==============================================================================#
-CC = gcc
-CFLAGS = -Wall
+ifeq (${OS}, Linux)
+ DBG = -ggdb
+else
+ DBG = -glldb
+endif
+FSANITIZE = -fsanitize=address
+#------------------------------------------------------------------------------#
+ifeq (${OS}, Linux)
+ CC = gcc
+else
+ CC = clang
+endif
+#------------------------------------------------------------------------------#
+CFLAGS = -std=c89
+CFLAGS += -Wall
CFLAGS += -Wextra
CFLAGS += -Werror
-CFLAGS += ${DEBUG}
-CFLAGS += ${FSANITIZE}
+CFLAGS += -pedantic
+ifdef DEBUG
+ CFLAGS += ${DBG}
+endif
#------------------------------------------------------------------------------#
-DEBUG = -Og -ggdb
-FSANITIZE = -fsanitize=address
+ifdef ASAN
+ CFLAGS += ${DBG}
+ CFLAGS += ${FSANITIZE}
+endif
#------------------------------------------------------------------------------#
NAME = libft.a
#==============================================================================#
@@ -111,22 +151,16 @@ NAME = libft.a
#==============================================================================#
AR = ar rcs
#==============================================================================#
-#--------------------------------- UNIX ---------------------------------------#
-#==============================================================================#
-MKDIR = mkdir -p
-RM = rm -rf
-#==============================================================================#
#--------------------------------- Rules --------------------------------------#
#==============================================================================#
${OBJS_DIR}%.o: ${SRCS_DIR}%.c ${INCS_DIR}${INCS}
@${MKDIR} ${OBJS_DIR}
- ${CC} ${CFLAGS} -I${INCS_DIR} -o $@ -c $<
+ ${CC} -c ${CFLAGS} -I${INCS_DIR} -o $@ $<
#------------------------------------------------------------------------------#
${NAME}: ${OBJS}
${AR} ${NAME} ${OBJS}
#------------------------------------------------------------------------------#
-all:
- @$(MAKE) --no-print-directory -j5 ${NAME}
+all: ${NAME}
#------------------------------------------------------------------------------#
clean:
${RM} ${OBJS_DIR}
@@ -136,41 +170,8 @@ fclean: clean
#------------------------------------------------------------------------------#
re: fclean all
#------------------------------------------------------------------------------#
-build: ${OBJS}
+run: ${OBJS}
${CC} ${CFLAGS} -Iinc/ -o a.out ${OBJS} ${SRCS_DIR}main.c
#------------------------------------------------------------------------------#
-.PHONY: all clean clean fclean re default
-#==============================================================================#
-#-------------------------------- Colors --------------------------------------#
-#==============================================================================#
-_END = \033[0m
-_BOLD = \033[1m
-_UNDER = \033[4m
-#------------------------------------------------------------------------------#
-_NBLACK = \033[0;30m
-_NRED = \033[0;31m
-_NGREEN = \033[0;32m
-_NYELLOW = \033[0;33m
-_NBLUE = \033[0;34m
-_NMAGENTA = \033[0;35m
-_NCYAN = \033[0;36m
-_NWHITE = \033[0;37m
-#------------------------------------------------------------------------------#
-_BBLACK = \033[1;30m
-_BRED = \033[1;31m
-_BGREEN = \033[1;32m
-_BYELLOW = \033[1;33m
-_BBLUE = \033[1;34m
-_BMAGENTA = \033[1;35m
-_BCYAN = \033[1;36m
-_BWHITE = \033[1;37m
-#------------------------------------------------------------------------------#
-_IBLACK = \033[1;40m
-_IRED = \033[1;41m
-_IGREEN = \033[1;42m
-_IYELLOW = \033[1;43m
-_IBLUE = \033[1;44m
-_IMAGENTA = \033[1;45m
-_ICYAN = \033[1;46m
-_IWHITE = \033[1;47m
+.PHONY: all clean clean fclean re run default
#==================================== EOF =====================================#
diff --git a/libft/inc/libft.h b/libft/inc/libft.h
index 1a47877..843e97c 100644
--- a/libft/inc/libft.h
+++ b/libft/inc/libft.h
@@ -1,24 +1,27 @@
/* ************************************************************************** */
-/* LE - / */
-/* / */
-/* libft.h .:: .:/ . .:: */
-/* +:+:+ +: +: +:+:+ */
-/* By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ */
-/* #+# #+ #+ #+# */
-/* Created: 2019/10/07 18:15:13 by rbousset #+# ## ## #+# */
-/* Updated: 2019/10/13 14:17:02 by rbousset ### #+. /#+ ###.fr */
-/* / */
-/* / */
+/* */
+/* ::: :::::::: */
+/* libft.h :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:19:27 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:19:29 by rbousset ### ########lyon.fr */
+/* */
/* ************************************************************************** */
# ifndef LIBFT_H
# define LIBFT_H
#include <stddef.h>
+#include <stdarg.h>
#include <inttypes.h>
+# define FT_MIN_HEX_BASE "0123456789abcdef"
+# define FT_MAJ_HEX_BASE "0123456789ABCDEF"
+# define FT_PRINTF_CONV_CHARSET "cspdiuxX%"
# ifndef BUFFER_SIZE
-# define BUFFER_SIZE 72
+# define BUFFER_SIZE 72
# endif
typedef struct s_list
@@ -27,21 +30,40 @@ typedef struct s_list
struct s_list *next;
} t_list;
+typedef struct s_gnl
+{
+ int fd;
+ char *rest;
+ struct s_gnl *next;
+} t_gnl;
+
+typedef struct s_printflist
+{
+ int putlen;
+ char conv;
+ char actconv;
+ char *fullflag;
+ size_t flaglen;
+ int width;
+ int precision;
+ uint8_t isreverse;
+ uint8_t isneg;
+ uint8_t isaz;
+ int8_t isaspace;
+ uint8_t isaplus;
+ int8_t lh;
+ uint8_t zflag;
+ uint8_t issharp;
+ uint8_t isminus;
+ int fulllen;
+ char *output;
+} t_printflist;
+
/*
** 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);
-void *ft_calloc(size_t count, size_t size);
-void *ft_realloc(void *ptr, size_t size);
-int ft_putchar_fd(char c, int fd);
-int ft_putstr_fd(char *s, int fd);
void ft_putendl_fd(char *s, int fd);
void ft_putnbr_fd(int n, int fd);
void ft_lstadd_front(t_list **alst, t_list *new);
@@ -50,8 +72,17 @@ void ft_lstdelone(t_list *lst, void (*del)(void *));
void ft_lstclear(t_list **lst, void (*del)(void *));
void ft_lstiter(t_list *lst, void (*f)(void *));
void ft_kernel_panic(void);
-void ft_putnbr(long long nb);
-void ft_putnbr_base(long long nb, char *base);
+void ft_putnbr(long nb);
+void ft_putnbr_base(long nb, char *base);
+void ft_memdel(void **ptr);
+void *ft_memset(void *b, int c, size_t len);
+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);
+void *ft_calloc(size_t count, size_t size);
+void *ft_nrealloc(void *ptr, size_t oldsize, size_t newsize);
/*
** CHAR
@@ -67,8 +98,10 @@ char *ft_substr(const char *s, unsigned int start,
size_t len);
char *ft_strjoin(const char *s1, const char *s2);
char *ft_strtrim(const char *s1, const char *set);
-char *ft_itoa(long long n);
-char *ft_itoa_base(long long n, char *base);
+char *ft_itoa(long n);
+char *ft_itoa_base(long n, char *base);
+char *ft_uitoa(unsigned long n);
+char *ft_uitoa_base(unsigned long n, char *base);
char *ft_strmapi(const char *s,
char (*f)(unsigned int, char));
char *ft_nstr(size_t size);
@@ -80,8 +113,10 @@ char **ft_split(const char *s, char c);
uint8_t ft_isspace(int c);
uint8_t ft_ischarset(const char *charset, int c);
-uint8_t ft_intlen(long long n);
-uint8_t ft_intlen_base(long long n, char *base);
+uint8_t ft_intlen(long n);
+uint8_t ft_intlen_base(long n, char *base);
+uint8_t ft_uintlen(unsigned long n);
+uint8_t ft_uintlen_base(unsigned long n, char *base);
int ft_memcmp(const void *s1, const void *s2, size_t n);
int ft_isalpha(int c);
int ft_isdigit(int c);
@@ -97,9 +132,11 @@ int ft_putchar(int c);
int ft_putnchar(int c, const size_t n);
int ft_putstr(const char *s);
int ft_putendl(const char *s);
+int ft_putchar_fd(char c, int fd);
+int ft_putstr_fd(char *s, int fd);
int ft_strcmp(const char *s1, const char *s2);
-int get_next_line(int fd, char **line);
long ft_memlchr(const void *s, int c, size_t n);
+long ft_strlchr(const char *s, int c);
size_t ft_strlen(const char *s);
size_t ft_strlcpy(char *dst, const char *src, size_t size);
size_t ft_strlcat(char *dst, const char *src, size_t size);
@@ -114,5 +151,70 @@ t_list *ft_lstnew(void *content);
t_list *ft_lstlast(t_list *lst);
t_list *ft_lstmap(t_list *lst, void *(*f)(void *),
void (*del)(void *));
+/*
+** get_next_line
+*/
+
+char *ft_strchr_gnl(const char *s, int c);
+char *ft_swap_gnl(char *s1, char *free_ft);
+int get_next_line(int fd, char **line);
+int ft_free_gnl(int fd, t_gnl **list);
+size_t ft_strlen_gnl(const char *s, char c);
+t_gnl *ft_find_fd(int fd, t_gnl **list);
+
+/*
+** ft_printf
+*/
+
+void ft_printf_process(const char *format,
+ va_list arg,
+ t_printflist *pflist);
+void ft_printf_reinit_struct(t_printflist *pflist);
+void ft_printf_cat_output(char *src,
+ size_t len,
+ t_printflist *format);
+void ft_printf_treat_flags(va_list arg,
+ t_printflist *pflist);
+void ft_printf_put_c(va_list arg, t_printflist *pflist);
+void ft_printf_put_s(va_list arg, t_printflist *pflist);
+void ft_printf_put_p(va_list arg, t_printflist *pflist);
+void ft_printf_put_d(va_list arg, t_printflist *pflist);
+void ft_printf_put_u(va_list arg, t_printflist *pflist);
+void ft_printf_put_x(va_list arg, t_printflist *pflist);
+void ft_printf_put_big_x(va_list arg, t_printflist *pflist);
+void ft_printf_put_perc(va_list arg, t_printflist *pflist);
+void ft_printf_put_none(t_printflist *pflist);
+void ft_printf_put_width_pre(t_printflist *pflist);
+void ft_printf_put_width_post(t_printflist *pflist);
+char *ft_printf_get_flags(const char *format,
+ int pos,
+ t_printflist *pflist);
+char *ft_printf_flag_to_atoi(char *str);
+char *ft_printf_get_width_nstr(char *str,
+ t_printflist *pflist);
+uint8_t ft_printf_is_multiwrite(const char *format);
+int ft_printf_flags(const char *format,
+ int pos,
+ va_list arg,
+ t_printflist *pflist);
+int ft_printf(const char *format,
+ ...) __attribute__((format(printf,1,2)));
+int ft_dprintf(int fd,
+ const char *format,
+ ...) __attribute__((format(printf,2,3)));
+int ft_sprintf(char *str,
+ const char *format,
+ ...) __attribute__((format(printf,2,3)));
+int ft_printf_get_partlen(const char *format);
+int ft_printf_putpart(const char *format,
+ int start,
+ int len,
+ t_printflist *pflist);
+int ft_printf_put_precision(t_printflist *pflist);
+int ft_printf_get_s_putlen(char *str, t_printflist *pflist);
+int ft_printf_fetch_width(va_list arg,
+ char *nstr,
+ t_printflist *pflist);
+t_printflist *ft_printf_init_struct(const char *format);
# endif
diff --git a/libft/src/ft_atoi.c b/libft/src/ft_atoi.c
index 4459c1d..7a97eae 100644
--- a/libft/src/ft_atoi.c
+++ b/libft/src/ft_atoi.c
@@ -1,14 +1,13 @@
/* ************************************************************************** */
-/* LE - / */
-/* / */
-/* ft_atoi.c .:: .:/ . .:: */
-/* +:+:+ +: +: +:+:+ */
-/* By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ */
-/* #+# #+ #+ #+# */
-/* Created: 2019/10/10 05:32:13 by rbousset #+# ## ## #+# */
-/* Updated: 2019/10/15 02:16:20 by rbousset ### #+. /#+ ###.fr */
-/* / */
-/* / */
+/* */
+/* ::: :::::::: */
+/* ft_atoi.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:06:22 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:07:24 by rbousset ### ########lyon.fr */
+/* */
/* ************************************************************************** */
#include <libft.h>
diff --git a/libft/src/ft_bzero.c b/libft/src/ft_bzero.c
index 1f09fbe..bec9e50 100644
--- a/libft/src/ft_bzero.c
+++ b/libft/src/ft_bzero.c
@@ -1,14 +1,13 @@
/* ************************************************************************** */
-/* LE - / */
-/* / */
-/* ft_bzero.c .:: .:/ . .:: */
-/* +:+:+ +: +: +:+:+ */
-/* By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ */
-/* #+# #+ #+ #+# */
-/* Created: 2019/10/08 14:04:55 by rbousset #+# ## ## #+# */
-/* Updated: 2019/10/13 08:45:28 by rbousset ### #+. /#+ ###.fr */
-/* / */
-/* / */
+/* */
+/* ::: :::::::: */
+/* ft_bzero.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:06:31 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:06:31 by rbousset ### ########lyon.fr */
+/* */
/* ************************************************************************** */
#include <libft.h>
diff --git a/libft/src/ft_calloc.c b/libft/src/ft_calloc.c
index 4ec518e..88c5457 100644
--- a/libft/src/ft_calloc.c
+++ b/libft/src/ft_calloc.c
@@ -1,14 +1,13 @@
/* ************************************************************************** */
-/* LE - / */
-/* / */
-/* ft_calloc.c .:: .:/ . .:: */
-/* +:+:+ +: +: +:+:+ */
-/* By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ */
-/* #+# #+ #+ #+# */
-/* Created: 2019/10/11 02:47:15 by rbousset #+# ## ## #+# */
-/* Updated: 2019/10/13 08:43:53 by rbousset ### #+. /#+ ###.fr */
-/* / */
-/* / */
+/* */
+/* ::: :::::::: */
+/* ft_calloc.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:06:32 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:06:32 by rbousset ### ########lyon.fr */
+/* */
/* ************************************************************************** */
#include <libft.h>
diff --git a/libft/src/ft_dprintf.c b/libft/src/ft_dprintf.c
new file mode 100644
index 0000000..caa28dc
--- /dev/null
+++ b/libft/src/ft_dprintf.c
@@ -0,0 +1,56 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_dprintf.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:06:39 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:06:39 by rbousset ### ########lyon.fr */
+/* */
+/* ************************************************************************** */
+
+#include <libft.h>
+#include <stddef.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <unistd.h>
+
+static int
+ ft_printf_return(int fd, t_printflist *pflist)
+{
+ int ret;
+
+ ret = write(fd, pflist->output, pflist->fulllen);
+ ft_memdel((void**)&pflist->output);
+ ft_memdel((void**)&pflist->fullflag);
+ ft_memdel((void**)&pflist);
+ return (ret);
+}
+
+int
+ ft_dprintf(int fd, const char *format, ...)
+{
+ t_printflist *pflist;
+ va_list arg;
+ int pos;
+
+ if (!format)
+ return (-1);
+ if ((pos = ft_strlchr(format, '%')) < 0)
+ return (write(fd, format, ft_strlen(format)));
+ else
+ {
+ pflist = ft_printf_init_struct(format);
+ ft_printf_putpart(format, 0, pos, pflist);
+ va_start(arg, format);
+ while (pos >= 0)
+ {
+ pos = ft_printf_flags(format, pos, arg, pflist);
+ ft_printf_reinit_struct(pflist);
+ }
+ va_end(arg);
+ return (ft_printf_return(fd, pflist));
+ }
+ return (0);
+}
diff --git a/libft/src/ft_intlen.c b/libft/src/ft_intlen.c
index 17a22b3..c122657 100644
--- a/libft/src/ft_intlen.c
+++ b/libft/src/ft_intlen.c
@@ -1,20 +1,19 @@
/* ************************************************************************** */
-/* LE - / */
-/* / */
-/* ft_intlen.c .:: .:/ . .:: */
-/* +:+:+ +: +: +:+:+ */
-/* By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ */
-/* #+# #+ #+ #+# */
-/* Created: 2019/12/07 02:24:29 by rbousset #+# ## ## #+# */
-/* Updated: 2019/12/07 02:24:30 by rbousset ### #+. /#+ ###.fr */
-/* / */
-/* / */
+/* */
+/* ::: :::::::: */
+/* ft_intlen.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:06:39 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:06:39 by rbousset ### ########lyon.fr */
+/* */
/* ************************************************************************** */
#include <inttypes.h>
uint8_t
- ft_intlen(long long n)
+ ft_intlen(long n)
{
uint8_t len;
diff --git a/libft/src/ft_intlen_base.c b/libft/src/ft_intlen_base.c
index 9de740c..47da31d 100644
--- a/libft/src/ft_intlen_base.c
+++ b/libft/src/ft_intlen_base.c
@@ -1,21 +1,20 @@
/* ************************************************************************** */
-/* LE - / */
-/* / */
-/* ft_intlen_base.c .:: .:/ . .:: */
-/* +:+:+ +: +: +:+:+ */
-/* By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ */
-/* #+# #+ #+ #+# */
-/* Created: 2019/12/19 17:22:26 by rbousset #+# ## ## #+# */
-/* Updated: 2019/12/19 17:22:27 by rbousset ### #+. /#+ ###.fr */
-/* / */
-/* / */
+/* */
+/* ::: :::::::: */
+/* ft_intlen_base.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:06:39 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:06:39 by rbousset ### ########lyon.fr */
+/* */
/* ************************************************************************** */
#include <libft.h>
#include <inttypes.h>
uint8_t
- ft_intlen_base(long long n, char *base)
+ ft_intlen_base(long n, char *base)
{
uint8_t len;
uint8_t size;
diff --git a/libft/src/ft_isalnum.c b/libft/src/ft_isalnum.c
index 1ab9ca2..e764ac6 100644
--- a/libft/src/ft_isalnum.c
+++ b/libft/src/ft_isalnum.c
@@ -1,14 +1,13 @@
/* ************************************************************************** */
-/* LE - / */
-/* / */
-/* ft_isalnum.c .:: .:/ . .:: */
-/* +:+:+ +: +: +:+:+ */
-/* By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ */
-/* #+# #+ #+ #+# */
-/* Created: 2019/10/07 18:07:44 by rbousset #+# ## ## #+# */
-/* Updated: 2019/10/13 08:45:57 by rbousset ### #+. /#+ ###.fr */
-/* / */
-/* / */
+/* */
+/* ::: :::::::: */
+/* ft_isalnum.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:06:39 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:06:39 by rbousset ### ########lyon.fr */
+/* */
/* ************************************************************************** */
#include <libft.h>
diff --git a/libft/src/ft_isalpha.c b/libft/src/ft_isalpha.c
index 9e95bd6..562825d 100644
--- a/libft/src/ft_isalpha.c
+++ b/libft/src/ft_isalpha.c
@@ -1,14 +1,13 @@
/* ************************************************************************** */
-/* LE - / */
-/* / */
-/* ft_isalpha.c .:: .:/ . .:: */
-/* +:+:+ +: +: +:+:+ */
-/* By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ */
-/* #+# #+ #+ #+# */
-/* Created: 2019/10/07 16:45:42 by rbousset #+# ## ## #+# */
-/* Updated: 2019/10/13 08:42:03 by rbousset ### #+. /#+ ###.fr */
-/* / */
-/* / */
+/* */
+/* ::: :::::::: */
+/* ft_isalpha.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:06:39 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:06:39 by rbousset ### ########lyon.fr */
+/* */
/* ************************************************************************** */
static int
diff --git a/libft/src/ft_isascii.c b/libft/src/ft_isascii.c
index 937ead5..8d2f3f2 100644
--- a/libft/src/ft_isascii.c
+++ b/libft/src/ft_isascii.c
@@ -1,14 +1,13 @@
/* ************************************************************************** */
-/* LE - / */
-/* / */
-/* ft_isascii.c .:: .:/ . .:: */
-/* +:+:+ +: +: +:+:+ */
-/* By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ */
-/* #+# #+ #+ #+# */
-/* Created: 2019/10/07 18:18:31 by rbousset #+# ## ## #+# */
-/* Updated: 2019/10/13 08:41:32 by rbousset ### #+. /#+ ###.fr */
-/* / */
-/* / */
+/* */
+/* ::: :::::::: */
+/* ft_isascii.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:06:39 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:06:39 by rbousset ### ########lyon.fr */
+/* */
/* ************************************************************************** */
int
diff --git a/libft/src/ft_ischarset.c b/libft/src/ft_ischarset.c
index 24d7b6e..95b9172 100644
--- a/libft/src/ft_ischarset.c
+++ b/libft/src/ft_ischarset.c
@@ -1,14 +1,13 @@
/* ************************************************************************** */
-/* LE - / */
-/* / */
-/* ft_ischarset.c .:: .:/ . .:: */
-/* +:+:+ +: +: +:+:+ */
-/* By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ */
-/* #+# #+ #+ #+# */
-/* Created: 2019/12/22 16:48:45 by rbousset #+# ## ## #+# */
-/* Updated: 2019/12/22 16:48:47 by rbousset ### #+. /#+ ###.fr */
-/* / */
-/* / */
+/* */
+/* ::: :::::::: */
+/* ft_ischarset.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:06:39 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:06:39 by rbousset ### ########lyon.fr */
+/* */
/* ************************************************************************** */
#include <libft.h>
diff --git a/libft/src/ft_isdigit.c b/libft/src/ft_isdigit.c
index 52ededc..ebe1f40 100644
--- a/libft/src/ft_isdigit.c
+++ b/libft/src/ft_isdigit.c
@@ -1,14 +1,13 @@
/* ************************************************************************** */
-/* LE - / */
-/* / */
-/* ft_isdigit.c .:: .:/ . .:: */
-/* +:+:+ +: +: +:+:+ */
-/* By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ */
-/* #+# #+ #+ #+# */
-/* Created: 2019/10/07 17:46:41 by rbousset #+# ## ## #+# */
-/* Updated: 2019/10/13 08:41:27 by rbousset ### #+. /#+ ###.fr */
-/* / */
-/* / */
+/* */
+/* ::: :::::::: */
+/* ft_isdigit.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:06:39 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:06:39 by rbousset ### ########lyon.fr */
+/* */
/* ************************************************************************** */
int
diff --git a/libft/src/ft_isprint.c b/libft/src/ft_isprint.c
index d82ded0..12fdb7a 100644
--- a/libft/src/ft_isprint.c
+++ b/libft/src/ft_isprint.c
@@ -1,14 +1,13 @@
/* ************************************************************************** */
-/* LE - / */
-/* / */
-/* ft_isprint.c .:: .:/ . .:: */
-/* +:+:+ +: +: +:+:+ */
-/* By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ */
-/* #+# #+ #+ #+# */
-/* Created: 2019/10/07 18:23:39 by rbousset #+# ## ## #+# */
-/* Updated: 2019/10/13 08:41:21 by rbousset ### #+. /#+ ###.fr */
-/* / */
-/* / */
+/* */
+/* ::: :::::::: */
+/* ft_isprint.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:06:40 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:06:40 by rbousset ### ########lyon.fr */
+/* */
/* ************************************************************************** */
int
diff --git a/libft/src/ft_isspace.c b/libft/src/ft_isspace.c
index c9cf255..188e94a 100644
--- a/libft/src/ft_isspace.c
+++ b/libft/src/ft_isspace.c
@@ -1,14 +1,13 @@
/* ************************************************************************** */
-/* LE - / */
-/* / */
-/* ft_isspace.c .:: .:/ . .:: */
-/* +:+:+ +: +: +:+:+ */
-/* By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ */
-/* #+# #+ #+ #+# */
-/* Created: 2019/10/10 05:57:19 by rbousset #+# ## ## #+# */
-/* Updated: 2019/10/13 08:44:18 by rbousset ### #+. /#+ ###.fr */
-/* / */
-/* / */
+/* */
+/* ::: :::::::: */
+/* ft_isspace.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:06:40 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:06:40 by rbousset ### ########lyon.fr */
+/* */
/* ************************************************************************** */
#include <inttypes.h>
diff --git a/libft/src/ft_itoa.c b/libft/src/ft_itoa.c
index 2f68068..e10fbab 100644
--- a/libft/src/ft_itoa.c
+++ b/libft/src/ft_itoa.c
@@ -1,14 +1,13 @@
/* ************************************************************************** */
-/* LE - / */
-/* / */
-/* ft_itoa.c .:: .:/ . .:: */
-/* +:+:+ +: +: +:+:+ */
-/* By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ */
-/* #+# #+ #+ #+# */
-/* Created: 2019/10/13 02:22:48 by rbousset #+# ## ## #+# */
-/* Updated: 2019/10/13 13:35:46 by rbousset ### #+. /#+ ###.fr */
-/* / */
-/* / */
+/* */
+/* ::: :::::::: */
+/* ft_itoa.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:06:40 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:06:40 by rbousset ### ########lyon.fr */
+/* */
/* ************************************************************************** */
#include <libft.h>
@@ -16,11 +15,11 @@
#include <stdlib.h>
char
- *ft_itoa(long long n)
+ *ft_itoa(long n)
{
- char *s;
- long long nb;
- uint8_t i;
+ char *s;
+ long nb;
+ uint8_t i;
i = ft_intlen(n) - 1;
if (!(s = (char*)malloc((i + 2) * sizeof(char))))
diff --git a/libft/src/ft_itoa_base.c b/libft/src/ft_itoa_base.c
index 3c84616..f3abe46 100644
--- a/libft/src/ft_itoa_base.c
+++ b/libft/src/ft_itoa_base.c
@@ -1,12 +1,24 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_itoa_base.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:06:40 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:06:40 by rbousset ### ########lyon.fr */
+/* */
+/* ************************************************************************** */
+
#include <libft.h>
#include <stdlib.h>
char
- *ft_itoa_base(long long n, char *base)
+ *ft_itoa_base(long n, char *base)
{
- char *s;
- long long nb;
- uint8_t i;
+ char *s;
+ long nb;
+ uint8_t i;
i = ft_intlen_base(n, base) - 1;
if (!(s = (char*)malloc((i + 2) * sizeof(char))))
@@ -22,7 +34,7 @@ char
while (n > 0)
{
nb = n;
- if (nb >= (long long)ft_strlen(base))
+ if (nb >= (long)ft_strlen(base))
nb = n % ft_strlen(base);
s[i] = base[nb];
n /= ft_strlen(base);
diff --git a/libft/src/ft_kernel_panic.c b/libft/src/ft_kernel_panic.c
index d58047a..437a79a 100644
--- a/libft/src/ft_kernel_panic.c
+++ b/libft/src/ft_kernel_panic.c
@@ -1,14 +1,13 @@
/* ************************************************************************** */
-/* LE - / */
-/* / */
-/* ft_kernel_panic.c .:: .:/ . .:: */
-/* +:+:+ +: +: +:+:+ */
-/* By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ */
-/* #+# #+ #+ #+# */
-/* Created: 2019/12/11 18:26:08 by rbousset #+# ## ## #+# */
-/* Updated: 2019/12/11 18:26:09 by rbousset ### #+. /#+ ###.fr */
-/* / */
-/* / */
+/* */
+/* ::: :::::::: */
+/* ft_kernel_panic.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:06:40 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:06:40 by rbousset ### ########lyon.fr */
+/* */
/* ************************************************************************** */
#include <libft.h>
@@ -20,8 +19,6 @@ void
int *ptr;
while (1)
- {
ptr = (int *)ft_calloc((1024 * 1024) * sizeof(int), 1);
- }
free(ptr);
}
diff --git a/libft/src/ft_lstadd_back.c b/libft/src/ft_lstadd_back.c
index 1c8aeeb..3f031ab 100644
--- a/libft/src/ft_lstadd_back.c
+++ b/libft/src/ft_lstadd_back.c
@@ -1,14 +1,13 @@
/* ************************************************************************** */
-/* LE - / */
-/* / */
-/* ft_lstadd_back.c .:: .:/ . .:: */
-/* +:+:+ +: +: +:+:+ */
-/* By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ */
-/* #+# #+ #+ #+# */
-/* Created: 2019/10/13 10:04:16 by rbousset #+# ## ## #+# */
-/* Updated: 2019/10/13 10:11:08 by rbousset ### #+. /#+ ###.fr */
-/* / */
-/* / */
+/* */
+/* ::: :::::::: */
+/* ft_lstadd_back.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:06:40 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:06:40 by rbousset ### ########lyon.fr */
+/* */
/* ************************************************************************** */
#include <libft.h>
diff --git a/libft/src/ft_lstadd_front.c b/libft/src/ft_lstadd_front.c
index 796740b..fac38cc 100644
--- a/libft/src/ft_lstadd_front.c
+++ b/libft/src/ft_lstadd_front.c
@@ -1,14 +1,13 @@
/* ************************************************************************** */
-/* LE - / */
-/* / */
-/* ft_lstadd_front.c .:: .:/ . .:: */
-/* +:+:+ +: +: +:+:+ */
-/* By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ */
-/* #+# #+ #+ #+# */
-/* Created: 2019/10/13 09:31:45 by rbousset #+# ## ## #+# */
-/* Updated: 2019/10/13 10:11:10 by rbousset ### #+. /#+ ###.fr */
-/* / */
-/* / */
+/* */
+/* ::: :::::::: */
+/* ft_lstadd_front.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:06:40 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:06:40 by rbousset ### ########lyon.fr */
+/* */
/* ************************************************************************** */
#include <libft.h>
diff --git a/libft/src/ft_lstclear.c b/libft/src/ft_lstclear.c
index 936672d..10a6d91 100644
--- a/libft/src/ft_lstclear.c
+++ b/libft/src/ft_lstclear.c
@@ -1,14 +1,13 @@
/* ************************************************************************** */
-/* LE - / */
-/* / */
-/* ft_lstclear.c .:: .:/ . .:: */
-/* +:+:+ +: +: +:+:+ */
-/* By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ */
-/* #+# #+ #+ #+# */
-/* Created: 2019/10/13 10:19:53 by rbousset #+# ## ## #+# */
-/* Updated: 2019/10/13 13:52:03 by rbousset ### #+. /#+ ###.fr */
-/* / */
-/* / */
+/* */
+/* ::: :::::::: */
+/* ft_lstclear.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:06:41 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:06:41 by rbousset ### ########lyon.fr */
+/* */
/* ************************************************************************** */
#include <libft.h>
diff --git a/libft/src/ft_lstdelone.c b/libft/src/ft_lstdelone.c
index 47f0669..3653e70 100644
--- a/libft/src/ft_lstdelone.c
+++ b/libft/src/ft_lstdelone.c
@@ -1,14 +1,13 @@
/* ************************************************************************** */
-/* LE - / */
-/* / */
-/* ft_lstdelone.c .:: .:/ . .:: */
-/* +:+:+ +: +: +:+:+ */
-/* By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ */
-/* #+# #+ #+ #+# */
-/* Created: 2019/10/13 10:11:20 by rbousset #+# ## ## #+# */
-/* Updated: 2019/10/13 10:18:40 by rbousset ### #+. /#+ ###.fr */
-/* / */
-/* / */
+/* */
+/* ::: :::::::: */
+/* ft_lstdelone.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:06:41 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:06:41 by rbousset ### ########lyon.fr */
+/* */
/* ************************************************************************** */
#include <libft.h>
diff --git a/libft/src/ft_lstiter.c b/libft/src/ft_lstiter.c
index 2570cf0..72810c9 100644
--- a/libft/src/ft_lstiter.c
+++ b/libft/src/ft_lstiter.c
@@ -1,14 +1,13 @@
/* ************************************************************************** */
-/* LE - / */
-/* / */
-/* ft_lstiter.c .:: .:/ . .:: */
-/* +:+:+ +: +: +:+:+ */
-/* By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ */
-/* #+# #+ #+ #+# */
-/* Created: 2019/10/13 10:30:22 by rbousset #+# ## ## #+# */
-/* Updated: 2019/10/13 11:01:22 by rbousset ### #+. /#+ ###.fr */
-/* / */
-/* / */
+/* */
+/* ::: :::::::: */
+/* ft_lstiter.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:06:41 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:06:41 by rbousset ### ########lyon.fr */
+/* */
/* ************************************************************************** */
#include <libft.h>
diff --git a/libft/src/ft_lstlast.c b/libft/src/ft_lstlast.c
index 0ac542a..85a708b 100644
--- a/libft/src/ft_lstlast.c
+++ b/libft/src/ft_lstlast.c
@@ -1,14 +1,13 @@
/* ************************************************************************** */
-/* LE - / */
-/* / */
-/* ft_lstlast.c .:: .:/ . .:: */
-/* +:+:+ +: +: +:+:+ */
-/* By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ */
-/* #+# #+ #+ #+# */
-/* Created: 2019/10/13 09:53:13 by rbousset #+# ## ## #+# */
-/* Updated: 2019/10/13 10:11:09 by rbousset ### #+. /#+ ###.fr */
-/* / */
-/* / */
+/* */
+/* ::: :::::::: */
+/* ft_lstlast.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:06:41 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:06:41 by rbousset ### ########lyon.fr */
+/* */
/* ************************************************************************** */
#include <libft.h>
diff --git a/libft/src/ft_lstmap.c b/libft/src/ft_lstmap.c
index 9aed5b9..b489527 100644
--- a/libft/src/ft_lstmap.c
+++ b/libft/src/ft_lstmap.c
@@ -1,14 +1,13 @@
/* ************************************************************************** */
-/* LE - / */
-/* / */
-/* ft_lstmap.c .:: .:/ . .:: */
-/* +:+:+ +: +: +:+:+ */
-/* By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ */
-/* #+# #+ #+ #+# */
-/* Created: 2019/10/13 10:36:15 by rbousset #+# ## ## #+# */
-/* Updated: 2019/10/13 11:06:32 by rbousset ### #+. /#+ ###.fr */
-/* / */
-/* / */
+/* */
+/* ::: :::::::: */
+/* ft_lstmap.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:06:41 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:06:41 by rbousset ### ########lyon.fr */
+/* */
/* ************************************************************************** */
#include <libft.h>
diff --git a/libft/src/ft_lstnew.c b/libft/src/ft_lstnew.c
index f4a9908..9f66691 100644
--- a/libft/src/ft_lstnew.c
+++ b/libft/src/ft_lstnew.c
@@ -1,14 +1,13 @@
/* ************************************************************************** */
-/* LE - / */
-/* / */
-/* ft_lstnew.c .:: .:/ . .:: */
-/* +:+:+ +: +: +:+:+ */
-/* By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ */
-/* #+# #+ #+ #+# */
-/* Created: 2019/10/13 09:25:56 by rbousset #+# ## ## #+# */
-/* Updated: 2019/10/13 10:56:17 by rbousset ### #+. /#+ ###.fr */
-/* / */
-/* / */
+/* */
+/* ::: :::::::: */
+/* ft_lstnew.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:06:41 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:06:41 by rbousset ### ########lyon.fr */
+/* */
/* ************************************************************************** */
#include <libft.h>
diff --git a/libft/src/ft_lstsize.c b/libft/src/ft_lstsize.c
index 0c71a69..7134a9f 100644
--- a/libft/src/ft_lstsize.c
+++ b/libft/src/ft_lstsize.c
@@ -1,14 +1,13 @@
/* ************************************************************************** */
-/* LE - / */
-/* / */
-/* ft_lstsize.c .:: .:/ . .:: */
-/* +:+:+ +: +: +:+:+ */
-/* By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ */
-/* #+# #+ #+ #+# */
-/* Created: 2019/10/13 09:45:10 by rbousset #+# ## ## #+# */
-/* Updated: 2019/10/13 09:51:16 by rbousset ### #+. /#+ ###.fr */
-/* / */
-/* / */
+/* */
+/* ::: :::::::: */
+/* ft_lstsize.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:06:41 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:06:41 by rbousset ### ########lyon.fr */
+/* */
/* ************************************************************************** */
#include <libft.h>
diff --git a/libft/src/ft_memccpy.c b/libft/src/ft_memccpy.c
index a029e7d..70f8226 100644
--- a/libft/src/ft_memccpy.c
+++ b/libft/src/ft_memccpy.c
@@ -1,14 +1,13 @@
/* ************************************************************************** */
-/* LE - / */
-/* / */
-/* ft_memccpy.c .:: .:/ . .:: */
-/* +:+:+ +: +: +:+:+ */
-/* By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ */
-/* #+# #+ #+ #+# */
-/* Created: 2019/10/08 14:59:46 by rbousset #+# ## ## #+# */
-/* Updated: 2019/10/13 08:40:44 by rbousset ### #+. /#+ ###.fr */
-/* / */
-/* / */
+/* */
+/* ::: :::::::: */
+/* ft_memccpy.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:06:41 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:06:41 by rbousset ### ########lyon.fr */
+/* */
/* ************************************************************************** */
#include <stddef.h>
diff --git a/libft/src/ft_memchr.c b/libft/src/ft_memchr.c
index 8dfb477..8917427 100644
--- a/libft/src/ft_memchr.c
+++ b/libft/src/ft_memchr.c
@@ -1,14 +1,13 @@
/* ************************************************************************** */
-/* LE - / */
-/* / */
-/* ft_memchr.c .:: .:/ . .:: */
-/* +:+:+ +: +: +:+:+ */
-/* By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ */
-/* #+# #+ #+ #+# */
-/* Created: 2019/10/08 19:14:54 by rbousset #+# ## ## #+# */
-/* Updated: 2019/12/10 18:34:21 by rbousset ### #+. /#+ ###.fr */
-/* / */
-/* / */
+/* */
+/* ::: :::::::: */
+/* ft_memchr.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:06:42 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:06:42 by rbousset ### ########lyon.fr */
+/* */
/* ************************************************************************** */
#include <stddef.h>
diff --git a/libft/src/ft_memcmp.c b/libft/src/ft_memcmp.c
index 96f21c4..39fbdf6 100644
--- a/libft/src/ft_memcmp.c
+++ b/libft/src/ft_memcmp.c
@@ -1,14 +1,13 @@
/* ************************************************************************** */
-/* LE - / */
-/* / */
-/* ft_memcmp.c .:: .:/ . .:: */
-/* +:+:+ +: +: +:+:+ */
-/* By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ */
-/* #+# #+ #+ #+# */
-/* Created: 2019/10/08 19:23:43 by rbousset #+# ## ## #+# */
-/* Updated: 2019/10/13 08:40:10 by rbousset ### #+. /#+ ###.fr */
-/* / */
-/* / */
+/* */
+/* ::: :::::::: */
+/* ft_memcmp.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:06:42 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:06:42 by rbousset ### ########lyon.fr */
+/* */
/* ************************************************************************** */
#include <stddef.h>
diff --git a/libft/src/ft_memcpy.c b/libft/src/ft_memcpy.c
index 49a1ff7..1357f2e 100644
--- a/libft/src/ft_memcpy.c
+++ b/libft/src/ft_memcpy.c
@@ -1,14 +1,13 @@
/* ************************************************************************** */
-/* LE - / */
-/* / */
-/* ft_memcpy.c .:: .:/ . .:: */
-/* +:+:+ +: +: +:+:+ */
-/* By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ */
-/* #+# #+ #+ #+# */
-/* Created: 2019/10/08 14:17:11 by rbousset #+# ## ## #+# */
-/* Updated: 2019/10/13 08:39:01 by rbousset ### #+. /#+ ###.fr */
-/* / */
-/* / */
+/* */
+/* ::: :::::::: */
+/* ft_memcpy.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:06:42 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:06:42 by rbousset ### ########lyon.fr */
+/* */
/* ************************************************************************** */
#include <libft.h>
diff --git a/libft/src/ft_memdel.c b/libft/src/ft_memdel.c
new file mode 100644
index 0000000..38d6e08
--- /dev/null
+++ b/libft/src/ft_memdel.c
@@ -0,0 +1,20 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_memdel.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:06:42 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:06:42 by rbousset ### ########lyon.fr */
+/* */
+/* ************************************************************************** */
+
+#include <stdlib.h>
+
+void
+ ft_memdel(void **ptr)
+{
+ free(*ptr);
+ *ptr = NULL;
+}
diff --git a/libft/src/ft_memlchr.c b/libft/src/ft_memlchr.c
index 1123743..643affc 100644
--- a/libft/src/ft_memlchr.c
+++ b/libft/src/ft_memlchr.c
@@ -1,14 +1,13 @@
/* ************************************************************************** */
-/* LE - / */
-/* / */
-/* ft_memlchr.c .:: .:/ . .:: */
-/* +:+:+ +: +: +:+:+ */
-/* By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ */
-/* #+# #+ #+ #+# */
-/* Created: 2019/12/11 16:50:58 by rbousset #+# ## ## #+# */
-/* Updated: 2019/12/11 16:50:59 by rbousset ### #+. /#+ ###.fr */
-/* / */
-/* / */
+/* */
+/* ::: :::::::: */
+/* ft_memlchr.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:06:42 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:06:42 by rbousset ### ########lyon.fr */
+/* */
/* ************************************************************************** */
#include <libft.h>
diff --git a/libft/src/ft_memmove.c b/libft/src/ft_memmove.c
index 5d79fab..1aa3588 100644
--- a/libft/src/ft_memmove.c
+++ b/libft/src/ft_memmove.c
@@ -1,14 +1,13 @@
/* ************************************************************************** */
-/* LE - / */
-/* / */
-/* ft_memmove.c .:: .:/ . .:: */
-/* +:+:+ +: +: +:+:+ */
-/* By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ */
-/* #+# #+ #+ #+# */
-/* Created: 2019/10/08 18:57:44 by rbousset #+# ## ## #+# */
-/* Updated: 2019/10/13 08:38:47 by rbousset ### #+. /#+ ###.fr */
-/* / */
-/* / */
+/* */
+/* ::: :::::::: */
+/* ft_memmove.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:06:42 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:06:42 by rbousset ### ########lyon.fr */
+/* */
/* ************************************************************************** */
#include <libft.h>
@@ -17,11 +16,26 @@
void
*ft_memmove(void *dst, const void *src, size_t len)
{
- char buff[len];
+ const char *from = (const char*)src;
+ char *to;
+ int i;
+ size_t j;
- if (src == NULL && dst == NULL && len != 0)
- return (NULL);
- ft_memcpy(buff, src, len);
- ft_memcpy(dst, buff, len);
+ to = (char*)dst;
+ if (to > from && to - from < (int)len)
+ {
+ i = len;
+ while (--i >= 0)
+ to[i] = from[i];
+ return (dst);
+ }
+ if (from > to && from - to < (int)len)
+ {
+ j = -1;
+ while (++j < len)
+ to[j] = from[j];
+ return (dst);
+ }
+ ft_memcpy(dst, src, len);
return (dst);
}
diff --git a/libft/src/ft_memset.c b/libft/src/ft_memset.c
index 1498ae6..e53cf38 100644
--- a/libft/src/ft_memset.c
+++ b/libft/src/ft_memset.c
@@ -1,14 +1,13 @@
/* ************************************************************************** */
-/* LE - / */
-/* / */
-/* ft_memset.c .:: .:/ . .:: */
-/* +:+:+ +: +: +:+:+ */
-/* By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ */
-/* #+# #+ #+ #+# */
-/* Created: 2019/10/08 13:41:09 by rbousset #+# ## ## #+# */
-/* Updated: 2019/10/13 08:38:10 by rbousset ### #+. /#+ ###.fr */
-/* / */
-/* / */
+/* */
+/* ::: :::::::: */
+/* ft_memset.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:06:42 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:06:42 by rbousset ### ########lyon.fr */
+/* */
/* ************************************************************************** */
#include <stddef.h>
diff --git a/libft/src/ft_nrealloc.c b/libft/src/ft_nrealloc.c
new file mode 100644
index 0000000..ea13f19
--- /dev/null
+++ b/libft/src/ft_nrealloc.c
@@ -0,0 +1,38 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_nrealloc.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:06:43 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:06:43 by rbousset ### ########lyon.fr */
+/* */
+/* ************************************************************************** */
+
+#include <libft.h>
+#include <stddef.h>
+#include <stdlib.h>
+
+void
+ *ft_nrealloc(void *ptr, size_t oldsize, size_t newsize)
+{
+ void *nptr;
+
+ if (!ptr)
+ {
+ if (!(ptr = malloc(newsize)))
+ return (NULL);
+ return (ptr);
+ }
+ else if (!newsize)
+ {
+ free(ptr);
+ return (NULL);
+ }
+ if (!(nptr = malloc(newsize)))
+ return (ptr);
+ ft_memcpy(nptr, ptr, oldsize);
+ free(ptr);
+ return (nptr);
+}
diff --git a/libft/src/ft_nstr.c b/libft/src/ft_nstr.c
index 8919e64..7b09053 100644
--- a/libft/src/ft_nstr.c
+++ b/libft/src/ft_nstr.c
@@ -1,14 +1,13 @@
/* ************************************************************************** */
-/* LE - / */
-/* / */
-/* ft_nstr.c .:: .:/ . .:: */
-/* +:+:+ +: +: +:+:+ */
-/* By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ */
-/* #+# #+ #+ #+# */
-/* Created: 2019/12/07 04:23:30 by rbousset #+# ## ## #+# */
-/* Updated: 2019/12/07 04:23:32 by rbousset ### #+. /#+ ###.fr */
-/* / */
-/* / */
+/* */
+/* ::: :::::::: */
+/* ft_nstr.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:06:43 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:06:43 by rbousset ### ########lyon.fr */
+/* */
/* ************************************************************************** */
#include <stdlib.h>
diff --git a/libft/src/ft_printf.c b/libft/src/ft_printf.c
new file mode 100644
index 0000000..ec1922f
--- /dev/null
+++ b/libft/src/ft_printf.c
@@ -0,0 +1,56 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_printf.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:06:43 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:06:43 by rbousset ### ########lyon.fr */
+/* */
+/* ************************************************************************** */
+
+#include <libft.h>
+#include <stddef.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <unistd.h>
+
+static int
+ ft_printf_return(t_printflist *pflist)
+{
+ int ret;
+
+ ret = write(1, pflist->output, pflist->fulllen);
+ ft_memdel((void**)&pflist->output);
+ ft_memdel((void**)&pflist->fullflag);
+ ft_memdel((void**)&pflist);
+ return (ret);
+}
+
+int
+ ft_printf(const char *format, ...)
+{
+ t_printflist *pflist;
+ va_list arg;
+ int pos;
+
+ if (!format)
+ return (-1);
+ if ((pos = ft_strlchr(format, '%')) < 0)
+ return (ft_putstr(format));
+ else
+ {
+ pflist = ft_printf_init_struct(format);
+ ft_printf_putpart(format, 0, pos, pflist);
+ va_start(arg, format);
+ while (pos >= 0)
+ {
+ pos = ft_printf_flags(format, pos, arg, pflist);
+ ft_printf_reinit_struct(pflist);
+ }
+ va_end(arg);
+ return (ft_printf_return(pflist));
+ }
+ return (0);
+}
diff --git a/libft/src/ft_printf_cat_output.c b/libft/src/ft_printf_cat_output.c
new file mode 100644
index 0000000..f340109
--- /dev/null
+++ b/libft/src/ft_printf_cat_output.c
@@ -0,0 +1,29 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_printf_cat_output.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:06:43 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:06:43 by rbousset ### ########lyon.fr */
+/* */
+/* ************************************************************************** */
+
+#include <libft.h>
+#include <stddef.h>
+#include <unistd.h>
+
+void
+ ft_printf_cat_output(char *src, size_t len, t_printflist *pflist)
+{
+ size_t dst_len;
+
+ dst_len = pflist->fulllen;
+ pflist->output = (char*)ft_nrealloc(pflist->output,
+ (dst_len + 1) * sizeof(char),
+ (dst_len + len + 1) * sizeof(char));
+ ft_memcpy(pflist->output + dst_len, src, len);
+ *(pflist->output + dst_len + len) = '\0';
+ pflist->fulllen += len;
+}
diff --git a/libft/src/ft_printf_flag_to_atoi.c b/libft/src/ft_printf_flag_to_atoi.c
new file mode 100644
index 0000000..2f3c6e7
--- /dev/null
+++ b/libft/src/ft_printf_flag_to_atoi.c
@@ -0,0 +1,33 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_printf_flag_to_atoi.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:06:43 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:06:43 by rbousset ### ########lyon.fr */
+/* */
+/* ************************************************************************** */
+
+#include <libft.h>
+#include <stddef.h>
+#include <stdlib.h>
+
+char
+ *ft_printf_flag_to_atoi(char *str)
+{
+ char *nstr;
+ char *nnstr;
+ int len;
+
+ while (*str != '.' && *str)
+ str++;
+ while (*str != '-' && *str)
+ str--;
+ len = ft_strlchr(str, ' ');
+ nnstr = ft_substr(str, 0, len);
+ nstr = ft_strjoin(nnstr, str + len + 1);
+ ft_memdel((void**)&nnstr);
+ return (nstr);
+}
diff --git a/libft/src/ft_printf_get_flags.c b/libft/src/ft_printf_get_flags.c
new file mode 100644
index 0000000..ca49206
--- /dev/null
+++ b/libft/src/ft_printf_get_flags.c
@@ -0,0 +1,42 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_printf_get_flags.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:06:43 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:06:43 by rbousset ### ########lyon.fr */
+/* */
+/* ************************************************************************** */
+
+#include <libft.h>
+#include <stddef.h>
+#include <stdlib.h>
+
+/*
+** Copies everything between '%' and any
+** FT_PRINTF_CONV_CHARSET "cspdiuxX%"
+** into the fullflag string and returns it.
+** Also puts actual conv into pflist->actconv
+*/
+
+char
+ *ft_printf_get_flags(const char *format, int pos, t_printflist *pflist)
+{
+ int i;
+ char *nstr;
+ char *fullflag;
+
+ i = 0;
+ while (!ft_ischarset(FT_PRINTF_CONV_CHARSET, *(format + pos + i + 1))
+ && *(format + pos + i + 1))
+ i++;
+ if (!(fullflag = (char*)malloc((i + 1) * sizeof(char))))
+ return (NULL);
+ ft_memcpy(fullflag, nstr = ft_substr(format, pos + 1, i), i);
+ ft_memdel((void**)&nstr);
+ fullflag[i] = '\0';
+ pflist->actconv = *(format + pos + i + 1);
+ return (fullflag);
+}
diff --git a/libft/src/ft_printf_get_s_putlen.c b/libft/src/ft_printf_get_s_putlen.c
new file mode 100644
index 0000000..3f26a90
--- /dev/null
+++ b/libft/src/ft_printf_get_s_putlen.c
@@ -0,0 +1,28 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_printf_get_s_putlen.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:06:43 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:06:43 by rbousset ### ########lyon.fr */
+/* */
+/* ************************************************************************** */
+
+#include <libft.h>
+
+int
+ ft_printf_get_s_putlen(char *str, t_printflist *pflist)
+{
+ int ret;
+
+ if (pflist->precision > 0
+ && (int)ft_strlen((const char*)str) > pflist->precision)
+ ret = pflist->precision;
+ else if (pflist->precision == -1)
+ ret = 0;
+ else
+ ret = ft_strlen((const char*)str);
+ return (ret);
+}
diff --git a/libft/src/ft_printf_get_width_nstr.c b/libft/src/ft_printf_get_width_nstr.c
new file mode 100644
index 0000000..2aec3b8
--- /dev/null
+++ b/libft/src/ft_printf_get_width_nstr.c
@@ -0,0 +1,56 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_printf_get_width_nstr.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:06:44 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:06:44 by rbousset ### ########lyon.fr */
+/* */
+/* ************************************************************************** */
+
+#include <libft.h>
+#include <stdlib.h>
+#include <stdarg.h>
+
+int
+ ft_printf_fetch_width(va_list arg, char *nstr, t_printflist *pflist)
+{
+ int ret;
+ char *str;
+
+ if (ft_strlchr(nstr, '*') >= 0)
+ {
+ (ft_strlchr(pflist->fullflag, '-') >= 0) ? (pflist->isminus = 1) : 0;
+ (pflist->isminus) ? (pflist->isreverse = 1) : 0;
+ ret = va_arg(arg, int);
+ }
+ else if ((pflist->isaspace = ft_strlchr(pflist->fullflag, ' ')) >= 0)
+ {
+ str = ft_printf_flag_to_atoi(pflist->fullflag);
+ ret = ft_atoi(str);
+ ft_memdel((void**)&str);
+ }
+ else
+ {
+ if (*nstr == '-' && ft_strlen(nstr) >= 2)
+ {
+ nstr += 1;
+ pflist->isreverse = 1;
+ }
+ ret = ft_atoi(nstr);
+ }
+ return (ret);
+}
+
+char
+ *ft_printf_get_width_nstr(char *str, t_printflist *pflist)
+{
+ (ft_strlchr(pflist->fullflag, '+') >= 0) ? (pflist->isaplus = 1) : 0;
+ (*(pflist->fullflag) == '+' && *(pflist->fullflag + 1)) ? (str += 1) : 0;
+ (*(pflist->fullflag) == '0' && *(pflist->fullflag + 1)) ? (str += 1) : 0;
+ (*(pflist->fullflag) == '#' && *(pflist->fullflag + 1)
+ && (pflist->actconv == 'x' || pflist->actconv == 'X')) ? (str += 1) : 0;
+ return (str);
+}
diff --git a/libft/src/ft_printf_init_struct.c b/libft/src/ft_printf_init_struct.c
new file mode 100644
index 0000000..8c65046
--- /dev/null
+++ b/libft/src/ft_printf_init_struct.c
@@ -0,0 +1,52 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_printf_init_struct.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:06:44 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:06:44 by rbousset ### ########lyon.fr */
+/* */
+/* ************************************************************************** */
+
+#include <libft.h>
+#include <stddef.h>
+#include <stdlib.h>
+
+t_printflist
+ *ft_printf_init_struct(const char *format)
+{
+ t_printflist *pflist;
+
+ (void)format;
+ if (!(pflist = (t_printflist*)malloc(sizeof(t_printflist))))
+ return (NULL);
+ if (!(pflist->fullflag = (char *)ft_calloc(1, sizeof(char))))
+ return (NULL);
+ ft_printf_reinit_struct(pflist);
+ pflist->fulllen = 0;
+ if (!(pflist->output = (char*)ft_calloc(1, sizeof(char))))
+ return (NULL);
+ return (pflist);
+}
+
+void
+ ft_printf_reinit_struct(t_printflist *pflist)
+{
+ pflist->conv = 0;
+ pflist->actconv = 0;
+ pflist->flaglen = 0;
+ pflist->width = 0;
+ pflist->precision = 0;
+ pflist->isreverse = 0;
+ pflist->isneg = 0;
+ pflist->isaz = 0;
+ pflist->isaspace = -1;
+ pflist->isaplus = 0;
+ pflist->putlen = 0;
+ pflist->lh = 0;
+ pflist->zflag = 0;
+ pflist->issharp = 0;
+ pflist->isminus = 0;
+}
diff --git a/libft/src/ft_printf_parts.c b/libft/src/ft_printf_parts.c
new file mode 100644
index 0000000..f29d680
--- /dev/null
+++ b/libft/src/ft_printf_parts.c
@@ -0,0 +1,42 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_printf_parts.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:06:44 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:06:44 by rbousset ### ########lyon.fr */
+/* */
+/* ************************************************************************** */
+
+#include <libft.h>
+#include <stddef.h>
+#include <stdlib.h>
+
+int
+ ft_printf_get_partlen(const char *format)
+{
+ int ret;
+
+ ret = ft_strlchr(format, '%');
+ if (ret < 0)
+ return (ft_strlen(format));
+ else
+ return (ret);
+}
+
+int
+ ft_printf_putpart(const char *format,
+ int start,
+ int len,
+ t_printflist *pflist)
+{
+ char *nstr;
+ int ret;
+
+ ft_printf_cat_output(nstr = ft_substr(format, start, len), len, pflist);
+ ft_memdel((void**)&nstr);
+ ret = 0;
+ return (ret);
+}
diff --git a/libft/src/ft_printf_process.c b/libft/src/ft_printf_process.c
new file mode 100644
index 0000000..92f4601
--- /dev/null
+++ b/libft/src/ft_printf_process.c
@@ -0,0 +1,45 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_printf_process.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:06:44 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:06:44 by rbousset ### ########lyon.fr */
+/* */
+/* ************************************************************************** */
+
+#include <libft.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <inttypes.h>
+#include <limits.h>
+
+/*
+** calls the corresponding function to
+** the right conv using:
+** FT_PRINTF_CONV_CHARSET "cspdiuxX%"
+*/
+
+void
+ ft_printf_process(const char *format, va_list arg, t_printflist *pflist)
+{
+ int conv;
+ void (*fun_ptr[9])(va_list, t_printflist *);
+
+ fun_ptr[0] = ft_printf_put_c;
+ fun_ptr[1] = ft_printf_put_s;
+ fun_ptr[2] = ft_printf_put_p;
+ fun_ptr[3] = ft_printf_put_d;
+ fun_ptr[4] = ft_printf_put_d;
+ fun_ptr[5] = ft_printf_put_u;
+ fun_ptr[6] = ft_printf_put_x;
+ fun_ptr[7] = ft_printf_put_big_x;
+ fun_ptr[8] = ft_printf_put_perc;
+ if ((conv = ft_strlchr(FT_PRINTF_CONV_CHARSET,
+ *(format + pflist->flaglen + 1))) >= 0)
+ (*fun_ptr[conv])(arg, pflist);
+ else
+ ft_printf_put_none(pflist);
+}
diff --git a/libft/src/ft_printf_put_char.c b/libft/src/ft_printf_put_char.c
new file mode 100644
index 0000000..f9cc6e5
--- /dev/null
+++ b/libft/src/ft_printf_put_char.c
@@ -0,0 +1,41 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_printf_put_char.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:06:44 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:06:44 by rbousset ### ########lyon.fr */
+/* */
+/* ************************************************************************** */
+
+#include <libft.h>
+#include <stddef.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <inttypes.h>
+#include <unistd.h>
+
+void
+ ft_printf_put_c(va_list arg, t_printflist *pflist)
+{
+ char c;
+
+ c = va_arg(arg, int);
+ pflist->putlen += 1;
+ ft_printf_put_width_pre(pflist);
+ ft_printf_cat_output(&c, 1, pflist);
+ ft_printf_put_width_post(pflist);
+}
+
+void
+ ft_printf_put_perc(va_list arg, t_printflist *pflist)
+{
+ (void)arg;
+ pflist->putlen += 1;
+ (pflist->isaz) ? (ft_printf_put_precision(pflist)) : 0;
+ ft_printf_put_width_pre(pflist);
+ ft_printf_cat_output("%", 1, pflist);
+ ft_printf_put_width_post(pflist);
+}
diff --git a/libft/src/ft_printf_put_hex.c b/libft/src/ft_printf_put_hex.c
new file mode 100644
index 0000000..68126a4
--- /dev/null
+++ b/libft/src/ft_printf_put_hex.c
@@ -0,0 +1,85 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_printf_put_hex.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:06:44 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:06:44 by rbousset ### ########lyon.fr */
+/* */
+/* ************************************************************************** */
+
+#include <libft.h>
+#include <stddef.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <inttypes.h>
+
+static unsigned long
+ ft_printf_get_xlh(va_list arg, int8_t lh, uint8_t zflag)
+{
+ if (zflag == 1)
+ return (va_arg(arg, size_t));
+ else if (lh == 0)
+ return (va_arg(arg, unsigned int));
+ else if (lh == -2)
+ return ((unsigned char)va_arg(arg, unsigned int));
+ else if (lh == -1)
+ return ((unsigned short)va_arg(arg, unsigned int));
+ else if (lh == 1)
+ return (va_arg(arg, unsigned long));
+ else if (lh == 2)
+ return (va_arg(arg, unsigned long));
+ return (va_arg(arg, unsigned int));
+}
+
+void
+ ft_printf_put_x(va_list arg, t_printflist *pflist)
+{
+ unsigned long x;
+ char *str;
+
+ x = ft_printf_get_xlh(arg, pflist->lh, pflist->zflag);
+ pflist->conv = 'd';
+ pflist->putlen += ft_uintlen_base(x, FT_MIN_HEX_BASE);
+ (pflist->issharp && x != 0) ? (pflist->putlen += 2) : 0;
+ (x == 0 && pflist->precision == -1 && pflist->width > 0)
+ ? (pflist->putlen = 0) : 0;
+ ft_printf_put_width_pre(pflist);
+ if (pflist->issharp && x != 0)
+ ft_printf_cat_output("0x", 2, pflist);
+ ft_printf_put_precision(pflist);
+ if (!(pflist->precision < 0 && x == 0))
+ {
+ str = ft_uitoa_base(x, FT_MIN_HEX_BASE);
+ ft_printf_cat_output(str, ft_strlen(str), pflist);
+ ft_memdel((void**)&str);
+ }
+ ft_printf_put_width_post(pflist);
+}
+
+void
+ ft_printf_put_big_x(va_list arg, t_printflist *pflist)
+{
+ unsigned long x;
+ char *str;
+
+ x = ft_printf_get_xlh(arg, pflist->lh, pflist->zflag);
+ pflist->conv = 'd';
+ pflist->putlen += ft_uintlen_base(x, FT_MAJ_HEX_BASE);
+ (pflist->issharp && x != 0) ? (pflist->putlen += 2) : 0;
+ (x == 0 && pflist->precision == -1 && pflist->width > 0)
+ ? (pflist->putlen = 0) : 0;
+ ft_printf_put_width_pre(pflist);
+ if (pflist->issharp && x != 0)
+ ft_printf_cat_output("0X", 2, pflist);
+ ft_printf_put_precision(pflist);
+ if (!(pflist->precision < 0 && x == 0))
+ {
+ str = ft_uitoa_base(x, FT_MAJ_HEX_BASE);
+ ft_printf_cat_output(str, ft_strlen(str), pflist);
+ ft_memdel((void**)&str);
+ }
+ ft_printf_put_width_post(pflist);
+}
diff --git a/libft/src/ft_printf_put_int.c b/libft/src/ft_printf_put_int.c
new file mode 100644
index 0000000..09b8bf6
--- /dev/null
+++ b/libft/src/ft_printf_put_int.c
@@ -0,0 +1,114 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_printf_put_int.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:06:44 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:06:44 by rbousset ### ########lyon.fr */
+/* */
+/* ************************************************************************** */
+
+#include <libft.h>
+#include <stddef.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <inttypes.h>
+
+static long
+ ft_printf_get_dlh(va_list arg, int8_t lh)
+{
+ if (lh == 0)
+ return (va_arg(arg, int));
+ else if (lh == -2)
+ return ((char)va_arg(arg, int));
+ else if (lh == -1)
+ return ((short)va_arg(arg, int));
+ else if (lh == 1)
+ return (va_arg(arg, long int));
+ else if (lh == 2)
+ return (va_arg(arg, long int));
+ return (va_arg(arg, int));
+}
+
+static unsigned long
+ ft_printf_get_ulh(va_list arg, int8_t lh, uint8_t zflag)
+{
+ if (zflag == 1)
+ return (va_arg(arg, size_t));
+ else if (lh == 0)
+ return (va_arg(arg, unsigned int));
+ else if (lh == -2)
+ return ((unsigned char)va_arg(arg, unsigned int));
+ else if (lh == -1)
+ return ((unsigned short)va_arg(arg, unsigned int));
+ else if (lh == 1)
+ return (va_arg(arg, unsigned long int));
+ else if (lh == 2)
+ return (va_arg(arg, unsigned long int));
+ return (va_arg(arg, unsigned int));
+}
+
+static long
+ ft_printf_put_plus_minus(long d, t_printflist *pflist)
+{
+ if (pflist->precision >= pflist->putlen && pflist->isneg == 1)
+ {
+ ft_printf_cat_output("-", 1, pflist);
+ pflist->putlen -= 1;
+ d = -d;
+ }
+ else if (pflist->isaplus && !pflist->isneg)
+ ft_printf_cat_output("+", 1, pflist);
+ return (d);
+}
+
+void
+ ft_printf_put_d(va_list arg, t_printflist *pflist)
+{
+ long d;
+ char *str;
+
+ d = ft_printf_get_dlh(arg, pflist->lh);
+ (d < 0) ? (pflist->isneg = 1)
+ : (pflist->isneg = 0);
+ pflist->conv = 'd';
+ pflist->putlen += ft_intlen(d);
+ if (pflist->isaplus && !pflist->isneg)
+ pflist->putlen += 1;
+ (d == 0 && pflist->precision == -1 && pflist->width > 0)
+ ? (pflist->putlen = 0) : 0;
+ ft_printf_put_width_pre(pflist);
+ d = ft_printf_put_plus_minus(d, pflist);
+ ft_printf_put_precision(pflist);
+ if (!(pflist->precision < 0 && d == 0))
+ {
+ str = ft_itoa(d);
+ ft_printf_cat_output(str, ft_strlen(str), pflist);
+ ft_memdel((void**)&str);
+ }
+ ft_printf_put_width_post(pflist);
+}
+
+void
+ ft_printf_put_u(va_list arg, t_printflist *pflist)
+{
+ unsigned long d;
+ char *str;
+
+ d = ft_printf_get_ulh(arg, pflist->lh, pflist->zflag);
+ pflist->conv = 'd';
+ pflist->putlen += ft_uintlen(d);
+ (d == 0 && pflist->precision == -1 && pflist->width > 0)
+ ? (pflist->putlen = 0) : 0;
+ ft_printf_put_width_pre(pflist);
+ ft_printf_put_precision(pflist);
+ if (!(pflist->precision < 0 && d == 0))
+ {
+ str = ft_uitoa(d);
+ ft_printf_cat_output(str, ft_strlen(str), pflist);
+ ft_memdel((void**)&str);
+ }
+ ft_printf_put_width_post(pflist);
+}
diff --git a/libft/src/ft_printf_put_none.c b/libft/src/ft_printf_put_none.c
new file mode 100644
index 0000000..01fd672
--- /dev/null
+++ b/libft/src/ft_printf_put_none.c
@@ -0,0 +1,20 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_printf_put_none.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:06:45 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:06:45 by rbousset ### ########lyon.fr */
+/* */
+/* ************************************************************************** */
+
+#include <libft.h>
+
+void
+ ft_printf_put_none(t_printflist *pflist)
+{
+ ft_printf_put_width_pre(pflist);
+ ft_printf_put_width_post(pflist);
+}
diff --git a/libft/src/ft_printf_put_precision.c b/libft/src/ft_printf_put_precision.c
new file mode 100644
index 0000000..af7f7b7
--- /dev/null
+++ b/libft/src/ft_printf_put_precision.c
@@ -0,0 +1,66 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_printf_put_precision.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:06:45 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:06:45 by rbousset ### ########lyon.fr */
+/* */
+/* ************************************************************************** */
+
+#include <libft.h>
+#include <stdlib.h>
+
+static int
+ ft_printf_get_len(t_printflist *pflist)
+{
+ if (pflist->conv == 'p' && pflist->precision > pflist->putlen)
+ return (pflist->precision - pflist->putlen + 2);
+ else if (pflist->precision > pflist->putlen && pflist->isneg == 0
+ && pflist->isaplus == 0)
+ return (pflist->precision - pflist->putlen);
+ else if (pflist->precision >= pflist->putlen && pflist->isneg == 1)
+ {
+ if (pflist->isaz == 1)
+ return (pflist->precision - pflist->putlen - 1);
+ else
+ return (pflist->precision - pflist->putlen);
+ }
+ else if (pflist->precision >= pflist->putlen && pflist->isneg == 0
+ && pflist->isaplus == 1)
+ {
+ if (pflist->isaz == 1)
+ return (pflist->precision - pflist->putlen);
+ else
+ return (pflist->precision - pflist->putlen + 1);
+ }
+ return (0);
+}
+
+/*
+** Puts the correct amount of 0's when
+** needed using pflist->precision.
+** Used for %p, %d, %i, %u, %x and %X
+*/
+
+int
+ ft_printf_put_precision(t_printflist *pflist)
+{
+ char *str;
+ int len;
+
+ len = 0;
+ if (pflist->precision >= pflist->putlen)
+ {
+ len = ft_printf_get_len(pflist);
+ if (!(str = (char*)malloc((len + 1) * sizeof(char))))
+ return (1);
+ str = ft_memset(str, '0', len);
+ *(str + len) = '\0';
+ ft_printf_cat_output(str, ft_strlen(str), pflist);
+ ft_memdel((void**)&str);
+ }
+ return (0);
+}
diff --git a/libft/src/ft_printf_put_ptr.c b/libft/src/ft_printf_put_ptr.c
new file mode 100644
index 0000000..bd50443
--- /dev/null
+++ b/libft/src/ft_printf_put_ptr.c
@@ -0,0 +1,42 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_printf_put_ptr.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:06:45 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:06:45 by rbousset ### ########lyon.fr */
+/* */
+/* ************************************************************************** */
+
+#include <libft.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <inttypes.h>
+
+/*
+** For GCC: if (!p) { ft_putstr("(nil)"); return ; }
+*/
+
+void
+ ft_printf_put_p(va_list arg, t_printflist *pflist)
+{
+ unsigned long p;
+ char *str;
+
+ p = va_arg(arg, unsigned long);
+ pflist->conv = 'p';
+ pflist->putlen += 2 + ft_uintlen_base(p, FT_MIN_HEX_BASE);
+ ft_printf_put_width_pre(pflist);
+ ft_printf_cat_output("0x", 2, pflist);
+ if (pflist->precision > pflist->putlen - 2)
+ ft_printf_put_precision(pflist);
+ if (!(pflist->precision < 0 && p == 0))
+ {
+ str = ft_uitoa_base(p, FT_MIN_HEX_BASE);
+ ft_printf_cat_output(str, ft_strlen(str), pflist);
+ ft_memdel((void**)&str);
+ }
+ ft_printf_put_width_post(pflist);
+}
diff --git a/libft/src/ft_printf_put_str.c b/libft/src/ft_printf_put_str.c
new file mode 100644
index 0000000..6834fff
--- /dev/null
+++ b/libft/src/ft_printf_put_str.c
@@ -0,0 +1,39 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_printf_put_str.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:06:45 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:06:45 by rbousset ### ########lyon.fr */
+/* */
+/* ************************************************************************** */
+
+#include <libft.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <inttypes.h>
+
+void
+ ft_printf_put_s(va_list arg, t_printflist *pflist)
+{
+ char *str;
+ char *nstr;
+
+ pflist->conv = 's';
+ str = va_arg(arg, char*);
+ if (!str)
+ str = "(null)";
+ pflist->putlen += ft_printf_get_s_putlen(str, pflist);
+ ft_printf_put_width_pre(pflist);
+ if ((int)ft_strlen(str) > pflist->putlen)
+ {
+ ft_printf_cat_output(nstr = ft_substr(str, 0, pflist->putlen),
+ pflist->putlen, pflist);
+ ft_memdel((void**)&nstr);
+ }
+ else
+ ft_printf_cat_output(str, pflist->putlen, pflist);
+ ft_printf_put_width_post(pflist);
+}
diff --git a/libft/src/ft_printf_put_width.c b/libft/src/ft_printf_put_width.c
new file mode 100644
index 0000000..e649a65
--- /dev/null
+++ b/libft/src/ft_printf_put_width.c
@@ -0,0 +1,104 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_printf_put_width.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:06:45 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:06:45 by rbousset ### ########lyon.fr */
+/* */
+/* ************************************************************************** */
+
+#include <libft.h>
+#include <stdlib.h>
+
+static int
+ ft_printf_get_len(t_printflist *pflist)
+{
+ int len;
+ int width;
+ int prec;
+
+ width = pflist->width;
+ prec = pflist->precision;
+ if (pflist->conv == 'd' && prec > pflist->putlen && !pflist->isneg)
+ len = (width - pflist->putlen - (prec - pflist->putlen));
+ else if (pflist->conv == 'd' && prec >= pflist->putlen && (pflist->isneg))
+ len = (width - pflist->putlen - 1 - (prec - pflist->putlen));
+ else if (pflist->conv == 'p' && prec > pflist->putlen)
+ len = (width - pflist->putlen - (prec - pflist->putlen + 2));
+ else if (pflist->conv == 's' && prec > pflist->putlen && pflist->isaz == 1)
+ len = (width - pflist->putlen - (prec - pflist->putlen));
+ else
+ len = (width - pflist->putlen);
+ if (pflist->conv == 'd' && pflist->isaspace == 1 && !pflist->isaplus
+ && (pflist->putlen < 3 && !pflist->isneg))
+ len -= 1;
+ (len < 0) ? (len = 0) : 0;
+ return (len);
+}
+
+/*
+** Puts the (correct) amount of spaces
+** when needed using pflist->width
+*/
+
+void
+ ft_printf_put_width_pre(t_printflist *pflist)
+{
+ char *str;
+
+ if (pflist->conv == 'd' && pflist->isaspace == 1 && !pflist->isaplus
+ && (pflist->putlen < 3 && !pflist->isneg))
+ ft_printf_cat_output(" ", 1, pflist);
+ if (pflist->width - pflist->putlen > 0 && pflist->width - pflist->putlen
+ - (pflist->precision - pflist->putlen) >= 0 && !pflist->isreverse)
+ {
+ if (!(str = malloc((ft_printf_get_len(pflist) + 1) * sizeof(char))))
+ return ;
+ str = ft_memset(str, ' ', ft_printf_get_len(pflist));
+ *(str + ft_printf_get_len(pflist)) = '\0';
+ ft_printf_cat_output(str, ft_strlen(str), pflist);
+ ft_memdel((void**)&str);
+ }
+ else if (pflist->conv == 's' && pflist->width - pflist->putlen > 0
+ && !pflist->isreverse)
+ {
+ if (!(str = malloc((ft_printf_get_len(pflist) + 1) * sizeof(char))))
+ return ;
+ str = ft_memset(str, ' ', ft_printf_get_len(pflist));
+ *(str + ft_printf_get_len(pflist)) = '\0';
+ ft_printf_cat_output(str, ft_strlen(str), pflist);
+ ft_memdel((void**)&str);
+ }
+}
+
+void
+ ft_printf_put_width_post(t_printflist *pflist)
+{
+ char *str;
+
+ if (pflist->width - pflist->putlen > 0 && pflist->width - pflist->putlen
+ - (pflist->precision - pflist->putlen) >= 0 && pflist->isreverse)
+ {
+ if (!(str = (char*)malloc((ft_printf_get_len(pflist) + 1)
+ * sizeof(char))))
+ return ;
+ str = ft_memset(str, ' ', ft_printf_get_len(pflist));
+ *(str + ft_printf_get_len(pflist)) = '\0';
+ ft_printf_cat_output(str, ft_strlen(str), pflist);
+ ft_memdel((void**)&str);
+ }
+ else if (pflist->conv == 's' && pflist->width - pflist->putlen > 0
+ && pflist->isreverse)
+ {
+ if (!(str = (char*)malloc((ft_printf_get_len(pflist) + 1)
+ * sizeof(char))))
+ return ;
+ str = ft_memset(str, ' ', ft_printf_get_len(pflist));
+ *(str + ft_printf_get_len(pflist)) = '\0';
+ ft_printf_cat_output(str, ft_strlen(str), pflist);
+ ft_memdel((void**)&str);
+ }
+}
diff --git a/libft/src/ft_printf_treat_flags.c b/libft/src/ft_printf_treat_flags.c
new file mode 100644
index 0000000..d7b11a1
--- /dev/null
+++ b/libft/src/ft_printf_treat_flags.c
@@ -0,0 +1,146 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_printf_treat_flags.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:06:45 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:06:45 by rbousset ### ########lyon.fr */
+/* */
+/* ************************************************************************** */
+
+#include <libft.h>
+#include <stdlib.h>
+#include <stdarg.h>
+
+static int
+ ft_printf_get_width(va_list arg, t_printflist *pflist)
+{
+ char *nstr;
+ char *nstr_ptr;
+ int ret;
+
+ if (ft_strlchr(pflist->fullflag, '.') >= 0)
+ nstr = ft_substr(pflist->fullflag, 0,
+ ft_strlchr(pflist->fullflag, '.'));
+ else
+ nstr = ft_strdup(pflist->fullflag);
+ nstr_ptr = nstr;
+ nstr = ft_printf_get_width_nstr(nstr, pflist);
+ ret = ft_printf_fetch_width(arg, nstr, pflist);
+ ft_memdel((void**)&nstr_ptr);
+ (ret < 0) ? (pflist->isreverse = 1) : 0;
+ (ret < 0) ? (ret = -ret) : 0;
+ return (ret);
+}
+
+static int
+ ft_printf_get_precision(va_list arg, int pos, t_printflist *pflist)
+{
+ int ret;
+ char *ptr;
+
+ ptr = pflist->fullflag;
+ if (pflist->isaz && ft_strlchr(pflist->fullflag, '+') >= 0)
+ {
+ pflist->isaplus = 1;
+ if (ft_strlen(ptr) < pflist->flaglen)
+ ptr += 1;
+ }
+ if (*(ptr + pos + 1) == '*')
+ {
+ ret = va_arg(arg, int);
+ (ret < 0) ? (ret = 0) : 0;
+ return (ret);
+ }
+ else
+ ret = ft_atoi(ptr + pos + 1);
+ if (ret == 0)
+ return (-1);
+ return (ret);
+}
+
+/*
+** Corresponding l ll hh h
+** in pflist->lh
+** hh = -2
+** h = -1
+** l = 1
+** ll = 2
+*/
+
+static void
+ ft_printf_get_lh(t_printflist *pflist)
+{
+ int pos;
+
+ if ((pos = ft_strlchr(pflist->fullflag, 'z')) >= 0)
+ pflist->zflag = 1;
+ else if ((pos = ft_strlchr(pflist->fullflag, 'l')) >= 0)
+ {
+ if (pos + 2 <= (int)pflist->flaglen &&
+ *(pflist->fullflag + pos + 1) == 'l')
+ pflist->lh = 2;
+ else
+ pflist->lh = 1;
+ }
+ else if ((pos = ft_strlchr(pflist->fullflag, 'h')) >= 0)
+ {
+ if (pos + 2 <= (int)pflist->flaglen &&
+ *(pflist->fullflag + pos + 1) == 'h')
+ pflist->lh = -2;
+ else
+ pflist->lh = -1;
+ }
+}
+
+static uint8_t
+ ft_printf_check_z(t_printflist *pflist)
+{
+ char *ptr;
+
+ ptr = pflist->fullflag;
+ while (!ft_isdigit(*ptr) && *ptr)
+ ptr++;
+ if ((ptr - pflist->fullflag) <= (long)ft_strlen(pflist->fullflag)
+ && (*ptr == '0') && ft_strlchr(pflist->fullflag, '.') < 0)
+ return (1);
+ return (0);
+}
+
+/*
+** Uses pflist->fullflag to put
+** width and precision in the list
+** also l ll hh h
+*/
+
+void
+ ft_printf_treat_flags(va_list arg, t_printflist *pflist)
+{
+ int pos;
+ char c;
+
+ pflist->flaglen = ft_strlen(pflist->fullflag);
+ if (((pflist->isaz = ft_printf_check_z(pflist)) == 1
+ && ft_strlchr(pflist->fullflag, '.') < 0
+ && ft_strlchr(pflist->fullflag, '-') < 0))
+ pflist->precision = ft_printf_get_precision(arg, 0, pflist);
+ else
+ {
+ pflist->width = ft_printf_get_width(arg, pflist);
+ (pflist->isaspace >= 0) ? (pflist->isaspace = 1) : 0;
+ if ((pos = ft_strlchr(pflist->fullflag, '.')) >= 0)
+ pflist->precision = ft_printf_get_precision(arg, pos, pflist);
+ }
+ (pflist->isaz && pflist->width) ? (pflist->isaz = 0) : 0;
+ (ft_strlchr(pflist->fullflag, '#') >= 0) ? (pflist->issharp = 1) : 0;
+ c = pflist->actconv;
+ if (ft_strlchr(pflist->fullflag, '.') < 0 && pflist->isaz
+ && pflist->precision < 0 && c != 'c' && c != 's' && c != '%')
+ {
+ pflist->precision = 0;
+ pflist->isaz = 0;
+ }
+ ft_printf_get_lh(pflist);
+}
diff --git a/libft/src/ft_printf_use_flags.c b/libft/src/ft_printf_use_flags.c
new file mode 100644
index 0000000..562d499
--- /dev/null
+++ b/libft/src/ft_printf_use_flags.c
@@ -0,0 +1,67 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_printf_use_flags.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:06:45 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:06:45 by rbousset ### ########lyon.fr */
+/* */
+/* ************************************************************************** */
+
+#include <libft.h>
+#include <stdlib.h>
+
+static void
+ ft_printf_noflags(const char *format,
+ int pos,
+ va_list arg,
+ t_printflist *pflist)
+{
+ ft_printf_process(format + pos, arg, pflist);
+}
+
+static void
+ ft_printf_withflags(const char *format,
+ int pos,
+ va_list arg,
+ t_printflist *pflist)
+{
+ ft_memdel((void**)&pflist->fullflag);
+ pflist->fullflag = ft_printf_get_flags(format, pos, pflist);
+ ft_printf_treat_flags(arg, pflist);
+ ft_printf_process(format + pos, arg, pflist);
+}
+
+int
+ ft_printf_flags(const char *format,
+ int pos,
+ va_list arg,
+ t_printflist *pflist)
+{
+ int plen;
+
+ plen = 0;
+ if (ft_ischarset(FT_PRINTF_CONV_CHARSET, *(format + pos + 1)))
+ {
+ ft_printf_noflags(format, pos, arg, pflist);
+ plen = ft_printf_get_partlen(format + pos + 2);
+ ft_printf_putpart(format, pos + 2, plen, pflist);
+ if (plen == (int)ft_strlen(format + pos + 2))
+ return (-1);
+ else
+ return (pos + plen + 2);
+ }
+ else
+ {
+ ft_printf_withflags(format, pos, arg, pflist);
+ plen = ft_printf_get_partlen(format + pos + pflist->flaglen + 2);
+ ft_printf_putpart(format, pos + pflist->flaglen + 2,
+ plen, pflist);
+ if (plen == (int)ft_strlen(format + pos + pflist->flaglen + 2))
+ return (-1);
+ else
+ return (pos + plen + pflist->flaglen + 2);
+ }
+}
diff --git a/libft/src/ft_putchar.c b/libft/src/ft_putchar.c
index b558ead..b48bd32 100644
--- a/libft/src/ft_putchar.c
+++ b/libft/src/ft_putchar.c
@@ -1,14 +1,13 @@
/* ************************************************************************** */
-/* LE - / */
-/* / */
-/* ft_putchar.c .:: .:/ . .:: */
-/* +:+:+ +: +: +:+:+ */
-/* By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ */
-/* #+# #+ #+ #+# */
-/* Created: 2019/10/12 15:02:55 by rbousset #+# ## ## #+# */
-/* Updated: 2019/10/15 01:10:32 by rbousset ### #+. /#+ ###.fr */
-/* / */
-/* / */
+/* */
+/* ::: :::::::: */
+/* ft_putchar.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:06:56 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:06:56 by rbousset ### ########lyon.fr */
+/* */
/* ************************************************************************** */
#include <unistd.h>
diff --git a/libft/src/ft_putchar_fd.c b/libft/src/ft_putchar_fd.c
index a8fed8f..7e32ea7 100644
--- a/libft/src/ft_putchar_fd.c
+++ b/libft/src/ft_putchar_fd.c
@@ -1,14 +1,13 @@
/* ************************************************************************** */
-/* LE - / */
-/* / */
-/* ft_putchar_fd.c .:: .:/ . .:: */
-/* +:+:+ +: +: +:+:+ */
-/* By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ */
-/* #+# #+ #+ #+# */
-/* Created: 2019/10/13 08:27:19 by rbousset #+# ## ## #+# */
-/* Updated: 2019/10/13 08:49:34 by rbousset ### #+. /#+ ###.fr */
-/* / */
-/* / */
+/* */
+/* ::: :::::::: */
+/* ft_putchar_fd.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:06:57 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:06:57 by rbousset ### ########lyon.fr */
+/* */
/* ************************************************************************** */
#include <unistd.h>
diff --git a/libft/src/ft_putendl.c b/libft/src/ft_putendl.c
index e2ab518..8ffbd60 100644
--- a/libft/src/ft_putendl.c
+++ b/libft/src/ft_putendl.c
@@ -1,14 +1,13 @@
/* ************************************************************************** */
-/* LE - / */
-/* / */
-/* ft_putendl.c .:: .:/ . .:: */
-/* +:+:+ +: +: +:+:+ */
-/* By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ */
-/* #+# #+ #+ #+# */
-/* Created: 2019/10/15 05:19:52 by rbousset #+# ## ## #+# */
-/* Updated: 2019/10/15 05:19:53 by rbousset ### #+. /#+ ###.fr */
-/* / */
-/* / */
+/* */
+/* ::: :::::::: */
+/* ft_putendl.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:06:58 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:06:58 by rbousset ### ########lyon.fr */
+/* */
/* ************************************************************************** */
#include <libft.h>
diff --git a/libft/src/ft_putendl_fd.c b/libft/src/ft_putendl_fd.c
index 9b0f495..c8c6401 100644
--- a/libft/src/ft_putendl_fd.c
+++ b/libft/src/ft_putendl_fd.c
@@ -1,14 +1,13 @@
/* ************************************************************************** */
-/* LE - / */
-/* / */
-/* ft_putendl_fd.c .:: .:/ . .:: */
-/* +:+:+ +: +: +:+:+ */
-/* By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ */
-/* #+# #+ #+ #+# */
-/* Created: 2019/10/13 08:52:34 by rbousset #+# ## ## #+# */
-/* Updated: 2019/10/13 09:01:41 by rbousset ### #+. /#+ ###.fr */
-/* / */
-/* / */
+/* */
+/* ::: :::::::: */
+/* ft_putendl_fd.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:06:59 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:06:59 by rbousset ### ########lyon.fr */
+/* */
/* ************************************************************************** */
#include <libft.h>
diff --git a/libft/src/ft_putnbr.c b/libft/src/ft_putnbr.c
index a3a1e24..3aacca3 100644
--- a/libft/src/ft_putnbr.c
+++ b/libft/src/ft_putnbr.c
@@ -1,14 +1,13 @@
/* ************************************************************************** */
-/* LE - / */
-/* / */
-/* ft_putnbr.c .:: .:/ . .:: */
-/* +:+:+ +: +: +:+:+ */
-/* By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ */
-/* #+# #+ #+ #+# */
-/* Created: 2019/08/08 12:22:48 by rbousset #+# ## ## #+# */
-/* Updated: 2019/08/12 17:54:48 by rbousset ### #+. /#+ ###.fr */
-/* / */
-/* / */
+/* */
+/* ::: :::::::: */
+/* ft_putnbr.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:07:00 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:07:00 by rbousset ### ########lyon.fr */
+/* */
/* ************************************************************************** */
#include <libft.h>
@@ -16,9 +15,9 @@
#include <inttypes.h>
void
- ft_putnbr(long long nb)
+ ft_putnbr(long nb)
{
- long long i;
+ long i;
i = nb;
if (nb < 0)
diff --git a/libft/src/ft_putnbr_base.c b/libft/src/ft_putnbr_base.c
index 7ec0a85..3a04cad 100644
--- a/libft/src/ft_putnbr_base.c
+++ b/libft/src/ft_putnbr_base.c
@@ -1,23 +1,22 @@
/* ************************************************************************** */
-/* LE - / */
-/* / */
-/* ft_putnbr_base.c .:: .:/ . .:: */
-/* +:+:+ +: +: +:+:+ */
-/* By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ */
-/* #+# #+ #+ #+# */
-/* Created: 2019/12/19 15:00:38 by rbousset #+# ## ## #+# */
-/* Updated: 2019/12/19 15:00:40 by rbousset ### #+. /#+ ###.fr */
-/* / */
-/* / */
+/* */
+/* ::: :::::::: */
+/* ft_putnbr_base.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:07:01 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:07:01 by rbousset ### ########lyon.fr */
+/* */
/* ************************************************************************** */
#include <libft.h>
#include <inttypes.h>
void
- ft_putnbr_base(long long nb, char *base)
+ ft_putnbr_base(long nb, char *base)
{
- long long i;
+ long i;
uint8_t size;
i = nb;
diff --git a/libft/src/ft_putnbr_fd.c b/libft/src/ft_putnbr_fd.c
index 3246976..437a6e6 100644
--- a/libft/src/ft_putnbr_fd.c
+++ b/libft/src/ft_putnbr_fd.c
@@ -1,14 +1,13 @@
/* ************************************************************************** */
-/* LE - / */
-/* / */
-/* ft_putnbr_fd.c .:: .:/ . .:: */
-/* +:+:+ +: +: +:+:+ */
-/* By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ */
-/* #+# #+ #+ #+# */
-/* Created: 2019/10/13 08:57:19 by rbousset #+# ## ## #+# */
-/* Updated: 2019/10/13 12:13:09 by rbousset ### #+. /#+ ###.fr */
-/* / */
-/* / */
+/* */
+/* ::: :::::::: */
+/* ft_putnbr_fd.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:07:02 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:07:02 by rbousset ### ########lyon.fr */
+/* */
/* ************************************************************************** */
#include <libft.h>
diff --git a/libft/src/ft_putnchar.c b/libft/src/ft_putnchar.c
index 5d20f4c..5fdfc3f 100644
--- a/libft/src/ft_putnchar.c
+++ b/libft/src/ft_putnchar.c
@@ -1,14 +1,13 @@
/* ************************************************************************** */
-/* LE - / */
-/* / */
-/* ft_putnchar.c .:: .:/ . .:: */
-/* +:+:+ +: +: +:+:+ */
-/* By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ */
-/* #+# #+ #+ #+# */
-/* Created: 2019/12/22 16:49:05 by rbousset #+# ## ## #+# */
-/* Updated: 2019/12/22 16:49:07 by rbousset ### #+. /#+ ###.fr */
-/* / */
-/* / */
+/* */
+/* ::: :::::::: */
+/* ft_putnchar.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:07:03 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:07:03 by rbousset ### ########lyon.fr */
+/* */
/* ************************************************************************** */
#include <libft.h>
diff --git a/libft/src/ft_putstr.c b/libft/src/ft_putstr.c
index 572e989..5cd7a6d 100644
--- a/libft/src/ft_putstr.c
+++ b/libft/src/ft_putstr.c
@@ -1,14 +1,13 @@
/* ************************************************************************** */
-/* LE - / */
-/* / */
-/* ft_putstr.c .:: .:/ . .:: */
-/* +:+:+ +: +: +:+:+ */
-/* By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ */
-/* #+# #+ #+ #+# */
-/* Created: 2019/10/13 09:05:27 by rbousset #+# ## ## #+# */
-/* Updated: 2019/10/13 09:07:45 by rbousset ### #+. /#+ ###.fr */
-/* / */
-/* / */
+/* */
+/* ::: :::::::: */
+/* ft_putstr.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:07:03 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:07:03 by rbousset ### ########lyon.fr */
+/* */
/* ************************************************************************** */
#include <libft.h>
diff --git a/libft/src/ft_putstr_fd.c b/libft/src/ft_putstr_fd.c
index 068d959..ae827a1 100644
--- a/libft/src/ft_putstr_fd.c
+++ b/libft/src/ft_putstr_fd.c
@@ -1,14 +1,13 @@
/* ************************************************************************** */
-/* LE - / */
-/* / */
-/* ft_putstr_fd.c .:: .:/ . .:: */
-/* +:+:+ +: +: +:+:+ */
-/* By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ */
-/* #+# #+ #+ #+# */
-/* Created: 2019/10/13 08:48:25 by rbousset #+# ## ## #+# */
-/* Updated: 2019/10/13 09:00:42 by rbousset ### #+. /#+ ###.fr */
-/* / */
-/* / */
+/* */
+/* ::: :::::::: */
+/* ft_putstr_fd.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:07:04 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:07:04 by rbousset ### ########lyon.fr */
+/* */
/* ************************************************************************** */
#include <libft.h>
diff --git a/libft/src/ft_realloc.c b/libft/src/ft_realloc.c
deleted file mode 100644
index 34b43c3..0000000
--- a/libft/src/ft_realloc.c
+++ /dev/null
@@ -1,26 +0,0 @@
-#include <libft.h>
-#include <stddef.h>
-#include <stdlib.h>
-
-void
- *ft_realloc(void *ptr, size_t size)
-{
- void *nptr;
-
- if (!ptr)
- {
- if (!(ptr = malloc(size)))
- return (NULL);
- return (ptr);
- }
- else if (!size)
- {
- free(ptr);
- return (NULL);
- }
- if (!(nptr = malloc(size)))
- return (ptr);
- ft_memcpy(nptr, ptr, ft_strlen(ptr));
- free(ptr);
- return (nptr);
-}
diff --git a/libft/src/ft_split.c b/libft/src/ft_split.c
index f0cac95..3035a00 100644
--- a/libft/src/ft_split.c
+++ b/libft/src/ft_split.c
@@ -1,14 +1,13 @@
/* ************************************************************************** */
-/* LE - / */
-/* / */
-/* ft_split.c .:: .:/ . .:: */
-/* +:+:+ +: +: +:+:+ */
-/* By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ */
-/* #+# #+ #+ #+# */
-/* Created: 2019/10/12 19:24:20 by rbousset #+# ## ## #+# */
-/* Updated: 2019/10/13 08:37:16 by rbousset ### #+. /#+ ###.fr */
-/* / */
-/* / */
+/* */
+/* ::: :::::::: */
+/* ft_split.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:07:05 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:07:05 by rbousset ### ########lyon.fr */
+/* */
/* ************************************************************************** */
#include <libft.h>
@@ -16,16 +15,8 @@
#include <stdlib.h>
#include <inttypes.h>
-static uint8_t
- ft_check(int c, char sep)
-{
- if (c == sep)
- return (1);
- return (0);
-}
-
static size_t
- ft_strlen_plus(const char *str, char c)
+ ft_count_words(const char *s, char c)
{
size_t i;
size_t count;
@@ -34,11 +25,11 @@ static size_t
i = 0;
count = 0;
ibool = 1;
- while (str[i])
+ while (s[i])
{
- while (ft_check(str[i], c) && str[i])
+ while (s[i] == c && s[i])
i++;
- while (!ft_check(str[i], c) && str[i])
+ while (s[i] != c && s[i])
{
if (ibool == 1)
count++;
@@ -51,59 +42,70 @@ static size_t
}
static size_t
- ft_strlen_again(const char *str, char c)
+ ft_splitlen(const char *str, char c)
{
size_t i;
i = 0;
- while (!ft_check(str[i], c) && str[i])
+ while (str[i] != c && str[i])
i++;
return (i);
}
static char
- *ft_strdup_plus(const char *src, char c)
+ *ft_splitdup(const char *str, char c)
{
+ char *word;
size_t i;
- size_t slen;
- char *nstr;
i = 0;
- slen = ft_strlen_again(src, c) + 1;
- if (!(nstr = (char*)ft_calloc(slen, sizeof(char))))
+ if (!(word = (char*)malloc((ft_splitlen(str, c) + 1) * sizeof(char))))
return (NULL);
- while (!ft_check(src[i], c) && src[i])
+ while (str[i] != c && str[i])
{
- nstr[i] = src[i];
+ word[i] = str[i];
i++;
}
- nstr[i] = '\0';
- return (nstr);
+ word[i] = '\0';
+ return (word);
+}
+
+static char
+ **ft_splitfree(char **best_split, size_t j)
+{
+ while (j > 0)
+ {
+ ft_memdel((void**)&best_split[j]);
+ j--;
+ }
+ ft_memdel((void**)best_split);
+ return (NULL);
}
char
**ft_split(const char *s, char c)
{
+ char **best_split;
size_t i;
size_t j;
- char **best_split;
i = 0;
j = 0;
- if (!(best_split = (char **)ft_calloc(ft_strlen_plus(s, c) + 1,
- sizeof(char *))))
+ if (!(best_split = (char **)malloc((ft_count_words(s, c) + 1)
+ * sizeof(char *))))
return (NULL);
while (s[i])
{
- while (ft_check(s[i], c) && s[i])
+ while (s[i] == c && s[i])
i++;
- while (!ft_check(s[i], c) && s[i])
+ while (s[i] != c && s[i])
{
- best_split[j] = ft_strdup_plus(&s[i], c);
- i += ft_strlen_again(&s[i], c);
+ if (!(best_split[j] = ft_splitdup(s + i, c)))
+ return (ft_splitfree(best_split, j));
+ i += ft_splitlen(s + i, c);
j++;
}
}
- best_split[j] = 0;
+ best_split[j] = NULL;
return (best_split);
}
diff --git a/libft/src/ft_sprintf.c b/libft/src/ft_sprintf.c
new file mode 100644
index 0000000..8413505
--- /dev/null
+++ b/libft/src/ft_sprintf.c
@@ -0,0 +1,57 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_sprintf.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:07:06 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:07:06 by rbousset ### ########lyon.fr */
+/* */
+/* ************************************************************************** */
+
+#include <libft.h>
+#include <stddef.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <unistd.h>
+
+static int
+ ft_printf_return(char *str, t_printflist *pflist)
+{
+ int ret;
+
+ ft_strlcpy(str, pflist->output, pflist->fulllen + 1);
+ ret = pflist->fulllen;
+ ft_memdel((void**)&pflist->output);
+ ft_memdel((void**)&pflist->fullflag);
+ ft_memdel((void**)&pflist);
+ return (ret);
+}
+
+int
+ ft_sprintf(char *str, const char *format, ...)
+{
+ t_printflist *pflist;
+ va_list arg;
+ int pos;
+
+ if (!format)
+ return (-1);
+ if ((pos = ft_strlchr(format, '%')) < 0)
+ return (ft_strlcpy(str, format, ft_strlen(format) + 1));
+ else
+ {
+ pflist = ft_printf_init_struct(format);
+ ft_printf_putpart(format, 0, pos, pflist);
+ va_start(arg, format);
+ while (pos >= 0)
+ {
+ pos = ft_printf_flags(format, pos, arg, pflist);
+ ft_printf_reinit_struct(pflist);
+ }
+ va_end(arg);
+ return (ft_printf_return(str, pflist));
+ }
+ return (0);
+}
diff --git a/libft/src/ft_sqrt.c b/libft/src/ft_sqrt.c
index 3003e6d..ed69117 100644
--- a/libft/src/ft_sqrt.c
+++ b/libft/src/ft_sqrt.c
@@ -1,14 +1,13 @@
/* ************************************************************************** */
-/* LE - / */
-/* / */
-/* ft_sqrt.c .:: .:/ . .:: */
-/* +:+:+ +: +: +:+:+ */
-/* By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ */
-/* #+# #+ #+ #+# */
-/* Created: 2019/08/10 21:34:14 by rbousset #+# ## ## #+# */
-/* Updated: 2019/10/14 23:26:06 by rbousset ### #+. /#+ ###.fr */
-/* / */
-/* / */
+/* */
+/* ::: :::::::: */
+/* ft_sqrt.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:07:06 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:07:06 by rbousset ### ########lyon.fr */
+/* */
/* ************************************************************************** */
#include <limits.h>
diff --git a/libft/src/ft_strcat.c b/libft/src/ft_strcat.c
index 59084c2..b43e439 100644
--- a/libft/src/ft_strcat.c
+++ b/libft/src/ft_strcat.c
@@ -1,14 +1,13 @@
/* ************************************************************************** */
-/* LE - / */
-/* / */
-/* ft_strcat.c .:: .:/ . .:: */
-/* +:+:+ +: +: +:+:+ */
-/* By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ */
-/* #+# #+ #+ #+# */
-/* Created: 2019/10/12 16:31:34 by rbousset #+# ## ## #+# */
-/* Updated: 2019/10/13 08:44:34 by rbousset ### #+. /#+ ###.fr */
-/* / */
-/* / */
+/* */
+/* ::: :::::::: */
+/* ft_strcat.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:07:07 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:07:07 by rbousset ### ########lyon.fr */
+/* */
/* ************************************************************************** */
char
diff --git a/libft/src/ft_strchr.c b/libft/src/ft_strchr.c
index 40dcd0f..1f2e745 100644
--- a/libft/src/ft_strchr.c
+++ b/libft/src/ft_strchr.c
@@ -1,14 +1,13 @@
/* ************************************************************************** */
-/* LE - / */
-/* / */
-/* ft_strchr.c .:: .:/ . .:: */
-/* +:+:+ +: +: +:+:+ */
-/* By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ */
-/* #+# #+ #+ #+# */
-/* Created: 2019/10/07 18:39:17 by rbousset #+# ## ## #+# */
-/* Updated: 2019/10/13 08:36:43 by rbousset ### #+. /#+ ###.fr */
-/* / */
-/* / */
+/* */
+/* ::: :::::::: */
+/* ft_strchr.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:07:07 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:07:07 by rbousset ### ########lyon.fr */
+/* */
/* ************************************************************************** */
#include <stddef.h>
@@ -16,14 +15,16 @@
char
*ft_strchr(const char *s, int c)
{
- size_t i;
+ char ch;
- i = 0;
- while (s[i] != c)
+ ch = (char)c;
+ while (s)
{
- if (!s[i])
+ if (*s == ch)
+ return ((char *)s);
+ if (*s == '\0')
return (NULL);
- i++;
+ s++;
}
- return ((char*)&s[i]);
+ return (NULL);
}
diff --git a/libft/src/ft_strcmp.c b/libft/src/ft_strcmp.c
index ca5cf60..4122ab2 100644
--- a/libft/src/ft_strcmp.c
+++ b/libft/src/ft_strcmp.c
@@ -1,14 +1,13 @@
/* ************************************************************************** */
-/* LE - / */
-/* / */
-/* ft_strcmp.c .:: .:/ . .:: */
-/* +:+:+ +: +: +:+:+ */
-/* By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ */
-/* #+# #+ #+ #+# */
-/* Created: 2019/10/13 13:55:24 by rbousset #+# ## ## #+# */
-/* Updated: 2019/10/13 13:56:42 by rbousset ### #+. /#+ ###.fr */
-/* / */
-/* / */
+/* */
+/* ::: :::::::: */
+/* ft_strcmp.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:07:08 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:07:08 by rbousset ### ########lyon.fr */
+/* */
/* ************************************************************************** */
#include <libft.h>
@@ -17,7 +16,7 @@
int
ft_strcmp(const char *s1, const char *s2)
{
- size_t i;
+ size_t i;
i = 0;
while (s1[i] == s2[i] && i < ft_strlen(s1) - 1)
diff --git a/libft/src/ft_strdup.c b/libft/src/ft_strdup.c
index 830c965..ab5b5c1 100644
--- a/libft/src/ft_strdup.c
+++ b/libft/src/ft_strdup.c
@@ -1,14 +1,13 @@
/* ************************************************************************** */
-/* LE - / */
-/* / */
-/* ft_strdup.c .:: .:/ . .:: */
-/* +:+:+ +: +: +:+:+ */
-/* By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ */
-/* #+# #+ #+ #+# */
-/* Created: 2019/10/11 05:45:32 by rbousset #+# ## ## #+# */
-/* Updated: 2019/10/13 08:36:24 by rbousset ### #+. /#+ ###.fr */
-/* / */
-/* / */
+/* */
+/* ::: :::::::: */
+/* ft_strdup.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:07:09 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:07:09 by rbousset ### ########lyon.fr */
+/* */
/* ************************************************************************** */
#include <libft.h>
diff --git a/libft/src/ft_strjoin.c b/libft/src/ft_strjoin.c
index 2e00daf..90650d0 100644
--- a/libft/src/ft_strjoin.c
+++ b/libft/src/ft_strjoin.c
@@ -1,14 +1,13 @@
/* ************************************************************************** */
-/* LE - / */
-/* / */
-/* ft_strjoin.c .:: .:/ . .:: */
-/* +:+:+ +: +: +:+:+ */
-/* By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ */
-/* #+# #+ #+ #+# */
-/* Created: 2019/10/12 16:35:23 by rbousset #+# ## ## #+# */
-/* Updated: 2019/10/13 08:36:17 by rbousset ### #+. /#+ ###.fr */
-/* / */
-/* / */
+/* */
+/* ::: :::::::: */
+/* ft_strjoin.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:07:10 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:07:10 by rbousset ### ########lyon.fr */
+/* */
/* ************************************************************************** */
#include <libft.h>
diff --git a/libft/src/ft_strlcat.c b/libft/src/ft_strlcat.c
index 4b6f036..b9feae1 100644
--- a/libft/src/ft_strlcat.c
+++ b/libft/src/ft_strlcat.c
@@ -1,14 +1,13 @@
/* ************************************************************************** */
-/* LE - / */
-/* / */
-/* ft_strlcat.c .:: .:/ . .:: */
-/* +:+:+ +: +: +:+:+ */
-/* By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ */
-/* #+# #+ #+ #+# */
-/* Created: 2019/10/09 06:44:30 by rbousset #+# ## ## #+# */
-/* Updated: 2019/10/13 08:36:04 by rbousset ### #+. /#+ ###.fr */
-/* / */
-/* / */
+/* */
+/* ::: :::::::: */
+/* ft_strlcat.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:07:10 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:07:10 by rbousset ### ########lyon.fr */
+/* */
/* ************************************************************************** */
#include <libft.h>
diff --git a/libft/src/ft_strlchr.c b/libft/src/ft_strlchr.c
new file mode 100644
index 0000000..228aa89
--- /dev/null
+++ b/libft/src/ft_strlchr.c
@@ -0,0 +1,25 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_strlchr.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:07:11 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:07:11 by rbousset ### ########lyon.fr */
+/* */
+/* ************************************************************************** */
+
+#include <libft.h>
+#include <stddef.h>
+
+long
+ ft_strlchr(const char *s, int c)
+{
+ const size_t len = ft_strlen(s);
+ const size_t rem = ft_strlen(ft_strchr(s, c));
+
+ if (len - rem >= ft_strlen(s))
+ return (-1);
+ return (len - rem);
+}
diff --git a/libft/src/ft_strlcpy.c b/libft/src/ft_strlcpy.c
index 9331f1c..ed4d924 100644
--- a/libft/src/ft_strlcpy.c
+++ b/libft/src/ft_strlcpy.c
@@ -1,14 +1,13 @@
/* ************************************************************************** */
-/* LE - / */
-/* / */
-/* ft_strlcpy.c .:: .:/ . .:: */
-/* +:+:+ +: +: +:+:+ */
-/* By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ */
-/* #+# #+ #+ #+# */
-/* Created: 2019/10/08 20:44:40 by rbousset #+# ## ## #+# */
-/* Updated: 2019/10/13 08:35:51 by rbousset ### #+. /#+ ###.fr */
-/* / */
-/* / */
+/* */
+/* ::: :::::::: */
+/* ft_strlcpy.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:07:11 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:07:11 by rbousset ### ########lyon.fr */
+/* */
/* ************************************************************************** */
#include <libft.h>
diff --git a/libft/src/ft_strlen.c b/libft/src/ft_strlen.c
index 0964c64..90f5110 100644
--- a/libft/src/ft_strlen.c
+++ b/libft/src/ft_strlen.c
@@ -1,14 +1,13 @@
/* ************************************************************************** */
-/* LE - / */
-/* / */
-/* ft_strlen.c .:: .:/ . .:: */
-/* +:+:+ +: +: +:+:+ */
-/* By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ */
-/* #+# #+ #+ #+# */
-/* Created: 2019/10/07 16:32:28 by rbousset #+# ## ## #+# */
-/* Updated: 2019/10/13 08:35:37 by rbousset ### #+. /#+ ###.fr */
-/* / */
-/* / */
+/* */
+/* ::: :::::::: */
+/* ft_strlen.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:07:12 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:07:12 by rbousset ### ########lyon.fr */
+/* */
/* ************************************************************************** */
#include <stddef.h>
diff --git a/libft/src/ft_strmapi.c b/libft/src/ft_strmapi.c
index 8a47875..fe455c1 100644
--- a/libft/src/ft_strmapi.c
+++ b/libft/src/ft_strmapi.c
@@ -1,14 +1,13 @@
/* ************************************************************************** */
-/* LE - / */
-/* / */
-/* ft_strmapi.c .:: .:/ . .:: */
-/* +:+:+ +: +: +:+:+ */
-/* By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ */
-/* #+# #+ #+ #+# */
-/* Created: 2019/10/13 05:57:35 by rbousset #+# ## ## #+# */
-/* Updated: 2019/10/13 08:35:12 by rbousset ### #+. /#+ ###.fr */
-/* / */
-/* / */
+/* */
+/* ::: :::::::: */
+/* ft_strmapi.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:07:13 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:07:13 by rbousset ### ########lyon.fr */
+/* */
/* ************************************************************************** */
#include <libft.h>
diff --git a/libft/src/ft_strncmp.c b/libft/src/ft_strncmp.c
index 3bccfd5..30a4562 100644
--- a/libft/src/ft_strncmp.c
+++ b/libft/src/ft_strncmp.c
@@ -1,14 +1,13 @@
/* ************************************************************************** */
-/* LE - / */
-/* / */
-/* ft_strncmp.c .:: .:/ . .:: */
-/* +:+:+ +: +: +:+:+ */
-/* By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ */
-/* #+# #+ #+ #+# */
-/* Created: 2019/10/07 20:25:31 by rbousset #+# ## ## #+# */
-/* Updated: 2019/10/13 08:35:01 by rbousset ### #+. /#+ ###.fr */
-/* / */
-/* / */
+/* */
+/* ::: :::::::: */
+/* ft_strncmp.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:07:13 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:07:13 by rbousset ### ########lyon.fr */
+/* */
/* ************************************************************************** */
#include <stddef.h>
diff --git a/libft/src/ft_strnlen.c b/libft/src/ft_strnlen.c
index d9d20a1..325fa0d 100644
--- a/libft/src/ft_strnlen.c
+++ b/libft/src/ft_strnlen.c
@@ -1,14 +1,13 @@
/* ************************************************************************** */
-/* LE - / */
-/* / */
-/* ft_strnlen.c .:: .:/ . .:: */
-/* +:+:+ +: +: +:+:+ */
-/* By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ */
-/* #+# #+ #+ #+# */
-/* Created: 2019/10/30 14:28:01 by rbousset #+# ## ## #+# */
-/* Updated: 2019/10/30 14:28:03 by rbousset ### #+. /#+ ###.fr */
-/* / */
-/* / */
+/* */
+/* ::: :::::::: */
+/* ft_strnlen.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:07:14 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:07:14 by rbousset ### ########lyon.fr */
+/* */
/* ************************************************************************** */
#include <stddef.h>
diff --git a/libft/src/ft_strnstr.c b/libft/src/ft_strnstr.c
index 711629d..58e1d0e 100644
--- a/libft/src/ft_strnstr.c
+++ b/libft/src/ft_strnstr.c
@@ -1,14 +1,13 @@
/* ************************************************************************** */
-/* LE - / */
-/* / */
-/* ft_strnstr.c .:: .:/ . .:: */
-/* +:+:+ +: +: +:+:+ */
-/* By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ */
-/* #+# #+ #+ #+# */
-/* Created: 2019/10/10 00:23:15 by rbousset #+# ## ## #+# */
-/* Updated: 2019/10/13 08:34:35 by rbousset ### #+. /#+ ###.fr */
-/* / */
-/* / */
+/* */
+/* ::: :::::::: */
+/* ft_strnstr.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:07:14 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:07:14 by rbousset ### ########lyon.fr */
+/* */
/* ************************************************************************** */
#include <libft.h>
diff --git a/libft/src/ft_strrchr.c b/libft/src/ft_strrchr.c
index ada7470..1ebbdc3 100644
--- a/libft/src/ft_strrchr.c
+++ b/libft/src/ft_strrchr.c
@@ -1,14 +1,13 @@
/* ************************************************************************** */
-/* LE - / */
-/* / */
-/* ft_strrchr.c .:: .:/ . .:: */
-/* +:+:+ +: +: +:+:+ */
-/* By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ */
-/* #+# #+ #+ #+# */
-/* Created: 2019/10/07 19:07:53 by rbousset #+# ## ## #+# */
-/* Updated: 2019/10/13 08:34:19 by rbousset ### #+. /#+ ###.fr */
-/* / */
-/* / */
+/* */
+/* ::: :::::::: */
+/* ft_strrchr.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:07:15 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:07:15 by rbousset ### ########lyon.fr */
+/* */
/* ************************************************************************** */
#include <libft.h>
diff --git a/libft/src/ft_strtrim.c b/libft/src/ft_strtrim.c
index 48fdad5..69fd95a 100644
--- a/libft/src/ft_strtrim.c
+++ b/libft/src/ft_strtrim.c
@@ -1,14 +1,13 @@
/* ************************************************************************** */
-/* LE - / */
-/* / */
-/* ft_strtrim.c .:: .:/ . .:: */
-/* +:+:+ +: +: +:+:+ */
-/* By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ */
-/* #+# #+ #+ #+# */
-/* Created: 2019/10/12 17:30:33 by rbousset #+# ## ## #+# */
-/* Updated: 2019/10/13 08:34:03 by rbousset ### #+. /#+ ###.fr */
-/* / */
-/* / */
+/* */
+/* ::: :::::::: */
+/* ft_strtrim.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:07:15 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:07:15 by rbousset ### ########lyon.fr */
+/* */
/* ************************************************************************** */
#include <libft.h>
diff --git a/libft/src/ft_substr.c b/libft/src/ft_substr.c
index 0cb9733..6d94368 100644
--- a/libft/src/ft_substr.c
+++ b/libft/src/ft_substr.c
@@ -1,14 +1,13 @@
/* ************************************************************************** */
-/* LE - / */
-/* / */
-/* ft_substr.c .:: .:/ . .:: */
-/* +:+:+ +: +: +:+:+ */
-/* By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ */
-/* #+# #+ #+ #+# */
-/* Created: 2019/10/12 15:37:02 by rbousset #+# ## ## #+# */
-/* Updated: 2019/10/13 08:33:09 by rbousset ### #+. /#+ ###.fr */
-/* / */
-/* / */
+/* */
+/* ::: :::::::: */
+/* ft_substr.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:07:15 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:07:15 by rbousset ### ########lyon.fr */
+/* */
/* ************************************************************************** */
#include <libft.h>
diff --git a/libft/src/ft_tolower.c b/libft/src/ft_tolower.c
index 48c065e..1877dbb 100644
--- a/libft/src/ft_tolower.c
+++ b/libft/src/ft_tolower.c
@@ -1,14 +1,13 @@
/* ************************************************************************** */
-/* LE - / */
-/* / */
-/* ft_tolower.c .:: .:/ . .:: */
-/* +:+:+ +: +: +:+:+ */
-/* By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ */
-/* #+# #+ #+ #+# */
-/* Created: 2019/10/07 18:32:59 by rbousset #+# ## ## #+# */
-/* Updated: 2019/10/13 08:32:22 by rbousset ### #+. /#+ ###.fr */
-/* / */
-/* / */
+/* */
+/* ::: :::::::: */
+/* ft_tolower.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:07:16 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:07:16 by rbousset ### ########lyon.fr */
+/* */
/* ************************************************************************** */
static int
diff --git a/libft/src/ft_toupper.c b/libft/src/ft_toupper.c
index 3346cc3..864ef70 100644
--- a/libft/src/ft_toupper.c
+++ b/libft/src/ft_toupper.c
@@ -1,14 +1,13 @@
/* ************************************************************************** */
-/* LE - / */
-/* / */
-/* ft_toupper.c .:: .:/ . .:: */
-/* +:+:+ +: +: +:+:+ */
-/* By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ */
-/* #+# #+ #+ #+# */
-/* Created: 2019/10/07 18:25:57 by rbousset #+# ## ## #+# */
-/* Updated: 2019/10/13 08:32:15 by rbousset ### #+. /#+ ###.fr */
-/* / */
-/* / */
+/* */
+/* ::: :::::::: */
+/* ft_toupper.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:07:16 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:07:16 by rbousset ### ########lyon.fr */
+/* */
/* ************************************************************************** */
static int
diff --git a/libft/src/ft_uintlen.c b/libft/src/ft_uintlen.c
new file mode 100644
index 0000000..da5be7b
--- /dev/null
+++ b/libft/src/ft_uintlen.c
@@ -0,0 +1,29 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_uintlen.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:07:16 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:07:16 by rbousset ### ########lyon.fr */
+/* */
+/* ************************************************************************** */
+
+#include <inttypes.h>
+
+uint8_t
+ ft_uintlen(unsigned long n)
+{
+ uint8_t len;
+
+ len = 0;
+ if (!n)
+ return (1);
+ while (n != 0)
+ {
+ n /= 10;
+ len++;
+ }
+ return (len);
+}
diff --git a/libft/src/ft_uintlen_base.c b/libft/src/ft_uintlen_base.c
new file mode 100644
index 0000000..ba96a29
--- /dev/null
+++ b/libft/src/ft_uintlen_base.c
@@ -0,0 +1,32 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_uintlen_base.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:07:17 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:07:17 by rbousset ### ########lyon.fr */
+/* */
+/* ************************************************************************** */
+
+#include <libft.h>
+#include <inttypes.h>
+
+uint8_t
+ ft_uintlen_base(unsigned long n, char *base)
+{
+ uint8_t len;
+ uint8_t size;
+
+ size = ft_strlen(base);
+ len = 0;
+ if (!n)
+ return (1);
+ while (n != 0)
+ {
+ n /= size;
+ len++;
+ }
+ return (len);
+}
diff --git a/libft/src/ft_uitoa.c b/libft/src/ft_uitoa.c
new file mode 100644
index 0000000..f1a5fa2
--- /dev/null
+++ b/libft/src/ft_uitoa.c
@@ -0,0 +1,38 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_uitoa.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:07:18 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:07:18 by rbousset ### ########lyon.fr */
+/* */
+/* ************************************************************************** */
+
+#include <libft.h>
+#include <inttypes.h>
+#include <stdlib.h>
+
+char
+ *ft_uitoa(unsigned long n)
+{
+ char *s;
+ unsigned long nb;
+ uint8_t i;
+
+ i = ft_uintlen(n) - 1;
+ if (!(s = (char*)malloc((i + 2) * sizeof(char))))
+ return (NULL);
+ if (!n)
+ s[i] = '0';
+ nb = n;
+ s[i + 1] = '\0';
+ while (nb > 0)
+ {
+ s[i] = 48 + (nb % 10);
+ nb = nb / 10;
+ i--;
+ }
+ return (s);
+}
diff --git a/libft/src/ft_uitoa_base.c b/libft/src/ft_uitoa_base.c
new file mode 100644
index 0000000..a931d29
--- /dev/null
+++ b/libft/src/ft_uitoa_base.c
@@ -0,0 +1,39 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_uitoa_base.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:07:19 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:07:19 by rbousset ### ########lyon.fr */
+/* */
+/* ************************************************************************** */
+
+#include <libft.h>
+#include <stdlib.h>
+
+char
+ *ft_uitoa_base(unsigned long n, char *base)
+{
+ char *s;
+ unsigned long nb;
+ uint8_t i;
+
+ i = ft_uintlen_base(n, base) - 1;
+ if (!(s = (char*)malloc((i + 2) * sizeof(char))))
+ return (NULL);
+ if (!n)
+ s[i] = '0';
+ s[i + 1] = '\0';
+ while (n > 0)
+ {
+ nb = n;
+ if (nb >= (unsigned long)ft_strlen(base))
+ nb = n % ft_strlen(base);
+ s[i] = base[nb];
+ n /= ft_strlen(base);
+ i--;
+ }
+ return (s);
+}
diff --git a/libft/src/get_next_line.c b/libft/src/get_next_line.c
index 2b2f084..ae64125 100644
--- a/libft/src/get_next_line.c
+++ b/libft/src/get_next_line.c
@@ -1,112 +1,100 @@
/* ************************************************************************** */
-/* LE - / */
-/* / */
-/* get_next_line.c .:: .:/ . .:: */
-/* +:+:+ +: +: +:+:+ */
-/* By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ */
-/* #+# #+ #+ #+# */
-/* Created: 2019/10/29 00:37:39 by rbousset #+# ## ## #+# */
-/* Updated: 2019/10/29 00:37:41 by rbousset ### #+. /#+ ###.fr */
-/* / */
-/* / */
+/* */
+/* ::: :::::::: */
+/* get_next_line.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:07:20 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:07:20 by rbousset ### ########lyon.fr */
+/* */
/* ************************************************************************** */
#include <libft.h>
#include <stdlib.h>
+#include <stddef.h>
+#include <stdint.h>
#include <unistd.h>
-#include <stdio.h>
-static uint8_t
- ft_linecheck(const char *str)
+static char
+ *ft_strjoin_gnl(char *s1, char *s2)
{
size_t i;
+ size_t j;
+ char *dst;
+ size_t size1;
+ size_t size2;
- i = 0;
- while (str && str[i])
- {
- if (str[i] == '\n')
- return (1);
- i++;
- }
- return (0);
-}
-
-static size_t
- ft_linelen(const char *str)
-{
- size_t i;
-
- i = 0;
- while (str[i] != '\n' && str[i] != '\0')
- i++;
- return (i);
+ i = -1;
+ j = -1;
+ size1 = ft_strlen_gnl(s1, 10);
+ size2 = ft_strlen_gnl(s2, 10);
+ if (!(dst = (char*)malloc((size1 + size2 + 1) * sizeof(char))))
+ return (NULL);
+ while (++i < size1)
+ dst[i] = s1[i];
+ while (++j < size2)
+ dst[i + j] = s2[j];
+ dst[i + j] = '\0';
+ ft_memdel((void**)&s1);
+ return (dst);
}
static int
- ft_linedup(int fd, char **str)
+ ft_read_gnl(int fd, char **line, t_gnl *curr)
{
- char *buff;
- char *tmp;
- int ret;
+ char *buf;
+ char *end;
+ int64_t size;
- if (!(buff = (char *)malloc((BUFFER_SIZE + 1) * sizeof(char))))
- return (0);
- ret = 1;
- while (!ft_linecheck(*str) && (ret = read(fd, buff, BUFFER_SIZE)) > 0)
- {
- buff[ret] = '\0';
- tmp = *str;
- *str = ft_strjoin(tmp, buff);
- free(tmp);
- }
- if (ret < 0)
- {
- free(*str);
- free(buff);
+ if (!(buf = malloc(BUFFER_SIZE + 1)))
return (-1);
- }
- free(buff);
- return (ret);
-}
-
-static int
- ft_errchck(int fd, char **line, char **str)
-{
- if (*str == NULL)
- *str = ft_nstr(0);
- if (fd < 0 || !line || BUFFER_SIZE <= 0)
+ *buf = 0;
+ *line = ft_strjoin_gnl(*line, curr->rest);
+ size = BUFFER_SIZE;
+ while ((end = ft_strchr_gnl(buf, 10)) == NULL && size == BUFFER_SIZE)
{
- free(*str);
- return (-1);
+ *line = ft_strjoin_gnl(*line, buf);
+ if ((size = read(fd, buf, BUFFER_SIZE)) == -1)
+ ft_memdel((void**)&buf);
+ if (size == -1)
+ return (-1);
+ buf[size] = 0;
}
- return (0);
+ *line = ft_strjoin_gnl(*line, buf);
+ if (end)
+ curr->rest = ft_swap_gnl(end + 1, curr->rest);
+ ft_memdel((void**)&buf);
+ if (!end)
+ return (0);
+ return (size);
}
int
get_next_line(int fd, char **line)
{
- static char *str[1024];
- char *tmp;
- size_t i;
- int ret;
+ static t_gnl *list;
+ t_gnl *curr;
+ char *end;
+ int size;
- if (ft_errchck(fd, line, &str[fd]) == -1)
+ if (fd < 0 || BUFFER_SIZE <= 0)
return (-1);
- ret = ft_linedup(fd, &str[fd]);
- if (ret < 0)
+ if (!(*line = (char *)malloc(1 * sizeof(char))))
return (-1);
- i = ft_linelen(str[fd]);
- *line = ft_substr(str[fd], 0, i);
- tmp = str[fd];
- if (tmp[0] != '\0' && tmp)
- str[fd] = ft_strdup(tmp + i + (tmp[i] == '\n'));
- if (ret == 0 && ((str[fd] == NULL || str[fd][0] == '\0') || !ft_linecheck(str[fd])))
+ **line = 0;
+ curr = ft_find_fd(fd, &list);
+ if (ft_strchr_gnl(curr->rest, 10) == NULL)
+ size = ft_read_gnl(fd, line, curr);
+ else
{
- i = tmp[i];
- free(tmp);
- tmp = NULL;
- return (i == '\n');
+ end = ft_strchr_gnl(curr->rest, 10);
+ *line = ft_strjoin_gnl(*line, curr->rest);
+ curr->rest = ft_swap_gnl(end + 1, curr->rest);
+ size = 1;
}
- free(tmp);
- return (1);
+ if (size > 0)
+ return (1);
+ ft_free_gnl(fd, &list);
+ return ((size == -1) ? -1 : 0);
}
diff --git a/libft/src/get_next_line_utils.c b/libft/src/get_next_line_utils.c
new file mode 100644
index 0000000..42d5d3a
--- /dev/null
+++ b/libft/src/get_next_line_utils.c
@@ -0,0 +1,118 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* get_next_line_utils.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:07:20 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:07:20 by rbousset ### ########lyon.fr */
+/* */
+/* ************************************************************************** */
+
+#include <libft.h>
+#include <stdlib.h>
+#include <stddef.h>
+
+size_t
+ ft_strlen_gnl(const char *s, char c)
+{
+ size_t i;
+
+ i = 0;
+ if (!s)
+ return (0);
+ while (s[i] != c && s[i] != 0)
+ i++;
+ return (i);
+}
+
+int
+ ft_free_gnl(int fd, t_gnl **list)
+{
+ t_gnl *scout;
+ t_gnl *prev;
+
+ prev = *list;
+ if (prev->fd == fd)
+ {
+ scout = prev->next;
+ ft_memdel((void**)&prev->rest);
+ ft_memdel((void**)&prev);
+ *list = scout;
+ return (0);
+ }
+ scout = prev->next;
+ while (scout->fd != fd)
+ {
+ prev = prev->next;
+ scout = scout->next;
+ }
+ prev->next = scout->next;
+ ft_memdel((void**)&scout->rest);
+ ft_memdel((void**)&scout);
+ return (0);
+}
+
+t_gnl
+ *ft_find_fd(int fd, t_gnl **list)
+{
+ t_gnl *curr;
+ t_gnl *new;
+
+ if (!(new = malloc(sizeof(*new))))
+ return (NULL);
+ new->fd = fd;
+ new->rest = 0;
+ new->next = NULL;
+ if (!*list)
+ {
+ *list = new;
+ return (*list);
+ }
+ curr = *list;
+ if (fd != curr->fd)
+ {
+ while (curr->next != NULL && fd != curr->fd)
+ curr = curr->next;
+ if (curr->next == NULL)
+ return (curr->next = new);
+ }
+ ft_memdel((void**)&new);
+ return (curr);
+}
+
+char
+ *ft_strchr_gnl(const char *s, int c)
+{
+ unsigned int i;
+
+ i = 0;
+ c = (char)c;
+ if (!s)
+ return (NULL);
+ while (s[i] != 0 && s[i] != c)
+ i++;
+ if (s[i] != c)
+ return (NULL);
+ return ((char *)s + i);
+}
+
+char
+ *ft_swap_gnl(char *s1, char *free_ft)
+{
+ char *dst;
+ int i;
+
+ if (!(dst = malloc(ft_strlen_gnl(s1, 0) + 1)))
+ return (NULL);
+ i = 0;
+ while (s1[i])
+ {
+ dst[i] = s1[i];
+ i++;
+ }
+ dst[i] = 0;
+ ft_memdel((void**)&free_ft);
+ return (dst);
+}