skeletton untested project

This commit is contained in:
thrieg 2025-12-11 06:18:16 +01:00
commit 6fc620e8f4
187 changed files with 6584 additions and 0 deletions

79
libft/Makefile Executable file
View file

@ -0,0 +1,79 @@
CC = cc
CFLAGS = -Wall -Wextra -Werror -O3 -g3 -fPIC
SRCS = ./ft_isalnum.c ./ft_isalpha.c ./ft_isascii.c ./ft_isdigit.c \
./ft_isprint.c ./ft_memset.c ./ft_strlen.c ./ft_bzero.c ./ft_memcpy.c \
./ft_memmove.c ./ft_strlcpy.c ./ft_strlcat.c ./ft_toupper.c \
./ft_tolower.c ./ft_strchr.c ./ft_strrchr.c ./ft_strncmp.c \
./ft_memchr.c ./ft_memcmp.c ./ft_strnstr.c ./ft_atoi.c \
./ft_strdup.c ./ft_calloc.c ./ft_substr.c ./ft_strjoin.c \
./ft_strtrim.c ./ft_split.c ./ft_itoa.c ./ft_strmapi.c \
./ft_striteri.c ./ft_putchar_fd.c ./ft_putstr_fd.c \
./ft_putendl_fd.c ./ft_putnbr_fd.c ./ft_int_utils.c \
./ft_safe_int_math.c ./ft_split2.c ./ft_long_utils.c \
./ft_safe_long_math.c
SRCSBONUS = ./ft_lstnew_bonus.c ./ft_lstadd_front_bonus.c ./ft_lstsize_bonus.c ./ft_lstlast_bonus.c ./ft_lstadd_back_bonus.c ./ft_lstdelone_bonus.c ./ft_lstclear_bonus.c ./ft_lstiter_bonus.c ./ft_lstmap_bonus.c ./ft_vector.c ./ft_itoa_base.c ./ft_addr_to_str.c ./ft_utoa.c ./ft_strnonchr.c ./ft_utoa_base.c ./ft_strcmp.c ./ft_vecint.c ./ft_power.c
SRCS_GNL = ./get_next_line/get_next_line.c ./get_next_line/get_next_line_utils.c ./get_next_line/get_next_line_utils_two.c
FT_PRINTF_PATH = ./ft_printf/
SRC_PRINTF = ft_printf.c ft_cases_mandatory_one.c ft_cases_mandatory_two.c ft_printf_bonus.c ft_cases_easy_bonus.c ft_case_lowx_bonus.c ft_case_uppx_bonus.c ft_case_u_bonus.c ft_case_s_bonus.c ft_case_p_bonus.c ft_case_d_bonus.c ft_case_d_utils_bonus.c ft_arglist_bonus.c ft_padding_bonus.c
SRCS_PRINTF = $(addprefix $(FT_PRINTF_PATH), $(SRC_PRINTF))
FT_HASHMAP_PATH = ./ft_hashmap/
SRC_HASHMAP = ft_hashmap.c ft_hashmap_utils.c ft_hashmap_utils_two.c ft_hashmap_basic_type_hash.c ft_hashmap_advanced_type_hash.c ft_hashmap_basic_cmp.c
SRCS_HASHMAP = $(addprefix $(FT_HASHMAP_PATH), $(SRC_HASHMAP))
FT_PQ_PATH = ./ft_priority_queue/
SRC_PQ = ft_priority_queue.c ft_priority_queue_utils.c
SRCS_PQ = $(addprefix $(FT_PQ_PATH), $(SRC_PQ))
FT_SORTING_PATH = ./sorting/
SRC_SORTING = ft_radixsort.c ft_sorting.c
SRCS_SORTING = $(addprefix $(FT_SORTING_PATH), $(SRC_SORTING))
OBJS = $(SRCS:.c=.o)
OBJSBONUS = $(SRCSBONUS:.c=.o)
OBJS_GNL = $(SRCS_GNL:.c=.o)
OBJS_PRINTF = $(SRCS_PRINTF:.c=.o)
OBJS_HASHMAP = $(SRCS_HASHMAP:.c=.o)
OBJS_PQ = $(SRCS_PQ:.c=.o)
OBJS_SORTING = $(SRCS_SORTING:.c=.o)
NAME = libft.a
RED := \033[0;31m
GREEN := \033[0;32m
YELLOW := \033[0;33m
BLUE := \033[0;34m
NC := \033[0m
all: $(NAME)
$(NAME): $(OBJS) $(OBJSBONUS) $(OBJS_GNL) $(OBJS_PRINTF) $(OBJS_HASHMAP) $(OBJS_PQ) $(OBJS_SORTING)
@ar rcs $(NAME) $(OBJS) $(OBJSBONUS) $(OBJS_GNL) $(OBJS_PRINTF) $(OBJS_HASHMAP) $(OBJS_PQ) $(OBJS_SORTING)
@echo "$(GREEN)finished compiling $(NAME)!$(NC)"
bonus: $(NAME)
./%.o: ./%.c
@$(CC) $(CFLAGS) -c $< -o $@
clean:
@rm -f $(OBJS) $(OBJSBONUS) $(OBJS_GNL) $(OBJS_PRINTF) $(OBJS_HASHMAP) $(OBJS_PQ) $(OBJS_SORTING)
@echo "$(YELLOW)deleted object files from $(NAME)$(NC)"
fclean: clean
@rm -f $(NAME)
@echo "$(YELLOW)deleted $(NAME)$(NC)"
re: fclean all

55
libft/ft_addr_to_str.c Executable file
View file

@ -0,0 +1,55 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_addr_to_str.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: thrieg <thrieg@student.42mulhouse.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/22 16:54:09 by thrieg #+# #+# */
/* Updated: 2025/02/16 19:02:50 by thrieg ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include <stdint.h>
void ft_convert_to_hexa(char c, char hex_buff[2])
{
hex_buff[1] = c & 0b00001111;
hex_buff[0] = (c >> 4) & 0b00001111;
if (hex_buff[0] <= 9)
hex_buff[0] += '0';
else
hex_buff[0] += 'a' - 10;
if (hex_buff[1] <= 9)
hex_buff[1] += '0';
else
hex_buff[1] += 'a' - 10;
}
//convert the address addr in hexadecimal and returns a standard c string.
//returns NULL if the allocation fails
char *ft_addr_to_strhex(void *addr)
{
char hex_buff[2];
int i;
int j;
uintptr_t address;
char *ret;
ret = malloc((sizeof(char) * sizeof(uintptr_t) * 2) + 1);
if (!ret)
return (NULL);
address = (uintptr_t)addr;
i = (sizeof(uintptr_t) * 8) - 8;
j = 0;
while (i >= 0)
{
ft_convert_to_hexa(((address >> i) & 0xFF), hex_buff);
ret[j++] = hex_buff[0];
ret[j++] = hex_buff[1];
i -= 8;
}
ret[j] = '\0';
return (ret);
}

BIN
libft/ft_addr_to_str.o Normal file

Binary file not shown.

71
libft/ft_atoi.c Executable file
View file

@ -0,0 +1,71 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: thrieg <thrieg@student.42mulhouse.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/14 18:37:49 by thrieg #+# #+# */
/* Updated: 2025/02/16 19:02:53 by thrieg ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include <errno.h>
static int ft_is_space(char c)
{
if (c == '\t' || c == '\n' || c == '\v'
|| c == '\f' || c == '\r' || c == ' ')
return (1);
else
return (0);
}
static int ft_convert_to_int(const char *str, int sign, int *overflow_flag)
{
int value;
value = 0;
while (ft_isdigit(*str))
{
if (sign == 1)
{
if (value > (INT_MAX - (*str - '0')) / 10)
if (overflow_flag)
*overflow_flag = 1;
value = value * 10 + (*str - '0');
}
else
{
if (value < (INT_MIN + (*str - '0')) / 10)
if (overflow_flag)
*overflow_flag = 1;
value = value * 10 - (*str - '0');
}
str++;
}
return (value);
}
int ft_atoi(const char *nptr, int *overflow_flag)
{
int sign;
if (overflow_flag)
*overflow_flag = 0;
while ((*nptr != '\0') && ft_is_space(*nptr))
{
nptr++;
}
sign = 1;
if ((*nptr != '\0') && (*nptr == '-' || *nptr == '+'))
{
if (*nptr == '-')
sign = -sign;
nptr++;
}
if (!ft_isdigit(*nptr))
return (0);
return (ft_convert_to_int(nptr, sign, overflow_flag));
}

BIN
libft/ft_atoi.o Normal file

Binary file not shown.

18
libft/ft_bzero.c Executable file
View file

@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_bzero.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: thrieg <thrieg@student.42mulhouse.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/14 15:50:09 by thrieg #+# #+# */
/* Updated: 2025/02/16 19:03:30 by thrieg ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_bzero(void *s, size_t n)
{
ft_memset(s, '\0', n);
}

BIN
libft/ft_bzero.o Normal file

Binary file not shown.

30
libft/ft_calloc.c Executable file
View file

@ -0,0 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_calloc.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: thrieg <thrieg@student.42mulhouse.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/14 19:42:05 by thrieg #+# #+# */
/* Updated: 2025/02/16 19:03:37 by thrieg ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_calloc(size_t nmemb, size_t size)
{
void *ret;
if ((size == 0) || (nmemb == 0))
{
return (malloc(0));
}
if (nmemb > __SIZE_MAX__ / size)
return (NULL);
ret = malloc(nmemb * size);
if (!ret)
return (NULL);
ft_bzero(ret, (nmemb * size));
return (ret);
}

BIN
libft/ft_calloc.o Normal file

Binary file not shown.

93
libft/ft_hashmap.h Executable file
View file

@ -0,0 +1,93 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_hashmap.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: thrieg <thrieg@student.42mulhouse.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/07 12:14:47 by thrieg #+# #+# */
/* Updated: 2025/02/16 19:06:02 by thrieg ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef FT_HASHMAP_H
# define FT_HASHMAP_H
# include "libft.h"
# include "ft_vector.h"
# define HASHMAP_FILL_PERCENT_MAX 200
# define HASHMAP_RESIZE_FACTOR 2
# define HASHMAP_MINIMUM_SIZE 16
# define HASHMAP_FILL_PERCENT_BEFORE_SHRINK 50
# define HASHMAP_SHRINK_FACTOR 2
typedef struct s_hashmap
{
t_list **table;
size_t hashmap_size;
size_t nb_elems;
void (*free_key)(void *key);
void (*free_value)(void *value);
int (*cmp)(void *key, void *key_to_compare);
} t_hashmap;
size_t ft_hash_int(int value);
size_t ft_hash_uint(unsigned int value);
size_t ft_hash_char(char value);
size_t ft_hash_string(const char *str);
size_t ft_hash_size_t(size_t value);
size_t ft_hash_address(const void *key);
size_t ft_hash_list(const t_list *list);
size_t ft_hash_hashmap(const t_hashmap *hashmap);
size_t ft_hash_vector(const t_vector *vec);
// Comparison function for integers
int int_cmp(void *key1, void *key2);
// Comparison function for strings
int cmp_str(void *key1, void *key2);
// Comparison function for unsigned chars
int cmp_uchar(void *key1, void *key2);
// Comparison function for unsigned integers
int uint_cmp(void *key1, void *key2);
// Comparison function for size_t
int sizet_cmp(void *key1, void *key2);
//returns 0 without doing anything if the allocation of the new table fails
//in that case the old table is still valid!
//returns 1 if the resize is a success
int ft_resize_hashmap(t_hashmap *map);
//returns 0 without doing anything if the allocation of the new table fails
//or if the table is too little in that case the old table is still valid!
//returns 1 if the shrink is a success
int ft_shrink_hashmap(t_hashmap *map);
//applies functions free_key and free_value on the element if they are not NULL
//returns 1 if the element has been deleted
//returns 0 if the element has not been found
int ft_delete_hashmap_element(t_hashmap *map, void *key, size_t hash);
//returns a pointer to the value of key, or a NULL pointer if not found
void *ft_lookup_hashmap_element(t_hashmap *map, void *key, size_t hash);
//frees the entire hashmap and then returns NULL once done
void *ft_free_hashmap(t_hashmap *map);
// Inserts a key-value pair into the hashmap,
//returns 0 for an error, 1 for remplaced value for a key and 2 for new key
int ft_hashmap_insert_element(
t_hashmap *map,
void *key,
void *value,
size_t hash);
//allocates an array of initial_size, and sets nb_elems/hashmap_size to 0
//cmp is a function that returns 0 if both keys are the same
//returns NULL if any allocation fails
t_hashmap *ft_create_hashmap(
size_t initial_size,
void (*free_key)(void *),
void (*free_value)(void *),
int (*cmp)(void *key, void *key_to_compare));
#endif

156
libft/ft_hashmap/ft_hashmap.c Executable file
View file

@ -0,0 +1,156 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_hashmap.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: thrieg <thrieg@student.42mulhouse.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/07 12:14:50 by thrieg #+# #+# */
/* Updated: 2025/02/16 19:08:34 by thrieg ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_hashmap_private.h"
//allocates an array of initial_size, and sets nb_elems/hashmap_size to 0
//cmp is a function that returns 0 if both keys are the same
//returns NULL if any allocation fails
t_hashmap *ft_create_hashmap(
size_t initial_size,
void (*free_key)(void *),
void (*free_value)(void *),
int (*cmp)(void *key, void *key_to_compare))
{
t_hashmap *map;
if (initial_size == 0)
return (NULL);
map = malloc(sizeof(t_hashmap));
if (!map)
return (NULL);
map->nb_elems = 0;
map->hashmap_size = initial_size;
map->cmp = cmp;
map->free_key = free_key;
map->free_value = free_value;
map->table = ft_calloc((initial_size), sizeof(t_list *));
if (!(map->table))
return (free(map), NULL);
return (map);
}
// Inserts a key-value pair into the hashmap,
//returns 0 for an error, 1 for remplaced value for a key and 2 for new key
int ft_hashmap_insert_element(
t_hashmap *map,
void *key,
void *value,
size_t hash)
{
size_t index;
t_list *current;
t_hash_element *element;
if (!map || !key)
return (0);
if ((map->nb_elems * 100) > map->hashmap_size * HASHMAP_FILL_PERCENT_MAX)
ft_resize_hashmap(map);
index = hash % map->hashmap_size;
current = map->table[index];
while (current)
{
if (map->cmp(((t_hash_element *)(current->content))->key, key) == 0)
{
map->free_value(((t_hash_element *)(current->content))->value);
return (((t_hash_element *)(current->content))->value = value, 1);
}
current = current->next;
}
element = ft_create_hash_element(key, value, hash);
if (!element)
return (0);
if (!ft_add_hashmap_element(index, map, element))
return (ft_free_hash_element(element, map), 0);
return (2);
}
//returns 1 if the element has been deleted
//returns 0 if the element has not been found
int ft_delete_hashmap_element(t_hashmap *map, void *key, size_t hash)
{
size_t index;
t_list *curr;
t_list *prev;
t_hash_element *elem;
if (!map || !key || map->hashmap_size == 0)
return (0);
if (((map->nb_elems * 100) / map->hashmap_size)
<= HASHMAP_FILL_PERCENT_BEFORE_SHRINK)
ft_shrink_hashmap(map);
index = hash % map->hashmap_size;
curr = map->table[index];
prev = NULL;
while (curr)
{
elem = (t_hash_element *)curr->content;
if (map->cmp(elem->key, key) == 0)
{
return (ft_delete_hashmap_list_node(curr, prev, index, map), 1);
}
prev = curr;
curr = curr->next;
}
return (0);
}
//returns a pointer to the value of key, or a NULL pointer if not found
void *ft_lookup_hashmap_element(t_hashmap *map, void *key, size_t hash)
{
size_t index;
t_list *curr;
t_hash_element *elem;
if (!map || !key || map->hashmap_size == 0)
return (NULL);
index = hash % map->hashmap_size;
curr = map->table[index];
while (curr)
{
elem = (t_hash_element *)curr->content;
if (map->cmp(elem->key, key) == 0)
return (elem->value);
curr = curr->next;
}
return (NULL);
}
//frees the entire hashmap and then returns NULL once done
void *ft_free_hashmap(t_hashmap *map)
{
size_t index;
t_list *curr;
t_list *next;
t_hash_element *elem;
if (!map)
return (NULL);
if (!map->table)
return (free(map), NULL);
index = 0;
while (index < map->hashmap_size)
{
curr = map->table[index];
while (curr)
{
next = curr->next;
elem = (t_hash_element *)curr->content;
ft_free_hash_element(elem, map);
free(curr);
curr = next;
}
index++;
}
free(map->table);
return (free(map), NULL);
}

Binary file not shown.

View file

@ -0,0 +1,57 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_hashmap_advanced_type_hash.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: thrieg <thrieg@student.42mulhouse.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/07 12:47:23 by thrieg #+# #+# */
/* Updated: 2025/02/16 19:08:26 by thrieg ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_hashmap_private.h"
#include <stdint.h>
//hash function for an address, returns a size_t between 0 and size_t max
size_t ft_hash_address(const void *key)
{
uintptr_t address;
address = (uintptr_t)key;
return ((size_t)address >> 3);
}
// Hash function for a t_list, returns a size_t between 0 and size_t max
//takes the function to hash a single element
size_t ft_hash_list(const t_list *list)
{
return (ft_hash_address(list));
}
// Hash function for a t_hashmap, returns a size_t between 0 and size_t max
size_t ft_hash_hashmap(const t_hashmap *hashmap)
{
return (ft_hash_address(hashmap));
}
// Hash function for a t_vector, returns a size_t between 0 and size_t max
size_t ft_hash_vector(const t_vector *vec)
{
size_t i;
int c;
size_t index;
size_t hash;
char *str;
hash = 5381;
index = vec->index;
str = vec->buffer;
i = 0;
while (i < index)
{
c = str[i++];
hash = ((hash << 5) + hash) + c;
}
return (hash);
}

Binary file not shown.

View file

@ -0,0 +1,79 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_hashmap_basic_cmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: thrieg <thrieg@student.42mulhouse.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/08 13:18:52 by thrieg #+# #+# */
/* Updated: 2025/02/16 19:08:27 by thrieg ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_hashmap_private.h"
#include <limits.h>
// Comparison function for integers
int int_cmp(void *key1, void *key2)
{
int a;
int b;
a = *(int *)key1;
b = *(int *)key2;
if (a < b)
return (-1);
else if (a > b)
return (1);
else
return (0);
}
// Comparison function for strings
int cmp_str(void *key1, void *key2)
{
return (ft_strcmp((char *)key1, (char *)key2));
}
// Comparison function for unsigned chars
int cmp_uchar(void *key1, void *key2)
{
unsigned char *c1;
unsigned char *c2;
c1 = (unsigned char *)key1;
c2 = (unsigned char *)key2;
return (*c1 - *c2);
}
// Comparison function for unsigned integers
int uint_cmp(void *key1, void *key2)
{
unsigned int a;
unsigned int b;
a = *(unsigned int *)key1;
b = *(unsigned int *)key2;
if (a < b)
return (-1);
else if (a > b)
return (1);
else
return (0);
}
// Comparison function for size_t
int sizet_cmp(void *key1, void *key2)
{
size_t a;
size_t b;
a = *(size_t *)key1;
b = *(size_t *)key2;
if (a < b)
return (-1);
else if (a > b)
return (1);
else
return (0);
}

Binary file not shown.

View file

@ -0,0 +1,57 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_hashmap_basic_type_hash.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: thrieg <thrieg@student.42mulhouse.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/07 12:34:20 by thrieg #+# #+# */
/* Updated: 2025/02/16 19:08:29 by thrieg ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_hashmap_private.h"
// Integer hash function, returns a size_t between 0 and size_t max
size_t ft_hash_int(int value)
{
return ((size_t)(value * 2654435761u));
}
// Unsigned integer hash function, returns a size_t between 0 and size_t max
size_t ft_hash_uint(unsigned int value)
{
return ((size_t)(value * 2654435761u));
}
// Character hash function, returns a size_t between 0 and size_t max
size_t ft_hash_char(char value)
{
return ((size_t)(value * 31));
}
// String hash function (DJB2), returns a size_t between 0 and size_t max
size_t ft_hash_string(const char *str)
{
int c;
size_t hash;
hash = 5381;
while (*str)
{
c = *str++;
hash = ((hash << 5) + hash) + c;
}
return (hash);
}
// size_t hash function, returns a size_t between 0 and size_t max
size_t ft_hash_size_t(size_t value)
{
value ^= value >> 33;
value *= 0xff51afd7ed558ccd;
value ^= value >> 33;
value *= 0xc4ceb9fe1a85ec53;
value ^= value >> 33;
return (value);
}

Binary file not shown.

View file

@ -0,0 +1,46 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_hashmap_private.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: thrieg <thrieg@student.42mulhouse.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/07 13:49:11 by thrieg #+# #+# */
/* Updated: 2025/02/16 19:08:30 by thrieg ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef FT_HASHMAP_PRIVATE_H
# define FT_HASHMAP_PRIVATE_H
# include "../ft_hashmap.h"
typedef struct s_hash_element
{
void *key;
void *value;
size_t hash;
} t_hash_element;
t_hash_element *ft_create_hash_element(void *key, void *value, size_t hash);
void ft_free_hash_element(t_hash_element *elem, t_hashmap *map);
int ft_add_hashmap_element(
size_t index,
t_hashmap *map,
t_hash_element *elem);
int ft_add_hashmap_element(
size_t index,
t_hashmap *map,
t_hash_element *elem);
void ft_copy_hashmap_table(
t_list **new_table,
t_list **old_table,
size_t new_size,
size_t old_size);
void ft_delete_hashmap_list_node(
t_list *curr,
t_list *prev,
size_t index,
t_hashmap *map);
#endif

View file

@ -0,0 +1,70 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_hashmap_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: thrieg <thrieg@student.42mulhouse.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/07 13:51:48 by thrieg #+# #+# */
/* Updated: 2025/02/16 19:08:32 by thrieg ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_hashmap_private.h"
void ft_free_hash_element(t_hash_element *elem, t_hashmap *map)
{
if (map->free_key)
map->free_key(elem->key);
if (map->free_value)
map->free_value(elem->value);
free(elem);
}
// Helper function to create a new hash element
t_hash_element *ft_create_hash_element(void *key, void *value, size_t hash)
{
t_hash_element *new_element;
new_element = malloc(sizeof(t_hash_element));
if (!new_element)
return (NULL);
new_element->key = key;
new_element->value = value;
new_element->hash = hash;
return (new_element);
}
//returns 0 for allocation fail without allocating or freeing anything
int ft_add_hashmap_element(size_t index, t_hashmap *map, t_hash_element *elem)
{
t_list *new_node;
new_node = malloc(sizeof(t_list));
if (!new_node)
return (0);
new_node->content = elem;
new_node->next = map->table[index];
map->table[index] = new_node;
map->nb_elems++;
return (1);
}
//returns 0 without doing anything if the allocation of the new table fails
//in that case the old table is still valid!
//returns 1 if the resize is a success
int ft_resize_hashmap(t_hashmap *map)
{
size_t new_size;
t_list **new_table;
new_size = map->hashmap_size * HASHMAP_RESIZE_FACTOR;
new_table = ft_calloc(new_size, sizeof(t_list *));
if (!new_table)
return (0);
ft_copy_hashmap_table(new_table, map->table, new_size, map->hashmap_size);
free(map->table);
map->table = new_table;
map->hashmap_size = new_size;
return (1);
}

Binary file not shown.

View file

@ -0,0 +1,85 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_hashmap_utils_two.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: thrieg <thrieg@student.42mulhouse.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/07 16:04:36 by thrieg #+# #+# */
/* Updated: 2025/02/16 19:08:31 by thrieg ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_hashmap_private.h"
//doesn't allocate anything no error possible
void ft_copy_hashmap_table(
t_list **new_table,
t_list **old_table,
size_t new_size,
size_t old_size)
{
t_list *curr;
t_list *next;
t_hash_element *elem;
size_t i;
size_t new_index;
i = 0;
while (i < old_size)
{
curr = old_table[i];
while (curr)
{
next = curr->next;
elem = (t_hash_element *)curr->content;
new_index = elem->hash % new_size;
curr->next = new_table[new_index];
new_table[new_index] = curr;
curr = next;
}
i++;
}
}
//helper function for delete_hashmap_element to delete the node once found
void ft_delete_hashmap_list_node(
t_list *curr,
t_list *prev,
size_t index,
t_hashmap *map)
{
t_hash_element *elem;
elem = (t_hash_element *)curr->content;
if (prev)
prev->next = curr->next;
else
map->table[index] = curr->next;
ft_free_hash_element(elem, map);
free(curr);
map->nb_elems--;
}
//returns 0 without doing anything if the allocation of the new table fails
//or if the table is too little in that case the old table is still valid!
//returns 1 if the shrink is a success
int ft_shrink_hashmap(t_hashmap *map)
{
size_t new_size;
t_list **new_table;
if (map->hashmap_size == HASHMAP_MINIMUM_SIZE)
return (0);
new_size = map->hashmap_size / HASHMAP_SHRINK_FACTOR;
if (new_size < HASHMAP_MINIMUM_SIZE)
new_size = HASHMAP_MINIMUM_SIZE;
new_table = ft_calloc(new_size, sizeof(t_list *));
if (!new_table)
return (0);
ft_copy_hashmap_table(new_table, map->table, new_size, map->hashmap_size);
free(map->table);
map->table = new_table;
map->hashmap_size = new_size;
return (1);
}

Binary file not shown.

80
libft/ft_int_utils.c Normal file
View file

@ -0,0 +1,80 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_int_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: thrieg <thrieg@student.42mulhouse.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/30 10:11:17 by alier #+# #+# */
/* Updated: 2025/02/16 19:03:36 by thrieg ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
#include <errno.h>
#include "libft.h"
size_t i_drep_len(int n)
{
size_t len;
len = 0;
if (n < 0)
len++;
while (1)
{
len++;
n /= 10;
if (n == 0)
break ;
}
return (len);
}
/*
* Reimplementation of libc atoi() but sets `errno` to `ERANGE` if an
* domain error is encountered (overflow, underflow) or `EINVAL` if
* no digits characters or invalid characters at end).
*/
int ft_atoie(const char *nptr)
{
int n;
int mult;
n = 0;
mult = -1;
while (ft_isspace(*nptr))
nptr++;
if (*nptr == '+' || *nptr == '-')
{
if (*nptr == '-')
mult = 1;
nptr++;
}
if (!ft_isdigit(*nptr))
errno = EINVAL;
while (ft_isdigit(*nptr))
{
n = safe_int_sub(safe_int_mul(n, 10), *nptr - '0');
nptr++;
}
if (*nptr != '\0')
errno = EINVAL;
return (safe_int_mul(n, mult));
}
unsigned int ft_max_uint(size_t len, unsigned int a[len])
{
size_t i;
unsigned int max;
i = 0;
max = 0;
while (i < len)
{
if (a[i] > max)
max = a[i];
i++;
}
return (max);
}

BIN
libft/ft_int_utils.o Normal file

Binary file not shown.

20
libft/ft_isalnum.c Executable file
View file

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isalnum.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: thrieg <thrieg@student.42mulhouse.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/14 12:44:53 by thrieg #+# #+# */
/* Updated: 2025/02/16 19:03:40 by thrieg ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_isalnum(int c)
{
if (ft_isalpha(c) | ft_isdigit(c))
return (1);
return (0);
}

BIN
libft/ft_isalnum.o Normal file

Binary file not shown.

39
libft/ft_isalpha.c Executable file
View file

@ -0,0 +1,39 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isalpha.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: thrieg <thrieg@student.42mulhouse.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/09/06 12:44:45 by thrieg #+# #+# */
/* Updated: 2025/02/16 19:03:42 by thrieg ### ########.fr */
/* */
/* ************************************************************************** */
int ft_isalpha(int c)
{
if (c < 65 || c > 122 || (c > 90 && c < 97))
return (0);
else
return (1);
}
int ft_isspace(char c)
{
return (c == ' ' || c == '\f' || c == '\n' || c == '\r'
|| c == '\t' || c == '\v');
}
int ft_tolower(int c)
{
if (c >= 'A' && c <= 'Z')
return (c + ('a' - 'A'));
return (c);
}
int ft_toupper(int c)
{
if (c >= 'a' && c <= 'z')
return (c - ('a' - 'A'));
return (c);
}

BIN
libft/ft_isalpha.o Normal file

Binary file not shown.

18
libft/ft_isascii.c Executable file
View file

@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isascii.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: thrieg <thrieg@student.42mulhouse.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/14 15:10:04 by thrieg #+# #+# */
/* Updated: 2025/02/16 19:03:43 by thrieg ### ########.fr */
/* */
/* ************************************************************************** */
int ft_isascii(int c)
{
if (c >= 0 && c < 128)
return (1);
return (0);
}

BIN
libft/ft_isascii.o Normal file

Binary file not shown.

18
libft/ft_isdigit.c Executable file
View file

@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isdigit.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: thrieg <thrieg@student.42mulhouse.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/09/08 12:57:11 by thrieg #+# #+# */
/* Updated: 2025/02/16 19:03:45 by thrieg ### ########.fr */
/* */
/* ************************************************************************** */
int ft_isdigit(int c)
{
if (c < '0' || c > '9')
return (0);
return (1);
}

BIN
libft/ft_isdigit.o Normal file

Binary file not shown.

18
libft/ft_isprint.c Executable file
View file

@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isprint.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: thrieg <thrieg@student.42mulhouse.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/14 15:14:35 by thrieg #+# #+# */
/* Updated: 2025/02/16 19:03:47 by thrieg ### ########.fr */
/* */
/* ************************************************************************** */
int ft_isprint(int c)
{
if (c < 32 || c > 126)
return (0);
return (1);
}

BIN
libft/ft_isprint.o Normal file

Binary file not shown.

83
libft/ft_itoa.c Executable file
View file

@ -0,0 +1,83 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_itoa.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: thrieg <thrieg@student.42mulhouse.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/15 15:29:15 by thrieg #+# #+# */
/* Updated: 2025/02/16 19:03:49 by thrieg ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static void ft_swap(char *a, char *b)
{
char c;
c = *a;
*a = *b;
*b = c;
}
static void ft_reverse_buff(char buff[11], size_t(len))
{
size_t index;
if (buff[0] == '-')
{
index = 1;
while ((len / 2) >= index)
{
ft_swap(&buff[index], &buff[len - index]);
index++;
}
}
else
{
index = 0;
while (((len - 1) / 2) >= index)
{
ft_swap(&buff[index], &buff[len - index - 1]);
index++;
}
}
}
static char *subfunction(char *ret, char buff[11], size_t buff_len)
{
ft_reverse_buff(buff, buff_len);
ft_memcpy(ret, (const void *)buff, buff_len);
ret[buff_len] = '\0';
return (ret);
}
//only works if an int is 32 bits, I'll maybe change it later for the bonuses
char *ft_itoa(int n)
{
char *ret;
char buff[11];
size_t buff_len;
if (n <= -2147483648)
return (ft_strdup("-2147483648"));
if (n == 0)
return (ft_strdup("0"));
buff_len = 0;
if (n < 0)
{
buff[0] = '-';
buff_len++;
n *= -1;
}
while (n > 0)
{
buff[buff_len++] = (n % 10) + '0';
n /= 10;
}
ret = malloc(sizeof(char) * (buff_len) + 1);
if (!ret)
return (NULL);
return (subfunction(ret, buff, buff_len));
}

BIN
libft/ft_itoa.o Normal file

Binary file not shown.

120
libft/ft_itoa_base.c Executable file
View file

@ -0,0 +1,120 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_itoa_base.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: thrieg < thrieg@student.42mulhouse.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/09/11 11:50:53 by thrieg #+# #+# */
/* Updated: 2025/11/17 17:14:48 by thrieg ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include "ft_vector.h"
static int ft_is_sign(char c)
{
if (c == '-' || c == '+')
return (1);
else
return (0);
}
//converts nbr into a known to be valid base, then append it to vec
//returns 0 if the concatenation fails, or 1 if everything goes well
static int ft_put_ok_base(
unsigned int nbr,
char *base,
size_t base_lenght,
t_vector *vec)
{
char buffer[32];
int i;
i = 31;
if (nbr == 0)
if (!ft_vector_pushback(vec, base[0]))
return (0);
while (nbr > 0)
{
buffer[i] = base[nbr % base_lenght];
nbr /= base_lenght;
i--;
}
if (!ft_vector_concat(vec, (buffer + i + 1), (31 - i)))
return (0);
return (1);
}
//converts nbr into an unsigned int,
//append a minus sign in vec if nbr is negative
//sets flag_pushback_failed to 1 if ft_vector_pushback returns NULL
static unsigned int ft_transform_int_to_unsigned(
int nbr,
t_vector *vec,
int *flag_pushback_failed)
{
if (nbr < 0)
{
if (!ft_vector_pushback(vec, '-'))
*flag_pushback_failed = 1;
if (nbr == -2147483648)
return (2147483648);
else
return ((unsigned int) -nbr);
}
else
return ((unsigned int) nbr);
}
//returns 1 if the base is valid, and 0 if it's not
static int ft_is_ok_base(char *base)
{
char used_characters[128];
size_t i;
i = 0;
ft_bzero(used_characters, 128);
while (base[i] != '\0')
{
if (used_characters[(int) base[i]] == 0)
used_characters[(int) base[i]]++;
else
return (0);
if (ft_is_sign(base[i]))
return (0);
i++;
}
if (i < 2)
return (0);
return (1);
}
//returns a standard C string of nbr converted in the "base" base
//base have to only cointain ascii characters
//returns NULL if the base is invalid or if an allocation failed
char *ft_itoa_base(int nbr, char *base)
{
unsigned int unsigned_nbr;
t_vector *ret;
char *ret_str;
int flag;
ret = ft_create_vector(2);
if (!ret)
return (NULL);
flag = 0;
if (!ft_is_ok_base(base))
return (ft_free_vector(&ret), NULL);
unsigned_nbr = ft_transform_int_to_unsigned(nbr, ret, &flag);
if (flag)
return (ft_free_vector(&ret), NULL);
if (!ft_put_ok_base(unsigned_nbr, base, ft_strlen(base), ret))
return (ft_free_vector(&ret), NULL);
ret_str = ft_vtoc(ret);
ft_free_vector(&ret);
if (!ret_str)
return (NULL);
return (ret_str);
}

BIN
libft/ft_itoa_base.o Normal file

Binary file not shown.

46
libft/ft_long_utils.c Normal file
View file

@ -0,0 +1,46 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_long_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: thrieg <thrieg@student.42mulhouse.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/30 10:11:17 by alier #+# #+# */
/* Updated: 2025/02/16 19:03:51 by thrieg ### ########.fr */
/* */
/* ************************************************************************** */
#include <errno.h>
#include "libft.h"
/*
* Reimplementation of libc atol() but sets `errno` to `ERANGE` if an
* domain error is encountered (overflow, underflow) or `EINVAL` if
* no digits characters or invalid characters at end).
*/
long ft_atole(const char *nptr)
{
long n;
long mult;
n = 0;
mult = -1;
while (ft_isspace(*nptr))
nptr++;
if (*nptr == '+' || *nptr == '-')
{
if (*nptr == '-')
mult = 1;
nptr++;
}
if (!ft_isdigit(*nptr))
errno = EINVAL;
while (ft_isdigit(*nptr))
{
n = safe_long_sub(safe_long_mul(n, 10), *nptr - '0');
nptr++;
}
if (*nptr != '\0')
errno = EINVAL;
return (safe_long_mul(n, mult));
}

BIN
libft/ft_long_utils.o Normal file

Binary file not shown.

26
libft/ft_lstadd_back_bonus.c Executable file
View file

@ -0,0 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstadd_back_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: thrieg <thrieg@student.42mulhouse.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/16 12:41:51 by thrieg #+# #+# */
/* Updated: 2025/02/16 19:03:52 by thrieg ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
//returns without doing anything if lst or new is NULL, this is dumb because we
//can't report the error given the prototyping but I'm not taking any risk for
//my 3th retry...
void ft_lstadd_back(t_list **lst, t_list *new)
{
if (!lst || !new)
return ;
if (*lst == NULL)
*lst = new;
else
ft_lstlast(*lst)->next = new;
}

Binary file not shown.

24
libft/ft_lstadd_front_bonus.c Executable file
View file

@ -0,0 +1,24 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstadd_front_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: thrieg <thrieg@student.42mulhouse.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/16 12:04:47 by thrieg #+# #+# */
/* Updated: 2025/02/16 19:03:53 by thrieg ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
//returns without doing anything if lst or new are NULL, this is dumb because we
//can't report the error given the prototyping but I'm not taking any risk for
//my 3th retry...
void ft_lstadd_front(t_list **lst, t_list *new)
{
if (!new || !lst)
return ;
new->next = *lst;
*lst = new;
}

Binary file not shown.

31
libft/ft_lstclear_bonus.c Executable file
View file

@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstclear_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: thrieg <thrieg@student.42mulhouse.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/16 13:00:50 by thrieg #+# #+# */
/* Updated: 2025/02/16 19:03:54 by thrieg ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
//returns without doing anything if lst or del are NULL, this is dumb because we
//can't report the error given the prototyping but I'm not taking any risk for
//my 3th retry...
void ft_lstclear(t_list **lst, void (*del)(void *))
{
t_list *next;
if (!lst || !del)
return ;
while (*lst)
{
next = (*lst)->next;
del((*lst)->content);
free(*lst);
*lst = next;
}
}

BIN
libft/ft_lstclear_bonus.o Normal file

Binary file not shown.

24
libft/ft_lstdelone_bonus.c Executable file
View file

@ -0,0 +1,24 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstdelone_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: thrieg <thrieg@student.42mulhouse.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/16 12:53:23 by thrieg #+# #+# */
/* Updated: 2025/02/16 19:03:55 by thrieg ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
//returns without doing anything if lst or del are NULL, this is dumb because we
//can't report the error given the prototyping but I'm not taking any risk for
//my 3th retry...
void ft_lstdelone(t_list *lst, void (*del)(void *))
{
if (!lst || !del)
return ;
del(lst->content);
free(lst);
}

BIN
libft/ft_lstdelone_bonus.o Normal file

Binary file not shown.

28
libft/ft_lstiter_bonus.c Executable file
View file

@ -0,0 +1,28 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstiter_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: thrieg <thrieg@student.42mulhouse.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/16 13:11:26 by thrieg #+# #+# */
/* Updated: 2025/02/16 19:03:57 by thrieg ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
//returns without doing anything if lst or f are NULL, this is dumb because we
//can't report the error given the prototyping but I'm not taking any risk for
//my 3th retry...
void ft_lstiter(t_list *lst, void (*f)(void *))
{
if (!lst || !f)
return ;
while (lst->next)
{
f(lst->content);
lst = lst->next;
}
f(lst->content);
}

BIN
libft/ft_lstiter_bonus.o Normal file

Binary file not shown.

44
libft/ft_lstlast_bonus.c Executable file
View file

@ -0,0 +1,44 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstlast_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: thrieg <thrieg@student.42mulhouse.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/16 12:21:13 by thrieg #+# #+# */
/* Updated: 2025/02/16 19:04:00 by thrieg ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
//returns NULL if lst is NULL
t_list *ft_lstlast(t_list *lst)
{
if (!lst)
return (NULL);
while (lst->next)
lst = lst->next;
return (lst);
}
/*
* @return the element of `lst` at position `i`, NULL if doesn't exist.
* `ft_lstat(lst, 0)` returns `lst`.
*/
t_list *ft_lstat(t_list *lst, size_t i)
{
size_t j;
if (lst == NULL)
return (lst);
j = 0;
while (lst->next != NULL && j < i)
{
lst = lst->next;
j++;
}
if (j != i)
return (NULL);
return (lst);
}

BIN
libft/ft_lstlast_bonus.o Normal file

Binary file not shown.

63
libft/ft_lstmap_bonus.c Executable file
View file

@ -0,0 +1,63 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstmap_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: thrieg <thrieg@student.42mulhouse.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/16 13:22:26 by thrieg #+# #+# */
/* Updated: 2025/02/16 19:04:01 by thrieg ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static t_list *ft_safe_create(
void *(*f)(void *),
void (*del)(void *),
void *content)
{
void *temp;
t_list *ret;
temp = f(content);
if (!temp)
return (NULL);
ret = ft_lstnew(temp);
if (!ret)
{
del(temp);
return (NULL);
}
return (ret);
}
//returns NULL without doing anything else if any argument is NULL
//returns NULL if any allocation fails
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *))
{
t_list *new_list;
t_list *new_node;
t_list *temp;
if (!lst || !f || !del)
return (NULL);
new_node = ft_safe_create(f, del, lst->content);
if (!new_node)
return (NULL);
new_list = new_node;
lst = lst->next;
while (lst)
{
temp = ft_safe_create(f, del, lst->content);
if (!temp)
{
ft_lstclear(&new_list, del);
return (NULL);
}
new_node->next = temp;
new_node = new_node->next;
lst = lst->next;
}
return (new_list);
}

BIN
libft/ft_lstmap_bonus.o Normal file

Binary file not shown.

26
libft/ft_lstnew_bonus.c Executable file
View file

@ -0,0 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstnew_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: thrieg <thrieg@student.42mulhouse.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/16 11:54:17 by thrieg #+# #+# */
/* Updated: 2025/02/16 19:04:02 by thrieg ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
//returns NULL if any allocation fails
t_list *ft_lstnew(void *content)
{
t_list *ret;
ret = malloc(sizeof(t_list));
if (!ret)
return (NULL);
ret->content = content;
ret->next = NULL;
return (ret);
}

BIN
libft/ft_lstnew_bonus.o Normal file

Binary file not shown.

29
libft/ft_lstsize_bonus.c Executable file
View file

@ -0,0 +1,29 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstsize_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: thrieg <thrieg@student.42mulhouse.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/16 12:13:44 by thrieg #+# #+# */
/* Updated: 2025/02/16 19:04:03 by thrieg ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
//returns 0 if lst is NULL
int ft_lstsize(t_list *lst)
{
int i;
if (!lst)
return (0);
i = 1;
while (lst->next)
{
i++;
lst = lst->next;
}
return (i);
}

BIN
libft/ft_lstsize_bonus.o Normal file

Binary file not shown.

27
libft/ft_memchr.c Executable file
View file

@ -0,0 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: thrieg <thrieg@student.42mulhouse.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/14 17:19:34 by thrieg #+# #+# */
/* Updated: 2025/02/16 19:04:05 by thrieg ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_memchr(const void *s, int c, size_t n)
{
const char *str;
str = (const char *)s;
while (n--)
{
if (*str == (char)c)
return ((void *)str);
str++;
}
return (NULL);
}

BIN
libft/ft_memchr.o Normal file

Binary file not shown.

31
libft/ft_memcmp.c Executable file
View file

@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memcmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: thrieg <thrieg@student.42mulhouse.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/14 17:39:59 by thrieg #+# #+# */
/* Updated: 2025/02/16 19:04:06 by thrieg ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_memcmp(const void *s1, const void *s2, size_t n)
{
const unsigned char *st1;
const unsigned char *st2;
st1 = (const unsigned char *)s1;
st2 = (const unsigned char *)s2;
while (n && (*st1 == *st2))
{
st1++;
st2++;
n--;
}
if (n == 0)
return (0);
return (*st1 - *st2);
}

BIN
libft/ft_memcmp.o Normal file

Binary file not shown.

37
libft/ft_memcpy.c Executable file
View file

@ -0,0 +1,37 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memcpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: thrieg <thrieg@student.42mulhouse.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/14 15:52:40 by thrieg #+# #+# */
/* Updated: 2025/02/16 19:04:07 by thrieg ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_memcpy(void *dest, const void *src, size_t n)
{
char *str;
unsigned long long *str_packed;
char *str_src;
unsigned long long *str_src_packed;
str_packed = (unsigned long long *)dest;
str_src_packed = (unsigned long long *)src;
while (n >= sizeof(unsigned long long))
{
*str_packed++ = *str_src_packed++;
n -= sizeof(unsigned long long);
}
str = (char *)str_packed;
str_src = (char *)str_src_packed;
while (n > 0)
{
*str++ = *str_src++;
n--;
}
return (dest);
}

BIN
libft/ft_memcpy.o Normal file

Binary file not shown.

61
libft/ft_memmove.c Executable file
View file

@ -0,0 +1,61 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memmove.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: thrieg <thrieg@student.42mulhouse.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/14 16:00:16 by thrieg #+# #+# */
/* Updated: 2025/02/16 19:04:08 by thrieg ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static void *ft_optimised_revcpy(void *dest, const void *src, size_t n)
{
char *str;
unsigned long long *str_packed;
char *str_src;
unsigned long long *str_src_packed;
str = (char *)dest;
str_src = (char *)src;
while (n % sizeof(unsigned long long))
{
n--;
str[n] = str_src[n];
}
n /= sizeof(unsigned long long);
str_packed = (unsigned long long *)dest;
str_src_packed = (unsigned long long *)src;
while (n > 0)
{
n--;
str_packed[n] = str_src_packed[n];
}
return (dest);
}
void *ft_memmove(void *dest, const void *src, size_t n)
{
char *str;
const char *str_src;
if (!dest && !src)
return (NULL);
str = (char *)dest;
str_src = (const char *)src;
if (str > str_src)
{
if ((str + sizeof(unsigned long long)) > str_src)
return (ft_optimised_revcpy(dest, src, n));
while (n-- > 0)
str[n] = str_src[n];
}
else
{
ft_memcpy(dest, src, n);
}
return (dest);
}

BIN
libft/ft_memmove.o Normal file

Binary file not shown.

42
libft/ft_memset.c Executable file
View file

@ -0,0 +1,42 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memset.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: thrieg <thrieg@student.42mulhouse.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/14 15:40:57 by thrieg #+# #+# */
/* Updated: 2025/02/16 19:04:13 by thrieg ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_memset(void *s, int c, size_t n)
{
char *str;
unsigned long long *str_packed;
unsigned long long cccccccc;
size_t i;
str = (char *)s;
while (n % sizeof(unsigned long long))
{
*str++ = (unsigned char)c;
n--;
}
str_packed = (unsigned long long *)str;
cccccccc = 0;
i = 0;
while (i < sizeof(unsigned long long))
{
cccccccc |= ((unsigned long long)(unsigned char)c) << (i * 8);
i++;
}
while (n >= sizeof(unsigned long long))
{
*str_packed++ = cccccccc;
n -= sizeof(unsigned long long);
}
return (s);
}

BIN
libft/ft_memset.o Normal file

Binary file not shown.

38
libft/ft_power.c Normal file
View file

@ -0,0 +1,38 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_power.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: thrieg <thrieg@student.42mulhouse.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/01/07 14:57:23 by thrieg #+# #+# */
/* Updated: 2025/02/16 19:04:15 by thrieg ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
ssize_t ft_power(ssize_t nb, ssize_t power)
{
ssize_t answer;
ssize_t i;
if (power < 0)
return (0);
if (power == 0)
return (1);
if (power % 2 == 0)
return (ft_power(nb * nb, power / 2));
answer = nb;
i = 1;
while (i < power)
{
if ((power - i) % 2 == 0)
{
return (answer * ft_power(nb, (power - i)));
}
answer *= nb;
i++;
}
return (answer);
}

BIN
libft/ft_power.o Normal file

Binary file not shown.

View file

@ -0,0 +1,104 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_arglist_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: thrieg <thrieg@student.42mulhouse.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/27 17:04:47 by thrieg #+# #+# */
/* Updated: 2025/02/16 19:07:39 by thrieg ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
#include "ft_printf.h"
#include "ft_printf_bonus.h"
static void ft_set_default_flag_values(t_arglist *arglist)
{
arglist->width_mini = 0;
arglist->precision = -1;
arglist->flag_hashtag = 0;
arglist->flag_zero = 0;
arglist->flag_justified_left = 0;
arglist->flag_space = 0;
arglist->flag_plus = 0;
}
static void ft_handle_overriding_arguments(t_arglist *arglist)
{
if ((arglist->precision >= 0) || arglist->flag_justified_left)
arglist->flag_zero = 0;
if (arglist->flag_plus)
arglist->flag_space = 0;
}
static void ft_handle_width_precision(
t_arglist *arglist,
int *i,
const char *str,
va_list *args)
{
if (ft_isdigit(str[*i]))
{
arglist->width_mini = ft_atoi(&str[*i], NULL);
while (ft_isdigit(str[*i]))
(*i)++;
}
else if (str[*i] == '*')
{
arglist->width_mini = va_arg(*args, int);
(*i)++;
}
if (str[*i] == '.')
{
(*i)++;
if (str[*i] == '*')
{
arglist->precision = va_arg(*args, int);
(*i)++;
}
else
arglist->precision = ft_atoi(&str[*i], NULL);
while (ft_isdigit(str[*i]))
(*i)++;
}
}
static void ft_handle_flags(t_arglist *arglist, int *i, const char *str)
{
while (str[*i] == '#' || str[*i] == '0' || str[*i] == '-'
|| str[*i] == ' ' || str[*i] == '+')
{
if (str[*i] == '#')
arglist->flag_hashtag = 1;
if (str[*i] == '0')
arglist->flag_zero = 1;
if (str[*i] == '-')
arglist->flag_justified_left = 1;
if (str[*i] == ' ')
arglist->flag_space = 1;
if (str[*i] == '+')
arglist->flag_plus = 1;
(*i)++;
}
}
t_arglist *ft_create_arglist(const char *str, va_list *args)
{
t_arglist *arglist;
int i;
arglist = malloc(sizeof(t_arglist));
if (!arglist)
return (NULL);
ft_set_default_flag_values(arglist);
i = 0;
if (str[i] == '%')
i++;
ft_handle_flags(arglist, &i, str);
ft_handle_width_precision(arglist, &i, str, args);
arglist->size_of_argument_string = i;
ft_handle_overriding_arguments(arglist);
return (arglist);
}

Binary file not shown.

View file

@ -0,0 +1,75 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_case_d_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: thrieg <thrieg@student.42mulhouse.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/25 17:12:38 by thrieg #+# #+# */
/* Updated: 2025/02/16 19:07:44 by thrieg ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
#include "ft_printf.h"
#include "ft_printf_bonus.h"
int padding_if_needed_before(
t_arglist *arglist,
char caller,
size_t len,
t_vector *vec);
int padding_if_needed_after(
t_arglist *arglist,
char caller,
size_t len,
t_vector *vec);
char *init_str_to_cat(t_arglist *arglist, unsigned int nbr);
void convert_precision_if_flag_zero(t_arglist *arglist, int nbr);
int ft_handle_if_precision(
t_arglist *arglist,
int nbr,
t_vector *vec,
int *size);
int ft_handle_if_not_precision(
t_arglist *arglist,
int nbr,
t_vector *vec,
int *size);
int ft_handle_concat_and_padding(
t_arglist *arglist,
char *str_to_cat,
t_vector *vec,
int size);
//flags to handle: zero, space, plus, precision, justified left... hard mode
//flag zero padding without precision behaves just like a precision
//(zeroes after the sign) and when it's spaces they're before the sign
int ft_case_d_bonus(t_vector *vec, va_list *args, t_arglist *arglist)
{
char *str_to_cat;
int nbr;
int size;
nbr = va_arg(*args, int);
str_to_cat = init_str_to_cat(arglist, nbr);
if (!str_to_cat)
return (0);
convert_precision_if_flag_zero(arglist, nbr);
size = (int)ft_strlen(str_to_cat);
if (nbr < 0)
size--;
if ((size < arglist->precision) && (arglist->precision >= 0))
{
if (!ft_handle_if_precision(arglist, nbr, vec, &size))
return (free(str_to_cat), 0);
}
else
{
if (!ft_handle_if_not_precision(arglist, nbr, vec, &size))
return (free(str_to_cat), 0);
}
if (!ft_handle_concat_and_padding(arglist, str_to_cat, vec, size))
return (free(str_to_cat), 0);
return (free(str_to_cat), 1);
}

Binary file not shown.

View file

@ -0,0 +1,115 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_case_d_utils_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: thrieg <thrieg@student.42mulhouse.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/27 15:59:04 by thrieg #+# #+# */
/* Updated: 2025/02/16 19:07:45 by thrieg ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
#include "ft_printf.h"
#include "ft_printf_bonus.h"
int padding_if_needed_before(
t_arglist *arglist,
char caller,
size_t len,
t_vector *vec);
int padding_if_needed_after(
t_arglist *arglist,
char caller,
size_t len,
t_vector *vec);
char *init_str_to_cat(t_arglist *arglist, unsigned int nbr)
{
if (nbr == 0 && arglist->precision == 0)
return (ft_strdup(""));
return (ft_itoa(nbr));
}
void convert_precision_if_flag_zero(t_arglist *arglist, int nbr)
{
if ((arglist->precision < 0) && !(arglist->flag_justified_left)
&& arglist->flag_zero)
{
arglist->precision = arglist->width_mini;
arglist->width_mini = 0;
if (nbr < 0 || arglist->flag_plus || arglist->flag_space)
arglist->precision--;
}
}
int ft_handle_if_precision(
t_arglist *arglist,
int nbr,
t_vector *vec,
int *size)
{
if (nbr < 0 || arglist->flag_plus || arglist->flag_space)
{
if (padding_if_needed_before(arglist, 'd',
arglist->precision + 1, vec) < 0)
return (0);
}
else
if (padding_if_needed_before(arglist, 'd', arglist->precision, vec) < 0)
return (0);
if (arglist->flag_plus && (nbr >= 0) && !ft_vector_pushback(vec, '+'))
return (0);
if (arglist->flag_space && (nbr >= 0) && !(arglist->flag_plus) && nbr >= 0)
if (!ft_vector_pushback(vec, ' '))
return (0);
if (nbr < 0 && !ft_vector_pushback(vec, '-'))
return (0);
while ((*size) < arglist->precision)
{
if (!ft_vector_pushback(vec, '0'))
return (0);
(*size)++;
}
if (nbr < 0 || arglist->flag_plus || arglist->flag_space)
(*size)++;
return (1);
}
int ft_handle_if_not_precision(
t_arglist *arglist,
int nbr,
t_vector *vec,
int *size)
{
if (nbr < 0 || arglist->flag_space || arglist->flag_plus)
(*size)++;
if (padding_if_needed_before(arglist, 'd', (*size), vec) < 0)
return (0);
if (arglist->flag_plus && (nbr >= 0))
if (!ft_vector_pushback(vec, '+'))
return (0);
if (arglist->flag_space && (nbr >= 0) && !(arglist->flag_plus))
if (nbr >= 0)
if (!ft_vector_pushback(vec, ' '))
return (0);
if (nbr < 0)
if (!ft_vector_pushback(vec, '-'))
return (0);
return (1);
}
int ft_handle_concat_and_padding(
t_arglist *arglist,
char *str_to_cat,
t_vector *vec,
int size)
{
if (!ft_vector_concat(vec, str_to_cat + ft_strnonchr(str_to_cat, '-'),
ft_strlen(str_to_cat) - ft_strnonchr(str_to_cat, '-')))
return (0);
if (padding_if_needed_after(arglist, 'd', size, vec) < 0)
return (0);
return (1);
}

Binary file not shown.

View file

@ -0,0 +1,115 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_case_lowx_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: thrieg <thrieg@student.42mulhouse.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/25 17:09:37 by thrieg #+# #+# */
/* Updated: 2025/02/16 19:07:46 by thrieg ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
#include "ft_printf.h"
#include "ft_printf_bonus.h"
int padding_if_needed_before(
t_arglist *arglist,
char caller,
size_t len,
t_vector *vec);
int padding_if_needed_after(
t_arglist *arglist,
char caller,
size_t len,
t_vector *vec);
static int handle_hashtag_prefix(
t_vector *vec,
t_arglist *arglist,
unsigned int nbr,
int flag_zero)
{
if (arglist->flag_hashtag && !flag_zero && nbr != 0)
{
if (!ft_vector_concat(vec, "0x", 2))
return (0);
}
return (1);
}
static int apply_precision_padding(t_vector *vec, size_t *size, int precision)
{
while ((int)(*size)++ < precision)
{
if (!ft_vector_pushback(vec, '0'))
return (0);
}
(*size)--;
return (1);
}
static char *init_str_to_cat(t_arglist *arglist, unsigned int nbr)
{
if (nbr == 0 && arglist->precision == 0)
return (ft_strdup(""));
return (ft_utoa_base(nbr, "0123456789abcdef"));
}
static int handle_padding_and_prefix(
t_vector *vec,
t_arglist *arglist,
size_t size,
unsigned int nbr)
{
if (arglist->flag_hashtag && arglist->flag_zero && nbr != 0)
{
if (!ft_vector_concat(vec, "0x", 2))
return (0);
}
if (((int)size < arglist->precision) && (arglist->precision >= 0))
{
if (padding_if_needed_before(arglist, 'x', arglist->precision
+ (arglist->flag_hashtag * 2 * (nbr != 0)), vec) < 0)
return (0);
if (!handle_hashtag_prefix(vec, arglist, nbr, arglist->flag_zero))
return (0);
}
else
{
if (arglist->flag_hashtag && nbr != 0)
size += 2;
if (padding_if_needed_before(arglist, 'x', size, vec) < 0)
return (0);
if (!handle_hashtag_prefix(vec, arglist, nbr, arglist->flag_zero))
return (0);
}
return (1);
}
int ft_case_x_bonus(t_vector *vec, va_list *args, t_arglist *arglist)
{
char *str_to_cat;
size_t size;
unsigned int nbr;
nbr = va_arg(*args, unsigned int);
str_to_cat = init_str_to_cat(arglist, nbr);
if (!str_to_cat)
return (0);
size = ft_strlen(str_to_cat);
if (!handle_padding_and_prefix(vec, arglist, size, nbr))
return (free(str_to_cat), 0);
if (((int)size < arglist->precision) && (arglist->precision >= 0))
{
if (!apply_precision_padding(vec, &size, arglist->precision))
return (free(str_to_cat), 0);
}
if (!ft_vector_concat(vec, str_to_cat, ft_strlen(str_to_cat)))
return (free(str_to_cat), 0);
free(str_to_cat);
if (padding_if_needed_after(arglist, 'x', size, vec) < 0)
return (0);
return (1);
}

Binary file not shown.

View file

@ -0,0 +1,70 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_case_p_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: thrieg <thrieg@student.42mulhouse.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/23 16:22:40 by thrieg #+# #+# */
/* Updated: 2025/02/16 19:07:47 by thrieg ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
#include "ft_printf.h"
#include "ft_printf_bonus.h"
int padding_if_needed_before(
t_arglist *arglist,
char caller,
size_t len,
t_vector *vec);
int padding_if_needed_after(
t_arglist *arglist,
char caller,
size_t len,
t_vector *vec);
//zero and precision flags have undefined behavior here
int ft_case_p_bonus_utils(t_vector *vec, char *str_to_cat, t_arglist *arglist)
{
size_t index;
size_t size;
index = ft_strnonchr(str_to_cat, '0');
size = ft_strlen(str_to_cat + index);
if (padding_if_needed_before(arglist, 'p', (size + 2), vec) < 0)
return (0);
if (!ft_vector_concat(vec, "0x", 2))
return (0);
if (!ft_vector_concat(vec, (str_to_cat + index), size))
return (0);
if (padding_if_needed_after(arglist, 'p', (size + 2), vec) < 0)
return (0);
return (1);
}
//zero and precision flags have undefined behavior here
int ft_case_p_bonus(t_vector *vec, va_list *args, t_arglist *arglist)
{
char *str_to_cat;
void *arg;
int ret;
arg = va_arg(*args, void *);
if (!arg)
{
if (padding_if_needed_before(arglist, 'p', 5, vec) < 0)
return (0);
if (!ft_vector_concat(vec, "(nil)", 5))
return (0);
if (padding_if_needed_after(arglist, 'p', 5, vec) < 0)
return (0);
return (1);
}
str_to_cat = ft_addr_to_strhex(arg);
if (!str_to_cat)
return (0);
ret = ft_case_p_bonus_utils(vec, str_to_cat, arglist);
return (free(str_to_cat), ret);
}

Binary file not shown.

View file

@ -0,0 +1,64 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_case_s_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: thrieg <thrieg@student.42mulhouse.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/25 17:03:40 by thrieg #+# #+# */
/* Updated: 2025/02/16 19:07:48 by thrieg ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
#include "ft_printf.h"
#include "ft_printf_bonus.h"
int padding_if_needed_before(
t_arglist *arglist,
char caller,
size_t len,
t_vector *vec);
int padding_if_needed_after(
t_arglist *arglist,
char caller,
size_t len,
t_vector *vec);
static int ft_s_sub_bonus(t_vector *vec, char *str_to_cat, t_arglist *arglist)
{
size_t size;
if (!str_to_cat)
{
size = 6;
if ((int)size > arglist->precision && (arglist->precision >= 0))
size = 0;
if (padding_if_needed_before(arglist, 's', size, vec) < 0)
return (0);
if (!ft_vector_concat(vec, "(null)", size))
return (0);
}
else
{
size = ft_strlen(str_to_cat);
if ((int)size > arglist->precision && (arglist->precision >= 0))
size = arglist->precision;
if (padding_if_needed_before(arglist, 's', size, vec) < 0)
return (0);
if (!ft_vector_concat(vec, str_to_cat, size))
return (0);
}
if (padding_if_needed_after(arglist, 's', size, vec) < 0)
return (0);
return (1);
}
//flag 0 has undefined behavior with c so the minimum width has to be spaces
int ft_case_s_bonus(t_vector *vec, va_list *args, t_arglist *arglist)
{
char *str_to_cat;
str_to_cat = va_arg(*args, char *);
return (ft_s_sub_bonus(vec, str_to_cat, arglist));
}

Binary file not shown.

View file

@ -0,0 +1,72 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_case_u_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: thrieg <thrieg@student.42mulhouse.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/25 17:07:14 by thrieg #+# #+# */
/* Updated: 2025/02/16 19:07:49 by thrieg ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
#include "ft_printf.h"
#include "ft_printf_bonus.h"
int padding_if_needed_before(
t_arglist *arglist,
char caller,
size_t len,
t_vector *vec);
int padding_if_needed_after(
t_arglist *arglist,
char caller,
size_t len,
t_vector *vec);
static int ft_handle_padding_precision_bonus(
t_vector *vec,
size_t size,
t_arglist *arglist,
int padding_length)
{
if (padding_if_needed_before(arglist, 'u', padding_length, vec) < 0)
return (0);
while ((int)size++ < arglist->precision)
{
if (!ft_vector_pushback(vec, '0'))
return (0);
}
size--;
return (1);
}
// Plus and space flags have undefined behavior here
int ft_case_u_bonus(t_vector *vec, va_list *args, t_arglist *arglist)
{
char *str_to_cat;
int size;
unsigned int nbr;
int padding_length;
nbr = va_arg(*args, unsigned int);
if (nbr == 0 && arglist->precision == 0)
str_to_cat = ft_strdup("");
else
str_to_cat = ft_utoa(nbr);
if (!str_to_cat)
return (0);
size = (int)ft_strlen(str_to_cat);
if (size < arglist->precision)
padding_length = arglist->precision;
else
padding_length = size;
if (!ft_handle_padding_precision_bonus(vec, size, arglist, padding_length))
return (free(str_to_cat), 0);
if (!ft_vector_concat(vec, str_to_cat, size))
return (free(str_to_cat), 0);
if (padding_if_needed_after(arglist, 'u', padding_length, vec) < 0)
return (free(str_to_cat), 0);
return (free(str_to_cat), 1);
}

Binary file not shown.

View file

@ -0,0 +1,115 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_case_uppx_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: thrieg <thrieg@student.42mulhouse.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/25 17:11:07 by thrieg #+# #+# */
/* Updated: 2025/02/16 19:07:50 by thrieg ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
#include "ft_printf.h"
#include "ft_printf_bonus.h"
int padding_if_needed_before(
t_arglist *arglist,
char caller,
size_t len,
t_vector *vec);
int padding_if_needed_after(
t_arglist *arglist,
char caller,
size_t len,
t_vector *vec);
static int handle_hashtag_prefix(
t_vector *vec,
t_arglist *arglist,
unsigned int nbr,
int flag_zero)
{
if (arglist->flag_hashtag && !flag_zero && nbr != 0)
{
if (!ft_vector_concat(vec, "0X", 2))
return (0);
}
return (1);
}
static int apply_precision_padding(t_vector *vec, size_t *size, int precision)
{
while ((int)(*size)++ < precision)
{
if (!ft_vector_pushback(vec, '0'))
return (0);
}
(*size)--;
return (1);
}
static char *init_str_to_cat(t_arglist *arglist, unsigned int nbr)
{
if (nbr == 0 && arglist->precision == 0)
return (ft_strdup(""));
return (ft_utoa_base(nbr, "0123456789ABCDEF"));
}
static int handle_padding_and_prefix(
t_vector *vec,
t_arglist *arglist,
size_t size,
unsigned int nbr)
{
if (arglist->flag_hashtag && arglist->flag_zero && nbr != 0)
{
if (!ft_vector_concat(vec, "0X", 2))
return (0);
}
if (((int)size < arglist->precision) && (arglist->precision >= 0))
{
if (padding_if_needed_before(arglist, 'X', arglist->precision
+ (arglist->flag_hashtag * 2 * (nbr != 0)), vec) < 0)
return (0);
if (!handle_hashtag_prefix(vec, arglist, nbr, arglist->flag_zero))
return (0);
}
else
{
if (arglist->flag_hashtag && nbr != 0)
size += 2;
if (padding_if_needed_before(arglist, 'X', size, vec) < 0)
return (0);
if (!handle_hashtag_prefix(vec, arglist, nbr, arglist->flag_zero))
return (0);
}
return (1);
}
int ft_case_upperx_bonus(t_vector *vec, va_list *args, t_arglist *arglist)
{
char *str_to_cat;
size_t size;
unsigned int nbr;
nbr = va_arg(*args, unsigned int);
str_to_cat = init_str_to_cat(arglist, nbr);
if (!str_to_cat)
return (0);
size = ft_strlen(str_to_cat);
if (!handle_padding_and_prefix(vec, arglist, size, nbr))
return (free(str_to_cat), 0);
if (((int)size < arglist->precision) && (arglist->precision >= 0))
{
if (!apply_precision_padding(vec, &size, arglist->precision))
return (free(str_to_cat), 0);
}
if (!ft_vector_concat(vec, str_to_cat, ft_strlen(str_to_cat)))
return (free(str_to_cat), 0);
free(str_to_cat);
if (padding_if_needed_after(arglist, 'X', size, vec) < 0)
return (0);
return (1);
}

Binary file not shown.

View file

@ -0,0 +1,52 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_cases_easy_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: thrieg <thrieg@student.42mulhouse.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/23 13:03:05 by thrieg #+# #+# */
/* Updated: 2025/02/16 19:07:51 by thrieg ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
#include "ft_printf.h"
#include "ft_printf_bonus.h"
int padding_if_needed_before(
t_arglist *arglist,
char caller,
size_t len,
t_vector *vec);
int padding_if_needed_after(
t_arglist *arglist,
char caller,
size_t len,
t_vector *vec);
//flag 0 has undefined behavior with c so the minimum width has to be spaces
int ft_case_c_bonus(t_vector *vec, va_list *args, t_arglist *arglist)
{
if (padding_if_needed_before(arglist, 'c', 1, vec) < 0)
return (0);
if (!ft_vector_pushback(vec, (char)va_arg(*args, int)))
return (0);
if (padding_if_needed_after(arglist, 'c', 1, vec) < 0)
return (0);
return (1);
}
int ft_case_percent_bonus(t_vector *vec)
{
if (!ft_vector_pushback(vec, '%'))
return (0);
return (1);
}
int ft_case_d_bonus(t_vector *vec, va_list *args, t_arglist *arglist);
int ft_case_i_bonus(t_vector *vec, va_list *args, t_arglist *arglist)
{
return (ft_case_d_bonus(vec, args, arglist));
}

Binary file not shown.

View file

@ -0,0 +1,85 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_cases_mandatory_one.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: thrieg <thrieg@student.42mulhouse.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/22 18:52:37 by thrieg #+# #+# */
/* Updated: 2025/02/16 19:07:52 by thrieg ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
#include "ft_printf.h"
int ft_case_c(t_vector *vec, va_list *args)
{
if (!ft_vector_pushback(vec, (char)va_arg(*args, int)))
return (0);
return (1);
}
int ft_case_percent(t_vector *vec)
{
if (!ft_vector_pushback(vec, '%'))
return (0);
return (1);
}
int ft_case_s(t_vector *vec, va_list *args)
{
char *str_to_cat;
str_to_cat = va_arg(*args, char *);
if (!str_to_cat)
{
if (!ft_vector_concat(vec, "(null)", 6))
return (free(str_to_cat), 0);
}
else
{
str_to_cat = ft_strdup(str_to_cat);
if (!ft_vector_concat(vec, str_to_cat, ft_strlen(str_to_cat)))
return (free(str_to_cat), 0);
free(str_to_cat);
}
return (1);
}
int ft_case_p(t_vector *vec, va_list *args)
{
char *str_to_cat;
void *arg;
size_t index;
arg = va_arg(*args, void *);
if (!arg)
{
if (!ft_vector_concat(vec, "(nil)", 5))
return (0);
return (1);
}
if (!ft_vector_concat(vec, "0x", 2))
return (0);
str_to_cat = ft_addr_to_strhex(arg);
if (!str_to_cat)
return (0);
index = ft_strnonchr(str_to_cat, '0');
if (!ft_vector_concat(vec, str_to_cat + index,
ft_strlen(str_to_cat) - index))
return (free(str_to_cat), 0);
free(str_to_cat);
return (1);
}
int ft_case_u(t_vector *vec, va_list *args)
{
char *str_to_cat;
str_to_cat = ft_utoa(va_arg(*args, unsigned int));
if (!ft_vector_concat(vec, str_to_cat, ft_strlen(str_to_cat)))
return (free(str_to_cat), 0);
free(str_to_cat);
return (1);
}

Binary file not shown.

View file

@ -0,0 +1,58 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_cases_mandatory_two.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: thrieg <thrieg@student.42mulhouse.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/22 18:52:33 by thrieg #+# #+# */
/* Updated: 2025/02/16 19:07:58 by thrieg ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
#include "ft_printf.h"
int ft_case_x(t_vector *vec, va_list *args)
{
char *str_to_cat;
str_to_cat = ft_utoa_base(va_arg(*args, unsigned int), "0123456789abcdef");
if (!ft_vector_concat(vec, str_to_cat, ft_strlen(str_to_cat)))
return (free(str_to_cat), 0);
free(str_to_cat);
return (1);
}
int ft_case_upperx(t_vector *vec, va_list *args)
{
char *str_to_cat;
str_to_cat = ft_utoa_base(va_arg(*args, unsigned int), "0123456789ABCDEF");
if (!ft_vector_concat(vec, str_to_cat, ft_strlen(str_to_cat)))
return (free(str_to_cat), 0);
free(str_to_cat);
return (1);
}
int ft_case_d(t_vector *vec, va_list *args)
{
char *str_to_cat;
str_to_cat = ft_itoa(va_arg(*args, int));
if (!ft_vector_concat(vec, str_to_cat, ft_strlen(str_to_cat)))
return (free(str_to_cat), 0);
free(str_to_cat);
return (1);
}
int ft_case_i(t_vector *vec, va_list *args)
{
char *str_to_cat;
str_to_cat = ft_itoa(va_arg(*args, int));
if (!ft_vector_concat(vec, str_to_cat, ft_strlen(str_to_cat)))
return (free(str_to_cat), 0);
free(str_to_cat);
return (1);
}

Binary file not shown.

View file

@ -0,0 +1,66 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_padding_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: thrieg <thrieg@student.42mulhouse.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/27 16:54:14 by thrieg #+# #+# */
/* Updated: 2025/02/16 19:07:59 by thrieg ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
#include "ft_printf.h"
#include "ft_printf_bonus.h"
//len is the len of what's already printed
//returns the number of characters writen or -1 if an error occurs.
int padding_if_needed_before(t_arglist *arglist,
char caller,
size_t len,
t_vector *vec)
{
char padding_char;
int i;
int padding_len;
padding_len = arglist->width_mini - (int)len;
if (padding_len <= 0)
return (0);
if (arglist->flag_justified_left)
return (0);
if ((arglist->flag_zero == 1) && caller != 'c' && caller != 's'
&& caller != 'p' && (arglist->precision < 0))
padding_char = '0';
else
padding_char = ' ';
i = 0;
while (i++ < padding_len)
if (!ft_vector_pushback(vec, padding_char))
return (-1);
return (padding_len);
}
//len is the len of what's already printed
//returns the number of characters writen or -1 if an error occurs.
int padding_if_needed_after(t_arglist *arglist,
char caller,
size_t len,
t_vector *vec)
{
int i;
int padding_len;
(void)caller;
padding_len = arglist->width_mini - (int)len;
if (padding_len <= 0)
return (0);
if (!(arglist->flag_justified_left))
return (0);
i = 0;
while (i++ < padding_len)
if (!ft_vector_pushback(vec, ' '))
return (-1);
return (padding_len);
}

Binary file not shown.

126
libft/ft_printf/ft_printf.c Executable file
View file

@ -0,0 +1,126 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: thrieg <thrieg@student.42mulhouse.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/21 18:24:04 by thrieg #+# #+# */
/* Updated: 2025/02/16 19:08:03 by thrieg ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
#include "ft_printf.h"
int ft_case_c(t_vector *vec, va_list *args);
int ft_case_percent(t_vector *vec);
int ft_case_s(t_vector *vec, va_list *args);
int ft_case_p(t_vector *vec, va_list *args);
int ft_case_u(t_vector *vec, va_list *args);
int ft_case_x(t_vector *vec, va_list *args);
int ft_case_upperx(t_vector *vec, va_list *args);
int ft_case_d(t_vector *vec, va_list *args);
int ft_case_i(t_vector *vec, va_list *args);
int handle_percent_bonus(const char *str, t_vector *vec, va_list *args);
//properly frees the vector and return string
void ft_cleanup(t_vector **vec, va_list *args)
{
ft_free_vector(vec);
va_end(*args);
}
//returns the number of characters to skip after the % sign
//or 0 if something goes wrong
int handle_percent(const char *str, t_vector *vec, va_list *args)
{
if (str[0] == '%' && str[1] == 'c')
return (ft_case_c(vec, args));
if (str[0] == '%' && str[1] == '%')
return (ft_case_percent(vec));
if (str[0] == '%' && str[1] == 's')
return (ft_case_s(vec, args));
if (str[0] == '%' && str[1] == 'p')
return (ft_case_p(vec, args));
if (str[0] == '%' && str[1] == 'u')
return (ft_case_u(vec, args));
if (str[0] == '%' && str[1] == 'x')
return (ft_case_x(vec, args));
if (str[0] == '%' && str[1] == 'X')
return (ft_case_upperx(vec, args));
if (str[0] == '%' && (str[1] == 'd'))
return (ft_case_d(vec, args));
if (str[0] == '%' && (str[1] == 'i'))
return (ft_case_i(vec, args));
return (handle_percent_bonus(str, vec, args));
}
static int ft_parsing_loop(
t_vector *return_vector,
const char *str,
va_list *args
)
{
char *next_percent;
int nb_character;
while (*str)
{
next_percent = ft_strchr(str, '%');
if (!next_percent)
{
next_percent = ft_strchr(str, '\0');
if (!ft_vector_concat(return_vector, str, (next_percent - str)))
return (0);
return (1);
}
if (!ft_vector_concat(return_vector, str, (next_percent - str)))
return (0);
str = next_percent;
nb_character = handle_percent(str, return_vector, args);
if (!nb_character)
return (0);
str += nb_character;
str++;
}
return (1);
}
//returns the number of characters written or -1 on errors
int ft_printf(const char *str, ...)
{
int nb_character;
t_vector *return_vector;
va_list args;
if (!str)
return (-1);
va_start(args, str);
return_vector = ft_create_vector(2);
if (!return_vector)
return (-1);
if (!ft_parsing_loop(return_vector, str, &args))
return (ft_cleanup(&return_vector, &args), -1);
nb_character = write(1, return_vector->buffer, return_vector->index);
return (ft_cleanup(&return_vector, &args), nb_character);
}
//returns the number of characters written or -1 on errors
int ft_dprintf(int fd, const char *str, ...)
{
int nb_character;
t_vector *return_vector;
va_list args;
if (!str)
return (-1);
va_start(args, str);
return_vector = ft_create_vector(2);
if (!return_vector)
return (-1);
if (!ft_parsing_loop(return_vector, str, &args))
return (ft_cleanup(&return_vector, &args), -1);
nb_character = write(fd, return_vector->buffer, return_vector->index);
return (ft_cleanup(&return_vector, &args), nb_character);
}

22
libft/ft_printf/ft_printf.h Executable file
View file

@ -0,0 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: thrieg <thrieg@student.42mulhouse.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/14 12:38:59 by thrieg #+# #+# */
/* Updated: 2025/02/16 19:08:20 by thrieg ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef FT_PRINTF_H
# define FT_PRINTF_H
# include <stdarg.h>
# include "../ft_vector.h"
int ft_printf(const char *format, ...);
int ft_dprintf(int fd, const char *format, ...);
#endif

BIN
libft/ft_printf/ft_printf.o Normal file

Binary file not shown.

139
libft/ft_printf/ft_printf_bonus.c Executable file
View file

@ -0,0 +1,139 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: thrieg <thrieg@student.42mulhouse.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/23 12:55:41 by thrieg #+# #+# */
/* Updated: 2025/02/16 19:08:00 by thrieg ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
#include "ft_printf.h"
#include "ft_printf_bonus.h"
int ft_case_c_bonus(t_vector *vec, va_list *args, t_arglist *arglist);
int ft_case_percent_bonus(t_vector *vec);
int ft_case_s_bonus(t_vector *vec, va_list *args, t_arglist *arglist);
int ft_case_p_bonus(t_vector *vec, va_list *args, t_arglist *arglist);
int ft_case_u_bonus(t_vector *vec, va_list *args, t_arglist *arglist);
int ft_case_x_bonus(t_vector *vec, va_list *args, t_arglist *arglist);
int ft_case_upperx_bonus(t_vector *vec, va_list *args, t_arglist *arglist);
int ft_case_d_bonus(t_vector *vec, va_list *args, t_arglist *arglist);
int ft_case_i_bonus(t_vector *vec, va_list *args, t_arglist *arglist);
static int ft_handle_percent_bonus_i(
const char *str,
t_vector *vec,
va_list *args,
t_arglist *arglist)
{
int offset;
offset = arglist->size_of_argument_string;
if (str[0] == 'i')
{
if (ft_case_i_bonus(vec, args, arglist))
return (free(arglist), offset);
else
return (free(arglist), 0);
}
return (free(arglist), 0);
}
static int ft_handle_percent_bonus_xd(
const char *str,
t_vector *vec,
va_list *args,
t_arglist *arglist)
{
int offset;
offset = arglist->size_of_argument_string;
if (str[0] == 'x')
{
if (ft_case_x_bonus(vec, args, arglist))
return (free(arglist), offset);
else
return (free(arglist), 0);
}
if (str[0] == 'X')
{
if (ft_case_upperx_bonus(vec, args, arglist))
return (free(arglist), offset);
else
return (free(arglist), 0);
}
if (str[0] == 'd')
{
if (ft_case_d_bonus(vec, args, arglist))
return (free(arglist), offset);
else
return (free(arglist), 0);
}
return (ft_handle_percent_bonus_i(str, vec, args, arglist));
}
static int ft_handle_percent_bonus_spu(
const char *str,
t_vector *vec,
va_list *args,
t_arglist *arglist)
{
int offset;
offset = arglist->size_of_argument_string;
if (str[0] == 's')
{
if (ft_case_s_bonus(vec, args, arglist))
return (free(arglist), offset);
else
return (free(arglist), 0);
}
if (str[0] == 'p')
{
if (ft_case_p_bonus(vec, args, arglist))
return (free(arglist), offset);
else
return (free(arglist), 0);
}
if (str[0] == 'u')
{
if (ft_case_u_bonus(vec, args, arglist))
return (free(arglist), offset);
else
return (free(arglist), 0);
}
return (ft_handle_percent_bonus_xd(str, vec, args, arglist));
}
//returns the number of characters to skip after the % sign
//or 0 if something goes wrong
int handle_percent_bonus(const char *str, t_vector *vec, va_list *args)
{
t_arglist *arglist;
int offset;
arglist = ft_create_arglist(str, args);
if (!arglist)
return (0);
offset = arglist->size_of_argument_string;
str += offset;
if (str[0] == 'c')
{
if (ft_case_c_bonus(vec, args, arglist))
return (free(arglist), offset);
else
return (free(arglist), 0);
}
if (str[0] == '%')
{
if (ft_case_percent_bonus(vec))
return (free(arglist), offset);
else
return (free(arglist), 0);
}
return (ft_handle_percent_bonus_spu(str, vec, args, arglist));
}

View file

@ -0,0 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf_bonus.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: thrieg <thrieg@student.42mulhouse.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/23 13:04:14 by thrieg #+# #+# */
/* Updated: 2025/02/16 19:08:01 by thrieg ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef FT_PRINTF_BONUS_H
# define FT_PRINTF_BONUS_H
typedef struct s_arglist
{
int width_mini;
int precision;
int flag_hashtag;
int flag_zero;
int flag_justified_left;
int flag_space;
int flag_plus;
int size_of_argument_string;
} t_arglist;
t_arglist *ft_create_arglist(const char *str, va_list *args);
#endif

Some files were not shown because too many files have changed in this diff Show more