feat: added configuration and USE_SLIST

This commit is contained in:
Zoëy Noort 2025-05-31 20:43:20 +02:00
parent 14adc54215
commit 721a840908
16 changed files with 57 additions and 9 deletions

View file

@ -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)) TESTS_BINS = $(patsubst $(TESTS_DIR)/%.c,$(BUILD_DIR)/%_test,$(TESTS_SRCS))
# Flags for configuration # 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) all: $(LIBRARY)
@ -62,3 +64,12 @@ fclean: clean
re: fclean all re: fclean all
.PHONY: all clean fclean re tests .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)

View file

@ -1,7 +1,14 @@
#ifndef LIBFT_H #ifndef LIBFT_H
#define LIBFT_H #define LIBFT_H
#include <stdlib.h> #include <stdlib.h>
#if DEBUG
#include <stdio.h>
#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); void *ft_realloc(void *ptr, size_t old_size, size_t new_size);
@ -50,6 +57,7 @@ typedef struct s_string
} t_string; } t_string;
/* Single Linked List */ /* Single Linked List */
#if USE_SLIST
typedef struct s_slist typedef struct s_slist
{ {
void *data; 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); int ft_slist_insert(t_slist **lst, t_slist *node, int index);
t_slist *ft_slist_get(t_slist *lst, int index); t_slist *ft_slist_get(t_slist *lst, int index);
#endif
/* Vector */ /* Vector */
typedef struct s_vec typedef struct s_vec
{ {

View file

@ -1,3 +1,4 @@
#if USE_SLIST
#include "libft.h" #include "libft.h"
#include <stdlib.h> #include <stdlib.h>
@ -11,3 +12,4 @@ void ft_slist_clear(t_slist **lst)
*lst = tmp; *lst = tmp;
} }
} }
#endif

View file

@ -1,6 +1,8 @@
#if USE_SLIST
#include "libft.h" #include "libft.h"
int ft_slist_empty(t_slist *lst) int ft_slist_empty(t_slist *lst)
{ {
return (lst == NULL); return (lst == NULL);
} }
#endif

View file

@ -1,3 +1,4 @@
#if USE_SLIST
#include "libft.h" #include "libft.h"
t_slist *ft_slist_find(t_slist *lst, void *data, int (*cmp)(void *, void *)) t_slist *ft_slist_find(t_slist *lst, void *data, int (*cmp)(void *, void *))
@ -10,3 +11,4 @@ t_slist *ft_slist_find(t_slist *lst, void *data, int (*cmp)(void *, void *))
} }
return (NULL); return (NULL);
} }
#endif

View file

@ -1,3 +1,4 @@
#if USE_SLIST
#include "libft.h" #include "libft.h"
t_slist *ft_slist_get(t_slist *lst, int index) 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); return ((i == index) ? lst : NULL);
} }
#endif

View file

@ -1,3 +1,4 @@
#if USE_SLIST
#include "libft.h" #include "libft.h"
int ft_slist_insert(t_slist **lst, t_slist *node, int index) 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); return (-1);
} }
#endif

View file

@ -1,3 +1,4 @@
#if USE_SLIST
#include "libft.h" #include "libft.h"
void ft_slist_iter(t_slist *lst, void (*f)(void *)) 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; lst = lst->next;
} }
} }
#endif

View file

@ -1,3 +1,4 @@
#if USE_SLIST
#include "libft.h" #include "libft.h"
t_slist *ft_slist_new(void *data) t_slist *ft_slist_new(void *data)
@ -12,3 +13,4 @@ t_slist *ft_slist_new(void *data)
return node; return node;
} }
#endif

View file

@ -1,3 +1,4 @@
#if USE_SLIST
#include "libft.h" #include "libft.h"
t_slist *ft_list_pop(t_slist **lst) t_slist *ft_list_pop(t_slist **lst)
@ -21,3 +22,4 @@ t_slist *ft_list_pop(t_slist **lst)
prev->next = NULL; prev->next = NULL;
return current; return current;
} }
#endif

View file

@ -1,3 +1,4 @@
#if USE_SLIST
#include "libft.h" #include "libft.h"
void ft_slist_push(t_slist **lst, t_slist *node) 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 = current->next;
current->next = node; current->next = node;
} }
#endif

View file

@ -1,3 +1,4 @@
#if USE_SLIST
#include "libft.h" #include "libft.h"
void ft_slist_reverse(t_slist **lst) void ft_slist_reverse(t_slist **lst)
@ -15,3 +16,4 @@ void ft_slist_reverse(t_slist **lst)
} }
*lst = prev; *lst = prev;
} }
#endif

View file

@ -1,3 +1,4 @@
#if USE_SLIST
#include "libft.h" #include "libft.h"
void ft_slist_rm(t_slist **lst, void *data, int (*cmp)(void *, void *), void (*del)(void *)) void ft_slist_rm(t_slist **lst, void *data, int (*cmp)(void *, void *), void (*del)(void *))
@ -22,3 +23,4 @@ void ft_slist_rm(t_slist **lst, void *data, int (*cmp)(void *, void *), void (*d
curr = curr->next; curr = curr->next;
} }
} }
#endif

View file

@ -1,3 +1,4 @@
#if USE_SLIST
#include "libft.h" #include "libft.h"
t_slist *ft_slist_shift(t_slist **lst) t_slist *ft_slist_shift(t_slist **lst)
@ -11,3 +12,4 @@ t_slist *ft_slist_shift(t_slist **lst)
first->next = NULL; first->next = NULL;
return first; return first;
} }
#endif

View file

@ -1,3 +1,4 @@
#if USE_SLIST
#include "libft.h" #include "libft.h"
int ft_slist_size(t_slist *lst) int ft_slist_size(t_slist *lst)
@ -10,3 +11,4 @@ int ft_slist_size(t_slist *lst)
} }
return size; return size;
} }
#endif

View file

@ -1,3 +1,4 @@
#if USE_SLIST
#include "libft.h" #include "libft.h"
void ft_slist_unshift(t_slist **lst, t_slist *node) 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; node->next = *lst;
*lst = node; *lst = node;
} }
#endif