removing the libft of rparodi

This commit is contained in:
Raphael 2024-11-08 19:37:30 +01:00
parent 0391323626
commit be6038dcc8
523 changed files with 724 additions and 3336 deletions

54
libft/include/ft_args.h Normal file
View file

@ -0,0 +1,54 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_args.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/13 23:42:28 by bgoulard #+# #+# */
/* Updated: 2024/06/24 00:01:59 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef FT_ARGS_H
# define FT_ARGS_H
/* ************************************************************************** */
/* */
/* Module: FT_ARGS */
/* Prefix: ft_arg */
/* */
/* The Module FT_ARGS provides an easy way to handle task related to the cli */
/* arguments both for manipulation and parsing. */
/* */
/* ************************************************************************** */
// Change version with -DVERSION="x.y.z-W" via Makefile
# ifndef VERSION
# define VERSION "1.0.0"
# endif
# include "ft_defs.h"
# include <sys/types.h>
# include "ft_args_types.h"
/* @file: src/ft_args/ft_arg_custom_checker.c */
void ft_arg_set_custom_checker(t_data_is custom_checker);
t_data_is ft_arg_get_custom_checker(void);
/* @file: src/ft_args/ft_setup_prog.c */
void ft_setup_prog(const char *const *av);
/// @file: src/ft_args/ft_parse_args
int ft_parse_args(const char **argv, void *usr_control_struct);
void ft_set_opt_list(const t_opt *opt_list);
const t_opt *ft_get_opt_list(void);
void ft_set_progname(const char *program_name);
const char *ft_progname(void);
void ft_set_version(const char *version);
const char *ft_progversion(void);
#endif

View file

@ -0,0 +1,146 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_args_types.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/13 23:42:58 by bgoulard #+# #+# */
/* Updated: 2024/06/23 18:25:43 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef FT_ARGS_TYPES_H
# define FT_ARGS_TYPES_H
# define ARG_MASK_ATYPE ~3
# define ARG_MASK_ANY_ARG 0x1
/*
OPT_ARG = 1,// technically the inverse of OPT_NOARG so mask it
OPT_EQSIGN = 2,// if it has an arg and not eqsign,
it will be the next arg aka space separated
OPT_OTHER = 4,// custom type, see set_custom_checker
*
*/
/// @brief Enum to define the type of the option
/// @details The type of the option is defined by the flags that are set in the
/// t_opt structure. The flags are defined in the enum e_opt_type.
/// The flags are defined as follows:
/// - OPT_ARG: The option has an argument
/// - OPT_EQSIGN: The option has an argument and the argument is separated by an
/// equal sign '=' (e.g. --option=arg). If the flag is not set, the argument is
/// considered to be in the next argument (e.g. --option arg).
/// - OPT_OTHER: The argument of the option is of another custom type (e.g. a
/// structure or an array or file with a custom extension etc.)
/// - OPT_INT: The argument of the option is an integer
/// - OPT_STRING: The argument of the option is a string
/// - OPT_BOOL: The argument of the option is a boolean (0 | 1 | true | false)
/// - OPT_FLOAT: The argument of the option is a float
/// - OPT_LONG: The argument of the option is a long
/// - OPT_DOUBLE: The argument of the option is a double
/// - OPT_ALPHANUM: The argument of the option is an alphanumeric string
/// - OPT_HEX: The argument of the option is a hexadecimal number
/// - OPT_OCT: The argument of the option is an octal number
/// @details The flags can be combined with the bitwise OR operator '|'.
/// @details The flags OPT_INT, OPT_STRING, OPT_BOOL, OPT_FLOAT, OPT_LONG,
/// OPT_DOUBLE, OPT_ALPHANUM, OPT_HEX, OPT_OCT are the standard types that can
/// be used to define the type of the argument of the option. The flag OPT_OTHER
/// is a custom type that can be used to define the type of the argument of the
/// option. The custom type can be defined by setting a custom checker with the
/// function set_custom_checker. The custom checker will be called to check the
/// argument of the option. The custom checker should return 0 if the argument
/// is valid and -1 if the argument is invalid. The custom checker should be
/// defined as follows:
/// @code
/// int custom_checker(char *arg)
/// {
/// // check the argument
/// return (0 or -1);
/// }
/// @endcode
/// @see: set_custom_checker to set a custom checker for the argument of type
/// OPT_OTHER.
/// @warning: System limitations: Currently you cannot set an option which uses
/// more than one argument. You can set an option which uses a custom type
/// (OPT_OTHER) but the custom type should be defined as a single argument.
/// @see: t_opt
/// @see: set_custom_checker
///
typedef enum e_opt_type
{
OPT_ARG = 1,
OPT_EQSIGN = 2,
OPT_OTHER = 4,
OPT_INT = 8,
OPT_STRING = 12,
OPT_BOOL = 16,
OPT_FLOAT = 20,
OPT_LONG = 24,
OPT_DOUBLE = 28,
OPT_ALPHANUM = 32,
OPT_HEX = 36,
OPT_OCT = 40,
} t_opt_type;
/// @brief Structure to define the options
/// @param opt_long_name: The long name of the option "name" (without the "--")
/// @param opt_short_name: The short name of the option 'n' (without the "-")
/// @param opt_type: The type of the option
/// @param opt_func: The function to call when the option is found casted as
/// void * and later casted depending on the flags
/// @details An example of how to use the structure:
/// @code
/// #include "ft_args.h"
/// #include "ft_args_types.h"
/// #include "ft_string.h"
/// #include <stdio.h>
///
/// typedef struct s_control {
/// int n;
/// char *name;
/// float f;
/// } t_control;
///
/// void set_n(void *control_struct, char *arg) {
/// printf("set_n\n");
/// ((t_control *)control_struct)->n = ft_atoi(arg);
/// }
/// void set_name(void *control_struct, char *arg) {
/// printf("set_name\n");
/// ((t_control *)control_struct)->name = arg;
/// }
/// void set_f(void *control_struct, char *arg) {
/// printf("set_f\n");
/// ((t_control *)control_struct)->f = ft_atof(arg);
/// }
/// int main(int argc, char **argv) {
/// t_control control;
/// t_opt opt_list[] = {
/// {"nbr", 'n', set_n, OPT_INT | OPT_EQSIGN},
/// {"name", 'a', set_name, OPT_STRING | OPT_EQSIGN},
/// {"float", 'f', set_f, OPT_FLOAT | OPT_EQSIGN},
/// {NULL, 0, NULL, 0}
/// };
///
/// ft_bzero(&control, sizeof(t_control));
/// ft_set_opt_list(opt_list);
/// ft_parse_args(argv, &control);
/// printf("n = %d\nname = %s\nf = %f\n", control.n, control.name,
/// control.f);
/// return (0);
/// }
/// @endcode
/// @details The previous code will parse the arguments and set the values of
/// the control structure according to the options found in the arguments.
/// @details the function set_n will be called when the option --nbr or -n is
/// found in the arguments, and will be casted as a void (*) (void *, char *).
///
typedef struct s_opt
{
char *long_name;
char short_name;
void *func;
t_opt_type type;
} t_opt;
#endif

101
libft/include/ft_char.h Normal file
View file

@ -0,0 +1,101 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_char.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/21 16:59:44 by bgoulard #+# #+# */
/* Updated: 2024/07/19 18:49:37 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef FT_CHAR_H
# define FT_CHAR_H
/* ************************************************************************** */
/* */
/* Module: FT_CHAR */
/* Prefix: ft_* */
/* */
/* The module ft_char - (a sub module of the module string) provides an easy */
/* way to handle task or queries related purely to chars. It was */
/* separated from module ft_string to lighten and clarify it. */
/* */
/* ************************************************************************** */
# include <stdbool.h>
/// @file: src/ft_string/ft_char/ft_isoctdigit.c
int ft_isoctdigit(int c);
/// @file: src/ft_string/ft_char/ft_ishexdigit.c
int ft_ishexdigit(int c);
/// @brief check if the char is a space character
/// @param c char to check
/// @return 1 if the char is a space character, 0 otherwise
/// @file: src/ft_string/ft_char/ft_isspace.c
int ft_isspace(int c);
/// @brief check if the char is a lower case character
/// @param c char to check
/// @return 1 if the char is a lower case character, 0 otherwise
/// @file: src/ft_string/ft_char/ft_islower.c
int ft_islower(int c);
/// @brief check if the char is an ascii character
/// @param c char to check
/// @return 1 if the char is an ascii character, 0 otherwise
/// @file: src/ft_string/ft_char/ft_isascii.c
int ft_isascii(int c);
/// @brief check if the char is an upper case character
/// @param c char to check
/// @return 1 if the char is an upper case character, 0 otherwise
/// @file: src/ft_string/ft_char/ft_isupper.c
int ft_isupper(int c);
/// @brief check if the char is an alphanumeric character
/// @param c char to check
/// @return 1 if the char is an alphanumeric character, 0 otherwise
/// @file: src/ft_string/ft_char/ft_isalnum.c
int ft_isalnum(int c);
/// @brief check if the char is a digit
/// @param c char to check
/// @return 1 if the char is a digit, 0 otherwise
/// @file: src/ft_string/ft_char/ft_isdigit.c
int ft_isdigit(int c);
/// @brief check if the char is a letter
/// @param c char to check
/// @return 1 if the char is a letter, 0 otherwise
/// @file: src/ft_string/ft_char/ft_isalpha.c
int ft_isalpha(int c);
/// @brief pass a char to lower case
/// @param c char to pass to lower case
/// @return the char in lower case
/// @file: src/ft_string/ft_char/ft_tolower.c
int ft_tolower(int c);
/// @brief check if the char is printable
/// @param c char to check
/// @return 1 if the char is printable, 0 otherwise
/// @file: src/ft_string/ft_char/ft_isprint.c
int ft_isprint(int c);
/// @brief print the char on the specified file descriptor
/// @param c char to print
/// @param fd file descriptor to print on
/// @return 1 if the char was printed, -1 otherwise
int ft_putchar_fd(char c, int fd);
/// @brief pass a char to lower case
/// @param c char to pass to lower case
/// @return the char in lower case
/// @file: src/ft_string/ft_char/ft_toupper.c
int ft_toupper(int c);
#endif /* FT_CHAR_H */

42
libft/include/ft_colors.h Normal file
View file

@ -0,0 +1,42 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_colors.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/20 15:01:55 by bgoulard #+# #+# */
/* Updated: 2024/08/20 15:04:03 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef FT_COLORS_H
# define FT_COLORS_H
# define FT_C_BOLD "\033[1m"
# define FT_C_DIM "\033[2m"
# define FT_C_ITALIC "\033[3m"
# define FT_C_UNDERLINED "\033[4m"
# define FT_C_BLINK "\033[5m"
# define FT_C_BLACK "\033[30m"
# define FT_C_RED "\033[31m"
# define FT_C_GREEN "\033[32m"
# define FT_C_YELLOW "\033[33m"
# define FT_C_BLUE "\033[34m"
# define FT_C_MAGENTA "\033[35m"
# define FT_C_CYAN "\033[36m"
# define FT_C_WHITE "\033[37m"
# define FT_C_BG_BLACK "\033[40m"
# define FT_C_BG_RED "\033[41m"
# define FT_C_BG_GREEN "\033[42m"
# define FT_C_BG_YELLOW "\033[43m"
# define FT_C_BG_BLUE "\033[44m"
# define FT_C_BG_MAGENTA "\033[45m"
# define FT_C_BG_CYAN "\033[46m"
# define FT_C_BG_WHITE "\033[47m"
# define FT_C_RESET "\033[0m"
#endif

43
libft/include/ft_defs.h Normal file
View file

@ -0,0 +1,43 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_defs.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/21 14:55:34 by bgoulard #+# #+# */
/* Updated: 2024/05/27 09:00:04 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef FT_DEFS_H
# define FT_DEFS_H
# include <stdbool.h>
# include <stddef.h>
/// @brief Type of function to compare two elements
/// @param A The first element to compare
/// @param B The second element to compare
/// @return Standard cmp c function ( < 0, 0, > 0 for a < b, a == b, a > b)
typedef int (*t_data_cmp)(const void *, const void *);
/// @brief Type of function to apply on a node data
/// @param Data The data to apply the function on
/// @return Void
typedef void (*t_data_apply)(void *);
/// @brief Type of function to see if a node data is something
/// @return True if the data is what we are looking for, false otherwise
typedef bool (*t_data_is)(const void *);
/// @brief Type of function to transform a data into something else
/// @return The new data
typedef void *(*t_data_tr)(const void *);
/// @brief Type of function to transform inplace a data into some other data
/// @return pointer to the data (think of strcat or memcpy, returns a pointer
/// to dst)
typedef void *(*t_data_tr_i)(void *);
#endif /* FT_DEFS_H */

415
libft/include/ft_errno.h Normal file
View file

