update stuff

This commit is contained in:
Maix0 2024-05-20 00:35:39 +02:00
parent 5973022688
commit 544ed8b045
194 changed files with 2060 additions and 1464 deletions

View file

@ -18,7 +18,6 @@
# include "me/vec2/vec2.h"
# include "me/blx/sprite.h"
# include "me/blx/inputs.h"
# include "me/blx/points.h"
# include "me/types.h"
typedef struct s_blx t_blx;
@ -61,20 +60,77 @@ typedef struct s_blx
t_blx_data _data;
} t_blx;
/// @brief The main loop function
/// @param ctx the BLX context
/// @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);
/// @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);
/// @brief is the key pressed
/// @param ctx the BLX context
/// @param input the key to check
/// @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
/// @return true if the key is released, false otherwise
bool is_key_released(t_blx *ctx, t_keysym input);
/// @brief Start the game
/// @param app the BLX context
void blx_run(t_blx app);
/// @brief Free the game
/// @param app the BLX context
void blx_free(t_blx app);
/// @brief Draw a pixel onto the screen
/// @param app the BLX context
/// @param pos the position to draw the pixel at
/// @param col the color of the pixel
void blx_draw(t_blx *app, t_vi2d pos, t_color col);
/// @brief Clear the screen with a color
/// @param app the BLX context
/// @param col the color to clear the screen with
void blx_clear(t_blx *app, t_color col);
/// @brief Draw a sprite onto another sprite
/// @param dest the sprite to be drawn onto
/// @param pos the position to draw the sprite at
/// @param source the sprite to draw
void sprite_draw_onto(t_sprite *dest, t_vi2d pos,
t_sprite *source);
/// @brief Draw a string onto the screen
/// @param app the BLX context
/// @param pos the position to draw the string at
/// @param s the string to draw
/// @param col the color of the string
void blx_draw_string(t_blx *app, t_vi2d pos,
t_const_str s, t_color col);

View file

@ -15,8 +15,21 @@
# include "me/blx/blx_key.h"
# include "me/types.h"
/// @brief Handle a key press event
/// @param keysym the key that was pressed
/// @param ctx the BLX context
/// @note this is an internal function, you should not call it yourself
int blx_key_pressed_handler(t_keysym keysym, t_blx *ctx);
/// @brief Handle a key released event
/// @param keysym the key that was released
/// @param ctx the BLX context
/// @note this is an internal function, you should not call it yourself
int blx_key_released_handler(t_keysym keysym, t_blx *ctx);
/// @brief Handle a exit event
/// @param ctx the BLX context
/// @note this is an internal function, you should not call it yourself
int blx_key_exit_handler(t_blx *ctx);
#endif

View file

@ -166,10 +166,34 @@ typedef enum e_keysym
typedef struct s_blx t_blx;
/// @brief Convert a keysym to a bit index
/// @param key the keysym to convert
/// @return the bit index
/// @note this is an internal function, you should not call it yourself
t_usize keysym_to_bit_index(t_keysym key);
/// @brief Get a key from a key storage
/// @param key_storage the key storage
/// @param keysym the key to get
/// @return true if the key is present in the storage, false otherwise
bool get_key(t_vec_u8 *key_storage, t_keysym keysym);
/// @brief is the key pressed
/// @param ctx The BLX context
/// @param key the key to check
/// @return true if the key is pressed, false otherwise
bool is_key_pressed(t_blx *ctx, t_keysym key);
/// @brief is the key held
/// @param ctx The BLX context
/// @param key the key to check
/// @return true if the key is held, false otherwise
bool is_key_held(t_blx *ctx, t_keysym key);
/// @brief is the key released
/// @param ctx The BLX context
/// @param key the key to check
/// @return true if the key is released, false otherwise
bool is_key_released(t_blx *ctx, t_keysym key);
#endif

View file

@ -23,7 +23,19 @@ typedef __attribute__((aligned(4))) struct s_color
t_u8 a;
} t_color;
/// @brief Create a new color with an specified alpha channel
/// @param r the red channel
/// @param g the green channel
/// @param b the blue channel
/// @param alpha the alpha channel
/// @return the resulting color
t_color new_color_with_alpha(t_u8 r, t_u8 g, t_u8 b, t_u8 alpha);
/// @brief Create a new color
/// @param r the red channel
/// @param g the green channel
/// @param b the blue channel
/// @return the resulting color
t_color new_color(t_u8 r, t_u8 g, t_u8 b);
#endif

View file

@ -31,6 +31,10 @@ typedef struct s_blx_input
} t_blx_input;
/// @brief Create an input manager
/// @param ctx the BLX context
/// @return the created input manager
/// @note this is an internal function, you should not call it yourself
t_blx_input create_inputs_manager(t_blx *ctx);
#endif

View file

@ -1,24 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* points.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/13 17:47:17 by maiboyer #+# #+# */
/* Updated: 2023/12/13 18:14:20 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef POINTS_H
# define POINTS_H
# include "me/types.h"
typedef struct s_point
{
t_i32 x;
t_i32 y;
} t_point;
#endif

View file

@ -35,19 +35,63 @@ typedef struct s_sprite
bool big_endian;
} t_sprite;
bool blx_sprite_from_xpm(t_blx *ctx, t_str path,
/// @brief Create a sprite from an XPM file
/// @param ctx the BLX context
/// @param path the path to the XPM file
/// @param[out] out the output sprite
/// @return true if an error occured, false otherwise
t_error blx_sprite_from_xpm(t_blx *ctx, t_str path,
t_sprite *out);
bool blx_sprite_new(t_blx *ctx, t_i32 width, t_i32 height,
/// @brief Create a new sprite
/// @param ctx the BLX context
/// @param width the width of the sprite in pixels
/// @param height the height of the sprite in pixels
/// @param out[out] the output sprite
/// @return true if an error occured, false otherwise
t_error blx_sprite_new(t_blx *ctx, t_i32 width, t_i32 height,
t_sprite *out);
/// @brief Free a sprite
/// @param img the sprite to free
void blx_sprite_free(t_sprite img);
/// @brief Draw a sprite at a position onto the screen
/// @param ctx the BLX context
/// @param pos the position to draw the sprite at
/// @param img the sprite to draw
void blx_draw_sprite_raw(t_blx *ctx, t_vi2d pos,
t_sprite *img);
/// @brief Draw a pixel onto the sprite
/// @param img the sprite to draw onto
/// @param pos the position to draw the pixel at
/// @param col the color of the pixel
void sprite_draw(t_sprite *img, t_vi2d pos, t_color col);
/// @brief Clear a sprite with a color
/// @param img the sprite to clear
/// @param col the color to clear the sprite with
void sprite_clear(t_sprite *img, t_color col);
bool sprite_get_pixel(t_sprite *spr, t_vi2d pos,
/// @brief Get the color of a pixel on a sprite
/// @param spr the sprite to get the pixel from
/// @param pos the position of the pixel
/// @param[out] out the color of the pixel
/// @return true if an error occured, false otherwise
t_error sprite_get_pixel(t_sprite *spr, t_vi2d pos,
t_color *out);
/// @brief Draw a sprite onto another sprite
/// @param dest The sprite to be drawn onto
/// @param pos The position to draw the sprite at
/// @param source The sprite to draw
void sprite_draw_onto(t_sprite *dest, t_vi2d pos,
t_sprite *source);
/// @brief Draw a string onto a sprite
/// @param spr The sprite to draw onto
/// @param pos The position to draw the string at
/// @param sText The string to draw
/// @param col The color of the string
void sprite_draw_string(t_sprite *spr, t_vi2d pos,
t_const_str sText, t_color col);

View file

@ -1,50 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* buf_str.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/16 17:54:28 by maiboyer #+# #+# */
/* Updated: 2024/04/30 14:14:42 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef BUF_STR_H
# define BUF_STR_H
# include "me/types.h"
typedef struct s_buffer_str
{
t_str buf;
t_usize capacity;
t_usize len;
} t_buffer_str;
bool push_str_buffer(t_buffer_str *buf, t_const_str to_push);
bool push_str_char(t_buffer_str *buf, char to_push);
void str_clear(t_buffer_str *buf);
t_buffer_str alloc_new_buffer(t_usize capacity);
t_error str_reserve(t_buffer_str *buf, t_usize size);
static inline void str_free(t_buffer_str buf)
{
void mem_free(void *);
mem_free(buf.buf);
}
static inline char str_pop(t_buffer_str *buf)
{
char c;
c = '\0';
if (buf->buf && buf->len)
{
c = buf->buf[buf->len - 1];
buf->buf[buf->len - 1] = '\0';
}
return (c);
}
#endif

View file

@ -0,0 +1,63 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* char.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/19 17:11:41 by maiboyer #+# #+# */
/* Updated: 2024/05/19 17:11:42 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef CHAR_H
#define CHAR_H
#include "me/types.h"
/// @brief Check if a character is alphanumeric
/// @param chr char to check
/// @return chr is a alphanumeric
bool me_isalnum(char chr);
/// @brief Check if a character is alphabetic
/// @param chr char to check
/// @return chr is a alphabetic
bool me_isalpha(char chr);
/// @brief Check if a character is a digit
/// @param chr
/// @return chr is a digit
bool me_isdigit(char chr);
/// @brief Check if a character is in the ascii range
/// @param chr char to check
/// @return chr is a ascii character
bool me_isascii(char chr);
/// @brief Check if a character is lowercase
/// @param chr char to check
/// @return chr is a lowercase letter
bool me_islower(char chr);
/// @brief Check if a character is uppercase
/// @param chr char to check
/// @return chr is a uppercase letter
bool me_isupper(char chr);
/// @brief Check if a character is a whitespace
/// @param chr char to check
/// @return chr is a whitespace
bool me_isspace(char chr);
/// @brief Set the character to lowercase if it's uppercase
/// @param chr char to convert
/// @return uppercase chr or chr if not a lowercase letter
char me_tolower(char chr);
/// @brief Set the character to uppercase if it's lowercase
/// @param chr char to convert
/// @return lowercase chr or chr if not a uppercase letter
char me_toupper(char chr);
#endif /* CHAR_H */

