update stuff
This commit is contained in:
parent
5973022688
commit
544ed8b045
194 changed files with 2060 additions and 1464 deletions
|
|
@ -25,16 +25,25 @@ C__TYPEHEADER__
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
/// @struct A key-value pair for the hashmap
|
||||
typedef struct s_kv_C__PREFIX__
|
||||
{
|
||||
C__KEYTYPE__ key;
|
||||
C__VALTYPE__ val;
|
||||
} t_kv_C__PREFIX__;
|
||||
|
||||
/// @typedef A function that hashes a key
|
||||
typedef void (*t_hash_C__PREFIX___fn)(t_hasher *hasher, C__KEYTYPE__ *key);
|
||||
/// @typedef A function that drops a key-value pair
|
||||
typedef void (*t_drop_C__PREFIX___fn)(t_kv_C__PREFIX__ val);
|
||||
/// @typedef A function that compares two keys and returns true if they are equal
|
||||
typedef bool (*t_eq_C__PREFIX___fn)(C__KEYTYPE__ *lhs, C__KEYTYPE__ *rhs);
|
||||
|
||||
|
||||
/// @struct A single entry in the hashmap
|
||||
/// @var hash_id The hash of the key
|
||||
/// @var kv The key-value pair
|
||||
/// @var next The next entry in the bucket
|
||||
typedef struct s_entry_C__PREFIX__
|
||||
{
|
||||
t_usize hash_id;
|
||||
|
|
@ -42,6 +51,13 @@ typedef struct s_entry_C__PREFIX__
|
|||
struct s_entry_C__PREFIX__ *next;
|
||||
} t_entry_C__PREFIX__;
|
||||
|
||||
/// @struct A hashmap of keys C__KEYTYPE__ and values C__VALTYPE__
|
||||
/// @var buckets The array of buckets
|
||||
/// @var num_buckets The number of buckets
|
||||
/// @var hasher The hasher function
|
||||
/// @var hfunc The hash function
|
||||
/// @var cfunc The comparison function
|
||||
/// @var drop The drop function
|
||||
typedef struct s_hashmap_C__PREFIX__
|
||||
{
|
||||
t_entry_C__PREFIX__ **buckets;
|
||||
|
|
@ -52,31 +68,56 @@ typedef struct s_hashmap_C__PREFIX__
|
|||
t_drop_C__PREFIX___fn drop;
|
||||
} t_hashmap_C__PREFIX__;
|
||||
|
||||
t_hashmap_C__PREFIX__ *new_hashmap_C__PREFIX__(t_hash_C__PREFIX___fn hash,
|
||||
t_eq_C__PREFIX___fn cmp,
|
||||
t_drop_C__PREFIX___fn drop);
|
||||
t_hashmap_C__PREFIX__ *new_hashmap_with_buckets_C__PREFIX__(
|
||||
t_hash_C__PREFIX___fn hash, t_eq_C__PREFIX___fn cmp,
|
||||
t_drop_C__PREFIX___fn drop, size_t cap);
|
||||
/// @brief Creates a new hashmap with the given hash, comparison, and drop functions
|
||||
/// @param hash The hash function
|
||||
/// @param cmp The comparison function
|
||||
/// @param drop The drop function
|
||||
/// @return A new hashmap
|
||||
t_hashmap_C__PREFIX__ *hmap_new_C__PREFIX__(t_hash_C__PREFIX___fn hash, t_eq_C__PREFIX___fn cmp, t_drop_C__PREFIX___fn drop);
|
||||
|
||||
void drop_hashmap_C__PREFIX__(t_hashmap_C__PREFIX__ *hmap);
|
||||
/// @brief Creates a new hashmap with the given hash, comparison, and drop functions
|
||||
/// @param hash The hash function
|
||||
/// @param cmp The comparison function
|
||||
/// @param drop The drop function
|
||||
/// @param cap The number of buckets
|
||||
/// @return A new hashmap
|
||||
t_hashmap_C__PREFIX__ *hmap_new_with_buckets_C__PREFIX__(t_hash_C__PREFIX___fn hash, t_eq_C__PREFIX___fn cmp, t_drop_C__PREFIX___fn drop, size_t cap);
|
||||
|
||||
void insert_hashmap_C__PREFIX__(t_hashmap_C__PREFIX__ *hmap, C__KEYTYPE__ key,
|
||||
C__VALTYPE__ value);
|
||||
/// @brief Drops the hashmap and all of its entries
|
||||
/// @param hmap The hashmap to drop
|
||||
void hmap_free_C__PREFIX__(t_hashmap_C__PREFIX__ *hmap);
|
||||
|
||||
C__VALTYPE__ *get_hashmap_C__PREFIX__(t_hashmap_C__PREFIX__ *hmap,
|
||||
C__KEYTYPE__ *key);
|
||||
void remove_hashmap_C__PREFIX__(t_hashmap_C__PREFIX__ *hmap, C__KEYTYPE__ *key);
|
||||
/// @brief Inserts a key-value pair into the hashmap
|
||||
/// @param hmap The hashmap
|
||||
/// @param key The key
|
||||
/// @param value The value
|
||||
void hmap_insert_C__PREFIX__(t_hashmap_C__PREFIX__ *hmap, C__KEYTYPE__ key, C__VALTYPE__ value);
|
||||
|
||||
t_entry_C__PREFIX__ *hashmap_get_entry_C__PREFIX__(t_hashmap_C__PREFIX__ *hmap,
|
||||
t_usize hash,
|
||||
C__KEYTYPE__ *key,
|
||||
t_entry_C__PREFIX__ **prev);
|
||||
/// @brief Gets the value associated with the key
|
||||
/// @param hmap The hashmap
|
||||
/// @param key The key
|
||||
/// @return The value associated with the key, or NULL if the key is not in the hashmap
|
||||
C__VALTYPE__ *hmap_get_C__PREFIX__(t_hashmap_C__PREFIX__ *hmap, C__KEYTYPE__ *key);
|
||||
/// @brief Removes the key-value pair from the hashmap
|
||||
/// @param hmap The hashmap
|
||||
/// @param key The key
|
||||
void hmap_remove_C__PREFIX__(t_hashmap_C__PREFIX__ *hmap, C__KEYTYPE__ *key);
|
||||
|
||||
t_error hashmap_C__PREFIX___iter(t_hashmap_C__PREFIX__ *self,
|
||||
t_error (*func)(t_usize idx,
|
||||
const C__KEYTYPE__ *key,
|
||||
C__VALTYPE__ *val, void *ctx),
|
||||
void *ctx);
|
||||
/// @brief Get an entry from the hashmap
|
||||
/// @param hmap The hashmap
|
||||
/// @param hash The hash of the key
|
||||
/// @param key The key
|
||||
/// @param prev The previous entry in the bucket
|
||||
/// @return The entry, or NULL if the key is not in the hashmap
|
||||
/// @note this is an internal function
|
||||
t_entry_C__PREFIX__ *hmap_get_entry_C__PREFIX__(t_hashmap_C__PREFIX__ *hmap, t_usize hash, C__KEYTYPE__ *key, t_entry_C__PREFIX__ **prev);
|
||||
|
||||
/// @brief Iterates over the hashmap and calls the given function for each key-value pair
|
||||
/// @param self The hashmap
|
||||
/// @param func The function to call
|
||||
/// @param ctx The context to pass to the function
|
||||
/// @return An error code
|
||||
/// @note The iteration can be stopped by returning an error code from the function
|
||||
t_error hmap_C__PREFIX___iter(t_hashmap_C__PREFIX__ *self, t_error (*func)(t_usize idx, const C__KEYTYPE__ *key, C__VALTYPE__ *val, void *ctx), void *ctx);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -16,9 +16,12 @@
|
|||
C__TYPEHEADER__
|
||||
#include "me/types.h"
|
||||
|
||||
/// @brief A function that takes two C__TYPENAME__ and compare them
|
||||
typedef bool (*t_vec_C__PREFIX___sort_fn)(C__TYPENAME__ *, C__TYPENAME__ *);
|
||||
/// @brief A function that free an C__TYPENAME__
|
||||
typedef void (*t_free_C__PREFIX___item)(C__TYPENAME__);
|
||||
|
||||
/// @brief A dynamic array of C__TYPENAME__
|
||||
typedef struct s_vec_C__PREFIX__
|
||||
{
|
||||
t_free_C__PREFIX___item free_func;
|
||||
|
|
@ -27,32 +30,94 @@ typedef struct s_vec_C__PREFIX__
|
|||
C__TYPENAME__ *buffer;
|
||||
} t_vec_C__PREFIX__;
|
||||
|
||||
t_vec_C__PREFIX__ vec_C__PREFIX___new(t_usize capacity,
|
||||
t_free_C__PREFIX___item free_function);
|
||||
/// @brief Create a new vec_C__PREFIX__ with a given capacity
|
||||
/// @param capacity The capacity of the new vec_C__PREFIX__ (in terms of elements)
|
||||
/// @param free_function The function that will be used to free the elements of the vec_C__PREFIX__
|
||||
t_vec_C__PREFIX__ vec_C__PREFIX___new(t_usize capacity, t_free_C__PREFIX___item free_function);
|
||||
/// @brief Push an element to the last position of the vec_C__PREFIX__
|
||||
/// @param vec The vec_C__PREFIX__ to push the element to
|
||||
/// @param element The element to push
|
||||
t_error vec_C__PREFIX___push(t_vec_C__PREFIX__ *vec, C__TYPENAME__ element);
|
||||
t_error vec_C__PREFIX___push_front(t_vec_C__PREFIX__ *vec,
|
||||
C__TYPENAME__ element);
|
||||
|
||||
/// @brief Push an element to the first position of the vec_C__PREFIX__
|
||||
/// @param vec The vec_C__PREFIX__ to push the element to
|
||||
/// @param element The element to push
|
||||
/// @note This operation is O(n)
|
||||
t_error vec_C__PREFIX___push_front(t_vec_C__PREFIX__ *vec, C__TYPENAME__ element);
|
||||
|
||||
/// @brief Get the last element from the vec_C__PREFIX__, and remove it from the vec_C__PREFIX__
|
||||
/// @param vec The vec_C__PREFIX__ to get the element from
|
||||
/// @param[out] out The last element of the vec_C__PREFIX__
|
||||
/// @return true if the operation failed, false otherwise
|
||||
t_error vec_C__PREFIX___pop(t_vec_C__PREFIX__ *vec, C__TYPENAME__ *value);
|
||||
|
||||
|
||||
/// @brief Get the first element from the vec_C__PREFIX__, and remove it from the vec_C__PREFIX__
|
||||
/// @param vec The vec_C__PREFIX__ to get the element from
|
||||
/// @param[out] out The first element of the vec_C__PREFIX__
|
||||
/// @return true if the operation failed, false otherwise
|
||||
/// @note This operation is O(n)
|
||||
t_error vec_C__PREFIX___pop_front(t_vec_C__PREFIX__ *vec, C__TYPENAME__ *value);
|
||||
|
||||
/// @brief Free the vector and all its elements
|
||||
/// @param vec The vec_C__PREFIX__ to free
|
||||
void vec_C__PREFIX___free(t_vec_C__PREFIX__ vec);
|
||||
t_error vec_C__PREFIX___reserve(t_vec_C__PREFIX__ *vec,
|
||||
t_usize wanted_capacity);
|
||||
t_error vec_C__PREFIX___find(t_vec_C__PREFIX__ *vec,
|
||||
bool (*fn)(const C__TYPENAME__ *), t_usize *index);
|
||||
t_error vec_C__PREFIX___find_starting(t_vec_C__PREFIX__ *vec,
|
||||
bool (*fn)(const C__TYPENAME__ *),
|
||||
t_usize starting_index, t_usize *index);
|
||||
t_error vec_C__PREFIX___all(t_vec_C__PREFIX__ *vec,
|
||||
bool (*fn)(const C__TYPENAME__ *), bool *result);
|
||||
t_error vec_C__PREFIX___any(t_vec_C__PREFIX__ *vec,
|
||||
bool (*fn)(const C__TYPENAME__ *), bool *result);
|
||||
void vec_C__PREFIX___iter(t_vec_C__PREFIX__ *vec,
|
||||
void (*fn)(t_usize index, C__TYPENAME__ *value,
|
||||
void *state),
|
||||
void *state);
|
||||
|
||||
/// @brief Make the vec_C__PREFIX__ at least the given capacity
|
||||
/// @param vec The vec_C__PREFIX__ to reserve
|
||||
/// @param wanted_capacity The minimum capacity to reserve
|
||||
/// @return true if the operation failed, false otherwise
|
||||
t_error vec_C__PREFIX___reserve(t_vec_C__PREFIX__ *vec, t_usize wanted_capacity);
|
||||
|
||||
/// @brief Run the function and returns the index of the first element that returns true
|
||||
/// @param vec The vec_C__PREFIX__ to search in
|
||||
/// @param fn The function to run on each element
|
||||
/// @param[out] index The index of the first element that returns true
|
||||
t_error vec_C__PREFIX___find(t_vec_C__PREFIX__ *vec, bool (*fn)(const C__TYPENAME__ *), t_usize *index);
|
||||
|
||||
|
||||
/// @brief Run the function and returns the index of the first element that returns true, but starting at index starting_index
|
||||
/// @param vec The vec_C__PREFIX__ to search in
|
||||
/// @param fn The function to run on each element
|
||||
/// @param starting_index The index to start the search from
|
||||
/// @param[out] index The index of the first element that returns true
|
||||
t_error vec_C__PREFIX___find_starting(t_vec_C__PREFIX__ *vec, bool (*fn)(const C__TYPENAME__ *), t_usize starting_index, t_usize *index);
|
||||
|
||||
/// @brief Run the function on every element of the vec_C__PREFIX__ and returns if all elements returned true
|
||||
/// @param vec The vec_C__PREFIX__ to search in
|
||||
/// @param fn The function to run on each element
|
||||
/// @param[out] result The result of the operation
|
||||
/// @return true if the operation failed, false otherwise
|
||||
/// @note If the vec_C__PREFIX__ is empty, result will be true
|
||||
t_error vec_C__PREFIX___all(t_vec_C__PREFIX__ *vec, bool (*fn)(const C__TYPENAME__ *), bool *result);
|
||||
|
||||
/// @brief Run the function on every element of the vec_C__PREFIX__ and returns if any element returned true
|
||||
/// @param vec The vec_C__PREFIX__ to search in
|
||||
/// @param fn The function to run on each element
|
||||
/// @param[out] result The result of the operation
|
||||
/// @return true if the operation failed, false otherwise
|
||||
/// @note If the vec_C__PREFIX__ is empty, result will be false
|
||||
t_error vec_C__PREFIX___any(t_vec_C__PREFIX__ *vec, bool (*fn)(const C__TYPENAME__ *), bool *result);
|
||||
|
||||
/// @brief Run the function on every element of the vec_C__PREFIX__
|
||||
/// @param vec The vec_C__PREFIX__ to iterate over
|
||||
/// @param fn The function to run on each element
|
||||
/// @param state The state to pass to the function
|
||||
void vec_C__PREFIX___iter(t_vec_C__PREFIX__ *vec, void (*fn)(t_usize index, C__TYPENAME__ *value, void *state), void *state);
|
||||
|
||||
/// @brief Reverse the order of the elements in the vec_C__PREFIX__
|
||||
/// @param vec The vec_C__PREFIX__ to reverse
|
||||
void vec_C__PREFIX___reverse(t_vec_C__PREFIX__ *vec);
|
||||
void vec_C__PREFIX___sort(t_vec_C__PREFIX__ *vec,
|
||||
t_vec_C__PREFIX___sort_fn is_sorted);
|
||||
|
||||
/// @brief Sort the elements of the vec_C__PREFIX__
|
||||
/// @param vec The vec_C__PREFIX__ to sort
|
||||
/// @param is_sorted The function to use to compare the elements
|
||||
void vec_C__PREFIX___sort(t_vec_C__PREFIX__ *vec, t_vec_C__PREFIX___sort_fn is_sorted);
|
||||
|
||||
/// @brief Get a pointer to the last element of the vec_C__PREFIX__
|
||||
/// @param vec The vec_C__PREFIX__ to get the element from
|
||||
/// @param[out] out A pointer to the last element of the vec_C__PREFIX__
|
||||
/// @return true if the operation failed, false otherwise
|
||||
t_error vec_C__PREFIX___back(t_vec_C__PREFIX__ *vec, C__TYPENAME__ **out);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -10,9 +10,9 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/char/isalpha.h"
|
||||
#include "me/char/char.h"
|
||||
#include "me/convert/str_to_numbers.h"
|
||||
#include "me/string/str_len.h"
|
||||
#include "me/str/str.h"
|
||||
#include "me/types.h"
|
||||
|
||||
#define OP_ADD 0b0001
|
||||
|
|
|
|||
|
|
@ -11,9 +11,9 @@
|
|||
/* ************************************************************************** */
|
||||
|
||||
|
||||
#include "me/char/isalpha.h"
|
||||
#include "me/char/char.h"
|
||||
#include "me/convert/str_to_numbers.h"
|
||||
#include "me/string/str_len.h"
|
||||
#include "me/str/str.h"
|
||||
#include "me/types.h"
|
||||
#include "me/printf/printf.h"
|
||||
|
||||
|
|
|
|||
|
|
@ -14,19 +14,19 @@
|
|||
#include "me/hash/sip.h"
|
||||
#include "me/hashmap/hashmap_C__PREFIX__.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/mem/mem_copy.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/types.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
t_hashmap_C__PREFIX__ *new_hashmap_C__PREFIX__(t_hash_C__PREFIX___fn hfunc,
|
||||
t_hashmap_C__PREFIX__ *hmap_new_C__PREFIX__(t_hash_C__PREFIX___fn hfunc,
|
||||
t_eq_C__PREFIX___fn cfunc,
|
||||
t_drop_C__PREFIX___fn drop)
|
||||
{
|
||||
return (new_hashmap_with_buckets_C__PREFIX__(hfunc, cfunc, drop,
|
||||
return (hmap_new_with_buckets_C__PREFIX__(hfunc, cfunc, drop,
|
||||
DEFAULT_BUCKETS));
|
||||
}
|
||||
|
||||
t_hashmap_C__PREFIX__ *new_hashmap_with_buckets_C__PREFIX__(
|
||||
t_hashmap_C__PREFIX__ *hmap_new_with_buckets_C__PREFIX__(
|
||||
t_hash_C__PREFIX___fn hfunc, t_eq_C__PREFIX___fn cfunc,
|
||||
t_drop_C__PREFIX___fn drop, t_usize buckets)
|
||||
{
|
||||
|
|
@ -46,7 +46,7 @@ t_hashmap_C__PREFIX__ *new_hashmap_with_buckets_C__PREFIX__(
|
|||
return (hmap);
|
||||
}
|
||||
|
||||
void drop_hashmap_C__PREFIX__(t_hashmap_C__PREFIX__ *hmap)
|
||||
void hmap_free_C__PREFIX__(t_hashmap_C__PREFIX__ *hmap)
|
||||
{
|
||||
t_usize index;
|
||||
|
||||
|
|
@ -65,7 +65,7 @@ void drop_hashmap_C__PREFIX__(t_hashmap_C__PREFIX__ *hmap)
|
|||
mem_free(hmap);
|
||||
}
|
||||
|
||||
t_entry_C__PREFIX__ *hashmap_get_entry_C__PREFIX__(t_hashmap_C__PREFIX__ *hmap,
|
||||
t_entry_C__PREFIX__ *hmap_get_entry_C__PREFIX__(t_hashmap_C__PREFIX__ *hmap,
|
||||
t_usize hashed_key,
|
||||
C__KEYTYPE__ *key,
|
||||
t_entry_C__PREFIX__ **prev)
|
||||
|
|
@ -88,7 +88,7 @@ t_entry_C__PREFIX__ *hashmap_get_entry_C__PREFIX__(t_hashmap_C__PREFIX__ *hmap,
|
|||
return (NULL);
|
||||
}
|
||||
|
||||
void insert_hashmap_C__PREFIX__(t_hashmap_C__PREFIX__ *hmap, C__KEYTYPE__ key,
|
||||
void hmap_insert_C__PREFIX__(t_hashmap_C__PREFIX__ *hmap, C__KEYTYPE__ key,
|
||||
C__VALTYPE__ value)
|
||||
{
|
||||
t_usize hashed_key;
|
||||
|
|
@ -98,7 +98,7 @@ void insert_hashmap_C__PREFIX__(t_hashmap_C__PREFIX__ *hmap, C__KEYTYPE__ key,
|
|||
hmap->hfunc(&hmap->hasher, &key);
|
||||
hashed_key = hasher_reset_and_finish(&hmap->hasher);
|
||||
prev = NULL;
|
||||
entry = hashmap_get_entry_C__PREFIX__(hmap, hashed_key, &key, &prev);
|
||||
entry = hmap_get_entry_C__PREFIX__(hmap, hashed_key, &key, &prev);
|
||||
if (entry == NULL)
|
||||
{
|
||||
entry = mem_alloc(sizeof(t_entry_C__PREFIX__));
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
#include "me/hashmap/hashmap_C__PREFIX__.h"
|
||||
|
||||
t_error hashmap_C__PREFIX___iter(t_hashmap_C__PREFIX__ *self,
|
||||
t_error hmap_C__PREFIX___iter(t_hashmap_C__PREFIX__ *self,
|
||||
t_error (*func)(t_usize idx,
|
||||
const C__KEYTYPE__ *key,
|
||||
C__VALTYPE__ *val, void *ctx),
|
||||
|
|
|
|||
|
|
@ -13,11 +13,11 @@
|
|||
#include "me/hash/sip.h"
|
||||
#include "me/hashmap/hashmap_C__PREFIX__.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/mem/mem_copy.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/types.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
C__VALTYPE__ *get_hashmap_C__PREFIX__(t_hashmap_C__PREFIX__ *hmap,
|
||||
C__VALTYPE__ *hmap_get_C__PREFIX__(t_hashmap_C__PREFIX__ *hmap,
|
||||
C__KEYTYPE__ *key)
|
||||
{
|
||||
t_usize hashed_key;
|
||||
|
|
@ -26,13 +26,13 @@ C__VALTYPE__ *get_hashmap_C__PREFIX__(t_hashmap_C__PREFIX__ *hmap,
|
|||
|
||||
hmap->hfunc(&hmap->hasher, key);
|
||||
hashed_key = hasher_reset_and_finish(&hmap->hasher);
|
||||
entry = hashmap_get_entry_C__PREFIX__(hmap, hashed_key, key, &prev);
|
||||
entry = hmap_get_entry_C__PREFIX__(hmap, hashed_key, key, &prev);
|
||||
if (entry == NULL)
|
||||
return (NULL);
|
||||
return (&entry->kv.val);
|
||||
}
|
||||
|
||||
void remove_hashmap_C__PREFIX__(t_hashmap_C__PREFIX__ *hmap, C__KEYTYPE__ *key)
|
||||
void hmap_remove_C__PREFIX__(t_hashmap_C__PREFIX__ *hmap, C__KEYTYPE__ *key)
|
||||
{
|
||||
t_usize hashed_key;
|
||||
t_entry_C__PREFIX__ *prev;
|
||||
|
|
@ -42,7 +42,7 @@ void remove_hashmap_C__PREFIX__(t_hashmap_C__PREFIX__ *hmap, C__KEYTYPE__ *key)
|
|||
hashed_key = hasher_reset_and_finish(&hmap->hasher);
|
||||
hmap->hasher = hasher_sip13_new();
|
||||
prev = NULL;
|
||||
entry = hashmap_get_entry_C__PREFIX__(hmap, hashed_key, key, &prev);
|
||||
entry = hmap_get_entry_C__PREFIX__(hmap, hashed_key, key, &prev);
|
||||
if (entry == NULL)
|
||||
return;
|
||||
if (prev == NULL)
|
||||
|
|
|
|||
|
|
@ -10,9 +10,9 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/mem/mem_alloc_array.h"
|
||||
#include "me/mem/mem_copy.h"
|
||||
#include "me/mem/mem_set_zero.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/types.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/vec/vec_C__PREFIX__.h"
|
||||
|
|
|
|||
|
|
@ -10,9 +10,9 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/mem/mem_alloc_array.h"
|
||||
#include "me/mem/mem_copy.h"
|
||||
#include "me/mem/mem_set_zero.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/types.h"
|
||||
#include "me/vec/vec_C__PREFIX__.h"
|
||||
#include <stdlib.h>
|
||||
|
|
|
|||
|
|
@ -10,9 +10,9 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/mem/mem_alloc_array.h"
|
||||
#include "me/mem/mem_copy.h"
|
||||
#include "me/mem/mem_set_zero.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/types.h"
|
||||
#include "me/vec/vec_C__PREFIX__.h"
|
||||
#include <stdlib.h>
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
63
stdme/include/me/char/char.h
Normal file
63
stdme/include/me/char/char.h
Normal 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 */
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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
91
stdme/include/me/fs/fs.h
Normal 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 */
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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 */
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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 */
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
113
stdme/include/me/str/str.h
Normal 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 */
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
77
stdme/include/me/string/string.h
Normal file
77
stdme/include/me/string/string.h
Normal 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
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
|
|
|
|||
|
|
@ -146,7 +146,7 @@ replace.C__PREFIXUP__ = "STR"
|
|||
[[create.vec]]
|
||||
sources_output = "src/vec/C__PREFIX__"
|
||||
headers_output = "include/me/vec/"
|
||||
replace.C__TYPENAME__ = "t_buffer_str"
|
||||
replace.C__TYPEHEADER__ = '#include "me/buffered_str/buf_str.h"'
|
||||
replace.C__TYPENAME__ = "t_string"
|
||||
replace.C__TYPEHEADER__ = '#include "me/string/string.h"'
|
||||
replace.C__PREFIX__ = "buf_str"
|
||||
replace.C__PREFIXUP__ = "BUF_STR"
|
||||
|
|
|
|||
|
|
@ -13,46 +13,111 @@
|
|||
#ifndef VEC_BUF_STR_H
|
||||
#define VEC_BUF_STR_H
|
||||
|
||||
#include "me/buffered_str/buf_str.h"
|
||||
#include "me/string/string.h"
|
||||
#include "me/types.h"
|
||||
|
||||
typedef bool (*t_vec_buf_str_sort_fn)(t_buffer_str *, t_buffer_str *);
|
||||
typedef void (*t_free_buf_str_item)(t_buffer_str);
|
||||
/// @brief A function that takes two t_string and compare them
|
||||
typedef bool (*t_vec_buf_str_sort_fn)(t_string *, t_string *);
|
||||
/// @brief A function that free an t_string
|
||||
typedef void (*t_free_buf_str_item)(t_string);
|
||||
|
||||
/// @brief A dynamic array of t_string
|
||||
typedef struct s_vec_buf_str
|
||||
{
|
||||
t_free_buf_str_item free_func;
|
||||
t_usize len;
|
||||
t_usize capacity;
|
||||
t_buffer_str *buffer;
|
||||
t_string *buffer;
|
||||
} t_vec_buf_str;
|
||||
|
||||
t_vec_buf_str vec_buf_str_new(t_usize capacity,
|
||||
t_free_buf_str_item free_function);
|
||||
t_error vec_buf_str_push(t_vec_buf_str *vec, t_buffer_str element);
|
||||
t_error vec_buf_str_push_front(t_vec_buf_str *vec,
|
||||
t_buffer_str element);
|
||||
t_error vec_buf_str_pop(t_vec_buf_str *vec, t_buffer_str *value);
|
||||
t_error vec_buf_str_pop_front(t_vec_buf_str *vec, t_buffer_str *value);
|
||||
/// @brief Create a new vec_buf_str with a given capacity
|
||||
/// @param capacity The capacity of the new vec_buf_str (in terms of elements)
|
||||
/// @param free_function The function that will be used to free the elements of the vec_buf_str
|
||||
t_vec_buf_str vec_buf_str_new(t_usize capacity, t_free_buf_str_item free_function);
|
||||
/// @brief Push an element to the last position of the vec_buf_str
|
||||
/// @param vec The vec_buf_str to push the element to
|
||||
/// @param element The element to push
|
||||
t_error vec_buf_str_push(t_vec_buf_str *vec, t_string element);
|
||||
|
||||
/// @brief Push an element to the first position of the vec_buf_str
|
||||
/// @param vec The vec_buf_str to push the element to
|
||||
/// @param element The element to push
|
||||
/// @note This operation is O(n)
|
||||
t_error vec_buf_str_push_front(t_vec_buf_str *vec, t_string element);
|
||||
|
||||
/// @brief Get the last element from the vec_buf_str, and remove it from the vec_buf_str
|
||||
/// @param vec The vec_buf_str to get the element from
|
||||
/// @param[out] out The last element of the vec_buf_str
|
||||
/// @return true if the operation failed, false otherwise
|
||||
t_error vec_buf_str_pop(t_vec_buf_str *vec, t_string *value);
|
||||
|
||||
|
||||
/// @brief Get the first element from the vec_buf_str, and remove it from the vec_buf_str
|
||||
/// @param vec The vec_buf_str to get the element from
|
||||
/// @param[out] out The first element of the vec_buf_str
|
||||
/// @return true if the operation failed, false otherwise
|
||||
/// @note This operation is O(n)
|
||||
t_error vec_buf_str_pop_front(t_vec_buf_str *vec, t_string *value);
|
||||
|
||||
/// @brief Free the vector and all its elements
|
||||
/// @param vec The vec_buf_str to free
|
||||
void vec_buf_str_free(t_vec_buf_str vec);
|
||||
t_error vec_buf_str_reserve(t_vec_buf_str *vec,
|
||||
t_usize wanted_capacity);
|
||||
t_error vec_buf_str_find(t_vec_buf_str *vec,
|
||||
bool (*fn)(const t_buffer_str *), t_usize *index);
|
||||
t_error vec_buf_str_find_starting(t_vec_buf_str *vec,
|
||||
bool (*fn)(const t_buffer_str *),
|
||||
t_usize starting_index, t_usize *index);
|
||||
t_error vec_buf_str_all(t_vec_buf_str *vec,
|
||||
bool (*fn)(const t_buffer_str *), bool *result);
|
||||
t_error vec_buf_str_any(t_vec_buf_str *vec,
|
||||
bool (*fn)(const t_buffer_str *), bool *result);
|
||||
void vec_buf_str_iter(t_vec_buf_str *vec,
|
||||
void (*fn)(t_usize index, t_buffer_str *value,
|
||||
void *state),
|
||||
void *state);
|
||||
|
||||
/// @brief Make the vec_buf_str at least the given capacity
|
||||
/// @param vec The vec_buf_str to reserve
|
||||
/// @param wanted_capacity The minimum capacity to reserve
|
||||
/// @return true if the operation failed, false otherwise
|
||||
t_error vec_buf_str_reserve(t_vec_buf_str *vec, t_usize wanted_capacity);
|
||||
|
||||
/// @brief Run the function and returns the index of the first element that returns true
|
||||
/// @param vec The vec_buf_str to search in
|
||||
/// @param fn The function to run on each element
|
||||
/// @param[out] index The index of the first element that returns true
|
||||
t_error vec_buf_str_find(t_vec_buf_str *vec, bool (*fn)(const t_string *), t_usize *index);
|
||||
|
||||
|
||||
/// @brief Run the function and returns the index of the first element that returns true, but starting at index starting_index
|
||||
/// @param vec The vec_buf_str to search in
|
||||
/// @param fn The function to run on each element
|
||||
/// @param starting_index The index to start the search from
|
||||
/// @param[out] index The index of the first element that returns true
|
||||
t_error vec_buf_str_find_starting(t_vec_buf_str *vec, bool (*fn)(const t_string *), t_usize starting_index, t_usize *index);
|
||||
|
||||
/// @brief Run the function on every element of the vec_buf_str and returns if all elements returned true
|
||||
/// @param vec The vec_buf_str to search in
|
||||
/// @param fn The function to run on each element
|
||||
/// @param[out] result The result of the operation
|
||||
/// @return true if the operation failed, false otherwise
|
||||
/// @note If the vec_buf_str is empty, result will be true
|
||||
t_error vec_buf_str_all(t_vec_buf_str *vec, bool (*fn)(const t_string *), bool *result);
|
||||
|
||||
/// @brief Run the function on every element of the vec_buf_str and returns if any element returned true
|
||||
/// @param vec The vec_buf_str to search in
|
||||
/// @param fn The function to run on each element
|
||||
/// @param[out] result The result of the operation
|
||||
/// @return true if the operation failed, false otherwise
|
||||
/// @note If the vec_buf_str is empty, result will be false
|
||||
t_error vec_buf_str_any(t_vec_buf_str *vec, bool (*fn)(const t_string *), bool *result);
|
||||
|
||||
/// @brief Run the function on every element of the vec_buf_str
|
||||
/// @param vec The vec_buf_str to iterate over
|
||||
/// @param fn The function to run on each element
|
||||
/// @param state The state to pass to the function
|
||||
void vec_buf_str_iter(t_vec_buf_str *vec, void (*fn)(t_usize index, t_string *value, void *state), void *state);
|
||||
|
||||
/// @brief Reverse the order of the elements in the vec_buf_str
|
||||
/// @param vec The vec_buf_str to reverse
|
||||
void vec_buf_str_reverse(t_vec_buf_str *vec);
|
||||
void vec_buf_str_sort(t_vec_buf_str *vec,
|
||||
t_vec_buf_str_sort_fn is_sorted);
|
||||
t_error vec_buf_str_back(t_vec_buf_str *vec, t_buffer_str **out);
|
||||
|
||||
/// @brief Sort the elements of the vec_buf_str
|
||||
/// @param vec The vec_buf_str to sort
|
||||
/// @param is_sorted The function to use to compare the elements
|
||||
void vec_buf_str_sort(t_vec_buf_str *vec, t_vec_buf_str_sort_fn is_sorted);
|
||||
|
||||
/// @brief Get a pointer to the last element of the vec_buf_str
|
||||
/// @param vec The vec_buf_str to get the element from
|
||||
/// @param[out] out A pointer to the last element of the vec_buf_str
|
||||
/// @return true if the operation failed, false otherwise
|
||||
t_error vec_buf_str_back(t_vec_buf_str *vec, t_string **out);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -16,9 +16,12 @@
|
|||
|
||||
#include "me/types.h"
|
||||
|
||||
/// @brief A function that takes two t_str and compare them
|
||||
typedef bool (*t_vec_str_sort_fn)(t_str *, t_str *);
|
||||
/// @brief A function that free an t_str
|
||||
typedef void (*t_free_str_item)(t_str);
|
||||
|
||||
/// @brief A dynamic array of t_str
|
||||
typedef struct s_vec_str
|
||||
{
|
||||
t_free_str_item free_func;
|
||||
|
|
@ -27,32 +30,94 @@ typedef struct s_vec_str
|
|||
t_str *buffer;
|
||||
} t_vec_str;
|
||||
|
||||
t_vec_str vec_str_new(t_usize capacity,
|
||||
t_free_str_item free_function);
|
||||
/// @brief Create a new vec_str with a given capacity
|
||||
/// @param capacity The capacity of the new vec_str (in terms of elements)
|
||||
/// @param free_function The function that will be used to free the elements of the vec_str
|
||||
t_vec_str vec_str_new(t_usize capacity, t_free_str_item free_function);
|
||||
/// @brief Push an element to the last position of the vec_str
|
||||
/// @param vec The vec_str to push the element to
|
||||
/// @param element The element to push
|
||||
t_error vec_str_push(t_vec_str *vec, t_str element);
|
||||
t_error vec_str_push_front(t_vec_str *vec,
|
||||
t_str element);
|
||||
|
||||
/// @brief Push an element to the first position of the vec_str
|
||||
/// @param vec The vec_str to push the element to
|
||||
/// @param element The element to push
|
||||
/// @note This operation is O(n)
|
||||
t_error vec_str_push_front(t_vec_str *vec, t_str element);
|
||||
|
||||
/// @brief Get the last element from the vec_str, and remove it from the vec_str
|
||||
/// @param vec The vec_str to get the element from
|
||||
/// @param[out] out The last element of the vec_str
|
||||
/// @return true if the operation failed, false otherwise
|
||||
t_error vec_str_pop(t_vec_str *vec, t_str *value);
|
||||
|
||||
|
||||
/// @brief Get the first element from the vec_str, and remove it from the vec_str
|
||||
/// @param vec The vec_str to get the element from
|
||||
/// @param[out] out The first element of the vec_str
|
||||
/// @return true if the operation failed, false otherwise
|
||||
/// @note This operation is O(n)
|
||||
t_error vec_str_pop_front(t_vec_str *vec, t_str *value);
|
||||
|
||||
/// @brief Free the vector and all its elements
|
||||
/// @param vec The vec_str to free
|
||||
void vec_str_free(t_vec_str vec);
|
||||
t_error vec_str_reserve(t_vec_str *vec,
|
||||
t_usize wanted_capacity);
|
||||
t_error vec_str_find(t_vec_str *vec,
|
||||
bool (*fn)(const t_str *), t_usize *index);
|
||||
t_error vec_str_find_starting(t_vec_str *vec,
|
||||
bool (*fn)(const t_str *),
|
||||
t_usize starting_index, t_usize *index);
|
||||
t_error vec_str_all(t_vec_str *vec,
|
||||
bool (*fn)(const t_str *), bool *result);
|
||||
t_error vec_str_any(t_vec_str *vec,
|
||||
bool (*fn)(const t_str *), bool *result);
|
||||
void vec_str_iter(t_vec_str *vec,
|
||||
void (*fn)(t_usize index, t_str *value,
|
||||
void *state),
|
||||
void *state);
|
||||
|
||||
/// @brief Make the vec_str at least the given capacity
|
||||
/// @param vec The vec_str to reserve
|
||||
/// @param wanted_capacity The minimum capacity to reserve
|
||||
/// @return true if the operation failed, false otherwise
|
||||
t_error vec_str_reserve(t_vec_str *vec, t_usize wanted_capacity);
|
||||
|
||||
/// @brief Run the function and returns the index of the first element that returns true
|
||||
/// @param vec The vec_str to search in
|
||||
/// @param fn The function to run on each element
|
||||
/// @param[out] index The index of the first element that returns true
|
||||
t_error vec_str_find(t_vec_str *vec, bool (*fn)(const t_str *), t_usize *index);
|
||||
|
||||
|
||||
/// @brief Run the function and returns the index of the first element that returns true, but starting at index starting_index
|
||||
/// @param vec The vec_str to search in
|
||||
/// @param fn The function to run on each element
|
||||
/// @param starting_index The index to start the search from
|
||||
/// @param[out] index The index of the first element that returns true
|
||||
t_error vec_str_find_starting(t_vec_str *vec, bool (*fn)(const t_str *), t_usize starting_index, t_usize *index);
|
||||
|
||||
/// @brief Run the function on every element of the vec_str and returns if all elements returned true
|
||||
/// @param vec The vec_str to search in
|
||||
/// @param fn The function to run on each element
|
||||
/// @param[out] result The result of the operation
|
||||
/// @return true if the operation failed, false otherwise
|
||||
/// @note If the vec_str is empty, result will be true
|
||||
t_error vec_str_all(t_vec_str *vec, bool (*fn)(const t_str *), bool *result);
|
||||
|
||||
/// @brief Run the function on every element of the vec_str and returns if any element returned true
|
||||
/// @param vec The vec_str to search in
|
||||
/// @param fn The function to run on each element
|
||||
/// @param[out] result The result of the operation
|
||||
/// @return true if the operation failed, false otherwise
|
||||
/// @note If the vec_str is empty, result will be false
|
||||
t_error vec_str_any(t_vec_str *vec, bool (*fn)(const t_str *), bool *result);
|
||||
|
||||
/// @brief Run the function on every element of the vec_str
|
||||
/// @param vec The vec_str to iterate over
|
||||
/// @param fn The function to run on each element
|
||||
/// @param state The state to pass to the function
|
||||
void vec_str_iter(t_vec_str *vec, void (*fn)(t_usize index, t_str *value, void *state), void *state);
|
||||
|
||||
/// @brief Reverse the order of the elements in the vec_str
|
||||
/// @param vec The vec_str to reverse
|
||||
void vec_str_reverse(t_vec_str *vec);
|
||||
void vec_str_sort(t_vec_str *vec,
|
||||
t_vec_str_sort_fn is_sorted);
|
||||
|
||||
/// @brief Sort the elements of the vec_str
|
||||
/// @param vec The vec_str to sort
|
||||
/// @param is_sorted The function to use to compare the elements
|
||||
void vec_str_sort(t_vec_str *vec, t_vec_str_sort_fn is_sorted);
|
||||
|
||||
/// @brief Get a pointer to the last element of the vec_str
|
||||
/// @param vec The vec_str to get the element from
|
||||
/// @param[out] out A pointer to the last element of the vec_str
|
||||
/// @return true if the operation failed, false otherwise
|
||||
t_error vec_str_back(t_vec_str *vec, t_str **out);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -16,9 +16,12 @@
|
|||
|
||||
#include "me/types.h"
|
||||
|
||||
/// @brief A function that takes two t_u8 and compare them
|
||||
typedef bool (*t_vec_u8_sort_fn)(t_u8 *, t_u8 *);
|
||||
/// @brief A function that free an t_u8
|
||||
typedef void (*t_free_u8_item)(t_u8);
|
||||
|
||||
/// @brief A dynamic array of t_u8
|
||||
typedef struct s_vec_u8
|
||||
{
|
||||
t_free_u8_item free_func;
|
||||
|
|
@ -27,32 +30,94 @@ typedef struct s_vec_u8
|
|||
t_u8 *buffer;
|
||||
} t_vec_u8;
|
||||
|
||||
t_vec_u8 vec_u8_new(t_usize capacity,
|
||||
t_free_u8_item free_function);
|
||||
/// @brief Create a new vec_u8 with a given capacity
|
||||
/// @param capacity The capacity of the new vec_u8 (in terms of elements)
|
||||
/// @param free_function The function that will be used to free the elements of the vec_u8
|
||||
t_vec_u8 vec_u8_new(t_usize capacity, t_free_u8_item free_function);
|
||||
/// @brief Push an element to the last position of the vec_u8
|
||||
/// @param vec The vec_u8 to push the element to
|
||||
/// @param element The element to push
|
||||
t_error vec_u8_push(t_vec_u8 *vec, t_u8 element);
|
||||
t_error vec_u8_push_front(t_vec_u8 *vec,
|
||||
t_u8 element);
|
||||
|
||||
/// @brief Push an element to the first position of the vec_u8
|
||||
/// @param vec The vec_u8 to push the element to
|
||||
/// @param element The element to push
|
||||
/// @note This operation is O(n)
|
||||
t_error vec_u8_push_front(t_vec_u8 *vec, t_u8 element);
|
||||
|
||||
/// @brief Get the last element from the vec_u8, and remove it from the vec_u8
|
||||
/// @param vec The vec_u8 to get the element from
|
||||
/// @param[out] out The last element of the vec_u8
|
||||
/// @return true if the operation failed, false otherwise
|
||||
t_error vec_u8_pop(t_vec_u8 *vec, t_u8 *value);
|
||||
|
||||
|
||||
/// @brief Get the first element from the vec_u8, and remove it from the vec_u8
|
||||
/// @param vec The vec_u8 to get the element from
|
||||
/// @param[out] out The first element of the vec_u8
|
||||
/// @return true if the operation failed, false otherwise
|
||||
/// @note This operation is O(n)
|
||||
t_error vec_u8_pop_front(t_vec_u8 *vec, t_u8 *value);
|
||||
|
||||
/// @brief Free the vector and all its elements
|
||||
/// @param vec The vec_u8 to free
|
||||
void vec_u8_free(t_vec_u8 vec);
|
||||
t_error vec_u8_reserve(t_vec_u8 *vec,
|
||||
t_usize wanted_capacity);
|
||||
t_error vec_u8_find(t_vec_u8 *vec,
|
||||
bool (*fn)(const t_u8 *), t_usize *index);
|
||||
t_error vec_u8_find_starting(t_vec_u8 *vec,
|
||||
bool (*fn)(const t_u8 *),
|
||||
t_usize starting_index, t_usize *index);
|
||||
t_error vec_u8_all(t_vec_u8 *vec,
|
||||
bool (*fn)(const t_u8 *), bool *result);
|
||||
t_error vec_u8_any(t_vec_u8 *vec,
|
||||
bool (*fn)(const t_u8 *), bool *result);
|
||||
void vec_u8_iter(t_vec_u8 *vec,
|
||||
void (*fn)(t_usize index, t_u8 *value,
|
||||
void *state),
|
||||
void *state);
|
||||
|
||||
/// @brief Make the vec_u8 at least the given capacity
|
||||
/// @param vec The vec_u8 to reserve
|
||||
/// @param wanted_capacity The minimum capacity to reserve
|
||||
/// @return true if the operation failed, false otherwise
|
||||
t_error vec_u8_reserve(t_vec_u8 *vec, t_usize wanted_capacity);
|
||||
|
||||
/// @brief Run the function and returns the index of the first element that returns true
|
||||
/// @param vec The vec_u8 to search in
|
||||
/// @param fn The function to run on each element
|
||||
/// @param[out] index The index of the first element that returns true
|
||||
t_error vec_u8_find(t_vec_u8 *vec, bool (*fn)(const t_u8 *), t_usize *index);
|
||||
|
||||
|
||||
/// @brief Run the function and returns the index of the first element that returns true, but starting at index starting_index
|
||||
/// @param vec The vec_u8 to search in
|
||||
/// @param fn The function to run on each element
|
||||
/// @param starting_index The index to start the search from
|
||||
/// @param[out] index The index of the first element that returns true
|
||||
t_error vec_u8_find_starting(t_vec_u8 *vec, bool (*fn)(const t_u8 *), t_usize starting_index, t_usize *index);
|
||||
|
||||
/// @brief Run the function on every element of the vec_u8 and returns if all elements returned true
|
||||
/// @param vec The vec_u8 to search in
|
||||
/// @param fn The function to run on each element
|
||||
/// @param[out] result The result of the operation
|
||||
/// @return true if the operation failed, false otherwise
|
||||
/// @note If the vec_u8 is empty, result will be true
|
||||
t_error vec_u8_all(t_vec_u8 *vec, bool (*fn)(const t_u8 *), bool *result);
|
||||
|
||||
/// @brief Run the function on every element of the vec_u8 and returns if any element returned true
|
||||
/// @param vec The vec_u8 to search in
|
||||
/// @param fn The function to run on each element
|
||||
/// @param[out] result The result of the operation
|
||||
/// @return true if the operation failed, false otherwise
|
||||
/// @note If the vec_u8 is empty, result will be false
|
||||
t_error vec_u8_any(t_vec_u8 *vec, bool (*fn)(const t_u8 *), bool *result);
|
||||
|
||||
/// @brief Run the function on every element of the vec_u8
|
||||
/// @param vec The vec_u8 to iterate over
|
||||
/// @param fn The function to run on each element
|
||||
/// @param state The state to pass to the function
|
||||
void vec_u8_iter(t_vec_u8 *vec, void (*fn)(t_usize index, t_u8 *value, void *state), void *state);
|
||||
|
||||
/// @brief Reverse the order of the elements in the vec_u8
|
||||
/// @param vec The vec_u8 to reverse
|
||||
void vec_u8_reverse(t_vec_u8 *vec);
|
||||
void vec_u8_sort(t_vec_u8 *vec,
|
||||
t_vec_u8_sort_fn is_sorted);
|
||||
|
||||
/// @brief Sort the elements of the vec_u8
|
||||
/// @param vec The vec_u8 to sort
|
||||
/// @param is_sorted The function to use to compare the elements
|
||||
void vec_u8_sort(t_vec_u8 *vec, t_vec_u8_sort_fn is_sorted);
|
||||
|
||||
/// @brief Get a pointer to the last element of the vec_u8
|
||||
/// @param vec The vec_u8 to get the element from
|
||||
/// @param[out] out A pointer to the last element of the vec_u8
|
||||
/// @return true if the operation failed, false otherwise
|
||||
t_error vec_u8_back(t_vec_u8 *vec, t_u8 **out);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -10,9 +10,9 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/char/isalpha.h"
|
||||
#include "me/char/char.h"
|
||||
#include "me/convert/str_to_numbers.h"
|
||||
#include "me/string/str_len.h"
|
||||
#include "me/str/str.h"
|
||||
#include "me/types.h"
|
||||
|
||||
#define OP_ADD 0b0001
|
||||
|
|
|
|||
|
|
@ -11,9 +11,9 @@
|
|||
/* ************************************************************************** */
|
||||
|
||||
|
||||
#include "me/char/isalpha.h"
|
||||
#include "me/char/char.h"
|
||||
#include "me/convert/str_to_numbers.h"
|
||||
#include "me/string/str_len.h"
|
||||
#include "me/str/str.h"
|
||||
#include "me/types.h"
|
||||
#include "me/printf/printf.h"
|
||||
|
||||
|
|
|
|||
|
|
@ -10,9 +10,9 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/char/isalpha.h"
|
||||
#include "me/char/char.h"
|
||||
#include "me/convert/str_to_numbers.h"
|
||||
#include "me/string/str_len.h"
|
||||
#include "me/str/str.h"
|
||||
#include "me/types.h"
|
||||
|
||||
#define OP_ADD 0b0001
|
||||
|
|
|
|||
|
|
@ -11,9 +11,9 @@
|
|||
/* ************************************************************************** */
|
||||
|
||||
|
||||
#include "me/char/isalpha.h"
|
||||
#include "me/char/char.h"
|
||||
#include "me/convert/str_to_numbers.h"
|
||||
#include "me/string/str_len.h"
|
||||
#include "me/str/str.h"
|
||||
#include "me/types.h"
|
||||
#include "me/printf/printf.h"
|
||||
|
||||
|
|
|
|||
|
|
@ -10,9 +10,9 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/char/isalpha.h"
|
||||
#include "me/char/char.h"
|
||||
#include "me/convert/str_to_numbers.h"
|
||||
#include "me/string/str_len.h"
|
||||
#include "me/str/str.h"
|
||||
#include "me/types.h"
|
||||
|
||||
#define OP_ADD 0b0001
|
||||
|
|
|
|||
|
|
@ -11,9 +11,9 @@
|
|||
/* ************************************************************************** */
|
||||
|
||||
|
||||
#include "me/char/isalpha.h"
|
||||
#include "me/char/char.h"
|
||||
#include "me/convert/str_to_numbers.h"
|
||||
#include "me/string/str_len.h"
|
||||
#include "me/str/str.h"
|
||||
#include "me/types.h"
|
||||
#include "me/printf/printf.h"
|
||||
|
||||
|
|
|
|||
|
|
@ -10,9 +10,9 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/char/isalpha.h"
|
||||
#include "me/char/char.h"
|
||||
#include "me/convert/str_to_numbers.h"
|
||||
#include "me/string/str_len.h"
|
||||
#include "me/str/str.h"
|
||||
#include "me/types.h"
|
||||
|
||||
#define OP_ADD 0b0001
|
||||
|
|
|
|||
|
|
@ -11,9 +11,9 @@
|
|||
/* ************************************************************************** */
|
||||
|
||||
|
||||
#include "me/char/isalpha.h"
|
||||
#include "me/char/char.h"
|
||||
#include "me/convert/str_to_numbers.h"
|
||||
#include "me/string/str_len.h"
|
||||
#include "me/str/str.h"
|
||||
#include "me/types.h"
|
||||
#include "me/printf/printf.h"
|
||||
|
||||
|
|
|
|||
|
|
@ -10,9 +10,9 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/char/isalpha.h"
|
||||
#include "me/char/char.h"
|
||||
#include "me/convert/str_to_numbers.h"
|
||||
#include "me/string/str_len.h"
|
||||
#include "me/str/str.h"
|
||||
#include "me/types.h"
|
||||
|
||||
#define OP_ADD 0b0001
|
||||
|
|
|
|||
|
|
@ -11,9 +11,9 @@
|
|||
/* ************************************************************************** */
|
||||
|
||||
|
||||
#include "me/char/isalpha.h"
|
||||
#include "me/char/char.h"
|
||||
#include "me/convert/str_to_numbers.h"
|
||||
#include "me/string/str_len.h"
|
||||
#include "me/str/str.h"
|
||||
#include "me/types.h"
|
||||
#include "me/printf/printf.h"
|
||||
|
||||
|
|
|
|||
|
|
@ -10,9 +10,9 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/char/isalpha.h"
|
||||
#include "me/char/char.h"
|
||||
#include "me/convert/str_to_numbers.h"
|
||||
#include "me/string/str_len.h"
|
||||
#include "me/str/str.h"
|
||||
#include "me/types.h"
|
||||
|
||||
#define OP_ADD 0b0001
|
||||
|
|
|
|||
|
|
@ -11,9 +11,9 @@
|
|||
/* ************************************************************************** */
|
||||
|
||||
|
||||
#include "me/char/isalpha.h"
|
||||
#include "me/char/char.h"
|
||||
#include "me/convert/str_to_numbers.h"
|
||||
#include "me/string/str_len.h"
|
||||
#include "me/str/str.h"
|
||||
#include "me/types.h"
|
||||
#include "me/printf/printf.h"
|
||||
|
||||
|
|
|
|||
|
|
@ -10,9 +10,9 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/char/isalpha.h"
|
||||
#include "me/char/char.h"
|
||||
#include "me/convert/str_to_numbers.h"
|
||||
#include "me/string/str_len.h"
|
||||
#include "me/str/str.h"
|
||||
#include "me/types.h"
|
||||
|
||||
#define OP_ADD 0b0001
|
||||
|
|
|
|||
|
|
@ -11,9 +11,9 @@
|
|||
/* ************************************************************************** */
|
||||
|
||||
|
||||
#include "me/char/isalpha.h"
|
||||
#include "me/char/char.h"
|
||||
#include "me/convert/str_to_numbers.h"
|
||||
#include "me/string/str_len.h"
|
||||
#include "me/str/str.h"
|
||||
#include "me/types.h"
|
||||
#include "me/printf/printf.h"
|
||||
|
||||
|
|
|
|||
|
|
@ -10,9 +10,9 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/char/isalpha.h"
|
||||
#include "me/char/char.h"
|
||||
#include "me/convert/str_to_numbers.h"
|
||||
#include "me/string/str_len.h"
|
||||
#include "me/str/str.h"
|
||||
#include "me/types.h"
|
||||
|
||||
#define OP_ADD 0b0001
|
||||
|
|
|
|||
|
|
@ -11,9 +11,9 @@
|
|||
/* ************************************************************************** */
|
||||
|
||||
|
||||
#include "me/char/isalpha.h"
|
||||
#include "me/char/char.h"
|
||||
#include "me/convert/str_to_numbers.h"
|
||||
#include "me/string/str_len.h"
|
||||
#include "me/str/str.h"
|
||||
#include "me/types.h"
|
||||
#include "me/printf/printf.h"
|
||||
|
||||
|
|
|
|||
|
|
@ -10,9 +10,9 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/mem/mem_alloc_array.h"
|
||||
#include "me/mem/mem_copy.h"
|
||||
#include "me/mem/mem_set_zero.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/types.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/vec/vec_buf_str.h"
|
||||
|
|
@ -25,14 +25,14 @@ t_vec_buf_str vec_buf_str_new(t_usize capacity,
|
|||
|
||||
out = (t_vec_buf_str){0};
|
||||
out.free_func = free_function;
|
||||
out.buffer = mem_alloc_array(capacity, sizeof(t_buffer_str));
|
||||
out.buffer = mem_alloc_array(capacity, sizeof(t_string));
|
||||
if (out.buffer)
|
||||
out.capacity = capacity;
|
||||
return (out);
|
||||
}
|
||||
|
||||
/// Return true in case of an error
|
||||
t_error vec_buf_str_push(t_vec_buf_str *vec, t_buffer_str element)
|
||||
t_error vec_buf_str_push(t_vec_buf_str *vec, t_string element)
|
||||
{
|
||||
if (vec == NULL)
|
||||
return (ERROR);
|
||||
|
|
@ -54,7 +54,7 @@ t_error vec_buf_str_reserve(t_vec_buf_str *vec, t_usize wanted_capacity)
|
|||
new_capacity = (vec->capacity * 3) / 2 + 1;
|
||||
while (wanted_capacity > new_capacity)
|
||||
new_capacity = (new_capacity * 3) / 2 + 1;
|
||||
vec->buffer = mem_realloc_array(vec->buffer, new_capacity, sizeof(t_buffer_str));
|
||||
vec->buffer = mem_realloc_array(vec->buffer, new_capacity, sizeof(t_string));
|
||||
vec->capacity = new_capacity;
|
||||
}
|
||||
return (NO_ERROR);
|
||||
|
|
@ -62,10 +62,10 @@ t_error vec_buf_str_reserve(t_vec_buf_str *vec, t_usize wanted_capacity)
|
|||
|
||||
/// Return true if the vector is empty
|
||||
/// This function is safe to call with value being NULL
|
||||
t_error vec_buf_str_pop(t_vec_buf_str *vec, t_buffer_str *value)
|
||||
t_error vec_buf_str_pop(t_vec_buf_str *vec, t_string *value)
|
||||
{
|
||||
t_buffer_str temp_value;
|
||||
t_buffer_str *ptr;
|
||||
t_string temp_value;
|
||||
t_string *ptr;
|
||||
|
||||
if (vec == NULL)
|
||||
return (ERROR);
|
||||
|
|
@ -76,7 +76,7 @@ t_error vec_buf_str_pop(t_vec_buf_str *vec, t_buffer_str *value)
|
|||
ptr = &temp_value;
|
||||
vec->len--;
|
||||
*ptr = vec->buffer[vec->len];
|
||||
mem_set_zero(&vec->buffer[vec->len], sizeof(t_buffer_str));
|
||||
mem_set_zero(&vec->buffer[vec->len], sizeof(t_string));
|
||||
return (NO_ERROR);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,15 +10,15 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/mem/mem_alloc_array.h"
|
||||
#include "me/mem/mem_copy.h"
|
||||
#include "me/mem/mem_set_zero.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/types.h"
|
||||
#include "me/vec/vec_buf_str.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
t_error vec_buf_str_find(t_vec_buf_str *vec,
|
||||
bool (*fn)(const t_buffer_str *), t_usize *index)
|
||||
bool (*fn)(const t_string *), t_usize *index)
|
||||
{
|
||||
t_usize idx;
|
||||
|
||||
|
|
@ -38,7 +38,7 @@ t_error vec_buf_str_find(t_vec_buf_str *vec,
|
|||
}
|
||||
|
||||
t_error vec_buf_str_find_starting(t_vec_buf_str *vec,
|
||||
bool (*fn)(const t_buffer_str *),
|
||||
bool (*fn)(const t_string *),
|
||||
t_usize starting_index, t_usize *index)
|
||||
{
|
||||
t_usize idx;
|
||||
|
|
@ -59,7 +59,7 @@ t_error vec_buf_str_find_starting(t_vec_buf_str *vec,
|
|||
}
|
||||
|
||||
t_error vec_buf_str_all(t_vec_buf_str *vec,
|
||||
bool (*fn)(const t_buffer_str *), bool *result)
|
||||
bool (*fn)(const t_string *), bool *result)
|
||||
{
|
||||
t_usize idx;
|
||||
|
||||
|
|
@ -77,7 +77,7 @@ t_error vec_buf_str_all(t_vec_buf_str *vec,
|
|||
}
|
||||
|
||||
t_error vec_buf_str_any(t_vec_buf_str *vec,
|
||||
bool (*fn)(const t_buffer_str *), bool *result)
|
||||
bool (*fn)(const t_string *), bool *result)
|
||||
{
|
||||
t_usize idx;
|
||||
|
||||
|
|
@ -95,7 +95,7 @@ t_error vec_buf_str_any(t_vec_buf_str *vec,
|
|||
}
|
||||
|
||||
void vec_buf_str_iter(t_vec_buf_str *vec,
|
||||
void (*fn)(t_usize index, t_buffer_str *value,
|
||||
void (*fn)(t_usize index, t_string *value,
|
||||
void *state),
|
||||
void *state)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -10,15 +10,15 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/mem/mem_alloc_array.h"
|
||||
#include "me/mem/mem_copy.h"
|
||||
#include "me/mem/mem_set_zero.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/types.h"
|
||||
#include "me/vec/vec_buf_str.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
t_error vec_buf_str_push_front(t_vec_buf_str *vec,
|
||||
t_buffer_str element)
|
||||
t_string element)
|
||||
{
|
||||
t_usize i;
|
||||
|
||||
|
|
@ -39,7 +39,7 @@ t_error vec_buf_str_push_front(t_vec_buf_str *vec,
|
|||
return (NO_ERROR);
|
||||
}
|
||||
|
||||
t_error vec_buf_str_pop_front(t_vec_buf_str *vec, t_buffer_str *value)
|
||||
t_error vec_buf_str_pop_front(t_vec_buf_str *vec, t_string *value)
|
||||
{
|
||||
t_usize i;
|
||||
|
||||
|
|
@ -59,7 +59,7 @@ t_error vec_buf_str_pop_front(t_vec_buf_str *vec, t_buffer_str *value)
|
|||
|
||||
void vec_buf_str_reverse(t_vec_buf_str *vec)
|
||||
{
|
||||
t_buffer_str temporary;
|
||||
t_string temporary;
|
||||
t_usize i;
|
||||
|
||||
i = 0;
|
||||
|
|
@ -72,9 +72,9 @@ void vec_buf_str_reverse(t_vec_buf_str *vec)
|
|||
}
|
||||
}
|
||||
|
||||
t_error vec_buf_str_back(t_vec_buf_str *vec, t_buffer_str **out)
|
||||
t_error vec_buf_str_back(t_vec_buf_str *vec, t_string **out)
|
||||
{
|
||||
t_buffer_str *temporary;
|
||||
t_string *temporary;
|
||||
|
||||
if (out == NULL)
|
||||
out = &temporary;
|
||||
|
|
|
|||
|
|
@ -10,9 +10,9 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/mem/mem_alloc_array.h"
|
||||
#include "me/mem/mem_copy.h"
|
||||
#include "me/mem/mem_set_zero.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/types.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/vec/vec_str.h"
|
||||
|
|
|
|||
|
|
@ -10,9 +10,9 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/mem/mem_alloc_array.h"
|
||||
#include "me/mem/mem_copy.h"
|
||||
#include "me/mem/mem_set_zero.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/types.h"
|
||||
#include "me/vec/vec_str.h"
|
||||
#include <stdlib.h>
|
||||
|
|
|
|||
|
|
@ -10,9 +10,9 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/mem/mem_alloc_array.h"
|
||||
#include "me/mem/mem_copy.h"
|
||||
#include "me/mem/mem_set_zero.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/types.h"
|
||||
#include "me/vec/vec_str.h"
|
||||
#include <stdlib.h>
|
||||
|
|
|
|||
|
|
@ -10,9 +10,9 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/mem/mem_alloc_array.h"
|
||||
#include "me/mem/mem_copy.h"
|
||||
#include "me/mem/mem_set_zero.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/types.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/vec/vec_u8.h"
|
||||
|
|
|
|||
|
|
@ -10,9 +10,9 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/mem/mem_alloc_array.h"
|
||||
#include "me/mem/mem_copy.h"
|
||||
#include "me/mem/mem_set_zero.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/types.h"
|
||||
#include "me/vec/vec_u8.h"
|
||||
#include <stdlib.h>
|
||||
|
|
|
|||
|
|
@ -10,9 +10,9 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/mem/mem_alloc_array.h"
|
||||
#include "me/mem/mem_copy.h"
|
||||
#include "me/mem/mem_set_zero.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/types.h"
|
||||
#include "me/vec/vec_u8.h"
|
||||
#include <stdlib.h>
|
||||
|
|
|
|||
|
|
@ -15,8 +15,6 @@ blx/sprite/free_image
|
|||
blx/sprite/get_pixel
|
||||
blx/sprite/new_image
|
||||
blx/sprite/sprite_draw_onto_sprite
|
||||
buffered_str/mod
|
||||
buffered_str/push_char
|
||||
char/isalnum
|
||||
char/isalpha
|
||||
char/isascii
|
||||
|
|
@ -30,6 +28,7 @@ char/toupper
|
|||
convert/atoi
|
||||
convert/itoa
|
||||
fs/close
|
||||
fs/fd_array_buffer
|
||||
fs/open
|
||||
fs/putchar_fd
|
||||
fs/putendl_fd
|
||||
|
|
@ -87,19 +86,20 @@ printf/formatter/utils_numbers
|
|||
printf/matchers
|
||||
printf/printf
|
||||
printf/vprintf
|
||||
string/str_clone
|
||||
string/str_compare
|
||||
string/str_find_chr
|
||||
string/str_find_rev_chr
|
||||
string/str_find_str
|
||||
string/str_iter
|
||||
string/str_join
|
||||
string/str_l_cat
|
||||
string/str_l_copy
|
||||
string/str_len
|
||||
string/str_map
|
||||
string/str_n_compare
|
||||
string/str_n_find_str
|
||||
string/str_split
|
||||
string/str_substring
|
||||
string/str_trim
|
||||
string/mod
|
||||
str/str_clone
|
||||
str/str_compare
|
||||
str/str_find_chr
|
||||
str/str_find_rev_chr
|
||||
str/str_find_str
|
||||
str/str_iter
|
||||
str/str_join
|
||||
str/str_l_cat
|
||||
str/str_l_copy
|
||||
str/str_len
|
||||
str/str_map
|
||||
str/str_n_compare
|
||||
str/str_n_find_str
|
||||
str/str_split
|
||||
str/str_substring
|
||||
str/str_trim
|
||||
|
|
|
|||
|
|
@ -1,13 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* push_char.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/30 14:17:47 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/04/30 14:17:47 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue