From c98de126d2252fe47dc2a9094a5f9a8fa6b4b60a Mon Sep 17 00:00:00 2001 From: Charles Cabergs Date: Sun, 11 Oct 2020 15:52:52 +0200 Subject: Removing libft/minishell_test submodules, Removing subject/README/etc --- libft | 1 - libft/.gitignore | 13 ++++ libft/Makefile | 98 ++++++++++++++++++++++++++ libft/include/libft.h | 34 +++++++++ libft/include/libft_algo.h | 81 +++++++++++++++++++++ libft/include/libft_bt.h | 28 ++++++++ libft/include/libft_ctype.h | 36 ++++++++++ libft/include/libft_def.h | 56 +++++++++++++++ libft/include/libft_dlst.h | 30 ++++++++ libft/include/libft_dstr.h | 45 ++++++++++++ libft/include/libft_ht.h | 72 +++++++++++++++++++ libft/include/libft_io.h | 46 ++++++++++++ libft/include/libft_lst.h | 68 ++++++++++++++++++ libft/include/libft_mem.h | 39 +++++++++++ libft/include/libft_printf.h | 27 +++++++ libft/include/libft_str.h | 108 ++++++++++++++++++++++++++++ libft/include/libft_util.h | 20 ++++++ libft/include/libft_vec.h | 60 ++++++++++++++++ libft/src/algo/ft_bsearch.c | 32 +++++++++ libft/src/algo/ft_compar_int.c | 25 +++++++ libft/src/algo/ft_compar_str.c | 25 +++++++ libft/src/algo/ft_is_set.c | 39 +++++++++++ libft/src/algo/ft_lfind.c | 28 ++++++++ libft/src/algo/ft_lsearch.c | 23 ++++++ libft/src/algo/ft_mergesort.c | 98 ++++++++++++++++++++++++++ libft/src/algo/ft_qsort.c | 97 +++++++++++++++++++++++++ libft/src/algo/ft_reverse.c | 34 +++++++++ libft/src/bt/ft_btdestroy.c | 23 ++++++ libft/src/bt/ft_btnew.c | 25 +++++++ libft/src/ctype/ft_isalnum.c | 18 +++++ libft/src/ctype/ft_isalpha.c | 16 +++++ libft/src/ctype/ft_isascii.c | 16 +++++ libft/src/ctype/ft_isblank.c | 16 +++++ libft/src/ctype/ft_isdigit.c | 16 +++++ libft/src/ctype/ft_isprint.c | 16 +++++ libft/src/ctype/ft_isspace.c | 19 +++++ libft/src/ctype/ft_todigit.c | 20 ++++++ libft/src/ctype/ft_tolower.c | 24 +++++++ libft/src/ctype/ft_toupper.c | 20 ++++++ libft/src/dlst/ft_dlstdelone.c | 26 +++++++ libft/src/dlst/ft_dlstdestroy.c | 32 +++++++++ libft/src/dlst/ft_dlstnew.c | 25 +++++++ libft/src/dstr/ft_dstrdestroy.c | 26 +++++++ libft/src/dstr/ft_dstrerase.c | 34 +++++++++ libft/src/dstr/ft_dstrgrow.c | 41 +++++++++++ libft/src/dstr/ft_dstrinsert.c | 38 ++++++++++ libft/src/dstr/ft_dstrnew.c | 32 +++++++++ libft/src/dstr/ft_dstrsubstitute.c | 32 +++++++++ libft/src/dstr/ft_dstrunwrap.c | 28 ++++++++ libft/src/dstr/ft_dstrwrap.c | 25 +++++++ libft/src/ht/ft_htdelone.c | 30 ++++++++ libft/src/ht/ft_htdestroy.c | 32 +++++++++ libft/src/ht/ft_htentry_new.c | 37 ++++++++++ libft/src/ht/ft_htget.c | 35 +++++++++ libft/src/ht/ft_hthash.c | 35 +++++++++ libft/src/ht/ft_htiter.c | 31 ++++++++ libft/src/ht/ft_htnew.c | 37 ++++++++++ libft/src/ht/ft_htset.c | 59 ++++++++++++++++ libft/src/ht/ft_htset_safe.c | 25 +++++++ libft/src/ht/ft_inter_htdel_first_order.c | 33 +++++++++ libft/src/ht/ft_inter_htkey_cmp.c | 25 +++++++ libft/src/io/ft_getchar.c | 22 ++++++ libft/src/io/ft_getline.c | 113 ++++++++++++++++++++++++++++++ libft/src/io/ft_putchar.c | 18 +++++ libft/src/io/ft_putchar_fd.c | 20 ++++++ libft/src/io/ft_putendl.c | 18 +++++ libft/src/io/ft_putendl_fd.c | 21 ++++++ libft/src/io/ft_putnbr.c | 18 +++++ libft/src/io/ft_putnbr_fd.c | 30 ++++++++ libft/src/io/ft_putstr.c | 18 +++++ libft/src/io/ft_putstr_fd.c | 20 ++++++ libft/src/lst/ft_lstbsearch.c | 65 +++++++++++++++++ libft/src/lst/ft_lstdelone.c | 27 +++++++ libft/src/lst/ft_lstdestroy.c | 31 ++++++++ libft/src/lst/ft_lstiter.c | 29 ++++++++ libft/src/lst/ft_lstlast.c | 27 +++++++ libft/src/lst/ft_lstlfind.c | 22 ++++++ libft/src/lst/ft_lstlsearch.c | 27 +++++++ libft/src/lst/ft_lstmap.c | 56 +++++++++++++++ libft/src/lst/ft_lstnew.c | 29 ++++++++ libft/src/lst/ft_lstpop_back.c | 31 ++++++++ libft/src/lst/ft_lstpop_front.c | 29 ++++++++ libft/src/lst/ft_lstpush_back.c | 30 ++++++++ libft/src/lst/ft_lstpush_front.c | 26 +++++++ libft/src/lst/ft_lstpush_front_node.c | 23 ++++++ libft/src/lst/ft_lstremove_if.c | 38 ++++++++++ libft/src/lst/ft_lstreverse.c | 22 ++++++ libft/src/lst/ft_lstreverse_ret.c | 32 +++++++++ libft/src/lst/ft_lstsize.c | 31 ++++++++ libft/src/lst/ft_lstsort.c | 46 ++++++++++++ libft/src/lst/ft_lstsorted_merge.c | 43 ++++++++++++ libft/src/mem/ft_bzero.c | 18 +++++ libft/src/mem/ft_calloc.c | 23 ++++++ libft/src/mem/ft_memalloc.c | 18 +++++ libft/src/mem/ft_memccpy.c | 31 ++++++++ libft/src/mem/ft_memchr.c | 26 +++++++ libft/src/mem/ft_memcmp.c | 30 ++++++++ libft/src/mem/ft_memcpy.c | 33 +++++++++ libft/src/mem/ft_memdel.c | 21 ++++++ libft/src/mem/ft_memmem.c | 58 +++++++++++++++ libft/src/mem/ft_memmove.c | 35 +++++++++ libft/src/mem/ft_memset.c | 31 ++++++++ libft/src/mem/ft_memset_pattern4.c | 26 +++++++ libft/src/mem/ft_memswap.c | 29 ++++++++ libft/src/str/ft_atoi.c | 25 +++++++ libft/src/str/ft_atoi_strict.c | 38 ++++++++++ libft/src/str/ft_fnmatch.c | 37 ++++++++++ libft/src/str/ft_itoa.c | 40 +++++++++++ libft/src/str/ft_itoa_cpy.c | 44 ++++++++++++ libft/src/str/ft_split.c | 63 +++++++++++++++++ libft/src/str/ft_splitf.c | 22 ++++++ libft/src/str/ft_strcasecmp.c | 24 +++++++ libft/src/str/ft_strcat.c | 19 +++++ libft/src/str/ft_strcat3.c | 26 +++++++ libft/src/str/ft_strchr.c | 18 +++++ libft/src/str/ft_strclr.c | 20 ++++++ libft/src/str/ft_strcmp.c | 23 ++++++ libft/src/str/ft_strcount.c | 24 +++++++ libft/src/str/ft_strcpy.c | 18 +++++ libft/src/str/ft_strcspn.c | 23 ++++++ libft/src/str/ft_strdel.c | 18 +++++ libft/src/str/ft_strdup.c | 22 ++++++ libft/src/str/ft_strequ.c | 20 ++++++ libft/src/str/ft_striter.c | 21 ++++++ libft/src/str/ft_striteri.c | 27 +++++++ libft/src/str/ft_strjoin.c | 25 +++++++ libft/src/str/ft_strjoin3.c | 36 ++++++++++ libft/src/str/ft_strjoinf.c | 42 +++++++++++ libft/src/str/ft_strlcat.c | 32 +++++++++ libft/src/str/ft_strlcpy.c | 28 ++++++++ libft/src/str/ft_strlen.c | 41 +++++++++++ libft/src/str/ft_strmap.c | 34 +++++++++ libft/src/str/ft_strmapi.c | 34 +++++++++ libft/src/str/ft_strncasecmp.c | 26 +++++++ libft/src/str/ft_strncat.c | 29 ++++++++ libft/src/str/ft_strncmp.c | 26 +++++++ libft/src/str/ft_strncpy.c | 24 +++++++ libft/src/str/ft_strndup.c | 23 ++++++ libft/src/str/ft_strnequ.c | 20 ++++++ libft/src/str/ft_strnew.c | 18 +++++ libft/src/str/ft_strnlen.c | 25 +++++++ libft/src/str/ft_strnstr.c | 29 ++++++++ libft/src/str/ft_strpbrk.c | 24 +++++++ libft/src/str/ft_strrchr.c | 24 +++++++ libft/src/str/ft_strsep.c | 32 +++++++++ libft/src/str/ft_strsjoin.c | 50 +++++++++++++ libft/src/str/ft_strsjoinf.c | 29 ++++++++ libft/src/str/ft_strspn.c | 23 ++++++ libft/src/str/ft_strstr.c | 29 ++++++++ libft/src/str/ft_strsub.c | 39 +++++++++++ libft/src/str/ft_strsubf.c | 30 ++++++++ libft/src/str/ft_strtol.c | 89 +++++++++++++++++++++++ libft/src/str/ft_strtolower.c | 26 +++++++ libft/src/str/ft_strtoupper.c | 26 +++++++ libft/src/str/ft_strtrim.c | 31 ++++++++ libft/src/util/ft_split_destroy.c | 24 +++++++ libft/src/vec/ft_vecdestroy.c | 31 ++++++++ libft/src/vec/ft_vecfrom_lst.c | 29 ++++++++ libft/src/vec/ft_vecgrow.c | 43 ++++++++++++ libft/src/vec/ft_vecinsert.c | 36 ++++++++++ libft/src/vec/ft_vecinsert_safe.c | 20 ++++++ libft/src/vec/ft_veciter.c | 31 ++++++++ libft/src/vec/ft_veciter_addr.c | 25 +++++++ libft/src/vec/ft_vecnew.c | 38 ++++++++++ libft/src/vec/ft_vecpop.c | 28 ++++++++ libft/src/vec/ft_vecpush.c | 30 ++++++++ libft/src/vec/ft_vecpush_safe.c | 27 +++++++ libft/src/vec/ft_vecremove.c | 30 ++++++++ libft/src/vec/ft_vecreserve.c | 30 ++++++++ libft/src/vec/ft_vecsort.c | 24 +++++++ libft/src/vec/ft_vecswallow.c | 35 +++++++++ libft/src/vec/ft_vectake.c | 26 +++++++ libft/src/vec/ft_vecunwrap.c | 22 ++++++ 173 files changed, 5595 insertions(+), 1 deletion(-) delete mode 160000 libft create mode 100644 libft/.gitignore create mode 100644 libft/Makefile create mode 100644 libft/include/libft.h create mode 100644 libft/include/libft_algo.h create mode 100644 libft/include/libft_bt.h create mode 100644 libft/include/libft_ctype.h create mode 100644 libft/include/libft_def.h create mode 100644 libft/include/libft_dlst.h create mode 100644 libft/include/libft_dstr.h create mode 100644 libft/include/libft_ht.h create mode 100644 libft/include/libft_io.h create mode 100644 libft/include/libft_lst.h create mode 100644 libft/include/libft_mem.h create mode 100644 libft/include/libft_printf.h create mode 100644 libft/include/libft_str.h create mode 100644 libft/include/libft_util.h create mode 100644 libft/include/libft_vec.h create mode 100644 libft/src/algo/ft_bsearch.c create mode 100644 libft/src/algo/ft_compar_int.c create mode 100644 libft/src/algo/ft_compar_str.c create mode 100644 libft/src/algo/ft_is_set.c create mode 100644 libft/src/algo/ft_lfind.c create mode 100644 libft/src/algo/ft_lsearch.c create mode 100644 libft/src/algo/ft_mergesort.c create mode 100644 libft/src/algo/ft_qsort.c create mode 100644 libft/src/algo/ft_reverse.c create mode 100644 libft/src/bt/ft_btdestroy.c create mode 100644 libft/src/bt/ft_btnew.c create mode 100644 libft/src/ctype/ft_isalnum.c create mode 100644 libft/src/ctype/ft_isalpha.c create mode 100644 libft/src/ctype/ft_isascii.c create mode 100644 libft/src/ctype/ft_isblank.c create mode 100644 libft/src/ctype/ft_isdigit.c create mode 100644 libft/src/ctype/ft_isprint.c create mode 100644 libft/src/ctype/ft_isspace.c create mode 100644 libft/src/ctype/ft_todigit.c create mode 100644 libft/src/ctype/ft_tolower.c create mode 100644 libft/src/ctype/ft_toupper.c create mode 100644 libft/src/dlst/ft_dlstdelone.c create mode 100644 libft/src/dlst/ft_dlstdestroy.c create mode 100644 libft/src/dlst/ft_dlstnew.c create mode 100644 libft/src/dstr/ft_dstrdestroy.c create mode 100644 libft/src/dstr/ft_dstrerase.c create mode 100644 libft/src/dstr/ft_dstrgrow.c create mode 100644 libft/src/dstr/ft_dstrinsert.c create mode 100644 libft/src/dstr/ft_dstrnew.c create mode 100644 libft/src/dstr/ft_dstrsubstitute.c create mode 100644 libft/src/dstr/ft_dstrunwrap.c create mode 100644 libft/src/dstr/ft_dstrwrap.c create mode 100644 libft/src/ht/ft_htdelone.c create mode 100644 libft/src/ht/ft_htdestroy.c create mode 100644 libft/src/ht/ft_htentry_new.c create mode 100644 libft/src/ht/ft_htget.c create mode 100644 libft/src/ht/ft_hthash.c create mode 100644 libft/src/ht/ft_htiter.c create mode 100644 libft/src/ht/ft_htnew.c create mode 100644 libft/src/ht/ft_htset.c create mode 100644 libft/src/ht/ft_htset_safe.c create mode 100644 libft/src/ht/ft_inter_htdel_first_order.c create mode 100644 libft/src/ht/ft_inter_htkey_cmp.c create mode 100644 libft/src/io/ft_getchar.c create mode 100644 libft/src/io/ft_getline.c create mode 100644 libft/src/io/ft_putchar.c create mode 100644 libft/src/io/ft_putchar_fd.c create mode 100644 libft/src/io/ft_putendl.c create mode 100644 libft/src/io/ft_putendl_fd.c create mode 100644 libft/src/io/ft_putnbr.c create mode 100644 libft/src/io/ft_putnbr_fd.c create mode 100644 libft/src/io/ft_putstr.c create mode 100644 libft/src/io/ft_putstr_fd.c create mode 100644 libft/src/lst/ft_lstbsearch.c create mode 100644 libft/src/lst/ft_lstdelone.c create mode 100644 libft/src/lst/ft_lstdestroy.c create mode 100644 libft/src/lst/ft_lstiter.c create mode 100644 libft/src/lst/ft_lstlast.c create mode 100644 libft/src/lst/ft_lstlfind.c create mode 100644 libft/src/lst/ft_lstlsearch.c create mode 100644 libft/src/lst/ft_lstmap.c create mode 100644 libft/src/lst/ft_lstnew.c create mode 100644 libft/src/lst/ft_lstpop_back.c create mode 100644 libft/src/lst/ft_lstpop_front.c create mode 100644 libft/src/lst/ft_lstpush_back.c create mode 100644 libft/src/lst/ft_lstpush_front.c create mode 100644 libft/src/lst/ft_lstpush_front_node.c create mode 100644 libft/src/lst/ft_lstremove_if.c create mode 100644 libft/src/lst/ft_lstreverse.c create mode 100644 libft/src/lst/ft_lstreverse_ret.c create mode 100644 libft/src/lst/ft_lstsize.c create mode 100644 libft/src/lst/ft_lstsort.c create mode 100644 libft/src/lst/ft_lstsorted_merge.c create mode 100644 libft/src/mem/ft_bzero.c create mode 100644 libft/src/mem/ft_calloc.c create mode 100644 libft/src/mem/ft_memalloc.c create mode 100644 libft/src/mem/ft_memccpy.c create mode 100644 libft/src/mem/ft_memchr.c create mode 100644 libft/src/mem/ft_memcmp.c create mode 100644 libft/src/mem/ft_memcpy.c create mode 100644 libft/src/mem/ft_memdel.c create mode 100644 libft/src/mem/ft_memmem.c create mode 100644 libft/src/mem/ft_memmove.c create mode 100644 libft/src/mem/ft_memset.c create mode 100644 libft/src/mem/ft_memset_pattern4.c create mode 100644 libft/src/mem/ft_memswap.c create mode 100644 libft/src/str/ft_atoi.c create mode 100644 libft/src/str/ft_atoi_strict.c create mode 100644 libft/src/str/ft_fnmatch.c create mode 100644 libft/src/str/ft_itoa.c create mode 100644 libft/src/str/ft_itoa_cpy.c create mode 100644 libft/src/str/ft_split.c create mode 100644 libft/src/str/ft_splitf.c create mode 100644 libft/src/str/ft_strcasecmp.c create mode 100644 libft/src/str/ft_strcat.c create mode 100644 libft/src/str/ft_strcat3.c create mode 100644 libft/src/str/ft_strchr.c create mode 100644 libft/src/str/ft_strclr.c create mode 100644 libft/src/str/ft_strcmp.c create mode 100644 libft/src/str/ft_strcount.c create mode 100644 libft/src/str/ft_strcpy.c create mode 100644 libft/src/str/ft_strcspn.c create mode 100644 libft/src/str/ft_strdel.c create mode 100644 libft/src/str/ft_strdup.c create mode 100644 libft/src/str/ft_strequ.c create mode 100644 libft/src/str/ft_striter.c create mode 100644 libft/src/str/ft_striteri.c create mode 100644 libft/src/str/ft_strjoin.c create mode 100644 libft/src/str/ft_strjoin3.c create mode 100644 libft/src/str/ft_strjoinf.c create mode 100644 libft/src/str/ft_strlcat.c create mode 100644 libft/src/str/ft_strlcpy.c create mode 100644 libft/src/str/ft_strlen.c create mode 100644 libft/src/str/ft_strmap.c create mode 100644 libft/src/str/ft_strmapi.c create mode 100644 libft/src/str/ft_strncasecmp.c create mode 100644 libft/src/str/ft_strncat.c create mode 100644 libft/src/str/ft_strncmp.c create mode 100644 libft/src/str/ft_strncpy.c create mode 100644 libft/src/str/ft_strndup.c create mode 100644 libft/src/str/ft_strnequ.c create mode 100644 libft/src/str/ft_strnew.c create mode 100644 libft/src/str/ft_strnlen.c create mode 100644 libft/src/str/ft_strnstr.c create mode 100644 libft/src/str/ft_strpbrk.c create mode 100644 libft/src/str/ft_strrchr.c create mode 100644 libft/src/str/ft_strsep.c create mode 100644 libft/src/str/ft_strsjoin.c create mode 100644 libft/src/str/ft_strsjoinf.c create mode 100644 libft/src/str/ft_strspn.c create mode 100644 libft/src/str/ft_strstr.c create mode 100644 libft/src/str/ft_strsub.c create mode 100644 libft/src/str/ft_strsubf.c create mode 100644 libft/src/str/ft_strtol.c create mode 100644 libft/src/str/ft_strtolower.c create mode 100644 libft/src/str/ft_strtoupper.c create mode 100644 libft/src/str/ft_strtrim.c create mode 100644 libft/src/util/ft_split_destroy.c create mode 100644 libft/src/vec/ft_vecdestroy.c create mode 100644 libft/src/vec/ft_vecfrom_lst.c create mode 100644 libft/src/vec/ft_vecgrow.c create mode 100644 libft/src/vec/ft_vecinsert.c create mode 100644 libft/src/vec/ft_vecinsert_safe.c create mode 100644 libft/src/vec/ft_veciter.c create mode 100644 libft/src/vec/ft_veciter_addr.c create mode 100644 libft/src/vec/ft_vecnew.c create mode 100644 libft/src/vec/ft_vecpop.c create mode 100644 libft/src/vec/ft_vecpush.c create mode 100644 libft/src/vec/ft_vecpush_safe.c create mode 100644 libft/src/vec/ft_vecremove.c create mode 100644 libft/src/vec/ft_vecreserve.c create mode 100644 libft/src/vec/ft_vecsort.c create mode 100644 libft/src/vec/ft_vecswallow.c create mode 100644 libft/src/vec/ft_vectake.c create mode 100644 libft/src/vec/ft_vecunwrap.c (limited to 'libft') diff --git a/libft b/libft deleted file mode 160000 index 39951f0..0000000 --- a/libft +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 39951f08a2938683d800c677c3a244e9ff8dbe19 diff --git a/libft/.gitignore b/libft/.gitignore new file mode 100644 index 0000000..cf870d3 --- /dev/null +++ b/libft/.gitignore @@ -0,0 +1,13 @@ +*.o +*.so +*.a +*.ghc +*.dSYM +a.out +test/libft_test +obj/* +rendu.makefile +doc/* +tmp/* +*.gz +vgcore.* diff --git a/libft/Makefile b/libft/Makefile new file mode 100644 index 0000000..aa03c59 --- /dev/null +++ b/libft/Makefile @@ -0,0 +1,98 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# Makefile :+: :+: :+: # +# +:+ +:+ +:+ # +# By: cacharle +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2019/10/08 15:45:53 by cacharle #+# #+# # +# Updated: 2020/10/11 14:51:18 by cacharle ### ########.fr # +# # +# **************************************************************************** # + +LIB = ar rcs +RM = rm -f +NORM = norminette +MAKE = make +MAKE_ARGS = --no-print-directory +DOXYGEN = doxygen +DOXYGEN_FILE = Doxyfile + +SRC_DIR = src +INCLUDE_DIR = include +OBJ_DIR = obj +SCRIPT_DIR = script +TEST_DIR = test +DOC_DIR = doc + +INCLUDE_DIR = include + + +CC = gcc +OFLAG ?= -g -O1 +CCFLAGS = $(OFLAG) -I$(INCLUDE_DIR) -Wall -Wextra -Werror +ifeq ($(TRAVIS_COMPILER),gcc) +CCFLAGS += -Wno-unused-result +endif + +IGNORE_FILE = .libftignore +IGNORE_DEFAULT = ft_printf + +NAME = libft.a + +SRC = $(shell find $(SRC_DIR) -type f -name '*.c') +OBJ = $(SRC:$(SRC_DIR)/%.c=$(OBJ_DIR)/%.o) + +INCLUDE = $(shell find $(INCLUDE_DIR) -name "*.h") + +all: prebuild + @$(MAKE) -j$(JOBS) allnopre + +allnopre: $(NAME) + +.PHONY: test +test: all + @echo "Testing" + @$(MAKE) -C $(TEST_DIR) run + +norm: + @if [ `command -v $(NORM)` ]; \ + then echo "Running norminette"; \ + $(NORM) $(SRC) $(INCLUDE); \ + else echo "$(NORM) not installed"; fi + +prebuild: + @for dir in $$(find $(SRC_DIR)/* $(FIND_ARGS) -type d | \ + sed 's_$(SRC_DIR)/_$(OBJ_DIR)/_g'); \ + do \ + if [ ! -d "$$dir" ]; then \ + mkdir -p $$dir; echo "Making build dir: $$dir"; fi \ + done + +$(NAME): $(OBJ) $(INCLUDE) + @echo "Linking: $@" + @$(LIB) $@ $(OBJ) + +$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c $(INCLUDE) + @echo "Compiling: $@" + @$(CC) $(CCFLAGS) -c -o $@ $< + +clean: + @echo "Removing objects" + @$(RM) -r $(OBJ_DIR) + +fclean: clean + @echo "Removing $(NAME)" + @$(RM) $(NAME) + +re: fclean all + +.PHONY: doc +doc: + mkdir -p tmp + for f in $(SRC) $(INCLUDE); do mkdir -p tmp/`dirname $$f` && sed 's_^/\*$$_/**_' $$f > tmp/$$f; done + $(DOXYGEN) $(DOXYGEN_FILE) + +doc_clean: + $(RM) -r $(DOC_DIR) + diff --git a/libft/include/libft.h b/libft/include/libft.h new file mode 100644 index 0000000..e982608 --- /dev/null +++ b/libft/include/libft.h @@ -0,0 +1,34 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* libft.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/10/07 09:45:02 by cacharle #+# #+# */ +/* Updated: 2020/04/03 06:32:37 by charles ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef LIBFT_H +# define LIBFT_H + +# include +# include +# include +# include +# include +# include +# include + +# ifdef __linux__ +# include +# define OPEN_MAX FOPEN_MAX +# endif + +# include "libft_io.h" +# include "libft_mem.h" +# include "libft_str.h" +# include "libft_ctype.h" + +#endif diff --git a/libft/include/libft_algo.h b/libft/include/libft_algo.h new file mode 100644 index 0000000..e859de5 --- /dev/null +++ b/libft/include/libft_algo.h @@ -0,0 +1,81 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* libft_algo.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/01/19 07:22:57 by cacharle #+# #+# */ +/* Updated: 2020/04/04 23:33:51 by charles ### ########.fr */ +/* */ +/* ************************************************************************** */ + +/* +** \file libft_algo.h +** \brief Algorithms +*/ + +#ifndef LIBFT_ALGO_H +# define LIBFT_ALGO_H + +# include +# include "libft_mem.h" +# include "libft_def.h" +# include "libft_str.h" + +/* +** \brief Range struct +** \param lo Lower bound +** \param hi Upper bound +*/ + +typedef struct +{ + int lo; + int hi; +} t_ftrange; + +/* +** \brief Merge sort consts struct +** \param base Array to sort +** \param left Left subarray +** \param right Right subarray +** \note Only used internaly by ft_mergesort +*/ + +struct s_merge_sorted_arrays +{ + void *base; + void *left; + void *right; +}; + +/* +** remove this horror +*/ + +typedef struct s_ft_search_const +{ + const void *key; + t_ftcompar_func compar; +} t_ftsearch_const; + +bool ft_is_set(void *base, size_t nel, size_t width, + t_ftcompar_func compar); +int ft_compar_int(const void *a, const void *b); +int ft_compar_str(const void *s1_p, const void *s2_p); +void ft_qsort(void *base, size_t nel, size_t width, + t_ftcompar_func compar); +int ft_mergesort(void *base, size_t nel, size_t width, + int (*compar)(const void *, const void *)); +int ft_heapsort(void *base, size_t nel, size_t width, + int (*compar)(const void *, const void *)); +void ft_reverse(void *base, size_t nel, size_t width); +void *ft_bsearch(const void *base, size_t nel, size_t width, + t_ftsearch_const *consts); +void *ft_lfind(const void *base, size_t *nelp, size_t width, + t_ftsearch_const *consts); +void *ft_lsearch(const void *base, size_t *nelp, size_t width, + t_ftsearch_const *consts); + +#endif diff --git a/libft/include/libft_bt.h b/libft/include/libft_bt.h new file mode 100644 index 0000000..6e2cc91 --- /dev/null +++ b/libft/include/libft_bt.h @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* libft_bt.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/07 21:26:34 by cacharle #+# #+# */ +/* Updated: 2020/02/07 21:34:52 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef LIBFT_BT_H +# define LIBFT_BT_H + +# include + +typedef struct s_ftbtree +{ + void *data; + struct s_ftbtree *left; + struct s_ftbtree *right; +} t_ftbtree; + +t_ftbtree *ft_btnew(void *data); +void ft_btdestroy(t_ftbtree *tree, void (*del)(void *data)); + +#endif diff --git a/libft/include/libft_ctype.h b/libft/include/libft_ctype.h new file mode 100644 index 0000000..61f4534 --- /dev/null +++ b/libft/include/libft_ctype.h @@ -0,0 +1,36 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* libft_ctype.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/01/31 10:35:31 by cacharle #+# #+# */ +/* Updated: 2020/02/28 12:08:52 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef LIBFT_CTYPE_H +# define LIBFT_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); +int ft_isblank(int c); + +/* +** conversion +*/ + +int ft_toupper(int c); +int ft_tolower(int c); +int ft_todigit(int c); + +#endif diff --git a/libft/include/libft_def.h b/libft/include/libft_def.h new file mode 100644 index 0000000..7406959 --- /dev/null +++ b/libft/include/libft_def.h @@ -0,0 +1,56 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* libft_def.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/01/31 10:36:56 by cacharle #+# #+# */ +/* Updated: 2020/04/04 21:40:37 by charles ### ########.fr */ +/* */ +/* ************************************************************************** */ + +/* +** \file libft_def.h +** \brief Type and constant definition +*/ + +#ifndef LIBFT_DEF_H +# define LIBFT_DEF_H + +# include +# include + +# 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; + +/* +** \brief Standard delete function +** \param x Resource to delete +*/ + +typedef void (*t_ftdel_func)(void *x); + +/* +** \brief Standard comparison function +** \param x1 Resource 1 +** \param x2 Resource 2 +** \return negative number if x1 < x2, +** 0 if x1 == x2, +** positive number if x1 > x2 +*/ + +typedef int (*t_ftcompar_func)(const void *x1, const void *x2); + +#endif diff --git a/libft/include/libft_dlst.h b/libft/include/libft_dlst.h new file mode 100644 index 0000000..9870ea7 --- /dev/null +++ b/libft/include/libft_dlst.h @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* libft_dlst.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: charles +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/04/03 15:15:04 by charles #+# #+# */ +/* Updated: 2020/04/03 15:44:32 by charles ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef LIBFT_DLST_H +# define LIBFT_DLST_H + +# include +# include "libft_def.h" + +typedef struct s_ftdlst +{ + struct s_ftdlst *prev; + struct s_ftdlst *next; + void *data; +} t_ftdlst; + +t_ftdlst *ft_dlstnew(void *data); +void ft_dlstdestroy(t_ftdlst *dlst, t_ftdel_func del); +void ft_dlstdelone(t_ftdlst *dlst, t_ftdel_func del); + +#endif diff --git a/libft/include/libft_dstr.h b/libft/include/libft_dstr.h new file mode 100644 index 0000000..d482f73 --- /dev/null +++ b/libft/include/libft_dstr.h @@ -0,0 +1,45 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* libft_dstr.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: charles +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/04/03 10:39:51 by charles #+# #+# */ +/* Updated: 2020/06/09 17:35:47 by charles ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef LIBFT_DSTR_H +# define LIBFT_DSTR_H + +# include +# include "libft_def.h" +# include "libft_str.h" +# include "libft_mem.h" + +/* +** \brief Dynamic string struct +** \param str Underlying null-terminated character array +** \param length Number of character (not including the '\0') +** \param capacity Maximum length - 1 of the current string +*/ + +typedef struct s_ftdstr +{ + char *str; + size_t length; + size_t capacity; +} t_ftdstr; + +t_ftdstr *ft_dstrnew(char *from); +void ft_dstrdestroy(t_ftdstr *dstr); +t_ftdstr *ft_dstrgrow(t_ftdstr *dstr, size_t at_least); +t_ftdstr *ft_dstrwrap(char *str); +char *ft_dstrunwrap(t_ftdstr *dstr); +t_ftdstr *ft_dstrinsert(t_ftdstr *dstr, char *inserted, size_t i); +void ft_dstrerase(t_ftdstr *dstr, size_t start, size_t len); +t_ftdstr *ft_dstrsubstitute(t_ftdstr *dstr, char *replacement, + size_t start, size_t end); + +#endif diff --git a/libft/include/libft_ht.h b/libft/include/libft_ht.h new file mode 100644 index 0000000..91aa153 --- /dev/null +++ b/libft/include/libft_ht.h @@ -0,0 +1,72 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* libft_ht.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/01/31 10:36:09 by cacharle #+# #+# */ +/* Updated: 2020/09/09 15:47:22 by charles ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef LIBFT_HT_H +# define LIBFT_HT_H + +/* +** \file libft_ht.h +** \brief Hash table manipulation +*/ + +# include "libft.h" +# include "libft_def.h" +# include "libft_lst.h" +# include "libft_mem.h" + +/* +** \brief Hash table entry, key/value pair +** \param key String key +** \param value Pointer to data +*/ + +typedef struct s_ftht_entry +{ + char *key; + void *value; +} t_ftht_entry; + +/* +** \brief Hash table struct +** \param size Number of buckets +** \param buckets Bucket array, each bucket is a linked list +*/ + +typedef struct s_ftht +{ + size_t size; + t_ftlst **buckets; +} t_ftht; + +size_t ft_hthash(t_ftht *ht, char *key); + +t_ftht *ft_htnew(size_t size); +void ft_htdestroy(t_ftht *ht, t_ftdel_func del); +void *ft_htget(t_ftht *ht, char *key); +t_ftht_entry *ft_htset(t_ftht *ht, char *key, void *value, + t_ftdel_func del); +t_ftht_entry *ft_htset_safe(t_ftht *ht, char *key, void *value, + t_ftdel_func del); +void ft_htdelone(t_ftht *ht, char *key, t_ftdel_func del); +t_ftht_entry *ft_htentry_new(char *key, void *value); +void ft_htiter(t_ftht *ht, void (*f)(t_ftht_entry*)); + +/* +** internals +*/ + +int ft_inter_htkey_cmp(const void *ref_key, const void *content); +void ft_inter_htdel_first_order(t_ftht_entry *entry); +void ft_inter_htdel_first_order_setup(t_ftdel_func del); +void ft_inter_htdel_first_order_teardown(void); + +#endif diff --git a/libft/include/libft_io.h b/libft/include/libft_io.h new file mode 100644 index 0000000..1294abc --- /dev/null +++ b/libft/include/libft_io.h @@ -0,0 +1,46 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* libft_io.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/01/31 10:35:43 by cacharle #+# #+# */ +/* Updated: 2020/06/19 17:45:34 by charles ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef LIBFT_IO_H +# define LIBFT_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); + +char ft_getchar(void); + +# ifndef FTGL_BUFFER_SIZE +# define FTGL_BUFFER_SIZE 32 +# endif + +# define FTGL_OK 1 +# define FTGL_EOF 0 +# define FTGL_ERROR -1 + +/* +** ft_getline.c (get_next_line) +*/ + +int ft_getline(int fd, char **line); + +#endif diff --git a/libft/include/libft_lst.h b/libft/include/libft_lst.h new file mode 100644 index 0000000..0dc1e7c --- /dev/null +++ b/libft/include/libft_lst.h @@ -0,0 +1,68 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* libft_lst.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/01/31 10:36:39 by cacharle #+# #+# */ +/* Updated: 2020/08/20 14:40:01 by charles ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef LIBFT_LST_H +# define LIBFT_LST_H + +/* +** \file libft_lst.h +** \brief Linked list Manipulation +*/ + +# include +# include "libft_def.h" +# include "libft_algo.h" + +/* +** \brief List struct +** \param data Pointer to node data +** \param next Pointer to next node or NULL if last node +*/ + +typedef struct s_ftlst +{ + void *data; + struct s_ftlst *next; +} t_ftlst; + +typedef void (*t_ftdel_func)(void *); + +t_ftlst *ft_lstnew(void const *data); +int ft_lstsize(t_ftlst *lst); +void ft_lstpush_front(t_ftlst **alst, t_ftlst *new); +t_ftlst *ft_lstpush_front_node(t_ftlst **alst, void *data); +void ft_lstpush_back(t_ftlst **alst, t_ftlst *new); +void ft_lstpop_front(t_ftlst **lst, void (*del)(void *)); +void ft_lstpop_back(t_ftlst **lst, void (*del)(void *)); +t_ftlst *ft_lstlast(t_ftlst *lst); +void ft_lstdelone(t_ftlst *lst, void (*del)(void *)); +void *ft_lstdestroy(t_ftlst **lst, void (*del)(void *)); +void ft_lstiter(t_ftlst *lst, void (*f)(void *)); +t_ftlst *ft_lstmap(t_ftlst *lst, void *(*f)(void *), + t_ftdel_func del); +t_ftlst *ft_lstreverse_ret(t_ftlst *lst); +void ft_lstreverse(t_ftlst **lst); +void ft_lstremove_if(t_ftlst **lst, + t_ftcompar_func cmp, const void *ref, + t_ftdel_func del); +void ft_lstinsert(t_ftlst **lst, t_ftlst *insert, size_t i); +t_ftlst *ft_lstbsearch(t_ftlst *lst, t_ftcompar_func cmp, + const void *ref); +t_ftlst *ft_lstlsearch(t_ftlst *lst, t_ftcompar_func cmp, + const void *ref); +t_ftlst *ft_lstlfind(t_ftlst *lst, t_ftcompar_func cmp, + const void *ref); +void ft_lstsort(t_ftlst **begin_list, t_ftcompar_func cmp); +t_ftlst *ft_lstsorted_merge(t_ftlst *l1, t_ftlst *l2, + t_ftcompar_func cmp); + +#endif diff --git a/libft/include/libft_mem.h b/libft/include/libft_mem.h new file mode 100644 index 0000000..26b4ccd --- /dev/null +++ b/libft/include/libft_mem.h @@ -0,0 +1,39 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* libft_mem.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/01/31 10:35:57 by cacharle #+# #+# */ +/* Updated: 2020/02/28 12:17:48 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef LIBFT_MEM_H +# define LIBFT_MEM_H + +# include +# include "libft_def.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); +void ft_memswap(void *a, void *b, size_t size); +void *ft_memmem(const void *big, size_t big_len, + const void *little, size_t little_len); +void ft_memset_pattern4(void *b, const void *pattern4, + size_t len); + +/* +** bloat ? +*/ + +void ft_memdel(void **ap); + +#endif diff --git a/libft/include/libft_printf.h b/libft/include/libft_printf.h new file mode 100644 index 0000000..8e64208 --- /dev/null +++ b/libft/include/libft_printf.h @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* libft_printf.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/01/31 10:36:47 by cacharle #+# #+# */ +/* Updated: 2020/01/31 10:36:51 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef LIBFT_PRINTF_H +# define LIBFT_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/libft/include/libft_str.h b/libft/include/libft_str.h new file mode 100644 index 0000000..3a52a2f --- /dev/null +++ b/libft/include/libft_str.h @@ -0,0 +1,108 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* libft_str.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/01/31 10:39:22 by cacharle #+# #+# */ +/* Updated: 2020/10/08 09:40:44 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef LIBFT_STR_H +# define LIBFT_STR_H + +# include +# include +# include "libft_ctype.h" +# include "libft_util.h" + +typedef enum +{ + FT_STRJOINF_FST, + FT_STRJOINF_SND, + FT_STRJOINF_ALL +} t_ftstrjoinf_tag; + +/* +** 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_strsub(char const *s, size_t start, size_t len); +char *ft_strsubf(char const *s, size_t start, size_t len); +char *ft_strjoin(char const *s1, char const *s2); +char *ft_strjoin3(char const *s1, char const *s2, char const *s3); +char *ft_strjoinf(char const *s1, char const *s2, t_ftstrjoinf_tag tag); +char *ft_strjoinf_fst(char const *s1, char const *s2); +char *ft_strjoinf_snd(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_splitf(char *s, char c); +int ft_strcount(char *str, char c); +char *ft_itoa(int n); +char *ft_itoa_cpy(char *dst, int n); +int ft_atoi_strict(const char *s); +long ft_strtol(const char *s, char **endptr, int base); +int ft_strcasecmp(const char *s1, const char *s2); +int ft_strncasecmp(const char *s1, const char *s2, size_t n); +size_t ft_strspn(const char *s, const char *charset); +size_t ft_strcspn(const char *s, const char *charset); +char *ft_strpbrk(const char *s, const char *charset); +char *ft_strsep(char **stringp, const char *delim); +size_t ft_strnlen(const char *s, size_t maxlen); +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_strtolower(char *s); +char *ft_strtoupper(char *s); +char *ft_strcat3(char *dest, const char *src1, const char *src2); + +/* +** glob +*/ + +bool ft_fnmatch(const char *pattern, const char *string); + +/* +** NULL terminated string array +*/ + +char *ft_strsjoin(char **strs, char *delim); +char *ft_strsjoinf(char **strs, char *delim); + +/* +** bloat ? +*/ + +/* +** char *ft_strnew(size_t size); +** void ft_strdel(char **as); +** void ft_strclr(char *s); +*/ + +#endif diff --git a/libft/include/libft_util.h b/libft/include/libft_util.h new file mode 100644 index 0000000..7a9e056 --- /dev/null +++ b/libft/include/libft_util.h @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* libft_util.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/27 17:51:36 by cacharle #+# #+# */ +/* Updated: 2020/02/27 17:52:16 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef LIBFT_UTIL_H +# define LIBFT_UTIL_H + +# include + +void *ft_split_destroy(char **strs); + +#endif diff --git a/libft/include/libft_vec.h b/libft/include/libft_vec.h new file mode 100644 index 0000000..287ce6f --- /dev/null +++ b/libft/include/libft_vec.h @@ -0,0 +1,60 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* libft_vec.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: charles +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/04/01 18:57:16 by charles #+# #+# */ +/* Updated: 2020/10/11 14:04:43 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef LIBFT_VEC_H +# define LIBFT_VEC_H + +/* +** \file libft_vec.h +** \brief Vector manipulation +*/ + +# include +# include "libft_def.h" +# include "libft_mem.h" +# include "libft_algo.h" +# include "libft_lst.h" + +/* +** \brief Vector struct +** \param data Underlying array +** \param capacity Size of the underlying array +** \param size Number of element in the vector +*/ + +typedef struct s_ftvec +{ + void **data; + size_t capacity; + size_t size; +} t_ftvec; + +t_ftvec *ft_vecnew(size_t capacity); +void *ft_vecdestroy(t_ftvec *vec, void (*del)(void *elem)); +t_ftvec *ft_vecgrow(t_ftvec *vec); +t_ftvec *ft_vecreserve(t_ftvec *vec, size_t capacity); +t_ftvec *ft_vecpush(t_ftvec *vec, void *pushed); +t_ftvec *ft_vecpush_safe(t_ftvec *vec, void *pushed); +void ft_vecpop(t_ftvec *vec, void (*del)(void *elem)); +void ft_veciter(t_ftvec *vec, void (*f)(void *elem)); +void ft_veciter_addr(t_ftvec *vec, void (*f)(void **addr)); +void *ft_vectake(t_ftvec *vec, size_t i); +void ft_vecremove(t_ftvec *vec, size_t i, void (*del)(void *elem)); +t_ftvec *ft_vecinsert(t_ftvec *vec, size_t i, void *elem); +t_ftvec *ft_vecinsert_safe(t_ftvec *vec, size_t i, void *elem); +void ft_vecsort(t_ftvec *vec, t_ftcompar_func cmp); +void **ft_vecunwrap(t_ftvec *vec); +t_ftvec *ft_vecfrom_lst(t_ftlst *lst); +t_ftvec *ft_vecswallow_at( + t_ftvec *vec, size_t index, t_ftvec *swallowed); + +#endif diff --git a/libft/src/algo/ft_bsearch.c b/libft/src/algo/ft_bsearch.c new file mode 100644 index 0000000..5132fa2 --- /dev/null +++ b/libft/src/algo/ft_bsearch.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_bsearch.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/10 05:29:05 by cacharle #+# #+# */ +/* Updated: 2020/02/13 23:14:48 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft_algo.h" + +void *ft_bsearch(const void *base, size_t nel, size_t width, + t_ftsearch_const *consts) +{ + int res; + size_t mid; + + if (nel < 1) + return (NULL); + mid = nel / 2; + res = (consts->compar)(consts->key, base + mid * width); + if (res == 0) + return ((void*)base + mid * width); + if (res < 0) + return (ft_bsearch(base, mid, width, consts)); + else + return (ft_bsearch(base + (mid + 1) * width, nel - mid - 1, + width, consts)); +} diff --git a/libft/src/algo/ft_compar_int.c b/libft/src/algo/ft_compar_int.c new file mode 100644 index 0000000..ab057bf --- /dev/null +++ b/libft/src/algo/ft_compar_int.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_compar_int.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/01/19 08:24:43 by cacharle #+# #+# */ +/* Updated: 2020/04/04 22:30:09 by charles ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +/* +** \brief Comparison function for 2 ints +** \param a Pointer to first int +** \param b Pointer to first int +** \return The difference between a and b +*/ + +int ft_compar_int(const void *a, const void *b) +{ + return (*(int*)a - *(int*)b); +} diff --git a/libft/src/algo/ft_compar_str.c b/libft/src/algo/ft_compar_str.c new file mode 100644 index 0000000..6749ab0 --- /dev/null +++ b/libft/src/algo/ft_compar_str.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_compar_str.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: charles +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/04/04 15:44:24 by charles #+# #+# */ +/* Updated: 2020/04/04 22:31:15 by charles ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft_algo.h" + +/* +** \brief String comparison function +** \param s1_p Pointer to first string +** \param s2_p Pointer to second string +** \return `strcmp` of both strings +*/ + +int ft_compar_str(const void *s1_p, const void *s2_p) +{ + return (ft_strcmp(*(const char**)s1_p, *(const char**)s2_p)); +} diff --git a/libft/src/algo/ft_is_set.c b/libft/src/algo/ft_is_set.c new file mode 100644 index 0000000..fd26a88 --- /dev/null +++ b/libft/src/algo/ft_is_set.c @@ -0,0 +1,39 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_is_set.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/01/19 07:17:15 by cacharle #+# #+# */ +/* Updated: 2020/04/04 22:33:03 by charles ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft_algo.h" + +/* +** \brief Test whether array only contains unique elements +** \param base Array to test +** \param nel Number of element in the array +** \param width Size of an element +** \param compar Comparison function to test if 2 elements are equal +*/ + +bool ft_is_set(void *base, size_t nel, size_t width, + t_ftcompar_func compar) +{ + size_t i; + + if (nel < 2) + return (TRUE); + ft_qsort(base, nel, width, compar); + i = 0; + while (i < nel - 1) + { + if (compar(base + (i * width), base + ((i + 1) * width)) == 0) + return (FALSE); + i++; + } + return (TRUE); +} diff --git a/libft/src/algo/ft_lfind.c b/libft/src/algo/ft_lfind.c new file mode 100644 index 0000000..8538f50 --- /dev/null +++ b/libft/src/algo/ft_lfind.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lfind.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/10 05:49:19 by cacharle #+# #+# */ +/* Updated: 2020/02/10 05:58:19 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft_algo.h" + +void *ft_lfind(const void *base, size_t *nelp, size_t width, + t_ftsearch_const *consts) +{ + size_t i; + + i = 0; + while (i < *nelp) + { + if ((consts->compar)(consts->key, base + i * width) == 0) + return ((void*)base + i * width); + i++; + } + return (NULL); +} diff --git a/libft/src/algo/ft_lsearch.c b/libft/src/algo/ft_lsearch.c new file mode 100644 index 0000000..4c77bca --- /dev/null +++ b/libft/src/algo/ft_lsearch.c @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lsearch.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/10 05:53:57 by cacharle #+# #+# */ +/* Updated: 2020/02/10 05:59:33 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft_algo.h" + +void *ft_lsearch(const void *base, size_t *nelp, size_t width, + t_ftsearch_const *consts) +{ + void *found; + + if ((found = ft_lfind(base, nelp, width, consts)) != NULL) + return (found); + return (ft_memcpy((void*)base + (*nelp)++ * width, consts->key, width)); +} diff --git a/libft/src/algo/ft_mergesort.c b/libft/src/algo/ft_mergesort.c new file mode 100644 index 0000000..8556145 --- /dev/null +++ b/libft/src/algo/ft_mergesort.c @@ -0,0 +1,98 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_mergesort.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/10 02:26:41 by cacharle #+# #+# */ +/* Updated: 2020/04/04 22:40:55 by charles ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft_algo.h" + +/* +** \brief Helper function to return in case of error +** \param left Left subarray +** \param right Right subarray +** \return -1 to indicate error +*/ + +static int st_mergesort_error(void *left, void *right) +{ + free(left); + free(right); + return (-1); +} + +/* +** \brief Merge 2 sorted arrays +** \param arrays Struct containing the arrays (base, left, right) +** \param nel Number of element in base +** \param compar Comparison function +*/ + +static void st_merge_sorted(struct s_merge_sorted_arrays *arrays, size_t nel, + size_t width, int (*compar)(const void *, const void *)) +{ + size_t bi; + size_t li; + size_t ri; + size_t mid; + + mid = nel / 2; + bi = 0; + li = 0; + ri = 0; + while (li < mid && ri < nel - mid) + { + if (compar(arrays->left + li * width, arrays->right + ri * width) < 0) + ft_memcpy(arrays->base + bi * width, + arrays->left + li++ * width, width); + else + ft_memcpy(arrays->base + bi * width, + arrays->right + ri++ * width, width); + bi++; + } + while (li < mid) + ft_memcpy(arrays->base + bi++ * width, + arrays->left + li++ * width, width); + while (ri < nel - mid) + ft_memcpy(arrays->base + bi++ * width, + arrays->right + ri++ * width, width); +} + +/* +** \brief Sort an array using the merge sort algorithm +** \param base Array to sort +** \param nel Number of element in the array +** \param width Size of each element +** \return 0 on success, -1 on error +*/ + +int ft_mergesort(void *base, size_t nel, size_t width, + int (*compar)(const void *, const void *)) +{ + size_t mid; + struct s_merge_sorted_arrays arrays; + + if (nel < 2) + return (0); + mid = nel / 2; + if ((arrays.left = malloc(mid * width)) == NULL) + return (-1); + if ((arrays.right = malloc((nel - mid) * width)) == NULL) + return (st_mergesort_error(arrays.left, NULL)); + ft_memcpy(arrays.left, base, mid * width); + ft_memcpy(arrays.right, base + mid * width, (nel - mid) * width); + if (ft_mergesort(arrays.left, mid, width, compar) == -1) + return (st_mergesort_error(arrays.left, arrays.right))