normed the stdme headers

This commit is contained in:
Maieul BOYER 2024-07-11 19:01:59 +02:00
parent 79e039c94a
commit 398dd520d0
No known key found for this signature in database
84 changed files with 297 additions and 2819 deletions

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/13 17:05:45 by maiboyer #+# #+# */
/* Updated: 2023/12/31 18:48:40 by maiboyer ### ########.fr */
/* Updated: 2024/07/11 18:56:47 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
@ -15,10 +15,10 @@
# include "me/blx/blx_key.h"
# include "me/blx/colors.h"
# include "me/vec2/vec2.h"
# include "me/blx/sprite.h"
# include "me/blx/inputs.h"
# include "me/blx/sprite.h"
# include "me/types.h"
# include "me/vec2/vec2.h"
typedef struct s_blx t_blx;
@ -65,20 +65,20 @@ typedef struct s_blx
/// @note this is the function that will be called every frame
/// @note this is an internal function, you should not call it yourself
int blx_loop_func(t_blx *ctx);
/// @brief Initialize the BLX context
/// @param func the main loop function
/// @param free_fn the free function
/// @param data the application data
/// @return
t_blx blx_initialize(t_run_function func,
t_free_function free_fn, t_blx_app data);
t_blx blx_initialize(t_run_function func, \
t_free_function free_fn, t_blx_app data);
/// @brief Draw a sprite onto the screen
/// @param app The blx context
/// @param pos The position to draw the sprite at
/// @param spr The sprite to draw
void draw_sprite(t_blx *app, t_vi2d pos,
t_sprite *spr);
void draw_sprite(t_blx *app, t_vi2d pos, t_sprite *spr);
/// @brief is the key pressed
/// @param ctx the BLX context
@ -86,14 +86,12 @@ void draw_sprite(t_blx *app, t_vi2d pos,
/// @return true if the key is pressed, false otherwise
bool is_key_pressed(t_blx *ctx, t_keysym input);
/// @brief is the key held
/// @param ctx the BLX context
/// @param input the key to check
/// @return true if the key is held, false otherwise
bool is_key_held(t_blx *ctx, t_keysym input);
/// @brief is the key released
/// @param ctx the BLX context
/// @param input the key to check

View file

@ -11,13 +11,13 @@
/* ************************************************************************** */
#ifndef CHAR_H
#define CHAR_H
# define CHAR_H
#include "me/types.h"
# include "me/types.h"
/// @brief Check if a character is alphanumeric
/// @param chr char to check
/// @return chr is a alphanumeric
/// @return chr is a alphanumeric
bool me_isalnum(char chr);
/// @brief Check if a character is alphabetic
@ -26,7 +26,7 @@ bool me_isalnum(char chr);
bool me_isalpha(char chr);
/// @brief Check if a character is a digit
/// @param chr
/// @param chr
/// @return chr is a digit
bool me_isdigit(char chr);

View file

@ -50,7 +50,6 @@ t_error str_to_i16(t_const_str str, t_u32 radix, t_i16 *out);
/// @return true if an error occured, false otherwise
t_error str_to_i8(t_const_str str, t_u32 radix, t_i8 *out);
/// @brief convert the string to a number and checks for error
/// @param str string to convert from
/// @param radix base of the number (between 2 and 36)

View file