@ -0,0 +1,415 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_errno.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/08 14:10:11 by bgoulard #+# #+# */
/* Updated: 2024/07/08 14:24:35 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef FT_ERRNO_H
# define FT_ERRNO_H
/* ************************************************************************** */
/* */
/* Module: ft_string */
/* */
/* Prefix: */
/* */
/* Description: */
/* - This file is part of the ft_string module. Was separated for */
/* clarity. */
/* */
/* ************************************************************************** */
# define EPERM 1
// EPERM 'Operation not permitted'
# define ENOENT 2
// ENOENT 'No such file or directory'
# define ESRCH 3
// ESRCH 'No such process'
# define EINTR 4
// EINTR 'Interrupted system call'
# define EIO 5
// EIO 'I/O error'
# define ENXIO 6
// ENXIO 'No such device or address'
# define E2BIG 7
// E2BIG 'Argument list too long'
# define ENOEXEC 8
// ENOEXEC 'Exec format error'
# define EBADF 9
// EBADF 'Bad file number'
# define ECHILD 10
// ECHILD 'No child processes'
# define EAGAIN 11
// EAGAIN 'Try again'
# define ENOMEM 12
// ENOMEM 'Out of memory'
# define EACCES 13
// EACCES 'Permission denied'
# define EFAULT 14
// EFAULT 'Bad address'
# define ENOTBLK 15
// ENOTBLK 'Block device required'
# define EBUSY 16
// EBUSY 'Device or resource busy'
# define EEXIST 17
// EEXIST 'File exists'
# define EXDEV 18
// EXDEV 'Cross-device link'
# define ENODEV 19
// ENODEV 'No such device'
# define ENOTDIR 20
// ENOTDIR 'Not a directory'
# define EISDIR 21
// EISDIR 'Is a directory'
# define EINVAL 22
// EINVAL 'Invalid argument'
# define ENFILE 23
// ENFILE 'File table overflow'
# define EMFILE 24
// EMFILE 'Too many open files'
# define ENOTTY 25
// ENOTTY 'Not a typewriter'
# define ETXTBSY 26
// ETXTBSY 'Text file busy'
# define EFBIG 27
// EFBIG 'File too large'
# define ENOSPC 28
// ENOSPC 'No space left on device'
# define ESPIPE 29
// ESPIPE 'Illegal seek'
# define EROFS 30
// EROFS 'Read-only file system'
# define EMLINK 31
// EMLINK 'Too many links'
# define EPIPE 32
// EPIPE 'Broken pipe'
# define EDOM 33
// EDOM 'Math argument out of domain of func'
# define ERANGE 34
// ERANGE 'Math result not representable'
# define EDEADLK 35
// EDEADLK 'Resource deadlock would occur'
# define ENAMETOOLONG 36
// ENAMETOOLONG 'File name too long'
# define ENOLCK 37
// ENOLCK 'No record locks available'
# define ENOSYS 38
// ENOSYS 'Function not implemented'
# define ENOTEMPTY 39
// ENOTEMPTY 'Directory not empty'
# define ELOOP 40
// ELOOP 'Too many symbolic links encountered'
# define ENOMSG 42
// ENOMSG 'No message of desired type'
# define EIDRM 43
// EIDRM 'Identifier removed'
# define ECHRNG 44
// ECHRNG 'Channel number out of range'
# define EL2NSYNC 45
// EL2NSYNC 'Level 2 not synchronized'
# define EL3HLT 46
// EL3HLT 'Level 3 halted'
# define EL3RST 47
// EL3RST 'Level 3 reset'
# define ELNRNG 48
// ELNRNG 'Link number out of range'
# define EUNATCH 49
// EUNATCH 'Protocol driver not attached'
# define ENOCSI 50
// ENOCSI 'No CSI structure available'
# define EL2HLT 51
// EL2HLT 'Level 2 halted'
# define EBADE 52
// EBADE 'Invalid exchange'
# define EBADR 53
// EBADR 'Invalid request descriptor'
# define EXFULL 54
// EXFULL 'Exchange full'
# define ENOANO 55
// ENOANO 'No anode'
# define EBADRQC 56
// EBADRQC 'Invalid request code'
# define EBADSLT 57
// EBADSLT 'Invalid slot'
# define EBFONT 59
// EBFONT 'Bad font file format'
# define ENOSTR 60
// ENOSTR 'Device not a stream'
# define ENODATA 61
// ENODATA 'No data available'
# define ETIME 62
// ETIME 'Timer expired'
# define ENOSR 63
// ENOSR 'Out of streams resources'
# define ENONET 64
// ENONET 'Machine is not on the network'
# define ENOPKG 65
// ENOPKG 'Package not installed'
# define EREMOTE 66
// EREMOTE 'Object is remote'
# define ENOLINK 67
// ENOLINK 'Link has been severed'
# define EADV 68
// EADV 'Advertise error'
# define ESRMNT 69
// ESRMNT 'Srmount error'
# define ECOMM 70
// ECOMM 'Communication error on send'
# define EPROTO 71
// EPROTO 'Protocol error'
# define EMULTIHOP 72
// EMULTIHOP 'Multihop attempted'
# define EDOTDOT 73
// EDOTDOT 'RFS specific error'
# define EBADMSG 74
// EBADMSG 'Not a data message'
# define EOVERFLOW 75
// EOVERFLOW 'Value too large for defined data type'
# define ENOTUNIQ 76
// ENOTUNIQ 'Name not unique on network'
# define EBADFD 77
// EBADFD 'File descriptor in bad state'
# define EREMCHG 78
// EREMCHG 'Remote address changed'
# define ELIBACC 79
// ELIBACC 'Can not access a needed shared library'
# define ELIBBAD 80
// ELIBBAD 'Accessing a corrupted shared library'
# define ELIBSCN 81
// ELIBSCN '.lib section in a.out corrupted'
# define ELIBMAX 82
// ELIBMAX 'Attempting to link in too many shared libraries'
# define ELIBEXEC 83
// ELIBEXEC 'Cannot exec a shared library directly'
# define EILSEQ 84
// EILSEQ 'Illegal byte sequence'
# define ERESTART 85
// ERESTART 'Interrupted system call should be restarted'
# define ESTRPIPE 86
// ESTRPIPE 'Streams pipe error'
# define EUSERS 87
// EUSERS 'Too many users'
# define ENOTSOCK 88
// ENOTSOCK 'Socket operation on non-socket'
# define EDESTADDRREQ 89
// EDESTADDRREQ 'Destination address required'
# define EMSGSIZE 90
// EMSGSIZE 'Message too long'
# define EPROTOTYPE 91
// EPROTOTYPE 'Protocol wrong type for socket'
# define ENOPROTOOPT 92
// ENOPROTOOPT 'Protocol not available'
# define EPROTONOSUPPORT 93
// EPROTONOSUPPORT 'Protocol not supported'
# define ESOCKTNOSUPPORT 94
// ESOCKTNOSUPPORT 'Socket type not supported'
# define EOPNOTSUPP 95
// EOPNOTSUPP 'Operation not supported on transport endpoint'
# define EPFNOSUPPORT 96
// EPFNOSUPPORT 'Protocol family not supported'
# define EAFNOSUPPORT 97
// EAFNOSUPPORT 'Address family not supported by protocol'
# define EADDRINUSE 98
// EADDRINUSE 'Address already in use'
# define EADDRNOTAVAIL 99
// EADDRNOTAVAIL 'Cannot assign requested address'
# define ENETDOWN 100
// ENETDOWN 'Network is down'
# define ENETUNREACH 101
// ENETUNREACH 'Network is unreachable'
# define ENETRESET 102
// ENETRESET 'Network dropped connection because of reset'
# define ECONNABORTED 103
// ECONNABORTED 'Software caused connection abort'
# define ECONNRESET 104
// ECONNRESET 'Connection reset by peer'
# define ENOBUFS 105
// ENOBUFS 'No buffer space available'
# define EISCONN 106
// EISCONN 'Transport endpoint is already connected'
# define ENOTCONN 107
// ENOTCONN 'Transport endpoint is not connected'
# define ESHUTDOWN 108
// ESHUTDOWN 'Cannot send after transport endpoint shutdown'
# define ETOOMANYREFS 109
// ETOOMANYREFS 'Too many references: cannot splice'
# define ETIMEDOUT 110
// ETIMEDOUT 'Connection timed out'
# define ECONNREFUSED 111
// ECONNREFUSED 'Connection refused'
# define EHOSTDOWN 112
// EHOSTDOWN 'Host is down'
# define EHOSTUNREACH 113
// EHOSTUNREACH 'No route to host'
# define EALREADY 114
// EALREADY 'Operation already in progress'
# define EINPROGRESS 115
// EINPROGRESS 'Operation now in progress'
# define ESTALE 116
// ESTALE 'Stale NFS file handle'
# define EUCLEAN 117
// EUCLEAN 'Structure needs cleaning'
# define ENOTNAM 118
// ENOTNAM 'Not a XENIX named type file'
# define ENAVAIL 119
// ENAVAIL 'No XENIX semaphores available'
# define EISNAM 120
// EISNAM 'Is a named type file'
# define EREMOTEIO 121
// EREMOTEIO 'Remote I/O error'
# define EDQUOT 122
// EDQUOT 'Quota exceeded'
# define ENOMEDIUM 123
// ENOMEDIUM 'No medium found'
# define EMEDIUMTYPE 124
// EMEDIUMTYPE 'Wrong medium type'
# define ECANCELED 125
// ECANCELED 'Operation Canceled'
# define ENOKEY 126
// ENOKEY 'Required key not available'
# define EKEYEXPIRED 127
// EKEYEXPIRED 'Key has expired'
# define EKEYREVOKED 128
// EKEYREVOKED 'Key has been revoked'
# define EKEYREJECTED 129
// EKEYREJECTED 'Key was rejected by service'
# define EOWNERDEAD 130
// EOWNERDEAD 'Owner died'
# define ENOTRECOVERABLE 131
// ENOTRECOVERABLE 'State not recoverable'
#endif /* FT_ERRNO_H */

450
libft/include/ft_list.h Normal file
View file

@ -0,0 +1,450 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_list.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/11 11:40:02 by bgoulard #+# #+# */
/* Updated: 2024/06/24 00:04:12 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef FT_LIST_H
# define FT_LIST_H
/* ************************************************************************** */
/* */
/* Module: FT_LIST */
/* Prefix: ft_dl, ft_ll */
/* */
/* The module FT_LIST provides a way to handle task related to linked */
/* lists whether the list happens to be simply linked, doubly linked. */
/* Due to the nature of the module (handling different types of the same */
/* variety of struct the prototypes are arranged using functionality */
/* instead of type as would be common. */
/* Currently supported types: */
/* -simply_linked, */
/* -doubly_linked. */
/* */
/* ************************************************************************** */
# include "ft_list_types.h"
# include "ft_defs.h"
/* ************************************************************************** */
/* ADD */
/* ************************************************************************** */
/// @brief Add a node at the end of the list
/// @param head The head of the list
/// @param added The node to add
void ft_dl_add_back(t_dlist **head, t_dlist *const added);
/// @brief Add a node at the beginning of the list
/// @param head The head of the list
/// @param added The node to add
void ft_dl_add_front(t_dlist **head, t_dlist *const added);
/// @brief Add a node at the begining of the list
/// @param head The head of the list
/// @param added The node to add
/// @return void
void ft_ll_add_front(t_list **lst, t_list *const new_node);
/// @brief Add a node at the end of the list
/// @param head The head of the list
/// @param added The node to add
/// @return void
void ft_ll_add_back(t_list **lst, t_list *const new_node);
/* ************************************************************************** */
/* APPLY */
/* ************************************************************************** */
/// @brief Apply a function on every node of the list
/// @param start The start of the list
/// @param applied The function to apply
/// @return The number of nodes applied
size_t ft_dl_apply(const t_dlist *start, t_data_apply applied);
/// @brief Apply a function on every node of the list until the end
/// @param start The start of the list
/// @param end The end of the list
/// @param applied The function to apply
/// @return The number of nodes applied
size_t ft_dl_apply_range(const t_dlist *start, const t_dlist *end,
t_data_apply applied);
/// @brief Apply a function on every node of the list until the end
/// @param start The start of the list
/// @param end The end of the list
/// @param applied The function to apply
/// @return The number of nodes applied
size_t ft_dl_apply_range_node(const t_dlist *start, const t_dlist *end,
t_dnode_apply applied);
/// @brief Apply a function on every node of the list
/// @param lst The list
/// @param f The function to apply
/// @return void
void ft_ll_apply(const t_list *lst, t_data_apply f);
/// @brief Apply a function on every node of the list until the element end
/// @param lst The list
/// @param end The end of the list
/// @param f The function to apply
/// @return void
void ft_ll_apply_range(const t_list *lst, const t_list *end,
t_data_apply f);
/// @brief Apply a function on every node of the list until the element end
/// @param lst The list
/// @param end The end of the list
/// @param f The function to apply
/// @return void
void ft_ll_apply_range_node(const t_list *lst, const t_list *end,
t_lnode_apply f);
/* ************************************************************************** */
/* CLEAR */
/* ************************************************************************** */
/// @brief Clear a list
/// @param head The adress of head of the list to clear
/// @param del The function to delete the data
/// @return The number of nodes deleted
/// @note The head is set to NULL
size_t ft_dl_clear(t_dlist **head, t_data_apply del);
/// @brief Clear a list until the end
/// @param start The start of the list
/// @param end The end of the list
/// @param del The function to delete the data
/// @return The number of nodes deleted
size_t ft_dl_clear_range(t_dlist *start, t_dlist *end, t_data_apply del);
/// @brief Clear a list
/// @param lst The list
/// @param del The function to delete the data
/// @return void
void ft_ll_clear(t_list **lst, t_data_apply del);
// TODO: implement clear range for ll
/* ************************************************************************** */
/* CREATE & COPY */
/* ************************************************************************** */
/// @brief Create a new node
/// @param data The data of the node
/// @return The new node
t_dlist *ft_dl_create(const void *data);
/// @brief Copy a node
/// @param other The node to copy
/// @return The new node
/// @note The node is a copy of the original node but does not copy the data
/// in a new ptr
t_dlist *ft_dl_copy_node(const t_dlist *const other);
/// @brief Copy a node
/// @param other The node to copy
/// @return The new node
/// @note The node is a copy of the original node but does not copy the data
/// in a new ptr. This is wgy it doesn't need a delete function.
t_dlist *ft_dl_copy_list(const t_dlist *const other);
/// @brief Create a new node
/// @param data The data of the node
/// @return The new node
t_list *ft_ll_create(const void *const data);
/// @brief Copy a node
/// @param other The node to copy
/// @return The new node
t_list *ft_ll_copy_node(const t_list *const other);
/// @brief Copy a list
/// @param other The list to copy
/// @return The new list
t_list *ft_ll_copy_list(const t_list *const other);
/* ************************************************************************** */
/* DELETE */
/* ************************************************************************** */
/// @brief Delete a node
/// @param node The node to delete
/// @param del The function to delete the data
/// @return The number of nodes deleted
int ft_dl_delete_self(t_dlist *node, t_data_apply del);
/// @brief Delete a node
/// @param start The node from which to delete
/// @param end The node until which to delete
/// @return The number of nodes deleted
size_t ft_dl_delete_range(t_dlist *start, const t_dlist *target,
t_data_apply del);
/// @brief Delete a doubly linked list entirely
/// @param head The head of the list
/// @return The number of nodes deleted
size_t ft_dl_delete(t_dlist **head, t_data_apply del);
// TODO: implement delete dup for dl
// not currently implemented - idea of the function:
// /// @brief Delete duplicates node
// /// @param head The head of the list
// /// @param cmp The compare function
// /// @param del The function to delete the data
// /// @return The number of nodes deleted
// size_t ft_dl_delete_dup(t_dlist **src, t_data_cmp cmp,
// t_data_apply del);
/// @brief Delete a node
/// @param node The node to delete
/// @param del The function to delete the data
/// @return void
/// @note this is a useles function, it is here for compatibility with the
/// libft project.
void ft_ll_delone(t_list *lst, t_data_apply del);
/// @brief Delete a node
/// @param lst The node from which to delete
/// @param target The node until which to delete
/// @param del The function to delete the data
/// @return void
size_t ft_ll_delete_range(t_list *lst, const t_list *end, t_data_apply del);
// TODO: implement delete for ll
// delete should delete the whole list
// TODO: implement delete dup for ll
// not currently implemented - idea of the function:
// /// @brief Delete duplicates node
// /// @param head The head of the list
// /// @param cmp The compare function
// /// @param del The function to delete the data
// /// @return The number of nodes deleted
// size_t ft_listdelete_dup(t_list **src, t_data_cmp cmp,
// t_data_apply del);
/* ************************************************************************** */
/* FIND */
/* ************************************************************************** */
/// @brief Find a node in a list
/// @param head The head of the list
/// @param data The data to find
/// @param cmp The compare function
/// @return The node found or NULL
t_dlist *ft_dl_find(const t_dlist *head, const void *data, t_data_cmp cmp);
/// @brief Find a node in a list
/// @param list The list
/// @param data The data to find
/// @param cmp The compare function
/// @return The node found or NULL
void *ft_ll_find(const t_list *list, const void *data, t_data_cmp cmp);
/* ************************************************************************** */
/* GETTERS */
/* ************************************************************************** */
/// @brief Get the datas of a list
/// @param src The list
/// @return The datas of the list
/// @note The datas are in the same order as the nodes and the pointers to the
/// datas need to be freed
void **ft_dl_get_datas(const t_dlist *src);
/// @brief Get the nodes of a list
/// @param src The list
/// @return The nodes of the list
/// @note The nodes are in the same order as the datas and the pointers to the
/// nodes need to be freed
t_dlist **ft_dl_get_nodes(const t_dlist *src);
/// @brief Get the datas of a list
/// @param src The list
/// @return The datas of the list
void **ft_ll_get_datas(const t_list *src);
/// @brief Get the nodes of a list
/// @param src The list
/// @return The nodes of the list
t_list **ft_ll_get_nodes(const t_list *src);
/* ************************************************************************** */
/* ITERATORS */
/* ************************************************************************** */
/// @brief Get the last node of a list
/// @param head The head of the list
/// @param index The index of the node
/// @return The node at index or NULL
t_dlist *ft_dl_at(const t_dlist *head, size_t index);
/// @brief Get the last node of a list
/// @param head The head of the list
/// @return The last node of the list
t_dlist *ft_dl_end(const t_dlist *head);
/// @brief Get the first node of a list
/// @param head The head of the list
/// @return The first node of the list
t_dlist *ft_dl_begin(const t_dlist *head);
/// @brief Get the last node of a list
/// @param lst The list
/// @return The last node of the list
t_list *ft_ll_end(const t_list *lst);
/// @brief Get the node of a list at position index
/// @param lst The list
/// @param index The index of the node
/// @return The node at index or NULL
t_list *ft_ll_at(const t_list *lst, size_t index);
/* ************************************************************************** */
/* MAP */
/* ************************************************************************** */
/// @brief Apply a function on every node of the list
/// @param lst The list
/// @param f The function to apply
/// @param del The function to delete the data if allocation fails
/// @return The new list
t_dlist *ft_dl_map(const t_dlist *lst, t_data_tr f, t_data_apply del);
/// @brief Apply a function on every node of the list
/// @param lst The list
/// @param f The function to apply
/// @param del The function to delete the data if allocation fails
/// @return The new list
t_list *ft_ll_map(const t_list *lst, t_data_tr f, t_data_apply del);
/* ************************************************************************** */
/* NEW */
/* ************************************************************************** */
/// @brief Create a new node
/// @return The new node
t_dlist *ft_dl_new(void);
/// @brief Create a new node
/// @return The new node
t_list *ft_ll_new(void);
/* ************************************************************************** */
/* PUSH & POP */
/* ************************************************************************** */
/// @brief Push a node at the beginning of the list
/// @param node The head of the list
/// @param data The data of the node
/// @return The new head of the list
t_dlist *ft_dl_push(t_dlist **node, const void *data);
/// @brief Push a node at the end of the list
/// @param node The head of the list
/// @param data The data of the node
/// @return The new head of the list
t_dlist *ft_dl_push_back(t_dlist **node, const void *data);
/// @brief Pop a node at the beginning of the list
/// @param node The head of the list
/// @return The data of the node
void *ft_dl_pop(t_dlist **node);
/// @brief Pop a node at the end of the list
/// @param node The head of the list
/// @return The data of the node
void *ft_dl_pop_back(t_dlist **node);
/// @brief Push a node at the beginning of the list
/// @param lst The head of the list
/// @param data The data of the node
/// @return The new head of the list
t_list *ft_ll_push(t_list **lst, const void *data);
/// @brief Push a node at the end of the list
/// @param lst The head of the list
/// @param data The data of the node
/// @return The new head of the list
t_list *ft_ll_push_back(t_list **lst, const void *data);
/// @brief Pop a node at the beginning of the list
/// @param lst The head of the list
/// @return The data of the node
void *ft_ll_pop(t_list **lst);
/// @brief Pop a node at the end of the list
/// @param lst The head of the list
/// @return The data of the node
void *ft_ll_pop_back(t_list **lst);
/* ************************************************************************** */
/* REVERSE */
/* ************************************************************************** */
/// @brief Reverse a list
/// @param head The head of the list
/// @return the new head of the list
t_dlist *ft_dl_rev(t_dlist **head);
/// @brief Reverse a list
/// @param head The head of the list
/// @return the new head of the list
t_list *ft_ll_rev(t_list **head);
/* ************************************************************************** */
/* SIZE */
/* ************************************************************************** */
/// @brief Get the size of a list
/// @param head The head of the list
/// @return The size of the list
size_t ft_dl_size(const t_dlist *head);
/// @brief Get the size of a list
/// @param head The head of the list
/// @param function The function to check if the data is something
/// @return The size of the list
size_t ft_dl_size_of_data(const t_dlist *head, t_data_is function);
/// @brief Get the size of a list
/// @param lst The list
/// @return The size of the list
size_t ft_ll_size(const t_list *lst);
/// @brief Get the size of a list
/// @param lst The list
/// @param function The function to check if the data is something
/// @return The size of the list
size_t ft_ll_size_match(const t_list *lst, t_data_is function);
// todo: rename either ll_size_of_data or dl_size_match
/* ************************************************************************** */
/* SUB */
/* ************************************************************************** */
/// @brief Get a sublist of a list
/// @param src The list
/// @param to The node until which to get the sublist
/// @return The sublist
/// @note The sublist is a copy of the original list but does not copy
/// the data in a new ptr. This is why it doesn't need a delete function.
t_dlist *ft_dl_subrange(const t_dlist *src, const t_dlist *to);
/// @brief Get a sublist of a list
/// @param src The list
/// @param to The node until which to get the sublist
/// @note The sublist is a copy of the original list but does not copy
/// the data in a new ptr. This is why it doesn't need a delete function.
/// @return The sublist
t_list *ft_ll_subrange(const t_list *lst, const t_list *end);
#endif /* FT_LIST_H */

