From aa244ec3fb071a7fd08494d04cc865b281502804 Mon Sep 17 00:00:00 2001 From: Charles Date: Thu, 30 Jan 2020 18:36:30 +0100 Subject: renaming header files, .libftignore file for simpler features selection --- .gitignore | 3 +- .gitmodules | 3 -- .libftignore | 3 ++ Makefile | 49 ++++---------------- README.md | 15 +----- include/ft_ctype.h | 35 -------------- include/ft_get_next_line.h | 35 -------------- include/ft_io.h | 25 ---------- include/ft_lst.h | 39 ---------------- include/ft_mem.h | 31 ------------- include/ft_printf.h | 27 ----------- include/ft_str.h | 66 -------------------------- include/ft_types.h | 27 ----------- include/libft.h | 25 ++-------- include/libft_ctype.h | 35 ++++++++++++++ include/libft_io.h | 44 ++++++++++++++++++ include/libft_lst.h | 39 ++++++++++++++++ include/libft_mem.h | 31 +++++++++++++ include/libft_printf.h | 27 +++++++++++ include/libft_str.h | 66 ++++++++++++++++++++++++++ include/libft_types.h | 30 ++++++++++++ libft.conf | 7 --- script/find_src.sh | 21 +++++++++ script/generate_rendu.sh | 26 +++++++++++ scripts/generate_rendu.sh | 26 ----------- src/io/ft_get_next_line.c | 113 --------------------------------------------- src/io/ft_next_line.c | 101 ++++++++++++++++++++++++++++++++++++++++ 27 files changed, 441 insertions(+), 508 deletions(-) delete mode 100644 .gitmodules create mode 100644 .libftignore delete mode 100644 include/ft_ctype.h delete mode 100644 include/ft_get_next_line.h delete mode 100644 include/ft_io.h delete mode 100644 include/ft_lst.h delete mode 100644 include/ft_mem.h delete mode 100644 include/ft_printf.h delete mode 100644 include/ft_str.h delete mode 100644 include/ft_types.h create mode 100644 include/libft_ctype.h create mode 100644 include/libft_io.h create mode 100644 include/libft_lst.h create mode 100644 include/libft_mem.h create mode 100644 include/libft_printf.h create mode 100644 include/libft_str.h create mode 100644 include/libft_types.h delete mode 100644 libft.conf create mode 100755 script/find_src.sh create mode 100755 script/generate_rendu.sh delete mode 100644 scripts/generate_rendu.sh delete mode 100644 src/io/ft_get_next_line.c create mode 100644 src/io/ft_next_line.c diff --git a/.gitignore b/.gitignore index a406d47..407a87b 100644 --- a/.gitignore +++ b/.gitignore @@ -5,5 +5,4 @@ a.out test_libft main.c -build/* -test/* +obj/* diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index b2fc13a..0000000 --- a/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "test/ctest"] - path = test/ctest - url = https://github.com/HappyTramp/ctest diff --git a/.libftignore b/.libftignore new file mode 100644 index 0000000..dfb5df9 --- /dev/null +++ b/.libftignore @@ -0,0 +1,3 @@ +*ft_printf* +*ft_ht* +*ft_lst* diff --git a/Makefile b/Makefile index f7e97c6..27ac82e 100644 --- a/Makefile +++ b/Makefile @@ -17,55 +17,26 @@ MAKE_ARGS = --no-print-directory CC = gcc CCFLAGS = -I$(INCLUDE_DIR) -Wall -Wextra -Werror -NAME = libft.a SRC_DIR = src INCLUDE_DIR = include -BUILD_DIR = build -TEST_DIR = test - -# AVAILABLE_FEATURES = get_next_line ft_printf ft_lst -CONF_FILE = libft.conf +OBJ_DIR = obj +SCRIPT_DIR = script -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 +IGNORE_FILE = .libftignore +IGNORE_DEFAULT = ft_printf -ifeq ($(findstring get_next_line,$(FEATURES)),) - 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*.c" -else - CCFLAGS += -D FT_FEATURES_FT_LST -endif +NAME = libft.a -SRC = $(shell find $(SRC_DIR) $(FIND_ARGS) -name "*.c") -OBJ = $(SRC:$(SRC_DIR)/%.c=$(BUILD_DIR)/%.o) +SRC = $(shell sh $(SCRIPT_DIR)/find_src.sh $(IGNORE_FILE)) +OBJ = $(SRC:$(SRC_DIR)/%.c=$(OBJ_DIR)/%.o) HEADER = $(shell find $(INCLUDE_DIR) -name "*.h") all: make_build_dirs $(NAME) -.PHONY: test -test: - @$(MAKE) $(MAKE_ARGS) -C $(TEST_DIR) run_raw - make_build_dirs: @for dir in $$(find $(SRC_DIR)/* $(FIND_ARGS) -type d | \ - sed 's_$(SRC_DIR)/_$(BUILD_DIR)/_g'); \ + sed 's_$(SRC_DIR)/_$(OBJ_DIR)/_g'); \ do \ if [ ! -d "$$dir" ]; then \ mkdir -p $$dir; echo "Making build dir: $$dir"; fi \ @@ -75,13 +46,13 @@ $(NAME): $(OBJ) $(HEADER) @echo "Linking: $@" @$(LIB) $@ $(OBJ) -$(BUILD_DIR)/%.o: $(SRC_DIR)/%.c +$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c @echo "Compiling: $@" @$(CC) $(CCFLAGS) -c -o $@ $< clean: @echo "Removing objects" - @$(RM) -r $(BUILD_DIR) + @$(RM) -r $(OBJ_DIR) fclean: clean @echo "Removing library" diff --git a/README.md b/README.md index 632fa8b..875f6e0 100644 --- a/README.md +++ b/README.md @@ -12,20 +12,9 @@ make all This will produce a `libft.a` library which you can link to your project. -## Testing +## .libftignore -To install the test, you will have to clone this repo with the `--recurse-submodules` flag or run the following commands: - -``` -git submodule init -git submodule update -``` - -Then: `make test` - -## Dependencies - -* [CTest](https://github.com/HappyTramp/ctest) - my testing library +Much like the `.gitignore` file, you can put the files/directory to ignore when compiling. ### School turn in diff --git a/include/ft_ctype.h b/include/ft_ctype.h deleted file mode 100644 index 44e88b8..0000000 --- a/include/ft_ctype.h +++ /dev/null @@ -1,35 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* 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 deleted file mode 100644 index 03bf344..0000000 --- a/include/ft_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/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 deleted file mode 100644 index 8c633fb..0000000 --- a/include/ft_io.h +++ /dev/null @@ -1,25 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* 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 deleted file mode 100644 index 23fb192..0000000 --- a/include/ft_lst.h +++ /dev/null @@ -1,39 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_lst.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: cacharle +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2020/01/17 09:58:02 by cacharle #+# #+# */ -/* Updated: 2020/01/30 09:55:43 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); -void ft_lstremove_if(t_list **lst, - t_ftbool (*equal)(void *ref, void *content), void *ref, - void (*del)(void *content)); - -#endif diff --git a/include/ft_mem.h b/include/ft_mem.h deleted file mode 100644 index d1e47f6..0000000 --- a/include/ft_mem.h +++ /dev/null @@ -1,31 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* 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 deleted file mode 100644 index 615039b..0000000 --- a/include/ft_printf.h +++ /dev/null @@ -1,27 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* 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 deleted file mode 100644 index 105da79..0000000 --- a/include/ft_str.h +++ /dev/null @@ -1,66 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* 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 deleted file mode 100644 index b465382..0000000 --- a/include/ft_types.h +++ /dev/null @@ -1,27 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_types.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: cacharle +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2020/01/17 09:59:15 by cacharle #+# #+# */ -/* Updated: 2020/01/30 09:54:28 by cacharle ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef FT_TYPES_H -# define FT_TYPES_H - -typedef unsigned char t_ftbyte; -typedef int t_ftbool; -typedef unsigned int t_ftsize; - -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/libft.h b/include/libft.h index 0b4d608..898c7d9 100644 --- a/include/libft.h +++ b/include/libft.h @@ -20,30 +20,15 @@ # 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 - -# ifdef FT_FEATURES_FT_PRINTF -# include "ft_printf.h" -# endif +# include "libft_types.h" +# include "libft_ctype.h" +# include "libft_io.h" +# include "libft_mem.h" +# include "libft_str.h" # ifdef __linux__ # include # define OPEN_MAX FOPEN_MAX # endif -# define TRUE 1 -# define FALSE 0 - #endif diff --git a/include/libft_ctype.h b/include/libft_ctype.h new file mode 100644 index 0000000..44e88b8 --- /dev/null +++ b/include/libft_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/libft_io.h b/include/libft_io.h new file mode 100644 index 0000000..f4c223b --- /dev/null +++ b/include/libft_io.h @@ -0,0 +1,44 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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 + +# include +# include +# include +# include "libft.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); + +# ifndef FTNL_BUFFER_SIZE +# define FTNL_BUFFER_SIZE 32 +# endif + +# define FTNL_STATUS_LINE 1 +# define FTNL_STATUS_EOF 0 +# define FTNL_STATUS_ERROR -1 + +/* +** get_next_line.c +*/ + +int ft_next_line(int fd, char **line); + +#endif diff --git a/include/libft_lst.h b/include/libft_lst.h new file mode 100644 index 0000000..23fb192 --- /dev/null +++ b/include/libft_lst.h @@ -0,0 +1,39 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lst.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/01/17 09:58:02 by cacharle #+# #+# */ +/* Updated: 2020/01/30 09:55:43 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); +void ft_lstremove_if(t_list **lst, + t_ftbool (*equal)(void *ref, void *content), void *ref, + void (*del)(void *content)); + +#endif diff --git a/include/libft_mem.h b/include/libft_mem.h new file mode 100644 index 0000000..d1e47f6 --- /dev/null +++ b/include/libft_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/libft_printf.h b/include/libft_printf.h new file mode 100644 index 0000000..615039b --- /dev/null +++ b/include/libft_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/libft_str.h b/include/libft_str.h new file mode 100644 index 0000000..105da79 --- /dev/null +++ b/include/libft_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/libft_types.h b/include/libft_types.h new file mode 100644 index 0000000..04c9f02 --- /dev/null +++ b/include/libft_types.h @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_types.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/01/17 09:59:15 by cacharle #+# #+# */ +/* Updated: 2020/01/30 09:54:28 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_TYPES_H +# define FT_TYPES_H + +# define TRUE 1 +# define FALSE 0 + +typedef unsigned char t_ftbyte; +typedef int t_ftbool; +typedef unsigned int t_ftsize; + +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/libft.conf b/libft.conf deleted file mode 100644 index 47f2a55..0000000 --- a/libft.conf +++ /dev/null @@ -1,7 +0,0 @@ -# Making - -FEATURES=get_next_line ft_lst - -# Repository - -RENDU_IGNORE=subject.pdf README.md scripts build test libft.conf diff --git a/script/find_src.sh b/script/find_src.sh new file mode 100755 index 0000000..1d645a1 --- /dev/null +++ b/script/find_src.sh @@ -0,0 +1,21 @@ +#!bin/sh + +if [ $# -ne 1 ]; then + echo "Usage $0 ignore_file" + exit 1 +fi + +IGNORE_FILE=$1 + +if [ ! -e $IGNORE_FILE ]; then + echo "Ignore file doesnt exist" + exit 1 +fi + +SRC_DIR=src + +IGNORE_FIND_ARGS=`sed 's/.*/-not -path "&"/' $IGNORE_FILE | paste -sd " "` +IGNORE_FIND_ARGS="$IGNORE_FIND_ARGS -not -name \"*inter*\"" + +sh -c "find $SRC_DIR $IGNORE_FIND_ARGS -name \"*.c\"" +# find $SRC_DIR $IGNORE_FIND_ARGS -name "*.c" diff --git a/script/generate_rendu.sh b/script/generate_rendu.sh new file mode 100755 index 0000000..1b68a97 --- /dev/null +++ b/script/generate_rendu.sh @@ -0,0 +1,26 @@ +#!/bin/sh + +if [ "$(git status --porcelain)" ] +then + echo "Error: Your working directory isn't clean" + exit +fi + +BASE_BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD) +RENDU_BRANCH_NAME="rendu-$BASE_BRANCH_NAME" + +if [ -z $(git show-ref --verify --quiet refs/heads/$RENDU_BRANCH_NAME) ] +then + echo "Error: $RENDU_BRANCH_NAME was already generated" + exit +fi + +git checkout -b $RENDU_BRANCH_NAME +RENDU_IGNORE=$(sed -n 's/RENDU_IGNORE=//p') +make fclean +rm -f $RENDU_IGNORE + +# generate makefile strict src + +git add . +git commit --message "Generated commit: creation of rendu for $BASE_BRANCH_NAME" diff --git a/scripts/generate_rendu.sh b/scripts/generate_rendu.sh deleted file mode 100644 index 1b68a97..0000000 --- a/scripts/generate_rendu.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/sh - -if [ "$(git status --porcelain)" ] -then - echo "Error: Your working directory isn't clean" - exit -fi - -BASE_BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD) -RENDU_BRANCH_NAME="rendu-$BASE_BRANCH_NAME" - -if [ -z $(git show-ref --verify --quiet refs/heads/$RENDU_BRANCH_NAME) ] -then - echo "Error: $RENDU_BRANCH_NAME was already generated" - exit -fi - -git checkout -b $RENDU_BRANCH_NAME -RENDU_IGNORE=$(sed -n 's/RENDU_IGNORE=//p') -make fclean -rm -f $RENDU_IGNORE - -# generate makefile strict src - -git add . -git commit --message "Generated commit: creation of rendu for $BASE_BRANCH_NAME" diff --git a/src/io/ft_get_next_line.c b/src/io/ft_get_next_line.c deleted file mode 100644 index 4aecf3c..0000000 --- a/src/io/ft_get_next_line.c +++ /dev/null @@ -1,113 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* 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_next_line.c b/src/io/ft_next_line.c new file mode 100644 index 0000000..59e245b --- /dev/null +++ b/src/io/ft_next_line.c @@ -0,0 +1,101 @@ +#include "libft.h" + +static int st_find_newline(char *str) +{ + int i; + + i = -1; + while (str[++i]) + if (str[i] == '\n') + return (i); + return (-1); +} + +static int st_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 st_read_line(int fd, char **line, char *rest) +{ + int ret; + int split_at; + char *buf; + + if ((buf = malloc(sizeof(char) * (FTNL_BUFFER_SIZE + 1))) == NULL) + return (st_free_return(line, NULL, FTNL_STATUS_ERROR)); + while ((ret = read(fd, buf, FTNL_BUFFER_SIZE)) > 0) + { + buf[ret] = '\0'; + if ((split_at = st_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 (st_free_return(&buf, NULL, FTNL_STATUS_ERROR)); + return (st_free_return(&buf, NULL, FTNL_STATUS_LINE)); + } + if ((*line = ft_strjoin_free(*line, buf, 1)) == NULL) + return (st_free_return(&buf, NULL, FTNL_STATUS_ERROR)); + } + if (ret == -1) + return (st_free_return(&buf, line, FTNL_STATUS_ERROR)); + return (st_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 FTNL_EOF +*/ + +int ft_next_line(int fd, char **line) +{ + int split_at; + static char rest[OPEN_MAX][FTNL_BUFFER_SIZE + 1] = {{0}}; + + if (fd < 0 || fd > OPEN_MAX || line == NULL || FTNL_BUFFER_SIZE <= 0) + return (FTNL_STATUS_ERROR); + if ((*line = ft_strdup("")) == NULL) + return (FTNL_STATUS_ERROR); + if (rest[fd][0] == '\0') + return (st_read_line(fd, line, rest[fd])); + if ((split_at = st_find_newline(rest[fd])) != -1) + { + free(*line); + if ((*line = (char*)malloc(sizeof(char) * (split_at + 1))) == NULL) + return (FTNL_STATUS_ERROR); + ft_strncpy(*line, rest[fd], split_at); + (*line)[split_at] = '\0'; + ft_strcpy(rest[fd], rest[fd] + split_at + 1); + return (FTNL_STATUS_LINE); + } + free(*line); + if (!(*line = (char*)malloc(sizeof(char) * (ft_strlen(rest[fd]) + 1)))) + return (FTNL_STATUS_ERROR); + ft_strcpy(*line, rest[fd]); + rest[fd][0] = '\0'; + return (st_read_line(fd, line, rest[fd])); +} -- cgit