@ -6,25 +6,25 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/19 15:12:18 by maiboyer #+# #+# */
/* Updated: 2024/07/07 17:50:18 by maiboyer ### ########.fr */
/* Updated: 2024/07/11 18:56:59 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef FS_H
#define FS_H
# define FS_H
#include "me/types.h"
#include <dirent.h>
#include <fcntl.h>
#include <stdio.h>
#include <sys/types.h>
# include "me/types.h"
# include <dirent.h>
# include <fcntl.h>
# include <stdio.h>
# include <sys/types.h>
#if (!defined(FILE_SLOT_LEN)) || FILE_SLOT_LEN < 64
# ifdef FILE_SLOT_LEN
# undef FILE_SLOT_LEN
# if (!defined(FILE_SLOT_LEN)) || FILE_SLOT_LEN < 64
# ifdef FILE_SLOT_LEN
# undef FILE_SLOT_LEN
# endif
# define FILE_SLOT_LEN 512
# endif
# define FILE_SLOT_LEN 512
#endif
/// The tag of slot, used to know what is in the slot
/// A slot can only have one type at a time
@ -33,7 +33,7 @@
/// `FD` means the slot is used by a file descriptor
/// `DIR` means the slot is used by a directory stream
/// `FILE` means the slot is used by a file stream
enum e_file_slot_kind
enum e_file_slot_kind
{
SLOT_UNUSED = 0 << 0,
SLOT_FD = 1 << 0,
@ -49,7 +49,7 @@ typedef enum e_fd_type
FD_PIPE = 1 << 1,
FD_SOCK = 1 << 2,
FD_UNKNOWN = 1 << 7,
} t_fd_type;
} t_fd_type;
/// @brief File descriptor permission
/// @note you can combine them with the `|` operator
@ -57,7 +57,7 @@ typedef enum e_fd_perm
{
FD_READ = 1 << 0,
FD_WRITE = 1 << 1,
} t_fd_perm;
} t_fd_perm;
/// @brief File open options
/// @note you can combine them with the `|` operator
@ -70,7 +70,7 @@ typedef enum e_file_open_option
FD_CLOSE_ON_EXEC = O_CLOEXEC,
FD_TRUNCATE = O_TRUNC,
FD_NON_BLOCKING = O_NONBLOCK,
} t_file_open_option;
} t_file_open_option;
/// @brief File permission
/// `O` means owner
@ -91,13 +91,12 @@ typedef enum e_file_perm
FP_UEXEC = 1 << 6,
FP_UWRITE = 1 << 7,
FP_UREAD = 1 << 8,
FP_ALL_READ = FP_UREAD | FP_GREAD | FP_OREAD,
FP_ALL_WRITE = FP_UWRITE | FP_GWRITE | FP_OWRITE,
FP_ALL_EXEC = FP_UEXEC | FP_GEXEC | FP_OEXEC,
FP_DEFAULT = FP_UWRITE | FP_ALL_READ,
FP_DEFAULT_EXEC = FP_UWRITE | FP_ALL_EXEC | FP_ALL_READ,
} t_file_perm;
} t_file_perm;
/// @brief File descriptor structure
/// name: the name of the file, NULL if unknown
@ -106,66 +105,67 @@ typedef enum e_file_perm
/// type: the type of the file descriptor
typedef struct s_fd
{
t_str name;
int fd;
t_fd_perm perms;
t_fd_type type;
} t_fd;
t_str name;
int fd;
t_fd_perm perms;
t_fd_type type;
} t_fd;
/// @brief Directory structure
/// name: the name of the directory, NULL if unknown
/// ptr: the directory stream itself
typedef struct s_dir
{
DIR *ptr;
t_str name;
} t_dir;
DIR *ptr;
t_str name;
} t_dir;
/// @brief File structure
/// name: the name of the file, NULL if unknown
/// ptr: the file stream itself
typedef struct s_file
{
FILE *ptr;
t_str name;
} t_file;
FILE *ptr;
t_str name;
} t_file;
/// @brief Union of the file slot
/// @note if you use this, you should know what you are doing
union u_file_slot {
t_fd fd;
t_dir dir;
t_file file;
union u_file_slot
{
t_fd fd;
t_dir dir;
t_file file;
};
/// @brief File slot structure
/// ty: the type of the slot
/// slot: the slot itself
/// @note you should know what you are doing if you use this
struct s_file_slot
struct s_file_slot
{
enum e_file_slot_kind ty;
union u_file_slot slot;
enum e_file_slot_kind ty;
union u_file_slot slot;
};
/// An array of file slots
/// @note you should know what you are doing if you use this
typedef struct s_fd_array
{
struct s_file_slot storage[FILE_SLOT_LEN];
} t_fd_array;
struct s_file_slot storage[FILE_SLOT_LEN];
} t_fd_array;
/// @brief A mode used to open a file
typedef t_const_str t_mode;
typedef t_const_str t_mode;
/// @brief Stat structure
/// @note this is a simple typedef because I hate the struct keyword
typedef struct stat t_stat;
typedef struct stat t_stat;
/// @brief Directory entry structure
/// @note this is a simple typedef because I hate the struct keyword and it is
/// always behind a pointer
typedef struct dirent *t_dir_entry;
typedef struct dirent *t_dir_entry;
/*_____ _ _ _______ ______ _____ _ _ _
|_ _| \ | |__ __| ____| __ \| \ | | /\ | |
@ -178,21 +178,21 @@ typedef struct dirent *t_dir_entry;
/// @brief Get the fd arrays object
/// @return pointer to the files's array
/// @note internal function used to get the files array
t_fd_array *get_fd_arrays(void);
t_fd_array *get_fd_arrays(void);
/// @brief Get the unused fd slot object
/// @return pointer to the unused file slot
/// @note Will abort if no slot is available
struct s_file_slot *get_unused_fd_slot(void);
struct s_file_slot *get_unused_fd_slot(void);
/// @brief Close all slots
/// @note This is probably NOT what you want
void close_all_slots(void);
void close_all_slots(void);
/// @note Close the given slot
/// @param[in] slot the slot to close
/// @note this is probably NOT what you want
void close_slot(struct s_file_slot *slot);
void close_slot(struct s_file_slot *slot);
/* ______ _____
| ____| __ \
@ -208,8 +208,9 @@ void close_slot(struct s_file_slot *slot);
/// @param open_options the options to open the file
/// @param fileperm the file permission
/// @return the file descriptor* on success, NULL otherwise
t_fd *open_fd(t_str name, t_fd_perm perms, t_file_open_option open_options,
t_file_perm file_perm);
t_fd *open_fd(t_str name, t_fd_perm perms,
t_file_open_option open_options,
t_file_perm file_perm);
/// @brief Read from a file descriptor
/// @param[in] fd the file descriptor
@ -217,7 +218,8 @@ t_fd *open_fd(t_str name, t_fd_perm perms, t_file_open_option open_options,
/// @param[in] size the size of the buffer
/// @param[out] read_count the number of bytes read
/// @return true on error, false otherwise
t_error read_fd(t_fd *fd, t_u8 *buffer, t_usize size, t_isize *read_count);
t_error read_fd(t_fd *fd, t_u8 *buffer, t_usize size,
t_isize *read_count);
/// @brief Write to a file descriptor
/// @param[in] fd the file descriptor
@ -226,30 +228,31 @@ t_error read_fd(t_fd *fd, t_u8 *buffer, t_usize size, t_isize *read_count);
/// @param[out] write_count the number of bytes written
/// @return true on error, false otherwise
/// @note write_count can be NULL
t_error write_fd(t_fd *fd, t_u8 *buffer, t_usize size, t_isize *write_count);
t_error write_fd(t_fd *fd, t_u8 *buffer, t_usize size,
t_isize *write_count);
/// @brief Get the file descriptor's information through stat
/// @param[in] fd the file descriptor
/// @param[out] stat the stat structure to fill
/// @return true on error, false otherwise
t_error stat_fd(t_fd *fd, t_stat *stat);
t_error stat_fd(t_fd *fd, t_stat *stat);
/// @brief Close a file descriptor
/// @param[in] fd the file descriptor
/// @note Will close the file descriptor and free the slot
void close_fd(t_fd *fd);
void close_fd(t_fd *fd);
/// @brief write a number to a file descriptor
/// @note will fail silently if the fd is not open in write mode
void put_number_fd(t_fd *fd, t_u64 number);
void put_number_fd(t_fd *fd, t_u64 number);
/// @brief write a string to a file descriptor
/// @note will fail silently if the fd is not open in write mode
void put_string_fd(t_fd *fd, t_const_str string);
void put_string_fd(t_fd *fd, t_const_str string);
/// @brief write a char to a file descriptor
/// @note will fail silently if the fd is not open in write mode
void put_char_fd(t_fd *fd, t_u8 c);
void put_char_fd(t_fd *fd, t_u8 c);
/* _____ _____ _____ ______ _____ _______ ____ _______ __
| __ \_ _| __ \| ____/ ____|__ __/ __ \| __ \ \ / /
@ -263,7 +266,7 @@ void put_char_fd(t_fd *fd, t_u8 c);
/// @param[in] name the name of the file
/// @param[out] dir the file structure to fill
/// @return true on error, false otherwise
t_error open_dir(t_str name, t_dir **dir);
t_error open_dir(t_str name, t_dir **dir);
/// @brief Read a directory, advancing in the directory stream
/// @param[in] dir the directory to read from
@ -271,12 +274,12 @@ t_error open_dir(t_str name, t_dir **dir);
/// @return true on error, false otherwise
/// @note you need to open the dir again to read from the begining
/// @note you will get an NULL at the end of the directory stream
t_error read_dir(t_dir *dir, t_dir_entry *out);
t_error read_dir(t_dir *dir, t_dir_entry *out);
/// @brief Close a directory
/// @param[in] dir the directory to close
/// @note Will close the directory and free the slot
void close_dir(t_dir *dir);
void close_dir(t_dir *dir);
/*______ _____ _ ______
| ____|_ _| | | ____|
@ -291,7 +294,7 @@ void close_dir(t_dir *dir);
/// @param[in] mode the mode to open the file
/// @param[out] file the file structure to fill
/// @return true on error, false otherwise
t_error open_file(t_str name, t_mode mode, t_file **file);
t_error open_file(t_str name, t_mode mode, t_file **file);
/// @brief Read a file
/// @param[in] file the file to read from
@ -299,8 +302,8 @@ t_error open_file(t_str name, t_mode mode, t_file **file);
/// @param[in] size the size of the buffer
/// @param[out] read_count the number of bytes read
/// @return true on error, false otherwise
t_error read_file(t_file *file, t_u8 *buffer, t_usize size,
t_isize *read_count);
t_error read_file(t_file *file, t_u8 *buffer, t_usize size,
t_isize *read_count);
/// @brief Write to a file
/// @param[in] file the file to write to
@ -309,13 +312,13 @@ t_error read_file(t_file *file, t_u8 *buffer, t_usize size,
/// @param[out] write_count the number of bytes written
/// @return true on error, false otherwise
/// @note write_count can be NULL
t_error write_file(t_file *file, t_u8 *buffer, t_usize size,
t_isize *write_count);
t_error write_file(t_file *file, t_u8 *buffer, t_usize size,
t_isize *write_count);
/// @brief Close the underlying file stream
/// @param[in] file the file to close
/// @note Will close the file and free the slot
void close_file(t_file *file);
void close_file(t_file *file);
/* _____ ______ _______ _______ ______ _____ _____
/ ____| ____|__ __|__ __| ____| __ \ / ____|
@ -325,9 +328,9 @@ void close_file(t_file *file);
\_____|______| |_| |_| |______|_| \_\_____/
*/
//TODO: Documentation!
t_fd *get_stdin(void);
t_fd *get_stdout(void);
t_fd *get_stderr(void);
// TODO: Documentation!
t_fd *get_stdin(void);
t_fd *get_stdout(void);
t_fd *get_stderr(void);
#endif /* FS_H */

View file

@ -27,16 +27,16 @@
typedef struct s_static_buffer
{
int fd;
bool used;
char buf[BUFFER_SIZE + 1];
bool init;
} t_static_buffer;
bool used;
char buf[BUFFER_SIZE + 1];
bool init;
} t_static_buffer;
typedef struct s_copy_flags
{
bool error;
bool empty_read;
} t_copy_flags;
bool error;
bool empty_read;
} t_copy_flags;
t_string get_next_line(int fd, bool *error);

View file

@ -61,7 +61,6 @@ void hasher_write_u64(t_hasher *hasher, t_u64 n);
/// @param n the value to write
void hasher_write_usize(t_hasher *hasher, t_usize n);
/// @brief Write an i8 to the hasher
/// @param hasher the hasher to write to
/// @param n the value to write
@ -87,7 +86,6 @@ void hasher_write_i64(t_hasher *hasher, t_i64 n);
/// @param n the value to write
void hasher_write_isize(t_hasher *hasher, t_isize n);
/// @brief Write an string to the hasher
/// @param hasher the hasher to write to
/// @param str the string to write

View file

@ -6,12 +6,11 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/24 17:39:36 by maiboyer #+# #+# */
/* Updated: 2023/12/25 18:35:05 by maiboyer ### ########.fr */
/* Updated: 2024/07/11 18:57:51 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
/*
Copyright (c) 2021, Dominic Szablewski - https://phoboslab.org
SPDX-License-Identifier: MIT
@ -64,7 +63,8 @@ See the function declaration below for the signature and more information.
If you don't want/need the qoi_read and qoi_write functions, you can define
QOI_NO_STDIO before including this library.
This library uses malloc() and mem_free(). To supply your own malloc implementation
This library uses malloc() and mem_free(). To supply your own malloc
implementation
you can define QOI_MALLOC and QOI_FREE before including this library.
This library uses memset() to zero-initialize the index. To supply your own
@ -227,7 +227,6 @@ Header - Public functions */
#ifndef QOI_H
# define QOI_H
# include "me/mem/mem.h"
# include "me/mem/mem.h"
# include "me/types.h"
/* A pot_i32er to a t_qoi_desc struct has to be supplied to all of qoi's

View file

@ -11,11 +11,11 @@
/* ************************************************************************** */
#ifndef _ALLOCATOR_H
#define _ALLOCATOR_H
# define _ALLOCATOR_H
#include "aq/allocator.h"
# include "aq/allocator.h"
t_allocator *global_allocator(void);
void uninit_global_allocator(void);
t_allocator *global_allocator(void);
void uninit_global_allocator(void);
#endif /* _ALLOCATOR_H */

View file

@ -6,81 +6,81 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/14 18:32:57 by maiboyer #+# #+# */
/* Updated: 2024/05/19 17:04:44 by maiboyer ### ########.fr */
/* Updated: 2024/07/11 18:58:15 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef MEM_H
#define MEM_H
# define MEM_H
#include "me/types.h"
# include "me/types.h"
/// @brief Allocate [size] bytes of memory
/// @param size number of bytes to allocate
/// @return a pointer of at least [size] bytes
/// @remark will abort if unable to allocate
void *mem_alloc(t_usize size);
void *mem_alloc(t_usize size);
/// @brief Allocate [size] * [count] bytes of memory
/// @param size number of elements
/// @param count number of bytes of each element
/// @return a pointer of at least [size] * [count] bytes
/// @remark will abort if unable to allocate, or if the multiplication overflows
void *mem_alloc_array(t_usize size, t_usize count);
void *mem_alloc_array(t_usize size, t_usize count);
/// @brief Extend or Reallocate [size] bytes
/// @param ptr pointer to the memory block
/// @param size number of bytes required
/// @return a pointer of at least [size] bytes, it may be the same pointer as [ptr] if it was able to be extended
/// @return a pointer of at least [size] bytes,
/// it may be the same pointer as [ptr] if it was able to be extended
/// @remark will abort if unable to allocate
/// @remark Will be equal to an `mem_alloc` if [ptr] == NULL
void *mem_realloc(void *ptr, t_usize size);
void *mem_realloc(void *ptr, t_usize size);
/// @brief Extend or Reallocate [size] * [count] bytes
/// @param ptr pointer to the memory block
/// @param size size of each element in bytes
/// @param count number of elements
/// @return a pointer of at least [size] * [count] bytes, it may be the same pointer as [ptr] if it was able to be extended
/// @return a pointer of at least [size] * [count] bytes,
/// it may be the same pointer as [ptr] if it was able to be extended
/// @remark will abort if unable to allocate
/// @remark Will be equal to an `mem_alloc_array` if [ptr] == NULL
void *mem_realloc_array(void *ptr, t_usize size, t_usize count);
void *mem_realloc_array(void *ptr, t_usize size, t_usize count);
/// @brief Set the memory block assigned at [ptr] as unsued
/// @param ptr the memory block to free
void mem_free(void *ptr);
void mem_free(void *ptr);
/// @brief Set [count] bytes to zero at the pointer [buf]
/// @param buf start of at least [count] bytes
/// @param count number of bytes to set to zero
void mem_set_zero(void *buf, t_usize count);
void mem_set_zero(void *buf, t_usize count);
/// @brief Set [count] bytes to [byte] at the pointer [buf]
/// @param buf start of at least [count] bytes
/// @param byte byte to set
/// @param count number of bytes to set to [byte]
void mem_set(void *buf, t_u8 byte, t_usize count);
void mem_set(void *buf, t_u8 byte, t_usize count);
/// @brief Copy [count] bytes from [source] to [destination]
/// @param destination pointer to at least [count] bytes
/// @param source pointer to at least [count] bytes
/// @param count number of bytes to copy
/// @return [destination]
void *mem_move(void *destination, const void *source, t_usize count);
void *mem_move(void *destination, const void *source, t_usize count);
/// @brief Copy [count] bytes from [source] to [destination]
/// @param destination pointer to at least [count] bytes
/// @param source pointer to at least [count] bytes
/// @param count number of bytes to copy
/// @return [destination]
void *mem_copy(void *destination, const void *source, t_usize count);
void *mem_copy(void *destination, const void *source, t_usize count);
/// @brief find a byte [find] in the buffer [buf] of size [count]
/// @param buf the buffer to search in
/// @param find the byte to find
/// @param count the number of bytes to search
/// @return the pointer to the first occurence of [find] or NULL if not found
void *mem_find(void *buf, t_u8 find, t_usize count);
void *mem_find(void *buf, t_u8 find, t_usize count);
/// @brief find bytes [find][.find_count] in the buffer [buf] of size [count]
/// @param buf the buffer to search in
@ -88,13 +88,14 @@ void *mem_find(void *buf, t_u8 find, t_usize count);
/// @param find_count number of the bytes to find
/// @param count the number of bytes to search
/// @return the pointer to the first occurence of [find] or NULL if not found
void *mem_find_bytes(void *buf, t_u8 *find, t_usize find_count, t_usize count);
void *mem_find_bytes(void *buf, t_u8 *find, t_usize find_count,
t_usize count);
/// @brief compare [count] bytes from [lhs] to [rhs]
/// @param lhs bytes to compare
/// @param rhs bytes to compare
/// @param count number of bytes to compare
/// @return true if the bytes are equal for [count] bytes, false otherwise
bool mem_compare(const void *lhs, const void *rhs, t_usize count);
bool mem_compare(const void *lhs, const void *rhs, t_usize count);
#endif /* MEM_H */

View file

@ -17,6 +17,6 @@
t_usize usize_rotate_left(t_usize n, t_usize by);
t_usize usize_rotate_right(t_usize n, t_usize by);
t_usize usize_round_up_to(t_usize self, t_usize mul);
t_usize usize_round_up_to(t_usize self, t_usize mul);
#endif

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/03 15:43:08 by maiboyer #+# #+# */
/* Updated: 2024/07/07 18:25:23 by maiboyer ### ########.fr */
/* Updated: 2024/07/11 18:59:04 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
@ -31,7 +31,7 @@ union u_redirection
{
struct s_fd_redirection
{
int value;
int value;
} fd;
struct s_piped_redirection
{
@ -74,7 +74,9 @@ static inline t_redirection inherited(void)
static inline t_redirection fd(int fd)
{
return ((t_redirection){.tag = R_FD, \
.vals = (union u_redirection){.fd = {.value = fd},}});
.vals = (union u_redirection){\
.fd = {.value = fd}, \
}});
}
/// @brief Wrapped file descriptor tag
@ -91,15 +93,15 @@ union u_wrapped_fd
{
struct s_read_only
{
int fd;
int fd;
} ro;
struct s_write_only
{
int fd;
int fd;
} wo;
struct s_read_write
{
int fd;
int fd;
} rw;
};
@ -115,10 +117,10 @@ typedef struct s_wrapped_fd
/// @return the wrapped file descriptor
static inline t_wrapped_fd ro(int fd)
{
return ((t_wrapped_fd){.tag = READ_ONLY,
.vals = (union u_wrapped_fd){
.ro = {.fd = fd},
}});
return ((t_wrapped_fd){.tag = READ_ONLY, \
.vals = (union u_wrapped_fd){\
.ro = {.fd = fd}, \
}});
}
/// @brief Create a Write only wrapped file descriptor
@ -161,11 +163,10 @@ typedef struct s_process_output
t_exit_code exit_code;
} t_process_output;
/// @brief Spawn a new process with the given information
/// @param info the information to spawn the process
/// @param process data returned by the function
/// @return true if an error occured, false otherwise
/// @return true if an error occured, false otherwise
t_error spawn_process(t_spawn_info info,
t_process *process);

View file

@ -6,39 +6,39 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/07 17:36:38 by maiboyer #+# #+# */
/* Updated: 2024/07/07 18:01:17 by maiboyer ### ########.fr */
/* Updated: 2024/07/11 19:00:22 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef _INTERNAL_PRINTF_H
#define _INTERNAL_PRINTF_H
# define _INTERNAL_PRINTF_H
#include "me/fs/fs.h"
#include "me/string/string.h"
#include "me/types.h"
# include "me/fs/fs.h"
# include "me/string/string.h"
# include "me/types.h"
typedef enum e_printf_flags t_printf_flags;
typedef enum e_printf_type t_printf_type;
typedef struct s_fprintf_arg t_fprintf_arg;
typedef struct s_printf_args t_printf_arg;
typedef struct s_printf_extra_args t_printf_extra_args;
typedef struct s_sprintf_arg t_sprintf_arg;
typedef enum e_printf_flags t_printf_flags;
typedef enum e_printf_type t_printf_type;
typedef struct s_fprintf_arg t_fprintf_arg;
typedef struct s_printf_args t_printf_arg;
typedef struct s_printf_extra_args t_printf_extra_args;
typedef struct s_sprintf_arg t_sprintf_arg;
typedef void (*t_printf_func)(t_const_str to_write, t_usize to_write_len,
void *p_args);
typedef void (*t_printf_func)(t_const_str to_write,
t_usize to_write_len, void *p_args);
struct s_fprintf_arg
struct s_fprintf_arg
{
t_usize total_print;
t_fd *fd;
t_usize total_print;
t_fd *fd;
};
struct s_sprintf_arg
struct s_sprintf_arg
{
t_usize total_print;
t_string *buffer;
t_usize total_print;
t_string *buffer;
};
enum e_printf_flags
enum e_printf_flags
{
PRECISION = 1 << 1,
ALIGN = 1 << 2,
@ -46,7 +46,7 @@ enum e_printf_flags
SIGN = 1 << 4,
};
enum e_printf_type
enum e_printf_type
{
CHAR = 1 << 0,
STR = 1 << 1,
@ -57,25 +57,26 @@ enum e_printf_type
U32 = 1 << 6,
};
struct s_printf_extra_args
struct s_printf_extra_args
{
t_u64 precision;
t_u64 align;
bool left_align;
bool space_align;
bool pretty;
t_u64 precision;
t_u64 align;
bool left_align;
bool space_align;
bool pretty;
};
struct s_printf_args
struct s_printf_args
{
void *argument;
void *p_args;
t_printf_extra_args extra;
t_printf_flags flags;
void *argument;
void *p_args;
t_printf_extra_args extra;
t_printf_flags flags;
};
void me_printf_write(t_const_str to_write, t_usize to_write_len, void *p_args);
void me_printf_append_string(t_const_str to_write, t_usize to_write_len,
void *p_args);
void me_printf_write(t_const_str to_write,
t_usize to_write_len, void *p_args);
void me_printf_append_string(t_const_str to_write,
t_usize to_write_len, void *p_args);
#endif /* _INTERNAL_PRINTF_H */

View file

@ -6,72 +6,74 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/16 18:10:27 by maiboyer #+# #+# */
/* Updated: 2024/07/07 17:37:02 by maiboyer ### ########.fr */
/* Updated: 2024/07/11 19:00:06 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef PRINTF_H
#define PRINTF_H
#include "me/types.h"
#include <stdarg.h>
# define PRINTF_H
# include "me/types.h"
# include <stdarg.h>
#ifndef FS_H
typedef struct s_fd t_fd;
#endif
# ifndef FS_H
#ifndef STRING_H
typedef struct s_string t_string;
#endif
typedef struct s_fd t_fd;
# endif
# ifndef STRING_H
typedef struct s_string t_string;
# endif
/// @brief Print a formatted string to stdout
/// @param fmt the format string
/// @param ... the arguments to format
/// @return the number of characters printed
t_usize me_printf(t_const_str fmt, ...);
t_usize me_printf(t_const_str fmt, ...);
/// @brief Print a formatted string to a stderr
/// @param fmt the format string
/// @param ... the arguments to format
/// @return the number of characters printed
t_usize me_eprintf(t_const_str fmt, ...);
t_usize me_eprintf(t_const_str fmt, ...);
/// @brief Print a formatted string to a stdout
/// @param fmt the format string
/// @param args the arguments to format as a va_list
/// @return the number of characters printed
t_usize me_vprintf(t_const_str fmt, va_list *args);
t_usize me_vprintf(t_const_str fmt, va_list *args);
/// @brief Print a formatted string to a stderr
/// @param fmt the format string
/// @param args the arguments to format as a va_list
/// @return the number of characters printed
t_usize me_veprintf(t_const_str fmt, va_list *args);
t_usize me_veprintf(t_const_str fmt, va_list *args);
/// @brief Print a formatted string to the given fd
/// @param fmt the format string
/// @param ... the arguments to format
/// @return the number of characters printed
t_usize me_printf_fd(t_fd *, t_const_str fmt, ...);
t_usize me_printf_fd(t_fd *fd, t_const_str fmt, ...);
/// @brief Print a formatted string to the given fd
/// @param fmt the format string
/// @param args the arguments to format as a va_list
/// @return the number of characters printed
t_usize me_vprintf_fd(t_fd *, t_const_str fmt, va_list *args);
t_usize me_vprintf_fd(t_fd *f, t_const_str fmt, va_list *args);
/// @brief print a formatted string to a buffer
/// @param buffer the buffer to append to
/// @param fmt the format string
/// @param ... the arguments to format
/// @return the number of characters printed
t_usize me_printf_str(t_string *buffer, t_const_str fmt, ...);
t_usize me_printf_str(t_string *buffer, t_const_str fmt, ...);
/// @brief print a formatted string to a buffer
/// @param buffer the buffer to append to
/// @param fmt the format string
/// @param args the arguments to format
/// @return the number of characters printed
t_usize me_vprintf_str(t_string *buffer, t_const_str fmt, va_list *args);
t_usize me_vprintf_str(t_string *buffer, t_const_str fmt, \
va_list *args);
#endif

View file

@ -6,14 +6,14 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/19 23:30:46 by maiboyer #+# #+# */
/* Updated: 2024/05/19 23:30:46 by maiboyer ### ########.fr */
/* Updated: 2024/07/11 19:00:41 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef STR_H
#define STR_H
# define STR_H
#include "me/types.h"
# include "me/types.h"
/// @brief Get the length of a string
/// @param str the string
/// @return the length of the string
@ -47,25 +47,27 @@ bool str_n_compare(t_const_str lhs, t_const_str rhs, t_usize n);
/// @brief Find a character in a string
/// @param str the string to search in
/// @param chr the character to find
/// @return a pointer to the first occurence of the character, or NULL if not found
char *str_find_chr(t_const_str str, char chr);
/// @return a pointer to the first occurence of the character,
/// or NULL if not found
char *str_find_chr(t_const_str str, char chr);
/// @brief Find a character in a string, starting from the end
/// @param str the string to search in
/// @param chr the character to find
/// @return a pointer to the last occurence of the character, or NULL if not found
char *str_find_rev_chr(t_const_str str, char chr);
/// @return a pointer to the last occurence of the character,
/// or NULL if not found
char *str_find_rev_chr(t_const_str str, char chr);
/// @brief Find a string in a string
/// @param str the string to be searched
/// @param to_find the string to find
/// @return a pointer to the first occurence of the string, or NULL if not found
const char *str_find_str(t_const_str str, t_const_str to_find);
const char *str_find_str(t_const_str str, t_const_str to_find);
/// @brief Find a string in a string, up to n characters
/// @param str the string to be searched
/// @param to_find the string to find
/// @param len the maximum number of characters to search
/// @return a pointer to the first occurence of the string, or NULL if not found
const char *str_n_find_str(t_const_str str, t_const_str to_find, t_usize len);
const char *str_n_find_str(t_const_str str, t_const_str to_find, t_usize len);
/// @brief Join two string together
/// @param s1 First string
@ -102,7 +104,7 @@ t_str str_map(t_const_str s, char (*f)(t_usize, char));
/// @param str the string to be split
/// @param chr the character to split the string on
/// @return the vector of strings
t_str *str_split(t_const_str str, char chr);
t_str *str_split(t_const_str str, char chr);
/// @brief Remove consecutive leading and trailing characters from a string
/// @param str the string to trim

View file

@ -6,53 +6,53 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/16 17:54:28 by maiboyer #+# #+# */
/* Updated: 2024/07/08 21:58:11 by maiboyer ### ########.fr */
/* Updated: 2024/07/11 19:01:02 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef STRING_H
#define STRING_H
#include "me/types.h"
# define STRING_H
# include "me/types.h"
typedef struct s_string
{
t_str buf;
t_usize capacity;
t_usize len;
} t_string;
t_str buf;
t_usize capacity;
t_usize len;
} t_string;
/// @brief Push a string to a buffer
/// @param buf the string to be pushed to
/// @param to_push the string to push
/// @return true if it failed, false otherwise
t_error string_push(t_string *buf, t_const_str to_push);
t_error string_push(t_string *buf, t_const_str to_push);
/// @brief Push a character to a buffer
/// @param buf the string to be pushed to
/// @param to_push the character to push
/// @return true if it failed, false otherwise
t_error string_push_char(t_string *buf, char to_push);
t_error string_push_char(t_string *buf, char to_push);
/// @brief Clear a string
/// @param buf the string to clear
void string_clear(t_string *buf);
void string_clear(t_string *buf);
/// @brief Create a new string
/// @param capacity the initial capacity of the string
/// @return the created string
t_string string_new(t_usize capacity);
t_string string_new(t_usize capacity);
/// @brief Make the string able to hold at least size characters if not already
/// @param buf the string to operate on
/// @param size the minimum size of the string wanted
/// @return true if it failed, false otherwise
t_error string_reserve(t_string *buf, t_usize size);
t_error string_reserve(t_string *buf, t_usize size);
/// @brief free a string
/// @param buf the string to free
static inline void string_free(t_string buf)
static inline void string_free(t_string buf)
{
void mem_free(void *);
void mem_free(void *);
mem_free(buf.buf);
}
@ -60,9 +60,9 @@ static inline void string_free(t_string buf)
/// @brief Pop a character from a string
/// @param buf the string to pop from
/// @return the popped character, or '\0' if the string is empty
static inline char string_pop(t_string *buf)
static inline char string_pop(t_string *buf)
{
char c;
char c;
c = '\0';
if (buf->buf && buf->len)
@ -79,7 +79,7 @@ static inline char string_pop(t_string *buf)
/// @param str the string to insert
/// @return Error in case pos was over the string length, self was equal to NULL
/// or str was equal to NULL
t_error string_insert(t_string *self, t_usize pos, t_str str);
t_error string_insert(t_string *self, t_usize pos, t_str str);
/// @brief Insert a char into self
/// @param self the string to insert into
@ -87,19 +87,19 @@ t_error string_insert(t_string *self, t_usize pos, t_str str);
/// @param str the character to insert
/// @return Error in case pos was over the string length, self was equal to NULL
/// or chr was '\0'
t_error string_insert_char(t_string *self, t_usize pos, char chr);
t_error string_insert_char(t_string *self, t_usize pos, char chr);
/// @brief Clear the string, keeping everything before `pos`
/// @param self the string to operate on
/// @param pos the position to start remove from
/// @return returns an Error if self is null or pos is after the string length
t_error string_clear_after(t_string *self, t_usize pos);
t_error string_clear_after(t_string *self, t_usize pos);
/// @brief Remove a single character from the string, putting it in `out`
/// @param self the string to operate on
/// @param pos the position to start remove
/// @param out[out] the place to put the removed character, if any. Can be NULL
/// @return returns an Error if self is null or pos is after the string length
t_error string_remove(t_string *self, t_usize pos, char *out);
t_error string_remove(t_string *self, t_usize pos, char *out);
#endif

View file

@ -6,71 +6,67 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/03 14:31:12 by maiboyer #+# #+# */
/* Updated: 2024/05/30 13:38:20 by maiboyer ### ########.fr */
/* Updated: 2024/07/11 18:54:29 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef TYPES_H
#define TYPES_H
# define TYPES_H
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <unistd.h>
#ifndef _Nullable
# define _Nullable
#endif
# include <stdbool.h>
# include <stddef.h>
# include <stdint.h>
# include <unistd.h>
/// @brief A string, null terminated
typedef char *t_str;
typedef char *t_str;
/// @brief A constant string, null terminated
typedef const char *t_const_str;
typedef const char *t_const_str;
/// @brief an unsigned 8 bit integer
typedef uint8_t t_u8;
typedef uint8_t t_u8;
/// @brief a signed 8 bit integer
typedef int8_t t_i8;
typedef int8_t t_i8;
/// @brief an unsigned 16 bit integer
typedef uint16_t t_u16;
typedef uint16_t t_u16;
/// @brief a signed 16 bit integer
typedef int16_t t_i16;
typedef int16_t t_i16;
/// @brief an unsigned 32 bit integer
typedef uint32_t t_u32;
typedef uint32_t t_u32;
/// @brief a signed 32 bit integer
typedef int32_t t_i32;
typedef int32_t t_i32;
/// @brief an unsigned 64 bit integer
typedef uint64_t t_u64;
typedef uint64_t t_u64;
/// @brief a signed 64 bit integer
typedef int64_t t_i64;
typedef int64_t t_i64;
/// @brief a signed integer that can hold a pointer
typedef ssize_t t_isize;
typedef ssize_t t_isize;
/// @brief an unsigned integer that can hold a pointer
typedef size_t t_usize;
typedef size_t t_usize;
/// @brief a 32 bit floating point number
typedef float t_f32;
typedef float t_f32;
/// @brief a 64 bit floating point number
typedef double t_f64;
typedef double t_f64;
/// @brief a boolean value that represents an error
/// @note true is an error, false is no error
typedef bool t_error;
typedef bool t_error;
/// @brief a function that denotes an abrupt end of the program
/// @param msg the message to print before exiting
void me_abort(t_str msg);
void me_abort(t_str msg);
/// @brief a function that denotes a normal end of the program
/// @param code the exit code
void me_exit(t_i32 code);
void me_exit(t_i32 code);
/// @brief a function that prints the current stack trace
void print_trace(void);
void print_trace(void);
/// @def signal that an error occured
#define ERROR 1
# define ERROR 1
/// @def signal that no error occured
#define NO_ERROR 0
# define NO_ERROR 0
#endif

View file

@ -42,7 +42,6 @@ static inline t_vf2d vf2d(t_f32 x, t_f32 y)
return ((t_vf2d){.x = x, .y = y});
}
/// @brief Create a 2D int vector
/// @param x The x component
/// @param y The y component
@ -52,7 +51,6 @@ static inline t_vi2d vi2d(t_i32 x, t_i32 y)
return ((t_vi2d){.x = x, .y = y});
}
/// @brief Create a 2D unsigned int vector
/// @param x The x component
/// @param y The y component
@ -62,7 +60,6 @@ static inline t_vu2d vu2d(t_u32 x, t_u32 y)
return ((t_vu2d){.x = x, .y = y});
}
/// @brief Add two 2D int vectors
/// @param lhs The left hand side vector
/// @param rhs The right hand side vector
@ -72,7 +69,6 @@ static inline t_vi2d vi2d_add(t_vi2d lhs, t_vi2d rhs)
return ((t_vi2d){.x = lhs.x + rhs.x, .y = lhs.y + rhs.y});
}
/// @brief Substract two 2D int vectors
/// @param lhs The left hand side vector
/// @param rhs The right hand side vector