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))
# 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)

View file

@ -1,7 +1,14 @@
#ifndef LIBFT_H
#define LIBFT_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);
@ -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
{

View file

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

View file

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

View file

@ -1,3 +1,4 @@
#if USE_SLIST
#include "libft.h"
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);
}
#endif

View file

@ -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

View file

@ -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

View file

@ -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

View file

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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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 *))
@ -22,3 +23,4 @@ void ft_slist_rm(t_slist **lst, void *data, int (*cmp)(void *, void *), void (*d
curr = curr->next;
}
}
#endif

View file

@ -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

View file

@ -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

View file

@ -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