diff --git a/allocator/src/get_arena.c b/allocator/src/get_arena.c index 707d051d..6465024c 100644 --- a/allocator/src/get_arena.c +++ b/allocator/src/get_arena.c @@ -16,9 +16,9 @@ #include "me/fs/putendl_fd.h" #include "me/fs/putnbr_fd.h" #include "me/fs/putstr_fd.h" -#include "me/mem/mem_compare.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/num/usize.h" #include #include diff --git a/allocator/src/me_alloc/functions1.c b/allocator/src/me_alloc/functions1.c index 61699aa0..a2cda46e 100644 --- a/allocator/src/me_alloc/functions1.c +++ b/allocator/src/me_alloc/functions1.c @@ -10,8 +10,8 @@ /* */ /* ************************************************************************** */ -#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/types.h" #include "aq/allocator.h" diff --git a/includes/app/env.h b/includes/app/env.h index 956ba85a..fb809eb1 100644 --- a/includes/app/env.h +++ b/includes/app/env.h @@ -13,7 +13,7 @@ #ifndef ENV_H #define ENV_H -#include "me/buffered_str/buf_str.h" +#include "me/string/string.h" #include "me/hashmap/hashmap_env.h" #include "me/types.h" #include "me/vec/vec_str.h" @@ -25,7 +25,7 @@ t_error build_envp(t_hashmap_env *envs, t_vec_str *out); struct s_build_envp_state { t_vec_str out; - t_buffer_str buf; + t_string buf; }; #endif /* ENV_H */ diff --git a/output/include/me/hashmap/hashmap_env.h b/output/include/me/hashmap/hashmap_env.h index 27b96f88..7f96e5f3 100644 --- a/output/include/me/hashmap/hashmap_env.h +++ b/output/include/me/hashmap/hashmap_env.h @@ -25,16 +25,25 @@ #include #include +/// @struct A key-value pair for the hashmap typedef struct s_kv_env { t_str key; t_str val; } t_kv_env; +/// @typedef A function that hashes a key typedef void (*t_hash_env_fn)(t_hasher *hasher, t_str *key); +/// @typedef A function that drops a key-value pair typedef void (*t_drop_env_fn)(t_kv_env val); +/// @typedef A function that compares two keys and returns true if they are equal typedef bool (*t_eq_env_fn)(t_str *lhs, t_str *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_env { t_usize hash_id; @@ -42,6 +51,13 @@ typedef struct s_entry_env struct s_entry_env *next; } t_entry_env; +/// @struct A hashmap of keys t_str and values t_str +/// @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_env { t_entry_env **buckets; @@ -52,31 +68,56 @@ typedef struct s_hashmap_env t_drop_env_fn drop; } t_hashmap_env; -t_hashmap_env *new_hashmap_env(t_hash_env_fn hash, - t_eq_env_fn cmp, - t_drop_env_fn drop); -t_hashmap_env *new_hashmap_with_buckets_env( - t_hash_env_fn hash, t_eq_env_fn cmp, - t_drop_env_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_env *hmap_new_env(t_hash_env_fn hash, t_eq_env_fn cmp, t_drop_env_fn drop); -void drop_hashmap_env(t_hashmap_env *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_env *hmap_new_with_buckets_env(t_hash_env_fn hash, t_eq_env_fn cmp, t_drop_env_fn drop, size_t cap); -void insert_hashmap_env(t_hashmap_env *hmap, t_str key, - t_str value); +/// @brief Drops the hashmap and all of its entries +/// @param hmap The hashmap to drop +void hmap_free_env(t_hashmap_env *hmap); -t_str *get_hashmap_env(t_hashmap_env *hmap, - t_str *key); -void remove_hashmap_env(t_hashmap_env *hmap, t_str *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_env(t_hashmap_env *hmap, t_str key, t_str value); -t_entry_env *hashmap_get_entry_env(t_hashmap_env *hmap, - t_usize hash, - t_str *key, - t_entry_env **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 +t_str *hmap_get_env(t_hashmap_env *hmap, t_str *key); +/// @brief Removes the key-value pair from the hashmap +/// @param hmap The hashmap +/// @param key The key +void hmap_remove_env(t_hashmap_env *hmap, t_str *key); -t_error hashmap_env_iter(t_hashmap_env *self, - t_error (*func)(t_usize idx, - const t_str *key, - t_str *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_env *hmap_get_entry_env(t_hashmap_env *hmap, t_usize hash, t_str *key, t_entry_env **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_env_iter(t_hashmap_env *self, t_error (*func)(t_usize idx, const t_str *key, t_str *val, void *ctx), void *ctx); #endif diff --git a/output/include/me/vec/vec_parser_heredoc.h b/output/include/me/vec/vec_parser_heredoc.h index b6780051..ddce5766 100644 --- a/output/include/me/vec/vec_parser_heredoc.h +++ b/output/include/me/vec/vec_parser_heredoc.h @@ -16,9 +16,12 @@ #include "parser/types/types_heredoc.h" #include "me/types.h" +/// @brief A function that takes two t_heredoc and compare them typedef bool (*t_vec_parser_heredoc_sort_fn)(t_heredoc *, t_heredoc *); +/// @brief A function that free an t_heredoc typedef void (*t_free_parser_heredoc_item)(t_heredoc); +/// @brief A dynamic array of t_heredoc typedef struct s_vec_parser_heredoc { t_free_parser_heredoc_item free_func; @@ -27,32 +30,94 @@ typedef struct s_vec_parser_heredoc t_heredoc *buffer; } t_vec_parser_heredoc; -t_vec_parser_heredoc vec_parser_heredoc_new(t_usize capacity, - t_free_parser_heredoc_item free_function); +/// @brief Create a new vec_parser_heredoc with a given capacity +/// @param capacity The capacity of the new vec_parser_heredoc (in terms of elements) +/// @param free_function The function that will be used to free the elements of the vec_parser_heredoc +t_vec_parser_heredoc vec_parser_heredoc_new(t_usize capacity, t_free_parser_heredoc_item free_function); +/// @brief Push an element to the last position of the vec_parser_heredoc +/// @param vec The vec_parser_heredoc to push the element to +/// @param element The element to push t_error vec_parser_heredoc_push(t_vec_parser_heredoc *vec, t_heredoc element); -t_error vec_parser_heredoc_push_front(t_vec_parser_heredoc *vec, - t_heredoc element); + +/// @brief Push an element to the first position of the vec_parser_heredoc +/// @param vec The vec_parser_heredoc to push the element to +/// @param element The element to push +/// @note This operation is O(n) +t_error vec_parser_heredoc_push_front(t_vec_parser_heredoc *vec, t_heredoc element); + +/// @brief Get the last element from the vec_parser_heredoc, and remove it from the vec_parser_heredoc +/// @param vec The vec_parser_heredoc to get the element from +/// @param[out] out The last element of the vec_parser_heredoc +/// @return true if the operation failed, false otherwise t_error vec_parser_heredoc_pop(t_vec_parser_heredoc *vec, t_heredoc *value); + + +/// @brief Get the first element from the vec_parser_heredoc, and remove it from the vec_parser_heredoc +/// @param vec The vec_parser_heredoc to get the element from +/// @param[out] out The first element of the vec_parser_heredoc +/// @return true if the operation failed, false otherwise +/// @note This operation is O(n) t_error vec_parser_heredoc_pop_front(t_vec_parser_heredoc *vec, t_heredoc *value); + +/// @brief Free the vector and all its elements +/// @param vec The vec_parser_heredoc to free void vec_parser_heredoc_free(t_vec_parser_heredoc vec); -t_error vec_parser_heredoc_reserve(t_vec_parser_heredoc *vec, - t_usize wanted_capacity); -t_error vec_parser_heredoc_find(t_vec_parser_heredoc *vec, - bool (*fn)(const t_heredoc *), t_usize *index); -t_error vec_parser_heredoc_find_starting(t_vec_parser_heredoc *vec, - bool (*fn)(const t_heredoc *), - t_usize starting_index, t_usize *index); -t_error vec_parser_heredoc_all(t_vec_parser_heredoc *vec, - bool (*fn)(const t_heredoc *), bool *result); -t_error vec_parser_heredoc_any(t_vec_parser_heredoc *vec, - bool (*fn)(const t_heredoc *), bool *result); -void vec_parser_heredoc_iter(t_vec_parser_heredoc *vec, - void (*fn)(t_usize index, t_heredoc *value, - void *state), - void *state); + +/// @brief Make the vec_parser_heredoc at least the given capacity +/// @param vec The vec_parser_heredoc to reserve +/// @param wanted_capacity The minimum capacity to reserve +/// @return true if the operation failed, false otherwise +t_error vec_parser_heredoc_reserve(t_vec_parser_heredoc *vec, t_usize wanted_capacity); + +/// @brief Run the function and returns the index of the first element that returns true +/// @param vec The vec_parser_heredoc 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_parser_heredoc_find(t_vec_parser_heredoc *vec, bool (*fn)(const t_heredoc *), 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_parser_heredoc 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_parser_heredoc_find_starting(t_vec_parser_heredoc *vec, bool (*fn)(const t_heredoc *), t_usize starting_index, t_usize *index); + +/// @brief Run the function on every element of the vec_parser_heredoc and returns if all elements returned true +/// @param vec The vec_parser_heredoc 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_parser_heredoc is empty, result will be true +t_error vec_parser_heredoc_all(t_vec_parser_heredoc *vec, bool (*fn)(const t_heredoc *), bool *result); + +/// @brief Run the function on every element of the vec_parser_heredoc and returns if any element returned true +/// @param vec The vec_parser_heredoc 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_parser_heredoc is empty, result will be false +t_error vec_parser_heredoc_any(t_vec_parser_heredoc *vec, bool (*fn)(const t_heredoc *), bool *result); + +/// @brief Run the function on every element of the vec_parser_heredoc +/// @param vec The vec_parser_heredoc to iterate over +/// @param fn The function to run on each element +/// @param state The state to pass to the function +void vec_parser_heredoc_iter(t_vec_parser_heredoc *vec, void (*fn)(t_usize index, t_heredoc *value, void *state), void *state); + +/// @brief Reverse the order of the elements in the vec_parser_heredoc +/// @param vec The vec_parser_heredoc to reverse void vec_parser_heredoc_reverse(t_vec_parser_heredoc *vec); -void vec_parser_heredoc_sort(t_vec_parser_heredoc *vec, - t_vec_parser_heredoc_sort_fn is_sorted); + +/// @brief Sort the elements of the vec_parser_heredoc +/// @param vec The vec_parser_heredoc to sort +/// @param is_sorted The function to use to compare the elements +void vec_parser_heredoc_sort(t_vec_parser_heredoc *vec, t_vec_parser_heredoc_sort_fn is_sorted); + +/// @brief Get a pointer to the last element of the vec_parser_heredoc +/// @param vec The vec_parser_heredoc to get the element from +/// @param[out] out A pointer to the last element of the vec_parser_heredoc +/// @return true if the operation failed, false otherwise t_error vec_parser_heredoc_back(t_vec_parser_heredoc *vec, t_heredoc **out); #endif diff --git a/output/include/me/vec/vec_parser_range.h b/output/include/me/vec/vec_parser_range.h index 7beecdad..12dada37 100644 --- a/output/include/me/vec/vec_parser_range.h +++ b/output/include/me/vec/vec_parser_range.h @@ -16,9 +16,12 @@ #include "parser/types/types_parser_range.h" #include "me/types.h" +/// @brief A function that takes two t_parser_range and compare them typedef bool (*t_vec_parser_range_sort_fn)(t_parser_range *, t_parser_range *); +/// @brief A function that free an t_parser_range typedef void (*t_free_parser_range_item)(t_parser_range); +/// @brief A dynamic array of t_parser_range typedef struct s_vec_parser_range { t_free_parser_range_item free_func; @@ -27,32 +30,94 @@ typedef struct s_vec_parser_range t_parser_range *buffer; } t_vec_parser_range; -t_vec_parser_range vec_parser_range_new(t_usize capacity, - t_free_parser_range_item free_function); +/// @brief Create a new vec_parser_range with a given capacity +/// @param capacity The capacity of the new vec_parser_range (in terms of elements) +/// @param free_function The function that will be used to free the elements of the vec_parser_range +t_vec_parser_range vec_parser_range_new(t_usize capacity, t_free_parser_range_item free_function); +/// @brief Push an element to the last position of the vec_parser_range +/// @param vec The vec_parser_range to push the element to +/// @param element The element to push t_error vec_parser_range_push(t_vec_parser_range *vec, t_parser_range element); -t_error vec_parser_range_push_front(t_vec_parser_range *vec, - t_parser_range element); + +/// @brief Push an element to the first position of the vec_parser_range +/// @param vec The vec_parser_range to push the element to +/// @param element The element to push +/// @note This operation is O(n) +t_error vec_parser_range_push_front(t_vec_parser_range *vec, t_parser_range element); + +/// @brief Get the last element from the vec_parser_range, and remove it from the vec_parser_range +/// @param vec The vec_parser_range to get the element from +/// @param[out] out The last element of the vec_parser_range +/// @return true if the operation failed, false otherwise t_error vec_parser_range_pop(t_vec_parser_range *vec, t_parser_range *value); + + +/// @brief Get the first element from the vec_parser_range, and remove it from the vec_parser_range +/// @param vec The vec_parser_range to get the element from +/// @param[out] out The first element of the vec_parser_range +/// @return true if the operation failed, false otherwise +/// @note This operation is O(n) t_error vec_parser_range_pop_front(t_vec_parser_range *vec, t_parser_range *value); + +/// @brief Free the vector and all its elements +/// @param vec The vec_parser_range to free void vec_parser_range_free(t_vec_parser_range vec); -t_error vec_parser_range_reserve(t_vec_parser_range *vec, - t_usize wanted_capacity); -t_error vec_parser_range_find(t_vec_parser_range *vec, - bool (*fn)(const t_parser_range *), t_usize *index); -t_error vec_parser_range_find_starting(t_vec_parser_range *vec, - bool (*fn)(const t_parser_range *), - t_usize starting_index, t_usize *index); -t_error vec_parser_range_all(t_vec_parser_range *vec, - bool (*fn)(const t_parser_range *), bool *result); -t_error vec_parser_range_any(t_vec_parser_range *vec, - bool (*fn)(const t_parser_range *), bool *result); -void vec_parser_range_iter(t_vec_parser_range *vec, - void (*fn)(t_usize index, t_parser_range *value, - void *state), - void *state); + +/// @brief Make the vec_parser_range at least the given capacity +/// @param vec The vec_parser_range to reserve +/// @param wanted_capacity The minimum capacity to reserve +/// @return true if the operation failed, false otherwise +t_error vec_parser_range_reserve(t_vec_parser_range *vec, t_usize wanted_capacity); + +/// @brief Run the function and returns the index of the first element that returns true +/// @param vec The vec_parser_range 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_parser_range_find(t_vec_parser_range *vec, bool (*fn)(const t_parser_range *), 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_parser_range 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_parser_range_find_starting(t_vec_parser_range *vec, bool (*fn)(const t_parser_range *), t_usize starting_index, t_usize *index); + +/// @brief Run the function on every element of the vec_parser_range and returns if all elements returned true +/// @param vec The vec_parser_range 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_parser_range is empty, result will be true +t_error vec_parser_range_all(t_vec_parser_range *vec, bool (*fn)(const t_parser_range *), bool *result); + +/// @brief Run the function on every element of the vec_parser_range and returns if any element returned true +/// @param vec The vec_parser_range 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_parser_range is empty, result will be false +t_error vec_parser_range_any(t_vec_parser_range *vec, bool (*fn)(const t_parser_range *), bool *result); + +/// @brief Run the function on every element of the vec_parser_range +/// @param vec The vec_parser_range to iterate over +/// @param fn The function to run on each element +/// @param state The state to pass to the function +void vec_parser_range_iter(t_vec_parser_range *vec, void (*fn)(t_usize index, t_parser_range *value, void *state), void *state); + +/// @brief Reverse the order of the elements in the vec_parser_range +/// @param vec The vec_parser_range to reverse void vec_parser_range_reverse(t_vec_parser_range *vec); -void vec_parser_range_sort(t_vec_parser_range *vec, - t_vec_parser_range_sort_fn is_sorted); + +/// @brief Sort the elements of the vec_parser_range +/// @param vec The vec_parser_range to sort +/// @param is_sorted The function to use to compare the elements +void vec_parser_range_sort(t_vec_parser_range *vec, t_vec_parser_range_sort_fn is_sorted); + +/// @brief Get a pointer to the last element of the vec_parser_range +/// @param vec The vec_parser_range to get the element from +/// @param[out] out A pointer to the last element of the vec_parser_range +/// @return true if the operation failed, false otherwise t_error vec_parser_range_back(t_vec_parser_range *vec, t_parser_range **out); #endif diff --git a/output/include/me/vec/vec_reduce_action.h b/output/include/me/vec/vec_reduce_action.h index 6b6362a0..d3dbd7ed 100644 --- a/output/include/me/vec/vec_reduce_action.h +++ b/output/include/me/vec/vec_reduce_action.h @@ -16,9 +16,12 @@ #include "parser/types/types_reduce_action.h" #include "me/types.h" +/// @brief A function that takes two t_reduce_action and compare them typedef bool (*t_vec_reduce_action_sort_fn)(t_reduce_action *, t_reduce_action *); +/// @brief A function that free an t_reduce_action typedef void (*t_free_reduce_action_item)(t_reduce_action); +/// @brief A dynamic array of t_reduce_action typedef struct s_vec_reduce_action { t_free_reduce_action_item free_func; @@ -27,32 +30,94 @@ typedef struct s_vec_reduce_action t_reduce_action *buffer; } t_vec_reduce_action; -t_vec_reduce_action vec_reduce_action_new(t_usize capacity, - t_free_reduce_action_item free_function); +/// @brief Create a new vec_reduce_action with a given capacity +/// @param capacity The capacity of the new vec_reduce_action (in terms of elements) +/// @param free_function The function that will be used to free the elements of the vec_reduce_action +t_vec_reduce_action vec_reduce_action_new(t_usize capacity, t_free_reduce_action_item free_function); +/// @brief Push an element to the last position of the vec_reduce_action +/// @param vec The vec_reduce_action to push the element to +/// @param element The element to push t_error vec_reduce_action_push(t_vec_reduce_action *vec, t_reduce_action element); -t_error vec_reduce_action_push_front(t_vec_reduce_action *vec, - t_reduce_action element); + +/// @brief Push an element to the first position of the vec_reduce_action +/// @param vec The vec_reduce_action to push the element to +/// @param element The element to push +/// @note This operation is O(n) +t_error vec_reduce_action_push_front(t_vec_reduce_action *vec, t_reduce_action element); + +/// @brief Get the last element from the vec_reduce_action, and remove it from the vec_reduce_action +/// @param vec The vec_reduce_action to get the element from +/// @param[out] out The last element of the vec_reduce_action +/// @return true if the operation failed, false otherwise t_error vec_reduce_action_pop(t_vec_reduce_action *vec, t_reduce_action *value); + + +/// @brief Get the first element from the vec_reduce_action, and remove it from the vec_reduce_action +/// @param vec The vec_reduce_action to get the element from +/// @param[out] out The first element of the vec_reduce_action +/// @return true if the operation failed, false otherwise +/// @note This operation is O(n) t_error vec_reduce_action_pop_front(t_vec_reduce_action *vec, t_reduce_action *value); + +/// @brief Free the vector and all its elements +/// @param vec The vec_reduce_action to free void vec_reduce_action_free(t_vec_reduce_action vec); -t_error vec_reduce_action_reserve(t_vec_reduce_action *vec, - t_usize wanted_capacity); -t_error vec_reduce_action_find(t_vec_reduce_action *vec, - bool (*fn)(const t_reduce_action *), t_usize *index); -t_error vec_reduce_action_find_starting(t_vec_reduce_action *vec, - bool (*fn)(const t_reduce_action *), - t_usize starting_index, t_usize *index); -t_error vec_reduce_action_all(t_vec_reduce_action *vec, - bool (*fn)(const t_reduce_action *), bool *result); -t_error vec_reduce_action_any(t_vec_reduce_action *vec, - bool (*fn)(const t_reduce_action *), bool *result); -void vec_reduce_action_iter(t_vec_reduce_action *vec, - void (*fn)(t_usize index, t_reduce_action *value, - void *state), - void *state); + +/// @brief Make the vec_reduce_action at least the given capacity +/// @param vec The vec_reduce_action to reserve +/// @param wanted_capacity The minimum capacity to reserve +/// @return true if the operation failed, false otherwise +t_error vec_reduce_action_reserve(t_vec_reduce_action *vec, t_usize wanted_capacity); + +/// @brief Run the function and returns the index of the first element that returns true +/// @param vec The vec_reduce_action 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_reduce_action_find(t_vec_reduce_action *vec, bool (*fn)(const t_reduce_action *), 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_reduce_action 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_reduce_action_find_starting(t_vec_reduce_action *vec, bool (*fn)(const t_reduce_action *), t_usize starting_index, t_usize *index); + +/// @brief Run the function on every element of the vec_reduce_action and returns if all elements returned true +/// @param vec The vec_reduce_action 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_reduce_action is empty, result will be true +t_error vec_reduce_action_all(t_vec_reduce_action *vec, bool (*fn)(const t_reduce_action *), bool *result); + +/// @brief Run the function on every element of the vec_reduce_action and returns if any element returned true +/// @param vec The vec_reduce_action 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_reduce_action is empty, result will be false +t_error vec_reduce_action_any(t_vec_reduce_action *vec, bool (*fn)(const t_reduce_action *), bool *result); + +/// @brief Run the function on every element of the vec_reduce_action +/// @param vec The vec_reduce_action to iterate over +/// @param fn The function to run on each element +/// @param state The state to pass to the function +void vec_reduce_action_iter(t_vec_reduce_action *vec, void (*fn)(t_usize index, t_reduce_action *value, void *state), void *state); + +/// @brief Reverse the order of the elements in the vec_reduce_action +/// @param vec The vec_reduce_action to reverse void vec_reduce_action_reverse(t_vec_reduce_action *vec); -void vec_reduce_action_sort(t_vec_reduce_action *vec, - t_vec_reduce_action_sort_fn is_sorted); + +/// @brief Sort the elements of the vec_reduce_action +/// @param vec The vec_reduce_action to sort +/// @param is_sorted The function to use to compare the elements +void vec_reduce_action_sort(t_vec_reduce_action *vec, t_vec_reduce_action_sort_fn is_sorted); + +/// @brief Get a pointer to the last element of the vec_reduce_action +/// @param vec The vec_reduce_action to get the element from +/// @param[out] out A pointer to the last element of the vec_reduce_action +/// @return true if the operation failed, false otherwise t_error vec_reduce_action_back(t_vec_reduce_action *vec, t_reduce_action **out); #endif diff --git a/output/include/me/vec/vec_str.h b/output/include/me/vec/vec_str.h index deaf0727..e45d83c0 100644 --- a/output/include/me/vec/vec_str.h +++ b/output/include/me/vec/vec_str.h @@ -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 diff --git a/output/src/hashmap/env/env.c b/output/src/hashmap/env/env.c index 29278b34..51bfc202 100644 --- a/output/src/hashmap/env/env.c +++ b/output/src/hashmap/env/env.c @@ -14,19 +14,19 @@ #include "me/hash/sip.h" #include "me/hashmap/hashmap_env.h" #include "me/mem/mem.h" -#include "me/mem/mem_copy.h" +#include "me/mem/mem.h" #include "me/types.h" #include -t_hashmap_env *new_hashmap_env(t_hash_env_fn hfunc, +t_hashmap_env *hmap_new_env(t_hash_env_fn hfunc, t_eq_env_fn cfunc, t_drop_env_fn drop) { - return (new_hashmap_with_buckets_env(hfunc, cfunc, drop, + return (hmap_new_with_buckets_env(hfunc, cfunc, drop, DEFAULT_BUCKETS)); } -t_hashmap_env *new_hashmap_with_buckets_env( +t_hashmap_env *hmap_new_with_buckets_env( t_hash_env_fn hfunc, t_eq_env_fn cfunc, t_drop_env_fn drop, t_usize buckets) { @@ -46,7 +46,7 @@ t_hashmap_env *new_hashmap_with_buckets_env( return (hmap); } -void drop_hashmap_env(t_hashmap_env *hmap) +void hmap_free_env(t_hashmap_env *hmap) { t_usize index; @@ -65,7 +65,7 @@ void drop_hashmap_env(t_hashmap_env *hmap) mem_free(hmap); } -t_entry_env *hashmap_get_entry_env(t_hashmap_env *hmap, +t_entry_env *hmap_get_entry_env(t_hashmap_env *hmap, t_usize hashed_key, t_str *key, t_entry_env **prev) @@ -88,7 +88,7 @@ t_entry_env *hashmap_get_entry_env(t_hashmap_env *hmap, return (NULL); } -void insert_hashmap_env(t_hashmap_env *hmap, t_str key, +void hmap_insert_env(t_hashmap_env *hmap, t_str key, t_str value) { t_usize hashed_key; @@ -98,7 +98,7 @@ void insert_hashmap_env(t_hashmap_env *hmap, t_str key, hmap->hfunc(&hmap->hasher, &key); hashed_key = hasher_reset_and_finish(&hmap->hasher); prev = NULL; - entry = hashmap_get_entry_env(hmap, hashed_key, &key, &prev); + entry = hmap_get_entry_env(hmap, hashed_key, &key, &prev); if (entry == NULL) { entry = mem_alloc(sizeof(t_entry_env)); diff --git a/output/src/hashmap/env/env_iter.c b/output/src/hashmap/env/env_iter.c index 7f1c3668..04f79742 100644 --- a/output/src/hashmap/env/env_iter.c +++ b/output/src/hashmap/env/env_iter.c @@ -12,7 +12,7 @@ #include "me/hashmap/hashmap_env.h" -t_error hashmap_env_iter(t_hashmap_env *self, +t_error hmap_env_iter(t_hashmap_env *self, t_error (*func)(t_usize idx, const t_str *key, t_str *val, void *ctx), diff --git a/output/src/hashmap/env/env_utils.c b/output/src/hashmap/env/env_utils.c index a388fd4b..cd60f66d 100644 --- a/output/src/hashmap/env/env_utils.c +++ b/output/src/hashmap/env/env_utils.c @@ -13,11 +13,11 @@ #include "me/hash/sip.h" #include "me/hashmap/hashmap_env.h" #include "me/mem/mem.h" -#include "me/mem/mem_copy.h" +#include "me/mem/mem.h" #include "me/types.h" #include -t_str *get_hashmap_env(t_hashmap_env *hmap, +t_str *hmap_get_env(t_hashmap_env *hmap, t_str *key) { t_usize hashed_key; @@ -26,13 +26,13 @@ t_str *get_hashmap_env(t_hashmap_env *hmap, hmap->hfunc(&hmap->hasher, key); hashed_key = hasher_reset_and_finish(&hmap->hasher); - entry = hashmap_get_entry_env(hmap, hashed_key, key, &prev); + entry = hmap_get_entry_env(hmap, hashed_key, key, &prev); if (entry == NULL) return (NULL); return (&entry->kv.val); } -void remove_hashmap_env(t_hashmap_env *hmap, t_str *key) +void hmap_remove_env(t_hashmap_env *hmap, t_str *key) { t_usize hashed_key; t_entry_env *prev; @@ -42,7 +42,7 @@ void remove_hashmap_env(t_hashmap_env *hmap, t_str *key) hashed_key = hasher_reset_and_finish(&hmap->hasher); hmap->hasher = hasher_sip13_new(); prev = NULL; - entry = hashmap_get_entry_env(hmap, hashed_key, key, &prev); + entry = hmap_get_entry_env(hmap, hashed_key, key, &prev); if (entry == NULL) return; if (prev == NULL) diff --git a/output/src/vec/parser_heredoc/parser_heredoc.c b/output/src/vec/parser_heredoc/parser_heredoc.c index b3eb5831..34ae60d0 100644 --- a/output/src/vec/parser_heredoc/parser_heredoc.c +++ b/output/src/vec/parser_heredoc/parser_heredoc.c @@ -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_parser_heredoc.h" diff --git a/output/src/vec/parser_heredoc/parser_heredoc_functions2.c b/output/src/vec/parser_heredoc/parser_heredoc_functions2.c index f38b9f24..708fcf8f 100644 --- a/output/src/vec/parser_heredoc/parser_heredoc_functions2.c +++ b/output/src/vec/parser_heredoc/parser_heredoc_functions2.c @@ -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_parser_heredoc.h" #include diff --git a/output/src/vec/parser_heredoc/parser_heredoc_functions3.c b/output/src/vec/parser_heredoc/parser_heredoc_functions3.c index f9677148..9b7da819 100644 --- a/output/src/vec/parser_heredoc/parser_heredoc_functions3.c +++ b/output/src/vec/parser_heredoc/parser_heredoc_functions3.c @@ -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_parser_heredoc.h" #include diff --git a/output/src/vec/parser_range/parser_range.c b/output/src/vec/parser_range/parser_range.c index b333182b..8da5bdc5 100644 --- a/output/src/vec/parser_range/parser_range.c +++ b/output/src/vec/parser_range/parser_range.c @@ -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_parser_range.h" diff --git a/output/src/vec/parser_range/parser_range_functions2.c b/output/src/vec/parser_range/parser_range_functions2.c index b93ed9db..718306f2 100644 --- a/output/src/vec/parser_range/parser_range_functions2.c +++ b/output/src/vec/parser_range/parser_range_functions2.c @@ -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_parser_range.h" #include diff --git a/output/src/vec/parser_range/parser_range_functions3.c b/output/src/vec/parser_range/parser_range_functions3.c index a7ac9012..850ca371 100644 --- a/output/src/vec/parser_range/parser_range_functions3.c +++ b/output/src/vec/parser_range/parser_range_functions3.c @@ -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_parser_range.h" #include diff --git a/output/src/vec/reduce_action/reduce_action.c b/output/src/vec/reduce_action/reduce_action.c index e2de73c4..ecf79f06 100644 --- a/output/src/vec/reduce_action/reduce_action.c +++ b/output/src/vec/reduce_action/reduce_action.c @@ -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_reduce_action.h" diff --git a/output/src/vec/reduce_action/reduce_action_functions2.c b/output/src/vec/reduce_action/reduce_action_functions2.c index 29025453..78c91c3a 100644 --- a/output/src/vec/reduce_action/reduce_action_functions2.c +++ b/output/src/vec/reduce_action/reduce_action_functions2.c @@ -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_reduce_action.h" #include diff --git a/output/src/vec/reduce_action/reduce_action_functions3.c b/output/src/vec/reduce_action/reduce_action_functions3.c index 2dc18ad3..35e2dc7c 100644 --- a/output/src/vec/reduce_action/reduce_action_functions3.c +++ b/output/src/vec/reduce_action/reduce_action_functions3.c @@ -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_reduce_action.h" #include diff --git a/output/src/vec/str/str.c b/output/src/vec/str/str.c index 048f64c8..ce288abe 100644 --- a/output/src/vec/str/str.c +++ b/output/src/vec/str/str.c @@ -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" diff --git a/output/src/vec/str/str_functions2.c b/output/src/vec/str/str_functions2.c index 0b3a88bb..cd755f72 100644 --- a/output/src/vec/str/str_functions2.c +++ b/output/src/vec/str/str_functions2.c @@ -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 diff --git a/output/src/vec/str/str_functions3.c b/output/src/vec/str/str_functions3.c index b0fd48e7..6b9704a5 100644 --- a/output/src/vec/str/str_functions3.c +++ b/output/src/vec/str/str_functions3.c @@ -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 diff --git a/parser/includes/types/types_heredoc.h b/parser/includes/types/types_heredoc.h index 6d34f004..dd3a185d 100644 --- a/parser/includes/types/types_heredoc.h +++ b/parser/includes/types/types_heredoc.h @@ -13,7 +13,7 @@ #ifndef TYPES_HEREDOC_H #define TYPES_HEREDOC_H -#include "me/buffered_str/buf_str.h" +#include "me/string/string.h" #include "me/types.h" typedef struct s_heredoc @@ -21,8 +21,8 @@ typedef struct s_heredoc bool is_raw; bool started; bool allows_indent; - t_buffer_str delimiter; - t_buffer_str current_leading_word; + t_string delimiter; + t_string current_leading_word; } t_heredoc; #endif /* TYPES_HEREDOC_H */ diff --git a/sources/env.c b/sources/env.c index 1e437332..677782e7 100644 --- a/sources/env.c +++ b/sources/env.c @@ -6,18 +6,18 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/05/04 18:32:50 by maiboyer #+# #+# */ -/* Updated: 2024/05/18 18:44:24 by maiboyer ### ########.fr */ +/* Updated: 2024/05/19 14:55:56 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ #include "app/env.h" -#include "me/buffered_str/buf_str.h" +#include "me/string/string.h" #include "me/hash/hasher.h" #include "me/hashmap/hashmap_env.h" #include "me/mem/mem.h" -#include "me/string/str_clone.h" -#include "me/string/str_compare.h" -#include "me/string/str_len.h" +#include "me/str/str.h" +#include "me/str/str.h" +#include "me/str/str.h" #include "me/types.h" #include "me/vec/vec_str.h" #include @@ -47,7 +47,7 @@ static void _free_env(t_kv_env kv) t_hashmap_env *create_env_map(void) { - return (new_hashmap_env(_hash_str, _cmp_str, _free_env)); + return (hmap_new_env(_hash_str, _cmp_str, _free_env)); } t_error _build_envp_iterator(t_usize idx, const t_str *key, t_str *val, @@ -58,13 +58,13 @@ t_error _build_envp_iterator(t_usize idx, const t_str *key, t_str *val, (void)(idx); s = ctx; - if (push_str_buffer(&s->buf, *key) || push_str_buffer(&s->buf, "=") || - push_str_buffer(&s->buf, *val)) + if (string_push(&s->buf, *key) || string_push(&s->buf, "=") || + string_push(&s->buf, *val)) return (vec_str_free(s->out), ERROR); push = str_clone(s->buf.buf); if (vec_str_push(&s->out, push)) - return (str_free(s->buf), ERROR); - str_clear(&s->buf); + return (string_free(s->buf), ERROR); + string_clear(&s->buf); return (NO_ERROR); } @@ -72,13 +72,13 @@ t_error build_envp(t_hashmap_env *envs, t_vec_str *envp) { struct s_build_envp_state state; - state.buf = alloc_new_buffer(8096); + state.buf = string_new(8096); state.out = vec_str_new(1024, (void (*)(t_str))mem_free); - if (hashmap_env_iter(envs, _build_envp_iterator, &state)) - return (str_free(state.buf), printf("iter failed\n"), ERROR); + if (hmap_env_iter(envs, _build_envp_iterator, &state)) + return (string_free(state.buf), ERROR); if (vec_str_push(&state.out, NULL)) - return (str_free(state.buf), printf("coun't push null\n"), ERROR); + return (string_free(state.buf), ERROR); *envp = state.out; - str_free(state.buf); + string_free(state.buf); return (NO_ERROR); } diff --git a/sources/exec/handle_command.c b/sources/exec/handle_command.c index c39a60e6..10d4d45c 100644 --- a/sources/exec/handle_command.c +++ b/sources/exec/handle_command.c @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/05/09 15:00:53 by rparodi #+# #+# */ -/* Updated: 2024/05/18 18:31:34 by maiboyer ### ########.fr */ +/* Updated: 2024/05/19 14:56:22 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,7 +18,7 @@ #include "me/vec/vec_str.h" // #include "app/node/handle_program.h" #include "app/node/handle_command.h" -#include "me/string/str_clone.h" +#include "me/str/str.h" #include "minishell.h" #include @@ -48,8 +48,6 @@ t_error handle_command(t_node *self, t_utils *shcat, t_i32 *out_exit_code) printf("PAS ENCORE HANDLE FDP asignement!\n"); else { - printf("arg %s %s\n", self->childs[i].kind_str, - node_getstr(&self->childs[i])); if (handle_node_getstr(&self->childs[i], shcat, &tmp)) return (vec_str_free(spawn_info.arguments), ERROR); if (vec_str_push(&spawn_info.arguments, str_clone(tmp))) @@ -57,15 +55,11 @@ t_error handle_command(t_node *self, t_utils *shcat, t_i32 *out_exit_code) } i++; } - // printf("%zu\n", spawn_info.arguments.len); - vec_str_push(&spawn_info.arguments, NULL); - // for (i = 0; i < spawn_info.arguments.len; i++) - // printf("[%zu]\t%s\n", i, spawn_info.arguments.buffer[i]); + // vec_str_push(&spawn_info.arguments, NULL); spawn_info.stdin = inherited(); spawn_info.stdout = inherited(); spawn_info.stderr = inherited(); spawn_info.forked_free = NULL; - printf("building envp\n"); if (build_envp(shcat->env, &spawn_info.environement)) return (vec_str_free(spawn_info.arguments), ERROR); if (spawn_process(spawn_info, &shcat->ret)) diff --git a/sources/exec/handle_concat.c b/sources/exec/handle_concat.c index 402aec12..e5ba4009 100644 --- a/sources/exec/handle_concat.c +++ b/sources/exec/handle_concat.c @@ -16,7 +16,7 @@ #include "app/node/handle_word.h" #include "app/state.h" #include "gmr/symbols.h" -#include "me/buffered_str/buf_str.h" +#include "me/string/string.h" #include "me/types.h" t_error node_get_string(t_node *self, t_utils *shcat, t_str *ret) @@ -30,20 +30,20 @@ t_error node_get_string(t_node *self, t_utils *shcat, t_str *ret) t_error handle_concat(t_node *self, t_utils *shcat, t_str *ret) { - t_buffer_str out; + t_string out; t_usize i; t_str tmp; (void)(shcat); if (self == NULL || ret == NULL || self->kind != sym_concatenation) return (ERROR); - out = alloc_new_buffer(16); + out = string_new(16); i = 0; while (i < self->childs_count) { if (node_get_string(&self->childs[i], shcat, &tmp)) - return (str_free(out), ERROR); - push_str_buffer(&out, tmp); + return (string_free(out), ERROR); + string_push(&out, tmp); mem_free(tmp); i++; } diff --git a/sources/exec/handle_raw_word.c b/sources/exec/handle_raw_word.c index ad93ca50..1eddd35c 100644 --- a/sources/exec/handle_raw_word.c +++ b/sources/exec/handle_raw_word.c @@ -14,8 +14,8 @@ #include "app/node.h" #include "app/state.h" #include "gmr/symbols.h" -#include "me/string/str_len.h" -#include "me/string/str_substring.h" +#include "me/str/str.h" +#include "me/str/str.h" #include "me/types.h" t_error handle_raw_string(t_node *self, t_utils *shcat, t_str *ret) diff --git a/sources/exec/handle_word.c b/sources/exec/handle_word.c index 2b8f2c6b..1b890476 100644 --- a/sources/exec/handle_word.c +++ b/sources/exec/handle_word.c @@ -13,7 +13,7 @@ #include "app/node/handle_word.h" #include "app/state.h" #include "gmr/symbols.h" -#include "me/string/str_clone.h" +#include "me/str/str.h" #include "me/types.h" t_error handle_word(t_node *self, t_utils *shcat, t_str *ret) diff --git a/sources/exec/separator/semicolon.c b/sources/exec/separator/semicolon.c index bfc8c156..9777491d 100644 --- a/sources/exec/separator/semicolon.c +++ b/sources/exec/separator/semicolon.c @@ -18,7 +18,7 @@ #include "me/vec/vec_str.h" #include "app/node/handle_command.h" #include "minishell.h" -#include "me/string/str_clone.h" +#include "me/str/str.h" t_error ft_command_exec(t_node *self, t_i32 *ret); diff --git a/sources/ft_exit.c b/sources/ft_exit.c index 5f799036..ddb1156c 100644 --- a/sources/ft_exit.c +++ b/sources/ft_exit.c @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/29 11:35:51 by rparodi #+# #+# */ -/* Updated: 2024/05/18 18:11:59 by maiboyer ### ########.fr */ +/* Updated: 2024/05/19 14:51:28 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ @@ -40,10 +40,7 @@ void ft_free_utils(t_utils *s) if (s->path) ft_free_strs(s->path); if (s->env) - { - printf("Dropping HashMap\n"); - drop_hashmap_env(s->env); - } + hmap_free_env(s->env); ts_parser_delete(s->parser.parser); } diff --git a/sources/main.c b/sources/main.c index 4d33b499..86808f6b 100644 --- a/sources/main.c +++ b/sources/main.c @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/28 14:40:38 by rparodi #+# #+# */ -/* Updated: 2024/05/18 18:37:39 by maiboyer ### ########.fr */ +/* Updated: 2024/05/19 14:55:28 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,10 +17,8 @@ #include "app/signal_handler.h" #include "gmr/symbols.h" #include "me/hashmap/hashmap_env.h" -#include "me/mem/mem.h" -#include "me/string/str_len.h" -#include "me/string/str_split.h" -#include "me/string/str_substring.h" +#include "me/str/str.h" +#include "me/str/str.h" #include "me/types.h" #include "minishell.h" #include "parser/api.h" @@ -77,7 +75,7 @@ t_error populate_env(t_hashmap_env *env, t_str envp[]) return (ERROR); if (temp[0] == NULL || temp[1] == NULL) return (printf("TEMP NULL\n"), ERROR); - insert_hashmap_env(env, temp[0], temp[1]); + hmap_insert_env(env, temp[0], temp[1]); i++; } return (NO_ERROR); @@ -172,7 +170,7 @@ void exec_shcat(t_utils *shcat) { t_i32 ret; - print_node_data(&shcat->current_node, 0); + // print_node_data(&shcat->current_node, 0); handle_program(&shcat->current_node, shcat, &ret); free_node(shcat->current_node); (void)ret; @@ -193,24 +191,6 @@ void ft_take_args(t_utils *shcat) } } -void ft_find_path(t_str arge[], t_utils *utils) -{ - t_i32 i; - - i = 0; - while (arge[i] != NULL) - { - if (arge[i][0] == 'P' && arge[i][1] == 'A' && arge[i][2] == 'T' && - arge[i][3] == 'H' && arge[i][4] == '=') - { - utils->path = ft_split(arge[i] + 5, ':'); - return; - } - i++; - } - utils->path = ft_split(PATH_FILES, ':'); -} - t_language *tree_sitter_bash(void); t_parser create_myparser(void) @@ -237,14 +217,12 @@ t_i32 main(t_i32 argc, t_str argv[], t_str envp[]) (void)argv; (void)envp; if (install_signal()) - return (1); + me_abort("Unable to install signals"); utils = (t_utils){}; utils.parser = create_myparser(); utils.env = create_env_map(); - // if (install_signal()) - // return (1); if (populate_env(utils.env, envp)) - me_abort("unable to build ENV hashmap"); + me_abort("Unable to build env hashmap"); utils.name_shell = "\001\x1B[93m\002" "42sh" "\001\x1B[32m\002" diff --git a/sources/node/node.c b/sources/node/node.c index 96251183..94652a80 100644 --- a/sources/node/node.c +++ b/sources/node/node.c @@ -11,9 +11,9 @@ /* ************************************************************************** */ #include "app/node.h" -#include "me/mem/mem_alloc.h" -#include "me/mem/mem_alloc_array.h" -#include "me/string/str_l_copy.h" +#include "me/mem/mem.h" +#include "me/mem/mem.h" +#include "me/str/str.h" #include "parser/api.h" #include diff --git a/stdme/generic_sources/header/hashmap_C__PREFIX__.h__TEMPLATE__ b/stdme/generic_sources/header/hashmap_C__PREFIX__.h__TEMPLATE__ index cdd51c4f..c923a5d6 100644 --- a/stdme/generic_sources/header/hashmap_C__PREFIX__.h__TEMPLATE__ +++ b/stdme/generic_sources/header/hashmap_C__PREFIX__.h__TEMPLATE__ @@ -25,16 +25,25 @@ C__TYPEHEADER__ #include #include +/// @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 diff --git a/stdme/generic_sources/header/vec_C__PREFIX__.h__TEMPLATE__ b/stdme/generic_sources/header/vec_C__PREFIX__.h__TEMPLATE__ index 312c0967..f84d72ef 100644 --- a/stdme/generic_sources/header/vec_C__PREFIX__.h__TEMPLATE__ +++ b/stdme/generic_sources/header/vec_C__PREFIX__.h__TEMPLATE__ @@ -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 diff --git a/stdme/generic_sources/src/convert/str_to_C__PREFIX__.c__TEMPLATE__ b/stdme/generic_sources/src/convert/str_to_C__PREFIX__.c__TEMPLATE__ index 8984d44f..7e3b7158 100644 --- a/stdme/generic_sources/src/convert/str_to_C__PREFIX__.c__TEMPLATE__ +++ b/stdme/generic_sources/src/convert/str_to_C__PREFIX__.c__TEMPLATE__ @@ -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 diff --git a/stdme/generic_sources/src/convert/str_to_C__PREFIX___utils.c__TEMPLATE__ b/stdme/generic_sources/src/convert/str_to_C__PREFIX___utils.c__TEMPLATE__ index 73651ef0..81d5393e 100644 --- a/stdme/generic_sources/src/convert/str_to_C__PREFIX___utils.c__TEMPLATE__ +++ b/stdme/generic_sources/src/convert/str_to_C__PREFIX___utils.c__TEMPLATE__ @@ -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" diff --git a/stdme/generic_sources/src/hashmap/C__PREFIX__.c__TEMPLATE__ b/stdme/generic_sources/src/hashmap/C__PREFIX__.c__TEMPLATE__ index cea4e649..3f840c0d 100644 --- a/stdme/generic_sources/src/hashmap/C__PREFIX__.c__TEMPLATE__ +++ b/stdme/generic_sources/src/hashmap/C__PREFIX__.c__TEMPLATE__ @@ -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 -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__)); diff --git a/stdme/generic_sources/src/hashmap/C__PREFIX___iter.c__TEMPLATE__ b/stdme/generic_sources/src/hashmap/C__PREFIX___iter.c__TEMPLATE__ index 1f292b83..8a40a9e1 100644 --- a/stdme/generic_sources/src/hashmap/C__PREFIX___iter.c__TEMPLATE__ +++ b/stdme/generic_sources/src/hashmap/C__PREFIX___iter.c__TEMPLATE__ @@ -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), diff --git a/stdme/generic_sources/src/hashmap/C__PREFIX___utils.c__TEMPLATE__ b/stdme/generic_sources/src/hashmap/C__PREFIX___utils.c__TEMPLATE__ index 33dbefbe..75acfdcc 100644 --- a/stdme/generic_sources/src/hashmap/C__PREFIX___utils.c__TEMPLATE__ +++ b/stdme/generic_sources/src/hashmap/C__PREFIX___utils.c__TEMPLATE__ @@ -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 -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) diff --git a/stdme/generic_sources/src/vec/C__PREFIX__.c__TEMPLATE__ b/stdme/generic_sources/src/vec/C__PREFIX__.c__TEMPLATE__ index 364225d7..3ce45448 100644 --- a/stdme/generic_sources/src/vec/C__PREFIX__.c__TEMPLATE__ +++ b/stdme/generic_sources/src/vec/C__PREFIX__.c__TEMPLATE__ @@ -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" diff --git a/stdme/generic_sources/src/vec/C__PREFIX___functions2.c__TEMPLATE__ b/stdme/generic_sources/src/vec/C__PREFIX___functions2.c__TEMPLATE__ index 84ff32f7..9102ad5f 100644 --- a/stdme/generic_sources/src/vec/C__PREFIX___functions2.c__TEMPLATE__ +++ b/stdme/generic_sources/src/vec/C__PREFIX___functions2.c__TEMPLATE__ @@ -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 diff --git a/stdme/generic_sources/src/vec/C__PREFIX___functions3.c__TEMPLATE__ b/stdme/generic_sources/src/vec/C__PREFIX___functions3.c__TEMPLATE__ index d743a407..b56a2987 100644 --- a/stdme/generic_sources/src/vec/C__PREFIX___functions3.c__TEMPLATE__ +++ b/stdme/generic_sources/src/vec/C__PREFIX___functions3.c__TEMPLATE__ @@ -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 diff --git a/stdme/include/me/blx/blx.h b/stdme/include/me/blx/blx.h index 613c5d6b..fd87a3cd 100644 --- a/stdme/include/me/blx/blx.h +++ b/stdme/include/me/blx/blx.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); diff --git a/stdme/include/me/blx/blx_handlers.h b/stdme/include/me/blx/blx_handlers.h index f3c6393e..79222611 100644 --- a/stdme/include/me/blx/blx_handlers.h +++ b/stdme/include/me/blx/blx_handlers.h @@ -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 diff --git a/stdme/include/me/blx/blx_key.h b/stdme/include/me/blx/blx_key.h index 2c2384a0..8c55f026 100644 --- a/stdme/include/me/blx/blx_key.h +++ b/stdme/include/me/blx/blx_key.h @@ -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 diff --git a/stdme/include/me/blx/colors.h b/stdme/include/me/blx/colors.h index 2dac609d..db4d3546 100644 --- a/stdme/include/me/blx/colors.h +++ b/stdme/include/me/blx/colors.h @@ -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 diff --git a/stdme/include/me/blx/inputs.h b/stdme/include/me/blx/inputs.h index 27001875..3f1021ce 100644 --- a/stdme/include/me/blx/inputs.h +++ b/stdme/include/me/blx/inputs.h @@ -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 diff --git a/stdme/include/me/blx/points.h b/stdme/include/me/blx/points.h deleted file mode 100644 index 941bb617..00000000 --- a/stdme/include/me/blx/points.h +++ /dev/null @@ -1,24 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* points.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* 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 diff --git a/stdme/include/me/blx/sprite.h b/stdme/include/me/blx/sprite.h index ae3f0092..fcaf4113 100644 --- a/stdme/include/me/blx/sprite.h +++ b/stdme/include/me/blx/sprite.h @@ -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); diff --git a/stdme/include/me/buffered_str/buf_str.h b/stdme/include/me/buffered_str/buf_str.h deleted file mode 100644 index 00696723..00000000 --- a/stdme/include/me/buffered_str/buf_str.h +++ /dev/null @@ -1,50 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* buf_str.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* 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 diff --git a/stdme/include/me/char/char.h b/stdme/include/me/char/char.h new file mode 100644 index 00000000..8be68e39 --- /dev/null +++ b/stdme/include/me/char/char.h @@ -0,0 +1,63 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* char.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: maiboyer +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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 */ diff --git a/stdme/include/me/char/isalnum.h b/stdme/include/me/char/isalnum.h deleted file mode 100644 index f38c8e88..00000000 --- a/stdme/include/me/char/isalnum.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* isalnum.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* 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 diff --git a/stdme/include/me/char/isalpha.h b/stdme/include/me/char/isalpha.h deleted file mode 100644 index 680e1971..00000000 --- a/stdme/include/me/char/isalpha.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* isalpha.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* 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 diff --git a/stdme/include/me/char/isascii.h b/stdme/include/me/char/isascii.h deleted file mode 100644 index dfa19618..00000000 --- a/stdme/include/me/char/isascii.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* isascii.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* 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 diff --git a/stdme/include/me/char/isdigit.h b/stdme/include/me/char/isdigit.h deleted file mode 100644 index fbed9278..00000000 --- a/stdme/include/me/char/isdigit.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* isdigit.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* 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 diff --git a/stdme/include/me/char/islower.h b/stdme/include/me/char/islower.h deleted file mode 100644 index de8eedf0..00000000 --- a/stdme/include/me/char/islower.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* islower.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* 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 diff --git a/stdme/include/me/char/isprint.h b/stdme/include/me/char/isprint.h deleted file mode 100644 index 30c6b6fd..00000000 --- a/stdme/include/me/char/isprint.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* isprint.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* 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 diff --git a/stdme/include/me/char/isspace.h b/stdme/include/me/char/isspace.h deleted file mode 100644 index b2aa5c52..00000000 --- a/stdme/include/me/char/isspace.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* isspace.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* 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 diff --git a/stdme/include/me/char/isupper.h b/stdme/include/me/char/isupper.h deleted file mode 100644 index 4c485dde..00000000 --- a/stdme/include/me/char/isupper.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* isupper.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* 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 diff --git a/stdme/include/me/char/tolower.h b/stdme/include/me/char/tolower.h deleted file mode 100644 index 764f5a4c..00000000 --- a/stdme/include/me/char/tolower.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* tolower.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* 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 diff --git a/stdme/include/me/char/toupper.h b/stdme/include/me/char/toupper.h deleted file mode 100644 index 0e5a3a05..00000000 --- a/stdme/include/me/char/toupper.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* toupper.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* 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 diff --git a/stdme/include/me/convert/str_to_numbers.h b/stdme/include/me/convert/str_to_numbers.h index 9f90ddf7..48f9b620 100644 --- a/stdme/include/me/convert/str_to_numbers.h +++ b/stdme/include/me/convert/str_to_numbers.h @@ -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 */ diff --git a/stdme/include/me/fs/fs.h b/stdme/include/me/fs/fs.h new file mode 100644 index 00000000..47ee0081 --- /dev/null +++ b/stdme/include/me/fs/fs.h @@ -0,0 +1,91 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* fs.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: maiboyer +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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 +#include +#include + +#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 */ diff --git a/stdme/include/me/gnl/gnl.h b/stdme/include/me/gnl/gnl.h index 2933c2de..85501e5e 100644 --- a/stdme/include/me/gnl/gnl.h +++ b/stdme/include/me/gnl/gnl.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 diff --git a/stdme/include/me/hash/hasher.h b/stdme/include/me/hash/hasher.h index d9a9c1ca..4ac3c215 100644 --- a/stdme/include/me/hash/hasher.h +++ b/stdme/include/me/hash/hasher.h @@ -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 diff --git a/stdme/include/me/img/qoi.h b/stdme/include/me/img/qoi.h index 06ce6cc1..eb119d3c 100644 --- a/stdme/include/me/img/qoi.h +++ b/stdme/include/me/img/qoi.h @@ -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), diff --git a/stdme/include/me/mem/mem.h b/stdme/include/me/mem/mem.h index 24c937c1..3015ea91 100644 --- a/stdme/include/me/mem/mem.h +++ b/stdme/include/me/mem/mem.h @@ -6,7 +6,7 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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 */ diff --git a/stdme/include/me/mem/mem_alloc.h b/stdme/include/me/mem/mem_alloc.h deleted file mode 100644 index 1afc6fb5..00000000 --- a/stdme/include/me/mem/mem_alloc.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* mem_alloc.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* 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 diff --git a/stdme/include/me/mem/mem_alloc_array.h b/stdme/include/me/mem/mem_alloc_array.h deleted file mode 100644 index 2979ef32..00000000 --- a/stdme/include/me/mem/mem_alloc_array.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* mem_alloc_array.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* 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 diff --git a/stdme/include/me/mem/mem_compare.h b/stdme/include/me/mem/mem_compare.h deleted file mode 100644 index 1ae3c3e8..00000000 --- a/stdme/include/me/mem/mem_compare.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* mem_compare.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* 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 \ No newline at end of file diff --git a/stdme/include/me/mem/mem_copy.h b/stdme/include/me/mem/mem_copy.h deleted file mode 100644 index 59d71245..00000000 --- a/stdme/include/me/mem/mem_copy.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* mem_copy.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* 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 \ No newline at end of file diff --git a/stdme/include/me/mem/mem_find.h b/stdme/include/me/mem/mem_find.h deleted file mode 100644 index 048d844e..00000000 --- a/stdme/include/me/mem/mem_find.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* mem_find.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* 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 \ No newline at end of file diff --git a/stdme/include/me/mem/mem_find_bytes.h b/stdme/include/me/mem/mem_find_bytes.h deleted file mode 100644 index 5f220b61..00000000 --- a/stdme/include/me/mem/mem_find_bytes.h +++ /dev/null @@ -1,21 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* mem_find_bytes.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* 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 diff --git a/stdme/include/me/mem/mem_move.h b/stdme/include/me/mem/mem_move.h deleted file mode 100644 index b2bce61a..00000000 --- a/stdme/include/me/mem/mem_move.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* mem_move.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* 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 \ No newline at end of file diff --git a/stdme/include/me/mem/mem_realloc.h b/stdme/include/me/mem/mem_realloc.h deleted file mode 100644 index 22057951..00000000 --- a/stdme/include/me/mem/mem_realloc.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* mem_realloc.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* 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 */ diff --git a/stdme/include/me/mem/mem_set.h b/stdme/include/me/mem/mem_set.h deleted file mode 100644 index c6702a1f..00000000 --- a/stdme/include/me/mem/mem_set.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* mem_set.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* 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 \ No newline at end of file diff --git a/stdme/include/me/mem/mem_set_zero.h b/stdme/include/me/mem/mem_set_zero.h deleted file mode 100644 index dc38393f..00000000 --- a/stdme/include/me/mem/mem_set_zero.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* mem_set_zero.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* 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 \ No newline at end of file diff --git a/stdme/include/me/os/pipe.h b/stdme/include/me/os/pipe.h index 14cf3239..764e54c6 100644 --- a/stdme/include/me/os/pipe.h +++ b/stdme/include/me/os/pipe.h @@ -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 */ diff --git a/stdme/include/me/os/process.h b/stdme/include/me/os/process.h index cccb65c8..68e04b83 100644 --- a/stdme/include/me/os/process.h +++ b/stdme/include/me/os/process.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); diff --git a/stdme/include/me/printf/printf.h b/stdme/include/me/printf/printf.h index f12bbd60..070f3383 100644 --- a/stdme/include/me/printf/printf.h +++ b/stdme/include/me/printf/printf.h @@ -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 diff --git a/stdme/include/me/quit.h b/stdme/include/me/quit.h deleted file mode 100644 index 93dd8df2..00000000 --- a/stdme/include/me/quit.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* quit.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* 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 */ diff --git a/stdme/include/me/str/str.h b/stdme/include/me/str/str.h new file mode 100644 index 00000000..da7419bb --- /dev/null +++ b/stdme/include/me/str/str.h @@ -0,0 +1,113 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* str.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: maiboyer +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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 */ diff --git a/stdme/include/me/string/str_clone.h b/stdme/include/me/string/str_clone.h deleted file mode 100644 index a1523165..00000000 --- a/stdme/include/me/string/str_clone.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* str_clone.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* 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 diff --git a/stdme/include/me/string/str_compare.h b/stdme/include/me/string/str_compare.h deleted file mode 100644 index e3a64537..00000000 --- a/stdme/include/me/string/str_compare.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* str_compare.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* 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 diff --git a/stdme/include/me/string/str_find_chr.h b/stdme/include/me/string/str_find_chr.h deleted file mode 100644 index 0c583d6f..00000000 --- a/stdme/include/me/string/str_find_chr.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* str_find_chr.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* 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 \ No newline at end of file diff --git a/stdme/include/me/string/str_find_rev_chr.h b/stdme/include/me/string/str_find_rev_chr.h deleted file mode 100644 index 5dcd107e..00000000 --- a/stdme/include/me/string/str_find_rev_chr.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* str_find_rev_chr.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* 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 \ No newline at end of file diff --git a/stdme/include/me/string/str_find_str.h b/stdme/include/me/string/str_find_str.h deleted file mode 100644 index 30bd878e..00000000 --- a/stdme/include/me/string/str_find_str.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* str_find_str.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* 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 diff --git a/stdme/include/me/string/str_iter.h b/stdme/include/me/string/str_iter.h deleted file mode 100644 index e9bf1f53..00000000 --- a/stdme/include/me/string/str_iter.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* str_iter.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* 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 \ No newline at end of file diff --git a/stdme/include/me/string/str_join.h b/stdme/include/me/string/str_join.h deleted file mode 100644 index 408eb2ca..00000000 --- a/stdme/include/me/string/str_join.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* str_join.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* 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 \ No newline at end of file diff --git a/stdme/include/me/string/str_l_cat.h b/stdme/include/me/string/str_l_cat.h deleted file mode 100644 index fa752cbd..00000000 --- a/stdme/include/me/string/str_l_cat.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* str_l_cat.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* 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 diff --git a/stdme/include/me/string/str_l_copy.h b/stdme/include/me/string/str_l_copy.h deleted file mode 100644 index a75fbb45..00000000 --- a/stdme/include/me/string/str_l_copy.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* str_l_copy.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* 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 \ No newline at end of file diff --git a/stdme/include/me/string/str_len.h b/stdme/include/me/string/str_len.h deleted file mode 100644 index a1dddf32..00000000 --- a/stdme/include/me/string/str_len.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* str_len.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* 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 diff --git a/stdme/include/me/string/str_map.h b/stdme/include/me/string/str_map.h deleted file mode 100644 index a64e3d2d..00000000 --- a/stdme/include/me/string/str_map.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* str_map.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* 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 \ No newline at end of file diff --git a/stdme/include/me/string/str_n_compare.h b/stdme/include/me/string/str_n_compare.h deleted file mode 100644 index c07c04f5..00000000 --- a/stdme/include/me/string/str_n_compare.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* str_n_compare.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* 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 \ No newline at end of file diff --git a/stdme/include/me/string/str_n_find_str.h b/stdme/include/me/string/str_n_find_str.h deleted file mode 100644 index eea578b9..00000000 --- a/stdme/include/me/string/str_n_find_str.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* str_n_find_str.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* 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 diff --git a/stdme/include/me/string/str_split.h b/stdme/include/me/string/str_split.h deleted file mode 100644 index 578f1dd0..00000000 --- a/stdme/include/me/string/str_split.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* str_split.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* 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 \ No newline at end of file diff --git a/stdme/include/me/string/str_substring.h b/stdme/include/me/string/str_substring.h deleted file mode 100644 index da9cb412..00000000 --- a/stdme/include/me/string/str_substring.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* str_substring.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* 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 \ No newline at end of file diff --git a/stdme/include/me/string/str_trim.h b/stdme/include/me/string/str_trim.h deleted file mode 100644 index e7682d3a..00000000 --- a/stdme/include/me/string/str_trim.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* str_trim.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* 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 \ No newline at end of file diff --git a/stdme/include/me/string/string.h b/stdme/include/me/string/string.h new file mode 100644 index 00000000..ce59fab9 --- /dev/null +++ b/stdme/include/me/string/string.h @@ -0,0 +1,77 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* string.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: maiboyer +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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 diff --git a/stdme/include/me/types.h b/stdme/include/me/types.h index 5cac0bc5..315b38c0 100644 --- a/stdme/include/me/types.h +++ b/stdme/include/me/types.h @@ -22,30 +22,57 @@ #include #include +/// @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 diff --git a/stdme/include/me/vec2/vec2.h b/stdme/include/me/vec2/vec2.h index 81a0e527..21e370d5 100644 --- a/stdme/include/me/vec2/vec2.h +++ b/stdme/include/me/vec2/vec2.h @@ -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 */ diff --git a/stdme/input.toml b/stdme/input.toml index 0c3da5e6..5a7dff11 100644 --- a/stdme/input.toml +++ b/stdme/input.toml @@ -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" diff --git a/stdme/output/include/me/vec/vec_buf_str.h b/stdme/output/include/me/vec/vec_buf_str.h index ff230fc3..bb7e7718 100644 --- a/stdme/output/include/me/vec/vec_buf_str.h +++ b/stdme/output/include/me/vec/vec_buf_str.h @@ -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 diff --git a/stdme/output/include/me/vec/vec_str.h b/stdme/output/include/me/vec/vec_str.h index deaf0727..e45d83c0 100644 --- a/stdme/output/include/me/vec/vec_str.h +++ b/stdme/output/include/me/vec/vec_str.h @@ -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 diff --git a/stdme/output/include/me/vec/vec_u8.h b/stdme/output/include/me/vec/vec_u8.h index ec7fbedf..9cd76b29 100644 --- a/stdme/output/include/me/vec/vec_u8.h +++ b/stdme/output/include/me/vec/vec_u8.h @@ -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 diff --git a/stdme/output/src/convert/str_to_i16.c b/stdme/output/src/convert/str_to_i16.c index 64355c98..a22f9f44 100644 --- a/stdme/output/src/convert/str_to_i16.c +++ b/stdme/output/src/convert/str_to_i16.c @@ -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 diff --git a/stdme/output/src/convert/str_to_i16_utils.c b/stdme/output/src/convert/str_to_i16_utils.c index 6d6b30af..b037ee99 100644 --- a/stdme/output/src/convert/str_to_i16_utils.c +++ b/stdme/output/src/convert/str_to_i16_utils.c @@ -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" diff --git a/stdme/output/src/convert/str_to_i32.c b/stdme/output/src/convert/str_to_i32.c index cbbd6865..85c13396 100644 --- a/stdme/output/src/convert/str_to_i32.c +++ b/stdme/output/src/convert/str_to_i32.c @@ -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 diff --git a/stdme/output/src/convert/str_to_i32_utils.c b/stdme/output/src/convert/str_to_i32_utils.c index d6522527..57c588a8 100644 --- a/stdme/output/src/convert/str_to_i32_utils.c +++ b/stdme/output/src/convert/str_to_i32_utils.c @@ -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" diff --git a/stdme/output/src/convert/str_to_i64.c b/stdme/output/src/convert/str_to_i64.c index d0c50c69..9e5fe72d 100644 --- a/stdme/output/src/convert/str_to_i64.c +++ b/stdme/output/src/convert/str_to_i64.c @@ -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 diff --git a/stdme/output/src/convert/str_to_i64_utils.c b/stdme/output/src/convert/str_to_i64_utils.c index df9e4de1..d5a5ad84 100644 --- a/stdme/output/src/convert/str_to_i64_utils.c +++ b/stdme/output/src/convert/str_to_i64_utils.c @@ -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" diff --git a/stdme/output/src/convert/str_to_i8.c b/stdme/output/src/convert/str_to_i8.c index c45f66ec..7343eef2 100644 --- a/stdme/output/src/convert/str_to_i8.c +++ b/stdme/output/src/convert/str_to_i8.c @@ -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 diff --git a/stdme/output/src/convert/str_to_i8_utils.c b/stdme/output/src/convert/str_to_i8_utils.c index 0b9be619..0605d206 100644 --- a/stdme/output/src/convert/str_to_i8_utils.c +++ b/stdme/output/src/convert/str_to_i8_utils.c @@ -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" diff --git a/stdme/output/src/convert/str_to_u16.c b/stdme/output/src/convert/str_to_u16.c index 4e3414b3..1c37ec72 100644 --- a/stdme/output/src/convert/str_to_u16.c +++ b/stdme/output/src/convert/str_to_u16.c @@ -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 diff --git a/stdme/output/src/convert/str_to_u16_utils.c b/stdme/output/src/convert/str_to_u16_utils.c index 45b6d039..3e4cdbbb 100644 --- a/stdme/output/src/convert/str_to_u16_utils.c +++ b/stdme/output/src/convert/str_to_u16_utils.c @@ -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" diff --git a/stdme/output/src/convert/str_to_u32.c b/stdme/output/src/convert/str_to_u32.c index 0fa2ff2b..7d39e654 100644 --- a/stdme/output/src/convert/str_to_u32.c +++ b/stdme/output/src/convert/str_to_u32.c @@ -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 diff --git a/stdme/output/src/convert/str_to_u32_utils.c b/stdme/output/src/convert/str_to_u32_utils.c index c7fdc795..7dac096e 100644 --- a/stdme/output/src/convert/str_to_u32_utils.c +++ b/stdme/output/src/convert/str_to_u32_utils.c @@ -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" diff --git a/stdme/output/src/convert/str_to_u64.c b/stdme/output/src/convert/str_to_u64.c index 9c676dcd..c421d55a 100644 --- a/stdme/output/src/convert/str_to_u64.c +++ b/stdme/output/src/convert/str_to_u64.c @@ -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 diff --git a/stdme/output/src/convert/str_to_u64_utils.c b/stdme/output/src/convert/str_to_u64_utils.c index cfa335d0..7c9bb51a 100644 --- a/stdme/output/src/convert/str_to_u64_utils.c +++ b/stdme/output/src/convert/str_to_u64_utils.c @@ -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" diff --git a/stdme/output/src/convert/str_to_u8.c b/stdme/output/src/convert/str_to_u8.c index 1aa862f3..7a49bead 100644 --- a/stdme/output/src/convert/str_to_u8.c +++ b/stdme/output/src/convert/str_to_u8.c @@ -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 diff --git a/stdme/output/src/convert/str_to_u8_utils.c b/stdme/output/src/convert/str_to_u8_utils.c index 9b5e2665..3e0132bd 100644 --- a/stdme/output/src/convert/str_to_u8_utils.c +++ b/stdme/output/src/convert/str_to_u8_utils.c @@ -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" diff --git a/stdme/output/src/vec/buf_str/buf_str.c b/stdme/output/src/vec/buf_str/buf_str.c index ffc8265d..f660e393 100644 --- a/stdme/output/src/vec/buf_str/buf_str.c +++ b/stdme/output/src/vec/buf_str/buf_str.c @@ -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); } diff --git a/stdme/output/src/vec/buf_str/buf_str_functions2.c b/stdme/output/src/vec/buf_str/buf_str_functions2.c index 6d7fa65c..b7f7688f 100644 --- a/stdme/output/src/vec/buf_str/buf_str_functions2.c +++ b/stdme/output/src/vec/buf_str/buf_str_functions2.c @@ -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 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) { diff --git a/stdme/output/src/vec/buf_str/buf_str_functions3.c b/stdme/output/src/vec/buf_str/buf_str_functions3.c index 8b2205b4..4ec2c20a 100644 --- a/stdme/output/src/vec/buf_str/buf_str_functions3.c +++ b/stdme/output/src/vec/buf_str/buf_str_functions3.c @@ -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 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; diff --git a/stdme/output/src/vec/str/str.c b/stdme/output/src/vec/str/str.c index 048f64c8..ce288abe 100644 --- a/stdme/output/src/vec/str/str.c +++ b/stdme/output/src/vec/str/str.c @@ -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" diff --git a/stdme/output/src/vec/str/str_functions2.c b/stdme/output/src/vec/str/str_functions2.c index 0b3a88bb..cd755f72 100644 --- a/stdme/output/src/vec/str/str_functions2.c +++ b/stdme/output/src/vec/str/str_functions2.c @@ -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 diff --git a/stdme/output/src/vec/str/str_functions3.c b/stdme/output/src/vec/str/str_functions3.c index b0fd48e7..6b9704a5 100644 --- a/stdme/output/src/vec/str/str_functions3.c +++ b/stdme/output/src/vec/str/str_functions3.c @@ -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 diff --git a/stdme/output/src/vec/u8/u8.c b/stdme/output/src/vec/u8/u8.c index 0c5f1f6c..d9cfcbbf 100644 --- a/stdme/output/src/vec/u8/u8.c +++ b/stdme/output/src/vec/u8/u8.c @@ -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" diff --git a/stdme/output/src/vec/u8/u8_functions2.c b/stdme/output/src/vec/u8/u8_functions2.c index bb567f29..765fba7e 100644 --- a/stdme/output/src/vec/u8/u8_functions2.c +++ b/stdme/output/src/vec/u8/u8_functions2.c @@ -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 diff --git a/stdme/output/src/vec/u8/u8_functions3.c b/stdme/output/src/vec/u8/u8_functions3.c index f244463c..921200fc 100644 --- a/stdme/output/src/vec/u8/u8_functions3.c +++ b/stdme/output/src/vec/u8/u8_functions3.c @@ -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 diff --git a/stdme/src.list b/stdme/src.list index dc42c014..bdef8e56 100644 --- a/stdme/src.list +++ b/stdme/src.list @@ -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 diff --git a/stdme/src/buffered_str/push_char.c b/stdme/src/buffered_str/push_char.c deleted file mode 100644 index 730580b5..00000000 --- a/stdme/src/buffered_str/push_char.c +++ /dev/null @@ -1,13 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* push_char.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: maiboyer +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2024/04/30 14:17:47 by maiboyer #+# #+# */ -/* Updated: 2024/04/30 14:17:47 by maiboyer ### ########.fr */ -/* */ -/* ************************************************************************** */ - - diff --git a/stdme/src/char/isalnum.c b/stdme/src/char/isalnum.c index c4ebcfc5..73948704 100644 --- a/stdme/src/char/isalnum.c +++ b/stdme/src/char/isalnum.c @@ -10,9 +10,9 @@ /* */ /* ************************************************************************** */ -#include "me/char/isalnum.h" -#include "me/char/isalpha.h" -#include "me/char/isdigit.h" +#include "me/char/char.h" +#include "me/char/char.h" +#include "me/char/char.h" bool me_isalnum(char chr) { diff --git a/stdme/src/char/isalpha.c b/stdme/src/char/isalpha.c index bffddf0b..41492056 100644 --- a/stdme/src/char/isalpha.c +++ b/stdme/src/char/isalpha.c @@ -10,7 +10,7 @@ /* */ /* ************************************************************************** */ -#include "me/char/isalpha.h" +#include "me/char/char.h" bool me_isalpha(char chr) { diff --git a/stdme/src/char/isascii.c b/stdme/src/char/isascii.c index 5645b08c..1171b48c 100644 --- a/stdme/src/char/isascii.c +++ b/stdme/src/char/isascii.c @@ -10,7 +10,7 @@ /* */ /* ************************************************************************** */ -#include "me/char/isascii.h" +#include "me/char/char.h" bool me_isascii(char chr) { diff --git a/stdme/src/char/isdigit.c b/stdme/src/char/isdigit.c index f75d219a..e060ab3a 100644 --- a/stdme/src/char/isdigit.c +++ b/stdme/src/char/isdigit.c @@ -10,7 +10,7 @@ /* */ /* ************************************************************************** */ -#include "me/char/isdigit.h" +#include "me/char/char.h" bool me_isdigit(char chr) { diff --git a/stdme/src/char/islower.c b/stdme/src/char/islower.c index 384e88cd..0a67097b 100644 --- a/stdme/src/char/islower.c +++ b/stdme/src/char/islower.c @@ -10,7 +10,7 @@ /* */ /* ************************************************************************** */ -#include "me/char/islower.h" +#include "me/char/char.h" bool me_islower(char chr) { diff --git a/stdme/src/char/isprint.c b/stdme/src/char/isprint.c index f45c9ee6..a1eb4483 100644 --- a/stdme/src/char/isprint.c +++ b/stdme/src/char/isprint.c @@ -10,7 +10,7 @@ /* */ /* ************************************************************************** */ -#include "me/char/isprint.h" +#include "me/char/char.h" bool me_isprint(char chr) { diff --git a/stdme/src/char/isspace.c b/stdme/src/char/isspace.c index 1757f341..2c36e42b 100644 --- a/stdme/src/char/isspace.c +++ b/stdme/src/char/isspace.c @@ -10,7 +10,7 @@ /* */ /* ************************************************************************** */ -#include "me/char/isspace.h" +#include "me/char/char.h" bool me_isspace(char chr) { diff --git a/stdme/src/char/isupper.c b/stdme/src/char/isupper.c index 405cb09c..aea1c674 100644 --- a/stdme/src/char/isupper.c +++ b/stdme/src/char/isupper.c @@ -10,7 +10,7 @@ /* */ /* ************************************************************************** */ -#include "me/char/isupper.h" +#include "me/char/char.h" bool me_isupper(char chr) { diff --git a/stdme/src/char/tolower.c b/stdme/src/char/tolower.c index 4ee817cf..da81d8e0 100644 --- a/stdme/src/char/tolower.c +++ b/stdme/src/char/tolower.c @@ -10,10 +10,10 @@ /* */ /* ************************************************************************** */ -#include "me/char/isupper.h" -#include "me/char/tolower.h" +#include "me/char/char.h" +#include "me/char/char.h" -bool me_tolower(char chr) +char me_tolower(char chr) { if (me_isupper(chr)) return (chr + ('a' - 'A')); diff --git a/stdme/src/char/toupper.c b/stdme/src/char/toupper.c index 9888b7ee..70429249 100644 --- a/stdme/src/char/toupper.c +++ b/stdme/src/char/toupper.c @@ -10,10 +10,10 @@ /* */ /* ************************************************************************** */ -#include "me/char/islower.h" -#include "me/char/toupper.h" +#include "me/char/char.h" +#include "me/char/char.h" -bool me_toupper(char chr) +char me_toupper(char chr) { if (me_islower(chr)) return (chr - ('a' - 'A')); diff --git a/stdme/src/convert/atoi.c b/stdme/src/convert/atoi.c index 076e6efe..32fc8319 100644 --- a/stdme/src/convert/atoi.c +++ b/stdme/src/convert/atoi.c @@ -10,8 +10,8 @@ /* */ /* ************************************************************************** */ -#include "me/char/isdigit.h" -#include "me/char/isspace.h" +#include "me/char/char.h" +#include "me/char/char.h" #include "me/convert/atoi.h" t_i32 me_atoi(t_const_str str) diff --git a/stdme/src/convert/itoa.c b/stdme/src/convert/itoa.c index 426d84cc..a3a4a3fc 100644 --- a/stdme/src/convert/itoa.c +++ b/stdme/src/convert/itoa.c @@ -11,8 +11,8 @@ /* ************************************************************************** */ #include "me/convert/itoa.h" -#include "me/mem/mem_set.h" -#include "me/string/str_clone.h" +#include "me/mem/mem.h" +#include "me/str/str.h" #include static void me_itoa_inner(t_u64 nb, t_str out) diff --git a/stdme/src/fs/fd_array_buffer.c b/stdme/src/fs/fd_array_buffer.c new file mode 100644 index 00000000..96afb4ed --- /dev/null +++ b/stdme/src/fs/fd_array_buffer.c @@ -0,0 +1,65 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* fd_array_buffer.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: maiboyer +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/05/19 15:53:50 by maiboyer #+# #+# */ +/* Updated: 2024/05/19 17:05:40 by maiboyer ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "me/fs/fs.h" +#include "me/mem/mem.h" +#include "me/types.h" +#include + +t_fd_array *get_fd_arrays(void) +{ + static t_fd_array val = {}; + + return (&val); +} + +struct s_file_slot *get_unused_fd_slot(void) +{ + t_usize i; + t_fd_array *arr; + + arr = get_fd_arrays(); + i = 0; + while (i < FILE_SLOT_LEN) + { + if (arr->storage[i].ty == SLOT_UNUSED) + return (&arr->storage[i]); + i++; + } + me_abort( + "Unable to find slot for a file descriptor, increate FILE_SLOT_LEN"); + return (NULL); +} + +void close_all_fds(void) +{ + t_usize i; + t_fd_array *arr; + + arr = get_fd_arrays(); + i = 0; + while (i < FILE_SLOT_LEN) + { + if (arr->storage[i].ty == SLOT_UNUSED) + ; + else if (arr->storage[i].ty == SLOT_FD) + close(arr->storage[i].slot.fd.fd); + else if (arr->storage[i].ty == SLOT_DIR) + closedir(arr->storage[i].slot.dir.ptr); + else if (arr->storage[i].ty == SLOT_FILE) + fclose(arr->storage[i].slot.file.ptr); + else + write(2, "Unknown SLOT type", 17); + mem_set_zero(&arr->storage[i], sizeof(arr->storage[i])); + i++; + } +} diff --git a/stdme/src/fs/putchar_fd.c b/stdme/src/fs/putchar_fd.c index 2a100513..68d41139 100644 --- a/stdme/src/fs/putchar_fd.c +++ b/stdme/src/fs/putchar_fd.c @@ -12,7 +12,7 @@ #include "me/fs/putchar_fd.h" #include "me/fs/write.h" -#include "me/string/str_len.h" +#include "me/str/str.h" void me_putchar_fd(char chr, t_file file) { diff --git a/stdme/src/fs/putendl_fd.c b/stdme/src/fs/putendl_fd.c index ba94ff5e..fa854f3d 100644 --- a/stdme/src/fs/putendl_fd.c +++ b/stdme/src/fs/putendl_fd.c @@ -12,7 +12,7 @@ #include "me/fs/putstr_fd.h" #include "me/fs/write.h" -#include "me/string/str_len.h" +#include "me/str/str.h" void me_putendl_fd(t_str str, t_file file) { diff --git a/stdme/src/fs/putstr_fd.c b/stdme/src/fs/putstr_fd.c index 065b4909..749e2df2 100644 --- a/stdme/src/fs/putstr_fd.c +++ b/stdme/src/fs/putstr_fd.c @@ -12,7 +12,7 @@ #include "me/fs/putstr_fd.h" #include "me/fs/write.h" -#include "me/string/str_len.h" +#include "me/str/str.h" void me_putstr_fd(t_str str, t_file file) { diff --git a/stdme/src/fs/read_to_vec.c b/stdme/src/fs/read_to_vec.c index b04f3164..29830aa4 100644 --- a/stdme/src/fs/read_to_vec.c +++ b/stdme/src/fs/read_to_vec.c @@ -12,7 +12,7 @@ #include "me/fs/open.h" #include "me/fs/read.h" -#include "me/mem/mem_copy.h" +#include "me/mem/mem.h" #include "me/vec/vec_u8.h" #define READ_BUFFER_SIZE 4096 diff --git a/stdme/src/gnl/get_next_line.c b/stdme/src/gnl/get_next_line.c index 4bc69c2d..77b00b70 100644 --- a/stdme/src/gnl/get_next_line.c +++ b/stdme/src/gnl/get_next_line.c @@ -10,11 +10,11 @@ /* */ /* ************************************************************************** */ -#include "me/buffered_str/buf_str.h" +#include "me/string/string.h" #include "me/gnl/gnl.h" #include "me/mem/mem.h" -#include "me/mem/mem_move.h" -#include "me/string/str_len.h" +#include "me/mem/mem.h" +#include "me/str/str.h" #include "me/types.h" #include #include @@ -35,7 +35,7 @@ static t_static_buffer *get_next_line_buffer(t_file fd) return (&bufs[index]); } -static bool copy_next_line_into_buffer(t_file fd, t_buffer_str *out, +static bool copy_next_line_into_buffer(t_file fd, t_string *out, char *temp_buffer, t_usize amount) { char *buf; @@ -55,12 +55,12 @@ static bool copy_next_line_into_buffer(t_file fd, t_buffer_str *out, buf[(t_usize)(newline - buf)] = 0; temp_buffer[(t_usize)(newline - buf + got_newline)] = 0; mem_move(buf, newline + 1, other_part_len); - push_str_buffer(out, temp_buffer); + string_push(out, temp_buffer); buf[amount - (t_usize)(newline - buf + got_newline)] = 0; return (got_newline); } -static bool read_and_copy(t_file fd, t_buffer_str *out, char *tmp, +static bool read_and_copy(t_file fd, t_string *out, char *tmp, t_copy_flags *flags) { t_isize amount; @@ -82,7 +82,7 @@ static bool read_and_copy(t_file fd, t_buffer_str *out, char *tmp, return (copy_next_line_into_buffer(fd, out, tmp, (t_usize)amount)); } -static bool handle_leftovers(t_file fd, char *temp_buffer, t_buffer_str *buf) +static bool handle_leftovers(t_file fd, char *temp_buffer, t_string *buf) { t_static_buffer *static_buffer; @@ -99,21 +99,21 @@ static bool handle_leftovers(t_file fd, char *temp_buffer, t_buffer_str *buf) return (false); } -t_buffer_str get_next_line(t_file fd, bool *error) +t_string get_next_line(t_file fd, bool *error) { - t_buffer_str buf; + t_string buf; char *temp_buffer; t_copy_flags flags; *error = false; if (fd < 0 || BUFFER_SIZE <= 0) - return (*error = true, (t_buffer_str){0}); + return (*error = true, (t_string){0}); flags = (t_copy_flags){ .error = false, .empty_read = false, }; temp_buffer = mem_alloc(sizeof(char) * (BUFFER_SIZE + 2)); - buf = alloc_new_buffer(32); + buf = string_new(32); if (handle_leftovers(fd, temp_buffer, &buf)) return (buf); while (!read_and_copy(fd, &buf, temp_buffer, &flags) && !flags.empty_read) @@ -122,7 +122,7 @@ t_buffer_str get_next_line(t_file fd, bool *error) if (flags.error || flags.empty_read) { mem_free(buf.buf); - return (*error = true, (t_buffer_str){0}); + return (*error = true, (t_string){0}); } return (buf); } diff --git a/stdme/src/hash/hash_str.c b/stdme/src/hash/hash_str.c index 463e3181..95b4139f 100644 --- a/stdme/src/hash/hash_str.c +++ b/stdme/src/hash/hash_str.c @@ -11,7 +11,7 @@ /* ************************************************************************** */ #include "me/hash/hasher.h" -#include "me/string/str_len.h" +#include "me/str/str.h" #include "me/types.h" void hasher_write_str(t_hasher *hasher, t_str s) diff --git a/stdme/src/hash/sip/sip13.c b/stdme/src/hash/sip/sip13.c index d9ab5158..212467b6 100644 --- a/stdme/src/hash/sip/sip13.c +++ b/stdme/src/hash/sip/sip13.c @@ -12,7 +12,7 @@ #include "me/hash/sip.h" #include "me/hash/sip/sip_utils.h" -#include "me/mem/mem_alloc.h" +#include "me/mem/mem.h" t_hasher hasher_sip13_new(void) { diff --git a/stdme/src/mem/mem_alloc.c b/stdme/src/mem/mem_alloc.c index 8b2206e0..8766cd79 100644 --- a/stdme/src/mem/mem_alloc.c +++ b/stdme/src/mem/mem_alloc.c @@ -10,7 +10,7 @@ /* */ /* ************************************************************************** */ -#include "me/mem/mem_alloc.h" +#include "me/mem/mem.h" #include "me/mem/_allocator.h" void *mem_alloc(t_usize size) diff --git a/stdme/src/mem/mem_alloc_array.c b/stdme/src/mem/mem_alloc_array.c index 5d55cdae..bb7a70da 100644 --- a/stdme/src/mem/mem_alloc_array.c +++ b/stdme/src/mem/mem_alloc_array.c @@ -10,7 +10,7 @@ /* */ /* ************************************************************************** */ -#include "me/mem/mem_alloc_array.h" +#include "me/mem/mem.h" #include "me/mem/_allocator.h" void *mem_alloc_array(t_usize size, t_usize count) diff --git a/stdme/src/mem/mem_compare.c b/stdme/src/mem/mem_compare.c index 76d9d5bc..d2bfbd01 100644 --- a/stdme/src/mem/mem_compare.c +++ b/stdme/src/mem/mem_compare.c @@ -10,9 +10,9 @@ /* */ /* ************************************************************************** */ -#include "me/mem/mem_compare.h" +#include "me/mem/mem.h" -t_i32 mem_compare(const void *lhs, const void *rhs, t_usize count) +bool mem_compare(const void *lhs, const void *rhs, t_usize count) { t_usize i; t_u8 *lhs_; @@ -24,8 +24,8 @@ t_i32 mem_compare(const void *lhs, const void *rhs, t_usize count) while (i < count) { if (lhs_[i] - rhs_[i]) - return ((t_i32)(lhs_[i] - rhs_[i])); + return (false); i++; } - return (0); + return (true); } diff --git a/stdme/src/mem/mem_copy.c b/stdme/src/mem/mem_copy.c index bbd72980..9c1144d7 100644 --- a/stdme/src/mem/mem_copy.c +++ b/stdme/src/mem/mem_copy.c @@ -10,7 +10,7 @@ /* */ /* ************************************************************************** */ -#include "me/mem/mem_copy.h" +#include "me/mem/mem.h" void *mem_copy(void *destination, const void *source, t_usize count) { diff --git a/stdme/src/mem/mem_find.c b/stdme/src/mem/mem_find.c index e38303e1..4332c5aa 100644 --- a/stdme/src/mem/mem_find.c +++ b/stdme/src/mem/mem_find.c @@ -10,7 +10,7 @@ /* */ /* ************************************************************************** */ -#include "me/mem/mem_find.h" +#include "me/mem/mem.h" void *mem_find(void *buf, t_u8 find, t_usize count) { diff --git a/stdme/src/mem/mem_find_bytes.c b/stdme/src/mem/mem_find_bytes.c index 43704270..642f75e0 100644 --- a/stdme/src/mem/mem_find_bytes.c +++ b/stdme/src/mem/mem_find_bytes.c @@ -10,7 +10,7 @@ /* */ /* ************************************************************************** */ -#include "me/mem/mem_find_bytes.h" +#include "me/mem/mem.h" #include "stdio.h" void *mem_find_bytes(void *buf, t_u8 *find, t_usize find_len, t_usize count) diff --git a/stdme/src/mem/mem_move.c b/stdme/src/mem/mem_move.c index 03ebde31..5ef96da9 100644 --- a/stdme/src/mem/mem_move.c +++ b/stdme/src/mem/mem_move.c @@ -10,7 +10,7 @@ /* */ /* ************************************************************************** */ -#include "me/mem/mem_move.h" +#include "me/mem/mem.h" void *mem_move(void *destination, const void *source, t_usize count) { diff --git a/stdme/src/mem/mem_set.c b/stdme/src/mem/mem_set.c index 106c736a..534d943f 100644 --- a/stdme/src/mem/mem_set.c +++ b/stdme/src/mem/mem_set.c @@ -10,7 +10,7 @@ /* */ /* ************************************************************************** */ -#include "me/mem/mem_set.h" +#include "me/mem/mem.h" void mem_set(void *buf, t_u8 fill_by, t_usize count) { diff --git a/stdme/src/mem/mem_set_zero.c b/stdme/src/mem/mem_set_zero.c index b12e07d9..fa04bebd 100644 --- a/stdme/src/mem/mem_set_zero.c +++ b/stdme/src/mem/mem_set_zero.c @@ -10,7 +10,7 @@ /* */ /* ************************************************************************** */ -#include "me/mem/mem_set_zero.h" +#include "me/mem/mem.h" void mem_set_zero(void *buf, t_usize count) { diff --git a/stdme/src/os/exit.c b/stdme/src/os/exit.c index f522571e..e1783d94 100644 --- a/stdme/src/os/exit.c +++ b/stdme/src/os/exit.c @@ -6,16 +6,18 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/05/07 13:08:52 by maiboyer #+# #+# */ -/* Updated: 2024/05/16 17:12:46 by maiboyer ### ########.fr */ +/* Updated: 2024/05/19 17:08:45 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ +#include "me/fs/fs.h" #include "me/mem/_allocator.h" #include "me/types.h" #include void me_exit(t_i32 exit_code) { + close_all_fds(); uninit_global_allocator(); exit(exit_code); } diff --git a/stdme/src/os/process.c b/stdme/src/os/process.c index cb9bd902..4e2befae 100644 --- a/stdme/src/os/process.c +++ b/stdme/src/os/process.c @@ -6,17 +6,17 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/01/03 16:22:41 by maiboyer #+# #+# */ -/* Updated: 2024/05/18 18:33:53 by maiboyer ### ########.fr */ +/* Updated: 2024/05/19 14:57:20 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ #include "me/os/process.h" -#include "me/buffered_str/buf_str.h" +#include "me/string/string.h" #include "me/mem/mem.h" #include "me/os/pipe.h" -#include "me/string/str_find_chr.h" -#include "me/string/str_n_compare.h" -#include "me/string/str_split.h" +#include "me/str/str.h" +#include "me/str/str.h" +#include "me/str/str.h" #include "me/types.h" #include "me/vec/vec_str.h" #include @@ -53,21 +53,21 @@ t_error spawn_process_exec(t_spawn_info info, t_process *process) } t_error in_path(t_spawn_info *info, t_process *process, t_const_str path, - t_buffer_str *s) + t_string *s) { t_str *splitted_path; t_usize sp_index; splitted_path = str_split(path + 5, ':'); if (splitted_path == NULL) - return (str_free(*s), ERROR); + return (string_free(*s), ERROR); sp_index = 0; while (splitted_path[sp_index]) { - ((void)(process), str_clear(s)); - push_str_buffer(s, splitted_path[sp_index]); - push_str_buffer(s, "/"); - push_str_buffer(s, info->binary_path); + ((void)(process), string_clear(s)); + string_push(s, splitted_path[sp_index]); + string_push(s, "/"); + string_push(s, info->binary_path); sp_index++; if (access(s->buf, X_OK | R_OK) == 0) break; @@ -82,20 +82,19 @@ t_error in_path(t_spawn_info *info, t_process *process, t_const_str path, t_error find_binary(t_spawn_info *info, t_process *process) { t_usize p_idx; - t_buffer_str s; + t_string s; (void)(process); if (info->binary_path == NULL) return (ERROR); - s = alloc_new_buffer(256); + s = string_new(256); if (str_start_with(info->binary_path, "/") || str_find_chr(info->binary_path, '/') != NULL) - push_str_buffer(&s, info->binary_path); + string_push(&s, info->binary_path); else { if (vec_str_find(&info->environement, find_path, &p_idx)) - return (str_free(s), ERROR); - printf("finding in path\n"); + return (string_free(s), ERROR); if (in_path(info, process, info->environement.buffer[p_idx], &s)) return (ERROR); } @@ -105,7 +104,7 @@ t_error find_binary(t_spawn_info *info, t_process *process) info->binary_path = s.buf; return (NO_ERROR); } - return (str_free(s), ERROR); + return (string_free(s), ERROR); } static void cleanup(t_spawn_info info, t_process *process, bool cleanup_process) diff --git a/stdme/src/os/process_inner.c b/stdme/src/os/process_inner.c index 60f001b7..0cd77745 100644 --- a/stdme/src/os/process_inner.c +++ b/stdme/src/os/process_inner.c @@ -6,7 +6,7 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/01/04 22:25:44 by maiboyer #+# #+# */ -/* Updated: 2024/05/18 18:38:01 by maiboyer ### ########.fr */ +/* Updated: 2024/05/19 14:51:07 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ @@ -36,7 +36,6 @@ bool find_path(const t_str *s) if (*s == NULL) return (false); ss = *s; - printf("%s\n", ss); return (ss[0] == 'P' && ss[1] == 'A' && ss[2] == 'T' && ss[3] == 'H' && ss[4] == '='); } diff --git a/stdme/src/printf/formatter/char.c b/stdme/src/printf/formatter/char.c index 54fa8c13..a239c34e 100644 --- a/stdme/src/printf/formatter/char.c +++ b/stdme/src/printf/formatter/char.c @@ -13,8 +13,8 @@ #include "me/mem/mem.h" #include "me/printf/formatter/utils.h" #include "me/printf/printf.h" -#include "me/string/str_len.h" -#include "me/string/str_substring.h" +#include "me/str/str.h" +#include "me/str/str.h" #include void printf_c(t_printf_arg data, t_printf_func f) diff --git a/stdme/src/printf/formatter/decimal.c b/stdme/src/printf/formatter/decimal.c index 7f10ba32..ce5a5020 100644 --- a/stdme/src/printf/formatter/decimal.c +++ b/stdme/src/printf/formatter/decimal.c @@ -11,11 +11,11 @@ /* ************************************************************************** */ #include "me/mem/mem.h" -#include "me/mem/mem_set.h" +#include "me/mem/mem.h" #include "me/printf/formatter/utils.h" #include "me/printf/printf.h" -#include "me/string/str_clone.h" -#include "me/string/str_len.h" +#include "me/str/str.h" +#include "me/str/str.h" #include #include #define INT_INLINE_BUF 21 diff --git a/stdme/src/printf/formatter/hex.c b/stdme/src/printf/formatter/hex.c index 9e911506..fe2455b3 100644 --- a/stdme/src/printf/formatter/hex.c +++ b/stdme/src/printf/formatter/hex.c @@ -10,10 +10,10 @@ /* */ /* ************************************************************************** */ -#include "me/mem/mem_set.h" +#include "me/mem/mem.h" #include "me/printf/formatter/utils.h" #include "me/printf/printf.h" -#include "me/string/str_len.h" +#include "me/str/str.h" #define HEX_INLINE_BUF 17 static void fill_hex(t_str out_buf, t_u64 num, t_const_str base) diff --git a/stdme/src/printf/formatter/oct.c b/stdme/src/printf/formatter/oct.c index a6befc24..a249c419 100644 --- a/stdme/src/printf/formatter/oct.c +++ b/stdme/src/printf/formatter/oct.c @@ -10,10 +10,10 @@ /* */ /* ************************************************************************** */ -#include "me/mem/mem_set.h" +#include "me/mem/mem.h" #include "me/printf/formatter/utils.h" #include "me/printf/printf.h" -#include "me/string/str_len.h" +#include "me/str/str.h" #include #define OCT_INLINE_BUF 23 diff --git a/stdme/src/printf/formatter/ptr.c b/stdme/src/printf/formatter/ptr.c index 9f169eb7..27e65485 100644 --- a/stdme/src/printf/formatter/ptr.c +++ b/stdme/src/printf/formatter/ptr.c @@ -10,10 +10,10 @@ /* */ /* ************************************************************************** */ -#include "me/mem/mem_set.h" +#include "me/mem/mem.h" #include "me/printf/formatter/utils.h" #include "me/printf/printf.h" -#include "me/string/str_len.h" +#include "me/str/str.h" #define PTR_INLINE_BUF 17 static void fill_hex(t_str out_buf, t_u64 num, t_str base) diff --git a/stdme/src/printf/formatter/unsigned_decimal.c b/stdme/src/printf/formatter/unsigned_decimal.c index 5ac806b3..31900542 100644 --- a/stdme/src/printf/formatter/unsigned_decimal.c +++ b/stdme/src/printf/formatter/unsigned_decimal.c @@ -11,11 +11,11 @@ /* ************************************************************************** */ #include "me/mem/mem.h" -#include "me/mem/mem_set.h" +#include "me/mem/mem.h" #include "me/printf/formatter/utils.h" #include "me/printf/printf.h" -#include "me/string/str_clone.h" -#include "me/string/str_len.h" +#include "me/str/str.h" +#include "me/str/str.h" #include #include #define UINT_INLINE_BUF 21 diff --git a/stdme/src/printf/formatter/utils.c b/stdme/src/printf/formatter/utils.c index b2ab3cb5..1b4bd5d0 100644 --- a/stdme/src/printf/formatter/utils.c +++ b/stdme/src/printf/formatter/utils.c @@ -10,14 +10,14 @@ /* */ /* ************************************************************************** */ -#include "me/buffered_str/buf_str.h" +#include "me/string/string.h" #include "me/mem/mem.h" #include "me/convert/atoi.h" #include "me/printf/formatter/utils.h" #include "me/printf/matchers/matchers.h" #include "me/printf/printf.h" -#include "me/string/str_find_chr.h" -#include "me/string/str_substring.h" +#include "me/str/str.h" +#include "me/str/str.h" #include "me/types.h" #include #include diff --git a/stdme/src/printf/formatter/utils2.c b/stdme/src/printf/formatter/utils2.c index 1537211e..9976fe6d 100644 --- a/stdme/src/printf/formatter/utils2.c +++ b/stdme/src/printf/formatter/utils2.c @@ -10,8 +10,8 @@ /* */ /* ************************************************************************** */ -#include "me/buffered_str/buf_str.h" -#include "me/char/isdigit.h" +#include "me/string/string.h" +#include "me/char/char.h" #include "me/printf/formatter/utils.h" #include "me/printf/printf.h" #include "me/types.h" diff --git a/stdme/src/printf/formatter/utils3.c b/stdme/src/printf/formatter/utils3.c index 1b03f1e3..d35bb924 100644 --- a/stdme/src/printf/formatter/utils3.c +++ b/stdme/src/printf/formatter/utils3.c @@ -12,8 +12,8 @@ #include "me/printf/formatter/utils.h" #include "me/printf/matchers/matchers.h" -#include "me/string/str_find_chr.h" -#include "me/string/str_len.h" +#include "me/str/str.h" +#include "me/str/str.h" #include "me/types.h" #include diff --git a/stdme/src/printf/matchers.c b/stdme/src/printf/matchers.c index d122dac2..479950d3 100644 --- a/stdme/src/printf/matchers.c +++ b/stdme/src/printf/matchers.c @@ -10,7 +10,7 @@ /* */ /* ************************************************************************** */ -#include "me/mem/mem_compare.h" +#include "me/mem/mem.h" #include "me/printf/formatter/formatter.h" #include "me/printf/matchers/matchers.h" #include "me/printf/printf.h" diff --git a/stdme/src/printf/printf.c b/stdme/src/printf/printf.c index 6842f807..64199821 100644 --- a/stdme/src/printf/printf.c +++ b/stdme/src/printf/printf.c @@ -10,35 +10,35 @@ /* */ /* ************************************************************************** */ -#include "me/buffered_str/buf_str.h" +#include "me/string/string.h" #include "me/fs/write.h" #include "me/printf/formatter/formatter.h" #include "me/printf/formatter/utils.h" #include "me/printf/matchers/matchers.h" #include "me/printf/printf.h" -#include "me/string/str_len.h" +#include "me/str/str.h" #include "me/types.h" #include #include #include #include -// p_args is an t_buffer_str; +// p_args is an t_string; static void me_printf_add_to_string(t_const_str to_write, t_usize to_write_len, void *p_args) { - t_buffer_str *out_buf; + t_string *out_buf; - out_buf = (t_buffer_str *)p_args; + out_buf = (t_string *)p_args; (void)(to_write_len); - push_str_buffer(out_buf, to_write); + string_push(out_buf, to_write); } t_str me_printf_str(t_const_str fmt, va_list *arguments) { - t_buffer_str out; + t_string out; - out = alloc_new_buffer(str_len(fmt)); + out = string_new(str_len(fmt)); if (out.buf == NULL) { return (NULL); diff --git a/stdme/src/printf/vprintf.c b/stdme/src/printf/vprintf.c index 6cf3bc03..bd30f272 100644 --- a/stdme/src/printf/vprintf.c +++ b/stdme/src/printf/vprintf.c @@ -10,13 +10,13 @@ /* */ /* ************************************************************************** */ -#include "me/buffered_str/buf_str.h" +#include "me/string/string.h" #include "me/fs/write.h" #include "me/printf/formatter/formatter.h" #include "me/printf/formatter/utils.h" #include "me/printf/matchers/matchers.h" #include "me/printf/printf.h" -#include "me/string/str_len.h" +#include "me/str/str.h" #include "me/types.h" #include #include diff --git a/stdme/src/string/str_clone.c b/stdme/src/str/str_clone.c similarity index 92% rename from stdme/src/string/str_clone.c rename to stdme/src/str/str_clone.c index 731c6185..e2e2fd19 100644 --- a/stdme/src/string/str_clone.c +++ b/stdme/src/str/str_clone.c @@ -10,10 +10,10 @@ /* */ /* ************************************************************************** */ -#include "me/string/str_clone.h" +#include "me/str/str.h" #include "me/mem/mem.h" -#include "me/string/str_l_copy.h" -#include "me/string/str_len.h" +#include "me/str/str.h" +#include "me/str/str.h" #include t_str str_clone(t_const_str source) diff --git a/stdme/src/string/str_compare.c b/stdme/src/str/str_compare.c similarity index 92% rename from stdme/src/string/str_compare.c rename to stdme/src/str/str_compare.c index 5a2db02f..232540c6 100644 --- a/stdme/src/string/str_compare.c +++ b/stdme/src/str/str_compare.c @@ -10,7 +10,7 @@ /* */ /* ************************************************************************** */ -#include "me/string/str_compare.h" +#include "me/str/str.h" // PLEASE FIX THIS FUNCTION IF NEEDED ! bool str_compare(t_const_str lhs, t_const_str rhs) @@ -22,5 +22,5 @@ bool str_compare(t_const_str lhs, t_const_str rhs) index = 0; while (lhs[index] && rhs[index] && lhs[index] == rhs[index]) index++; - return ((t_i32)(t_u8)lhs[index] - (t_i32)(t_u8)rhs[index]); + return ((t_i32)(t_u8)lhs[index] == (t_i32)(t_u8)rhs[index]); } diff --git a/stdme/src/string/str_find_chr.c b/stdme/src/str/str_find_chr.c similarity index 96% rename from stdme/src/string/str_find_chr.c rename to stdme/src/str/str_find_chr.c index 565ead11..00f25b19 100644 --- a/stdme/src/string/str_find_chr.c +++ b/stdme/src/str/str_find_chr.c @@ -10,7 +10,7 @@ /* */ /* ************************************************************************** */ -#include "me/string/str_find_chr.h" +#include "me/str/str.h" char *str_find_chr(t_const_str str, char chr) { diff --git a/stdme/src/string/str_find_rev_chr.c b/stdme/src/str/str_find_rev_chr.c similarity index 94% rename from stdme/src/string/str_find_rev_chr.c rename to stdme/src/str/str_find_rev_chr.c index 3072f26b..c859f497 100644 --- a/stdme/src/string/str_find_rev_chr.c +++ b/stdme/src/str/str_find_rev_chr.c @@ -10,8 +10,8 @@ /* */ /* ************************************************************************** */ -#include "me/string/str_find_rev_chr.h" -#include "me/string/str_len.h" +#include "me/str/str.h" +#include "me/str/str.h" char *str_find_rev_chr(t_const_str str, char chr) { diff --git a/stdme/src/string/str_find_str.c b/stdme/src/str/str_find_str.c similarity index 97% rename from stdme/src/string/str_find_str.c rename to stdme/src/str/str_find_str.c index 4afa4893..a04a3729 100644 --- a/stdme/src/string/str_find_str.c +++ b/stdme/src/str/str_find_str.c @@ -10,7 +10,7 @@ /* */ /* ************************************************************************** */ -#include "me/string/str_n_find_str.h" +#include "me/str/str.h" const char *str_find_str(t_const_str str, t_const_str to_find) { diff --git a/stdme/src/string/str_iter.c b/stdme/src/str/str_iter.c similarity index 97% rename from stdme/src/string/str_iter.c rename to stdme/src/str/str_iter.c index dc9abb0e..2f59a3a8 100644 --- a/stdme/src/string/str_iter.c +++ b/stdme/src/str/str_iter.c @@ -10,7 +10,7 @@ /* */ /* ************************************************************************** */ -#include "me/string/str_iter.h" +#include "me/str/str.h" void str_iter(t_str s, void (*f)(t_usize, char *)) { diff --git a/stdme/src/string/str_join.c b/stdme/src/str/str_join.c similarity index 88% rename from stdme/src/string/str_join.c rename to stdme/src/str/str_join.c index 5aacfd92..29bc7d3b 100644 --- a/stdme/src/string/str_join.c +++ b/stdme/src/str/str_join.c @@ -10,11 +10,11 @@ /* */ /* ************************************************************************** */ -#include "me/mem/mem_alloc.h" -#include "me/string/str_join.h" -#include "me/string/str_l_cat.h" -#include "me/string/str_l_copy.h" -#include "me/string/str_len.h" +#include "me/mem/mem.h" +#include "me/str/str.h" +#include "me/str/str.h" +#include "me/str/str.h" +#include "me/str/str.h" #include t_str str_join(t_const_str s1, t_const_str s2) diff --git a/stdme/src/string/str_l_cat.c b/stdme/src/str/str_l_cat.c similarity index 97% rename from stdme/src/string/str_l_cat.c rename to stdme/src/str/str_l_cat.c index d35afd22..cbfa4a61 100644 --- a/stdme/src/string/str_l_cat.c +++ b/stdme/src/str/str_l_cat.c @@ -20,8 +20,8 @@ R*/ -#include "me/string/str_l_cat.h" -#include "me/string/str_len.h" +#include "me/str/str.h" +#include "me/str/str.h" t_usize str_l_cat(t_str dest, t_const_str src, t_usize buffer_size) { diff --git a/stdme/src/string/str_l_copy.c b/stdme/src/str/str_l_copy.c similarity index 97% rename from stdme/src/string/str_l_copy.c rename to stdme/src/str/str_l_copy.c index d4b9ae54..b1479ec8 100644 --- a/stdme/src/string/str_l_copy.c +++ b/stdme/src/str/str_l_copy.c @@ -20,8 +20,8 @@ R*/ -#include "me/string/str_l_copy.h" -#include "me/string/str_len.h" +#include "me/str/str.h" +#include "me/str/str.h" t_usize str_l_copy(t_str dest, t_const_str src, t_usize buffer_size) { diff --git a/stdme/src/string/str_len.c b/stdme/src/str/str_len.c similarity index 97% rename from stdme/src/string/str_len.c rename to stdme/src/str/str_len.c index e297150c..d04eb43d 100644 --- a/stdme/src/string/str_len.c +++ b/stdme/src/str/str_len.c @@ -10,7 +10,7 @@ /* */ /* ************************************************************************** */ -#include "me/string/str_len.h" +#include "me/str/str.h" t_usize str_len(t_const_str str) { diff --git a/stdme/src/string/str_map.c b/stdme/src/str/str_map.c similarity index 94% rename from stdme/src/string/str_map.c rename to stdme/src/str/str_map.c index 2e65a869..58c8f465 100644 --- a/stdme/src/string/str_map.c +++ b/stdme/src/str/str_map.c @@ -10,8 +10,8 @@ /* */ /* ************************************************************************** */ -#include "me/string/str_clone.h" -#include "me/string/str_map.h" +#include "me/str/str.h" +#include "me/str/str.h" t_str str_map(t_const_str s, char (*f)(t_usize, char)) { diff --git a/stdme/src/string/str_n_compare.c b/stdme/src/str/str_n_compare.c similarity index 85% rename from stdme/src/string/str_n_compare.c rename to stdme/src/str/str_n_compare.c index 5c39ac5e..443e96f5 100644 --- a/stdme/src/string/str_n_compare.c +++ b/stdme/src/str/str_n_compare.c @@ -10,18 +10,18 @@ /* */ /* ************************************************************************** */ -#include "me/string/str_n_compare.h" +#include "me/str/str.h" // PLEASE FIX THIS FUNCTION IF NEEDED ! -t_i32 str_n_compare(t_const_str lhs, t_const_str rhs, t_usize n) +bool str_n_compare(t_const_str lhs, t_const_str rhs, t_usize n) { t_usize index; index = 0; if (n == 0) - return (0); + return (true); while (lhs[index] && rhs[index] && lhs[index] == rhs[index] && index < n - 1) index++; - return ((t_i32)(t_u8)lhs[index] - (t_i32)(t_u8)rhs[index]); + return ((t_i32)(t_u8)lhs[index] == (t_i32)(t_u8)rhs[index]); } diff --git a/stdme/src/string/str_n_find_str.c b/stdme/src/str/str_n_find_str.c similarity index 95% rename from stdme/src/string/str_n_find_str.c rename to stdme/src/str/str_n_find_str.c index b6f618f4..9973e733 100644 --- a/stdme/src/string/str_n_find_str.c +++ b/stdme/src/str/str_n_find_str.c @@ -10,8 +10,8 @@ /* */ /* ************************************************************************** */ -#include "me/string/str_len.h" -#include "me/string/str_n_find_str.h" +#include "me/str/str.h" +#include "me/str/str.h" static t_str local_get_end_of_search(t_usize len, t_str str) { diff --git a/stdme/src/string/str_split.c b/stdme/src/str/str_split.c similarity index 97% rename from stdme/src/string/str_split.c rename to stdme/src/str/str_split.c index b6d4e80c..09a8ee6c 100644 --- a/stdme/src/string/str_split.c +++ b/stdme/src/str/str_split.c @@ -11,8 +11,8 @@ /* ************************************************************************** */ #include "me/mem/mem.h" -#include "me/string/str_l_copy.h" -#include "me/string/str_split.h" +#include "me/str/str.h" +#include "me/str/str.h" #include static t_usize local_count_words(t_const_str str, char chr); diff --git a/stdme/src/string/str_substring.c b/stdme/src/str/str_substring.c similarity index 91% rename from stdme/src/string/str_substring.c rename to stdme/src/str/str_substring.c index 790bd310..d5880cd0 100644 --- a/stdme/src/string/str_substring.c +++ b/stdme/src/str/str_substring.c @@ -10,10 +10,10 @@ /* */ /* ************************************************************************** */ -#include "me/mem/mem_alloc.h" -#include "me/string/str_l_copy.h" -#include "me/string/str_len.h" -#include "me/string/str_substring.h" +#include "me/mem/mem.h" +#include "me/str/str.h" +#include "me/str/str.h" +#include "me/str/str.h" #include t_str str_substring(t_const_str str, t_usize start, t_usize len) diff --git a/stdme/src/string/str_trim.c b/stdme/src/str/str_trim.c similarity index 90% rename from stdme/src/string/str_trim.c rename to stdme/src/str/str_trim.c index 9320f10e..5d97de7e 100644 --- a/stdme/src/string/str_trim.c +++ b/stdme/src/str/str_trim.c @@ -10,11 +10,11 @@ /* */ /* ************************************************************************** */ -#include "me/mem/mem_alloc.h" -#include "me/string/str_find_chr.h" -#include "me/string/str_l_copy.h" -#include "me/string/str_len.h" -#include "me/string/str_trim.h" +#include "me/mem/mem.h" +#include "me/str/str.h" +#include "me/str/str.h" +#include "me/str/str.h" +#include "me/str/str.h" #include t_str str_trim(t_const_str str, t_const_str charset) diff --git a/stdme/src/buffered_str/mod.c b/stdme/src/string/mod.c similarity index 82% rename from stdme/src/buffered_str/mod.c rename to stdme/src/string/mod.c index cc0fe99d..60617889 100644 --- a/stdme/src/buffered_str/mod.c +++ b/stdme/src/string/mod.c @@ -10,16 +10,16 @@ /* */ /* ************************************************************************** */ -#include "me/buffered_str/buf_str.h" +#include "me/string/string.h" #include "me/mem/mem.h" -#include "me/mem/mem_copy.h" -#include "me/mem/mem_set_zero.h" -#include "me/string/str_l_cat.h" -#include "me/string/str_len.h" +#include "me/mem/mem.h" +#include "me/mem/mem.h" +#include "me/str/str.h" +#include "me/str/str.h" #include "me/types.h" #include -t_error str_reserve(t_buffer_str *buf, t_usize size) +t_error str_reserve(t_string *buf, t_usize size) { t_str temp_buffer; t_usize new_capacity; @@ -42,7 +42,7 @@ t_error str_reserve(t_buffer_str *buf, t_usize size) return (NO_ERROR); } -t_error push_str_buffer(t_buffer_str *buf, t_const_str to_push) +t_error string_push(t_string *buf, t_const_str to_push) { t_usize to_push_len; @@ -56,25 +56,25 @@ t_error push_str_buffer(t_buffer_str *buf, t_const_str to_push) return (NO_ERROR); } -bool push_str_char(t_buffer_str *buf, char to_push) +bool string_push_char(t_string *buf, char to_push) { char push_str[2]; push_str[0] = to_push; push_str[1] = 0; - return (push_str_buffer(buf, push_str)); + return (string_push(buf, push_str)); } -void str_clear(t_buffer_str *buf) +void string_clear(t_string *buf) { mem_set_zero(buf->buf, buf->capacity); buf->len = 0; return; } -t_buffer_str alloc_new_buffer(t_usize capacity) +t_string string_new(t_usize capacity) { - t_buffer_str out; + t_string out; t_str buf; if (capacity == 0)