From fe37597119353ce183fc404417b81bd4702f64b7 Mon Sep 17 00:00:00 2001 From: Charles Date: Fri, 17 Jan 2020 10:56:16 +0100 Subject: Splited include like src/, Adding feature toggle protection in header --- Makefile | 24 +++-- include/ft_ctype.h | 35 +++++++ include/ft_get_next_line.h | 35 +++++++ include/ft_io.h | 25 +++++ include/ft_lst.h | 36 +++++++ include/ft_mem.h | 31 ++++++ include/ft_printf.h | 27 +++++ include/ft_str.h | 66 ++++++++++++ include/ft_types.h | 26 +++++ include/get_next_line.h | 35 ------- include/libft.h | 150 +++------------------------ src/io/ft_asprintf.c | 24 ----- src/io/ft_dprintf.c | 24 ----- src/io/ft_get_next_line.c | 113 ++++++++++++++++++++ src/io/ft_printf.c | 24 ----- src/io/ft_printf/convert.c | 122 ---------------------- src/io/ft_printf/convert_char.c | 53 ---------- src/io/ft_printf/convert_hex.c | 34 ------ src/io/ft_printf/convert_int.c | 40 ------- src/io/ft_printf/convert_none.c | 25 ----- src/io/ft_printf/convert_percent.c | 23 ---- src/io/ft_printf/convert_ptr.c | 29 ------ src/io/ft_printf/convert_str.c | 25 ----- src/io/ft_printf/convert_uint.c | 34 ------ src/io/ft_printf/convert_written.c | 28 ----- src/io/ft_printf/extract.c | 98 ----------------- src/io/ft_printf/ft_asprintf.c | 24 +++++ src/io/ft_printf/ft_dprintf.c | 24 +++++ src/io/ft_printf/ft_printf.c | 88 ++-------------- src/io/ft_printf/ft_snprintf.c | 24 +++++ src/io/ft_printf/ft_sprintf.c | 24 +++++ src/io/ft_printf/ft_vasprintf.c | 21 ++++ src/io/ft_printf/ft_vdprintf.c | 24 +++++ src/io/ft_printf/ft_vprintf.c | 18 ++++ src/io/ft_printf/ft_vsnprintf.c | 26 +++++ src/io/ft_printf/ft_vsprintf.c | 18 ++++ src/io/ft_printf/internals/convert.c | 122 ++++++++++++++++++++++ src/io/ft_printf/internals/convert_char.c | 53 ++++++++++ src/io/ft_printf/internals/convert_hex.c | 34 ++++++ src/io/ft_printf/internals/convert_int.c | 40 +++++++ src/io/ft_printf/internals/convert_none.c | 25 +++++ src/io/ft_printf/internals/convert_percent.c | 23 ++++ src/io/ft_printf/internals/convert_ptr.c | 29 ++++++ src/io/ft_printf/internals/convert_str.c | 25 +++++ src/io/ft_printf/internals/convert_uint.c | 34 ++++++ src/io/ft_printf/internals/convert_written.c | 28 +++++ src/io/ft_printf/internals/extract.c | 98 +++++++++++++++++ src/io/ft_printf/internals/length_modifier.c | 39 +++++++ src/io/ft_printf/internals/list.c | 67 ++++++++++++ src/io/ft_printf/internals/parse.c | 61 +++++++++++ src/io/ft_printf/internals/utils.c | 115 ++++++++++++++++++++ src/io/ft_printf/length_modifier.c | 39 ------- src/io/ft_printf/list.c | 67 ------------ src/io/ft_printf/parse.c | 61 ----------- src/io/ft_printf/utils.c | 115 -------------------- src/io/ft_snprintf.c | 24 ----- src/io/ft_sprintf.c | 24 ----- src/io/ft_vasprintf.c | 21 ---- src/io/ft_vdprintf.c | 24 ----- src/io/ft_vprintf.c | 18 ---- src/io/ft_vsnprintf.c | 26 ----- src/io/ft_vsprintf.c | 18 ---- src/io/get_next_line/get_next_line.c | 115 -------------------- src/lst/ft_lstreverse_ret.c | 3 +- src/mem/ft_memccpy.c | 12 +-- src/mem/ft_memchr.c | 8 +- src/mem/ft_memcmp.c | 12 +-- src/mem/ft_memcpy.c | 4 +- src/mem/ft_memmove.c | 4 +- src/mem/ft_memset.c | 4 +- src/str/ft_atoi_strict.c | 3 +- src/str/ft_strncpy.c | 4 +- src/str/ft_strtol.c | 4 +- test/ctest | 2 +- test/str/ft_strlen_test.c | 17 ++- test/test_libft.h | 1 + 76 files changed, 1477 insertions(+), 1423 deletions(-) create mode 100644 include/ft_ctype.h create mode 100644 include/ft_get_next_line.h create mode 100644 include/ft_io.h create mode 100644 include/ft_lst.h create mode 100644 include/ft_mem.h create mode 100644 include/ft_printf.h create mode 100644 include/ft_str.h create mode 100644 include/ft_types.h delete mode 100644 include/get_next_line.h delete mode 100644 src/io/ft_asprintf.c delete mode 100644 src/io/ft_dprintf.c create mode 100644 src/io/ft_get_next_line.c delete mode 100644 src/io/ft_printf.c delete mode 100644 src/io/ft_printf/convert.c delete mode 100644 src/io/ft_printf/convert_char.c delete mode 100644 src/io/ft_printf/convert_hex.c delete mode 100644 src/io/ft_printf/convert_int.c delete mode 100644 src/io/ft_printf/convert_none.c delete mode 100644 src/io/ft_printf/convert_percent.c delete mode 100644 src/io/ft_printf/convert_ptr.c delete mode 100644 src/io/ft_printf/convert_str.c delete mode 100644 src/io/ft_printf/convert_uint.c delete mode 100644 src/io/ft_printf/convert_written.c delete mode 100644 src/io/ft_printf/extract.c create mode 100644 src/io/ft_printf/ft_asprintf.c create mode 100644 src/io/ft_printf/ft_dprintf.c create mode 100644 src/io/ft_printf/ft_snprintf.c create mode 100644 src/io/ft_printf/ft_sprintf.c create mode 100644 src/io/ft_printf/ft_vasprintf.c create mode 100644 src/io/ft_printf/ft_vdprintf.c create mode 100644 src/io/ft_printf/ft_vprintf.c create mode 100644 src/io/ft_printf/ft_vsnprintf.c create mode 100644 src/io/ft_printf/ft_vsprintf.c create mode 100644 src/io/ft_printf/internals/convert.c create mode 100644 src/io/ft_printf/internals/convert_char.c create mode 100644 src/io/ft_printf/internals/convert_hex.c create mode 100644 src/io/ft_printf/internals/convert_int.c create mode 100644 src/io/ft_printf/internals/convert_none.c create mode 100644 src/io/ft_printf/internals/convert_percent.c create mode 100644 src/io/ft_printf/internals/convert_ptr.c create mode 100644 src/io/ft_printf/internals/convert_str.c create mode 100644 src/io/ft_printf/internals/convert_uint.c create mode 100644 src/io/ft_printf/internals/convert_written.c create mode 100644 src/io/ft_printf/internals/extract.c create mode 100644 src/io/ft_printf/internals/length_modifier.c create mode 100644 src/io/ft_printf/internals/list.c create mode 100644 src/io/ft_printf/internals/parse.c create mode 100644 src/io/ft_printf/internals/utils.c delete mode 100644 src/io/ft_printf/length_modifier.c delete mode 100644 src/io/ft_printf/list.c delete mode 100644 src/io/ft_printf/parse.c delete mode 100644 src/io/ft_printf/utils.c delete mode 100644 src/io/ft_snprintf.c delete mode 100644 src/io/ft_sprintf.c delete mode 100644 src/io/ft_vasprintf.c delete mode 100644 src/io/ft_vdprintf.c delete mode 100644 src/io/ft_vprintf.c delete mode 100644 src/io/ft_vsnprintf.c delete mode 100644 src/io/ft_vsprintf.c delete mode 100644 src/io/get_next_line/get_next_line.c diff --git a/Makefile b/Makefile index 76765dc..f7e97c6 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ # By: cacharle +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2019/10/08 15:45:53 by cacharle #+# #+# # -# Updated: 2020/01/16 10:23:07 by cacharle ### ########.fr # +# Updated: 2020/01/17 10:51:24 by cacharle ### ########.fr # # # # **************************************************************************** # @@ -26,30 +26,36 @@ TEST_DIR = test # AVAILABLE_FEATURES = get_next_line ft_printf ft_lst CONF_FILE = libft.conf -# ifndef (FEATURES) -# endif +ifndef (FEATURES) +endif ifeq ($(wildcard $(CONF_FILE)),) $(warning "No configuration file found with name $(CONF_FILE), using default") FEATURES = get_next_line + CCFLAGS += -D FT_FEATURES_FT_GET_NEXT_LINE else FEATURES = $(shell sed -n 's/FEATURES=//p' $(CONF_FILE)) endif ifeq ($(findstring get_next_line,$(FEATURES)),) - FIND_ARGS += -not -path "*get_next_line*" + FIND_ARGS += -not -name "ft_get_next_line.c" +else + CCFLAGS += -D FT_FEATURES_FT_GET_NEXT_LINE endif ifeq ($(findstring ft_printf,$(FEATURES)),) FIND_ARGS += -not -path "*printf*" +else + CCFLAGS += -D FT_FEATURES_FT_PRINTF endif ifeq ($(findstring ft_lst,$(FEATURES)),) - FIND_ARGS += -not -name "ft_lst*" + FIND_ARGS += -not -name "ft_lst*.c" +else + CCFLAGS += -D FT_FEATURES_FT_LST endif -SRC = $(shell find $(SRC_DIR) $(FIND_ARGS) -name *.c) +SRC = $(shell find $(SRC_DIR) $(FIND_ARGS) -name "*.c") OBJ = $(SRC:$(SRC_DIR)/%.c=$(BUILD_DIR)/%.o) -HEADER_FILES = libft.h get_next_line.h -HEADER = $(addprefix $(INCLUDE_DIR)/,$(HEADER_FILES)) +HEADER = $(shell find $(INCLUDE_DIR) -name "*.h") all: make_build_dirs $(NAME) @@ -67,7 +73,7 @@ make_build_dirs: $(NAME): $(OBJ) $(HEADER) @echo "Linking: $@" - @$(LIB) $(NAME) $(OBJ) + @$(LIB) $@ $(OBJ) $(BUILD_DIR)/%.o: $(SRC_DIR)/%.c @echo "Compiling: $@" diff --git a/include/ft_ctype.h b/include/ft_ctype.h new file mode 100644 index 0000000..44e88b8 --- /dev/null +++ b/include/ft_ctype.h @@ -0,0 +1,35 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_ctype.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/01/17 09:59:10 by cacharle #+# #+# */ +/* Updated: 2020/01/17 10:00:13 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_CTYPE_H +# define FT_CTYPE_H + +/* +** assertion +*/ + +int ft_isalpha(int c); +int ft_isdigit(int c); +int ft_isalnum(int c); +int ft_isascii(int c); +int ft_isprint(int c); +int ft_isspace(int c); + +/* +** conversion +*/ + +int ft_toupper(int c); +int ft_tolower(int c); +int ft_todigit(int c); + +#endif diff --git a/include/ft_get_next_line.h b/include/ft_get_next_line.h new file mode 100644 index 0000000..03bf344 --- /dev/null +++ b/include/ft_get_next_line.h @@ -0,0 +1,35 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* get_next_line.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/10/09 13:52:59 by cacharle #+# #+# */ +/* Updated: 2020/01/17 10:53:43 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_GET_NEXT_LINE_H +# define FT_GET_NEXT_LINE_H + +# include +# include +# include +# include "libft.h" + +# ifndef GNL_BUFFER_SIZE +# define GNL_BUFFER_SIZE 32 +# endif + +# define GNL_STATUS_LINE 1 +# define GNL_STATUS_EOF 0 +# define GNL_STATUS_ERROR -1 + +/* +** get_next_line.c +*/ + +int get_next_line(int fd, char **line); + +#endif diff --git a/include/ft_io.h b/include/ft_io.h new file mode 100644 index 0000000..8c633fb --- /dev/null +++ b/include/ft_io.h @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_io.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/01/17 09:47:14 by cacharle #+# #+# */ +/* Updated: 2020/01/17 10:07:47 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_IO_H +# define FT_IO_H + +void ft_putendl(char *s); +void ft_putchar(char c); +void ft_putstr(char const *s); +void ft_putnbr(int n); +void ft_putchar_fd(char c, int fd); +void ft_putstr_fd(char *s, int fd); +void ft_putendl_fd(char *s, int fd); +void ft_putnbr_fd(int n, int fd); + +#endif diff --git a/include/ft_lst.h b/include/ft_lst.h new file mode 100644 index 0000000..134df71 --- /dev/null +++ b/include/ft_lst.h @@ -0,0 +1,36 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lst.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/01/17 09:58:02 by cacharle #+# #+# */ +/* Updated: 2020/01/17 09:58:45 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_LST_H +# define FT_LST_H + +typedef struct s_list +{ + void *content; + struct s_list *next; +} t_list; + +t_list *ft_lstnew(void const *content); +void ft_lstadd_front(t_list **alst, t_list *new); +int ft_lstsize(t_list *lst); +t_list *ft_lstlast(t_list *lst); +void ft_lstadd_back(t_list **alst, t_list *new); +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 *)); +t_list *ft_lstmap(t_list *lst, void *(*f)(void *), + void (*del)(void *)); +void ft_lstpop_front(t_list **lst, void (*del)(void *)); +t_list *ft_lstreverse_ret(t_list *lst); +void ft_lstreverse(t_list **lst); + +#endif diff --git a/include/ft_mem.h b/include/ft_mem.h new file mode 100644 index 0000000..d1e47f6 --- /dev/null +++ b/include/ft_mem.h @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_mem.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/01/17 09:56:20 by cacharle #+# #+# */ +/* Updated: 2020/01/17 09:57:54 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_MEM_H +# define FT_MEM_H + +void ft_bzero(void *s, size_t n); +void *ft_memset(void *s, int c, size_t n); +void *ft_memcpy(void *dest, const void *src, size_t n); +void *ft_memccpy(void *dest, const void *src, int c, size_t n); +void *ft_memmove(void *dst, const void *src, size_t len); +void *ft_memchr(const void *s, int c, size_t n); +int ft_memcmp(const void *s1, const void *s2, size_t n); +void *ft_calloc(size_t count, size_t size); + +/* +** bloat ? +*/ + +void ft_memdel(void **ap); + +#endif diff --git a/include/ft_printf.h b/include/ft_printf.h new file mode 100644 index 0000000..615039b --- /dev/null +++ b/include/ft_printf.h @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_printf.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/01/17 10:05:59 by cacharle #+# #+# */ +/* Updated: 2020/01/17 10:10:18 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_PRINTF_H +# define FT_PRINTF_H + +int ft_printf(const char *format, ...); +int ft_sprintf(char *str, const char *format, ...); +int ft_snprintf(char *str, size_t size, const char *format, ...); +int ft_asprintf(char **ret, const char *format, ...); +int ft_dprintf(int fd, const char *format, ...); +int ft_vprintf(const char *format, va_list ap); +int ft_vsprintf(char *str, const char *format, va_list ap); +int ft_vsnprintf(char *str, size_t size, const char *format, va_list ap); +int ft_vasprintf(char **ret, const char *format, va_list ap); +int ft_vdprintf(int fd, const char *format, va_list ap); + +#endif diff --git a/include/ft_str.h b/include/ft_str.h new file mode 100644 index 0000000..105da79 --- /dev/null +++ b/include/ft_str.h @@ -0,0 +1,66 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_str.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/01/17 09:50:14 by cacharle #+# #+# */ +/* Updated: 2020/01/17 10:22:38 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_STR_H +# define FT_STR_H + +/* +** std +*/ + +size_t ft_strlen(const char *s); +char *ft_strcpy(char *dest, const char *src); +char *ft_strncpy(char *dest, const char *src, size_t n); +char *ft_strdup(const char *s); +char *ft_strndup(const char *s1, size_t n); +char *ft_strcat(char *dest, const char *src); +char *ft_strncat(char *dest, const char *src, size_t n); +size_t ft_strlcat(char *dst, const char *src, size_t size); +size_t ft_strlcpy(char *dst, const char *src, size_t size); +char *ft_strchr(const char *s, int c); +char *ft_strrchr(const char *s, int c); +char *ft_strstr(const char *haystack, const char *needle); +char *ft_strnstr(const char *haystack, const char *needle, size_t len); +int ft_strcmp(const char *s1, const char *s2); +int ft_strncmp(const char *s1, const char *s2, size_t n); +int ft_atoi(const char *nptr); + +/* +** extra +*/ + +void ft_striter(char *s, void (*f)(char *)); +void ft_striteri(char *s, void (*f)(unsigned int, char *)); +char *ft_substr(char const *s, unsigned int start, size_t len); +char *ft_strjoin(char const *s1, char const *s2); +char *ft_strtrim(char const *s1, char const *set); +char **ft_split(char const *s, char c); +char *ft_strjoin_free(char const *s1, char const *s2, int free_nb); +char *ft_strjoin_free_snd(char const *s1, char const *s2); +int ft_strcount(char *str, char c); +char *ft_itoa(int n); +int ft_strict_atoi(const char *s); +long ft_strtol(const char *s, char **endptr, int base); + +/* +** bloat ? +*/ + +char *ft_strnew(size_t size); +void ft_strdel(char **as); +void ft_strclr(char *s); +char *ft_strmap(char const *s, char (*f)(char)); +char *ft_strmapi(char *s, char (*f)(unsigned int, char)); +int ft_strequ(char const *s1, char const *s2); +int ft_strnequ(char const *s1, char const *s2, size_t n); + +#endif diff --git a/include/ft_types.h b/include/ft_types.h new file mode 100644 index 0000000..948e33d --- /dev/null +++ b/include/ft_types.h @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_types.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/01/17 09:59:15 by cacharle #+# #+# */ +/* Updated: 2020/01/17 10:16:14 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_TYPES_H +# define FT_TYPES_H + +typedef unsigned char t_ftbyte; +typedef int t_ftbool; + +typedef char t_ftchar; +typedef unsigned char t_ftuchar; +typedef int t_ftint; +typedef unsigned int t_ftuint; +typedef long int t_ftlong; +typedef unsigned long int t_ftulong; + +#endif diff --git a/include/get_next_line.h b/include/get_next_line.h deleted file mode 100644 index 9d15202..0000000 --- a/include/get_next_line.h +++ /dev/null @@ -1,35 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* get_next_line.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: cacharle +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2019/10/09 13:52:59 by cacharle #+# #+# */ -/* Updated: 2020/01/15 07:22:07 by cacharle ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef GET_NEXT_LINE_H -# define GET_NEXT_LINE_H - -# include -# include -# include -# include "libft.h" - -# ifndef BUFFER_SIZE -# define BUFFER_SIZE 32 -# endif - -# define GNL_STATUS_LINE 1 -# define GNL_STATUS_EOF 0 -# define GNL_STATUS_ERROR -1 - -/* -** get_next_line.c -*/ - -int get_next_line(int fd, char **line); - -#endif diff --git a/include/libft.h b/include/libft.h index d7dc175..0b4d608 100644 --- a/include/libft.h +++ b/include/libft.h @@ -6,7 +6,7 @@ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/10/07 09:45:02 by cacharle #+# #+# */ -/* Updated: 2020/01/16 10:25:57 by cacharle ### ########.fr */ +/* Updated: 2020/01/17 10:51:40 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,148 +18,32 @@ # include # include # include - # include +# include "ft_types.h" +# include "ft_ctype.h" +# include "ft_io.h" +# include "ft_mem.h" +# include "ft_str.h" + +# ifdef FT_FEATURES_FT_LST +# include "ft_lst.h" +# endif + +# ifdef FT_FEATURES_FT_GET_NEXT_LINE +# include "ft_get_next_line.h" +# endif -# include "get_next_line.h" +# ifdef FT_FEATURES_FT_PRINTF +# include "ft_printf.h" +# endif # ifdef __linux__ # include # define OPEN_MAX FOPEN_MAX # endif -# define MIN(x, y) ((x) < (y) ? (x) : (y)) -# define MAX(x, y) ((x) > (y) ? (x) : (y)) - -typedef unsigned char t_byte; -typedef int t_bool; - # define TRUE 1 # define FALSE 0 -/* -** ctype -*/ - -int ft_isalpha(int c); -int ft_isdigit(int c); -int ft_isalnum(int c); -int ft_isascii(int c); -int ft_isprint(int c); -int ft_isspace(int c); -int ft_toupper(int c); -int ft_tolower(int c); -int ft_todigit(int c); - -/* -** io -*/ - -void ft_putendl(char *s); -void ft_putchar(char c); -void ft_putstr(char const *s); -void ft_putnbr(int n); -void ft_putchar_fd(char c, int fd); -void ft_putstr_fd(char *s, int fd); -void ft_putendl_fd(char *s, int fd); -void ft_putnbr_fd(int n, int fd); -char *ft_strndup(const char *s1, size_t n); -int ft_printf(const char *format, ...); -int ft_sprintf(char *str, const char *format, ...); -int ft_snprintf(char *str, size_t size, - const char *format, ...); -int ft_asprintf(char **ret, const char *format, ...); -int ft_dprintf(int fd, const char *format, ...); - -int ft_vprintf(const char *format, va_list ap); -int ft_vsprintf(char *str, const char *format, va_list ap); -int ft_vsnprintf(char *str, size_t size, const char *format, - va_list ap); -int ft_vasprintf(char **ret, const char *format, va_list ap); -int ft_vdprintf(int fd, const char *format, va_list ap); - -/* -** lst -*/ - -typedef struct s_list -{ - void *content; - struct s_list *next; -} t_list; - -t_list *ft_lstnew(void const *content); -void ft_lstadd_front(t_list **alst, t_list *new); -int ft_lstsize(t_list *lst); -t_list *ft_lstlast(t_list *lst); -void ft_lstadd_back(t_list **alst, t_list *new); -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 *)); -t_list *ft_lstmap(t_list *lst, void *(*f)(void *), - void (*del)(void *)); -void ft_lstpop_front(t_list **lst, void (*del)(void *)); -t_list *ft_lstreverse_ret(t_list *lst); -void ft_lstreverse(t_list **lst); - -/* -** mem -*/ - -void *ft_memset(void *s, int c, size_t n); -void ft_bzero(void *s, size_t n); -void *ft_memcpy(void *dest, const void *src, size_t n); -void *ft_memccpy(void *dest, const void *src, int c, size_t n); -void *ft_memmove(void *dst, const void *src, size_t len); -void *ft_memchr(const void *s, int c, size_t n); -int ft_memcmp(const void *s1, const void *s2, size_t n); - -void *ft_memalloc(size_t size); -void ft_memdel(void **ap); -void *ft_calloc(size_t count, size_t size); - -/* -** str -*/ - -size_t ft_strlen(const char *s); -char *ft_strdup(const char *s); -char *ft_strcpy(char *dest, const char *src); -char *ft_strncpy(char *dest, const char *src, size_t n); -char *ft_strcat(char *dest, const char *src); -char *ft_strncat(char *dest, const char *src, size_t n); -size_t ft_strlcat(char *dst, const char *src, size_t size); -size_t ft_strlcpy(char *dst, const char *src, size_t size); -char *ft_strchr(const char *s, int c); -char *ft_strrchr(const char *s, int c); -char *ft_strstr(const char *haystack, const char *needle); -char *ft_strnstr(const char *haystack, - const char *needle, size_t len); -int ft_strcmp(const char *s1, const char *s2); -int ft_strncmp(const char *s1, const char *s2, size_t n); -void ft_striter(char *s, void (*f)(char *)); -void ft_striteri(char *s, void (*f)(unsigned int, char *)); -int ft_atoi(const char *nptr); - -char *ft_strnew(size_t size); -void ft_strdel(char **as); -void ft_strclr(char *s); -char *ft_strmap(char const *s, char (*f)(char)); -char *ft_strmapi(char *s, char (*f)(unsigned int, char)); -int ft_strequ(char const *s1, char const *s2); -int ft_strnequ(char const *s1, char const *s2, size_t n); -char *ft_substr(char const *s, unsigned int start, size_t len); -char *ft_strjoin(char const *s1, char const *s2); -char *ft_strtrim(char const *s1, char const *set); -char **ft_split(char const *s, char c); - -char *ft_strjoin_free(char const *s1, char const *s2, - int free_nb); -char *ft_strjoin_free_snd(char const *s1, char const *s2); -int ft_strcount(char *str, char c); -char *ft_itoa(int n); -int ft_strict_atoi(const char *s); -long ft_strtol(const char *s, char **endptr, int base); - #endif diff --git a/src/io/ft_asprintf.c b/src/io/ft_asprintf.c deleted file mode 100644 index 5eb62d9..0000000 --- a/src/io/ft_asprintf.c +++ /dev/null @@ -1,24 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_asprintf.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: cacharle +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2019/11/21 02:30:33 by cacharle #+# #+# */ -/* Updated: 2019/11/21 03:43:08 by cacharle ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -int ft_asprintf(char **ret, const char *format, ...) -{ - int vret; - va_list ap; - - va_start(ap, format); - vret = ft_vasprintf(ret, format, ap); - va_end(ap); - return (vret); -} diff --git a/src/io/ft_dprintf.c b/src/io/ft_dprintf.c deleted file mode 100644 index 8e60970..0000000 --- a/src/io/ft_dprintf.c +++ /dev/null @@ -1,24 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_dprintf.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: cacharle +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2019/11/21 02:29:11 by cacharle #+# #+# */ -/* Updated: 2019/11/21 03:42:05 by cacharle ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -int ft_dprintf(int fd, const char *format, ...) -{ - int ret; - va_list ap; - - va_start(ap, format); - ret = ft_vdprintf(fd, format, ap); - va_end(ap); - return (ret); -} diff --git a/src/io/ft_get_next_line.c b/src/io/ft_get_next_line.c new file mode 100644 index 0000000..4aecf3c --- /dev/null +++ b/src/io/ft_get_next_line.c @@ -0,0 +1,113 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* get_next_line.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/10/19 09:08:36 by cacharle #+# #+# */ +/* Updated: 2020/01/17 10:53:23 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +static int gnl_find_newline(char *str) +{ + int i; + + i = -1; + while (str[++i]) + if (str[i] == '\n') + return (i); + return (-1); +} + +static int gnl_free_return(char **ptr, char **ptr2, int ret) +{ + if (ptr != NULL) + { + free(*ptr); + *ptr = NULL; + } + if (ptr2 != NULL) + { + free(*ptr2); + *ptr2 = NULL; + } + return (ret); +} + +static int gnl_read_line(int fd, char **line, char *rest) +{ + int ret; + int split_at; + char *buf; + + if ((buf = malloc(sizeof(char) * (GNL_BUFFER_SIZE + 1))) == NULL) + return (gnl_free_return(line, NULL, GNL_STATUS_ERROR)); + while ((ret = read(fd, buf, GNL_BUFFER_SIZE)) > 0) + { + buf[ret] = '\0'; + if ((split_at = gnl_find_newline(buf)) != -1) + { + ft_strcpy(rest, buf + split_at + 1); + buf[split_at] = '\0'; + if ((*line = ft_strjoin_free(*line, buf, 1)) == NULL) + return (gnl_free_return(&buf, NULL, GNL_STATUS_ERROR)); + return (gnl_free_return(&buf, NULL, GNL_STATUS_LINE)); + } + if ((*line = ft_strjoin_free(*line, buf, 1)) == NULL) + return (gnl_free_return(&buf, NULL, GNL_STATUS_ERROR)); + } + if (ret == -1) + return (gnl_free_return(&buf, line, GNL_STATUS_ERROR)); + return (gnl_free_return(&buf, NULL, ret)); +} + +/* +** if has rest: +** if rest has newline: +** push rest until newline in line, shift rest +** return LINE_READ +** else: +** push rest in line +** +** while can read fd in buf +** if buf has newline: +** push buf until newline in line +** push buf after newline in rest +** return LINE_READ +** push buf in line +** +** return GNL_EOF +*/ + +int get_next_line(int fd, char **line) +{ + int split_at; + static char rest[OPEN_MAX][GNL_BUFFER_SIZE + 1] = {{0}}; + + if (fd < 0 || fd > OPEN_MAX || line == NULL || GNL_BUFFER_SIZE <= 0) + return (GNL_STATUS_ERROR); + if ((*line = ft_strdup("")) == NULL) + return (GNL_STATUS_ERROR); + if (rest[fd][0] == '\0') + return (gnl_read_line(fd, line, rest[fd])); + if ((split_at = gnl_find_newline(rest[fd])) != -1) + { + free(*line); + if ((*line = (char*)malloc(sizeof(char) * (split_at + 1))) == NULL) + return (GNL_STATUS_ERROR); + ft_strncpy(*line, rest[fd], split_at); + (*line)[split_at] = '\0'; + ft_strcpy(rest[fd], rest[fd] + split_at + 1); + return (GNL_STATUS_LINE); + } + free(*line); + if (!(*line = (char*)malloc(sizeof(char) * (ft_strlen(rest[fd]) + 1)))) + return (GNL_STATUS_ERROR); + ft_strcpy(*line, rest[fd]); + rest[fd][0] = '\0'; + return (gnl_read_line(fd, line, rest[fd])); +} diff --git a/src/io/ft_printf.c b/src/io/ft_printf.c deleted file mode 100644 index 1b92bb2..0000000 --- a/src/io/ft_printf.c +++ /dev/null @@ -1,24 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_printf.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: cacharle +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2019/11/21 02:31:32 by cacharle #+# #+# */ -/* Updated: 2019/11/21 03:41:54 by cacharle ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -int ft_printf(const char *format, ...) -{ - int ret; - va_list ap; - - va_start(ap, format); - ret = ft_vprintf(format, ap); - va_end(ap); - return (ret); -} diff --git a/src/io/ft_printf/convert.c b/src/io/ft_printf/convert.c deleted file mode 100644 index 398c754..0000000 --- a/src/io/ft_printf/convert.c +++ /dev/null @@ -1,122 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* printer.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: cacharle +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2019/10/28 23:19:24 by cacharle #+# #+# */ -/* Updated: 2019/11/14 10:22:04 by cacharle ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include -#include -#include -#include "libft.h" -#include "ft_vasprintf.h" - -char *convert(t_pformat *pformat, va_list ap) -{ - char *str; - - if (pformat == NULL) - return (NULL); - if (pformat->flags & FLAG_WIDTH_WILDCARD) - { - if (pformat->flags & FLAG_WIDTH_OVERWRITE) - (void)va_arg(ap, int); - else - pformat->width = va_arg(ap, int); - if (pformat->width < 0) - { - pformat->flags |= FLAG_MINUS; - pformat->width *= -1; - } - } - if (pformat->flags & FLAG_PRECISION_WILDCARD) - pformat->precision = va_arg(ap, int); - if ((str = convert_specifier(ap, pformat)) == NULL) - return (NULL); - return (str); -} - -char *convert_specifier(va_list ap, t_pformat *pformat) -{ - if (pformat->specifier == 'c') - return (convert_char(ap, pformat)); - if (pformat->specifier == 's') - return (convert_str(ap, pformat)); - if (pformat->specifier == 'p') - return (convert_ptr(ap, pformat)); - if (pformat->specifier == 'd' || pformat->specifier == 'i') - return (convert_int(ap, pformat)); - if (pformat->specifier == 'u') - return (convert_uint(ap, pformat)); - if (pformat->specifier == 'x') - return (convert_hex(ap, pformat)); - if (pformat->specifier == 'X') - return (convert_hex(ap, pformat)); - if (pformat->specifier == '%') - return (convert_percent(ap, pformat)); - if (pformat->specifier == 'n') - return (convert_written(ap, pformat)); - else - return (convert_none(ap, pformat)); - return (NULL); -} - -char *handle_width(t_pformat *pformat, char *str) -{ - char *tmp; - int len; - int i; - - if ((len = ft_strlen(str)) >= pformat->width) - return (str); - if ((tmp = (char*)malloc(sizeof(char) * (pformat->width + 1))) == NULL) - return (NULL); - if (pformat->flags & FLAG_MINUS) - { - i = len; - ft_strcpy(tmp, str); - while (i < pformat->width) - tmp[i++] = ' '; - tmp[i] = 0; - } - else - { - i = 0; - while (i <= pformat->width - len) - tmp[i++] = pformat->flags & FLAG_ZERO ? '0' : ' '; - ft_strcpy(tmp + i - 1, str); - } - free(str); - return (tmp); -} - -char *handle_precision(t_pformat *pformat, char *str) -{ - int len; - char *tmp; - - if (pformat == NULL || str == NULL) - return (NULL); - if (ft_strchr("diuxX", pformat->specifier) && pformat->precision >= 0) - pformat->flags &= ~FLAG_ZERO; - len = ft_strlen(str); - if (pformat->precision == 0 && str[0] == '0') - { - free(str); - return (ft_strdup("")); - } - if (!ft_strchr("diuxXp", pformat->specifier) || len >= pformat->precision) - return (str); - if ((tmp = (char*)malloc(sizeof(char) * (pformat->precision + 1))) == NULL) - return (NULL); - ft_strcpy(tmp + pformat->precision - len, str); - while (pformat->precision-- > len) - tmp[pformat->precision - len] = '0'; - free(str); - return (tmp); -} diff --git a/src/io/ft_printf/convert_char.c b/src/io/ft_printf/convert_char.c deleted file mode 100644 index c5f3a93..0000000 --- a/src/io/ft_printf/convert_char.c +++ /dev/null @@ -1,53 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* convert_char.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: cacharle +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2019/10/30 23:22:29 by cacharle #+# #+# */ -/* Updated: 2019/11/05 23:44:42 by cacharle ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "ft_vasprintf.h" - -static char *handle_width_char(t_pformat *pformat, char *str) -{ - char *tmp; - int i; - - pformat->size = 1; - if (1 >= pformat->width) - return (str); - if ((tmp = (char*)malloc(sizeof(char) * (pformat->width + 1))) == NULL) - return (NULL); - if (pformat->flags & FLAG_MINUS) - { - ft_memcpy(tmp, str, (i = 1) + 1); - while (i < pformat->width) - tmp[i++] = ' '; - tmp[i] = 0; - } - else - { - i = 0; - while (i <= pformat->width - 1) - tmp[i++] = pformat->flags & FLAG_ZERO ? '0' : ' '; - ft_memcpy(tmp + i - 1, str, 2); - } - free(str); - pformat->size = pformat->width; - return (tmp); -} - -char *convert_char(va_list ap, t_pformat *pformat) -{ - char *str; - - if ((str = ft_strnew(2)) == NULL) - return (NULL); - str[0] = va_arg(ap, int); - str[1] = '\0'; - return (handle_width_char(pformat, str)); -} diff --git a/src/io/ft_printf/convert_hex.c b/src/io/ft_printf/convert_hex.c deleted file mode 100644 index 0464dc7..0000000 --- a/src/io/ft_printf/convert_hex.c +++ /dev/null @@ -1,34 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* convert_hex.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: cacharle +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2019/10/30 23:23:06 by cacharle #+# #+# */ -/* Updated: 2019/11/05 23:58:59 by cacharle ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "ft_vasprintf.h" - -char *convert_hex(va_list ap, t_pformat *pformat) -{ - char *str; - long long unsigned int n; - - n = length_modifier_unsigned_int(ap, pformat); - str = pformat->specifier == 'x' ? ITOA_HEX_LOW(n) : ITOA_HEX_UP(n); - str = handle_precision(pformat, str); - if (pformat->flags & FLAG_ZERO) - { - if (pformat->flags & FLAG_ALTERNATE && n != 0) - pformat->width -= 2; - str = handle_width(pformat, str); - } - if (pformat->flags & FLAG_ALTERNATE && n != 0) - str = ft_strjoin_free_snd(pformat->specifier == 'X' ? "0X" : "0x", str); - if (!(pformat->flags & FLAG_ZERO)) - str = handle_width(pformat, str); - return (str); -} diff --git a/src/io/ft_printf/convert_int.c b/src/io/ft_printf/convert_int.c deleted file mode 100644 index 2345f76..0000000 --- a/src/io/ft_printf/convert_int.c +++ /dev/null @@ -1,40 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* convert_int.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: cacharle +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2019/10/30 23:29:53 by cacharle #+# #+# */ -/* Updated: 2019/11/06 00:00:09 by cacharle ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "ft_vasprintf.h" - -char *convert_int(va_list ap, t_pformat *pformat) -{ - int is_neg; - long long int n; - char *str; - - n = length_modifier_int(ap, pformat); - is_neg = n < 0; - str = ITOA_DEC(n); - if (is_neg) - ft_strcpy(str, str + 1); - str = handle_precision(pformat, str); - if (pformat->flags & FLAG_ZERO) - { - if (is_neg || pformat->flags & (FLAG_SIGNED | FLAG_SPACE)) - pformat->width--; - str = handle_width(pformat, str); - } - if (is_neg) - str = ft_strjoin_free_snd("-", str); - else if (pformat->flags & (FLAG_SIGNED | FLAG_SPACE)) - str = ft_strjoin_free_snd(pformat->flags & FLAG_SPACE ? " " : "+", str); - if (!(pformat->flags & FLAG_ZERO)) - str = handle_width(pformat, str); - return (str); -} diff --git a/src/io/ft_printf/convert_none.c b/src/io/ft_printf/convert_none.c deleted file mode 100644 index 358ef1b..0000000 --- a/src/io/ft_printf/convert_none.c +++ /dev/null @@ -1,25 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* convert_none.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: cacharle +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2019/11/04 19:30:25 by cacharle #+# #+# */ -/* Updated: 2019/11/05 23:44:13 by cacharle ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "ft_vasprintf.h" - -char *convert_none(va_list ap, t_pformat *pformat) -{ - char *str; - - (void)ap; - if ((str = ft_strdup("")) == NULL) - return (NULL); - str = handle_precision(pformat, str); - str = handle_width(pformat, str); - return (str); -} diff --git a/src/io/ft_printf/convert_percent.c b/src/io/ft_printf/convert_percent.c deleted file mode 100644 index 813bb77..0000000 --- a/src/io/ft_printf/convert_percent.c +++ /dev/null @@ -1,23 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* convert_percent.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: cacharle +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2019/10/30 23:23:27 by cacharle #+# #+# */ -/* Updated: 2019/11/05 23:44:07 by cacharle ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "ft_vasprintf.h" - -char *convert_percent(va_list ap, t_pformat *pformat) -{ - char *str; - - (void)ap; - str = ft_strdup("%"); - str = handle_width(pformat, str); - return (str); -} diff --git a/src/io/ft_printf/convert_ptr.c b/src/io/ft_printf/convert_ptr.c deleted file mode 100644 index 63babb9..0000000 --- a/src/io/ft_printf/convert_ptr.c +++ /dev/null @@ -1,29 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* convert_ptr.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: cacharle +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2019/10/30 23:24:08 by cacharle #+# #+# */ -/* Updated: 2019/11/05 23:43:45 by cacharle ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "ft_vasprintf.h" - -char *convert_ptr(va_list ap, t_pformat *pformat) -{ - char *str; - - str = ITOA_HEX_LOW((long long unsigned int)va_arg(ap, void*)); - str = handle_precision(pformat, str); - if (!(pformat->flags & FLAG_ZERO)) - str = ft_strjoin_free_snd("0x", str); - if (pformat->flags & FLAG_ZERO) - pformat->width -= 2; - str = handle_width(pformat, str); - if (pformat->flags & FLAG_ZERO) - str = ft_strjoin_free_snd("0x", str); - return (str); -} diff --git a/src/io/ft_printf/convert_str.c b/src/io/ft_printf/convert_str.c deleted file mode 100644 index 7d51a5e..0000000 --- a/src/io/ft_printf/convert_str.c +++ /dev/null @@ -1,25 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* convert_str.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: cacharle +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2019/10/30 23:22:25 by cacharle #+# #+# */ -/* Updated: 2019/11/09 01:07:24 by cacharle ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "ft_vasprintf.h" - -char *convert_str(va_list ap, t_pformat *pformat) -{ - char *str; - - str = va_arg(ap, char*); - str = str == NULL ? ft_strdup("(null)") : ft_strdup(str); - if (pformat->precision >= 0 && pformat->precision < (int)ft_strlen(str)) - str[pformat->precision] = '\0'; - str = handle_width(pformat, str); - return (str); -} diff --git a/src/io/ft_printf/convert_uint.c b/src/io/ft_printf/convert_uint.c deleted file mode 100644 index 4207165..0000000 --- a/src/io/ft_printf/convert_uint.c +++ /dev/null @@ -1,34 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* convert_uint.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: cacharle +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2019/10/30 23:25:40 by cacharle #+# #+# */ -/* Updated: 2019/11/05 23:44:19 by cacharle ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "ft_vasprintf.h" - -char *convert_uint(va_list ap, t_pformat *pformat) -{ - char *str; - long long unsigned int n; - - if (pformat->flags & FLAG_SHORT) - n = (unsigned short)va_arg(ap, int); - else if (pformat->flags & FLAG_SHORT_SHORT) - n = (unsigned char)va_arg(ap, int); - else if (pformat->flags & FLAG_LONG) - n = va_arg(ap, long unsigned int); - else if (pformat->flags & FLAG_LONG_LONG) - n = va_arg(ap, long long unsigned int); - else - n = va_arg(ap, unsigned int); - str = ft_itoa_unsigned_base(n, "0123456789"); - str = handle_precision(pformat, str); - str = handle_width(pformat, str); - return (str); -} diff --git a/src/io/ft_printf/convert_written.c b/src/io/ft_printf/convert_written.c deleted file mode 100644 index 4beeaef..0000000 --- a/src/io/ft_printf/convert_written.c +++ /dev/null @@ -1,28 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* convert_written.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: cacharle +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2019/10/30 23:38:28 by cacharle #+# #+# */ -/* Updated: 2019/11/05 23:59:24 by cacharle ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "ft_vasprintf.h" - -char *convert_written(va_list ap, t_pformat *pformat) -{ - if (pformat->flags & FLAG_SHORT) - pformat->written = (long long int*)va_arg(ap, signed char*); - if (pformat->flags & FLAG_SHORT_SHORT) - pformat->written = (long long int*)va_arg(ap, short*); - if (pformat->flags & FLAG_LONG) - pformat->written = (long long int*)va_arg(ap, long int*); - if (pformat->flags & FLAG_LONG_LONG) - pformat->written = va_arg(ap, long long int*); - else - pformat->written = (long long int*)va_arg(ap, int*); - return (NULL); -} diff --git a/src/io/ft_printf/extract.c b/src/io/ft_printf/extract.c deleted file mode 100644 index c56a777..0000000 --- a/src/io/ft_printf/extract.c +++ /dev/null @@ -1,98 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* extract.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: cacharle +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2019/10/29 00:10:36 by cacharle #+# #+# */ -/* Updated: 2019/11/10 10:33:33 by cacharle ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "ft_vasprintf.h" - -const char *extract_flags(t_pformat *pformat, const char *fmt) -{ - if (*fmt == '\0') - return (fmt); - while (ft_strchr(FLAGS_STR, *fmt) != NULL) - { - if (*fmt == '0') - pformat->flags |= FLAG_ZERO; - if (*fmt == '-') - pformat->flags |= FLAG_MINUS; - if (*fmt == '+') - pformat->flags |= FLAG_SIGNED; - if (*fmt == ' ') - pformat->flags |= FLAG_SPACE; - if (*fmt == '#') - pformat->flags |= FLAG_ALTERNATE; - if (*fmt == '\'') - ; - fmt++; - } - if (pformat->flags & FLAG_SIGNED) - pformat->flags &= ~FLAG_SPACE; - return (fmt); -} - -const char *extract_width(t_pformat *pformat, const char *fmt) -{ - if (*fmt == '\0') - return (fmt); - if (*fmt == '*') - { - pformat->flags |= FLAG_WIDTH_WILDCARD; - fmt++; - } - if (!ft_isdigit(*fmt)) - return (fmt); - pformat->width = ft_atoi(fmt); - while (*fmt && ft_isdigit(*fmt)) - fmt++; - if (pformat->flags & FLAG_WIDTH_WILDCARD) - pformat->flags |= FLAG_WIDTH_OVERWRITE; - return (fmt); -} - -const char *extract_precision(t_pformat *pformat, const char *fmt) -{ - if (*fmt == '\0' || *fmt != '.') - return (fmt); - fmt++; - if (*fmt == '*') - { - pformat->flags |= FLAG_PRECISION_WILDCARD; - fmt++; - } - pformat->precision = ft_atoi(fmt); - while (*fmt && ft_isdigit(*fmt)) - fmt++; - return (fmt); -} - -const char *extract_length_modifier(t_pformat *pformat, const char *fmt) -{ - if (fmt[0] && fmt[0] == 'l') - { - if (fmt[1] && fmt[1] == 'l') - { - pformat->flags |= FLAG_LONG_LONG; - return (fmt + 2); - } - pformat->flags |= FLAG_LONG; - return (fmt + 1); - } - if (fmt[0] && fmt[0] == 'h') - { - if (fmt[1] && fmt[1] == 'h') - { - pformat->flags |= FLAG_SHORT_SHORT; - return (fmt + 2); - } - pformat->flags |= FLAG_SHORT; - return (fmt + 1); - } - return (fmt); -} diff --git a/src/io/ft_printf/ft_asprintf.c b/src/io/ft_printf/ft_asprintf.c new file mode 100644 index 0000000..5eb62d9 --- /dev/null +++ b/src/io/ft_printf/ft_asprintf.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_asprintf.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/11/21 02:30:33 by cacharle #+# #+# */ +/* Updated: 2019/11/21 03:43:08 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_asprintf(char **ret, const char *format, ...) +{ + int vret; + va_list ap; + + va_start(ap, format); + vret = ft_vasprintf(ret, format, ap); + va_end(ap); + return (vret); +} diff --git a/src/io/ft_printf/ft_dprintf.c b/src/io/ft_printf/ft_dprintf.c new file mode 100644 index 0000000..8e60970 --- /dev/null +++ b/src/io/ft_printf/ft_dprintf.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_dprintf.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/11/21 02:29:11 by cacharle #+# #+# */ +/* Updated: 2019/11/21 03:42:05 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_dprintf(int fd, const char *format, ...) +{ + int ret; + va_list ap; + + va_start(ap, format); + ret = ft_vdprintf(fd, format, ap); + va_end(ap); + return (ret); +} diff --git a/src/io/ft_printf/ft_printf.c b/src/io/ft_printf/ft_printf.c index daa0cf2..1b92bb2 100644 --- a/src/io/ft_printf/ft_printf.c +++ b/src/io/ft_printf/ft_printf.c @@ -5,88 +5,20 @@ /* +:+ +:+ +:+ */ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2019/10/29 00:15:28 by cacharle #+# #+# */ -/* Updated: 2019/11/13 08:56:49 by cacharle ### ########.fr */ +/* Created: 2019/11/21 02:31:32 by cacharle #+# #+# */ +/* Updated: 2019/11/21 03:41:54 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ -#include "ft_vasprintf.h" +#include "libft.h" -int ft_printf(const char *format, ...) +int ft_printf(const char *format, ...) { - t_printf_status status; + int ret; + va_list ap; - if (format == NULL) - return (STATUS_ERROR); - if (!parse(format, &status.flist)) - return (STATUS_ERROR); - va_start(status.ap, format); - status.format = format; - status.out = NULL; - status.out_size = 0; - while (*status.format) - { - if (*status.format == '%' - && (status.format = - add_conversion(&status, status.flist->content)) == NULL) - return (destroy_status_error(&status)); - else if ((status.format = add_between(&status)) == NULL) - return (destroy_status_error(&status)); - } - va_end(status.ap); - list_destroy(&status.flist); - write(STDOUT_FILENO, status.out, status.out_size); - free(status.out); - return (status.out_size); -} - -const char *add_conversion(t_printf_status *status, t_pformat *pformat) -{ - char *conversion_str; - - conversion_str = convert(pformat, status->ap); - if (pformat->specifier == 'n') - { - if (pformat->written != NULL) - *pformat->written = status->out_size; - status->format += pformat->fmt_len; - list_pop_front(&status->flist); - return (status->format + 1); - } - if (conversion_str == NULL) - return (NULL); - if (pformat->specifier != 'c') - pformat->size = ft_strlen(conversion_str); - if ((status->out = ft_memjoin_free(status->out, status->out_size, - conversion_str, pformat->size)) == NULL) - return (NULL); - status->out_size += pformat->size; - free(conversion_str); - status->format += pformat->fmt_len; - list_pop_front(&status->flist); - return (status->format + 1); -} - -const char *add_between(t_printf_status *status) -{ - int i; - - i = 0; - while (status->format[i] && status->format[i] != '%') - i++; - if ((status->out = ft_memjoin_free(status->out, status->out_size, - (void*)status->format, i)) == NULL) - return (NULL); - status->out_size += i; - return (status->format + i); -} - -int destroy_status_error(t_printf_status *status) -{ - if (status == NULL) - return (STATUS_ERROR); - va_end(status->ap); - list_destroy(&status->flist); - free(status->out); - return (STATUS_ERROR); + va_start(ap, format); + ret = ft_vprintf(format, ap); + va_end(ap); + return (ret); } diff --git a/src/io/ft_printf/ft_snprintf.c b/src/io/ft_printf/ft_snprintf.c new file mode 100644 index 0000000..e1fdfbd --- /dev/null +++ b/src/io/ft_printf/ft_snprintf.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_snprintf.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/11/21 02:27:55 by cacharle #+# #+# */ +/* Updated: 2019/11/21 03:41:49 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_snprintf(char *str, size_t size, const char *format, ...) +{ + int ret; + va_list ap; + + va_start(ap, format); + ret = ft_vsnprintf(str, size, format, ap); + va_end(ap); + return (ret); +} diff --git a/src/io/ft_printf/ft_sprintf.c b/src/io/ft_printf/ft_sprintf.c new file mode 100644 index 0000000..31da75e --- /dev/null +++ b/src/io/ft_printf/ft_sprintf.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_sprintf.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/11/21 02:17:21 by cacharle #+# #+# */ +/* Updated: 2019/11/21 03:42:28 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_sprintf(char *str, const char *format, ...) +{ + int ret; + va_list ap; + + va_start(ap, format); + ret = ft_vsprintf(str, format, ap); + va_end(ap); + return (ret); +} diff --git a/src/io/ft_printf/ft_vasprintf.c b/src/io/ft_printf/ft_vasprintf.c new file mode 100644 index 0000000..85f66bc --- /dev/null +++ b/src/io/ft_printf/ft_vasprintf.c @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_vasprintf.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/11/21 02:49:56 by cacharle #+# #+# */ +/* Updated: 2019/11/21 03:45:39 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_vasprintf(char **ret, const char *format, va_list ap) +{ + (void)ret; + (void)format; + (void)ap; + return (0); +} diff --git a/src/io/ft_printf/ft_vdprintf.c b/src/io/ft_printf/ft_vdprintf.c new file mode 100644 index 0000000..a5e5ebf --- /dev/null +++ b/src/io/ft_printf/ft_vdprintf.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_vdprintf.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/11/21 02:40:03 by cacharle #+# #+# */ +/* Updated: 2019/11/21 03:46:00 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_vdprintf(int fd, const char *format, va_list ap) +{ + int out_len; + char *out; + + if ((out_len = ft_vasprintf(&out, format, ap)) == -1) + return (-1); + write(fd, out, out_len); + return (out_len); +} diff --git a/src/io/ft_printf/ft_vprintf.c b/src/io/ft_printf/ft_vprintf.c new file mode 100644 index 0000000..b98670b --- /dev/null +++ b/src/io/ft_printf/ft_vprintf.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_vprintf.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/11/21 02:32:44 by cacharle #+# #+# */ +/* Updated: 2019/11/21 03:44:11 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_vprintf(const char *format, va_list ap) +{ + return (ft_vdprintf(STDOUT_FILENO, format, ap)); +} diff --git a/src/io/ft_printf/ft_vsnprintf.c b/src/io/ft_printf/ft_vsnprintf.c new file mode 100644 index 0000000..7db988c --- /dev/null +++ b/src/io/ft_printf/ft_vsnprintf.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_vsnprintf.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/11/21 02:36:32 by cacharle #+# #+# */ +/* Updated: 2019/11/21 03:45:14 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_vsnprintf(char *str, size_t size, const char *format, va_list ap) +{ + int ret; + int full_out_len; + char *full_out; + + full_out_len = ft_vasprintf(&full_out, format, ap); + ft_strncpy(str, full_out, size); + ret = MIN((size_t)full_out_len, size); + free(full_out); + return (ret); +} diff --git a/src/io/ft_printf/ft_vsprintf.c b/src/io/ft_printf/ft_vsprintf.c new file mode 100644 index 0000000..91b4815 --- /dev/null +++ b/src/io/ft_printf/ft_vsprintf.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_vsprintf.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/11/21 02:34:17 by cacharle #+# #+# */ +/* Updated: 2019/11/21 03:44:24 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_vsprintf(char *str, const char *format, va_list ap) +{ + return (ft_vsnprintf(str, INT_MAX + 1, format, ap)); +} diff --git a/src/io/ft_printf/internals/convert.c b/src/io/ft_printf/internals/convert.c new file mode 100644 index 0000000..398c754 --- /dev/null +++ b/src/io/ft_printf/internals/convert.c @@ -0,0 +1,122 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* printer.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/10/28 23:19:24 by cacharle #+# #+# */ +/* Updated: 2019/11/14 10:22:04 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include +#include +#include "libft.h" +#include "ft_vasprintf.h" + +char *convert(t_pformat *pformat, va_list ap) +{ + char *str; + + if (pformat == NULL) + return (NULL); + if (pformat->flags & FLAG_WIDTH_WILDCARD) + { + if (pformat->flags & FLAG_WIDTH_OVERWRITE) + (void)va_arg(ap, int); + else + pformat->width = va_arg(ap, int); + if (pformat->width < 0) + { + pformat->flags |= FLAG_MINUS; + pformat->width *= -1; + } + } + if (pformat->flags & FLAG_PRECISION_WILDCARD) + pformat->precision = va_arg(ap, int); + if ((str = convert_specifier(ap, pformat)) == NULL) + return (NULL); + return (str); +} + +char *convert_specifier(va_list ap, t_pformat *pformat) +{ + if (pformat->specifier == 'c') + return (convert_char(ap, pformat)); + if (pformat->specifier == 's') + return (convert_str(ap, pformat)); + if (pformat->specifier == 'p') + return (convert_ptr(ap, pformat)); + if (pformat->specifier == 'd' || pformat->specifier == 'i') + return (convert_int(ap, pformat)); + if (pformat->specifier == 'u') + return (convert_uint(ap, pformat)); + if (pformat->specifier == 'x') + return (convert_hex(ap, pformat)); + if (pformat->specifier == 'X') + return (convert_hex(ap, pformat)); + if (pformat->specifier == '%') + return (convert_percent(ap, pformat)); + if (pformat->specifier == 'n') + return (convert_written(ap, pformat)); + else + return (convert_none(ap, pformat)); + return (NULL); +} + +char *handle_width(t_pformat *pformat, char *str) +{ + char *tmp; + int len; + int i; + + if ((len = ft_strlen(str)) >= pformat->width) + return (str); + if ((tmp = (char*)malloc(sizeof(char) * (pformat->width + 1))) == NULL) + return (NULL); + if (pformat->flags & FLAG_MINUS) + { + i = len; + ft_strcpy(tmp, str); + while (i < pformat->width) + tmp[i++] = ' '; + tmp[i] = 0; + } + else + { + i = 0; + while (i <= pformat->width - len) + tmp[i++] = pformat->flags & FLAG_ZERO ? '0' : ' '; + ft_strcpy(tmp + i - 1, str); + } + free(str); + return (tmp); +} + +char *handle_precision(t_pformat *pformat, char *str) +{ + int len; + char *tmp; + + if (pformat == NULL || str == NULL) + return (NULL); + if (ft_strchr("diuxX", pformat->specifier) && pformat->precision >= 0) + pformat->flags &= ~FLAG_ZERO; + len = ft_strlen(str); + if (pformat->precision == 0 && str[0] == '0') + { + free(str); + return (ft_strdup("")); + } + if (!ft_strchr("diuxXp", pformat->specifier) || len >= pformat->precision) + return (str); + if ((tmp = (char*)malloc(sizeof(char) * (pformat->precision + 1))) == NULL) + return (NULL); + ft_strcpy(tmp + pformat->precision - len, str); + while (pformat->precision-- > len) + tmp[pformat->precision - len] = '0'; + free(str); + return (tmp); +} diff --git a/src/io/ft_printf/internals/convert_char.c b/src/io/ft_printf/internals/convert_char.c new file mode 100644 index 0000000..c5f3a93 --- /dev/null +++ b/src/io/ft_printf/internals/convert_char.c @@ -0,0 +1,53 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* convert_char.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/10/30 23:22:29 by cacharle #+# #+# */ +/* Updated: 2019/11/05 23:44:42 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_vasprintf.h" + +static char *handle_width_char(t_pformat *pformat, char *str) +{ + char *tmp; + int i; + + pformat->size = 1; + if (1 >= pformat->width) + return (str); + if ((tmp = (char*)malloc(sizeof(char) * (pformat->width + 1))) == NULL) + return (NULL); + if (pformat->flags & FLAG_MINUS) + { + ft_memcpy(tmp, str, (i = 1) + 1); + while (i < pformat->width) + tmp[i++] = ' '; + tmp[i] = 0; + } + else + { + i = 0; + while (i <= pformat->width - 1) + tmp[i++] = pformat->flags & FLAG_ZERO ? '0' : ' '; + ft_memcpy(tmp + i - 1, str, 2); + } + free(str); + pformat->size = pformat->width; + return (tmp); +} + +char *convert_char(va_list ap, t_pformat *pformat) +{ + char *str; + + if ((str = ft_strnew(2)) == NULL) + return (NULL); + str[0] = va_arg(ap, int); + str[1] = '\0'; + return (handle_width_char(pformat, str)); +} diff --git a/src/io/ft_printf/internals/convert_hex.c b/src/io/ft_printf/internals/convert_hex.c new file mode 100644 index 0000000..0464dc7 --- /dev/null +++ b/src/io/ft_printf/internals/convert_hex.c @@ -0,0 +1,34 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* convert_hex.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/10/30 23:23:06 by cacharle #+# #+# */ +/* Updated: 2019/11/05 23:58:59 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_vasprintf.h" + +char *convert_hex(va_list ap, t_pformat *pformat) +{ + char *str; + long long unsigned int n; + + n = length_modifier_unsigned_int(ap, pformat); + str = pformat->specifier == 'x' ? ITOA_HEX_LOW(n) : ITOA_HEX_UP(n); + str = handle_precision(pformat, str); + if (pformat->flags & FLAG_ZERO) + { + if (pformat->flags & FLAG_ALTERNATE && n != 0) + pformat->width -= 2; + str = handle_width(pformat, str); + } + if (pformat->flags & FLAG_ALTERNATE && n != 0) + str = ft_strjoin_free_snd(pformat->specifier == 'X' ? "0X" : "0x", str); + if (!(pformat->flags & FLAG_ZERO)) + str = handle_width(pformat, str); + return (str); +} diff --git a/src/io/ft_printf/internals/convert_int.c b/src/io/ft_printf/internals/convert_int.c new file mode 100644 index 0000000..2345f76 --- /dev/null +++ b/src/io/ft_printf/internals/convert_int.c @@ -0,0 +1,40 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* convert_int.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/10/30 23:29:53 by cacharle #+# #+# */ +/* Updated: 2019/11/06 00:00:09 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_vasprintf.h" + +char *convert_int(va_list ap, t_pformat *pformat) +{ + int is_neg; + long long int n; + char *str; + + n = length_modifier_int(ap, pformat); + is_neg = n < 0; + str = ITOA_DEC(n); + if (is_neg) + ft_strcpy(str, str + 1); + str = handle_precision(pformat, str); + if (pformat->flags & FLAG_ZERO) + { + if (is_neg || pformat->flags & (FLAG_SIGNED | FLAG_SPACE)) + pformat->width--; + str = handle_width(pformat, str); + } + if (is_neg) + str = ft_strjoin_free_snd("-", str); + else if (pformat->flags & (FLAG_SIGNED | FLAG_SPACE)) + str = ft_strjoin_free_snd(pformat->flags & FLAG_SPACE ? " " : "+", str); + if (!(pformat->flags & FLAG_ZERO)) + str = handle_width(pformat, str); + return (str); +} diff --git a/src/io/ft_printf/internals/convert_none.c b/src/io/ft_printf/internals/convert_none.c new file mode 100644 index 0000000..358ef1b --- /dev/null +++ b/src/io/ft_printf/internals/convert_none.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* convert_none.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/11/04 19:30:25 by cacharle #+# #+# */ +/* Updated: 2019/11/05 23:44:13 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_vasprintf.h" + +char *convert_none(va_list ap, t_pformat *pformat) +{ + char *str; + + (void)ap; + if ((str = ft_strdup("")) == NULL) + return (NULL); + str = handle_precision(pformat, str); + str = handle_width(pformat, str); + return (str); +} diff --git a/src/io/ft_printf/internals/convert_percent.c b/src/io/ft_printf/internals/convert_percent.c new file mode 100644 index 0000000..813bb77 --- /dev/null +++ b/src/io/ft_printf/internals/convert_percent.c @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* convert_percent.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/10/30 23:23:27 by cacharle #+# #+# */ +/* Updated: 2019/11/05 23:44:07 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_vasprintf.h" + +char *convert_percent(va_list ap, t_pformat *pformat) +{ + char *str; + + (void)ap; + str = ft_strdup("%"); + str = handle_width(pformat, str); + return (str); +} diff --git a/src/io/ft_printf/internals/convert_ptr.c b/src/io/ft_printf/internals/convert_ptr.c new file mode 100644 index 0000000..63babb9 --- /dev/null +++ b/src/io/ft_printf/internals/convert_ptr.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* convert_ptr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/10/30 23:24:08 by cacharle #+# #+# */ +/* Updated: 2019/11/05 23:43:45 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_vasprintf.h" + +char *convert_ptr(va_list ap, t_pformat *pformat) +{ + char *str; + + str = ITOA_HEX_LOW((long long unsigned int)va_arg(ap, void*)); + str = handle_precision(pformat, str); + if (!(pformat->flags & FLAG_ZERO)) + str = ft_strjoin_free_snd("0x", str); + if (pformat->flags & FLAG_ZERO) + pformat->width -= 2; + str = handle_width(pformat, str); + if (pformat->flags & FLAG_ZERO) + str = ft_strjoin_free_snd("0x", str); + return (str); +} diff --git a/src/io/ft_printf/internals/convert_str.c b/src/io/ft_printf/internals/convert_str.c new file mode 100644 index 0000000..7d51a5e --- /dev/null +++ b/src/io/ft_printf/internals/convert_str.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* convert_str.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/10/30 23:22:25 by cacharle #+# #+# */ +/* Updated: 2019/11/09 01:07:24 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_vasprintf.h" + +char *convert_str(va_list ap, t_pformat *pformat) +{ + char *str; + + str = va_arg(ap, char*); + str = str == NULL ? ft_strdup("(null)") : ft_strdup(str); + if (pformat->precision >= 0 && pformat->precision < (int)ft_strlen(str)) + str[pformat->precision] = '\0'; + str = handle_width(pformat, str); + return (str); +} diff --git a/src/io/ft_printf/internals/convert_uint.c b/src/io/ft_printf/internals/convert_uint.c new file mode 100644 index 0000000..4207165 --- /dev/null +++ b/src/io/ft_printf/internals/convert_uint.c @@ -0,0 +1,34 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* convert_uint.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/10/30 23:25:40 by cacharle #+# #+# */ +/* Updated: 2019/11/05 23:44:19 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_vasprintf.h" + +char *convert_uint(va_list ap, t_pformat *pformat) +{ + char *str; + long long unsigned int n; + + if (pformat->flags & FLAG_SHORT) + n = (unsigned short)va_arg(ap, int); + else if (pformat->flags & FLAG_SHORT_SHORT) + n = (unsigned char)va_arg(ap, int); + else if (pformat->flags & FLAG_LONG) + n = va_arg(ap, long unsigned int); + else if (pformat->flags & FLAG_LONG_LONG) + n = va_arg(ap, long long unsigned int); + else + n = va_arg(ap, unsigned int); + str = ft_itoa_unsigned_base(n, "0123456789"); + str = handle_precision(pformat, str); + str = handle_width(pformat, str); + return (str); +} diff --git a/src/io/ft_printf/internals/convert_written.c b/src/io/ft_printf/internals/convert_written.c new file mode 100644 index 0000000..4beeaef --- /dev/null +++ b/src/io/ft_printf/internals/convert_written.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* convert_written.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/10/30 23:38:28 by cacharle #+# #+# */ +/* Updated: 2019/11/05 23:59:24 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_vasprintf.h" + +char *convert_written(va_list ap, t_pformat *pformat) +{ + if (pformat->flags & FLAG_SHORT) + pformat->written = (long long int*)va_arg(ap, signed char*); + if (pformat->flags & FLAG_SHORT_SHORT) + pformat->written = (long long int*)va_arg(ap, short*); + if (pformat->flags & FLAG_LONG) + pformat->written = (long long int*)va_arg(ap, long int*); + if (pformat->flags & FLAG_LONG_LONG) + pformat->written = va_arg(ap, long long int*); + else + pformat->written = (long long int*)va_arg(ap, int*); + return (NULL); +} diff --git a/src/io/ft_printf/internals/extract.c b/src/io/ft_printf/internals/extract.c new file mode 100644 index 0000000..c56a777 --- /dev/null +++ b/src/io/ft_printf/internals/extract.c @@ -0,0 +1,98 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* extract.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/10/29 00:10:36 by cacharle #+# #+# */ +/* Updated: 2019/11/10 10:33:33 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_vasprintf.h" + +const char *extract_flags(t_pformat *pformat, const char *fmt) +{ + if (*fmt == '\0') + return (fmt); + while (ft_strchr(FLAGS_STR, *fmt) != NULL) + { + if (*fmt == '0') + pformat->flags |= FLAG_ZERO; + if (*fmt == '-') + pformat->flags |= FLAG_MINUS; + if (*fmt == '+') + pformat->flags |= FLAG_SIGNED; + if (*fmt == ' ') + pformat->flags |= FLAG_SPACE; + if (*fmt == '#') + pformat->flags |= FLAG_ALTERNATE; + if (*fmt == '\'') + ; + fmt++; + } + if (pformat->flags & FLAG_SIGNED) + pformat->flags &= ~FLAG_SPACE; + return (fmt); +} + +const char *extract_width(t_pformat *pformat, const char *fmt) +{ + if (*fmt == '\0') + return (fmt); + if (*fmt == '*') + { + pformat->flags |= FLAG_WIDTH_WILDCARD; + fmt++; + } + if (!ft_isdigit(*fmt)) + return (fmt); + pformat->width = ft_atoi(fmt); + while (*fmt && ft_isdigit(*fmt)) + fmt++; + if (pformat->flags & FLAG_WIDTH_WILDCARD) + pformat->flags |= FLAG_WIDTH_OVERWRITE; + return (fmt); +} + +const char *extract_precision(t_pformat *pformat, const char *fmt) +{ + if (*fmt == '\0' || *fmt != '.') + return (fmt); + fmt++; + if (*fmt == '*') + { + pformat->flags |= FLAG_PRECISION_WILDCARD; + fmt++; + } + pformat->precision = ft_atoi(fmt); + while (*fmt && ft_isdigit(*fmt)) + fmt++; + return (fmt); +} + +const char *extract_length_modifier(t_pformat *pformat, const char *fmt) +{ + if (fmt[0] && fmt[0] == 'l') + { + if (fmt[1] && fmt[1] == 'l') + { + pformat->flags |= FLAG_LONG_LONG; + return (fmt + 2); + } + pformat->flags |= FLAG_LONG; + return (fmt + 1); + } + if (fmt[0] && fmt[0] == 'h') + { + if (fmt[1] && fmt[1] == 'h') + { + pformat->flags |= FLAG_SHORT_SHORT; + return (fmt + 2); + } + pformat->flags |= FLAG_SHORT; + return (fmt + 1); + } + return (fmt); +} diff --git a/src/io/ft_printf/internals/length_modifier.c b/src/io/ft_printf/internals/length_modifier.c new file mode 100644 index 0000000..88226da --- /dev/null +++ b/src/io/ft_printf/internals/length_modifier.c @@ -0,0 +1,39 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* length_modifier.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/11/05 23:56:07 by cacharle #+# #+# */ +/* Updated: 2019/11/09 00:50:06 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_vasprintf.h" + +t_big_uint length_modifier_unsigned_int(va_list ap, t_pformat *pformat) +{ + if (pformat->flags & FLAG_SHORT) + return ((unsigned short)va_arg(ap, int)); + else if (pformat->flags & FLAG_SHORT_SHORT) + return ((unsigned char)va_arg(ap, int)); + else if (pformat->flags & FLAG_LONG) + return (va_arg(ap, long unsigned int)); + else if (pformat->flags & FLAG_LONG_LONG) + return (va_arg(ap, long long unsigned int)); + return (va_arg(ap, unsigned int)); +} + +t_big_int length_modifier_int(va_list ap, t_pformat *pformat) +{ + if (pformat->flags & FLAG_SHORT) + return ((short)va_arg(ap, int)); + else if (pformat->flags & FLAG_SHORT_SHORT) + return ((signed char)va_arg(ap, int)); + else if (pformat->flags & FLAG_LONG) + return (va_arg(ap, long int)); + else if (pformat->flags & FLAG_LONG_LONG) + return (va_arg(ap, long long int)); + return (va_arg(ap, int)); +} diff --git a/src/io/ft_printf/internals/list.c b/src/io/ft_printf/internals/list.c new file mode 100644 index 0000000..99491f4 --- /dev/null +++ b/src/io/ft_printf/internals/list.c @@ -0,0 +1,67 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* list.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/10/29 00:14:50 by cacharle #+# #+# */ +/* Updated: 2019/11/05 23:45:42 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_vasprintf.h" + +t_flist *list_new(t_pformat *content) +{ + t_flist *lst; + + if ((lst = (t_flist*)malloc(sizeof(t_flist))) == NULL) + return (NULL); + lst->content = content; + lst->next = NULL; + return (lst); +} + +void *list_destroy(t_flist **lst) +{ + if (lst == NULL) + return (NULL); + while (*lst != NULL) + list_pop_front(lst); + return (NULL); +} + +void list_push_front(t_flist **lst, t_flist *new) +{ + if (lst == NULL || new == NULL) + return ; + new->next = *lst; + *lst = new; +} + +void list_pop_front(t_flist **lst) +{ + t_flist *tmp; + + if (lst == NULL || *lst == NULL) + return ; + tmp = (*lst)->next; + free((*lst)->content); + free(*lst); + *lst = tmp; +} + +t_flist *list_reverse(t_flist *lst) +{ + t_flist *tmp; + + if (lst == NULL) + return (NULL); + if (lst->next == NULL) + return (lst); + tmp = list_reverse(lst->next); + lst->next->next = lst; + lst->next = NULL; + return (tmp); +} diff --git a/src/io/ft_printf/internals/parse.c b/src/io/ft_printf/internals/parse.c new file mode 100644 index 0000000..33928a0 --- /dev/null +++ b/src/io/ft_printf/internals/parse.c @@ -0,0 +1,61 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* parse.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/10/29 00:11:33 by cacharle #+# #+# */ +/* Updated: 2019/11/13 08:13:02 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_vasprintf.h" + +int parse(const char *format, t_flist **flist) +{ + t_flist *tmp; + t_pformat *parsed; + + *flist = NULL; + while (*format) + { + format++; + if (format[-1] != '%') + continue; + if ((parsed = parse_reduced(format)) == NULL) + return ((int)list_destroy(flist)); + if ((tmp = list_new(parsed)) == NULL) + return ((int)list_destroy(flist)); + list_push_front(flist, tmp); + format += (*flist)->content->fmt_len; + } + *flist = list_reverse(*flist); + return (1); +} + +t_pformat *parse_reduced(const char *fmt) +{ + t_pformat *pformat; + const char *start; + + if ((pformat = (t_pformat*)malloc(sizeof(t_pformat))) == NULL) + return (NULL); + pformat->precision = -1; + pformat->width = -1; + pformat->flags = 0; + start = fmt; + fmt = extract_flags(pformat, fmt); + fmt = extract_width(pformat, fmt); + fmt = extract_precision(pformat, fmt); + fmt = extract_length_modifier(pformat, fmt); + pformat->fmt_len = fmt - start + 1; + if (*fmt == '\0' || ft_strchr(SPECIFIERS_STR, *fmt) == NULL) + { + pformat->fmt_len--; + pformat->specifier = '_'; + } + else + pformat->specifier = *ft_strchr(SPECIFIERS_STR, *fmt); + return (pformat); +} diff --git a/src/io/ft_printf/internals/utils.c b/src/io/ft_printf/internals/utils.c new file mode 100644 index 0000000..ad44980 --- /dev/null +++ b/src/io/ft_printf/internals/utils.c @@ -0,0 +1,115 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* utils.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/10/29 00:12:40 by cacharle #+# #+# */ +/* Updated: 2019/11/13 08:49:58 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_vasprintf.h" + +static int nbrlen_radix(long long int nbr, int radix) +{ + int counter; + long long unsigned int u_nbr; + + if (nbr == 0) + return (1); + counter = 0; + u_nbr = nbr; + if (nbr < 0) + { + counter++; + u_nbr = -nbr; + } + while (u_nbr > 0) + { + u_nbr /= radix; + counter++; + } + return (counter); +} + +char *ft_itoa_base(long long int n, char *base) +{ + char *str; + int len; + int radix; + long long unsigned int u_nbr; + + radix = ft_strlen(base); + len = nbrlen_radix(n, radix); + if ((str = (char*)malloc(sizeof(char) * (len + 1))) == NULL) + return (NULL); + str[len] = '\0'; + u_nbr = n < 0 ? -n : n; + if (n < 0) + str[0] = '-'; + while (--len >= (n < 0 ? 1 : 0)) + { + str[len] = base[u_nbr % radix]; + u_nbr /= radix; + } + return (str); +} + +static int nbrlen_unsigned_radix(long long unsigned int nbr, int radix) +{ + int counter; + + if (nbr == 0) + return (1); + counter = 0; + while (nbr > 0) + { + nbr /= radix; + counter++; + } + return (counter); +} + +char *ft_itoa_unsigned_base(long long unsigned int n, char *base) +{ + char *str; + int len; + int radix; + + radix = ft_strlen(base); + len = nbrlen_unsigned_radix(n, radix); + if ((str = (char*)malloc(sizeof(char) * (len + 1))) == NULL) + return (NULL); + str[len] = '\0'; + while (--len >= 0) + { + str[len] = base[n % radix]; + n /= radix; + } + return (str); +} + +void *ft_memjoin_free(void *dst, int dst_size, void *src, int src_size) +{ + void *clone; + + if (dst == NULL) + { + if ((dst = malloc(src_size)) == NULL) + return (NULL); + ft_memcpy(dst, src, src_size); + return (dst); + } + if ((clone = malloc(dst_size)) == NULL) + return (NULL); + ft_memcpy(clone, dst, dst_size); + free(dst); + if ((dst = malloc(dst_size + src_size)) == NULL) + return (NULL); + ft_memcpy(dst, clone, dst_size); + free(clone); + ft_memcpy(dst + dst_size, src, src_size); + return (dst); +} diff --git a/src/io/ft_printf/length_modifier.c b/src/io/ft_printf/length_modifier.c deleted file mode 100644 index 88226da..0000000 --- a/src/io/ft_printf/length_modifier.c +++ /dev/null @@ -1,39 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* length_modifier.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: cacharle +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2019/11/05 23:56:07 by cacharle #+# #+# */ -/* Updated: 2019/11/09 00:50:06 by cacharle ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "ft_vasprintf.h" - -t_big_uint length_modifier_unsigned_int(va_list ap, t_pformat *pformat) -{ - if (pformat->flags & FLAG_SHORT) - return ((unsigned short)va_arg(ap, int)); - else if (pformat->flags & FLAG_SHORT_SHORT) - return ((unsigned char)va_arg(ap, int)); - else if (pformat->flags & FLAG_LONG) - return (va_arg(ap, long unsigned int)); - else if (pformat->flags & FLAG_LONG_LONG) - return (va_arg(ap, long long unsigned int)); - return (va_arg(ap, unsigned int)); -} - -t_big_int length_modifier_int(va_list ap, t_pformat *pformat) -{ - if (pformat->flags & FLAG_SHORT) - return ((short)va_arg(ap, int)); - else if (pformat->flags & FLAG_SHORT_SHORT) - return ((signed char)va_arg(ap, int)); - else if (pformat->flags & FLAG_LONG) - return (va_arg(ap, long int)); - else if (pformat->flags & FLAG_LONG_LONG) - return (va_arg(ap, long long int)); - return (va_arg(ap, int)); -} diff --git a/src/io/ft_printf/list.c b/src/io/ft_printf/list.c deleted file mode 100644 index 99491f4..0000000 --- a/src/io/ft_printf/list.c +++ /dev/null @@ -1,67 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* list.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: cacharle +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2019/10/29 00:14:50 by cacharle #+# #+# */ -/* Updated: 2019/11/05 23:45:42 by cacharle ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "ft_vasprintf.h" - -t_flist *list_new(t_pformat *content) -{ - t_flist *lst; - - if ((lst = (t_flist*)malloc(sizeof(t_flist))) == NULL) - return (NULL); - lst->content = content; - lst->next = NULL; - return (lst); -} - -void *list_destroy(t_flist **lst) -{ - if (lst == NULL) - return (NULL); - while (*lst != NULL) - list_pop_front(lst); - return (NULL); -} - -void list_push_front(t_flist **lst, t_flist *new) -{ - if (lst == NULL || new == NULL) - return ; - new->next = *lst; - *lst = new; -} - -void list_pop_front(t_flist **lst) -{ - t_flist *tmp; - - if (lst == NULL || *lst == NULL) - return ; - tmp = (*lst)->next; - free((*lst)->content); - free(*lst); - *lst = tmp; -} - -t_flist *list_reverse(t_flist *lst) -{ - t_flist *tmp; - - if (lst == NULL) - return (NULL); - if (lst->next == NULL) - return (lst); - tmp = list_reverse(lst->next); - lst->next->next = lst; - lst->next = NULL; - return (tmp); -} diff --git a/src/io/ft_printf/parse.c b/src/io/ft_printf/parse.c deleted file mode 100644 index 33928a0..0000000 --- a/src/io/ft_printf/parse.c +++ /dev/null @@ -1,61 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* parse.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: cacharle +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2019/10/29 00:11:33 by cacharle #+# #+# */ -/* Updated: 2019/11/13 08:13:02 by cacharle ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "ft_vasprintf.h" - -int parse(const char *format, t_flist **flist) -{ - t_flist *tmp; - t_pformat *parsed; - - *flist = NULL; - while (*format) - { - format++; - if (format[-1] != '%') - continue; - if ((parsed = parse_reduced(format)) == NULL) - return ((int)list_destroy(flist)); - if ((tmp = list_new(parsed)) == NULL) - return ((int)list_destroy(flist)); - list_push_front(flist, tmp); - format += (*flist)->content->fmt_len; - } - *flist = list_reverse(*flist); - return (1); -} - -t_pformat *parse_reduced(const char *fmt) -{ - t_pformat *pformat; - const char *start; - - if ((pformat = (t_pformat*)malloc(sizeof(t_pformat))) == NULL) - return (NULL); - pformat->precision = -1; - pformat->width = -1; - pformat->flags = 0; - start = fmt; - fmt = extract_flags(pformat, fmt); - fmt = extract_width(pformat, fmt); - fmt = extract_precision(pformat, fmt); - fmt = extract_length_modifier(pformat, fmt); - pformat->fmt_len = fmt - start + 1; - if (*fmt == '\0' || ft_strchr(SPECIFIERS_STR, *fmt) == NULL) - { - pformat->fmt_len--; - pformat->specifier = '_'; - } - else - pformat->specifier = *ft_strchr(SPECIFIERS_STR, *fmt); - return (pformat); -} diff --git a/src/io/ft_printf/utils.c b/src/io/ft_printf/utils.c deleted file mode 100644 index ad44980..0000000 --- a/src/io/ft_printf/utils.c +++ /dev/null @@ -1,115 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* utils.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: cacharle +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2019/10/29 00:12:40 by cacharle #+# #+# */ -/* Updated: 2019/11/13 08:49:58 by cacharle ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "ft_vasprintf.h" - -static int nbrlen_radix(long long int nbr, int radix) -{ - int counter; - long long unsigned int u_nbr; - - if (nbr == 0) - return (1); - counter = 0; - u_nbr = nbr; - if (nbr < 0) - { - counter++; - u_nbr = -nbr; - } - while (u_nbr > 0) - { - u_nbr /= radix; - counter++; - } - return (counter); -} - -char *ft_itoa_base(long long int n, char *base) -{ - char *str; - int len; - int radix; - long long unsigned int u_nbr; - - radix = ft_strlen(base); - len = nbrlen_radix(n, radix); - if ((str = (char*)malloc(sizeof(char) * (len + 1))) == NULL) - return (NULL); - str[len] = '\0'; - u_nbr = n < 0 ? -n : n; - if (n < 0) - str[0] = '-'; - while (--len >= (n < 0 ? 1 : 0)) - { - str[len] = base[u_nbr % radix]; - u_nbr /= radix; - } - return (str); -} - -static int nbrlen_unsigned_radix(long long unsigned int nbr, int radix) -{ - int counter; - - if (nbr == 0) - return (1); - counter = 0; - while (nbr > 0) - { - nbr /= radix; - counter++; - } - return (counter); -} - -char *ft_itoa_unsigned_base(long long unsigned int n, char *base) -{ - char *str; - int len; - int radix; - - radix = ft_strlen(base); - len = nbrlen_unsigned_radix(n, radix); - if ((str = (char*)malloc(sizeof(char) * (len + 1))) == NULL) - return (NULL); - str[len] = '\0'; - while (--len >= 0) - { - str[len] = base[n % radix]; - n /= radix; - } - return (str); -} - -void *ft_memjoin_free(void *dst, int dst_size, void *src, int src_size) -{ - void *clone; - - if (dst == NULL) - { - if ((dst = malloc(src_size)) == NULL) - return (NULL); - ft_memcpy(dst, src, src_size); - return (dst); - } - if ((clone = malloc(dst_size)) == NULL) - return (NULL); - ft_memcpy(clone, dst, dst_size); - free(dst); - if ((dst = malloc(dst_size + src_size)) == NULL) - return (NULL); - ft_memcpy(dst, clone, dst_size); - free(clone); - ft_memcpy(dst + dst_size, src, src_size); - return (dst); -} diff --git a/src/io/ft_snprintf.c b/src/io/ft_snprintf.c deleted file mode 100644 index e1fdfbd..0000000 --- a/src/io/ft_snprintf.c +++ /dev/null @@ -1,24 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_snprintf.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: cacharle +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2019/11/21 02:27:55 by cacharle #+# #+# */ -/* Updated: 2019/11/21 03:41:49 by cacharle ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -int ft_snprintf(char *str, size_t size, const char *format, ...) -{ - int ret; - va_list ap; - - va_start(ap, format); - ret = ft_vsnprintf(str, size, format, ap); - va_end(ap); - return (ret); -} diff --git a/src/io/ft_sprintf.c b/src/io/ft_sprintf.c deleted file mode 100644 index 31da75e..0000000 --- a/src/io/ft_sprintf.c +++ /dev/null @@ -1,24 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_sprintf.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: cacharle +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2019/11/21 02:17:21 by cacharle #+# #+# */ -/* Updated: 2019/11/21 03:42:28 by cacharle ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -int ft_sprintf(char *str, const char *format, ...) -{ - int ret; - va_list ap; - - va_start(ap, format); - ret = ft_vsprintf(str, format, ap); - va_end(ap); - return (ret); -} diff --git a/src/io/ft_vasprintf.c b/src/io/ft_vasprintf.c deleted file mode 100644 index 85f66bc..0000000 --- a/src/io/ft_vasprintf.c +++ /dev/null @@ -1,21 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_vasprintf.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: cacharle +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2019/11/21 02:49:56 by cacharle #+# #+# */ -/* Updated: 2019/11/21 03:45:39 by cacharle ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -int ft_vasprintf(char **ret, const char *format, va_list ap) -{ - (void)ret; - (void)format; - (void)ap; - return (0); -} diff --git a/src/io/ft_vdprintf.c b/src/io/ft_vdprintf.c deleted file mode 100644 index a5e5ebf..0000000 --- a/src/io/ft_vdprintf.c +++ /dev/null @@ -1,24 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_vdprintf.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: cacharle +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2019/11/21 02:40:03 by cacharle #+# #+# */ -/* Updated: 2019/11/21 03:46:00 by cacharle ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -int ft_vdprintf(int fd, const char *format, va_list ap) -{ - int out_len; - char *out; - - if ((out_len = ft_vasprintf(&out, format, ap)) == -1) - return (-1); - write(fd, out, out_len); - return (out_len); -} diff --git a/src/io/ft_vprintf.c b/src/io/ft_vprintf.c deleted file mode 100644 index b98670b..0000000 --- a/src/io/ft_vprintf.c +++ /dev/null @@ -1,18 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_vprintf.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: cacharle +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2019/11/21 02:32:44 by cacharle #+# #+# */ -/* Updated: 2019/11/21 03:44:11 by cacharle ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -int ft_vprintf(const char *format, va_list ap) -{ - return (ft_vdprintf(STDOUT_FILENO, format, ap)); -} diff --git a/src/io/ft_vsnprintf.c b/src/io/ft_vsnprintf.c deleted file mode 100644 index 7db988c..0000000 --- a/src/io/ft_vsnprintf.c +++ /dev/null @@ -1,26 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_vsnprintf.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: cacharle +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2019/11/21 02:36:32 by cacharle #+# #+# */ -/* Updated: 2019/11/21 03:45:14 by cacharle ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -int ft_vsnprintf(char *str, size_t size, const char *format, va_list ap) -{ - int ret; - int full_out_len; - char *full_out; - - full_out_len = ft_vasprintf(&full_out, format, ap); - ft_strncpy(str, full_out, size); - ret = MIN((size_t)full_out_len, size); - free(full_out); - return (ret); -} diff --git a/src/io/ft_vsprintf.c b/src/io/ft_vsprintf.c deleted file mode 100644 index 91b4815..0000000 --- a/src/io/ft_vsprintf.c +++ /dev/null @@ -1,18 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_vsprintf.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: cacharle +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2019/11/21 02:34:17 by cacharle #+# #+# */ -/* Updated: 2019/11/21 03:44:24 by cacharle ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -int ft_vsprintf(char *str, const char *format, va_list ap) -{ - return (ft_vsnprintf(str, INT_MAX + 1, format, ap)); -} diff --git a/src/io/get_next_line/get_next_line.c b/src/io/get_next_line/get_next_line.c deleted file mode 100644 index e51f152..0000000 --- a/src/io/get_next_line/get_next_line.c +++ /dev/null @@ -1,115 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* get_next_line.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: cacharle +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2019/10/19 09:08:36 by cacharle #+# #+# */ -/* Updated: 2020/01/15 07:26:50 by cacharle ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "get_next_line.h" - -#define HAS_NEWLINE(str, split_at) ((split_at = gnl_find_newline(str)) != -1) - -static int gnl_find_newline(char *str) -{ - int i; - - i = -1; - while (str[++i]) - if (str[i] == '\n') - return (i); - return (-1); -} - -static int gnl_free_return(char **ptr, char **ptr2, int ret) -{ - if (ptr != NULL) - { - free(*ptr); - *ptr = NULL; - } - if (ptr2 != NULL) - { - free(*ptr2); - *ptr2 = NULL; - } - return (ret); -} - -static int gnl_read_line(int fd, char **line, char *rest) -{ - int ret; - int split_at; - char *buf; - - if ((buf = malloc(sizeof(char) * (BUFFER_SIZE + 1))) == NULL) - return (gnl_free_return(line, NULL, GNL_STATUS_ERROR)); - while ((ret = read(fd, buf, BUFFER_SIZE)) > 0) - { - buf[ret] = '\0'; - if (HAS_NEWLINE(buf, split_at)) - { - ft_strcpy(rest, buf + split_at + 1); - buf[split_at] = '\0'; - if ((*line = ft_strjoin_free(*line, buf, 1)) == NULL) - return (gnl_free_return(&buf, NULL, GNL_STATUS_ERROR)); - return (gnl_free_return(&buf, NULL, GNL_STATUS_LINE)); - } - if ((*line = ft_strjoin_free(*line, buf, 1)) == NULL) - return (gnl_free_return(&buf, NULL, GNL_STATUS_ERROR)); - } - if (ret == -1) - return (gnl_free_return(&buf, line, GNL_STATUS_ERROR)); - return (gnl_free_return(&buf, NULL, ret)); -} - -/* -** if has rest: -** if rest has newline: -** push rest until newline in line, shift rest -** return LINE_READ -** else: -** push rest in line -** -** while can read fd in buf -** if buf has newline: -** push buf until newline in line -** push buf after newline in rest -** return LINE_READ -** push buf in line -** -** return GNL_EOF -*/ - -int get_next_line(int fd, char **line) -{ - int split_at; - static char rest[OPEN_MAX][BUFFER_SIZE + 1] = {{0}}; - - if (fd < 0 || fd > OPEN_MAX || line == NULL || BUFFER_SIZE <= 0) - return (GNL_STATUS_ERROR); - if ((*line = ft_strdup("")) == NULL) - return (GNL_STATUS_ERROR); - if (rest[fd][0] == '\0') - return (gnl_read_line(fd, line, rest[fd])); - if (HAS_NEWLINE(rest[fd], split_at)) - { - free(*line); - if ((*line = (char*)malloc(sizeof(char) * (split_at + 1))) == NULL) - return (GNL_STATUS_ERROR); - ft_strncpy(*line, rest[fd], split_at); - (*line)[split_at] = '\0'; - ft_strcpy(rest[fd], rest[fd] + split_at + 1); - return (GNL_STATUS_LINE); - } - free(*line); - if (!(*line = (char*)malloc(sizeof(char) * (ft_strlen(rest[fd]) + 1)))) - return (GNL_STATUS_ERROR); - ft_strcpy(*line, rest[fd]); - rest[fd][0] = '\0'; - return (gnl_read_line(fd, line, rest[fd])); -} diff --git a/src/lst/ft_lstreverse_ret.c b/src/lst/ft_lstreverse_ret.c index 03ae98e..3e2118f 100644 --- a/src/lst/ft_lstreverse_ret.c +++ b/src/lst/ft_lstreverse_ret.c @@ -6,7 +6,7 @@ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/01/15 12:51:15 by cacharle #+# #+# */ -/* Updated: 2020/01/15 13:36:46 by cacharle ### ########.fr */ +/* Updated: 2020/01/17 10:12:42 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,6 +15,7 @@ t_list *ft_lstreverse_ret(t_list *lst) { t_list *tmp; + if (lst == NULL) return (NULL); if (lst->next == NULL) diff --git a/src/mem/ft_memccpy.c b/src/mem/ft_memccpy.c index f95aa03..8ce656a 100644 --- a/src/mem/ft_memccpy.c +++ b/src/mem/ft_memccpy.c @@ -6,7 +6,7 @@ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/10/07 10:01:53 by cacharle #+# #+# */ -/* Updated: 2019/11/20 03:30:45 by cacharle ### ########.fr */ +/* Updated: 2020/01/17 10:54:03 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,12 +14,12 @@ void *ft_memccpy(void *dest, const void *src, int c, size_t n) { - size_t i; - t_byte *cast_dest; - t_byte *cast_src; + size_t i; + t_ftbyte *cast_dest; + t_ftbyte *cast_src; - cast_dest = (t_byte*)dest; - cast_src = (t_byte*)src; + cast_dest = (t_ftbyte*)dest; + cast_src = (t_ftbyte*)src; i = -1; while (++i < n) { diff --git a/src/mem/ft_memchr.c b/src/mem/ft_memchr.c index d2364db..27e9028 100644 --- a/src/mem/ft_memchr.c +++ b/src/mem/ft_memchr.c @@ -6,7 +6,7 @@ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/10/07 09:55:31 by cacharle #+# #+# */ -/* Updated: 2019/11/20 03:30:55 by cacharle ### ########.fr */ +/* Updated: 2020/01/17 10:53:57 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,10 +14,10 @@ void *ft_memchr(const void *s, int c, size_t n) { - size_t i; - t_byte *cast_s; + size_t i; + t_ftbyte *cast_s; - cast_s = (t_byte*)s; + cast_s = (t_ftbyte*)s; i = -1; while (++i < n) if (cast_s[i] == (unsigned char)c) diff --git a/src/mem/ft_memcmp.c b/src/mem/ft_memcmp.c index 2c8e179..233d796 100644 --- a/src/mem/ft_memcmp.c +++ b/src/mem/ft_memcmp.c @@ -6,7 +6,7 @@ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/10/07 09:56:44 by cacharle #+# #+# */ -/* Updated: 2019/11/21 01:58:42 by cacharle ### ########.fr */ +/* Updated: 2020/01/17 10:54:15 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,12 +14,12 @@ int ft_memcmp(const void *s1, const void *s2, size_t n) { - size_t i; - t_byte *cast_s1; - t_byte *cast_s2; + size_t i; + t_ftbyte *cast_s1; + t_ftbyte *cast_s2; - cast_s1 = (t_byte*)s1; - cast_s2 = (t_byte*)s2; + cast_s1 = (t_ftbyte*)s1; + cast_s2 = (t_ftbyte*)s2; if (n == 0) return (0); i = -1; diff --git a/src/mem/ft_memcpy.c b/src/mem/ft_memcpy.c index ca679fc..d0ef008 100644 --- a/src/mem/ft_memcpy.c +++ b/src/mem/ft_memcpy.c @@ -6,7 +6,7 @@ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/10/07 10:00:07 by cacharle #+# #+# */ -/* Updated: 2019/11/21 18:04:36 by cacharle ### ########.fr */ +/* Updated: 2020/01/17 10:39:04 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,7 +22,7 @@ void *ft_memcpy(void *dest, const void *src, size_t n) while (n % 8 > 0) { n--; - ((t_byte*)dest)[n] = ((t_byte*)src)[n]; + ((t_ftbyte*)dest)[n] = ((t_ftbyte*)src)[n]; } long_dest = dest; long_src = src; diff --git a/src/mem/ft_memmove.c b/src/mem/ft_memmove.c index 73e26b8..2f794fd 100644 --- a/src/mem/ft_memmove.c +++ b/src/mem/ft_memmove.c @@ -6,7 +6,7 @@ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/10/07 10:03:21 by cacharle #+# #+# */ -/* Updated: 2019/11/21 18:43:26 by cacharle ### ########.fr */ +/* Updated: 2020/01/17 10:39:26 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -24,7 +24,7 @@ void *ft_memmove(void *dst, const void *src, size_t len) while (len % 8 > 0) { len--; - *(t_byte*)dst++ = *(t_byte*)src++; + *(t_ftbyte*)dst++ = *(t_ftbyte*)src++; } long_dst = dst; long_src = src; diff --git a/src/mem/ft_memset.c b/src/mem/ft_memset.c index 4ede5f3..89f53ff 100644 --- a/src/mem/ft_memset.c +++ b/src/mem/ft_memset.c @@ -6,7 +6,7 @@ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/10/07 10:01:23 by cacharle #+# #+# */ -/* Updated: 2019/11/21 18:40:59 by cacharle ### ########.fr */ +/* Updated: 2020/01/17 10:39:10 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,7 +19,7 @@ void *ft_memset(void *s, int c, size_t n) c = (unsigned char)c; while (n % 8 > 0) - *((t_byte*)s + --n) = c; + *((t_ftbyte*)s + --n) = c; buf = (long int)c | (long int)c << 8 | (long int)c << 16 | (long int)c << 24 | (long int)c << 32 | (long int)c << 40 | (long int)c << 48 | (long int)c << 56; diff --git a/src/str/ft_atoi_strict.c b/src/str/ft_atoi_strict.c index 6156b03..0079807 100644 --- a/src/str/ft_atoi_strict.c +++ b/src/str/ft_atoi_strict.c @@ -6,13 +6,12 @@ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/01/15 10:06:29 by cacharle #+# #+# */ -/* Updated: 2020/01/15 14:09:03 by cacharle ### ########.fr */ +/* Updated: 2020/01/17 10:12:54 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" -#include int ft_strict_atoi(const char *s) { char *end; diff --git a/src/str/ft_strncpy.c b/src/str/ft_strncpy.c index a0cfb4c..07a4927 100644 --- a/src/str/ft_strncpy.c +++ b/src/str/ft_strncpy.c @@ -6,7 +6,7 @@ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/10/07 10:26:59 by cacharle #+# #+# */ -/* Updated: 2019/11/21 02:49:48 by cacharle ### ########.fr */ +/* Updated: 2020/01/17 10:40:21 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,7 +17,7 @@ char *ft_strncpy(char *dest, const char *src, size_t n) size_t len; len = ft_strlen(src); - ft_memcpy(dest, src, MIN(n, len)); + ft_memcpy(dest, src, n < len ? n : len); if (len < n) ft_bzero(dest + len, n - len); return (dest); diff --git a/src/str/ft_strtol.c b/src/str/ft_strtol.c index 0fb5261..e5ce552 100644 --- a/src/str/ft_strtol.c +++ b/src/str/ft_strtol.c @@ -6,7 +6,7 @@ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/01/15 10:26:45 by cacharle #+# #+# */ -/* Updated: 2020/01/15 14:15:40 by cacharle ### ########.fr */ +/* Updated: 2020/01/17 10:54:41 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -51,7 +51,7 @@ static long errno_return(int err) long ft_strtol(const char *str, char **endptr, int base) { - t_bool is_negative; + t_ftbool is_negative; long long nb; char base_str[37]; diff --git a/test/ctest b/test/ctest index 61963f1..ab59068 160000 --- a/test/ctest +++ b/test/ctest @@ -1 +1 @@ -Subproject commit 61963f169ff5ae4dc18c5e6e1c7c6972745d6cf2 +Subproject commit ab5906865fab359cbb0a814ef3863bbc1fe5f10a diff --git a/test/str/ft_strlen_test.c b/test/str/ft_strlen_test.c index 57ccee4..1c444ba 100644 --- a/test/str/ft_strlen_test.c +++ b/test/str/ft_strlen_test.c @@ -14,10 +14,21 @@ ASSERT_FUNC1(ft_strlen, char*, str) } ASSERT_FUNC1_END +ASSERT_PRINT_ARG_FUNC1(ft_strlen, char*, str) +{ + printf("(str: \"%.30s", str); + if (strlen(str) > 30) + fputs("...", stdout); + fputs("\")", stdout); +} +ASSERT_PRINT_ARG_FUNC1_END + TEST(ft_strlen) { - ASSERT(ft_strlen, "bonjour"); - ASSERT(ft_strlen, "yo"); - ASSERT(ft_strlen, "slt"); + ASSERT(ft_strlen, CTEST_DEF_EMPTY); + ASSERT(ft_strlen, CTEST_DEF_HELLO); + ASSERT(ft_strlen, CTEST_DEF_HIDDEN); + ASSERT(ft_strlen, CTEST_DEF_FORMAT); + ASSERT(ft_strlen, CTEST_DEF_LOREM_IPSUM); } diff --git a/test/test_libft.h b/test/test_libft.h index f4d489f..aa23e54 100644 --- a/test/test_libft.h +++ b/test/test_libft.h @@ -2,6 +2,7 @@ # define TEST_LIBFT_H # include "ctest.h" +# include "libft.h" TEST(ft_strlen); -- cgit