update stuff
This commit is contained in:
parent
5973022688
commit
544ed8b045
194 changed files with 2060 additions and 1464 deletions
|
|
@ -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 <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
|
|
|
|||
|
|
@ -25,16 +25,25 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
/// @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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -16,9 +16,12 @@
|
|||
|
||||
#include "me/types.h"
|
||||
|
||||
/// @brief A function that takes two t_str and compare them
|
||||
typedef bool (*t_vec_str_sort_fn)(t_str *, t_str *);
|
||||
/// @brief A function that free an t_str
|
||||
typedef void (*t_free_str_item)(t_str);
|
||||
|
||||
/// @brief A dynamic array of t_str
|
||||
typedef struct s_vec_str
|
||||
{
|
||||
t_free_str_item free_func;
|
||||
|
|
@ -27,32 +30,94 @@ typedef struct s_vec_str
|
|||
t_str *buffer;
|
||||
} t_vec_str;
|
||||
|
||||
t_vec_str vec_str_new(t_usize capacity,
|
||||
t_free_str_item free_function);
|
||||
/// @brief Create a new vec_str with a given capacity
|
||||
/// @param capacity The capacity of the new vec_str (in terms of elements)
|
||||
/// @param free_function The function that will be used to free the elements of the vec_str
|
||||
t_vec_str vec_str_new(t_usize capacity, t_free_str_item free_function);
|
||||
/// @brief Push an element to the last position of the vec_str
|
||||
/// @param vec The vec_str to push the element to
|
||||
/// @param element The element to push
|
||||
t_error vec_str_push(t_vec_str *vec, t_str element);
|
||||
t_error vec_str_push_front(t_vec_str *vec,
|
||||
t_str element);
|
||||
|
||||
/// @brief Push an element to the first position of the vec_str
|
||||
/// @param vec The vec_str to push the element to
|
||||
/// @param element The element to push
|
||||
/// @note This operation is O(n)
|
||||
t_error vec_str_push_front(t_vec_str *vec, t_str element);
|
||||
|
||||
/// @brief Get the last element from the vec_str, and remove it from the vec_str
|
||||
/// @param vec The vec_str to get the element from
|
||||
/// @param[out] out The last element of the vec_str
|
||||
/// @return true if the operation failed, false otherwise
|
||||
t_error vec_str_pop(t_vec_str *vec, t_str *value);
|
||||
|
||||
|
||||
/// @brief Get the first element from the vec_str, and remove it from the vec_str
|
||||
/// @param vec The vec_str to get the element from
|
||||
/// @param[out] out The first element of the vec_str
|
||||
/// @return true if the operation failed, false otherwise
|
||||
/// @note This operation is O(n)
|
||||
t_error vec_str_pop_front(t_vec_str *vec, t_str *value);
|
||||
|
||||
/// @brief Free the vector and all its elements
|
||||
/// @param vec The vec_str to free
|
||||
void vec_str_free(t_vec_str vec);
|
||||
t_error vec_str_reserve(t_vec_str *vec,
|
||||
t_usize wanted_capacity);
|
||||
t_error vec_str_find(t_vec_str *vec,
|
||||
bool (*fn)(const t_str *), t_usize *index);
|
||||
t_error vec_str_find_starting(t_vec_str *vec,
|
||||
bool (*fn)(const t_str *),
|
||||
t_usize starting_index, t_usize *index);
|
||||
t_error vec_str_all(t_vec_str *vec,
|
||||
bool (*fn)(const t_str *), bool *result);
|
||||
t_error vec_str_any(t_vec_str *vec,
|
||||
bool (*fn)(const t_str *), bool *result);
|
||||
void vec_str_iter(t_vec_str *vec,
|
||||
void (*fn)(t_usize index, t_str *value,
|
||||
void *state),
|
||||
void *state);
|
||||
|
||||
/// @brief Make the vec_str at least the given capacity
|
||||
/// @param vec The vec_str to reserve
|
||||
/// @param wanted_capacity The minimum capacity to reserve
|
||||
/// @return true if the operation failed, false otherwise
|
||||
t_error vec_str_reserve(t_vec_str *vec, t_usize wanted_capacity);
|
||||
|
||||
/// @brief Run the function and returns the index of the first element that returns true
|
||||
/// @param vec The vec_str to search in
|
||||
/// @param fn The function to run on each element
|
||||
/// @param[out] index The index of the first element that returns true
|
||||
t_error vec_str_find(t_vec_str *vec, bool (*fn)(const t_str *), t_usize *index);
|
||||
|
||||
|
||||
/// @brief Run the function and returns the index of the first element that returns true, but starting at index starting_index
|
||||
/// @param vec The vec_str to search in
|
||||
/// @param fn The function to run on each element
|
||||
/// @param starting_index The index to start the search from
|
||||
/// @param[out] index The index of the first element that returns true
|
||||
t_error vec_str_find_starting(t_vec_str *vec, bool (*fn)(const t_str *), t_usize starting_index, t_usize *index);
|
||||
|
||||
/// @brief Run the function on every element of the vec_str and returns if all elements returned true
|
||||
/// @param vec The vec_str to search in
|
||||
/// @param fn The function to run on each element
|
||||
/// @param[out] result The result of the operation
|
||||
/// @return true if the operation failed, false otherwise
|
||||
/// @note If the vec_str is empty, result will be true
|
||||
t_error vec_str_all(t_vec_str *vec, bool (*fn)(const t_str *), bool *result);
|
||||
|
||||
/// @brief Run the function on every element of the vec_str and returns if any element returned true
|
||||
/// @param vec The vec_str to search in
|
||||
/// @param fn The function to run on each element
|
||||
/// @param[out] result The result of the operation
|
||||
/// @return true if the operation failed, false otherwise
|
||||
/// @note If the vec_str is empty, result will be false
|
||||
t_error vec_str_any(t_vec_str *vec, bool (*fn)(const t_str *), bool *result);
|
||||
|
||||
/// @brief Run the function on every element of the vec_str
|
||||
/// @param vec The vec_str to iterate over
|
||||
/// @param fn The function to run on each element
|
||||
/// @param state The state to pass to the function
|
||||
void vec_str_iter(t_vec_str *vec, void (*fn)(t_usize index, t_str *value, void *state), void *state);
|
||||
|
||||
/// @brief Reverse the order of the elements in the vec_str
|
||||
/// @param vec The vec_str to reverse
|
||||
void vec_str_reverse(t_vec_str *vec);
|
||||
void vec_str_sort(t_vec_str *vec,
|
||||
t_vec_str_sort_fn is_sorted);
|
||||
|
||||
/// @brief Sort the elements of the vec_str
|
||||
/// @param vec The vec_str to sort
|
||||
/// @param is_sorted The function to use to compare the elements
|
||||
void vec_str_sort(t_vec_str *vec, t_vec_str_sort_fn is_sorted);
|
||||
|
||||
/// @brief Get a pointer to the last element of the vec_str
|
||||
/// @param vec The vec_str to get the element from
|
||||
/// @param[out] out A pointer to the last element of the vec_str
|
||||
/// @return true if the operation failed, false otherwise
|
||||
t_error vec_str_back(t_vec_str *vec, t_str **out);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
16
output/src/hashmap/env/env.c
vendored
16
output/src/hashmap/env/env.c
vendored
|
|
@ -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 <stdlib.h>
|
||||
|
||||
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));
|
||||
|
|
|
|||
2
output/src/hashmap/env/env_iter.c
vendored
2
output/src/hashmap/env/env_iter.c
vendored
|
|
@ -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),
|
||||
|
|
|
|||
10
output/src/hashmap/env/env_utils.c
vendored
10
output/src/hashmap/env/env_utils.c
vendored
|
|
@ -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 <stdlib.h>
|
||||
|
||||
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)
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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 <stdlib.h>
|
||||
|
|
|
|||
|
|
@ -10,9 +10,9 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/mem/mem_alloc_array.h"
|
||||
#include "me/mem/mem_copy.h"
|
||||
#include "me/mem/mem_set_zero.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/types.h"
|
||||
#include "me/vec/vec_parser_heredoc.h"
|
||||
#include <stdlib.h>
|
||||
|
|
|
|||
|
|
@ -10,9 +10,9 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/mem/mem_alloc_array.h"
|
||||
#include "me/mem/mem_copy.h"
|
||||
#include "me/mem/mem_set_zero.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/types.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/vec/vec_parser_range.h"
|
||||
|
|
|
|||
|
|
@ -10,9 +10,9 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/mem/mem_alloc_array.h"
|
||||
#include "me/mem/mem_copy.h"
|
||||
#include "me/mem/mem_set_zero.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/types.h"
|
||||
#include "me/vec/vec_parser_range.h"
|
||||
#include <stdlib.h>
|
||||
|
|
|
|||
|
|
@ -10,9 +10,9 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/mem/mem_alloc_array.h"
|
||||
#include "me/mem/mem_copy.h"
|
||||
#include "me/mem/mem_set_zero.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/types.h"
|
||||
#include "me/vec/vec_parser_range.h"
|
||||
#include <stdlib.h>
|
||||
|
|
|
|||
|
|
@ -10,9 +10,9 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/mem/mem_alloc_array.h"
|
||||
#include "me/mem/mem_copy.h"
|
||||
#include "me/mem/mem_set_zero.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/types.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/vec/vec_reduce_action.h"
|
||||
|
|
|
|||
|
|
@ -10,9 +10,9 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/mem/mem_alloc_array.h"
|
||||
#include "me/mem/mem_copy.h"
|
||||
#include "me/mem/mem_set_zero.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/types.h"
|
||||
#include "me/vec/vec_reduce_action.h"
|
||||
#include <stdlib.h>
|
||||
|
|
|
|||
|
|
@ -10,9 +10,9 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/mem/mem_alloc_array.h"
|
||||
#include "me/mem/mem_copy.h"
|
||||
#include "me/mem/mem_set_zero.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/types.h"
|
||||
#include "me/vec/vec_reduce_action.h"
|
||||
#include <stdlib.h>
|
||||
|
|
|
|||
|
|
@ -10,9 +10,9 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/mem/mem_alloc_array.h"
|
||||
#include "me/mem/mem_copy.h"
|
||||
#include "me/mem/mem_set_zero.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/types.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/vec/vec_str.h"
|
||||
|
|
|
|||
|
|
@ -10,9 +10,9 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/mem/mem_alloc_array.h"
|
||||
#include "me/mem/mem_copy.h"
|
||||
#include "me/mem/mem_set_zero.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/types.h"
|
||||
#include "me/vec/vec_str.h"
|
||||
#include <stdlib.h>
|
||||
|
|
|
|||
|
|
@ -10,9 +10,9 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/mem/mem_alloc_array.h"
|
||||
#include "me/mem/mem_copy.h"
|
||||
#include "me/mem/mem_set_zero.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/types.h"
|
||||
#include "me/vec/vec_str.h"
|
||||
#include <stdlib.h>
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
|
|
|
|||
|
|
@ -6,18 +6,18 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 <stdlib.h>
|
||||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 <time.h>
|
||||
|
||||
|
|
@ -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))
|
||||
|
|
|
|||
|
|
@ -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++;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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"
|
||||
|
|
|
|||
|
|
@ -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 <stdio.h>
|
||||
|
||||
|
|
|
|||
|
|
@ -25,16 +25,25 @@ C__TYPEHEADER__
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
/// @struct A key-value pair for the hashmap
|
||||
typedef struct s_kv_C__PREFIX__
|
||||
{
|
||||
C__KEYTYPE__ key;
|
||||
C__VALTYPE__ val;
|
||||
} t_kv_C__PREFIX__;
|
||||
|
||||
/// @typedef A function that hashes a key
|
||||
typedef void (*t_hash_C__PREFIX___fn)(t_hasher *hasher, C__KEYTYPE__ *key);
|
||||
/// @typedef A function that drops a key-value pair
|
||||
typedef void (*t_drop_C__PREFIX___fn)(t_kv_C__PREFIX__ val);
|
||||
/// @typedef A function that compares two keys and returns true if they are equal
|
||||
typedef bool (*t_eq_C__PREFIX___fn)(C__KEYTYPE__ *lhs, C__KEYTYPE__ *rhs);
|
||||
|
||||
|
||||
/// @struct A single entry in the hashmap
|
||||
/// @var hash_id The hash of the key
|
||||
/// @var kv The key-value pair
|
||||
/// @var next The next entry in the bucket
|
||||
typedef struct s_entry_C__PREFIX__
|
||||
{
|
||||
t_usize hash_id;
|
||||
|
|
@ -42,6 +51,13 @@ typedef struct s_entry_C__PREFIX__
|
|||
struct s_entry_C__PREFIX__ *next;
|
||||
} t_entry_C__PREFIX__;
|
||||
|
||||
/// @struct A hashmap of keys C__KEYTYPE__ and values C__VALTYPE__
|
||||
/// @var buckets The array of buckets
|
||||
/// @var num_buckets The number of buckets
|
||||
/// @var hasher The hasher function
|
||||
/// @var hfunc The hash function
|
||||
/// @var cfunc The comparison function
|
||||
/// @var drop The drop function
|
||||
typedef struct s_hashmap_C__PREFIX__
|
||||
{
|
||||
t_entry_C__PREFIX__ **buckets;
|
||||
|
|
@ -52,31 +68,56 @@ typedef struct s_hashmap_C__PREFIX__
|
|||
t_drop_C__PREFIX___fn drop;
|
||||
} t_hashmap_C__PREFIX__;
|
||||
|
||||
t_hashmap_C__PREFIX__ *new_hashmap_C__PREFIX__(t_hash_C__PREFIX___fn hash,
|
||||
t_eq_C__PREFIX___fn cmp,
|
||||
t_drop_C__PREFIX___fn drop);
|
||||
t_hashmap_C__PREFIX__ *new_hashmap_with_buckets_C__PREFIX__(
|
||||
t_hash_C__PREFIX___fn hash, t_eq_C__PREFIX___fn cmp,
|
||||
t_drop_C__PREFIX___fn drop, size_t cap);
|
||||
/// @brief Creates a new hashmap with the given hash, comparison, and drop functions
|
||||
/// @param hash The hash function
|
||||
/// @param cmp The comparison function
|
||||
/// @param drop The drop function
|
||||
/// @return A new hashmap
|
||||
t_hashmap_C__PREFIX__ *hmap_new_C__PREFIX__(t_hash_C__PREFIX___fn hash, t_eq_C__PREFIX___fn cmp, t_drop_C__PREFIX___fn drop);
|
||||
|
||||
void drop_hashmap_C__PREFIX__(t_hashmap_C__PREFIX__ *hmap);
|
||||
/// @brief Creates a new hashmap with the given hash, comparison, and drop functions
|
||||
/// @param hash The hash function
|
||||
/// @param cmp The comparison function
|
||||
/// @param drop The drop function
|
||||
/// @param cap The number of buckets
|
||||
/// @return A new hashmap
|
||||
t_hashmap_C__PREFIX__ *hmap_new_with_buckets_C__PREFIX__(t_hash_C__PREFIX___fn hash, t_eq_C__PREFIX___fn cmp, t_drop_C__PREFIX___fn drop, size_t cap);
|
||||
|
||||
void insert_hashmap_C__PREFIX__(t_hashmap_C__PREFIX__ *hmap, C__KEYTYPE__ key,
|
||||
C__VALTYPE__ value);
|
||||
/// @brief Drops the hashmap and all of its entries
|
||||
/// @param hmap The hashmap to drop
|
||||
void hmap_free_C__PREFIX__(t_hashmap_C__PREFIX__ *hmap);
|
||||
|
||||
C__VALTYPE__ *get_hashmap_C__PREFIX__(t_hashmap_C__PREFIX__ *hmap,
|
||||
C__KEYTYPE__ *key);
|
||||
void remove_hashmap_C__PREFIX__(t_hashmap_C__PREFIX__ *hmap, C__KEYTYPE__ *key);
|
||||
/// @brief Inserts a key-value pair into the hashmap
|
||||
/// @param hmap The hashmap
|
||||
/// @param key The key
|
||||
/// @param value The value
|
||||
void hmap_insert_C__PREFIX__(t_hashmap_C__PREFIX__ *hmap, C__KEYTYPE__ key, C__VALTYPE__ value);
|
||||
|
||||
t_entry_C__PREFIX__ *hashmap_get_entry_C__PREFIX__(t_hashmap_C__PREFIX__ *hmap,
|
||||
t_usize hash,
|
||||
C__KEYTYPE__ *key,
|
||||
t_entry_C__PREFIX__ **prev);
|
||||
/// @brief Gets the value associated with the key
|
||||
/// @param hmap The hashmap
|
||||
/// @param key The key
|
||||
/// @return The value associated with the key, or NULL if the key is not in the hashmap
|
||||
C__VALTYPE__ *hmap_get_C__PREFIX__(t_hashmap_C__PREFIX__ *hmap, C__KEYTYPE__ *key);
|
||||
/// @brief Removes the key-value pair from the hashmap
|
||||
/// @param hmap The hashmap
|
||||
/// @param key The key
|
||||
void hmap_remove_C__PREFIX__(t_hashmap_C__PREFIX__ *hmap, C__KEYTYPE__ *key);
|
||||
|
||||
t_error hashmap_C__PREFIX___iter(t_hashmap_C__PREFIX__ *self,
|
||||
t_error (*func)(t_usize idx,
|
||||
const C__KEYTYPE__ *key,
|
||||
C__VALTYPE__ *val, void *ctx),
|
||||
void *ctx);
|
||||
/// @brief Get an entry from the hashmap
|
||||
/// @param hmap The hashmap
|
||||
/// @param hash The hash of the key
|
||||
/// @param key The key
|
||||
/// @param prev The previous entry in the bucket
|
||||
/// @return The entry, or NULL if the key is not in the hashmap
|
||||
/// @note this is an internal function
|
||||
t_entry_C__PREFIX__ *hmap_get_entry_C__PREFIX__(t_hashmap_C__PREFIX__ *hmap, t_usize hash, C__KEYTYPE__ *key, t_entry_C__PREFIX__ **prev);
|
||||
|
||||
/// @brief Iterates over the hashmap and calls the given function for each key-value pair
|
||||
/// @param self The hashmap
|
||||
/// @param func The function to call
|
||||
/// @param ctx The context to pass to the function
|
||||
/// @return An error code
|
||||
/// @note The iteration can be stopped by returning an error code from the function
|
||||
t_error hmap_C__PREFIX___iter(t_hashmap_C__PREFIX__ *self, t_error (*func)(t_usize idx, const C__KEYTYPE__ *key, C__VALTYPE__ *val, void *ctx), void *ctx);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -16,9 +16,12 @@
|
|||
C__TYPEHEADER__
|
||||
#include "me/types.h"
|
||||
|
||||
/// @brief A function that takes two C__TYPENAME__ and compare them
|
||||
typedef bool (*t_vec_C__PREFIX___sort_fn)(C__TYPENAME__ *, C__TYPENAME__ *);
|
||||
/// @brief A function that free an C__TYPENAME__
|
||||
typedef void (*t_free_C__PREFIX___item)(C__TYPENAME__);
|
||||
|
||||
/// @brief A dynamic array of C__TYPENAME__
|
||||
typedef struct s_vec_C__PREFIX__
|
||||
{
|
||||
t_free_C__PREFIX___item free_func;
|
||||
|
|
@ -27,32 +30,94 @@ typedef struct s_vec_C__PREFIX__
|
|||
C__TYPENAME__ *buffer;
|
||||
} t_vec_C__PREFIX__;
|
||||
|
||||
t_vec_C__PREFIX__ vec_C__PREFIX___new(t_usize capacity,
|
||||
t_free_C__PREFIX___item free_function);
|
||||
/// @brief Create a new vec_C__PREFIX__ with a given capacity
|
||||
/// @param capacity The capacity of the new vec_C__PREFIX__ (in terms of elements)
|
||||
/// @param free_function The function that will be used to free the elements of the vec_C__PREFIX__
|
||||
t_vec_C__PREFIX__ vec_C__PREFIX___new(t_usize capacity, t_free_C__PREFIX___item free_function);
|
||||
/// @brief Push an element to the last position of the vec_C__PREFIX__
|
||||
/// @param vec The vec_C__PREFIX__ to push the element to
|
||||
/// @param element The element to push
|
||||
t_error vec_C__PREFIX___push(t_vec_C__PREFIX__ *vec, C__TYPENAME__ element);
|
||||
t_error vec_C__PREFIX___push_front(t_vec_C__PREFIX__ *vec,
|
||||
C__TYPENAME__ element);
|
||||
|
||||
/// @brief Push an element to the first position of the vec_C__PREFIX__
|
||||
/// @param vec The vec_C__PREFIX__ to push the element to
|
||||
/// @param element The element to push
|
||||
/// @note This operation is O(n)
|
||||
t_error vec_C__PREFIX___push_front(t_vec_C__PREFIX__ *vec, C__TYPENAME__ element);
|
||||
|
||||
/// @brief Get the last element from the vec_C__PREFIX__, and remove it from the vec_C__PREFIX__
|
||||
/// @param vec The vec_C__PREFIX__ to get the element from
|
||||
/// @param[out] out The last element of the vec_C__PREFIX__
|
||||
/// @return true if the operation failed, false otherwise
|
||||
t_error vec_C__PREFIX___pop(t_vec_C__PREFIX__ *vec, C__TYPENAME__ *value);
|
||||
|
||||
|
||||
/// @brief Get the first element from the vec_C__PREFIX__, and remove it from the vec_C__PREFIX__
|
||||
/// @param vec The vec_C__PREFIX__ to get the element from
|
||||
/// @param[out] out The first element of the vec_C__PREFIX__
|
||||
/// @return true if the operation failed, false otherwise
|
||||
/// @note This operation is O(n)
|
||||
t_error vec_C__PREFIX___pop_front(t_vec_C__PREFIX__ *vec, C__TYPENAME__ *value);
|
||||
|
||||
/// @brief Free the vector and all its elements
|
||||
/// @param vec The vec_C__PREFIX__ to free
|
||||
void vec_C__PREFIX___free(t_vec_C__PREFIX__ vec);
|
||||
t_error vec_C__PREFIX___reserve(t_vec_C__PREFIX__ *vec,
|
||||
t_usize wanted_capacity);
|
||||
t_error vec_C__PREFIX___find(t_vec_C__PREFIX__ *vec,
|
||||
bool (*fn)(const C__TYPENAME__ *), t_usize *index);
|
||||
t_error vec_C__PREFIX___find_starting(t_vec_C__PREFIX__ *vec,
|
||||
bool (*fn)(const C__TYPENAME__ *),
|
||||
t_usize starting_index, t_usize *index);
|
||||
t_error vec_C__PREFIX___all(t_vec_C__PREFIX__ *vec,
|
||||
bool (*fn)(const C__TYPENAME__ *), bool *result);
|
||||
t_error vec_C__PREFIX___any(t_vec_C__PREFIX__ *vec,
|
||||
bool (*fn)(const C__TYPENAME__ *), bool *result);
|
||||
void vec_C__PREFIX___iter(t_vec_C__PREFIX__ *vec,
|
||||
void (*fn)(t_usize index, C__TYPENAME__ *value,
|
||||
void *state),
|
||||
void *state);
|
||||
|
||||
/// @brief Make the vec_C__PREFIX__ at least the given capacity
|
||||
/// @param vec The vec_C__PREFIX__ to reserve
|
||||
/// @param wanted_capacity The minimum capacity to reserve
|
||||
/// @return true if the operation failed, false otherwise
|
||||
t_error vec_C__PREFIX___reserve(t_vec_C__PREFIX__ *vec, t_usize wanted_capacity);
|
||||
|
||||
/// @brief Run the function and returns the index of the first element that returns true
|
||||
/// @param vec The vec_C__PREFIX__ to search in
|
||||
/// @param fn The function to run on each element
|
||||
/// @param[out] index The index of the first element that returns true
|
||||
t_error vec_C__PREFIX___find(t_vec_C__PREFIX__ *vec, bool (*fn)(const C__TYPENAME__ *), t_usize *index);
|
||||
|
||||
|
||||
/// @brief Run the function and returns the index of the first element that returns true, but starting at index starting_index
|
||||
/// @param vec The vec_C__PREFIX__ to search in
|
||||
/// @param fn The function to run on each element
|
||||
/// @param starting_index The index to start the search from
|
||||
/// @param[out] index The index of the first element that returns true
|
||||
t_error vec_C__PREFIX___find_starting(t_vec_C__PREFIX__ *vec, bool (*fn)(const C__TYPENAME__ *), t_usize starting_index, t_usize *index);
|
||||
|
||||
/// @brief Run the function on every element of the vec_C__PREFIX__ and returns if all elements returned true
|
||||
/// @param vec The vec_C__PREFIX__ to search in
|
||||
/// @param fn The function to run on each element
|
||||
/// @param[out] result The result of the operation
|
||||
/// @return true if the operation failed, false otherwise
|
||||
/// @note If the vec_C__PREFIX__ is empty, result will be true
|
||||
t_error vec_C__PREFIX___all(t_vec_C__PREFIX__ *vec, bool (*fn)(const C__TYPENAME__ *), bool *result);
|
||||
|
||||
/// @brief Run the function on every element of the vec_C__PREFIX__ and returns if any element returned true
|
||||
/// @param vec The vec_C__PREFIX__ to search in
|
||||
/// @param fn The function to run on each element
|
||||
/// @param[out] result The result of the operation
|
||||
/// @return true if the operation failed, false otherwise
|
||||
/// @note If the vec_C__PREFIX__ is empty, result will be false
|
||||
t_error vec_C__PREFIX___any(t_vec_C__PREFIX__ *vec, bool (*fn)(const C__TYPENAME__ *), bool *result);
|
||||
|
||||
/// @brief Run the function on every element of the vec_C__PREFIX__
|
||||
/// @param vec The vec_C__PREFIX__ to iterate over
|
||||
/// @param fn The function to run on each element
|
||||
/// @param state The state to pass to the function
|
||||
void vec_C__PREFIX___iter(t_vec_C__PREFIX__ *vec, void (*fn)(t_usize index, C__TYPENAME__ *value, void *state), void *state);
|
||||
|
||||
/// @brief Reverse the order of the elements in the vec_C__PREFIX__
|
||||
/// @param vec The vec_C__PREFIX__ to reverse
|
||||
void vec_C__PREFIX___reverse(t_vec_C__PREFIX__ *vec);
|
||||
void vec_C__PREFIX___sort(t_vec_C__PREFIX__ *vec,
|
||||
t_vec_C__PREFIX___sort_fn is_sorted);
|
||||
|
||||
/// @brief Sort the elements of the vec_C__PREFIX__
|
||||
/// @param vec The vec_C__PREFIX__ to sort
|
||||
/// @param is_sorted The function to use to compare the elements
|
||||
void vec_C__PREFIX___sort(t_vec_C__PREFIX__ *vec, t_vec_C__PREFIX___sort_fn is_sorted);
|
||||
|
||||
/// @brief Get a pointer to the last element of the vec_C__PREFIX__
|
||||
/// @param vec The vec_C__PREFIX__ to get the element from
|
||||
/// @param[out] out A pointer to the last element of the vec_C__PREFIX__
|
||||
/// @return true if the operation failed, false otherwise
|
||||
t_error vec_C__PREFIX___back(t_vec_C__PREFIX__ *vec, C__TYPENAME__ **out);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -10,9 +10,9 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/char/isalpha.h"
|
||||
#include "me/char/char.h"
|
||||
#include "me/convert/str_to_numbers.h"
|
||||
#include "me/string/str_len.h"
|
||||
#include "me/str/str.h"
|
||||
#include "me/types.h"
|
||||
|
||||
#define OP_ADD 0b0001
|
||||
|
|
|
|||
|
|
@ -11,9 +11,9 @@
|
|||
/* ************************************************************************** */
|
||||
|
||||
|
||||
#include "me/char/isalpha.h"
|
||||
#include "me/char/char.h"
|
||||
#include "me/convert/str_to_numbers.h"
|
||||
#include "me/string/str_len.h"
|
||||
#include "me/str/str.h"
|
||||
#include "me/types.h"
|
||||
#include "me/printf/printf.h"
|
||||
|
||||
|
|
|
|||
|
|
@ -14,19 +14,19 @@
|
|||
#include "me/hash/sip.h"
|
||||
#include "me/hashmap/hashmap_C__PREFIX__.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/mem/mem_copy.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/types.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
t_hashmap_C__PREFIX__ *new_hashmap_C__PREFIX__(t_hash_C__PREFIX___fn hfunc,
|
||||
t_hashmap_C__PREFIX__ *hmap_new_C__PREFIX__(t_hash_C__PREFIX___fn hfunc,
|
||||
t_eq_C__PREFIX___fn cfunc,
|
||||
t_drop_C__PREFIX___fn drop)
|
||||
{
|
||||
return (new_hashmap_with_buckets_C__PREFIX__(hfunc, cfunc, drop,
|
||||
return (hmap_new_with_buckets_C__PREFIX__(hfunc, cfunc, drop,
|
||||
DEFAULT_BUCKETS));
|
||||
}
|
||||
|
||||
t_hashmap_C__PREFIX__ *new_hashmap_with_buckets_C__PREFIX__(
|
||||
t_hashmap_C__PREFIX__ *hmap_new_with_buckets_C__PREFIX__(
|
||||
t_hash_C__PREFIX___fn hfunc, t_eq_C__PREFIX___fn cfunc,
|
||||
t_drop_C__PREFIX___fn drop, t_usize buckets)
|
||||
{
|
||||
|
|
@ -46,7 +46,7 @@ t_hashmap_C__PREFIX__ *new_hashmap_with_buckets_C__PREFIX__(
|
|||
return (hmap);
|
||||
}
|
||||
|
||||
void drop_hashmap_C__PREFIX__(t_hashmap_C__PREFIX__ *hmap)
|
||||
void hmap_free_C__PREFIX__(t_hashmap_C__PREFIX__ *hmap)
|
||||
{
|
||||
t_usize index;
|
||||
|
||||
|
|
@ -65,7 +65,7 @@ void drop_hashmap_C__PREFIX__(t_hashmap_C__PREFIX__ *hmap)
|
|||
mem_free(hmap);
|
||||
}
|
||||
|
||||
t_entry_C__PREFIX__ *hashmap_get_entry_C__PREFIX__(t_hashmap_C__PREFIX__ *hmap,
|
||||
t_entry_C__PREFIX__ *hmap_get_entry_C__PREFIX__(t_hashmap_C__PREFIX__ *hmap,
|
||||
t_usize hashed_key,
|
||||
C__KEYTYPE__ *key,
|
||||
t_entry_C__PREFIX__ **prev)
|
||||
|
|
@ -88,7 +88,7 @@ t_entry_C__PREFIX__ *hashmap_get_entry_C__PREFIX__(t_hashmap_C__PREFIX__ *hmap,
|
|||
return (NULL);
|
||||
}
|
||||
|
||||
void insert_hashmap_C__PREFIX__(t_hashmap_C__PREFIX__ *hmap, C__KEYTYPE__ key,
|
||||
void hmap_insert_C__PREFIX__(t_hashmap_C__PREFIX__ *hmap, C__KEYTYPE__ key,
|
||||
C__VALTYPE__ value)
|
||||
{
|
||||
t_usize hashed_key;
|
||||
|
|
@ -98,7 +98,7 @@ void insert_hashmap_C__PREFIX__(t_hashmap_C__PREFIX__ *hmap, C__KEYTYPE__ key,
|
|||
hmap->hfunc(&hmap->hasher, &key);
|
||||
hashed_key = hasher_reset_and_finish(&hmap->hasher);
|
||||
prev = NULL;
|
||||
entry = hashmap_get_entry_C__PREFIX__(hmap, hashed_key, &key, &prev);
|
||||
entry = hmap_get_entry_C__PREFIX__(hmap, hashed_key, &key, &prev);
|
||||
if (entry == NULL)
|
||||
{
|
||||
entry = mem_alloc(sizeof(t_entry_C__PREFIX__));
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
#include "me/hashmap/hashmap_C__PREFIX__.h"
|
||||
|
||||
t_error hashmap_C__PREFIX___iter(t_hashmap_C__PREFIX__ *self,
|
||||
t_error hmap_C__PREFIX___iter(t_hashmap_C__PREFIX__ *self,
|
||||
t_error (*func)(t_usize idx,
|
||||
const C__KEYTYPE__ *key,
|
||||
C__VALTYPE__ *val, void *ctx),
|
||||
|
|
|
|||
|
|
@ -13,11 +13,11 @@
|
|||
#include "me/hash/sip.h"
|
||||
#include "me/hashmap/hashmap_C__PREFIX__.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/mem/mem_copy.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/types.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
C__VALTYPE__ *get_hashmap_C__PREFIX__(t_hashmap_C__PREFIX__ *hmap,
|
||||
C__VALTYPE__ *hmap_get_C__PREFIX__(t_hashmap_C__PREFIX__ *hmap,
|
||||
C__KEYTYPE__ *key)
|
||||
{
|
||||
t_usize hashed_key;
|
||||
|
|
@ -26,13 +26,13 @@ C__VALTYPE__ *get_hashmap_C__PREFIX__(t_hashmap_C__PREFIX__ *hmap,
|
|||
|
||||
hmap->hfunc(&hmap->hasher, key);
|
||||
hashed_key = hasher_reset_and_finish(&hmap->hasher);
|
||||
entry = hashmap_get_entry_C__PREFIX__(hmap, hashed_key, key, &prev);
|
||||
entry = hmap_get_entry_C__PREFIX__(hmap, hashed_key, key, &prev);
|
||||
if (entry == NULL)
|
||||
return (NULL);
|
||||
return (&entry->kv.val);
|
||||
}
|
||||
|
||||
void remove_hashmap_C__PREFIX__(t_hashmap_C__PREFIX__ *hmap, C__KEYTYPE__ *key)
|
||||
void hmap_remove_C__PREFIX__(t_hashmap_C__PREFIX__ *hmap, C__KEYTYPE__ *key)
|
||||
{
|
||||
t_usize hashed_key;
|
||||
t_entry_C__PREFIX__ *prev;
|
||||
|
|
@ -42,7 +42,7 @@ void remove_hashmap_C__PREFIX__(t_hashmap_C__PREFIX__ *hmap, C__KEYTYPE__ *key)
|
|||
hashed_key = hasher_reset_and_finish(&hmap->hasher);
|
||||
hmap->hasher = hasher_sip13_new();
|
||||
prev = NULL;
|
||||
entry = hashmap_get_entry_C__PREFIX__(hmap, hashed_key, key, &prev);
|
||||
entry = hmap_get_entry_C__PREFIX__(hmap, hashed_key, key, &prev);
|
||||
if (entry == NULL)
|
||||
return;
|
||||
if (prev == NULL)
|
||||
|
|
|
|||
|
|
@ -10,9 +10,9 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/mem/mem_alloc_array.h"
|
||||
#include "me/mem/mem_copy.h"
|
||||
#include "me/mem/mem_set_zero.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/types.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/vec/vec_C__PREFIX__.h"
|
||||
|
|
|
|||
|
|
@ -10,9 +10,9 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/mem/mem_alloc_array.h"
|
||||
#include "me/mem/mem_copy.h"
|
||||
#include "me/mem/mem_set_zero.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/types.h"
|
||||
#include "me/vec/vec_C__PREFIX__.h"
|
||||
#include <stdlib.h>
|
||||
|
|
|
|||
|
|
@ -10,9 +10,9 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/mem/mem_alloc_array.h"
|
||||
#include "me/mem/mem_copy.h"
|
||||
#include "me/mem/mem_set_zero.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/types.h"
|
||||
#include "me/vec/vec_C__PREFIX__.h"
|
||||
#include <stdlib.h>
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@
|
|||
# include "me/vec2/vec2.h"
|
||||
# include "me/blx/sprite.h"
|
||||
# include "me/blx/inputs.h"
|
||||
# include "me/blx/points.h"
|
||||
# include "me/types.h"
|
||||
|
||||
typedef struct s_blx t_blx;
|
||||
|
|
@ -61,20 +60,77 @@ typedef struct s_blx
|
|||
t_blx_data _data;
|
||||
} t_blx;
|
||||
|
||||
/// @brief The main loop function
|
||||
/// @param ctx the BLX context
|
||||
/// @note this is the function that will be called every frame
|
||||
/// @note this is an internal function, you should not call it yourself
|
||||
int blx_loop_func(t_blx *ctx);
|
||||
/// @brief Initialize the BLX context
|
||||
/// @param func the main loop function
|
||||
/// @param free_fn the free function
|
||||
/// @param data the application data
|
||||
/// @return
|
||||
t_blx blx_initialize(t_run_function func,
|
||||
t_free_function free_fn, t_blx_app data);
|
||||
|
||||
/// @brief Draw a sprite onto the screen
|
||||
/// @param app The blx context
|
||||
/// @param pos The position to draw the sprite at
|
||||
/// @param spr The sprite to draw
|
||||
void draw_sprite(t_blx *app, t_vi2d pos,
|
||||
t_sprite *spr);
|
||||
|
||||
/// @brief is the key pressed
|
||||
/// @param ctx the BLX context
|
||||
/// @param input the key to check
|
||||
/// @return true if the key is pressed, false otherwise
|
||||
bool is_key_pressed(t_blx *ctx, t_keysym input);
|
||||
|
||||
|
||||
/// @brief is the key held
|
||||
/// @param ctx the BLX context
|
||||
/// @param input the key to check
|
||||
/// @return true if the key is held, false otherwise
|
||||
bool is_key_held(t_blx *ctx, t_keysym input);
|
||||
|
||||
|
||||
/// @brief is the key released
|
||||
/// @param ctx the BLX context
|
||||
/// @param input the key to check
|
||||
/// @return true if the key is released, false otherwise
|
||||
bool is_key_released(t_blx *ctx, t_keysym input);
|
||||
|
||||
/// @brief Start the game
|
||||
/// @param app the BLX context
|
||||
void blx_run(t_blx app);
|
||||
|
||||
/// @brief Free the game
|
||||
/// @param app the BLX context
|
||||
void blx_free(t_blx app);
|
||||
|
||||
/// @brief Draw a pixel onto the screen
|
||||
/// @param app the BLX context
|
||||
/// @param pos the position to draw the pixel at
|
||||
/// @param col the color of the pixel
|
||||
void blx_draw(t_blx *app, t_vi2d pos, t_color col);
|
||||
|
||||
/// @brief Clear the screen with a color
|
||||
/// @param app the BLX context
|
||||
/// @param col the color to clear the screen with
|
||||
void blx_clear(t_blx *app, t_color col);
|
||||
|
||||
/// @brief Draw a sprite onto another sprite
|
||||
/// @param dest the sprite to be drawn onto
|
||||
/// @param pos the position to draw the sprite at
|
||||
/// @param source the sprite to draw
|
||||
void sprite_draw_onto(t_sprite *dest, t_vi2d pos,
|
||||
t_sprite *source);
|
||||
|
||||
/// @brief Draw a string onto the screen
|
||||
/// @param app the BLX context
|
||||
/// @param pos the position to draw the string at
|
||||
/// @param s the string to draw
|
||||
/// @param col the color of the string
|
||||
void blx_draw_string(t_blx *app, t_vi2d pos,
|
||||
t_const_str s, t_color col);
|
||||
|
||||
|
|
|
|||
|
|
@ -15,8 +15,21 @@
|
|||
# include "me/blx/blx_key.h"
|
||||
# include "me/types.h"
|
||||
|
||||
/// @brief Handle a key press event
|
||||
/// @param keysym the key that was pressed
|
||||
/// @param ctx the BLX context
|
||||
/// @note this is an internal function, you should not call it yourself
|
||||
int blx_key_pressed_handler(t_keysym keysym, t_blx *ctx);
|
||||
|
||||
/// @brief Handle a key released event
|
||||
/// @param keysym the key that was released
|
||||
/// @param ctx the BLX context
|
||||
/// @note this is an internal function, you should not call it yourself
|
||||
int blx_key_released_handler(t_keysym keysym, t_blx *ctx);
|
||||
|
||||
/// @brief Handle a exit event
|
||||
/// @param ctx the BLX context
|
||||
/// @note this is an internal function, you should not call it yourself
|
||||
int blx_key_exit_handler(t_blx *ctx);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -166,10 +166,34 @@ typedef enum e_keysym
|
|||
|
||||
typedef struct s_blx t_blx;
|
||||
|
||||
/// @brief Convert a keysym to a bit index
|
||||
/// @param key the keysym to convert
|
||||
/// @return the bit index
|
||||
/// @note this is an internal function, you should not call it yourself
|
||||
t_usize keysym_to_bit_index(t_keysym key);
|
||||
|
||||
/// @brief Get a key from a key storage
|
||||
/// @param key_storage the key storage
|
||||
/// @param keysym the key to get
|
||||
/// @return true if the key is present in the storage, false otherwise
|
||||
bool get_key(t_vec_u8 *key_storage, t_keysym keysym);
|
||||
|
||||
/// @brief is the key pressed
|
||||
/// @param ctx The BLX context
|
||||
/// @param key the key to check
|
||||
/// @return true if the key is pressed, false otherwise
|
||||
bool is_key_pressed(t_blx *ctx, t_keysym key);
|
||||
|
||||
/// @brief is the key held
|
||||
/// @param ctx The BLX context
|
||||
/// @param key the key to check
|
||||
/// @return true if the key is held, false otherwise
|
||||
bool is_key_held(t_blx *ctx, t_keysym key);
|
||||
|
||||
/// @brief is the key released
|
||||
/// @param ctx The BLX context
|
||||
/// @param key the key to check
|
||||
/// @return true if the key is released, false otherwise
|
||||
bool is_key_released(t_blx *ctx, t_keysym key);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -23,7 +23,19 @@ typedef __attribute__((aligned(4))) struct s_color
|
|||
t_u8 a;
|
||||
} t_color;
|
||||
|
||||
/// @brief Create a new color with an specified alpha channel
|
||||
/// @param r the red channel
|
||||
/// @param g the green channel
|
||||
/// @param b the blue channel
|
||||
/// @param alpha the alpha channel
|
||||
/// @return the resulting color
|
||||
t_color new_color_with_alpha(t_u8 r, t_u8 g, t_u8 b, t_u8 alpha);
|
||||
|
||||
/// @brief Create a new color
|
||||
/// @param r the red channel
|
||||
/// @param g the green channel
|
||||
/// @param b the blue channel
|
||||
/// @return the resulting color
|
||||
t_color new_color(t_u8 r, t_u8 g, t_u8 b);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -31,6 +31,10 @@ typedef struct s_blx_input
|
|||
|
||||
} t_blx_input;
|
||||
|
||||
/// @brief Create an input manager
|
||||
/// @param ctx the BLX context
|
||||
/// @return the created input manager
|
||||
/// @note this is an internal function, you should not call it yourself
|
||||
t_blx_input create_inputs_manager(t_blx *ctx);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,24 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* points.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/12/13 17:47:17 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/13 18:14:20 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef POINTS_H
|
||||
# define POINTS_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
typedef struct s_point
|
||||
{
|
||||
t_i32 x;
|
||||
t_i32 y;
|
||||
} t_point;
|
||||
|
||||
#endif
|
||||
|
|
@ -35,19 +35,63 @@ typedef struct s_sprite
|
|||
bool big_endian;
|
||||
} t_sprite;
|
||||
|
||||
bool blx_sprite_from_xpm(t_blx *ctx, t_str path,
|
||||
/// @brief Create a sprite from an XPM file
|
||||
/// @param ctx the BLX context
|
||||
/// @param path the path to the XPM file
|
||||
/// @param[out] out the output sprite
|
||||
/// @return true if an error occured, false otherwise
|
||||
t_error blx_sprite_from_xpm(t_blx *ctx, t_str path,
|
||||
t_sprite *out);
|
||||
bool blx_sprite_new(t_blx *ctx, t_i32 width, t_i32 height,
|
||||
|
||||
/// @brief Create a new sprite
|
||||
/// @param ctx the BLX context
|
||||
/// @param width the width of the sprite in pixels
|
||||
/// @param height the height of the sprite in pixels
|
||||
/// @param out[out] the output sprite
|
||||
/// @return true if an error occured, false otherwise
|
||||
t_error blx_sprite_new(t_blx *ctx, t_i32 width, t_i32 height,
|
||||
t_sprite *out);
|
||||
/// @brief Free a sprite
|
||||
/// @param img the sprite to free
|
||||
void blx_sprite_free(t_sprite img);
|
||||
/// @brief Draw a sprite at a position onto the screen
|
||||
/// @param ctx the BLX context
|
||||
/// @param pos the position to draw the sprite at
|
||||
/// @param img the sprite to draw
|
||||
void blx_draw_sprite_raw(t_blx *ctx, t_vi2d pos,
|
||||
t_sprite *img);
|
||||
|
||||
/// @brief Draw a pixel onto the sprite
|
||||
/// @param img the sprite to draw onto
|
||||
/// @param pos the position to draw the pixel at
|
||||
/// @param col the color of the pixel
|
||||
void sprite_draw(t_sprite *img, t_vi2d pos, t_color col);
|
||||
|
||||
/// @brief Clear a sprite with a color
|
||||
/// @param img the sprite to clear
|
||||
/// @param col the color to clear the sprite with
|
||||
void sprite_clear(t_sprite *img, t_color col);
|
||||
bool sprite_get_pixel(t_sprite *spr, t_vi2d pos,
|
||||
|
||||
/// @brief Get the color of a pixel on a sprite
|
||||
/// @param spr the sprite to get the pixel from
|
||||
/// @param pos the position of the pixel
|
||||
/// @param[out] out the color of the pixel
|
||||
/// @return true if an error occured, false otherwise
|
||||
t_error sprite_get_pixel(t_sprite *spr, t_vi2d pos,
|
||||
t_color *out);
|
||||
|
||||
/// @brief Draw a sprite onto another sprite
|
||||
/// @param dest The sprite to be drawn onto
|
||||
/// @param pos The position to draw the sprite at
|
||||
/// @param source The sprite to draw
|
||||
void sprite_draw_onto(t_sprite *dest, t_vi2d pos,
|
||||
t_sprite *source);
|
||||
|
||||
/// @brief Draw a string onto a sprite
|
||||
/// @param spr The sprite to draw onto
|
||||
/// @param pos The position to draw the string at
|
||||
/// @param sText The string to draw
|
||||
/// @param col The color of the string
|
||||
void sprite_draw_string(t_sprite *spr, t_vi2d pos,
|
||||
t_const_str sText, t_color col);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,50 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* buf_str.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/16 17:54:28 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/04/30 14:14:42 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef BUF_STR_H
|
||||
# define BUF_STR_H
|
||||
# include "me/types.h"
|
||||
|
||||
typedef struct s_buffer_str
|
||||
{
|
||||
t_str buf;
|
||||
t_usize capacity;
|
||||
t_usize len;
|
||||
} t_buffer_str;
|
||||
|
||||
bool push_str_buffer(t_buffer_str *buf, t_const_str to_push);
|
||||
bool push_str_char(t_buffer_str *buf, char to_push);
|
||||
void str_clear(t_buffer_str *buf);
|
||||
t_buffer_str alloc_new_buffer(t_usize capacity);
|
||||
t_error str_reserve(t_buffer_str *buf, t_usize size);
|
||||
|
||||
static inline void str_free(t_buffer_str buf)
|
||||
{
|
||||
void mem_free(void *);
|
||||
|
||||
mem_free(buf.buf);
|
||||
}
|
||||
|
||||
static inline char str_pop(t_buffer_str *buf)
|
||||
{
|
||||
char c;
|
||||
|
||||
c = '\0';
|
||||
if (buf->buf && buf->len)
|
||||
{
|
||||
c = buf->buf[buf->len - 1];
|
||||
buf->buf[buf->len - 1] = '\0';
|
||||
}
|
||||
return (c);
|
||||
}
|
||||
|
||||
#endif
|
||||
63
stdme/include/me/char/char.h
Normal file
63
stdme/include/me/char/char.h
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* char.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/19 17:11:41 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/05/19 17:11:42 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef CHAR_H
|
||||
#define CHAR_H
|
||||
|
||||
#include "me/types.h"
|
||||
|
||||
/// @brief Check if a character is alphanumeric
|
||||
/// @param chr char to check
|
||||
/// @return chr is a alphanumeric
|
||||
bool me_isalnum(char chr);
|
||||
|
||||
/// @brief Check if a character is alphabetic
|
||||
/// @param chr char to check
|
||||
/// @return chr is a alphabetic
|
||||
bool me_isalpha(char chr);
|
||||
|
||||
/// @brief Check if a character is a digit
|
||||
/// @param chr
|
||||
/// @return chr is a digit
|
||||
bool me_isdigit(char chr);
|
||||
|
||||
/// @brief Check if a character is in the ascii range
|
||||
/// @param chr char to check
|
||||
/// @return chr is a ascii character
|
||||
bool me_isascii(char chr);
|
||||
|
||||
/// @brief Check if a character is lowercase
|
||||
/// @param chr char to check
|
||||
/// @return chr is a lowercase letter
|
||||
bool me_islower(char chr);
|
||||
|
||||
/// @brief Check if a character is uppercase
|
||||
/// @param chr char to check
|
||||
/// @return chr is a uppercase letter
|
||||
bool me_isupper(char chr);
|
||||
|
||||
/// @brief Check if a character is a whitespace
|
||||
/// @param chr char to check
|
||||
/// @return chr is a whitespace
|
||||
bool me_isspace(char chr);
|
||||
|
||||
/// @brief Set the character to lowercase if it's uppercase
|
||||
/// @param chr char to convert
|
||||
/// @return uppercase chr or chr if not a lowercase letter
|
||||
char me_tolower(char chr);
|
||||
|
||||
/// @brief Set the character to uppercase if it's lowercase
|
||||
/// @param chr char to convert
|
||||
/// @return lowercase chr or chr if not a uppercase letter
|
||||
char me_toupper(char chr);
|
||||
|
||||
#endif /* CHAR_H */
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* isalnum.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/04 16:19:40 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:39:39 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef ISALNUM_H
|
||||
# define ISALNUM_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
bool me_isalnum(char chr);
|
||||
|
||||
#endif
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* isalpha.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/04 16:19:40 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:39:36 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef ISALPHA_H
|
||||
# define ISALPHA_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
bool me_isalpha(char chr);
|
||||
|
||||
#endif
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* isascii.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/09 17:51:01 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:39:33 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef ISASCII_H
|
||||
# define ISASCII_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
bool me_isascii(char chr);
|
||||
|
||||
#endif
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* isdigit.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/04 16:19:40 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:41:55 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef ISDIGIT_H
|
||||
# define ISDIGIT_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
bool me_isdigit(char chr);
|
||||
|
||||
#endif
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* islower.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/04 16:19:40 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:48:25 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef ISLOWER_H
|
||||
# define ISLOWER_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
bool me_islower(char chr);
|
||||
|
||||
#endif
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* isprint.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/04 16:19:40 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:44:49 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef ISPRINT_H
|
||||
# define ISPRINT_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
bool me_isprint(char chr);
|
||||
|
||||
#endif
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* isspace.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/06 14:26:25 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:45:02 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef ISSPACE_H
|
||||
# define ISSPACE_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
bool me_isspace(char chr);
|
||||
|
||||
#endif
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* isupper.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/04 16:19:40 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:45:16 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef ISUPPER_H
|
||||
# define ISUPPER_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
bool me_isupper(char chr);
|
||||
|
||||
#endif
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tolower.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/04 16:47:50 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:45:33 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef TOLOWER_H
|
||||
# define TOLOWER_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
bool me_tolower(char chr);
|
||||
|
||||
#endif
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* toupper.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/04 16:47:50 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:45:52 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef TOUPPER_H
|
||||
# define TOUPPER_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
bool me_toupper(char chr);
|
||||
|
||||
#endif
|
||||
|
|
@ -15,16 +15,75 @@
|
|||
|
||||
# include "me/types.h"
|
||||
|
||||
/// @brief convert the string to a number and checks for error
|
||||
/// @param str string to convert from
|
||||
/// @param radix base of the number (between 2 and 36)
|
||||
/// @param out pointer to the number in case of success
|
||||
/// @return true if an error occured, false otherwise
|
||||
t_error str_to_isize(t_const_str str, t_u32 radix, t_isize *out);
|
||||
|
||||
/// @brief convert the string to a number and checks for error
|
||||
/// @param str string to convert from
|
||||
/// @param radix base of the number (between 2 and 36)
|
||||
/// @param out pointer to the number in case of success
|
||||
/// @return true if an error occured, false otherwise
|
||||
t_error str_to_i64(t_const_str str, t_u32 radix, t_i64 *out);
|
||||
|
||||
/// @brief convert the string to a number and checks for error
|
||||
/// @param str string to convert from
|
||||
/// @param radix base of the number (between 2 and 36)
|
||||
/// @param out pointer to the number in case of success
|
||||
/// @return true if an error occured, false otherwise
|
||||
t_error str_to_i32(t_const_str str, t_u32 radix, t_i32 *out);
|
||||
|
||||
/// @brief convert the string to a number and checks for error
|
||||
/// @param str string to convert from
|
||||
/// @param radix base of the number (between 2 and 36)
|
||||
/// @param out pointer to the number in case of success
|
||||
/// @return true if an error occured, false otherwise
|
||||
t_error str_to_i16(t_const_str str, t_u32 radix, t_i16 *out);
|
||||
|
||||
/// @brief convert the string to a number and checks for error
|
||||
/// @param str string to convert from
|
||||
/// @param radix base of the number (between 2 and 36)
|
||||
/// @param out pointer to the number in case of success
|
||||
/// @return true if an error occured, false otherwise
|
||||
t_error str_to_i8(t_const_str str, t_u32 radix, t_i8 *out);
|
||||
|
||||
|
||||
/// @brief convert the string to a number and checks for error
|
||||
/// @param str string to convert from
|
||||
/// @param radix base of the number (between 2 and 36)
|
||||
/// @param out pointer to the number in case of success
|
||||
/// @return true if an error occured, false otherwise
|
||||
t_error str_to_usize(t_const_str str, t_u32 radix, t_usize *out);
|
||||
|
||||
/// @brief convert the string to a number and checks for error
|
||||
/// @param str string to convert from
|
||||
/// @param radix base of the number (between 2 and 36)
|
||||
/// @param out pointer to the number in case of success
|
||||
/// @return true if an error occured, false otherwise
|
||||
t_error str_to_u64(t_const_str str, t_u32 radix, t_u64 *out);
|
||||
|
||||
/// @brief convert the string to a number and checks for error
|
||||
/// @param str string to convert from
|
||||
/// @param radix base of the number (between 2 and 36)
|
||||
/// @param out pointer to the number in case of success
|
||||
/// @return true if an error occured, false otherwise
|
||||
t_error str_to_u32(t_const_str str, t_u32 radix, t_u32 *out);
|
||||
|
||||
/// @brief convert the string to a number and checks for error
|
||||
/// @param str string to convert from
|
||||
/// @param radix base of the number (between 2 and 36)
|
||||
/// @param out pointer to the number in case of success
|
||||
/// @return true if an error occured, false otherwise
|
||||
t_error str_to_u16(t_const_str str, t_u32 radix, t_u16 *out);
|
||||
|
||||
/// @brief convert the string to a number and checks for error
|
||||
/// @param str string to convert from
|
||||
/// @param radix base of the number (between 2 and 36)
|
||||
/// @param out pointer to the number in case of success
|
||||
/// @return true if an error occured, false otherwise
|
||||
t_error str_to_u8(t_const_str str, t_u32 radix, t_u8 *out);
|
||||
|
||||
#endif /* STR_TO_NUMBERS_H */
|
||||
|
|
|
|||
91
stdme/include/me/fs/fs.h
Normal file
91
stdme/include/me/fs/fs.h
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* fs.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/19 15:12:18 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/05/19 17:08:38 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef FS_H
|
||||
#define FS_H
|
||||
|
||||
#include "me/types.h"
|
||||
#include <dirent.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#if !defined(FILE_SLOT_LEN) || FILE_SLOT_LEN < 64
|
||||
# ifdef FILE_SLOT_LEN
|
||||
# undef FILE_SLOT_LEN
|
||||
# endif
|
||||
# define FILE_SLOT_LEN 512
|
||||
#endif
|
||||
|
||||
enum e_file_slot_kind
|
||||
{
|
||||
SLOT_UNUSED = 0 << 0,
|
||||
SLOT_FD = 1 << 0,
|
||||
SLOT_DIR = 1 << 1,
|
||||
SLOT_FILE = 1 << 2,
|
||||
};
|
||||
|
||||
typedef enum e_fd_type
|
||||
{
|
||||
FD_FILE = 1 << 0,
|
||||
FD_PIPE = 1 << 1,
|
||||
FD_SOCK = 1 << 2,
|
||||
FD_UNKNOWN = 1 << 7,
|
||||
} t_fd_type;
|
||||
|
||||
typedef enum e_fd_perm
|
||||
{
|
||||
FD_READ = 1 << 0,
|
||||
FD_WRITE = 1 << 1,
|
||||
} t_fd_perm;
|
||||
|
||||
typedef struct s_fd
|
||||
{
|
||||
char *name;
|
||||
int fd;
|
||||
t_fd_perm perms;
|
||||
t_fd_type type;
|
||||
} t_fd;
|
||||
|
||||
typedef struct s_dir
|
||||
{
|
||||
DIR *ptr;
|
||||
char *name;
|
||||
} t_dir;
|
||||
|
||||
typedef struct s_file_data
|
||||
{
|
||||
FILE *ptr;
|
||||
char *name;
|
||||
} t_file_data;
|
||||
|
||||
union u_file_slot {
|
||||
t_fd fd;
|
||||
t_dir dir;
|
||||
t_file_data file;
|
||||
};
|
||||
|
||||
struct s_file_slot
|
||||
{
|
||||
enum e_file_slot_kind ty;
|
||||
union u_file_slot slot;
|
||||
};
|
||||
|
||||
typedef struct s_fd_array
|
||||
{
|
||||
struct s_file_slot storage[FILE_SLOT_LEN];
|
||||
} t_fd_array;
|
||||
|
||||
t_fd_array *get_fd_arrays(void);
|
||||
struct s_file_slot *get_unused_fd_slot(void);
|
||||
void close_all_fds(void);
|
||||
|
||||
#endif /* FS_H */
|
||||
|
|
@ -21,7 +21,7 @@
|
|||
# define BUFFER_LENGTH 512
|
||||
# endif
|
||||
|
||||
# include "me/buffered_str/buf_str.h"
|
||||
# include "me/string/string.h"
|
||||
# include "me/types.h"
|
||||
|
||||
typedef struct s_static_buffer
|
||||
|
|
@ -38,6 +38,6 @@ typedef struct s_copy_flags
|
|||
bool empty_read;
|
||||
} t_copy_flags;
|
||||
|
||||
t_buffer_str get_next_line(t_file fd, bool *error);
|
||||
t_string get_next_line(t_file fd, bool *error);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -29,24 +29,78 @@ typedef struct s_hasher
|
|||
|
||||
} t_hasher;
|
||||
|
||||
/// @brief Write [counts] bytes to the hasher
|
||||
/// @param hasher the hasher to write to
|
||||
/// @param bytes the bytes to write
|
||||
/// @param count the number of bytes to write
|
||||
void hasher_write_bytes(t_hasher *hasher,
|
||||
t_u8 *bytes, t_usize count);
|
||||
|
||||
/// @brief Write an u8 to the hasher
|
||||
/// @param hasher the hasher to write to
|
||||
/// @param n the value to write
|
||||
void hasher_write_u8(t_hasher *hasher, t_u8 n);
|
||||
|
||||
/// @brief Write an u16 to the hasher
|
||||
/// @param hasher the hasher to write to
|
||||
/// @param n the value to write
|
||||
void hasher_write_u16(t_hasher *hasher, t_u16 n);
|
||||
|
||||
/// @brief Write an u32 to the hasher
|
||||
/// @param hasher the hasher to write to
|
||||
/// @param n the value to write
|
||||
void hasher_write_u32(t_hasher *hasher, t_u32 n);
|
||||
|
||||
/// @brief Write an u64 to the hasher
|
||||
/// @param hasher the hasher to write to
|
||||
/// @param n the value to write
|
||||
void hasher_write_u64(t_hasher *hasher, t_u64 n);
|
||||
|
||||
/// @brief Write an usize to the hasher
|
||||
/// @param hasher the hasher to write to
|
||||
/// @param n the value to write
|
||||
void hasher_write_usize(t_hasher *hasher, t_usize n);
|
||||
|
||||
|
||||
/// @brief Write an i8 to the hasher
|
||||
/// @param hasher the hasher to write to
|
||||
/// @param n the value to write
|
||||
void hasher_write_i8(t_hasher *hasher, t_i8 n);
|
||||
|
||||
/// @brief Write an i16 to the hasher
|
||||
/// @param hasher the hasher to write to
|
||||
/// @param n the value to write
|
||||
void hasher_write_i16(t_hasher *hasher, t_i16 n);
|
||||
|
||||
/// @brief Write an i32 to the hasher
|
||||
/// @param hasher the hasher to write to
|
||||
/// @param n the value to write
|
||||
void hasher_write_i32(t_hasher *hasher, t_i32 n);
|
||||
|
||||
/// @brief Write an i64 to the hasher
|
||||
/// @param hasher the hasher to write to
|
||||
/// @param n the value to write
|
||||
void hasher_write_i64(t_hasher *hasher, t_i64 n);
|
||||
|
||||
/// @brief Write an isize to the hasher
|
||||
/// @param hasher the hasher to write to
|
||||
/// @param n the value to write
|
||||
void hasher_write_isize(t_hasher *hasher, t_isize n);
|
||||
|
||||
|
||||
/// @brief Write an string to the hasher
|
||||
/// @param hasher the hasher to write to
|
||||
/// @param str the string to write
|
||||
void hasher_write_str(t_hasher *hasher, t_str str);
|
||||
|
||||
/// @brief Finish the hashing, free the underlying hasher and return the hash
|
||||
/// @param hasher the hasher to finish
|
||||
/// @return the hash
|
||||
t_u64 hasher_finish(t_hasher *hasher);
|
||||
|
||||
/// @brief Finish the hashing and return the hash BUT DOESN't FREE THE HASHER
|
||||
/// @param hasher the hasher to finish
|
||||
/// @return the hash
|
||||
t_u64 hasher_reset_and_finish(t_hasher *hasher);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -227,8 +227,8 @@ Header - Public functions */
|
|||
#ifndef QOI_H
|
||||
# define QOI_H
|
||||
|
||||
# include "me/mem/mem_alloc.h"
|
||||
# include "me/mem/mem_set_zero.h"
|
||||
# include "me/mem/mem.h"
|
||||
# include "me/mem/mem.h"
|
||||
# include "me/types.h"
|
||||
/* A pot_i32er to a t_qoi_desc struct has to be supplied to all of qoi's
|
||||
functions. It describes either the input format (for qoi_write and qoi_encode),
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/14 18:32:57 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/05/14 18:39:13 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/05/19 17:04:44 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -14,11 +14,87 @@
|
|||
#define MEM_H
|
||||
|
||||
#include "me/types.h"
|
||||
|
||||
/// @brief Allocate [size] bytes of memory
|
||||
/// @param size number of bytes to allocate
|
||||
/// @return a pointer of at least [size] bytes
|
||||
/// @remark will abort if unable to allocate
|
||||
void *mem_alloc(t_usize size);
|
||||
|
||||
/// @brief Allocate [size] * [count] bytes of memory
|
||||
/// @param size number of elements
|
||||
/// @param count number of bytes of each element
|
||||
/// @return a pointer of at least [size] * [count] bytes
|
||||
/// @remark will abort if unable to allocate, or if the multiplication overflows
|
||||
void *mem_alloc_array(t_usize size, t_usize count);
|
||||
|
||||
/// @brief Extend or Reallocate [size] bytes
|
||||
/// @param ptr pointer to the memory block
|
||||
/// @param size number of bytes required
|
||||
/// @return a pointer of at least [size] bytes, it may be the same pointer as [ptr] if it was able to be extended
|
||||
/// @remark will abort if unable to allocate
|
||||
/// @remark Will be equal to an `mem_alloc` if [ptr] == NULL
|
||||
void *mem_realloc(void *ptr, t_usize size);
|
||||
|
||||
/// @brief Extend or Reallocate [size] * [count] bytes
|
||||
/// @param ptr pointer to the memory block
|
||||
/// @param size size of each element in bytes
|
||||
/// @param count number of elements
|
||||
/// @return a pointer of at least [size] * [count] bytes, it may be the same pointer as [ptr] if it was able to be extended
|
||||
/// @remark will abort if unable to allocate
|
||||
/// @remark Will be equal to an `mem_alloc_array` if [ptr] == NULL
|
||||
void *mem_realloc_array(void *ptr, t_usize size, t_usize count);
|
||||
|
||||
/// @brief Set the memory block assigned at [ptr] as unsued
|
||||
/// @param ptr the memory block to free
|
||||
void mem_free(void *ptr);
|
||||
|
||||
|
||||
|
||||
/// @brief Set [count] bytes to zero at the pointer [buf]
|
||||
/// @param buf start of at least [count] bytes
|
||||
/// @param count number of bytes to set to zero
|
||||
void mem_set_zero(void *buf, t_usize count);
|
||||
|
||||
/// @brief Set [count] bytes to [byte] at the pointer [buf]
|
||||
/// @param buf start of at least [count] bytes
|
||||
/// @param byte byte to set
|
||||
/// @param count number of bytes to set to [byte]
|
||||
void mem_set(void *buf, t_u8 byte, t_usize count);
|
||||
|
||||
/// @brief Copy [count] bytes from [source] to [destination]
|
||||
/// @param destination pointer to at least [count] bytes
|
||||
/// @param source pointer to at least [count] bytes
|
||||
/// @param count number of bytes to copy
|
||||
/// @return [destination]
|
||||
void *mem_move(void *destination, const void *source, t_usize count);
|
||||
|
||||
/// @brief Copy [count] bytes from [source] to [destination]
|
||||
/// @param destination pointer to at least [count] bytes
|
||||
/// @param source pointer to at least [count] bytes
|
||||
/// @param count number of bytes to copy
|
||||
/// @return [destination]
|
||||
void *mem_copy(void *destination, const void *source, t_usize count);
|
||||
|
||||
/// @brief find a byte [find] in the buffer [buf] of size [count]
|
||||
/// @param buf the buffer to search in
|
||||
/// @param find the byte to find
|
||||
/// @param count the number of bytes to search
|
||||
/// @return the pointer to the first occurence of [find] or NULL if not found
|
||||
void *mem_find(void *buf, t_u8 find, t_usize count);
|
||||
|
||||
/// @brief find bytes [find][.find_count] in the buffer [buf] of size [count]
|
||||
/// @param buf the buffer to search in
|
||||
/// @param find pointer to the bytes to find
|
||||
/// @param find_count number of the bytes to find
|
||||
/// @param count the number of bytes to search
|
||||
/// @return the pointer to the first occurence of [find] or NULL if not found
|
||||
void *mem_find_bytes(void *buf, t_u8 *find, t_usize find_count, t_usize count);
|
||||
|
||||
/// @brief compare [count] bytes from [lhs] to [rhs]
|
||||
/// @param lhs bytes to compare
|
||||
/// @param rhs bytes to compare
|
||||
/// @param count number of bytes to compare
|
||||
/// @return true if the bytes are equal for [count] bytes, false otherwise
|
||||
bool mem_compare(const void *lhs, const void *rhs, t_usize count);
|
||||
|
||||
#endif /* MEM_H */
|
||||
|
|
|
|||
|
|
@ -1,20 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* mem_alloc.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/12/06 14:47:49 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:41:31 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef MEM_ALLOC_H
|
||||
# define MEM_ALLOC_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
void *mem_alloc(t_usize size);
|
||||
|
||||
#endif
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* mem_alloc_array.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/06 15:53:21 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:19:45 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef MEM_ALLOC_ARRAY_H
|
||||
# define MEM_ALLOC_ARRAY_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
void *mem_alloc_array(t_usize item_count, t_usize item_size);
|
||||
|
||||
#endif
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* mem_compare.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/06 11:16:02 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:21:14 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef MEM_COMPARE_H
|
||||
# define MEM_COMPARE_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
t_i32 mem_compare(const void *lhs, const void *rhs, t_usize count);
|
||||
|
||||
#endif
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* mem_copy.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/06 11:16:02 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:21:31 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef MEM_COPY_H
|
||||
# define MEM_COPY_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
void *mem_copy(void *destination, const void *source, t_usize count);
|
||||
|
||||
#endif
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* mem_find.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/06 11:16:02 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:24:03 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef MEM_FIND_H
|
||||
# define MEM_FIND_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
void *mem_find(void *buf, t_u8 find, t_usize count);
|
||||
|
||||
#endif
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* mem_find_bytes.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/06 11:16:02 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/01/06 18:24:04 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef MEM_FIND_BYTES_H
|
||||
# define MEM_FIND_BYTES_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
void *mem_find_bytes(void *buf, t_u8 *find, t_usize find_count,
|
||||
t_usize count);
|
||||
|
||||
#endif
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* mem_move.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/06 11:16:02 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:24:26 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef MEM_MOVE_H
|
||||
# define MEM_MOVE_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
void *mem_move(void *destination, const void *source, t_usize count);
|
||||
|
||||
#endif
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* mem_realloc.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/07 12:47:23 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/05/07 12:47:42 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef MEM_REALLOC_H
|
||||
#define MEM_REALLOC_H
|
||||
|
||||
#include "me/types.h"
|
||||
|
||||
void *mem_realloc(void *ptr, t_usize size);
|
||||
|
||||
#endif /* MEM_REALLOC_H */
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* mem_set.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/06 11:16:02 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:25:19 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef MEM_SET_H
|
||||
# define MEM_SET_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
void mem_set(void *buf, t_u8 byte, t_usize count);
|
||||
|
||||
#endif
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* mem_set_zero.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/06 11:58:11 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:24:51 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef MEM_SET_ZERO_H
|
||||
# define MEM_SET_ZERO_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
void mem_set_zero(void *buf, t_usize count);
|
||||
|
||||
#endif
|
||||
|
|
@ -15,12 +15,16 @@
|
|||
|
||||
# include "me/types.h"
|
||||
|
||||
/// @brief Pipe structure
|
||||
typedef struct s_pipe
|
||||
{
|
||||
t_file read;
|
||||
t_file write;
|
||||
} t_pipe;
|
||||
|
||||
/// @brief Create a pipe
|
||||
/// @param[out] out the created pipe
|
||||
/// @return the error
|
||||
t_error create_pipe(t_pipe *out);
|
||||
|
||||
#endif /* PIPE_H */
|
||||
|
|
|
|||
|
|
@ -41,12 +41,16 @@ union u_redirection
|
|||
} inherited;
|
||||
};
|
||||
|
||||
/// @brief Redirection for spawning a process
|
||||
typedef struct s_redirection
|
||||
{
|
||||
enum e_redirection tag;
|
||||
union u_redirection vals;
|
||||
} t_redirection;
|
||||
|
||||
/// @brief Create a piped redirection
|
||||
/// @param void
|
||||
/// @return the redirection
|
||||
static inline t_redirection piped(void)
|
||||
{
|
||||
return ((t_redirection){
|
||||
|
|
@ -54,6 +58,9 @@ static inline t_redirection piped(void)
|
|||
});
|
||||
}
|
||||
|
||||
/// @brief Create an inherited redirection (inherit from the parent process)
|
||||
/// @param void
|
||||
/// @return the redirection
|
||||
static inline t_redirection inherited(void)
|
||||
{
|
||||
return ((t_redirection){
|
||||
|
|
@ -61,12 +68,16 @@ static inline t_redirection inherited(void)
|
|||
});
|
||||
}
|
||||
|
||||
/// @brief Create a file descriptor redirection
|
||||
/// @param fd file descriptor to redirect
|
||||
/// @return the redirection
|
||||
static inline t_redirection fd(t_file fd)
|
||||
{
|
||||
return ((t_redirection){.tag = R_FD, \
|
||||
.vals = (union u_redirection){.fd = {.value = fd},}});
|
||||
}
|
||||
|
||||
/// @brief Wrapped file descriptor tag
|
||||
enum e_wrapped_fd_tag
|
||||
{
|
||||
READ_ONLY,
|
||||
|
|
@ -75,6 +86,7 @@ enum e_wrapped_fd_tag
|
|||
INVALID,
|
||||
};
|
||||
|
||||
/// @brief Wrapped file descriptor
|
||||
union u_wrapped_fd
|
||||
{
|
||||
struct s_read_only
|
||||
|
|
@ -91,12 +103,16 @@ union u_wrapped_fd
|
|||
} rw;
|
||||
};
|
||||
|
||||
/// @brief Wrapped file descriptor
|
||||
typedef struct s_wrapped_fd
|
||||
{
|
||||
enum e_wrapped_fd_tag tag;
|
||||
union u_wrapped_fd vals;
|
||||
} t_wrapped_fd;
|
||||
|
||||
/// @brief Create a Read only wrapped file descriptor
|
||||
/// @param fd file descriptor to wrap
|
||||
/// @return the wrapped file descriptor
|
||||
static inline t_wrapped_fd ro(t_file fd)
|
||||
{
|
||||
return ((t_wrapped_fd){.tag = READ_ONLY,
|
||||
|
|
@ -105,12 +121,16 @@ static inline t_wrapped_fd ro(t_file fd)
|
|||
}});
|
||||
}
|
||||
|
||||
/// @brief Create a Write only wrapped file descriptor
|
||||
/// @param fd file descriptor to wrap
|
||||
/// @return the wrapped file descriptor
|
||||
static inline t_wrapped_fd wo(t_file fd)
|
||||
{
|
||||
return ((t_wrapped_fd){.tag = WRITE_ONLY,
|
||||
.vals = (union u_wrapped_fd){.wo = {.fd = fd}}});
|
||||
}
|
||||
|
||||
/// @brief Spawn information
|
||||
typedef struct s_spawn_info
|
||||
{
|
||||
t_redirection stdin;
|
||||
|
|
@ -123,6 +143,7 @@ typedef struct s_spawn_info
|
|||
void *forked_free_args;
|
||||
} t_spawn_info;
|
||||
|
||||
/// @brief Process information
|
||||
typedef struct s_process
|
||||
{
|
||||
t_wrapped_fd stdin;
|
||||
|
|
@ -130,7 +151,8 @@ typedef struct s_process
|
|||
t_wrapped_fd stderr;
|
||||
t_pid pid;
|
||||
} t_process;
|
||||
|
||||
/// @struct Process output
|
||||
/// @brief Process output information
|
||||
typedef struct s_process_output
|
||||
{
|
||||
t_pid pid;
|
||||
|
|
@ -139,6 +161,11 @@ typedef struct s_process_output
|
|||
t_exit_code exit_code;
|
||||
} t_process_output;
|
||||
|
||||
|
||||
/// @brief Spawn a new process with the given information
|
||||
/// @param info the information to spawn the process
|
||||
/// @param process data returned by the function
|
||||
/// @return true if an error occured, false otherwise
|
||||
t_error spawn_process(t_spawn_info info,
|
||||
t_process *process);
|
||||
|
||||
|
|
|
|||
|
|
@ -61,9 +61,28 @@ typedef struct s_printf_args
|
|||
typedef void (*t_printf_func)(t_const_str to_write,
|
||||
t_usize to_write_len, void *p_args);
|
||||
|
||||
/// @brief Print a formatted string to stdout
|
||||
/// @param fmt the format string
|
||||
/// @param ... the arguments to format
|
||||
/// @return the number of characters printed
|
||||
t_usize me_printf(t_const_str fmt, ...);
|
||||
|
||||
/// @brief Print a formatted string to a stderr
|
||||
/// @param fmt the format string
|
||||
/// @param ... the arguments to format
|
||||
/// @return the number of characters printed
|
||||
t_usize me_eprintf(t_const_str fmt, ...);
|
||||
|
||||
/// @brief Print a formatted string to a stdout
|
||||
/// @param fmt the format string
|
||||
/// @param args the arguments to format as a va_list
|
||||
/// @return the number of characters printed
|
||||
t_usize me_vprintf(t_const_str fmt, va_list *args);
|
||||
|
||||
/// @brief Print a formatted string to a stderr
|
||||
/// @param fmt the format string
|
||||
/// @param args the arguments to format as a va_list
|
||||
/// @return the number of characters printed
|
||||
t_usize me_veprintf(t_const_str fmt, va_list *args);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,20 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* quit.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/07 12:54:50 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/05/07 12:55:08 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef QUIT_H
|
||||
#define QUIT_H
|
||||
|
||||
#include "me/types.h"
|
||||
|
||||
void quit(t_i32 exit_code);
|
||||
|
||||
#endif /* QUIT_H */
|
||||
113
stdme/include/me/str/str.h
Normal file
113
stdme/include/me/str/str.h
Normal file
|
|
@ -0,0 +1,113 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* str.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/19 23:30:46 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/05/19 23:30:46 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef STR_H
|
||||
#define STR_H
|
||||
|
||||
#include "me/types.h"
|
||||
/// @brief Get the length of a string
|
||||
/// @param str the string
|
||||
/// @return the length of the string
|
||||
t_usize str_len(t_const_str str);
|
||||
|
||||
/// @brief Clone a string
|
||||
/// @param source the string to clone
|
||||
/// @return the cloned string
|
||||
t_str str_clone(t_const_str source);
|
||||
|
||||
/// @brief Get a substring of a string
|
||||
/// @param str the string to operate on
|
||||
/// @param start the start index of the substring
|
||||
/// @param len the length of the substring
|
||||
/// @return the substring
|
||||
t_str str_substring(t_const_str str, t_usize start, t_usize len);
|
||||
|
||||
/// @brief Compare two strings
|
||||
/// @param lhs left hand side string
|
||||
/// @param rhs right hand side string
|
||||
/// @return true if the strings are equal, false otherwise
|
||||
bool str_compare(t_const_str lhs, t_const_str rhs);
|
||||
|
||||
/// @brief Compare two strings up to n characters
|
||||
/// @param lhs left hand side string
|
||||
/// @param rhs right hand side string
|
||||
/// @param n the maximum number of characters to compare
|
||||
/// @return true if the strings are equal, false otherwise
|
||||
bool str_n_compare(t_const_str lhs, t_const_str rhs, t_usize n);
|
||||
|
||||
/// @brief Find a character in a string
|
||||
/// @param str the string to search in
|
||||
/// @param chr the character to find
|
||||
/// @return a pointer to the first occurence of the character, or NULL if not found
|
||||
char *str_find_chr(t_const_str str, char chr);
|
||||
|
||||
/// @brief Find a character in a string, starting from the end
|
||||
/// @param str the string to search in
|
||||
/// @param chr the character to find
|
||||
/// @return a pointer to the last occurence of the character, or NULL if not found
|
||||
char *str_find_rev_chr(t_const_str str, char chr);
|
||||
/// @brief Find a string in a string
|
||||
/// @param str the string to be searched
|
||||
/// @param to_find the string to find
|
||||
/// @return a pointer to the first occurence of the string, or NULL if not found
|
||||
const char *str_find_str(t_const_str str, t_const_str to_find);
|
||||
/// @brief Find a string in a string, up to n characters
|
||||
/// @param str the string to be searched
|
||||
/// @param to_find the string to find
|
||||
/// @param len the maximum number of characters to search
|
||||
/// @return a pointer to the first occurence of the string, or NULL if not found
|
||||
const char *str_n_find_str(t_const_str str, t_const_str to_find, t_usize len);
|
||||
|
||||
/// @brief Join two string together
|
||||
/// @param s1 First string
|
||||
/// @param s2 Second string
|
||||
/// @return the joined string
|
||||
t_str str_join(t_const_str s1, t_const_str s2);
|
||||
|
||||
/// @brief Concatenate two strings
|
||||
/// @param dest the destination string
|
||||
/// @param src the source string
|
||||
/// @param buffer_size the size of the destination buffer
|
||||
/// @return the length of the concatenated string
|
||||
t_usize str_l_cat(t_str dest, t_const_str src, t_usize buffer_size);
|
||||
|
||||
/// @brief Copy a string
|
||||
/// @param dest the destination string
|
||||
/// @param src the source string
|
||||
/// @param buffer_size the size of the destination buffer
|
||||
/// @return the length of the copied string
|
||||
t_usize str_l_copy(t_str dest, t_const_str src, t_usize buffer_size);
|
||||
|
||||
/// @brief run a function over each character of a string
|
||||
/// @param s the string to iterate over
|
||||
/// @param f the function to run over each character
|
||||
void str_iter(t_str s, void (*f)(t_usize, char *));
|
||||
|
||||
/// @brief run a function over each character of a string
|
||||
/// @param s the string to iterate over
|
||||
/// @param f the function to run over each character
|
||||
/// @return the mapped string
|
||||
t_str str_map(t_const_str s, char (*f)(t_usize, char));
|
||||
|
||||
/// @brief Split a string into a vector of strings
|
||||
/// @param str the string to be split
|
||||
/// @param chr the character to split the string on
|
||||
/// @return the vector of strings
|
||||
t_str *str_split(t_const_str str, char chr);
|
||||
|
||||
/// @brief Remove consecutive leading and trailing characters from a string
|
||||
/// @param str the string to trim
|
||||
/// @param charset the characters to remove
|
||||
/// @return the trimmed string
|
||||
t_str str_trim(t_const_str str, t_const_str charset);
|
||||
|
||||
#endif /* STR_H */
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* str_clone.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/06 16:05:48 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/11 17:30:19 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef STR_CLONE_H
|
||||
# define STR_CLONE_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
t_str str_clone(t_const_str source);
|
||||
|
||||
#endif
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* str_compare.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/04 18:53:47 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/05/04 18:37:55 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef STR_COMPARE_H
|
||||
# define STR_COMPARE_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
bool str_compare(t_const_str lhs, t_const_str rhs);
|
||||
|
||||
#endif
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* str_find_chr.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/04 17:29:13 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:07:01 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef STR_FIND_CHR_H
|
||||
# define STR_FIND_CHR_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
char *str_find_chr(t_const_str str, char chr);
|
||||
|
||||
#endif
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* str_find_rev_chr.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/04 17:29:13 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:07:15 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef STR_FIND_REV_CHR_H
|
||||
# define STR_FIND_REV_CHR_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
char *str_find_rev_chr(t_const_str str, char chr);
|
||||
|
||||
#endif
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* str_find_str.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/08/10 11:11:01 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:53:44 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef STR_FIND_STR_H
|
||||
# define STR_FIND_STR_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
const char *str_find_str(t_const_str str, t_const_str to_find);
|
||||
|
||||
#endif
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* str_iter.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/09 18:26:00 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:08:09 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef STR_ITER_H
|
||||
# define STR_ITER_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
void str_iter(t_str s, void (*f)(t_usize, char *));
|
||||
|
||||
#endif
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* str_join.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/07 23:02:58 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:08:32 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef STR_JOIN_H
|
||||
# define STR_JOIN_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
t_str str_join(t_const_str s1, t_const_str s2);
|
||||
|
||||
#endif
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* str_l_cat.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/08/09 18:01:09 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:09:07 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef STR_L_CAT_H
|
||||
# define STR_L_CAT_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
t_usize str_l_cat(t_str dest, t_const_str src, t_usize buffer_size);
|
||||
|
||||
#endif
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* str_l_copy.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/08/09 18:01:09 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:09:38 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef STR_L_COPY_H
|
||||
# define STR_L_COPY_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
t_usize str_l_copy(t_str dest, t_const_str src, t_usize buffer_size);
|
||||
|
||||
#endif
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* str_len.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/04 17:07:41 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/11 16:08:07 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef STR_LEN_H
|
||||
# define STR_LEN_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
t_usize str_len(t_const_str str);
|
||||
|
||||
#endif
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* str_map.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/09 18:26:00 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:11:40 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef STR_MAP_H
|
||||
# define STR_MAP_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
t_str str_map(t_const_str s, char (*f)(t_usize, char));
|
||||
|
||||
#endif
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* str_n_compare.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/04 18:53:47 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:17:14 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef STR_N_COMPARE_H
|
||||
# define STR_N_COMPARE_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
t_i32 str_n_compare(t_const_str lhs, t_const_str rhs, t_usize n);
|
||||
|
||||
#endif
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* str_n_find_str.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/08/10 11:11:01 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:53:35 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef STR_N_FIND_STR_H
|
||||
# define STR_N_FIND_STR_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
const char *str_n_find_str(t_const_str str, t_const_str to_find, t_usize len);
|
||||
|
||||
#endif
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* str_split.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/08/17 15:56:59 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:18:07 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef STR_SPLIT_H
|
||||
# define STR_SPLIT_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
t_str *str_split(t_const_str str, char chr);
|
||||
|
||||
#endif
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* str_substring.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/07 22:42:55 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:18:41 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef STR_SUBSTRING_H
|
||||
# define STR_SUBSTRING_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
t_str str_substring(t_const_str str, t_usize start, t_usize len);
|
||||
|
||||
#endif
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* str_trim.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/07 23:43:42 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:19:11 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef STR_TRIM_H
|
||||
# define STR_TRIM_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
t_str str_trim(t_const_str str, t_const_str charset);
|
||||
|
||||
#endif
|
||||
77
stdme/include/me/string/string.h
Normal file
77
stdme/include/me/string/string.h
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* string.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/16 17:54:28 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/04/30 14:14:42 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef STRING_H
|
||||
# define STRING_H
|
||||
# include "me/types.h"
|
||||
|
||||
typedef struct s_string
|
||||
{
|
||||
t_str buf;
|
||||
t_usize capacity;
|
||||
t_usize len;
|
||||
} t_string;
|
||||
|
||||
/// @brief Push a string to a buffer
|
||||
/// @param buf the string to be pushed to
|
||||
/// @param to_push the string to push
|
||||
/// @return true if it failed, false otherwise
|
||||
t_error string_push(t_string *buf, t_const_str to_push);
|
||||
|
||||
|
||||
/// @brief Push a character to a buffer
|
||||
/// @param buf the string to be pushed to
|
||||
/// @param to_push the character to push
|
||||
/// @return true if it failed, false otherwise
|
||||
t_error string_push_char(t_string *buf, char to_push);
|
||||
|
||||
/// @brief Clear a string
|
||||
/// @param buf the string to clear
|
||||
void string_clear(t_string *buf);
|
||||
|
||||
/// @brief Create a new string
|
||||
/// @param capacity the initial capacity of the string
|
||||
/// @return the created string
|
||||
t_string string_new(t_usize capacity);
|
||||
|
||||
/// @brief Make the string able to hold at least size characters if not already
|
||||
/// @param buf the string to operate on
|
||||
/// @param size the minimum size of the string wanted
|
||||
/// @return true if it failed, false otherwise
|
||||
t_error string_reserve(t_string *buf, t_usize size);
|
||||
|
||||
/// @brief free a string
|
||||
/// @param buf the string to free
|
||||
static inline void string_free(t_string buf)
|
||||
{
|
||||
void mem_free(void *);
|
||||
|
||||
mem_free(buf.buf);
|
||||
}
|
||||
|
||||
/// @brief Pop a character from a string
|
||||
/// @param buf the string to pop from
|
||||
/// @return the popped character, or '\0' if the string is empty
|
||||
static inline char string_pop(t_string *buf)
|
||||
{
|
||||
char c;
|
||||
|
||||
c = '\0';
|
||||
if (buf->buf && buf->len)
|
||||
{
|
||||
c = buf->buf[buf->len - 1];
|
||||
buf->buf[buf->len - 1] = '\0';
|
||||
}
|
||||
return (c);
|
||||
}
|
||||
|
||||
#endif
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue