From 721a840908c66b50d455765db9de999f9bfe9c22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zo=C3=ABy=20Noort?= Date: Sat, 31 May 2025 20:43:20 +0200 Subject: [PATCH] feat: added configuration and USE_SLIST --- Makefile | 13 ++++++++++++- hdrs/libft.h | 15 ++++++++++++--- srcs/slist/ft_slist_clear.c | 4 +++- srcs/slist/ft_slist_empty.c | 4 +++- srcs/slist/ft_slist_find.c | 4 +++- srcs/slist/ft_slist_get.c | 2 ++ srcs/slist/ft_slist_insert.c | 2 ++ srcs/slist/ft_slist_iter.c | 2 ++ srcs/slist/ft_slist_new.c | 4 +++- srcs/slist/ft_slist_pop.c | 2 ++ srcs/slist/ft_slist_push.c | 2 ++ srcs/slist/ft_slist_reverse.c | 2 ++ srcs/slist/ft_slist_rm.c | 4 +++- srcs/slist/ft_slist_shift.c | 2 ++ srcs/slist/ft_slist_size.c | 2 ++ srcs/slist/ft_slist_unshift.c | 2 ++ 16 files changed, 57 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index 87369c9..3c0cd7c 100644 --- a/Makefile +++ b/Makefile @@ -18,7 +18,9 @@ TESTS_OBJS = $(patsubst $(TESTS_DIR)/%.c,$(OBJ_DIR)/%.test.o,$(TESTS_SRCS)) TESTS_BINS = $(patsubst $(TESTS_DIR)/%.c,$(BUILD_DIR)/%_test,$(TESTS_SRCS)) # Flags for configuration -CONFIG_FLAGS := $(shell grep -E '^[a-zA-Z0-9_]+=' .config | sed 's/=\(.*\)/=-D\U&/g' | sed 's/=/ /g' | sed 's/y/1/;s/n/0/') +CONFIG_FLAGS := $(shell grep -E '^[a-zA-Z0-9_]+=' .config | sed 's/\([A-Za-z0-9_]*\)=y/-D\1=1/;s/\([A-Za-z0-9_]*\)=n/-D\1=0/') +CFLAGS += $(CONFIG_FLAGS) + all: $(LIBRARY) @@ -62,3 +64,12 @@ fclean: clean re: fclean all .PHONY: all clean fclean re tests + +CONFIG_FILE := .config + +genconfig: + @echo -e " C\t${CONFIG_FILE}" + @echo "USE_SLIST=y" > $(CONFIG_FILE) + @echo "USE_DLIST=y" >> $(CONFIG_FILE) + @echo "USE_STACK=y" >> $(CONFIG_FILE) + diff --git a/hdrs/libft.h b/hdrs/libft.h index b459ba4..f572d16 100644 --- a/hdrs/libft.h +++ b/hdrs/libft.h @@ -1,7 +1,14 @@ #ifndef LIBFT_H -# define LIBFT_H - -# include +#define LIBFT_H +#include +#if DEBUG +#include +#define DEBUG_PRINT(fmt, ...) \ + fprintf(stderr, "[DEBUG] %s:%d:%s(): " fmt "\n", \ + __FILE__, __LINE__, __func__, ##__VA_ARGS__) +#else +#define DEBUG_PRINT(fmt, ...) ((void)0) +#endif void *ft_realloc(void *ptr, size_t old_size, size_t new_size); @@ -50,6 +57,7 @@ typedef struct s_string } t_string; /* Single Linked List */ +#if USE_SLIST typedef struct s_slist { void *data; @@ -71,6 +79,7 @@ t_slist *ft_slist_find(t_slist *lst, void *data, int (*cmp)(void *, void *)); int ft_slist_insert(t_slist **lst, t_slist *node, int index); t_slist *ft_slist_get(t_slist *lst, int index); +#endif /* Vector */ typedef struct s_vec { diff --git a/srcs/slist/ft_slist_clear.c b/srcs/slist/ft_slist_clear.c index 70a0817..71e8b17 100644 --- a/srcs/slist/ft_slist_clear.c +++ b/srcs/slist/ft_slist_clear.c @@ -1,3 +1,4 @@ +#if USE_SLIST #include "libft.h" #include @@ -10,4 +11,5 @@ void ft_slist_clear(t_slist **lst) free(*lst); *lst = tmp; } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/srcs/slist/ft_slist_empty.c b/srcs/slist/ft_slist_empty.c index 92ebf48..cdcfa20 100644 --- a/srcs/slist/ft_slist_empty.c +++ b/srcs/slist/ft_slist_empty.c @@ -1,6 +1,8 @@ +#if USE_SLIST #include "libft.h" int ft_slist_empty(t_slist *lst) { return (lst == NULL); -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/srcs/slist/ft_slist_find.c b/srcs/slist/ft_slist_find.c index a481743..423bc94 100644 --- a/srcs/slist/ft_slist_find.c +++ b/srcs/slist/ft_slist_find.c @@ -1,3 +1,4 @@ +#if USE_SLIST #include "libft.h" t_slist *ft_slist_find(t_slist *lst, void *data, int (*cmp)(void *, void *)) @@ -9,4 +10,5 @@ t_slist *ft_slist_find(t_slist *lst, void *data, int (*cmp)(void *, void *)) lst = lst->next; } return (NULL); -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/srcs/slist/ft_slist_get.c b/srcs/slist/ft_slist_get.c index e3dfa26..af4bda8 100644 --- a/srcs/slist/ft_slist_get.c +++ b/srcs/slist/ft_slist_get.c @@ -1,3 +1,4 @@ +#if USE_SLIST #include "libft.h" t_slist *ft_slist_get(t_slist *lst, int index) @@ -10,3 +11,4 @@ t_slist *ft_slist_get(t_slist *lst, int index) } return ((i == index) ? lst : NULL); } +#endif \ No newline at end of file diff --git a/srcs/slist/ft_slist_insert.c b/srcs/slist/ft_slist_insert.c index 67239a7..9286ac1 100644 --- a/srcs/slist/ft_slist_insert.c +++ b/srcs/slist/ft_slist_insert.c @@ -1,3 +1,4 @@ +#if USE_SLIST #include "libft.h" int ft_slist_insert(t_slist **lst, t_slist *node, int index) @@ -28,3 +29,4 @@ int ft_slist_insert(t_slist **lst, t_slist *node, int index) } return (-1); } +#endif \ No newline at end of file diff --git a/srcs/slist/ft_slist_iter.c b/srcs/slist/ft_slist_iter.c index 21681af..ed64e52 100644 --- a/srcs/slist/ft_slist_iter.c +++ b/srcs/slist/ft_slist_iter.c @@ -1,3 +1,4 @@ +#if USE_SLIST #include "libft.h" void ft_slist_iter(t_slist *lst, void (*f)(void *)) @@ -8,3 +9,4 @@ void ft_slist_iter(t_slist *lst, void (*f)(void *)) lst = lst->next; } } +#endif \ No newline at end of file diff --git a/srcs/slist/ft_slist_new.c b/srcs/slist/ft_slist_new.c index 83c64ec..63ff49d 100644 --- a/srcs/slist/ft_slist_new.c +++ b/srcs/slist/ft_slist_new.c @@ -1,3 +1,4 @@ +#if USE_SLIST #include "libft.h" t_slist *ft_slist_new(void *data) @@ -11,4 +12,5 @@ t_slist *ft_slist_new(void *data) node->next = NULL; return node; -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/srcs/slist/ft_slist_pop.c b/srcs/slist/ft_slist_pop.c index ae7aa6f..a7bb9f6 100644 --- a/srcs/slist/ft_slist_pop.c +++ b/srcs/slist/ft_slist_pop.c @@ -1,3 +1,4 @@ +#if USE_SLIST #include "libft.h" t_slist *ft_list_pop(t_slist **lst) @@ -21,3 +22,4 @@ t_slist *ft_list_pop(t_slist **lst) prev->next = NULL; return current; } +#endif \ No newline at end of file diff --git a/srcs/slist/ft_slist_push.c b/srcs/slist/ft_slist_push.c index d49118b..9e63ddd 100644 --- a/srcs/slist/ft_slist_push.c +++ b/srcs/slist/ft_slist_push.c @@ -1,3 +1,4 @@ +#if USE_SLIST #include "libft.h" void ft_slist_push(t_slist **lst, t_slist *node) @@ -20,3 +21,4 @@ void ft_slist_push(t_slist **lst, t_slist *node) current = current->next; current->next = node; } +#endif \ No newline at end of file diff --git a/srcs/slist/ft_slist_reverse.c b/srcs/slist/ft_slist_reverse.c index e399fb3..f5532f9 100644 --- a/srcs/slist/ft_slist_reverse.c +++ b/srcs/slist/ft_slist_reverse.c @@ -1,3 +1,4 @@ +#if USE_SLIST #include "libft.h" void ft_slist_reverse(t_slist **lst) @@ -15,3 +16,4 @@ void ft_slist_reverse(t_slist **lst) } *lst = prev; } +#endif \ No newline at end of file diff --git a/srcs/slist/ft_slist_rm.c b/srcs/slist/ft_slist_rm.c index 97f4b77..86e6d18 100644 --- a/srcs/slist/ft_slist_rm.c +++ b/srcs/slist/ft_slist_rm.c @@ -1,3 +1,4 @@ +#if USE_SLIST #include "libft.h" void ft_slist_rm(t_slist **lst, void *data, int (*cmp)(void *, void *), void (*del)(void *)) @@ -21,4 +22,5 @@ void ft_slist_rm(t_slist **lst, void *data, int (*cmp)(void *, void *), void (*d prev = curr; curr = curr->next; } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/srcs/slist/ft_slist_shift.c b/srcs/slist/ft_slist_shift.c index e5ee48f..3e40019 100644 --- a/srcs/slist/ft_slist_shift.c +++ b/srcs/slist/ft_slist_shift.c @@ -1,3 +1,4 @@ +#if USE_SLIST #include "libft.h" t_slist *ft_slist_shift(t_slist **lst) @@ -11,3 +12,4 @@ t_slist *ft_slist_shift(t_slist **lst) first->next = NULL; return first; } +#endif \ No newline at end of file diff --git a/srcs/slist/ft_slist_size.c b/srcs/slist/ft_slist_size.c index 2957200..27ba999 100644 --- a/srcs/slist/ft_slist_size.c +++ b/srcs/slist/ft_slist_size.c @@ -1,3 +1,4 @@ +#if USE_SLIST #include "libft.h" int ft_slist_size(t_slist *lst) @@ -10,3 +11,4 @@ int ft_slist_size(t_slist *lst) } return size; } +#endif \ No newline at end of file diff --git a/srcs/slist/ft_slist_unshift.c b/srcs/slist/ft_slist_unshift.c index 850637f..5e2a459 100644 --- a/srcs/slist/ft_slist_unshift.c +++ b/srcs/slist/ft_slist_unshift.c @@ -1,3 +1,4 @@ +#if USE_SLIST #include "libft.h" void ft_slist_unshift(t_slist **lst, t_slist *node) @@ -7,3 +8,4 @@ void ft_slist_unshift(t_slist **lst, t_slist *node) node->next = *lst; *lst = node; } +#endif \ No newline at end of file