View file

@ -1,20 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* isalnum.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/04 16:19:40 by maiboyer #+# #+# */
/* Updated: 2023/12/09 16:39:39 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef ISALNUM_H
# define ISALNUM_H
# include "me/types.h"
bool me_isalnum(char chr);
#endif

View file

@ -1,20 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* isalpha.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/04 16:19:40 by maiboyer #+# #+# */
/* Updated: 2023/12/09 16:39:36 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef ISALPHA_H
# define ISALPHA_H
# include "me/types.h"
bool me_isalpha(char chr);
#endif

View file

@ -1,20 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* isascii.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/09 17:51:01 by maiboyer #+# #+# */
/* Updated: 2023/12/09 16:39:33 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef ISASCII_H
# define ISASCII_H
# include "me/types.h"
bool me_isascii(char chr);
#endif

View file

@ -1,20 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* isdigit.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/04 16:19:40 by maiboyer #+# #+# */
/* Updated: 2023/12/09 16:41:55 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef ISDIGIT_H
# define ISDIGIT_H
# include "me/types.h"
bool me_isdigit(char chr);
#endif

View file

@ -1,20 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* islower.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/04 16:19:40 by maiboyer #+# #+# */
/* Updated: 2023/12/09 16:48:25 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef ISLOWER_H
# define ISLOWER_H
# include "me/types.h"
bool me_islower(char chr);
#endif

View file

@ -1,20 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* isprint.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/04 16:19:40 by maiboyer #+# #+# */
/* Updated: 2023/12/09 16:44:49 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef ISPRINT_H
# define ISPRINT_H
# include "me/types.h"
bool me_isprint(char chr);
#endif

View file

@ -1,20 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* isspace.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/06 14:26:25 by maiboyer #+# #+# */
/* Updated: 2023/12/09 16:45:02 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef ISSPACE_H
# define ISSPACE_H
# include "me/types.h"
bool me_isspace(char chr);
#endif

View file

@ -1,20 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* isupper.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/04 16:19:40 by maiboyer #+# #+# */
/* Updated: 2023/12/09 16:45:16 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef ISUPPER_H
# define ISUPPER_H
# include "me/types.h"
bool me_isupper(char chr);
#endif

View file

@ -1,20 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* tolower.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/04 16:47:50 by maiboyer #+# #+# */
/* Updated: 2023/12/09 16:45:33 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef TOLOWER_H
# define TOLOWER_H
# include "me/types.h"
bool me_tolower(char chr);
#endif

View file

@ -1,20 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* toupper.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/04 16:47:50 by maiboyer #+# #+# */
/* Updated: 2023/12/09 16:45:52 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef TOUPPER_H
# define TOUPPER_H
# include "me/types.h"
bool me_toupper(char chr);
#endif

View file

@ -15,16 +15,75 @@
# include "me/types.h"
/// @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)
/// @param out pointer to the number in case of success
/// @return true if an error occured, false otherwise
t_error str_to_isize(t_const_str str, t_u32 radix, t_isize *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)
/// @param out pointer to the number in case of success
/// @return true if an error occured, false otherwise
t_error str_to_i64(t_const_str str, t_u32 radix, t_i64 *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)
/// @param out pointer to the number in case of success
/// @return true if an error occured, false otherwise
t_error str_to_i32(t_const_str str, t_u32 radix, t_i32 *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)
/// @param out pointer to the number in case of success
/// @return true if an error occured, false otherwise
t_error str_to_i16(t_const_str str, t_u32 radix, t_i16 *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)
/// @param out pointer to the number in case of success
/// @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)
/// @param out pointer to the number in case of success
/// @return true if an error occured, false otherwise
t_error str_to_usize(t_const_str str, t_u32 radix, t_usize *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)
/// @param out pointer to the number in case of success
/// @return true if an error occured, false otherwise
t_error str_to_u64(t_const_str str, t_u32 radix, t_u64 *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)
/// @param out pointer to the number in case of success
/// @return true if an error occured, false otherwise
t_error str_to_u32(t_const_str str, t_u32 radix, t_u32 *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)
/// @param out pointer to the number in case of success
/// @return true if an error occured, false otherwise
t_error str_to_u16(t_const_str str, t_u32 radix, t_u16 *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)
/// @param out pointer to the number in case of success
/// @return true if an error occured, false otherwise
t_error str_to_u8(t_const_str str, t_u32 radix, t_u8 *out);
#endif /* STR_TO_NUMBERS_H */

91
stdme/include/me/fs/fs.h Normal file
View file

@ -0,0 +1,91 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* fs.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/19 15:12:18 by maiboyer #+# #+# */
/* Updated: 2024/05/19 17:08:38 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef FS_H
#define FS_H
#include "me/types.h"
#include <dirent.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
# endif
# define FILE_SLOT_LEN 512
#endif
enum e_file_slot_kind
{
SLOT_UNUSED = 0 << 0,
SLOT_FD = 1 << 0,
SLOT_DIR = 1 << 1,
SLOT_FILE = 1 << 2,
};
typedef enum e_fd_type
{
FD_FILE = 1 << 0,
FD_PIPE = 1 << 1,
FD_SOCK = 1 << 2,
FD_UNKNOWN = 1 << 7,
} t_fd_type;
typedef enum e_fd_perm
{
FD_READ = 1 << 0,
FD_WRITE = 1 << 1,
} t_fd_perm;
typedef struct s_fd
{
char *name;
int fd;
t_fd_perm perms;
t_fd_type type;
} t_fd;
typedef struct s_dir
{
DIR *ptr;
char *name;
} t_dir;
typedef struct s_file_data
{
FILE *ptr;
char *name;
} t_file_data;
union u_file_slot {
t_fd fd;
t_dir dir;
t_file_data file;
};
struct s_file_slot
{
enum e_file_slot_kind ty;
union u_file_slot slot;
};
typedef struct s_fd_array
{
struct s_file_slot storage[FILE_SLOT_LEN];
} t_fd_array;
t_fd_array *get_fd_arrays(void);
struct s_file_slot *get_unused_fd_slot(void);
void close_all_fds(void);
#endif /* FS_H */

View file

@ -21,7 +21,7 @@
# define BUFFER_LENGTH 512
# endif
# include "me/buffered_str/buf_str.h"
# include "me/string/string.h"
# include "me/types.h"
typedef struct s_static_buffer
@ -38,6 +38,6 @@ typedef struct s_copy_flags
bool empty_read;
} t_copy_flags;
t_buffer_str get_next_line(t_file fd, bool *error);
t_string get_next_line(t_file fd, bool *error);
#endif

View file

@ -29,24 +29,78 @@ typedef struct s_hasher
} t_hasher;
/// @brief Write [counts] bytes to the hasher
/// @param hasher the hasher to write to
/// @param bytes the bytes to write
/// @param count the number of bytes to write
void hasher_write_bytes(t_hasher *hasher,
t_u8 *bytes, t_usize count);
/// @brief Write an u8 to the hasher
/// @param hasher the hasher to write to
/// @param n the value to write
void hasher_write_u8(t_hasher *hasher, t_u8 n);
/// @brief Write an u16 to the hasher
/// @param hasher the hasher to write to
/// @param n the value to write
void hasher_write_u16(t_hasher *hasher, t_u16 n);
/// @brief Write an u32 to the hasher
/// @param hasher the hasher to write to
/// @param n the value to write
void hasher_write_u32(t_hasher *hasher, t_u32 n);
/// @brief Write an u64 to the hasher
/// @param hasher the hasher to write to
/// @param n the value to write
void hasher_write_u64(t_hasher *hasher, t_u64 n);
/// @brief Write an usize to the hasher
/// @param hasher the hasher to write to
/// @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
void hasher_write_i8(t_hasher *hasher, t_i8 n);
/// @brief Write an i16 to the hasher
/// @param hasher the hasher to write to
/// @param n the value to write
void hasher_write_i16(t_hasher *hasher, t_i16 n);
/// @brief Write an i32 to the hasher
/// @param hasher the hasher to write to
/// @param n the value to write
void hasher_write_i32(t_hasher *hasher, t_i32 n);
/// @brief Write an i64 to the hasher
/// @param hasher the hasher to write to
/// @param n the value to write
void hasher_write_i64(t_hasher *hasher, t_i64 n);
/// @brief Write an isize to the hasher
/// @param hasher the hasher to write to
/// @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
void hasher_write_str(t_hasher *hasher, t_str str);
/// @brief Finish the hashing, free the underlying hasher and return the hash
/// @param hasher the hasher to finish
/// @return the hash
t_u64 hasher_finish(t_hasher *hasher);
/// @brief Finish the hashing and return the hash BUT DOESN't FREE THE HASHER
/// @param hasher the hasher to finish
/// @return the hash
t_u64 hasher_reset_and_finish(t_hasher *hasher);
#endif

View file

@ -227,8 +227,8 @@ Header - Public functions */
#ifndef QOI_H
# define QOI_H
# include "me/mem/mem_alloc.h"
# include "me/mem/mem_set_zero.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
functions. It describes either the input format (for qoi_write and qoi_encode),

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/14 18:32:57 by maiboyer #+# #+# */
/* Updated: 2024/05/14 18:39:13 by maiboyer ### ########.fr */
/* Updated: 2024/05/19 17:04:44 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
@ -14,11 +14,87 @@
#define MEM_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);
/// @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);
/// @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
/// @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);
/// @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
/// @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_free(void *ptr);
/// @brief Set the memory block assigned at [ptr] as unsued
/// @param ptr the memory block to free
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);
/// @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);
/// @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);
/// @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);
/// @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);
/// @brief find bytes [find][.find_count] in the buffer [buf] of size [count]
/// @param buf the buffer to search in
/// @param find pointer to the bytes to find
/// @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);
/// @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);
#endif /* MEM_H */

View file

@ -1,20 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* mem_alloc.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/06 14:47:49 by maiboyer #+# #+# */
/* Updated: 2023/12/09 16:41:31 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef MEM_ALLOC_H
# define MEM_ALLOC_H
# include "me/types.h"
void *mem_alloc(t_usize size);
#endif

View file

@ -1,20 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* mem_alloc_array.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/06 15:53:21 by maiboyer #+# #+# */
/* Updated: 2023/12/09 16:19:45 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef MEM_ALLOC_ARRAY_H
# define MEM_ALLOC_ARRAY_H
# include "me/types.h"
void *mem_alloc_array(t_usize item_count, t_usize item_size);
#endif

View file

@ -1,20 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* mem_compare.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/06 11:16:02 by maiboyer #+# #+# */
/* Updated: 2023/12/09 16:21:14 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef MEM_COMPARE_H
# define MEM_COMPARE_H
# include "me/types.h"
t_i32 mem_compare(const void *lhs, const void *rhs, t_usize count);
#endif

View file

@ -1,20 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* mem_copy.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/06 11:16:02 by maiboyer #+# #+# */
/* Updated: 2023/12/09 16:21:31 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef MEM_COPY_H
# define MEM_COPY_H
# include "me/types.h"
void *mem_copy(void *destination, const void *source, t_usize count);
#endif

View file

@ -1,20 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* mem_find.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/06 11:16:02 by maiboyer #+# #+# */
/* Updated: 2023/12/09 16:24:03 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef MEM_FIND_H
# define MEM_FIND_H
# include "me/types.h"
void *mem_find(void *buf, t_u8 find, t_usize count);
#endif

View file

@ -1,21 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* mem_find_bytes.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/06 11:16:02 by maiboyer #+# #+# */
/* Updated: 2024/01/06 18:24:04 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef MEM_FIND_BYTES_H
# define MEM_FIND_BYTES_H
# include "me/types.h"
void *mem_find_bytes(void *buf, t_u8 *find, t_usize find_count,
t_usize count);
#endif

View file

@ -1,20 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* mem_move.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/06 11:16:02 by maiboyer #+# #+# */
/* Updated: 2023/12/09 16:24:26 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef MEM_MOVE_H
# define MEM_MOVE_H
# include "me/types.h"
void *mem_move(void *destination, const void *source, t_usize count);
#endif

View file

@ -1,20 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* mem_realloc.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/07 12:47:23 by maiboyer #+# #+# */
/* Updated: 2024/05/07 12:47:42 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef MEM_REALLOC_H
#define MEM_REALLOC_H
#include "me/types.h"
void *mem_realloc(void *ptr, t_usize size);
#endif /* MEM_REALLOC_H */

View file

@ -1,20 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* mem_set.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/06 11:16:02 by maiboyer #+# #+# */
/* Updated: 2023/12/09 16:25:19 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef MEM_SET_H
# define MEM_SET_H
# include "me/types.h"
void mem_set(void *buf, t_u8 byte, t_usize count);
#endif

View file

@ -1,20 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* mem_set_zero.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/06 11:58:11 by maiboyer #+# #+# */
/* Updated: 2023/12/09 16:24:51 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef MEM_SET_ZERO_H
# define MEM_SET_ZERO_H
# include "me/types.h"
void mem_set_zero(void *buf, t_usize count);
#endif

View file

@ -15,12 +15,16 @@
# include "me/types.h"
/// @brief Pipe structure
typedef struct s_pipe
{
t_file read;
t_file write;
} t_pipe;
/// @brief Create a pipe
/// @param[out] out the created pipe
/// @return the error
t_error create_pipe(t_pipe *out);
#endif /* PIPE_H */

View file

@ -41,12 +41,16 @@ union u_redirection
} inherited;
};
/// @brief Redirection for spawning a process
typedef struct s_redirection
{
enum e_redirection tag;
union u_redirection vals;
} t_redirection;
/// @brief Create a piped redirection
/// @param void
/// @return the redirection
static inline t_redirection piped(void)
{
return ((t_redirection){
@ -54,6 +58,9 @@ static inline t_redirection piped(void)
});
}
/// @brief Create an inherited redirection (inherit from the parent process)
/// @param void
/// @return the redirection
static inline t_redirection inherited(void)
{
return ((t_redirection){
@ -61,12 +68,16 @@ static inline t_redirection inherited(void)
});
}
/// @brief Create a file descriptor redirection
/// @param fd file descriptor to redirect
/// @return the redirection
static inline t_redirection fd(t_file fd)
{
return ((t_redirection){.tag = R_FD, \
.vals = (union u_redirection){.fd = {.value = fd},}});
}
/// @brief Wrapped file descriptor tag
enum e_wrapped_fd_tag
{
READ_ONLY,
@ -75,6 +86,7 @@ enum e_wrapped_fd_tag
INVALID,
};
/// @brief Wrapped file descriptor
union u_wrapped_fd
{
struct s_read_only
@ -91,12 +103,16 @@ union u_wrapped_fd
} rw;
};
/// @brief Wrapped file descriptor
typedef struct s_wrapped_fd
{
enum e_wrapped_fd_tag tag;
union u_wrapped_fd vals;
} t_wrapped_fd;
/// @brief Create a Read only wrapped file descriptor
/// @param fd file descriptor to wrap
/// @return the wrapped file descriptor
static inline t_wrapped_fd ro(t_file fd)
{
return ((t_wrapped_fd){.tag = READ_ONLY,
@ -105,12 +121,16 @@ static inline t_wrapped_fd ro(t_file fd)
}});
}
/// @brief Create a Write only wrapped file descriptor
/// @param fd file descriptor to wrap
/// @return the wrapped file descriptor
static inline t_wrapped_fd wo(t_file fd)
{
return ((t_wrapped_fd){.tag = WRITE_ONLY,
.vals = (union u_wrapped_fd){.wo = {.fd = fd}}});
}
/// @brief Spawn information
typedef struct s_spawn_info
{
t_redirection stdin;
@ -123,6 +143,7 @@ typedef struct s_spawn_info
void *forked_free_args;
} t_spawn_info;
/// @brief Process information
typedef struct s_process
{
t_wrapped_fd stdin;
@ -130,7 +151,8 @@ typedef struct s_process
t_wrapped_fd stderr;
t_pid pid;
} t_process;
/// @struct Process output
/// @brief Process output information
typedef struct s_process_output
{
t_pid pid;
@ -139,6 +161,11 @@ 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
t_error spawn_process(t_spawn_info info,
t_process *process);

View file

@ -61,9 +61,28 @@ typedef struct s_printf_args
typedef void (*t_printf_func)(t_const_str to_write,
t_usize to_write_len, void *p_args);
/// @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, ...);
/// @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, ...);
/// @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);
/// @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);
#endif

View file

@ -1,20 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* quit.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/07 12:54:50 by maiboyer #+# #+# */
/* Updated: 2024/05/07 12:55:08 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef QUIT_H
#define QUIT_H
#include "me/types.h"
void quit(t_i32 exit_code);
#endif /* QUIT_H */

113
stdme/include/me/str/str.h Normal file
View file

@ -0,0 +1,113 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* str.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* 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 */
/* */
/* ************************************************************************** */
#ifndef STR_H
#define STR_H
#include "me/types.h"
/// @brief Get the length of a string
/// @param str the string
/// @return the length of the string
t_usize str_len(t_const_str str);
/// @brief Clone a string
/// @param source the string to clone
/// @return the cloned string
t_str str_clone(t_const_str source);
/// @brief Get a substring of a string
/// @param str the string to operate on
/// @param start the start index of the substring
/// @param len the length of the substring
/// @return the substring
t_str str_substring(t_const_str str, t_usize start, t_usize len);
/// @brief Compare two strings
/// @param lhs left hand side string
/// @param rhs right hand side string
/// @return true if the strings are equal, false otherwise
bool str_compare(t_const_str lhs, t_const_str rhs);
/// @brief Compare two strings up to n characters
/// @param lhs left hand side string
/// @param rhs right hand side string
/// @param n the maximum number of characters to compare
/// @return true if the strings are equal, false otherwise
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);
/// @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);
/// @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);
/// @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);
/// @brief Join two string together
/// @param s1 First string
/// @param s2 Second string
/// @return the joined string
t_str str_join(t_const_str s1, t_const_str s2);
/// @brief Concatenate two strings
/// @param dest the destination string
/// @param src the source string
/// @param buffer_size the size of the destination buffer
/// @return the length of the concatenated string
t_usize str_l_cat(t_str dest, t_const_str src, t_usize buffer_size);
/// @brief Copy a string
/// @param dest the destination string
/// @param src the source string
/// @param buffer_size the size of the destination buffer
/// @return the length of the copied string
t_usize str_l_copy(t_str dest, t_const_str src, t_usize buffer_size);
/// @brief run a function over each character of a string
/// @param s the string to iterate over
/// @param f the function to run over each character
void str_iter(t_str s, void (*f)(t_usize, char *));
/// @brief run a function over each character of a string
/// @param s the string to iterate over
/// @param f the function to run over each character
/// @return the mapped string
t_str str_map(t_const_str s, char (*f)(t_usize, char));
/// @brief Split a string into a vector of strings
/// @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);
/// @brief Remove consecutive leading and trailing characters from a string
/// @param str the string to trim
/// @param charset the characters to remove
/// @return the trimmed string
t_str str_trim(t_const_str str, t_const_str charset);
#endif /* STR_H */

View file

@ -1,20 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* str_clone.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/06 16:05:48 by maiboyer #+# #+# */
/* Updated: 2023/12/11 17:30:19 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef STR_CLONE_H
# define STR_CLONE_H
# include "me/types.h"
t_str str_clone(t_const_str source);
#endif

View file

@ -1,20 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* str_compare.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/04 18:53:47 by maiboyer #+# #+# */
/* Updated: 2024/05/04 18:37:55 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef STR_COMPARE_H
# define STR_COMPARE_H
# include "me/types.h"
bool str_compare(t_const_str lhs, t_const_str rhs);
#endif

View file

@ -1,20 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* str_find_chr.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/04 17:29:13 by maiboyer #+# #+# */
/* Updated: 2023/12/09 16:07:01 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef STR_FIND_CHR_H
# define STR_FIND_CHR_H
# include "me/types.h"
char *str_find_chr(t_const_str str, char chr);
#endif

View file

@ -1,20 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* str_find_rev_chr.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/04 17:29:13 by maiboyer #+# #+# */
/* Updated: 2023/12/09 16:07:15 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef STR_FIND_REV_CHR_H
# define STR_FIND_REV_CHR_H
# include "me/types.h"
char *str_find_rev_chr(t_const_str str, char chr);
#endif

View file

@ -1,20 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* str_find_str.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/08/10 11:11:01 by maiboyer #+# #+# */
/* Updated: 2023/12/09 16:53:44 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef STR_FIND_STR_H
# define STR_FIND_STR_H
# include "me/types.h"
const char *str_find_str(t_const_str str, t_const_str to_find);
#endif

View file

@ -1,20 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* str_iter.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/09 18:26:00 by maiboyer #+# #+# */
/* Updated: 2023/12/09 16:08:09 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef STR_ITER_H
# define STR_ITER_H
# include "me/types.h"
void str_iter(t_str s, void (*f)(t_usize, char *));
#endif

View file

@ -1,20 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* str_join.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/07 23:02:58 by maiboyer #+# #+# */
/* Updated: 2023/12/09 16:08:32 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef STR_JOIN_H
# define STR_JOIN_H
# include "me/types.h"
t_str str_join(t_const_str s1, t_const_str s2);
#endif

View file

@ -1,20 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* str_l_cat.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/08/09 18:01:09 by maiboyer #+# #+# */
/* Updated: 2023/12/09 16:09:07 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef STR_L_CAT_H
# define STR_L_CAT_H
# include "me/types.h"
t_usize str_l_cat(t_str dest, t_const_str src, t_usize buffer_size);
#endif

View file

@ -1,20 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* str_l_copy.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/08/09 18:01:09 by maiboyer #+# #+# */
/* Updated: 2023/12/09 16:09:38 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef STR_L_COPY_H
# define STR_L_COPY_H
# include "me/types.h"
t_usize str_l_copy(t_str dest, t_const_str src, t_usize buffer_size);
#endif

View file

@ -1,20 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* str_len.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/04 17:07:41 by maiboyer #+# #+# */
/* Updated: 2023/12/11 16:08:07 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef STR_LEN_H
# define STR_LEN_H
# include "me/types.h"
t_usize str_len(t_const_str str);
#endif

View file

@ -1,20 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* str_map.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/09 18:26:00 by maiboyer #+# #+# */
/* Updated: 2023/12/09 16:11:40 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef STR_MAP_H
# define STR_MAP_H
# include "me/types.h"
t_str str_map(t_const_str s, char (*f)(t_usize, char));
#endif

View file

@ -1,20 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* str_n_compare.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/04 18:53:47 by maiboyer #+# #+# */
/* Updated: 2023/12/09 16:17:14 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef STR_N_COMPARE_H
# define STR_N_COMPARE_H
# include "me/types.h"
t_i32 str_n_compare(t_const_str lhs, t_const_str rhs, t_usize n);
#endif

View file

@ -1,20 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* str_n_find_str.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/08/10 11:11:01 by maiboyer #+# #+# */
/* Updated: 2023/12/09 16:53:35 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef STR_N_FIND_STR_H
# define STR_N_FIND_STR_H
# include "me/types.h"
const char *str_n_find_str(t_const_str str, t_const_str to_find, t_usize len);
#endif

View file

@ -1,20 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* str_split.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/08/17 15:56:59 by maiboyer #+# #+# */
/* Updated: 2023/12/09 16:18:07 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef STR_SPLIT_H
# define STR_SPLIT_H
# include "me/types.h"
t_str *str_split(t_const_str str, char chr);
#endif

View file

@ -1,20 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* str_substring.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/07 22:42:55 by maiboyer #+# #+# */
/* Updated: 2023/12/09 16:18:41 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef STR_SUBSTRING_H
# define STR_SUBSTRING_H
# include "me/types.h"
t_str str_substring(t_const_str str, t_usize start, t_usize len);
#endif

View file

@ -1,20 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* str_trim.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/07 23:43:42 by maiboyer #+# #+# */
/* Updated: 2023/12/09 16:19:11 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef STR_TRIM_H
# define STR_TRIM_H
# include "me/types.h"
t_str str_trim(t_const_str str, t_const_str charset);
#endif

View file

@ -0,0 +1,77 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* string.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/16 17:54:28 by maiboyer #+# #+# */
/* Updated: 2024/04/30 14:14:42 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef STRING_H
# define STRING_H
# include "me/types.h"
typedef struct s_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);
/// @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);
/// @brief Clear a string
/// @param buf the string to clear
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);
/// @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);
/// @brief free a string
/// @param buf the string to free
static inline void string_free(t_string buf)
{
void mem_free(void *);
mem_free(buf.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)
{
char c;
c = '\0';
if (buf->buf && buf->len)
{
c = buf->buf[buf->len - 1];
buf->buf[buf->len - 1] = '\0';
}
return (c);
}
#endif

View file

@ -22,30 +22,57 @@
#include <stdint.h>
#include <unistd.h>
/// @brief A string, null terminated
typedef char *t_str;
/// @brief A constant string, null terminated
typedef const char *t_const_str;
/// @brief an unsigned 8 bit integer
typedef uint8_t t_u8;
/// @brief a signed 8 bit integer
typedef int8_t t_i8;
/// @brief an unsigned 16 bit integer
typedef uint16_t t_u16;
/// @brief a signed 16 bit integer
typedef int16_t t_i16;
/// @brief an unsigned 32 bit integer
typedef uint32_t t_u32;
/// @brief a signed 32 bit integer
typedef int32_t t_i32;
/// @brief an unsigned 64 bit integer
typedef uint64_t t_u64;
/// @brief a signed 64 bit integer
typedef int64_t t_i64;
/// @brief a signed integer that can hold a pointer
typedef ssize_t t_isize;
/// @brief an unsigned integer that can hold a pointer
typedef size_t t_usize;
/// @brief a 32 bit floating point number
typedef float t_f32;
/// @brief a 64 bit floating point number
typedef double t_f64;
/// @brief a file descriptor
typedef int t_file;
/// @brief a boolean value that represents an error
/// @note true is an error, false is no 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);
/// @brief a function that denotes a normal end of the program
/// @param code the exit code
void me_exit(t_i32 code);
/// @brief a function that prints the current stack trace
void print_trace(void);
/// @def signal that an error occured
#define ERROR 1
/// @def signal that no error occured
#define NO_ERROR 0
#endif

View file

@ -33,28 +33,53 @@ typedef struct s_vf2d
t_f32 y;
} t_vf2d;
/// @brief Create a 2D float vector
/// @param x The x component
/// @param y The y component
/// @return The created vector
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
/// @return The created vector
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
/// @return The created vector
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
/// @return The result of the addition
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
/// @return The result of the substraction
static inline t_vi2d vi2d_sub(t_vi2d lhs, t_vi2d rhs)
{
return ((t_vi2d){.x = lhs.x - rhs.x, .y = lhs.y - rhs.y});
}
#endif /* VEC2_H */