View file

@ -0,0 +1,46 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_list_types.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/07 10:37:44 by bgoulard #+# #+# */
/* Updated: 2024/05/19 17:48:07 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef FT_LIST_TYPES_H
# define FT_LIST_TYPES_H
# include <stdbool.h>
# define FTLIST_SUCCESS 0
# define FTLIST_FAILURE 1
/// @brief Structure representing a node in a list
/// @param data The data of the node
/// @param next The next node
typedef struct s_list
{
void *data;
struct s_list *next;
} t_list;
/// @brief Structure representing a node in a doubly linked list
/// @param data The data of the node
/// @param next The next node
/// @param prev The previous node
typedef struct s_dl_list
{
struct s_dl_list *next;
struct s_dl_list *prev;
void *data;
} t_dlist;
/// @brief Type of function to apply on a doubly linked list node
typedef void (*t_dnode_apply)(t_dlist *);
/// @brief Type of function to apply on a simply linked list node
typedef void (*t_lnode_apply)(t_list *);
#endif /* FT_LIST_TYPES_H */

144
libft/include/ft_map.h Normal file
View file

@ -0,0 +1,144 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_map.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/11 16:08:04 by bgoulard #+# #+# */
/* Updated: 2024/06/24 00:05:19 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef FT_MAP_H
# define FT_MAP_H
/* ************************************************************************** */
/* */
/* Module: FT_MAP */
/* Prefix: ft_map */
/* */
/* The module FT_MAP provides a way to handle hash maps and function */
/* related to hashmaps. */
/* */
/* ************************************************************************** */
# include "ft_defs.h"
# include "ft_map_types.h"
/// @brief Create a new map
/// @param capacity possible number of elements in the map
/// @return a pointer to the new map
/// @file ft_map/ft_map_create.c
t_map *ft_map_create(size_t capacity);
/// @brief Destroy a map and free the nodes
/// @param map map to destroy
/// @file ft_map/ft_map_destroy.c
/// @return void
void ft_map_destroy(t_map *map);
/// @brief Destroy a map and free the nodes and the user data in them using a
/// function passed as an argument
/// @param map map to destroy
/// @param free_data function to free the data in the map
/// @file ft_map/ft_map_destroy.c
/// @return void
void ft_map_destroy_free(t_map *map, t_data_apply free_data);
/// @brief Clears a map
/// @param map map to clear
/// @file ft_map/ft_map_clear.c
/// @return void
void ft_map_clear(t_map *map);
/// @brief Set a value in a map
/// @param map map to set the value in
/// @param key key of the value
/// @param value value to set
/// @param size size of the key
/// @file ft_map/ft_map_set.c
/// @return true if the value was set, otherwise if key creation failed false
bool ft_map_set(t_map *map, const void *key, const void *value,
size_t size);
/// @brief Set the compare function of a map
/// @param map map to set the compare function
/// @param cmp compare function newly set
/// @file ft_map/ft_map_set.c
/// @return void
void ft_map_set_cmp(t_map *map, t_data_cmp cmp);
/// @brief Set the hash function of a map
/// @param map map to set the hash function
/// @param hash hash function newly set
/// @file ft_map/ft_map_set.c
/// @return void
void ft_map_set_hash(t_map *map, t_memhash hash);
/// @brief Get a node from a map
/// @param map map to get the node from
/// @param key key of the node
/// @param size size of the key
/// @file ft_map/ft_map_get.c
t_map_node *ft_map_get_node(t_map *map, const void *key, size_t size);
/// @brief Get a value from a map
/// @param map map to get the value from
/// @param key key of the value
/// @param key_size size of the key
/// @file ft_map/ft_map_get.c
/// @return a pointer to the user data or NULL if the key is not found
void *ft_map_get(t_map *map, const void *key, size_t key_size);
/// @brief Get the number of elements in a map
/// @param map map to get the size from
/// @file ft_map/ft_map_size.c
/// @return the number of elements in the map
size_t ft_map_size(const t_map *map);
/// @brief Get the capacity of a map
/// @param map map to get the capacity from
/// @file ft_map/ft_map_get.c
/// @return the capacity of the map
size_t ft_map_capacity(const t_map *map);
/// @brief Remove a value from a map
/// @param map map to remove the value from
/// @param key key of the value
/// @param size size of the key
/// @file ft_map/ft_map_remove.c
/// @return the value removed or NULL if the key is not found
void *ft_map_remove(t_map *map, const void *key, size_t size);
/// @brief Hash a key
/// @param key key to hash
/// @param size size of the key
/// @file ft_map/ft_map_hash.c
/// @return the hash of the key
size_t ft_hash_djb2(const void *key, size_t size);
/// @brief Hash a key
/// @param key key to hash
/// @param size size of the key
/// @file ft_map/ft_map_hash.c
/// @return the hash of the key
size_t ft_hash_sdbm(const void *key, size_t size);
/// @brief Hash a key
/// @param key key to hash
/// @param size size of the key
/// @return the hash of the key
size_t ft_hash_fnv1a(const void *key, size_t size);
/// @brief Hash a key
/// @param key key to hash
/// @param size size of the key
/// @file ft_map/ft_map_hash.c
/// @return the hash of the key
/// @note this hash function is not very good, full of collisions
/// but it's very fast, easy to understand and never overflows.
/// use it ONLY for TESTing purposes
size_t ft_hash_dummy(const void *key, size_t size);
#endif /* FT_MAP_H */

View file

@ -0,0 +1,86 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_map_types.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/12 13:02:13 by bgoulard #+# #+# */
/* Updated: 2024/06/24 00:14:26 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef FT_MAP_TYPES_H
# define FT_MAP_TYPES_H
# include "ft_list_types.h"
# include "ft_defs.h"
# include "ft_vector_types.h"
# include <stdbool.h>
# include <stddef.h>
/// @brief Structure representing a node in a map
/// @param data The data of the node
/// @param key The key of the node
/// @param used Whether the node is used or not
typedef struct s_map_node
{
void *data;
const void *key;
size_t hash;
} t_map_node;
typedef size_t (*t_memhash)(const void *data, size_t data_len);
/// @brief Structure representing a map
/// @param capacity The capacity of the map
/// @param size The size of the map
/// @param nodes The nodes of the map (array of lists distributed by hash)
/// @param cmp The compare function of the map
/// @param hash The hash function of the map
/// @code
/// #include "ft_map.h"
/// #include "ft_string.h"
/// #include <stdio.h>
///
/// static void goodbye(void *data)
/// {
/// printf("Goodbye %s\n", (char *)data);
/// free(data);
/// }
///
/// int main()
/// {
/// t_map *map;
/// char *key = "key";
/// char *value = ft_strdup("value");
/// char *ptr;
///
/// map = ft_map_create(5);
///
/// ft_map_set(map, key, value, ft_strlen(key));
/// ft_map_set(map, "key2", ft_strdup("val32"), ft_strlen("key2"));
///
/// ptr = ft_map_remove(map, "key2", ft_strlen("key2"));
/// goodbye(ptr);
///
/// ft_map_set(map, "key3", ft_strdup("val3"), ft_strlen("key3"));
///
/// printf("---\n");
/// ft_map_destroy_free(map, goodbye);
/// return (0);
/// }
/// @endcode
/// @see ft_map_create
typedef struct s_map
{
size_t capacity;
size_t *weights;
size_t w_total;
t_list **nodes;
t_data_cmp cmp;
t_memhash hash;
t_vector *reserved_nodes;
} t_map;
#endif /* FT_MAP_TYPES_H */

187
libft/include/ft_math.h Normal file
View file

@ -0,0 +1,187 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_math.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/18 18:59:37 by bgoulard #+# #+# */
/* Updated: 2024/08/21 21:38:22 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef FT_MATH_H
# define FT_MATH_H
/* ************************************************************************** */
/* */
/* Module: FT_MATH */
/* Prefix: ft_* */
/* */
/* The FT_MATH module provides a way to handle task or queries related */
/* to arithmetic operations. */
/* */
/* ************************************************************************** */
# include "ft_math_types.h"
# include <stddef.h>
/// @brief Return the nearest aligned value of size on the alignment
/// @param size The size to align
/// @param alignment The alignment to use
/// @return The aligned value of size on the alignment
/// @note Optimized for power of 2 alignment
size_t ft_align_2(size_t size, size_t alignment);
/// @brief Return the nearest aligned value of size on the alignment
/// @param size The size to align
/// @param alignment The alignment to use
/// @return The aligned value of size on the alignment
/// @note See: ft_align_2 for an optimized version for power of 2
size_t ft_align(size_t size, size_t alignment);
/// @brief return the logaritm of the number in the specified base
/// @param nbr number to get the logaritm
/// @param base base of the logaritm
/// @return the logaritm of the number in the specified base. in case of error
/// return -1
int ft_llogof(long long nbr, int base);
/// @brief return the logaritm of the number in the specified base
/// @param nbr number to get the logaritm
/// @param base base of the logaritm
/// @return the logaritm of the number in the specified base. in case of error
/// return -1
int ft_ullogof(unsigned long long nbr, int base);
/// @brief return the logaritm of the number in the specified base
/// @param nbr number to get the logaritm
/// @param base base of the logaritm
/// @return the logaritm of the number in the specified base. in case of error
/// return -1
int ft_logof(int nbr, int base);
/// @brief return the logaritm of the number in the specified base
/// @param nbr number to get the logaritm
/// @param base base of the logaritm
/// @return the logaritm of the number in the specified base. in case of error
/// return -1
int ft_log(int nbr);
/// @brief returns the minimum of a and b
/// @param a first number
/// @param b second number
/// @return the smallest between a and b
int ft_min(int a, int b);
/// @brief returns the maximum of a and b
/// @param a first number
/// @param b second number
/// @return the biggest between a and b
int ft_max(int a, int b);
/// @brief Clamp a value between a minimum and a maximum
/// @param value The value to clamp
/// @param min The minimum value
/// @param max The maximum value
/// @return The clamped value between or at the minimum or maximum
/// @note This is a clamp function aka inferior and superior to min and max
/// are set to min and max
/// @file ft_clamp.c
int ft_clamp(int value, int min, int max);
/// @brief Clamp a value between a minimum and a maximum
/// @param value The value to clamp
/// @param min The minimum value
/// @param max The maximum value
/// @return The clamped value between or at the minimum or maximum
/// @note See ft_clamp.
/// @file ft_clamp.c
float ft_clamp_f(float value, float min, float max);
/// @brief Clamp a value between a minimum and a maximum
/// @param value The value to clamp
/// @param min The minimum value
/// @param max The maximum value
/// @return The clamped value between or at the minimum or maximum
/// @note See ft_clamp.
/// @file ft_clamp.c
double ft_clamp_d(double value, double min, double max);
/// @brief Take a value in a range and puts it in another range of 1 to new_max
/// @param value The value to range
/// @param min The minimum value of the range
/// @param max The maximum value of the range
/// @param new_max The maximum value of the new range
/// @return The value ranged between 1 and new_max
int ft_range(int value, int min, int max, int new_max);
/// @brief Take a value in a range and puts it in another range of 1 to new_max
/// @param value The value to range
/// @param min The minimum value of the range
/// @param max The maximum value of the range
/// @param new_max The maximum value of the new range
/// @return The value ranged between 1 and new_max
/// @note See ft_range.
float ft_range_f(float value, float min, float max, float new_max);
/// @brief Take a value in a range and puts it in another range of 1 to new_max
/// @param value The value to range
/// @param min The minimum value of the range
/// @param max The maximum value of the range
/// @param new_max The maximum value of the new range
/// @return The value ranged between 1 and new_max
/// @note See ft_range.
double ft_range_d(double value, double min, double max, double new_max);
/// @brief Return the absolute value of a
/// @param a The value to get the absolute value
/// @return The absolute value of a
int ft_abs(int a);
/// @brief Return the rounded value of x
/// @param x The value to round
/// @return The rounded value of x
/// @note This function round the value to the nearest integer
double ft_round(double x);
/// @brief Return the power of a number x to the power of y
/// @param x The number to power
/// @param y The power
/// @return The result of x to the power of y
size_t ft_pow(size_t x, size_t y);
/// @brief Return the root square of a number
/// @param nb The number to get the root square
/// @return The root square of nb
/// @note This function use the newton's method to get the root square
/// @note If nb is negative, return -1
/// @file ft_sqrt.c
double ft_sqrt(double nb);
/// @brief Return the absolute value of a
/// @param a The value to get the absolute value
/// @return The absolute value of a
/// @note See ft_abs.
double ft_complex_abs(t_complex nb);
/// @brief Add a long to a complex number
/// @param nb The complex number to add the factor
/// @param factor The factor to add to the complex number
/// @return The complex number with the factor added
/// @note See ft_complex_addl.
t_complex ft_complex_addl(t_complex nb, long factor);
/// @brief Multiply a complex number by a long
/// @param nb The complex number to multiply
/// @param factor The factor to multiply the complex number
/// @return The complex number multiplied by the factor
t_complex ft_complex_mull(t_complex nb, long factor);
/// @brief Multiply a complex number by a double
/// @param nb The complex number to multiply
/// @param factor The factor to multiply the complex number
/// @return The complex number multiplied by the factor
t_complex ft_complex_muld(t_complex nb, double factor);
#endif

View file

@ -0,0 +1,43 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_math_types.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/18 19:08:43 by bgoulard #+# #+# */
/* Updated: 2024/05/18 19:09:28 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef FT_MATH_TYPES_H
# define FT_MATH_TYPES_H
typedef struct s_complex
{
double real;
double imaginary;
} t_complex;
typedef struct s_vec2
{
double x;
double y;
} t_vec2;
typedef struct s_vec3
{
double x;
double y;
double z;
} t_vec3;
typedef struct s_vec4
{
double x;
double y;
double z;
double w;
} t_vec4;
#endif

145
libft/include/ft_optional.h Normal file
View file

@ -0,0 +1,145 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_optional.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/02 18:07:13 by bgoulard #+# #+# */
/* Updated: 2024/06/24 00:08:15 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef FT_OPTIONAL_H
# define FT_OPTIONAL_H
/* ************************************************************************** */
/* */
/* Module: FT_OPTIONAL */
/* Prefix: ft_optional */
/* */
/* The FT_OPTIONAL module provides a way to add the optional type to the */
/* project, this type is used to handle the case where a function can */
/* return a value or nothing, or to chain functions on a pointer */
/* (creating a 'pipeline' for the data to follow). */
/* */
/* ************************************************************************** */
# include "ft_defs.h"
# include "ft_optional_types.h"
# include <stdbool.h>
/// @brief Create a new empty optional
/// @return The new optional
/// @note prefer creating from stack
/// @note WARNING: you must free the optional after use
t_optional *ft_optional_new(void);
/// @brief Create a new optional with a value
/// @param ptr The value to store in the optional
/// @return The new optional
/// @note prefer creating from stack
/// @note WARNING: you must free the optional after use
t_optional *ft_optional_from_val(void *ptr);
/// @brief Copies the value of an optional into another
/// @param dest The destination optional
/// @param src The source optional
void ft_optional_copy(t_optional *dest, t_optional *src);
/// @brief Chain functions calls on an optional until either there are no more
/// functions to call or one of the functions returns NULL
/// @param opt The optional to chain
/// @param f The functions to call
/// @return true if all functions were called, false otherwise
/// @note This function was made to emulate object programming pipelines
/// @note WARNING: The function will return false if the optional is empty
/// or if the function list is NULL
/// @code
/// #include "ft_optional.h"
/// #include "ft_optional_types.h"
/// #include "ft_string.h"
/// #include "ft_defs.h"
/// #include <fcntl.h>
/// #include <stdio.h>
///
/// char *ft_fd_to_buff(int fd);
///
/// void *check_file_ext(void *filename) {
/// if (!filename)
/// return (NULL);
/// if (ft_strend_with(filename, ".txt"))
/// return (filename);
/// return (printf("Error: file must be a .txt\n"), free(filename), NULL);
/// }
///
/// void *load_file_to_buff(void *filename) {
/// int fd;
/// char *buff;
///
/// fd = open(filename, O_RDONLY);
/// if (fd < 0)
/// {
/// printf("Error: could not open file\n");
/// return (free(filename), NULL);
/// }
/// buff = ft_fd_to_buff(fd);
/// return (close(fd), free(filename), buff);
/// }
///
/// int main(int ac, char **av) {
/// t_optional opt = {OPT_NONE, NULL};
/// const t_data_tr_i function_list[] = {
/// check_file_ext,
/// load_file_to_buff,
/// NULL};
///
/// if (ac != 2)
/// return (printf("Usage: %s <file.txt>\n", av[0]), 1);
/// opt.pres = OPT_SOME;
/// opt.val = ft_strdup(av[1]);
/// if (!ft_optional_chain(&opt, function_list))
/// return (printf("Error: could not load file\n"), 1);
/// // Do something with the file
/// printf("File content: %s\n", (char *)opt.val);
/// return (free(opt.val), ft_optional_destroy(&opt), 0);
/// }
///
/// @endcode
/// @note Demonstrated above, we crate a list of operations to perform on a file
/// name, we then chain the operations on the optional until either:
/// 1) an operation returns NULL (we return false)
/// -or-
/// 2) there are no more operations to perform (we return true)
bool ft_optional_chain(t_optional *opt, const t_data_tr_i *f);
/// @brief Map a result of a function on an optional
/// @param opt The optional with the value to map
/// @param f The function to call
/// @return The new optional with the result of the functions.
/// @note WARNING: The function will return an empty optional if the result
/// of the function is NULL.
t_optional ft_optional_map(t_optional *opt, void *(**f)(void *));
/// @brief Destroy an optional
/// @param opt The optional to destroy
/// @return true if the optional was destroyed, false otherwise
/// @note WARNING: The optional must be empty before destroying it
/// otherwise the function will return false
bool ft_optional_destroy(t_optional *opt);
/// @brief Duplicate an optional
/// @param org The optional to duplicate
/// @return The new optional
/// @note prefer creating from stack
/// @note WARNING: you must free the optional after use
t_optional *ft_optional_dup(t_optional *org);
/// @brief Return the value contained in an optional
/// @param opt The optional to unwrap
/// @return The value contained in the optional
/// @note WARNING: The optional must not be empty otherwise the function will
/// crash
void *ft_optional_unwrap(t_optional opt);
#endif /* FT_OPTIONAL_H */

View file

@ -0,0 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_optional_types.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/02 18:07:23 by bgoulard #+# #+# */
/* Updated: 2024/05/19 17:47:06 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef FT_OPTIONAL_TYPES_H
# define FT_OPTIONAL_TYPES_H
# include <stddef.h>
typedef enum e_optional_type
{
OPT_NONE,
OPT_SOME,
} t_optional_type;
typedef struct s_optional
{
t_optional_type pres;
void *val;
} t_optional;
#endif /* FT_OPTIONAL_TYPES_H */

93
libft/include/ft_pair.h Normal file
View file

@ -0,0 +1,93 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_pair.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/23 22:14:08 by bgoulard #+# #+# */
/* Updated: 2024/07/06 17:12:22 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef FT_PAIR_H
# define FT_PAIR_H
/* ************************************************************************** */
/* */
/* Module: FT_PAIR */
/* Prefix: ft_pair */
/* */
/* This module provide a pair structure and a simple way to interact with it. */
/* */
/* ************************************************************************** */
# include "ft_defs.h"
# include "ft_pair_types.h"
/// @brief Create a new pair
/// @param first The first element of the pair
/// @param second The second element of the pair
/// @return The new pair allocated
/// @note avoid this function if you can, use ft_pair_set instead with a
/// stack allocated pair.
/// @note Free with basic free call.
t_pair *ft_pair_new(void *first, void *second);
/// @brief Set the first and second element of the pair
/// @param pair The pointer to the pair to set
/// @param first The first element of the pair
/// @param second The second element of the pair
/// @return void
void ft_pair_set(t_pair *pair, void *first, void *second);
/// @brief Get the first element of the pair
/// @param pair The pointer to the pair
/// @return The first element of the pair
/// @note Null safe.
void *ft_pair_first(t_pair *pair);
/// @brief Get the second element of the pair
/// @param pair The pointer to the pair
/// @return The second element of the pair
/// @note Null safe.
void *ft_pair_second(t_pair *pair);
/// @brief Frees the pair
/// @param pair The pointer to the pair to free.
/// @param del_f The function to apply to the first elements of the pair before
/// freeing the pair.
/// @param del_s The function to apply to the second elements of the pair before
/// freeing the pair.
/// @note The pair pointer is set to NULL.
void ft_pair_destroy(t_pair **pair, t_data_apply del_f, t_data_apply del_s);
/// @brief Compare two pairs
/// @param pair1 The first pair to compare
/// @param pair2 The second pair to compare
/// @param cmp The comparison function to use
/// @return The result of the comparison
/// @note The comparison function should conform to the c standard,
/// aka < 0, 0 or > 0 for pair1 < pair2, pair1 == pair2 or pair1 > pair2
/// respectively.
/// @note If no comparison function is provided, the comparison will be done
/// on the pointer value.
int ft_pair_cmp(t_pair *pair1, t_pair *pair2, t_data_cmp cmp);
/// @brief Compare two pairs
/// @param pair1 The first pair to compare
/// @param pair2 The second pair to compare
/// @param cmp The comparison function to use
/// @return The result of the comparison
/// @note Same as ft_pair_cmp but compare the first element of the pair
int ft_pair_cmp_first(t_pair *pair1, t_pair *pair2, t_data_cmp cmp);
/// @brief Compare two pairs
/// @param pair1 The first pair to compare
/// @param pair2 The second pair to compare
/// @param cmp The comparison function to use
/// @return The result of the comparison
/// @note Same as ft_pair_cmp but compare the second element of the pair
int ft_pair_cmp_second(t_pair *pair1, t_pair *pair2, t_data_cmp cmp);
#endif

View file

@ -0,0 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_pair_types.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/23 22:14:56 by bgoulard #+# #+# */
/* Updated: 2024/06/23 22:15:51 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef FT_PAIR_TYPES_H
# define FT_PAIR_TYPES_H
typedef struct s_pair
{
void *first;
void *second;
} t_pair;
#endif

925
libft/include/ft_string.h Normal file
View file

@ -0,0 +1,925 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_string.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/07 23:25:27 by bgoulard #+# #+# */
/* Updated: 2024/08/21 21:42:42 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef FT_STRING_H
# define FT_STRING_H
/* ************************************************************************** */
/* */
/* Module: FT_STRING */
/* Prefix: ft_, ft_string (t_string) */
/* */
/* This module provides a usefull c function for manipulationg string and */
/* manipulating memory. It also includes the type t_string a string that */
/* caches it's malloc and allocates by chunks instead of 'JIT' in the */
/* code. */
/* */
/* ************************************************************************** */
// sys types
# include <stddef.h>
# include <stdbool.h>
// self types
# include "ft_defs.h"
# include "ft_string_types.h"
// malloc + free
# include <stdlib.h>
# include <unistd.h>
// errno
# include <errno.h>
/* ************************************************************************** */
/* ** FT_MEM SUB MODULE ** */
/* ************************************************************************** */
/// @brief apply the function f on each byte of the memory
/// @param s start of the memory
/// @param n size of the memory
/// @param f function to apply
/// @return void
/// @note the memory is modified in place
void ft_apply_2d(void **array, t_data_apply f);
/// @brief fill the memory with 0
/// @param s start of the memory
/// @param n size of the memory
/// @return void
void ft_bzero(void *s, size_t n);
/// @brief allocate memory
/// @param size size of the memory to allocate
/// @return pointer to the allocated memory otherwise NULL
void *ft_malloc(size_t size);
/// @brief allocate memory and fill it with 0
/// @param nmemb number of elements
/// @param weight size of each element
/// @return pointer to the allocated memory
void *ft_calloc(size_t nmemb, size_t weight);
/// @brief load the content of the file descriptor into a string
/// @param fd file descriptor to read from
/// @return pointer to the string otherwise NULL
/// @note You must free the returned string
char *ft_fd_to_buff(int fd);
/// @brief allocate memory and copy the content of the source memory
/// @param ptr pointer to the source memory.
/// @param sizeNew size of the destination memory
/// @param sizeOld size of the source memory
/// @return pointer to a larger chunk of allocated memory otherwise NULL
/// @note WARNING: the pointer is FREE'ed after the copy in case of success
void *ft_realloc(void *ptr, size_t sizeNew, size_t sizeOld);
/// @brief free the memory
/// @param ptr pointer to the memory to free (set to NULL after)
/// @return void
void ft_free(void **ptr);
/// @brief free the memory
/// @param arr pointer to the 2d array to free.
/// @return void
/// @note the array is not set to NULL after as memory is freed and no longer
/// valid to write to.
void ft_free_2d(void **arr);
/// @brief return the length of the 2d array
/// @param array pointer to the 2d array
/// @return the length of the 2d array
/// @note the array must be NULL terminated
size_t ft_len_2d(const void *const *array);
/// @brief search for the first occurence of c in the memory
/// @param s start of the memory
/// @param c char to search
/// @param n size of the memory
/// @return pointer to the first occurence of c in the memory otherwise NULL
void *ft_memchr(const void *s, int c, size_t n);
/// @brief compare the memory
/// @param s1 start of the first memory
/// @param s2 start of the second memory
/// @param n size of the memory to compare
/// @return 0 if the memory are identical, otherwise the difference between the
/// first different char
int ft_memcmp(const void *s1, const void *s2, size_t n);
/// @brief copy the memory
/// @param dest start of the destination memory
/// @param src start of the source memory
/// @param n size of the memory to copy
/// @return pointer to the destination memory
void *ft_memcpy(void *dest, const void *src, size_t n);
/// @brief map memory region src to new region using f
/// @param src start of the source memory
/// @param nb_e number of elements
/// @param f function to apply
/// @return pointer to the new memory or NULL
void **ft_memmap(void **src, size_t nb_e, t_data_tr f);
/// @brief copy the memory
/// @param dest start of the destination memory
/// @param src start of the source memory
/// @param n size of the memory to copy
/// @return pointer to the destination memory
void *ft_memmove(void *dest, const void *src, size_t n);
/// @brief set the memory with c
/// @param s start of the memory
/// @param c char to set
/// @param n size of the memory
/// @return pointer to the memory
void *ft_memset(void *s, int c, size_t n);
/// @brief swap the memory
/// @param a first memory
/// @param b second memory
/// @return void
void ft_swap(void **a, void **b);
/// @brief sort the memory with the cmp function by chunks of size
/// @param array pointer to the memory
/// @param nmb number of chunks
/// @param size size of each chunk
/// @param cmp comparison function
/// @return void
/// @WARNING Do not use. Not implemented fully.
void ft_qsort(void *array, size_t nmb, size_t size, t_data_cmp cmp);
/* ************************************************************************** */
/* ** FT_PUT SUB MODULE ** */
/* ************************************************************************** */
/// @brief print the string on the specified file descriptor followed by a new
/// line
/// @param s string to print
/// @param fd file descriptor to print on
/// @return void
int ft_putendl_fd(const char *s, int fd);
/// @brief print the string on the specified file descriptor
/// @param nbr string to print
/// @param fd file descriptor to print on
/// @return void
int ft_putnbr_fd(int nbr, int fd);
/// @brief print the string on the specified file descriptor
/// @param s string to print
/// @param fd file descriptor to print on
/// @return void
int ft_putstr_fd(const char *s, int fd);
/* ************************************************************************** */
/* ** FT_STR MAIN MODULE ** */
/* ************************************************************************** */
/// @brief convert the string to a float
/// @param str string to convert
/// @return the float converted from the string
double ft_atof(const char *str);
/// @brief convert the string to an int
/// @param str string to convert
/// @return the int converted from the string
int ft_atoi(const char *str);
/// @brief convert the string to an int in the specified base
/// @param str string to convert
/// @param base base of the string
/// @return the int converted from the string
int ft_atoi_base(const char *str, const char *base);
/// @brief convert a string with the int converted in ascii chars
/// @param nbr number to convert
/// @return pointer to the string.
/// @note You must free the returned string
char *ft_itoa(int nbr);
/// @brief convert the int to a string in the specified base
/// @param nbr number to convert
/// @param base base of the string to return.
/// @return pointer to the string.
/// @note You must free the returned string
char *ft_itoa_base(int nbr, const char *base);
/// @brief convert the unsigned int to a string
/// @param nbr number to convert
/// @return pointer to the string.
/// @note You must free the returned string
char *ft_utoa(unsigned int nbr);
/// @brief Return a pointer to the first occurrence of any character contained
/// in the string delims in the string str
/// @param str_init string to search into WARNING: the string is modified by
/// this function. DO NOT PASS A CONST STRING.
/// @param delims string of delimiters
/// @return a pointer to the first occurrence of any character contained in the
/// string delims in the string str otherwise NULL
char *ft_strtok(char *str_init, const char *delims);
/// @brief Split the string str with the specified delimiter
/// @param str String to split
/// @param delim Char to split the string
/// @return A pointer to the array of string
/// @note You must free the returned array of string and its content
char **ft_split(const char *str, char delim);
/// @brief Same as ft_split but with multiple delimiters
/// @param str string to split
/// @param delims delimiters to split the string
/// @return a pointer to the array of string
/// @note You must free the returned array of string and its content
char **ft_splits(const char *str, const char *delims);
/// @brief Search for the first occurence of the char c in the string str
/// @param str string to search into
/// @param c char to search
/// @return a pointer to the first occurence of c in the string str otherwise
/// NULL
/// @note The returned pointer is from str and has the same constness as str
/// it was left as non-const to align with glibc's strchr
char *ft_strchr(const char *str, int c);
/// @brief duplicate the string src into a new allocated string
/// @param strsrc string to copy from
/// @return The copy of string src
/// @note You must free the returned string
char *ft_strdup(const char *strsrc);
/// @brief Iterate over the string s and execute the function f on each char
/// @param s String to iterate over
/// @param f Function to execute on each char
/// @return void
/// @note The first parameter of the function f is the index of the char in the
/// string s.
void ft_striteri(char *s, void (*f)(unsigned int, char *));
/// @brief Add up two strings s1 and s2 and return the result
/// @param s1 String to add
/// @param s2 String to add
/// @return The result of the addition of the two strings
/// @note You must free the returned string
char *ft_strjoin(char const *s1, char const *s2);
/// @brief Add up a char c at the end of a pre-existing and allocated string
/// @param str String to append to
/// @param c Char to append
/// @return The new memory segment pointed by *str or null if re-allocation
/// failed
/// @note You must free the returned string
/// @note Do no use this method to add two string, please use strjoin instead
char *ft_strappend_c(char **str, char c);
/// @brief copy up to size - 1 characters from the NULL-terminated string src
/// to dst, NULL-terminating the result.
/// Puts the result after the characters already in dst.
/// @param dst string to copy to
/// @param src string to copy from
/// @param size maximum number of characters in destination string, including
/// the terminating null character.
/// @return returns the total length of the string they tried to create.
size_t ft_strlcat(char *dst, const char *src, size_t size);
/// @brief Copies up to size - 1 characters from the NULL-terminated string src
/// to dst, NULL-terminating the result.
/// Puts the result directly at dst.
/// @param dst string to copy to
/// @param src string to copy from
/// @param size maximum number of characters in destination string, including
/// the terminating null character.
/// @return returns the total length of the string they tried to create.
/// @note If the length of src is greater than or equal to size, the string
/// will be truncated.
size_t ft_strlcpy(char *dst, const char *src, size_t size);
/// @brief Get the length of the string str
/// @param str String to get the length of
/// @return the length of the string str
size_t ft_strlen(const char *str);
/// @brief Get the length of the string str up to the first occurence of c
/// @param str String to get the length of
/// @param c Char to search
/// @return the length of the string str up to the first c, if c is not found
/// the length of the string str
size_t ft_strclen(char *str, char c);
/// @brief Get the number of occurance of char c in string str
/// @param str String to search from
/// @param c Char to search
/// @return the number of occurance of char c in string str
size_t ft_strcnb(char *str, char c);
/// @brief Calculate the length of the starting segment of str that contain
/// char from the accept string
/// @param str String to search from
/// @param accept String of the valid char
/// @return The calculated length.
size_t ft_strspn(const char *str, const char *accept);
/// @brief Calculate the length of the starting segment of str that don't
/// contain chars from the exclude string
/// @param str String to search from
/// @param exclude String of char to exclude
/// @return The calculated length.
size_t ft_strcspn(const char *str, const char *exclude);
/// @brief Execute the function f on each char of the string s
/// @param s String to iterate over
/// @param f function to execute on each char
/// @return an allocated string with the result of the function f on each char
/// of the string s otherwise NULL
/// @note You must free the returned string
char *ft_strmapi(char const *s, char (*f)(unsigned int, char));
/// @brief Compare the two strings s1 and s2
/// @param s1 String to compare s1
/// @param s2 String to compare s2
/// @return 0 if the strings are identical, otherwise the difference between the
/// first different char (s1 - s2)
int ft_strcmp(const char *s1, const char *s2);
/// @brief Compare the two strings s1 and s2 up to n characters or until a `\0'
/// @param s1 String to compare s1
/// @param s2 String to compare s2
/// @param n number of chars to compare maximum
/// @return 0 if the strings are identical, otherwise the difference between the
/// first different char (s1 - s2)
int ft_strncmp(const char *s1, const char *s2, size_t n);
/// @brief duplicate no more than n character of the string src into a
// new allocated string
/// @param str string to copy from
/// @param n number of chars to copy
/// @return A copy of the string src
/// @note You must free the returned string
char *ft_strndup(const char *str, size_t n);
/// @brief duplicate the string src into a new allocated string
/// @param src string to copy from
/// @return A copy of the string src
/// @note You must free the returned string
char *ft_strdup(const char *src);
/// @brief search for the first occurence of the string small in the string big
/// @param big string to search into
/// @param small string to search
/// @param n minimum number of characters to search
/// @return returns a pointer to the first occurrence of the string small in the
/// string big, where not more than n characters are searched. Characters that
/// appear after a `\0' character are not searched.
/// @note The returned pointer is from str and has the same constness as str
/// it was left as non-const to align with glibc's strnstr
char *ft_strnstr(const char *big, const char *small, size_t n);
/// @brief search for the last occurence of c in the string
/// @param str string to search from
/// @param c char to search
/// @return pointer to the last occurence of c in the string otherwise NULL
/// @note The returned pointer is from str and has the same constness as str
/// it was left as non-const to align with glibc's strrchr
char *ft_strrchr(const char *str, int c);
/// @brief remove the specified chars from the string s1
/// @param s1 string to trim
/// @param set characters to remove from s1
/// @return allocated string without the specified chars otherwise NULL
/// @note You must free the returned string
char *ft_strtrim(char const *s1, char const *set);
/// @brief return a substring of the string s from the specified position
/// @param s string to get the substring
/// @param start position of the substring
/// @param len length of the substring
/// @return allocated string with the substring otherwise NULL
/// @note You must free the returned string
char *ft_substr(char const *s, unsigned int start, size_t len);
/// @brief search and replace the string to_replace in the string str
/// by the string replace_by
/// @param str String to in which the string will be searched and replaced
/// @param to_replace string to search and replace
/// @param replace_by string to replace with
/// @return the string with the modified chars otherwise NULL
/// @note to_replace and replace_by must not be NULL
/// @note You must free the returned string !
char *ft_str_replace(const char *str, const char *to_replace,
const char *replace_by);
/// @brief search if the string str ends with the string end
/// @param str string to search from
/// @param end string to search
/// @return 1 if the string str ends with the string end, 0 otherwise
int ft_strend_with(const char *str, const char *end);
/// @brief search if the string str starts with the string start
/// @param str string to search from
/// @param start string to search
/// @return 1 if the string str starts with the string start, 0 otherwise
int ft_strstart_with(const char *str, const char *start);
/// @brief replace the chars to_replace in the string by the char replace_by
/// @param str string to in which the char will be replaced
/// @param to_replace char to replace
/// @param replace_by char to replace by
/// @return A pointer to the string str
/// @note The string is modified in place
char *ft_str_replace_chr(char *str, char to_replace, char replace_by);
/// @brief Returns a pointer to the first string pointed to by args
/// @param args Pointer to a list of const char pointer
/// @param index Number of elements in Args
/// @return if index is negative or the first string of args
/// is null fails and return null otherwise return the first
/// const char pointed to by args
const char *ft_shift_args(const char **args[], int *index);
/// @brief Checks if the string str is composed only of alphabetical characters
/// @param str string to check
/// @return true if the string is composed only of alphabetical characters,
/// false otherwise
bool ft_str_isalpha(const char *str);
/// @brief Checks if the string str is composed only of alphabetical and
/// numerical characters
/// @param str string to check
/// @return true if the string is composed only of alphabetical and numerical
/// characters, false otherwise
bool ft_str_isalnum(const char *str);
/// @brief Checks if the string str is comprised of only numbers.
/// @param str string to check
/// @return true if the string is composed only of numerical characters, false
/// otherwise
/// @note This function is not the same as ft_str_isdigit, as it checks for
/// and accepts negative symbols.
bool ft_str_isnum(const char *str);
/// @brief Checks if the string str is a valid boolean value ("false" ||
/// "true" || "0" || "1")
/// @param str string to check
/// @return true if it ;atches with any of the following: "false" "0" "true" "1"
/// false otherwise
bool ft_str_isbool(const char *str);
/// @brief Checks if the string str is composed only of numerical characters
/// @param str string to check
/// @return true if the string is composed only of numerical characters, false
/// otherwise
/// @note This function is not the same as ft_str_isnum, as it does not accept
/// ANYTHING other than numerical characters.
bool ft_str_isdigit(const char *str);
/// @brief Check if the string is a float
/// @param str string to check
/// @return 1 if the string is a float, 0 otherwise
/// @file: src/ft_string/ft_char/ft_isfloat.c
bool ft_str_isfloat(const char *str);
/// @brief Check if the string is a float
/// @param str string to check
/// @return 1 if the string is a float, 0 otherwise
/// @file: src/ft_string/ft_char/ft_isdouble.c
bool ft_str_isdouble(const char *str);
/// @brief Check if the string is an int valid value
/// @param str string to check
/// @return 1 if the string is an int, 0 otherwise
/// @file: src/ft_string/ft_char/ft_isint.c
bool ft_str_isint(const char *str);
/// @brief Check if the string is a long
/// @param str string to check
/// @return 1 if the string is a number, 0 otherwise
/// @file: src/ft_string/ft_char/ft_islong.c
bool ft_str_islong(const char *str);
/// @brief check if the string is a hex character
/// @param c char to check
/// @return 1 if the char is a hex character, 0 otherwise
/// @file: src/ft_string/ft_char/ft_ishex.c
bool ft_str_ishex(const char *str);
/// @brief check if the string is an octal number
/// @param str string to check
/// @return 1 if the string is an octal number, 0 otherwise
bool ft_str_isoct(const char *str);
/// @brief Check if the string is valid using a function pointer
/// @param str string to check
/// @param f function pointer to check the string (takes a char c as int
/// and returns 0 if the char is invalid)
/// @return 1 if the string is valid, 0 otherwise
/// @file: src/ft_string/ft_char/ft_isvalid.c
bool ft_str_isvalid(const char *str, int (*f)(int));
/// @brief Return a pointer to a constant string describing the error code
/// @param errnum Error code
/// @return A pointer to a constant string describing the error code
/// @note The returned pointer can be null if errnum is out of range (0 - 133)
const char *ft_strerror(int errnum);
/// @brief Print the string s if present to STDERR followed by the error code
/// as a string
/// @param s String to print before the error code
void ft_perror(const char *s);
/* ************************************************************************** */
/* FT_GNL SUB MODULE */
/* ************************************************************************** */
/// @brief Read the next line from the file descriptor
/// @param fd file descriptor to read from
/// @return the next line from the file descriptor otherwise NULL
/// @note You must free the returned string
/// @note You can see the number of supported file descriptor in the macro
/// MAX_FD
char *get_next_line(int fd);
// printf
// missing ... todo
/* ************************************************************************** */
/* FT_STRING SUB MODULE */
/* ************************************************************************** */
/* ************************************************************************** */
/* ** ft_string_new ** */
/* ************************************************************************** */
/// @brief create a new t_string
/// @param capacity initial capacity of the string
/// @return a pointer to the new t_string
/// @note You must free the returned string with ft_string_destroy
t_string *ft_string_new(size_t capacity);
/* ************************************************************************** */
/* ** ft_string_from ** */
/* ************************************************************************** */
/// @brief create a new t_string from the string
/// @param str string to copy from
/// @return a pointer to the new t_string
/// @note You must free the returned string with ft_string_destroy
/// @note This function does NOT take ownership of the passed string.
t_string *ft_string_from(const char *str);
/// @brief create a new t_string from the string with at most n chars
/// @param str string to copy from
/// @param n number of chars to copy (including the '\0') "1234" with n = 3
/// -> "123"
/// @return a pointer to the new t_string
/// @note You must free the returned string with ft_string_destroy
t_string *ft_string_from_n(const char *str, size_t n);
/// @brief create a new t_string from the char c
/// @param c char to copy from
/// @return a pointer to the new t_string
/// @note You must free the returned string with ft_string_destroy
t_string *ft_string_from_c(char c);
/// @brief create a new t_string from the t_string str
/// @param str t_string to copy from
/// @return a pointer to the new t_string
/// @note You must free the returned string with ft_string_destroy
t_string *ft_string_from_s(const t_string *str);
/// @brief create a new t_string from the t_string str using at most n chars
/// @param str t_string to copy from
/// @param n number of chars to copy
/// @return a pointer to the new t_string created
/// @note You must free the returned string with ft_string_destroy
t_string *ft_string_from_s_n(const t_string *str, size_t n);
/* ************************************************************************** */
/* ** ft_string_put ** */
/* ************************************************************************** */
/// @brief write the string on the specified file descriptor
/// @param str t_string to write
/// @param fd file descriptor to write on
/// @return the return of write if the fd and str are valid otherwise -1
int ft_string_put(t_string *str, int fd);
/* ************************************************************************** */
/* ** ft_string_append ** */
/* ************************************************************************** */
/// @brief append the string src to the string str
/// @param str t_string to modify
/// @param src string to append
/// @return 1 if the string has been appended otherwise 0
int ft_string_append(t_string *str, const char *src);
/// @brief append at most n chars of the string src to the string str
/// @param str t_string to modify
/// @param src string to append
/// @param n number of chars to append
/// @return 1 if the string has been appended otherwise 0
int ft_string_append_n(t_string *str, const char *src, size_t n);
/// @brief append the char c to the string str
/// @param str t_string to modify
/// @param c char to append
/// @return 1 if the string has been appended otherwise 0
int ft_string_append_c(t_string *str, char c);
/// @brief append the string src to the string str
/// @param str t_string to modify
/// @param src string to append
/// @return 1 if the string has been appended otherwise 0
int ft_string_append_s(t_string *str, t_string *src);
/// @brief append at most n chars of the string src to the string str
/// @param str t_string to modify
/// @param src string to append
/// @param n number of chars to append
/// @return 1 if the string has been appended otherwise 0
int ft_string_append_s_n(t_string *str, t_string *src, size_t n);
/* ************************************************************************** */
/* ** ft_string_clear ** */
/* ************************************************************************** */
/// @brief clear the string
/// @param str t_string to clear
/// @return void
/// @note the string is not freed but the content is cleared
void ft_string_clear(t_string *str);
/* ************************************************************************** */
/* ** ft_string_destroy ** */
/* ************************************************************************** */
/// @brief free the string
/// @param str pointer to the t_string to free
/// @return void
void ft_string_destroy(t_string **str);
/* ************************************************************************** */
/* ** ft_string_insert ** */
/* ************************************************************************** */
/// @brief insert the string src in the string str at the specified position
/// @param str t_string to modify
/// @param src string to insert
/// @param pos position to insert the string
/// @return 1 if the string has been inserted otherwise 0
int ft_string_insert(t_string *str, const char *src, size_t pos);
/// @brief insert at most n chars of the string src in the string str at the
/// specified position
/// @param str t_string to modify
/// @param src string to insert
/// @param pos position to insert the string
/// @param n number of chars to insert
/// @return 1 if the string has been inserted otherwise 0
int ft_string_insert_n(t_string *str, const char *src, size_t pos, \
size_t n);
/// @brief insert the char c in the string str at the specified position
/// @param str t_string to modify
/// @param c char to insert
/// @param pos position to insert the char
/// @return 1 if the string has been inserted otherwise 0
int ft_string_insert_c(t_string *str, char c, size_t pos);
/// @brief insert the string src in the string str at the specified position
/// @param str t_string to modify
/// @param src string to insert
/// @param pos position to insert the string
/// @return 1 if the string has been inserted otherwise 0
int ft_string_insert_s(t_string *str, t_string *src, size_t pos);
/// @brief insert at most n chars of the string src in the string str at the
/// specified position
/// @param str t_string to modify
/// @param src string to insert
/// @param pos position to insert the string
/// @param n number of chars to insert
/// @return 1 if the string has been inserted otherwise 0
int ft_string_insert_s_n(t_string *str, t_string *src, size_t pos,
size_t n);
/* ************************************************************************** */
/* ** ft_string_reserve ** */
/* ************************************************************************** */
/// @brief reserve the specified capacity for the string
/// @param str t_string to modify
/// @param capacity capacity to reserve
/// @return 1 if the string has been reserved otherwise 0
int ft_string_reserve(t_string *str, size_t capacity);
/* ************************************************************************** */
/* ** ft_string_resize ** */
/* ************************************************************************** */
/// @brief resize the string to the specified size
/// @param str t_string to modify
/// @param size size to resize
/// @return 1 if the string has been resized otherwise -1
/// @note if the size is smaller than the current size, the string is truncated
int ft_string_resize(t_string *str, size_t size);
/* ************************************************************************** */
/* ** ft_string_shrink ** */
/* ************************************************************************** */
/// @brief shrink the string to the minimum size
/// @param str t_string to modify
/// @return 1 if the string has been shrinked otherwise 0
int ft_string_shrink(t_string *str);
/* ************************************************************************** */
/* ** ft_string_substr ** */
/* ************************************************************************** */
/// @brief return a substring of the string str from the specified position
/// @param str t_string to get the substring
/// @param start position of the substring
/// @param len length of the substring
/// @return allocated string with the substring otherwise NULL
/// @note You must free the returned string. use ft_string_destroy.
t_string *ft_string_substr(t_string *str, size_t start, size_t len);
/* ************************************************************************** */
/* ** ft_string_to_str ** */
/* ************************************************************************** */
/// @brief convert the t_string to a string
/// @param str t_string to convert
/// @return allocated string with the content of the t_string otherwise NULL
/// @note You must free the returned string.
/// @note The t_string is not freed or modified.
char *ft_string_to_str(t_string *str);
/* ************************************************************************** */
/* ** ft_string_trim ** */
/* ************************************************************************** */
/// @brief trim the characters ' ' from the string
/// @param str t_string to trim
/// @return void
/// @note the inner string is not freed but the content modified.
void ft_string_trim(t_string *str);
/// @brief trim the specified char from the string
/// @param str t_string to trim
/// @param c char to trim
/// @return void
/// @note the inner string is not freed but the content modified.
void ft_string_trim_chr(t_string *str, char c);
/// @brief trim the specified chars from the string
/// @param str t_string to trim
/// @param to_trim chars to trim
/// @return void
/// @note the inner string is not freed but the content modified.
void ft_string_trimstr(t_string *str, const char *to_trim);
/* ************************************************************************** */
/* ** ft_string_cmp ** */
/* ************************************************************************** */
/// @brief compare the string with the string cmp
/// @param str t_string to compare
/// @param cmp string to compare
/// @return 0 if the strings are identical, otherwise the difference between the
/// first different char (s1 - s2)
int ft_string_cmp(const t_string *str, const char *cmp);
/// @brief compare the string with the string cmp up to n chars
/// @param str t_string to compare
/// @param cmp string to compare
/// @param n number of chars to compare
/// @return 0 if the strings are identical, otherwise the difference between the
/// first different char (s1 - s2)
int ft_string_ncmp(const t_string *str, const char *cmp, size_t n);
/// @brief compare the string with the string cmp
/// @param str t_string to compare
/// @param cmp string to compare
/// @return 0 if the strings are identical, otherwise the difference between the
/// first different char (s1 - s2)
int ft_string_cmpstr(const t_string *str, const t_string *cmp);
/// @brief compare the string with the string cmp up to n chars
/// @param str t_string to compare
/// @param cmp string to compare
/// @param n number of chars to compare
/// @return 0 if the strings are identical, otherwise the difference between the
/// first different char (s1 - s2)
int ft_string_ncmpstr(const t_string *str, const t_string *cmp, size_t \
n);
/* ************************************************************************** */
/* ** ft_string_get ** */
/* ************************************************************************** */
/// @brief get the length of the string
/// @param str t_string to get the length
/// @return the length of the string
size_t ft_string_len(const t_string *str);
/// @brief get the capacity of the string
/// @param str t_string to get the capacity
/// @return the capacity of the string
size_t ft_string_cap(const t_string *str);
/// @brief get the content of the string
/// @param str t_string to get the content
/// @return the content of the string
const char *ft_string_get(const t_string *str);
/* ************************************************************************** */
/* ** ft_string_set ** */
/* ************************************************************************** */
/// @brief replace the content of the string with the new string src
/// @param str t_string to modify
/// @param src string to copy from
/// @return 1 if the string has been set otherwise 0
int ft_string_set(t_string *str, const char *src);
/// @brief replace the content of the string with at most n chars of the new
/// string src
/// @param str t_string to modify
/// @param src string to copy from
/// @param n number of chars to set (including the '\0') "1234" with n = 3
/// -> "123"
/// @return 1 if the string has been set otherwise 0
int ft_string_set_n(t_string *str, const char *src, size_t n);
/// @brief replace the content of the string with the new string src
/// @param str t_string to modify
/// @param src string to set
/// @return 1 if the string has been set otherwise 0
/// @note This function takes ownership of the string src and does no alloc.
int ft_string_set_inplace(t_string *str, char *src);
/* ************************************************************************** */
/* ** ft_string_chr ** */
/* ************************************************************************** */
/// @brief search for the first occurence of c in the string
/// @param str t_string to search from
/// @param c char to search
/// @return an offset to the first occurence of c in the string otherwise -1
ssize_t ft_string_offset(const t_string *str, char c);
/// @brief search for the last occurence of c in the string
/// @param str t_string to search from
/// @param c char to search
/// @return an offset to the last occurence of c in the string otherwise -1
ssize_t ft_string_roffset(const t_string *str, char c);
/// @brief search for the first occurence of c in the string
/// @param str t_string to search from
/// @param c char to search
/// @return a pointer to the first occurence of c in the string otherwise NULL
char *ft_string_chr(const t_string *str, char c);
/// @brief search for the last occurence of c in the string
/// @param str t_string to search from
/// @param c char to search
/// @return a pointer to the last occurence of c in the string otherwise NULL
char *ft_string_rchr(const t_string *str, char c);
/* ************************************************************************** */
/* ** ft_string_replace ** */
/* ************************************************************************** */
/// @brief search and replace the string to_replace in the string str
/// by the string replace_by
/// @param str t_string to in which the string will be searched and replaced
/// @param to_replace string to search and replace
/// @param replace_by string to replace with
/// @return 1 if the string has been replaced otherwise 0
int ft_string_replace(t_string *str, const char *to_replace,
const char *replace_by);
/// @brief search and replace the string to_replace in the string str
/// by the string replace_by
/// @param str t_string to in which the string will be searched and replaced
/// @param to_replace string to search and replace
/// @param replace_by string to replace with
/// @return 1 if the string has been replaced otherwise 0
int ft_string_replace_chr(t_string *str, char to_replace,
char replace_by);
#endif // FT_STRING_H

View file

@ -0,0 +1,60 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_string_types.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/09 16:54:48 by bgoulard #+# #+# */
/* Updated: 2024/06/02 10:19:25 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef FT_STRING_TYPES_H
# define FT_STRING_TYPES_H
# include <stddef.h>
// maximum number of file descriptors
// - get_next_line
# ifndef MAX_FD
# ifdef TEST
# define MAX_FD 5
# else
# define MAX_FD 1024
# endif
# endif
// default allocation size for t_strings
// - ft_string_new
# ifndef T_STRING_BUFF
# ifdef TEST
# define T_STRING_BUFF 5
# else
# define T_STRING_BUFF 4096
# endif
# endif
// buffer size for temporary read buffers
// - get_next_line
// - ft_fd_to_buff
# ifndef BUFFER_SIZE
# ifdef TEST
# define BUFFER_SIZE 5
# else
# define BUFFER_SIZE 4096
# endif
# endif
/// @brief Structure representing a string
/// @param str The string
/// @param length The length of the string
/// @param capacity The capacity of the string
typedef struct s_string
{
char *str;
size_t length;
size_t capacity;
} t_string;
#endif /* FT_STRING_TYPES_H */

43
libft/include/ft_types.h Normal file
View file

@ -0,0 +1,43 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_types.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/23 23:11:19 by bgoulard #+# #+# */
/* Updated: 2024/06/24 00:12:08 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef FT_TYPES_H
# define FT_TYPES_H
/* ************************************************************************** */
/* */
/* Useful in early development of projects where you might no know what you */
/* want from the ft_personal lib - otherwise if you already know what */
/* you use / are at the end of a project remove this to lighten the .h */
/* step of compilation */
/* */
/* ************************************************************************** */
// true - false
# include <stdbool.h>
// size_t - ssize_t - ptrdiff_t ... NULL
# include <stddef.h>
// int8_t - int16_t - uint32_t ... INT_MAX - INT_MIN
# include <stdint.h>
# include "ft_args_types.h"
# include "ft_list_types.h"
# include "ft_map_types.h"
# include "ft_math_types.h"
# include "ft_optional_types.h"
# include "ft_pair_types.h"
# include "ft_string_types.h"
# include "ft_vector_types.h"
#endif

218
libft/include/ft_vector.h Normal file
View file

@ -0,0 +1,218 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_vector.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/27 13:37:46 by bgoulard #+# #+# */
/* Updated: 2024/06/24 00:09:31 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef FT_VECTOR_H
# define FT_VECTOR_H
/* ************************************************************************** */
/* */
/* Module: FT_VECTOR */
/* Prefix: ft_vec_ */
/* */
/* This module provides the vector type, a way to create array that are chunk */
/* allocated and allows for easy manipulations. */
/* */
/* ************************************************************************** */
# include "ft_defs.h"
# include "ft_vector_types.h"
// ft_vector/ft_vec_add.c
/// @brief Add an element to the end of the vector
/// @param vec pointer to the vector
/// @param data data to add
/// @return true if the element was added, false otherwise
bool ft_vec_add(t_vector **vec, void *data);
// ft_vector/ft_vec_apply.c
/// @brief Apply a function to all the elements of the vector
/// @param vec pointer to the vector
/// @param func function to apply
/// @return void
void ft_vec_apply(t_vector *vec, t_data_apply func);
// ft_vector/ft_vec_at.c
/// @brief Get an element from the vector
/// @param vec pointer to the vector
/// @param n index of the element
/// @return pointer to the element
void *ft_vec_at(t_vector *vec, size_t n);
// ft_vector/ft_vec_cat.c
/// @brief Concatenate two vectors
/// @param vec_a pointer to the first vector
/// @param vec_b pointer to the second vector
/// @return true if the vectors were concatenated, false otherwise
/// @note the second vector is not modified therefore it is not cleared.
/// Be careful with double free.
bool ft_vec_cat(t_vector **vec_a, const t_vector *vec_b);
// ft_vector/ft_vec_clear.c
/// @brief Clear a vector by setting its size to 0 and all elements to NULL
/// @param vec pointer to the vector cleared
/// @return void
/// @note the data is not freed, cappacity is not changed. if you want to free
// the data / reduce the cappacity use ft_vec_clear, then ft_vec_shrink.
void ft_vec_clear(t_vector *vec);
// ft_vector/ft_vec_destroy.c
/// @brief Destroy a vector
/// @param vec pointer to the vector
/// @return true if the vector was destroyed, false otherwise
bool ft_vec_destroy(t_vector **vec);
// ft_vector/ft_vec_filter.c
/// @brief Filter a vector
/// @param vec pointer to the vector
/// @param func function to filter the vector
/// @param del function to delete the elements filtered
/// @return void
void ft_vec_filter(t_vector *vec, t_data_is func, t_data_apply del);
// ft_vector/ft_vec_get.c
/// @brief Get an element from the vector
/// @param vector vector to get the element from
/// @param key key to search for using the cmp function
/// @param cmp function to compare the elements where the first argument is the
/// key and the second is the element of the vector
/// @return pointer to the element or NULL if not found
/// @note If you want to get an element by index, use ft_vec_at
void *ft_vec_get(t_vector *vector, const void *key, t_data_cmp cmp);
// ft_vector/ft_vec_map.c
/// @brief Map a vector
/// @param vec pointer to the vector
/// @param func function to map the vector
/// @return pointer to the new vector
/// @note the new vector is allocated and must be freed
/// @note as vec is an array under the hood,
// the new vector will be a collection of adress.
/// therefore, if your function changes the value of the data,
// the new vector will be a collection of pointers to the
// data of the old vector. If you want to do that and change the
// value of the data, use ft_vec_apply instead.
t_vector *ft_vec_map(t_vector *vec, t_data_tr func);
// ft_vector/ft_vec_new.c
/// @brief Create a new vector
/// @return pointer to the new vector
t_vector *ft_vec_new(void);
// ft_vector/ft_vec_pop.c
/// @brief Pop an element from the vector's end
/// @param vec pointer to the vector
/// @return pointer to the element
void *ft_vec_pop(t_vector *vec);
/// @brief Create a new vector with a given capacity
/// @param n capacity of the new vector
/// @return pointer to the new vector
t_vector *ft_vec_from_size(size_t n);
/// @brief Create a new vector from an array
/// @param data data to add to the vector
/// @param count count of the data
/// @return pointer to the new vector
t_vector *ft_vec_from_array(void **data, size_t count);
/// @brief Create a new vector from an array and steals ownership of the array
/// @param data data to create the vector from
/// @param count count of the data array
/// @return pointer to the new vector
t_vector *ft_vec_convert_alloccarray(void **data, size_t count);
// ft_vector/ft_vec_remove.c
/// @brief Remove an element from the vector
/// @param vector vector to remove the element from
/// @param n index of the element to remove
/// @param del function to delete the elements data
void ft_vec_remove(t_vector *vector, size_t n, t_data_apply del);
/// @brief Remove an element from the vector
/// @param vector vector to remove the element from
/// @param func function to remove the element
/// @param del function to delete the elements data
/// @return void
/// @note Similar to ft_vec_filter
void ft_vec_remove_if(t_vector *vector, t_data_is func,
t_data_apply del);
// ft_vector/ft_vec_reserve.c
/// @brief Reserve a given size for the vector
/// @param vec pointer to the vector
/// @param size size to reserve
/// @return true if the vector was reserved or size is smaller
/// than the current cappacity, false otherwise
bool ft_vec_reserve(t_vector **vec, size_t size);
// ft_vector/ft_vec_reverse.c
/// @brief Reverse a vector
/// @param vector vector to reverse
/// @return void
void ft_vec_reverse(t_vector *vector);
// ft_vector/ft_vec_shift.c
/// @brief Shift a vector
/// @param vec pointer to the vector
/// @param start index to start the shift
/// @param shift number of elements to shift
/// @return void
void ft_vec_shift(t_vector *vec, size_t start, size_t shift);
// ft_vector/ft_vec_sort.c
/// @brief Sort a vector
/// @param vec pointer to the vector
/// @param cmp_f function to compare the elements
/// @return void
void ft_vec_sort(t_vector *vec, t_data_cmp cmp_f);
// ft_vector/ft_vec_shrink.c
/// @brief Shrink a vector
/// @param vec pointer to the vector
/// @return true if the vector was shrunk, false otherwise
bool ft_vec_shrink(t_vector *vec);
// ft_vector/ft_vec_swap.c
/// @brief Swap two elements of a vector
/// @param vec pointer to the vector
/// @param a index of the first element
/// @param b index of the second element
/// @return void
void ft_vec_swap(t_vector *vec, size_t a, size_t b);
// ft_vector/ft_vec_to_array.c
/// @brief Convert a vector to an array
/// @param vec pointer to the vector
/// @return pointer to the array
/// @note the array is allocated and must be freed but the vector is freed
void **ft_vec_to_array(t_vector **vec);
#endif /* FT_VECTOR_H */

View file

@ -0,0 +1,38 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_vector_types.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/11 15:13:10 by bgoulard #+# #+# */
/* Updated: 2023/12/30 13:20:43 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef FT_VECTOR_TYPES_H
# define FT_VECTOR_TYPES_H
# ifndef FT_VECTOR_BASE_LEN
# ifdef TEST
# define FT_VECTOR_BASE_LEN 5
# else
# define FT_VECTOR_BASE_LEN 4096
# endif
# endif
# include <stdbool.h>
# include <stddef.h>
/// @brief vector structure
/// @param datas array of pointers to the elements
/// @param count number of elements in the vector
/// @param cappacity number of elements that can be stored in the vector
typedef struct s_vector
{
void **datas;
size_t count;
size_t cappacity;
} t_vector;
#endif /* FT_VECTOR_TYPES_H */

View file

@ -0,0 +1,45 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* args_helper.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/31 17:47:15 by bgoulard #+# #+# */
/* Updated: 2024/06/01 12:48:21 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef ARGS_HELPER_H
# define ARGS_HELPER_H
# include "ft_args_types.h"
# include <stddef.h>
# include <sys/types.h>
// Parser opt
//
// Parse long option
ssize_t parse_long_opt(const char *str_op, const t_opt *opt_list);
// Parse short option
ssize_t parse_short_opt(const char *str_op, const t_opt *opt_list);
// Checker
//
// Check if the argument is valid
int checker_arg(t_opt_type type, const char *arg);
// Run
//
// Run the function associated with the option
int run_opt_func(const t_opt opt, void *usr_control_struct, \
const char **arg, int *i);
// Error
//
// Print error message for option
int arg_opt_err(const char *opt);
// Print error message for argument type
int arg_type_err(const t_opt opt, const char *arg);
#endif

View file

@ -0,0 +1,35 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* args_tests.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/23 22:39:19 by bgoulard #+# #+# */
/* Updated: 2024/05/31 18:33:02 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef ARGS_TESTS_H
# define ARGS_TESTS_H
/* @file: tests/ft_args/args_tests.c */
int parse_args_test(void);
int tests_args(void);
/* @file: tests/ft_args/tests_custom_checker.c */
int getset_custom_checker_test(void);
/* @file: tests/ft_args/tests_optlist.c */
int getset_opt_list_test(void);
/* @file: tests/ft_args/tests_setup_prog.c */
int tests_setup_prog(void);
/* @file: tests/ft_args/tests_version.c */
int getset_version_test(void);
/* @file: tests/ft_args/tests_progname.c */
int getset_program_name_test(void);
#endif /* ARGS_TESTS_H */

View file

@ -0,0 +1,52 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* char_tests.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/23 22:39:35 by bgoulard #+# #+# */
/* Updated: 2024/05/26 12:28:06 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef CHAR_TESTS_H
# define CHAR_TESTS_H
/* @file: tests/ft_string/ft_char/test_tolower.c */
int test_ft_tolower(void);
/* @file: tests/ft_string/ft_char/test_isalpha.c */
int test_ft_isalpha(void);
/* @file: tests/ft_string/ft_char/test_isalnum.c */
int test_ft_isalnum(void);
/* @file: tests/ft_string/ft_char/test_puchar.c */
int test_ft_putchar(void);
/* @file: tests/ft_string/ft_char/test_ishexdigit.c */
int test_ft_ishexdigit(void);
/* @file: tests/ft_string/ft_char/test_isspace.c */
int test_ft_isspace(void);
/* @file: tests/ft_string/ft_char/test_isoctdigit.c */
int test_ft_isoctdigit(void);
/* @file: tests/ft_string/ft_char/test_isprint.c */
int test_ft_isprint(void);
/* @file: tests/ft_string/ft_char/test_toupper.c */
int test_ft_toupper(void);
/* @file: tests/ft_string/ft_char/test_isascii.c */
int test_ft_isascii(void);
/* @file: tests/ft_string/ft_char/ft_char_tests.c */
int char_tests(void);
/* @file: tests/ft_string/ft_char/test_isdigit.c */
int test_ft_isdigit(void);
#endif /* CHAR_TESTS_H */

View file

@ -0,0 +1,60 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* dl_tests.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/19 16:51:11 by bgoulard #+# #+# */
/* Updated: 2024/05/19 16:52:00 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef DL_TESTS_H
# define DL_TESTS_H
int t_dl_add_front(void);
int t_dl_add_back(void);
int t_dl_apply(void);
int t_dl_apply_range(void);
int t_dl_apply_range_node(void);
int t_dl_clear(void);
int t_dl_clear_range(void);
int t_dl_create(void);
int t_dl_copy_node(void);
int t_dl_copy_list(void);
int t_dl_delete_self(void);
int t_dl_delete_range(void);
int t_dl_delete(void);
int t_dl_find(void);
int t_dl_get_datas(void);
int t_dl_get_nodes(void);
int t_dl_at(void);
int t_dl_begin(void);
int t_dl_end(void);
int t_dl_map(void);
int t_dl_new(void);
int t_dl_pop(void);
int t_dl_pop_back(void);
int t_dl_push(void);
int t_dl_push_back(void);
int t_dl_rev(void);
int t_dl_size(void);
int t_dl_size_of_data(void);
int t_dl_subrange(void);
#endif /* DL_TESTS_H */

View file

@ -0,0 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* lists_test_utils.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/19 13:30:26 by bgoulard #+# #+# */
/* Updated: 2024/05/24 11:42:59 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef LISTS_TEST_UTILS_H
# define LISTS_TEST_UTILS_H
# include "ft_list_types.h"
# include <stdbool.h>
void create_2elem_dlist(t_dlist **list, void **data1, void **data2);
void create_2elem_list(t_list **list, void **data1, void **data2);
#endif

View file

@ -0,0 +1,57 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ll_tests.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/19 16:10:07 by bgoulard #+# #+# */
/* Updated: 2024/05/19 16:11:24 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef LL_TESTS_H
# define LL_TESTS_H
int t_ll_add_front(void);
int t_ll_add_back(void);
int t_ll_apply(void);
int t_ll_apply_range(void);
int t_ll_apply_range_node(void);
int t_ll_clear(void);
int t_ll_create(void);
int t_ll_copy_node(void);
int t_ll_copy_list(void);
int t_ll_delone(void);
int t_ll_delete_range(void);
int t_ll_find(void);
int t_ll_get_datas(void);
int t_ll_get_nodes(void);
int t_ll_end(void);
int t_ll_at(void);
int t_ll_map(void);
int t_ll_new(void);
int t_ll_push(void);
int t_ll_push_back(void);
int t_ll_pop(void);
int t_ll_pop_back(void);
int t_ll_rev(void);
int t_ll_size(void);
int t_ll_size_match(void);
int t_ll_subrange(void);
#endif /* LL_TESTS_H */

View file

@ -0,0 +1,48 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* map_tests.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/19 18:23:29 by bgoulard #+# #+# */
/* Updated: 2024/05/19 18:24:01 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef MAP_TESTS_H
# define MAP_TESTS_H
// File: tests/ft_map/tests_map_cappacity.c
int test_map_capacity(void);
// File: tests/ft_map/tests_map_clear.c
int test_map_clear(void);
// File: tests/ft_map/tests_map_create.c
int test_map_create(void);
// File: tests/ft_map/tests_map_destroy.c
int test_map_destroy(void);
int test_map_destroy_free(void);
// File: tests/ft_map/tests_map_get.c
int test_map_get(void);
// File: tests/ft_map/tests_map_hash.c
int test_map_hash(void);
// File: tests/ft_map/tests_map_remove.c
int test_map_remove(void);
// File: tests/ft_map/tests_map_set.c
int test_map_set(void);
// File: tests/ft_map/tests_map_set_cmphash.c
int test_map_set_cmp(void);
int test_map_set_hash(void);
// File: tests/ft_map/tests_map_size.c
int test_map_size(void);
#endif /* MAP_TESTS_H */

View file

@ -0,0 +1,59 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* math_tests.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/23 23:17:37 by bgoulard #+# #+# */
/* Updated: 2024/06/26 20:51:22 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef MATH_TESTS_H
# define MATH_TESTS_H
/* @file: tests/ft_math/tests_complex.c */
int test_ft_complex_abs(void);
int test_ft_complex_add(void);
int test_ft_complex_addl(void);
int test_ft_complex_mull(void);
int test_ft_complex_muld(void);
/* @file: tests/ft_math/tests_log.c */
int test_ft_log(void);
int test_ft_llogof(void);
int test_ft_ullogof(void);
int test_ft_logof(void);
/* @file: tests/ft_math/tests_intrange.c */
int test_ft_range(void);
int test_ft_range_f(void);
int test_ft_range_d(void);
/* @file: tests/ft_math/tests_sqrt.c */
int test_ft_sqrt(void);
/* @file: tests/ft_math/tests_minmax.c */
int test_ft_min(void);
int test_ft_max(void);
/* @file: tests/ft_math/tests_pow.c */
int test_ft_pow(void);
/* @file: tests/ft_math/tests_round.c */
int test_ft_round(void);
/* @file: tests/ft_math/tests_clamp.c */
int test_ft_clamp(void);
int test_ft_clamp_f(void);
int test_ft_clamp_d(void);
/* @file: tests/ft_math/tests_abs.c */
int test_ft_abs(void);
/* @file: tests/ft_math/tests_align.c */
int test_ft_align_2(void);
int test_ft_align(void);
#endif

View file

@ -0,0 +1,44 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* optional_test.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/23 22:39:46 by bgoulard #+# #+# */
/* Updated: 2024/05/30 12:08:37 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef OPTIONAL_TEST_H
# define OPTIONAL_TEST_H
/* @file: tests/ft_optional/test_optional_new.c */
int test_optional_new(void);
/* @file: tests/ft_optional/test_optional_dup.c */
int test_optional_dup(void);
/* @file: tests/ft_optional/test_optional_copy.c */
int test_optional_copy(void);
/* @file: tests/ft_optional/test_optional_unwrap.c */
int test_optional_unwrap(void);
/* @file: tests/ft_optional/test_optional_from_val.c */
int test_optional_from_val(void);
/* @file: tests/ft_optional/test_optional_chain.c */
int test_optional_chain(void);
/* @file: tests/ft_optional/optional_tests.c */
void *add_4(void *val);
int tests_optional(void);
/* @file: tests/ft_optional/test_optional_map.c */
int test_optional_map(void);
/* @file: tests/ft_optional/test_optional_destroy.c */
int test_optional_destroy(void);
#endif /* INCLUDE/TESTS/OPTIONAL_TEST_H */

View file

@ -0,0 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* pair_tests.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/24 00:30:00 by bgoulard #+# #+# */
/* Updated: 2024/07/06 17:11:02 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef PAIR_TESTS_H
# define PAIR_TESTS_H
int tests_pair_destroy(void);
int test_pair_set(void);
int test_pair_new(void);
int test_pair_second(void);
int test_pair_first(void);
int test_pair_destroy(void);
int test_pair_cmp(void);
int test_pair_cmp_first(void);
int test_pair_cmp_second(void);
#endif /* PAIR_TESTS_H */

View file

@ -0,0 +1,64 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* str__mem_tests.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/25 12:26:09 by bgoulard #+# #+# */
/* Updated: 2024/05/30 12:40:33 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef STR__MEM_TESTS_H
# define STR__MEM_TESTS_H
/// @file: tests/ft_string/ft_mem/tests_apply_2d
int test_apply_2d(void);
/// @file: tests/ft_string/ft_mem/tests_bzero.c
int test_bzero(void);
/// @file: tests/ft_string/ft_mem/tests_calloc.c
int test_calloc(void);
/// @file: tests/ft_string/ft_mem/tests_fd_to_buff.c
int test_fd_to_buff(void);
/// @file: tests/ft_string/ft_mem/tests_free.c
int test_free(void);
/// @file: tests/ft_string/ft_mem/tests_free_2d.c
int test_free_2d(void);
/// @file: tests/ft_string/ft_mem/tests_len_2d.c
int test_len_2d(void);
/// @file: tests/ft_string/ft_mem/tests_memchr.c
int test_memchr(void);
/// @file: tests/ft_string/ft_mem/tests_memcmp.c
int test_memcmp(void);
/// @file: tests/ft_string/ft_mem/tests_memcpy.c
int test_memcpy(void);
/// @file: tests/ft_string/ft_mem/tests_memmap.c
int test_memmap(void);
/// @file: tests/ft_string/ft_mem/tests_memmove.c
int test_memmove(void);
/// @file: tests/ft_string/ft_mem/tests_memset.c
int test_memset(void);
/// @file: tests/ft_string/ft_mem/tests_qsort.c
int test_qsort(void);
/// @file: tests/ft_string/ft_mem/tests_realloc.c
int test_realloc(void);
/// @file: tests/ft_string/ft_mem/tests_swap.c
int test_swap(void);
#endif /* STR__MEM_TESTS_H */

View file

@ -0,0 +1,169 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* str__str_tests.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/26 11:28:40 by bgoulard #+# #+# */
/* Updated: 2024/05/30 11:42:41 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef STR__STR_TESTS_H
# define STR__STR_TESTS_H
/// @brief test_striteri
/// @file: tests/ft_string/ft_str/test_striteri.c
int test_striteri(void);
/// @brief test_utoa
/// @file: tests/ft_string/ft_str/test_utoa.c
int test_utoa(void);
/// @brief test_strdup
/// @file: tests/ft_string/ft_str/test_strdup.c
int test_strdup(void);
/// @brief test_strnstr
/// @file: tests/ft_string/ft_str/test_strnstr.c
int test_strnstr(void);
/// @brief test_strrchr
/// @file: tests/ft_string/ft_str/test_strrchr.c
int test_strrchr(void);
/// @brief test_strtrim
/// @file: tests/ft_string/ft_str/test_strtrim.c
int test_strtrim(void);
/// @brief test_atoi
/// @file: tests/ft_string/ft_str/test_atoi.c
int test_atoi(void);
/// @brief test_strlcpy
/// @file: tests/ft_string/ft_str/test_strlcpy.c
int test_strlcpy(void);
/// @brief test_shift_args
/// @file: tests/ft_string/ft_str/test_shift_args.c
int test_shift_args(void);
/// @brief str_tests
/// @file: tests/ft_string/ft_str/str_tests.c
int str_tests(void);
/// @brief test_itoa_base
/// @file: tests/ft_string/ft_str/test_itoa_base.c
int test_itoa_base(void);
/// @brief test_putendl
/// @file: tests/ft_string/ft_str/test_putendl.c
int test_putendl(void);
/// @brief test_strtok
/// @file: tests/ft_string/ft_str/test_strtok.c
int test_strtok(void);
/// @brief test_strmapi
/// @file: tests/ft_string/ft_str/test_strmapi.c
int test_strmapi(void);
/// @brief test_strndup
/// @file: tests/ft_string/ft_str/test_strndup.c
int test_strndup(void);
/// @brief test_putstr
/// @file: tests/ft_string/ft_str/test_putstr.c
int test_putstr(void);
/// @brief test_strncmp
/// @file: tests/ft_string/ft_str/test_strncmp.c
int test_strncmp(void);
/// @brief test_strlcat
/// @file: tests/ft_string/ft_str/test_strlcat.c
int test_strlcat(void);
/// @brief test_atof
/// @file: tests/ft_string/ft_str/test_atof.c
int test_atof(void);
/// @brief test_itoa
/// @file: tests/ft_string/ft_str/test_itoa.c
int test_itoa(void);
/// @brief tests_splits
/// @file: tests/ft_string/ft_str/test_splits.c
int tests_splits(void);
/// @brief test_str_replace
/// @file: tests/ft_string/ft_str/test_str_replace.c
int test_str_replace(void);
/// @brief test_atoi_base
/// @file: tests/ft_string/ft_str/test_atoi_base.c
int test_atoi_base(void);
/// @brief test_str_replace_chr
/// @file: tests/ft_string/ft_str/test_str_replace_chr.c
int test_str_replace_chr(void);
/// @brief test_putnbr
/// @file: tests/ft_string/ft_str/test_putnbr.c
int test_putnbr(void);
/// @brief test_strjoin
/// @file: tests/ft_string/ft_str/test_strjoin.c
int test_strjoin(void);
/// @brief test_strcmp
/// @file: tests/ft_string/ft_str/test_strcmp.c
int test_strcmp(void);
/// @brief test_substr
/// @file: tests/ft_string/ft_str/test_substr.c
int test_substr(void);
/// @brief test_gnl
/// @file: tests/ft_string/ft_str/test_gnl.c
int test_gnl(void);
/// @brief test_strlen
/// @file: tests/ft_string/ft_str/test_strlen.c
int test_strlen(void);
/// @brief test_split
/// @file: tests/ft_string/ft_str/test_split.c
int test_split(void);
/// @brief test_strchr
/// @file: tests/ft_string/ft_str/test_strchr.c
int test_strchr(void);
/// @brief test_str_isbool
/// @file: tests/ft_string/ft_str/test_str_isbool.c
int test_str_isbool(void);
/// @brief test_str_isalpha
/// @file: tests/ft_string/ft_str/test_str_isalpha.c
int test_str_isalpha(void);
int test_str_isdouble(void);
int test_str_isalnum(void);
int test_str_isdigit(void);
int test_str_ishex(void);
int test_str_isfloat(void);
int test_str_isint(void);
int test_str_islong(void);
int test_str_isnum(void);
int test_str_isoct(void);
int test_str_isvalid(void);
int test_strclen(void);
int test_strcnb(void);
int test_strcspn(void);
int test_strspn(void);
int test_strend_with(void);
int test_strstart_with(void);
int test_strappend_c(void);
#endif /* STR__STR_TESTS_H */

View file

@ -0,0 +1,60 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* str__t_str_test.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/25 17:42:08 by bgoulard #+# #+# */
/* Updated: 2024/05/31 13:33:22 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef STR__T_STR_TEST_H
# define STR__T_STR_TEST_H
int test_string_append_c(void);
int test_string_append_n(void);
int test_string_append_sn(void);
int test_string_append_s(void);
int test_string_append(void);
int test_string_cap(void);
int test_string_chr(void);
int test_string_clear(void);
int test_string_cmp_str(void);
int test_string_cmp(void);
int test_string_destroy(void);
int test_string_from_c(void);
int test_string_from_n(void);
int test_string_from_sn(void);
int test_string_from_s(void);
int test_string_from(void);
int test_string_get(void);
int test_string_insert_c(void);
int test_string_insert_n(void);
int test_string_insert_sn(void);
int test_string_insert_s(void);
int test_string_insert(void);
int test_string_len(void);
int test_string_ncmp_str(void);
int test_string_ncmp(void);
int test_string_new(void);
int test_string_offset(void);
int test_string_put(void);
int test_string_rchr(void);
int test_string_replace_chr(void);
int test_string_replace(void);
int test_string_reserve(void);
int test_string_resize(void);
int test_string_roffset(void);
int test_string_set_inplace(void);
int test_string_set_n(void);
int test_string_set(void);
int test_string_shrink(void);
int test_string_substr(void);
int test_string_to_str(void);
int test_string_trim_chr(void);
int test_string_trimstr(void);
int test_string_trim(void);
#endif /* STR__T_STR_TEST_H */

View file

@ -0,0 +1,47 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* tests.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/29 11:15:14 by bgoulard #+# #+# */
/* Updated: 2024/07/06 16:23:00 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef TESTS_H
# define TESTS_H
# include <fcntl.h>
# include <sys/stat.h>
# include <sys/types.h>
# include <sys/wait.h>
# include <unistd.h>
# define TESTS_FPREFIX "build/test_"
# ifndef FORK_TESTS
# define FORK_TESTS 1
# endif
typedef struct s_test
{
char *name;
int (*test)(void);
} t_test;
int run_test(const t_test *test, int *collect);
int open_test_file(char **func_to_test);
void destroy_test_file(int fd, const char *file);
int tests_args(void);
int tests_doubly_linked_list_all(void);
int tests_linked_list_all(void);
int tests_map(void);
int tests_math(void);
int tests_optional(void);
int tests_pair(void);
int tests_string(void);
int tests_vector(void);
#endif /* TESTS_H */

View file

@ -0,0 +1,24 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* tests_lambda_functions.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/24 11:41:41 by bgoulard #+# #+# */
/* Updated: 2024/05/24 14:05:47 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef TESTS_LAMBDA_FUNCTIONS_H
# define TESTS_LAMBDA_FUNCTIONS_H
# include <stdbool.h>
// File: tests/lambda_functions.h
bool is42(const void *data);
void add42(void *data);
void *add42_ret(const void *data);
int cmp_int(const void *a, const void *b);
void **creat_tb(void);
#endif

View file

@ -0,0 +1,42 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* vector_tests.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/24 11:10:06 by bgoulard #+# #+# */
/* Updated: 2024/06/02 11:33:59 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef VECTOR_TESTS_H
# define VECTOR_TESTS_H
// File: tests/ft_vector/vector_tests.c
int test_vec_add(void);
int test_vec_apply(void);
int test_vec_at(void);
int test_vec_cat(void);
int test_vec_clear(void);
int test_vec_convert_alloc_array(void);
int test_vec_destroy(void);
int test_vec_filter(void);
int test_vec_from_array(void);
int test_vec_from_size(void);
int test_vec_get(void);
int test_vec_map(void);
int test_vec_new(void);
int test_vec_pop(void);
int test_vec_remove(void);
int test_vec_remove_if(void);
int test_vec_reserve(void);
int test_vec_reverse(void);
int test_vec_shift(void);
int test_vec_shrink(void);
int test_vec_sort(void);
int test_vec_swap(void);
int test_vec_to_array(void);
int tests_vector(void);
#endif /* VECTOR_TESTS_H */