normed the stdme headers

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

View file

@ -4,15 +4,6 @@ src/hashmap/env/env_utils.c
src/vec/ast/ast.c src/vec/ast/ast.c
src/vec/ast/ast_functions2.c src/vec/ast/ast_functions2.c
src/vec/ast/ast_functions3.c src/vec/ast/ast_functions3.c
src/vec/parser_heredoc/parser_heredoc.c
src/vec/parser_heredoc/parser_heredoc_functions2.c
src/vec/parser_heredoc/parser_heredoc_functions3.c
src/vec/parser_range/parser_range.c
src/vec/parser_range/parser_range_functions2.c
src/vec/parser_range/parser_range_functions3.c
src/vec/reduce_action/reduce_action.c
src/vec/reduce_action/reduce_action_functions2.c
src/vec/reduce_action/reduce_action_functions3.c
src/vec/str/str.c src/vec/str/str.c
src/vec/str/str_functions2.c src/vec/str/str_functions2.c
src/vec/str/str_functions3.c src/vec/str/str_functions3.c

View file

@ -11,21 +11,21 @@
/* ************************************************************************** */ /* ************************************************************************** */
#ifndef ENV_H #ifndef ENV_H
#define ENV_H # define ENV_H
#include "me/string/string.h" # include "me/hashmap/hashmap_env.h"
#include "me/hashmap/hashmap_env.h" # include "me/string/string.h"
#include "me/types.h" # include "me/types.h"
#include "me/vec/vec_str.h" # include "me/vec/vec_str.h"
t_hashmap_env *create_env_map(void); t_hashmap_env *create_env_map(void);
t_error build_envp(t_hashmap_env *envs, t_vec_str *out); t_error build_envp(t_hashmap_env *envs, t_vec_str *out);
struct s_build_envp_state struct s_build_envp_state
{ {
t_vec_str out; t_vec_str out;
t_string buf; t_string buf;
}; };
#endif /* ENV_H */ #endif /* ENV_H */

View file

@ -11,27 +11,27 @@
/* ************************************************************************** */ /* ************************************************************************** */
#ifndef NODE_H #ifndef NODE_H
#define NODE_H # define NODE_H
#include "me/types.h" # include "me/types.h"
#include "parser/api.h" # include "parser/api.h"
typedef struct s_node typedef struct s_node
{ {
t_u64 kind; t_u64 kind;
t_const_str kind_str; t_const_str kind_str;
t_const_str field_str; t_const_str field_str;
t_u64 field; t_u64 field;
t_const_str input; t_const_str input;
t_str single_str; t_str single_str;
t_usize start; t_usize start;
t_usize end; t_usize end;
t_usize childs_count; t_usize childs_count;
struct s_node *childs; struct s_node *childs;
} t_node; } t_node;
t_node build_node(t_parse_node curr, t_const_str input); t_node build_node(t_parse_node curr, t_const_str input);
t_str node_getstr(t_node *node); t_str node_getstr(t_node *node);
void free_node(t_node self); void free_node(t_node self);
#endif /* NODE_H */ #endif /* NODE_H */

View file

@ -1,22 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* handle_command.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/09 14:42:43 by rparodi #+# #+# */
/* Updated: 2024/05/09 14:59:28 by rparodi ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef HANDLE_COMMAND_H
# define HANDLE_COMMAND_H
# include "me/types.h"
# include "app/state.h"
# include "app/node.h"
t_error handle_command(t_node *self, t_utils *shcat, t_i32 *out_exit_code);
#endif

View file

@ -1,22 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* handle_concat.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/02 15:49:12 by maiboyer #+# #+# */
/* Updated: 2024/05/02 15:52:16 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef HANDLE_CONCAT_H
#define HANDLE_CONCAT_H
#include "app/state.h"
#include "app/node.h"
#include "me/types.h"
t_error handle_concat(t_node *self, t_utils *shcat, t_str *ret);
#endif /* HANDLE_CONCAT_H */

View file

@ -1,22 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* handle_expension.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/03 15:24:56 by maiboyer #+# #+# */
/* Updated: 2024/05/03 15:25:18 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef HANDLE_EXPENSION_H
#define HANDLE_EXPENSION_H
#include "app/node.h"
#include "app/state.h"
#include "me/types.h"
t_error handle_expension(t_node *self, t_utils *shcat, t_str *ret);
#endif /* HANDLE_EXPENSION_H */

View file

@ -1,22 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* handle_program.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/09 14:42:43 by rparodi #+# #+# */
/* Updated: 2024/05/09 15:51:11 by rparodi ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef HANDLE_PROGRAM_H
# define HANDLE_PROGRAM_H
# include "me/types.h"
# include "app/state.h"
# include "app/node.h"
t_error handle_program(t_node *self, t_utils *shcat, t_i32 *out_exit_code);
#endif

View file

@ -1,21 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* handle_raw_word.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/02 15:58:01 by maiboyer #+# #+# */
/* Updated: 2024/05/02 15:58:48 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef HANDLE_RAW_WORD_H
#define HANDLE_RAW_WORD_H
#include "app/node.h"
#include "app/state.h"
t_error handle_raw_string(t_node *self, t_utils *shcat, t_str *ret);
#endif /* HANDLE_RAW_WORD_H */

View file

@ -1,22 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* handle_word.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/02 16:00:11 by maiboyer #+# #+# */
/* Updated: 2024/05/02 16:00:40 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef HANDLE_WORD_H
#define HANDLE_WORD_H
#include "app/state.h"
#include "app/node.h"
#include "me/types.h"
t_error handle_word(t_node *self, t_utils *shcat, t_str *ret);
#endif /* HANDLE_WORD_H */

View file

@ -11,14 +11,14 @@
/* ************************************************************************** */ /* ************************************************************************** */
#ifndef SIGNAL_HANDLER_H #ifndef SIGNAL_HANDLER_H
#define SIGNAL_HANDLER_H # define SIGNAL_HANDLER_H
#include "me/types.h" # include "me/types.h"
#include <signal.h> # include <signal.h>
#include <stdio.h> # include <stdio.h>
typedef t_i32 t_signal; typedef t_i32 t_signal;
t_error install_signal(void); t_error install_signal(void);
#endif /* SIGNAL_HANDLER_H */ #endif /* SIGNAL_HANDLER_H */

View file

@ -11,17 +11,17 @@
/* ************************************************************************** */ /* ************************************************************************** */
#ifndef STATE_H #ifndef STATE_H
#define STATE_H # define STATE_H
#include "app/node.h" # include "app/node.h"
#include "me/hashmap/hashmap_env.h" # include "me/hashmap/hashmap_env.h"
#include "me/types.h" # include "me/os/process.h"
#include "me/os/process.h" # include "me/types.h"
typedef struct s_parser typedef struct s_parser
{ {
t_first_parser *parser; t_first_parser *parser;
} t_parser; } t_parser;
typedef struct s_utils typedef struct s_utils
{ {
@ -33,6 +33,6 @@ typedef struct s_utils
t_hashmap_env *env; t_hashmap_env *env;
t_node current_node; t_node current_node;
t_process ret; t_process ret;
} t_utils; } t_utils;
#endif /* STATE_H */ #endif /* STATE_H */

View file

@ -1,44 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* type_rust.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/28 14:44:20 by rparodi #+# #+# */
/* Updated: 2024/03/31 20:53:56 by rparodi ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef TYPE_RUST_H
#define TYPE_RUST_H
# include <stdbool.h>
# include <stddef.h>
# include <unistd.h>
typedef char *t_str;
typedef const char *t_const_str;
typedef unsigned char t_u8;
typedef char t_i8;
typedef unsigned short t_u16;
typedef short t_i16;
typedef int t_i32;
typedef unsigned int t_u32;
typedef unsigned long long t_u64;
typedef long long t_i64;
typedef ssize_t t_isize;
typedef size_t t_usize;
typedef float t_f32;
typedef double t_f64;
typedef int int;
typedef bool t_error;
# define ERROR 1
# define NO_ERROR 0
#endif

View file

@ -38,30 +38,6 @@ replace.C__MIN__ = "value"
replace.C__ZERO__ = "value" replace.C__ZERO__ = "value"
replace.C__SIGNED_TYPE__ = "bool" replace.C__SIGNED_TYPE__ = "bool"
[[create.vec]]
sources_output = "src/vec/C__PREFIX__/"
headers_output = "include/me/vec/"
replace.C__TYPENAME__ = "t_parser_range"
replace.C__TYPEHEADER__ = '#include "parser/types/types_parser_range.h"'
replace.C__PREFIX__ = "parser_range"
replace.C__PREFIXUP__ = "PARSER_RANGE"
[[create.vec]]
sources_output = "src/vec/C__PREFIX__/"
headers_output = "include/me/vec/"
replace.C__TYPENAME__ = "t_heredoc"
replace.C__TYPEHEADER__ = '#include "parser/types/types_heredoc.h"'
replace.C__PREFIX__ = "parser_heredoc"
replace.C__PREFIXUP__ = "PARSER_HEREDOC"
[[create.vec]]
sources_output = "src/vec/C__PREFIX__/"
headers_output = "include/me/vec/"
replace.C__TYPENAME__ = "t_reduce_action"
replace.C__TYPEHEADER__ = '#include "parser/types/types_reduce_action.h"'
replace.C__PREFIX__ = "reduce_action"
replace.C__PREFIXUP__ = "REDUCE_ACTION"
[[create.vec]] [[create.vec]]
sources_output = "src/vec/C__PREFIX__/" sources_output = "src/vec/C__PREFIX__/"
headers_output = "include/me/vec/" headers_output = "include/me/vec/"

View file

@ -1,123 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* vec_parser_heredoc.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/04 18:46:53 by maiboyer #+# #+# */
/* Updated: 2023/12/09 17:53:00 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef VEC_PARSER_HEREDOC_H
#define VEC_PARSER_HEREDOC_H
#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;
t_usize len;
t_usize capacity;
t_heredoc *buffer;
} t_vec_parser_heredoc;
/// @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);
/// @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);
/// @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);
/// @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

View file

@ -1,123 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* vec_parser_range.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/04 18:46:53 by maiboyer #+# #+# */
/* Updated: 2023/12/09 17:53:00 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef VEC_PARSER_RANGE_H
#define VEC_PARSER_RANGE_H
#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;
t_usize len;
t_usize capacity;
t_parser_range *buffer;
} t_vec_parser_range;
/// @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);
/// @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);
/// @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);
/// @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

View file

@ -1,123 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* vec_reduce_action.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/04 18:46:53 by maiboyer #+# #+# */
/* Updated: 2023/12/09 17:53:00 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef VEC_REDUCE_ACTION_H
#define VEC_REDUCE_ACTION_H
#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;
t_usize len;
t_usize capacity;
t_reduce_action *buffer;
} t_vec_reduce_action;
/// @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);
/// @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);
/// @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);
/// @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

View file

@ -1,95 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* vec_parser_heredoc.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/05 18:46:28 by maiboyer #+# #+# */
/* Updated: 2023/12/09 17:54:11 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "me/mem/mem.h"
#include "me/types.h"
#include "me/vec/vec_parser_heredoc.h"
#include <stdlib.h>
t_vec_parser_heredoc vec_parser_heredoc_new(t_usize capacity,
t_free_parser_heredoc_item free_function)
{
t_vec_parser_heredoc out;
out = (t_vec_parser_heredoc){0};
out.free_func = free_function;
out.buffer = mem_alloc_array(capacity, sizeof(t_heredoc));
if (out.buffer)
out.capacity = capacity;
return (out);
}
/// Return true in case of an error
t_error vec_parser_heredoc_push(t_vec_parser_heredoc *vec, t_heredoc element)
{
if (vec == NULL)
return (ERROR);
vec_parser_heredoc_reserve(vec, vec->len + 1);
vec->buffer[vec->len] = element;
vec->len += 1;
return (NO_ERROR);
}
/// Return true in case of an error
t_error vec_parser_heredoc_reserve(t_vec_parser_heredoc *vec, t_usize wanted_capacity)
{
size_t new_capacity;
if (vec == NULL)
return (ERROR);
if (wanted_capacity > vec->capacity)
{
new_capacity = (vec->capacity * 3) / 2 + 1;
while (wanted_capacity > new_capacity)
new_capacity = (new_capacity * 3) / 2 + 1;
vec->buffer =
mem_realloc_array(vec->buffer, new_capacity, sizeof(t_heredoc));
vec->capacity = new_capacity;
}
return (NO_ERROR);
}
/// Return true if the vector is empty
/// This function is safe to call with value being NULL
t_error vec_parser_heredoc_pop(t_vec_parser_heredoc *vec, t_heredoc *value)
{
t_heredoc temp_value;
t_heredoc *ptr;
if (vec == NULL)
return (ERROR);
ptr = value;
if (vec->len == 0)
return (ERROR);
if (value == NULL)
ptr = &temp_value;
vec->len--;
*ptr = vec->buffer[vec->len];
mem_set_zero(&vec->buffer[vec->len], sizeof(t_heredoc));
return (NO_ERROR);
}
/// This function is safe to call with `free_elem` being NULL
void vec_parser_heredoc_free(t_vec_parser_heredoc vec)
{
if (vec.buffer == NULL)
return;
if (vec.free_func)
{
while (vec.len)
{
vec.free_func(vec.buffer[vec.len - 1]);
vec.len--;
}
}
mem_free(vec.buffer);
}

View file

@ -1,112 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* vec_parser_heredoc.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/30 17:59:28 by maiboyer #+# #+# */
/* Updated: 2023/12/30 17:59:28 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#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>
t_error vec_parser_heredoc_find(t_vec_parser_heredoc *vec,
bool (*fn)(const t_heredoc *), t_usize *index)
{
t_usize idx;
if (vec == NULL || fn == NULL || index == NULL)
return (ERROR);
idx = 0;
while (idx < vec->len)
{
if (fn((const t_heredoc *)&vec->buffer[idx]))
{
*index = idx;
return (NO_ERROR);
}
idx++;
}
return (ERROR);
}
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_usize idx;
if (vec == NULL || fn == NULL || index == NULL)
return (ERROR);
idx = starting_index;
while (idx < vec->len)
{
if (fn((const t_heredoc *)&vec->buffer[idx]))
{
*index = idx;
return (NO_ERROR);
}
idx++;
}
return (ERROR);
}
t_error vec_parser_heredoc_all(t_vec_parser_heredoc *vec,
bool (*fn)(const t_heredoc *), bool *result)
{
t_usize idx;
if (vec == NULL || fn == NULL || result == NULL)
return (ERROR);
idx = 0;
*result = true;
while (*result && idx < vec->len)
{
if (!fn((const t_heredoc *)&vec->buffer[idx]))
*result = false;
idx++;
}
return (ERROR);
}
t_error vec_parser_heredoc_any(t_vec_parser_heredoc *vec,
bool (*fn)(const t_heredoc *), bool *result)
{
t_usize idx;
if (vec == NULL || fn == NULL || result == NULL)
return (ERROR);
idx = 0;
*result = false;
while (*result && idx < vec->len)
{
if (fn((const t_heredoc *)&vec->buffer[idx]))
*result = true;
idx++;
}
return (ERROR);
}
void vec_parser_heredoc_iter(t_vec_parser_heredoc *vec,
void (*fn)(t_usize index, t_heredoc *value,
void *state),
void *state)
{
t_usize idx;
if (vec == NULL || fn == NULL)
return;
idx = 0;
while (idx < vec->len)
{
fn(idx, &vec->buffer[idx], state);
idx++;
}
}

View file

@ -1,84 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* vec_parser_heredoc.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/30 17:59:28 by maiboyer #+# #+# */
/* Updated: 2023/12/30 17:59:28 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#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>
t_error vec_parser_heredoc_push_front(t_vec_parser_heredoc *vec,
t_heredoc element)
{
t_usize i;
if (vec->len == 0)
return (vec_parser_heredoc_push(vec, element));
i = vec->len - 1;
if (vec->capacity < vec->len + 1 &&
vec_parser_heredoc_reserve(vec, 3 * vec->len / 2 + 1))
return (ERROR);
while (i > 0)
{
vec->buffer[i + 1] = vec->buffer[i];
i--;
}
vec->buffer[1] = vec->buffer[0];
vec->buffer[0] = element;
vec->len++;
return (NO_ERROR);
}
t_error vec_parser_heredoc_pop_front(t_vec_parser_heredoc *vec, t_heredoc *value)
{
t_usize i;
if (vec->len <= 1)
return (vec_parser_heredoc_pop(vec, value));
i = 0;
*value = vec->buffer[0];
vec->len--;
while (i < vec->len)
{
vec->buffer[i] = vec->buffer[i + 1];
i++;
}
mem_set_zero(&vec->buffer[i], sizeof(*vec->buffer));
return (NO_ERROR);
}
void vec_parser_heredoc_reverse(t_vec_parser_heredoc *vec)
{
t_heredoc temporary;
t_usize i;
i = 0;
while (i < vec->len / 2)
{
temporary = vec->buffer[vec->len - 1 - i];
vec->buffer[vec->len - 1 - i] = vec->buffer[i];
vec->buffer[i] = temporary;
i++;
}
}
t_error vec_parser_heredoc_back(t_vec_parser_heredoc *vec, t_heredoc **out)
{
t_heredoc *temporary;
if (out == NULL)
out = &temporary;
if (vec->len != 0)
return (*out = &vec->buffer[vec->len - 1], true);
return (false);
}

View file

@ -1,95 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* vec_parser_range.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/05 18:46:28 by maiboyer #+# #+# */
/* Updated: 2023/12/09 17:54:11 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "me/mem/mem.h"
#include "me/types.h"
#include "me/vec/vec_parser_range.h"
#include <stdlib.h>
t_vec_parser_range vec_parser_range_new(t_usize capacity,
t_free_parser_range_item free_function)
{
t_vec_parser_range out;
out = (t_vec_parser_range){0};
out.free_func = free_function;
out.buffer = mem_alloc_array(capacity, sizeof(t_parser_range));
if (out.buffer)
out.capacity = capacity;
return (out);
}
/// Return true in case of an error
t_error vec_parser_range_push(t_vec_parser_range *vec, t_parser_range element)
{
if (vec == NULL)
return (ERROR);
vec_parser_range_reserve(vec, vec->len + 1);
vec->buffer[vec->len] = element;
vec->len += 1;
return (NO_ERROR);
}
/// Return true in case of an error
t_error vec_parser_range_reserve(t_vec_parser_range *vec, t_usize wanted_capacity)
{
size_t new_capacity;
if (vec == NULL)
return (ERROR);
if (wanted_capacity > vec->capacity)
{
new_capacity = (vec->capacity * 3) / 2 + 1;
while (wanted_capacity > new_capacity)
new_capacity = (new_capacity * 3) / 2 + 1;
vec->buffer =
mem_realloc_array(vec->buffer, new_capacity, sizeof(t_parser_range));
vec->capacity = new_capacity;
}
return (NO_ERROR);
}
/// Return true if the vector is empty
/// This function is safe to call with value being NULL
t_error vec_parser_range_pop(t_vec_parser_range *vec, t_parser_range *value)
{
t_parser_range temp_value;
t_parser_range *ptr;
if (vec == NULL)
return (ERROR);
ptr = value;
if (vec->len == 0)
return (ERROR);
if (value == NULL)
ptr = &temp_value;
vec->len--;
*ptr = vec->buffer[vec->len];
mem_set_zero(&vec->buffer[vec->len], sizeof(t_parser_range));
return (NO_ERROR);
}
/// This function is safe to call with `free_elem` being NULL
void vec_parser_range_free(t_vec_parser_range vec)
{
if (vec.buffer == NULL)
return;
if (vec.free_func)
{
while (vec.len)
{
vec.free_func(vec.buffer[vec.len - 1]);
vec.len--;
}
}
mem_free(vec.buffer);
}

View file

@ -1,112 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* vec_parser_range.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/30 17:59:28 by maiboyer #+# #+# */
/* Updated: 2023/12/30 17:59:28 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#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>
t_error vec_parser_range_find(t_vec_parser_range *vec,
bool (*fn)(const t_parser_range *), t_usize *index)
{
t_usize idx;
if (vec == NULL || fn == NULL || index == NULL)
return (ERROR);
idx = 0;
while (idx < vec->len)
{
if (fn((const t_parser_range *)&vec->buffer[idx]))
{
*index = idx;
return (NO_ERROR);
}
idx++;
}
return (ERROR);
}
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_usize idx;
if (vec == NULL || fn == NULL || index == NULL)
return (ERROR);
idx = starting_index;
while (idx < vec->len)
{
if (fn((const t_parser_range *)&vec->buffer[idx]))
{
*index = idx;
return (NO_ERROR);
}
idx++;
}
return (ERROR);
}
t_error vec_parser_range_all(t_vec_parser_range *vec,
bool (*fn)(const t_parser_range *), bool *result)
{
t_usize idx;
if (vec == NULL || fn == NULL || result == NULL)
return (ERROR);
idx = 0;
*result = true;
while (*result && idx < vec->len)
{
if (!fn((const t_parser_range *)&vec->buffer[idx]))
*result = false;
idx++;
}
return (ERROR);
}
t_error vec_parser_range_any(t_vec_parser_range *vec,
bool (*fn)(const t_parser_range *), bool *result)
{
t_usize idx;
if (vec == NULL || fn == NULL || result == NULL)
return (ERROR);
idx = 0;
*result = false;
while (*result && idx < vec->len)
{
if (fn((const t_parser_range *)&vec->buffer[idx]))
*result = true;
idx++;
}
return (ERROR);
}
void vec_parser_range_iter(t_vec_parser_range *vec,
void (*fn)(t_usize index, t_parser_range *value,
void *state),
void *state)
{
t_usize idx;
if (vec == NULL || fn == NULL)
return;
idx = 0;
while (idx < vec->len)
{
fn(idx, &vec->buffer[idx], state);
idx++;
}
}

View file

@ -1,84 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* vec_parser_range.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/30 17:59:28 by maiboyer #+# #+# */
/* Updated: 2023/12/30 17:59:28 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#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>
t_error vec_parser_range_push_front(t_vec_parser_range *vec,
t_parser_range element)
{
t_usize i;
if (vec->len == 0)
return (vec_parser_range_push(vec, element));
i = vec->len - 1;
if (vec->capacity < vec->len + 1 &&
vec_parser_range_reserve(vec, 3 * vec->len / 2 + 1))
return (ERROR);
while (i > 0)
{
vec->buffer[i + 1] = vec->buffer[i];
i--;
}
vec->buffer[1] = vec->buffer[0];
vec->buffer[0] = element;
vec->len++;
return (NO_ERROR);
}
t_error vec_parser_range_pop_front(t_vec_parser_range *vec, t_parser_range *value)
{
t_usize i;
if (vec->len <= 1)
return (vec_parser_range_pop(vec, value));
i = 0;
*value = vec->buffer[0];
vec->len--;
while (i < vec->len)
{
vec->buffer[i] = vec->buffer[i + 1];
i++;
}
mem_set_zero(&vec->buffer[i], sizeof(*vec->buffer));
return (NO_ERROR);
}
void vec_parser_range_reverse(t_vec_parser_range *vec)
{
t_parser_range temporary;
t_usize i;
i = 0;
while (i < vec->len / 2)
{
temporary = vec->buffer[vec->len - 1 - i];
vec->buffer[vec->len - 1 - i] = vec->buffer[i];
vec->buffer[i] = temporary;
i++;
}
}
t_error vec_parser_range_back(t_vec_parser_range *vec, t_parser_range **out)
{
t_parser_range *temporary;
if (out == NULL)
out = &temporary;
if (vec->len != 0)
return (*out = &vec->buffer[vec->len - 1], true);
return (false);
}

View file

@ -1,95 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* vec_reduce_action.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/05 18:46:28 by maiboyer #+# #+# */
/* Updated: 2023/12/09 17:54:11 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "me/mem/mem.h"
#include "me/types.h"
#include "me/vec/vec_reduce_action.h"
#include <stdlib.h>
t_vec_reduce_action vec_reduce_action_new(t_usize capacity,
t_free_reduce_action_item free_function)
{
t_vec_reduce_action out;
out = (t_vec_reduce_action){0};
out.free_func = free_function;
out.buffer = mem_alloc_array(capacity, sizeof(t_reduce_action));
if (out.buffer)
out.capacity = capacity;
return (out);
}
/// Return true in case of an error
t_error vec_reduce_action_push(t_vec_reduce_action *vec, t_reduce_action element)
{
if (vec == NULL)
return (ERROR);
vec_reduce_action_reserve(vec, vec->len + 1);
vec->buffer[vec->len] = element;
vec->len += 1;
return (NO_ERROR);
}
/// Return true in case of an error
t_error vec_reduce_action_reserve(t_vec_reduce_action *vec, t_usize wanted_capacity)
{
size_t new_capacity;
if (vec == NULL)
return (ERROR);
if (wanted_capacity > vec->capacity)
{
new_capacity = (vec->capacity * 3) / 2 + 1;
while (wanted_capacity > new_capacity)
new_capacity = (new_capacity * 3) / 2 + 1;
vec->buffer =
mem_realloc_array(vec->buffer, new_capacity, sizeof(t_reduce_action));
vec->capacity = new_capacity;
}
return (NO_ERROR);
}
/// Return true if the vector is empty
/// This function is safe to call with value being NULL
t_error vec_reduce_action_pop(t_vec_reduce_action *vec, t_reduce_action *value)
{
t_reduce_action temp_value;
t_reduce_action *ptr;
if (vec == NULL)
return (ERROR);
ptr = value;
if (vec->len == 0)
return (ERROR);
if (value == NULL)
ptr = &temp_value;
vec->len--;
*ptr = vec->buffer[vec->len];
mem_set_zero(&vec->buffer[vec->len], sizeof(t_reduce_action));
return (NO_ERROR);
}
/// This function is safe to call with `free_elem` being NULL
void vec_reduce_action_free(t_vec_reduce_action vec)
{
if (vec.buffer == NULL)
return;
if (vec.free_func)
{
while (vec.len)
{
vec.free_func(vec.buffer[vec.len - 1]);
vec.len--;
}
}
mem_free(vec.buffer);
}

View file

@ -1,112 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* vec_reduce_action.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/30 17:59:28 by maiboyer #+# #+# */
/* Updated: 2023/12/30 17:59:28 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#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>
t_error vec_reduce_action_find(t_vec_reduce_action *vec,
bool (*fn)(const t_reduce_action *), t_usize *index)
{
t_usize idx;
if (vec == NULL || fn == NULL || index == NULL)
return (ERROR);
idx = 0;
while (idx < vec->len)
{
if (fn((const t_reduce_action *)&vec->buffer[idx]))
{
*index = idx;
return (NO_ERROR);
}
idx++;
}
return (ERROR);
}
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_usize idx;
if (vec == NULL || fn == NULL || index == NULL)
return (ERROR);
idx = starting_index;
while (idx < vec->len)
{
if (fn((const t_reduce_action *)&vec->buffer[idx]))
{
*index = idx;
return (NO_ERROR);
}
idx++;
}
return (ERROR);
}
t_error vec_reduce_action_all(t_vec_reduce_action *vec,
bool (*fn)(const t_reduce_action *), bool *result)
{
t_usize idx;
if (vec == NULL || fn == NULL || result == NULL)
return (ERROR);
idx = 0;
*result = true;
while (*result && idx < vec->len)
{
if (!fn((const t_reduce_action *)&vec->buffer[idx]))
*result = false;
idx++;
}
return (ERROR);
}
t_error vec_reduce_action_any(t_vec_reduce_action *vec,
bool (*fn)(const t_reduce_action *), bool *result)
{
t_usize idx;
if (vec == NULL || fn == NULL || result == NULL)
return (ERROR);
idx = 0;
*result = false;
while (*result && idx < vec->len)
{
if (fn((const t_reduce_action *)&vec->buffer[idx]))
*result = true;
idx++;
}
return (ERROR);
}
void vec_reduce_action_iter(t_vec_reduce_action *vec,
void (*fn)(t_usize index, t_reduce_action *value,
void *state),
void *state)
{
t_usize idx;
if (vec == NULL || fn == NULL)
return;
idx = 0;
while (idx < vec->len)
{
fn(idx, &vec->buffer[idx], state);
idx++;
}
}

View file

@ -1,84 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* vec_reduce_action.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/30 17:59:28 by maiboyer #+# #+# */
/* Updated: 2023/12/30 17:59:28 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#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>
t_error vec_reduce_action_push_front(t_vec_reduce_action *vec,
t_reduce_action element)
{
t_usize i;
if (vec->len == 0)
return (vec_reduce_action_push(vec, element));
i = vec->len - 1;
if (vec->capacity < vec->len + 1 &&
vec_reduce_action_reserve(vec, 3 * vec->len / 2 + 1))
return (ERROR);
while (i > 0)
{
vec->buffer[i + 1] = vec->buffer[i];
i--;
}
vec->buffer[1] = vec->buffer[0];
vec->buffer[0] = element;
vec->len++;
return (NO_ERROR);
}
t_error vec_reduce_action_pop_front(t_vec_reduce_action *vec, t_reduce_action *value)
{
t_usize i;
if (vec->len <= 1)
return (vec_reduce_action_pop(vec, value));
i = 0;
*value = vec->buffer[0];
vec->len--;
while (i < vec->len)
{
vec->buffer[i] = vec->buffer[i + 1];
i++;
}
mem_set_zero(&vec->buffer[i], sizeof(*vec->buffer));
return (NO_ERROR);
}
void vec_reduce_action_reverse(t_vec_reduce_action *vec)
{
t_reduce_action temporary;
t_usize i;
i = 0;
while (i < vec->len / 2)
{
temporary = vec->buffer[vec->len - 1 - i];
vec->buffer[vec->len - 1 - i] = vec->buffer[i];
vec->buffer[i] = temporary;
i++;
}
}
t_error vec_reduce_action_back(t_vec_reduce_action *vec, t_reduce_action **out)
{
t_reduce_action *temporary;
if (out == NULL)
out = &temporary;
if (vec->len != 0)
return (*out = &vec->buffer[vec->len - 1], true);
return (false);
}

View file

@ -1,24 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* types_char_range.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/29 15:03:34 by maiboyer #+# #+# */
/* Updated: 2024/04/29 15:27:38 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef TYPES_CHAR_RANGE_H
# define TYPES_CHAR_RANGE_H
# include "me/types.h"
typedef struct s_char_range
{
t_i32 start;
t_i32 end;
} t_char_range;
#endif /* TYPES_CHAR_RANGE_H */

View file

@ -1,25 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* types_field_entry.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/29 14:51:21 by maiboyer #+# #+# */
/* Updated: 2024/04/29 15:35:36 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef TYPES_FIELD_ENTRY_H
# define TYPES_FIELD_ENTRY_H
# include "parser/types/types_field_id.h"
typedef struct s_field_map_entry
{
t_field_id field_id;
t_u8 child_index;
bool inherited;
} t_field_map_entry;
#endif /* TYPES_FIELD_ENTRY_H */

View file

@ -1,20 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* types_field_id.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/29 14:44:38 by maiboyer #+# #+# */
/* Updated: 2024/04/29 14:44:44 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef TYPES_FIELD_ID_H
# define TYPES_FIELD_ID_H
# include "me/types.h"
typedef t_u16 t_field_id;
#endif /* TYPES_FIELD_ID_H */

View file

@ -1,26 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* types_field_map_entry.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/29 14:51:45 by maiboyer #+# #+# */
/* Updated: 2024/04/29 14:53:31 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef TYPES_FIELD_MAP_ENTRY_H
# define TYPES_FIELD_MAP_ENTRY_H
# include "me/types.h"
# include "parser/types/types_field_id.h"
typedef struct s_field_map_entry
{
t_field_id field_id;
t_u8 child_index;
bool inherited;
} t_field_map_entry;
#endif /* TYPES_FIELD_MAP_ENTRY_H */

View file

@ -1,24 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* types_field_map_slice.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/29 14:54:41 by maiboyer #+# #+# */
/* Updated: 2024/04/29 15:08:21 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef TYPES_FIELD_MAP_SLICE_H
# define TYPES_FIELD_MAP_SLICE_H
# include "me/types.h"
typedef struct s_field_map_slice
{
t_u16 index;
t_u16 length;
} t_field_map_slice;
#endif /* TYPES_FIELD_MAP_SLICE_H */

View file

@ -1,28 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* types_heredoc.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/30 13:47:07 by maiboyer #+# #+# */
/* Updated: 2024/04/30 13:48:19 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef TYPES_HEREDOC_H
#define TYPES_HEREDOC_H
#include "me/string/string.h"
#include "me/types.h"
typedef struct s_heredoc
{
bool is_raw;
bool started;
bool allows_indent;
t_string delimiter;
t_string current_leading_word;
} t_heredoc;
#endif /* TYPES_HEREDOC_H */

View file

@ -1,61 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* types_language.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/29 14:39:37 by maiboyer #+# #+# */
/* Updated: 2024/04/29 15:36:47 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef TYPES_LANGUAGE_H
# define TYPES_LANGUAGE_H
# include "me/types.h"
# include "parser/types/types_field_map_entry.h"
# include "parser/types/types_field_map_slice.h"
# include "parser/types/types_lex_modes.h"
# include "parser/types/types_lexer.h"
# include "parser/types/types_parse_action_entry.h"
# include "parser/types/types_scanner.h"
# include "parser/types/types_state_id.h"
# include "parser/types/types_symbol.h"
# include "parser/types/types_symbol_metadata.h"
typedef bool (*t_lex_fn)(t_lexer *lex, t_state_id state);
typedef struct s_language
{
t_u32 version;
t_u32 symbol_count;
t_u32 alias_count;
t_u32 token_count;
t_u32 external_token_count;
t_u32 state_count;
t_u32 large_state_count;
t_u32 production_id_count;
t_u32 field_count;
t_u16 max_alias_sequence_length;
const t_u16 *parse_table;
const t_u16 *small_parse_table;
const t_u32 *small_parse_table_map;
const t_parse_action_entry *parse_actions;
const t_const_str *symbol_names;
const t_const_str *field_names;
const t_field_map_slice *field_map_slices;
const t_field_map_entry *field_map_entries;
const t_symbol_metadata *symbol_metadata;
const t_symbol *public_symbol_map;
const t_u16 *alias_map;
const t_symbol *alias_sequences;
const t_lex_modes *lex_modes;
t_lex_fn lex_fn;
t_lex_fn keyword_lex_fn;
t_symbol keyword_capture_token;
t_scanner external_scanner;
const t_state_id *primary_state_ids;
} t_language;
#endif /* TYPES_LANGUAGE_H */

View file

@ -1,24 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* types_lex_modes.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/29 15:01:24 by maiboyer #+# #+# */
/* Updated: 2024/04/29 15:01:31 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef TYPES_LEX_MODES_H
# define TYPES_LEX_MODES_H
# include "me/types.h"
typedef struct s_lex_modes
{
t_u16 lex_state;
t_u16 external_lex_state;
} t_lex_modes;
#endif /* TYPES_LEX_MODES_H */

View file

@ -1,30 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* types_lexer.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/29 14:45:45 by maiboyer #+# #+# */
/* Updated: 2024/04/29 16:24:16 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef TYPES_LEXER_H
# define TYPES_LEXER_H
# include "me/types.h"
# include "parser/types/types_symbol.h"
typedef struct s_lexer
{
t_i32 lookahead;
t_symbol result_symbol;
void (*advance)(struct s_lexer *, bool);
void (*mark_end)(struct s_lexer *);
t_i32 (*get_column)(struct s_lexer *);
bool (*is_at_included_range_start)(const struct s_lexer *);
bool (*eof)(const struct s_lexer *);
} t_lexer;
#endif /* TYPES_LEXER_H */

View file

@ -1,28 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* types_lexer_state.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/29 14:50:20 by maiboyer #+# #+# */
/* Updated: 2024/04/29 14:51:00 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef TYPES_LEXER_STATE_H
# define TYPES_LEXER_STATE_H
# include "me/types.h"
# include "parser/types/types_state_id.h"
typedef struct s_lexer_state
{
t_u32 lookahead;
t_state_id state;
bool result;
bool skip;
bool eof;
} t_lexer_state;
#endif /* TYPES_LEXER_STATE_H */

View file

@ -1,31 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* types_parse_action_entry.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/29 15:01:57 by maiboyer #+# #+# */
/* Updated: 2024/04/29 15:03:13 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef TYPES_PARSE_ACTION_ENTRY_H
# define TYPES_PARSE_ACTION_ENTRY_H
# include "me/types.h"
# include "parser/types/types_parse_actions.h"
struct s_parse_actions_entry_entry
{
t_u8 count;
bool reusable;
};
typedef union u_parse_actions_entry
{
t_parse_actions action;
struct s_parse_actions_entry_entry entry;
} t_parse_action_entry;
#endif /* TYPES_PARSE_ACTION_ENTRY_H */

View file

@ -1,24 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* types_parse_action_type.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/29 14:57:22 by maiboyer #+# #+# */
/* Updated: 2024/04/29 14:57:32 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef TYPES_PARSE_ACTION_TYPE_H
# define TYPES_PARSE_ACTION_TYPE_H
typedef enum e_parse_action_type
{
ActionTypeShift,
ActionTypeReduce,
ActionTypeAccept,
ActionTypeRecover,
} t_parse_action_type;
#endif /* TYPES_PARSE_ACTION_TYPE_H */

View file

@ -1,44 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* types_parse_actions.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/29 14:58:36 by maiboyer #+# #+# */
/* Updated: 2024/04/29 15:00:51 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef TYPES_PARSE_ACTIONS_H
# define TYPES_PARSE_ACTIONS_H
# include "me/types.h"
# include "parser/types/types_state_id.h"
# include "parser/types/types_symbol.h"
struct s_parse_action_shift
{
t_u8 type;
t_state_id state;
bool extra;
bool repetition;
};
struct s_parse_action_reduce
{
t_u8 type;
t_u8 child_count;
t_symbol symbol;
t_i16 dynamic_precedence;
t_u16 production_id;
};
typedef union u_parse_actions
{
struct s_parse_action_shift shift;
struct s_parse_action_reduce reduce;
t_u8 type;
} t_parse_actions;
#endif /* TYPES_PARSE_ACTIONS_H */

View file

@ -1,26 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* types_parser_node.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/29 14:36:46 by maiboyer #+# #+# */
/* Updated: 2024/04/29 14:37:36 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef TYPES_PARSER_NODE_H
# define TYPES_PARSER_NODE_H
# include "me/types.h"
# include "parser/types/types_parser_tree.h"
typedef struct s_parser_node
{
t_u32 context[4];
const void *id;
const t_parser_tree *tree;
} t_parser_node;
#endif /* TYPES_PARSER_NODE_H */

View file

@ -1,28 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* types_parser_range.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/29 14:11:26 by maiboyer #+# #+# */
/* Updated: 2024/04/29 14:25:11 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef TYPES_PARSER_RANGE_H
# define TYPES_PARSER_RANGE_H
# include "me/types.h"
# include "parser/types/types_point.h"
typedef struct s_parser_range
{
t_point start_point;
t_point end_point;
t_u32 start_byte;
t_u32 end_byte;
} t_parser_range;
#endif /* TYPES_PARSER_RANGE_H */

View file

@ -1,16 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* types_parser_subtree.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/29 14:49:40 by maiboyer #+# #+# */
/* Updated: 2024/04/29 14:49:40 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef TYPES_PARSER_SUBTREE_H
# define TYPES_PARSER_SUBTREE_H
#endif /* TYPES_PARSER_SUBTREE_H */

View file

@ -1,29 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* types_parser_tree.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/29 14:37:41 by maiboyer #+# #+# */
/* Updated: 2024/04/29 14:49:20 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef TYPES_PARSER_TREE_H
# define TYPES_PARSER_TREE_H
# include "me/types.h"
# include "parser/types/types_language.h"
# include "parser/types/types_parser_range.h"
# include "parser/types/types_parser_subtree.h"
typedef struct s_parser_tree
{
t_parser_subtree root;
const t_language *language;
t_parser_range *included_ranges;
t_i32 included_range_count;
} t_parser_tree;
#endif /* TYPES_PARSER_TREE_H */

View file

@ -1,24 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* types_point.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/29 14:20:34 by maiboyer #+# #+# */
/* Updated: 2024/04/29 14:21:16 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef TYPES_POINT_H
# define TYPES_POINT_H
# include "me/types.h"
typedef struct s_point
{
t_u32 row;
t_u32 column;
} t_point;
#endif /* TYPES_POINT_H */

View file

@ -1,27 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* types_reduce_action.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/30 15:21:59 by maiboyer #+# #+# */
/* Updated: 2024/04/30 15:22:18 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef TYPES_REDUCE_ACTION_H
#define TYPES_REDUCE_ACTION_H
#include "me/types.h"
#include "parser/types/types_symbol.h"
typedef struct s_reduce_action
{
t_u32 count;
t_symbol symbol;
t_i32 dynamic_precedence;
t_u16 production_id;
} t_reduce_action;
#endif /* TYPES_REDUCE_ACTION_H */

View file

@ -1,39 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* types_scanner.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/29 14:42:52 by maiboyer #+# #+# */
/* Updated: 2024/04/29 15:34:21 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef TYPES_SCANNER_H
# define TYPES_SCANNER_H
# include "me/types.h"
# include "parser/types/types_lexer.h"
# include "parser/types/types_symbol.h"
typedef bool (*t_scanner_scan)(void *self, t_lexer *lex,
const bool *symbol_whitelist);
typedef void *(*t_scanner_create)(void);
typedef void (*t_scanner_destroy)(void *ctx);
typedef unsigned (*t_scanner_serialize)(void *self, t_str s);
typedef void (*t_scanner_deserialize)(void *self, t_const_str s,
t_u32 len);
typedef struct s_scanner
{
const bool *states;
const t_symbol *symbol_map;
t_scanner_create create;
t_scanner_destroy destroy;
t_scanner_scan scan;
t_scanner_serialize serialize;
t_scanner_deserialize deserialize;
} t_scanner;
#endif /* TYPES_SCANNER_H */

View file

@ -1,27 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* types_scanner_ctx.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/30 13:41:02 by maiboyer #+# #+# */
/* Updated: 2024/04/30 13:50:24 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef TYPES_SCANNER_CTX_H
#define TYPES_SCANNER_CTX_H
#include "me/types.h"
#include "me/vec/vec_parser_heredoc.h"
typedef struct s_scanner_ctx
{
t_u8 last_glob_paren_depth;
bool ext_was_in_double_quote;
bool ext_saw_outside_quote;
t_vec_parser_heredoc heredocs;
} t_scanner_ctx;
#endif /* TYPES_SCANNER_CTX_H */

View file

@ -1,20 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* types_state_id.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/29 14:44:15 by maiboyer #+# #+# */
/* Updated: 2024/04/29 14:44:47 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef TYPES_STATE_ID_H
# define TYPES_STATE_ID_H
# include "me/types.h"
typedef t_u16 t_state_id;
#endif /* TYPES_STATE_ID_H */

View file

@ -1,23 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* types_symbol.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/29 14:43:33 by maiboyer #+# #+# */
/* Updated: 2024/04/29 16:41:28 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef TYPES_SYMBOL_H
#define TYPES_SYMBOL_H
#include "me/types.h"
typedef t_u16 t_symbol;
#define ts_builtin_sym_end (t_symbol)0
#define ts_builtin_sym_error (t_symbol)(-1)
#endif /* TYPES_SYMBOL_H */

View file

@ -1,25 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* types_symbol_metadata.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/29 14:55:57 by maiboyer #+# #+# */
/* Updated: 2024/04/29 14:56:04 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef TYPES_SYMBOL_METADATA_H
# define TYPES_SYMBOL_METADATA_H
# include "me/types.h"
typedef struct s_symbol_metadata
{
bool visible;
bool named;
bool supertype;
} t_symbol_metadata;
#endif /* TYPES_SYMBOL_METADATA_H */

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */ /* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/24 23:01:45 by maiboyer #+# #+# */ /* Created: 2024/04/24 23:01:45 by maiboyer #+# #+# */
/* Updated: 2024/06/30 18:03:54 by maiboyer ### ########.fr */ /* Updated: 2024/07/11 18:50:48 by maiboyer ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -21,8 +21,6 @@
#include "./src/parser.h" #include "./src/parser.h"
#include "me/types.h" #include "me/types.h"
#include "parser/types/types_lexer_state.h"
typedef TSSymbolMetadata t_symbol_metadata; typedef TSSymbolMetadata t_symbol_metadata;
typedef TSSymbol t_symbol; typedef TSSymbol t_symbol;
typedef TSStateId t_state_id; typedef TSStateId t_state_id;
@ -34,6 +32,18 @@ typedef TSParseActionEntry t_parse_action_entry;
typedef TSLexMode t_lex_modes; typedef TSLexMode t_lex_modes;
typedef TSCharacterRange t_char_range; typedef TSCharacterRange t_char_range;
struct s_lexer_state
{
t_u32 lookahead;
t_state_id state;
bool result;
bool skip;
bool eof;
};
typedef struct s_lexer_state t_lexer_state;
#define ActionTypeShift TSParseActionTypeShift #define ActionTypeShift TSParseActionTypeShift
#define ActionTypeReduce TSParseActionTypeReduce #define ActionTypeReduce TSParseActionTypeReduce
#define ActionTypeRecover TSParseActionTypeRecover #define ActionTypeRecover TSParseActionTypeRecover

View file

@ -1,77 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* handle_command.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/09 15:00:53 by rparodi #+# #+# */
/* Updated: 2024/06/21 13:55:02 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "app/env.h"
#include "app/node.h"
#include "app/state.h"
#include "gmr/symbols.h"
#include "me/mem/mem.h"
#include "me/types.h"
#include "me/vec/vec_str.h"
// #include "app/node/handle_program.h"
#include "app/node/handle_command.h"
#include "me/str/str.h"
#include "minishell.h"
#include <time.h>
void handle_command_free_infork(void *vshcat)
{
t_utils *shcat;
shcat = vshcat;
(void)(shcat);
//ft_exit(shcat, 255);
}
t_error handle_command(t_node *self, t_utils *shcat, t_i32 *out_exit_code)
{
t_usize i;
t_spawn_info spawn_info;
spawn_info.arguments =
vec_str_new(64, (void (*)(t_str))mem_free); // TODO: FIX VECTOR
if (self->kind != sym_command)
return (ERROR);
i = 0;
while (i < self->childs_count)
{
if (self->childs[i].kind == sym_command_name)
{
spawn_info.binary_path = str_clone(node_getstr(&self->childs[i]));
vec_str_push(&spawn_info.arguments,
str_clone(spawn_info.binary_path));
printf("%s\n", spawn_info.arguments.buffer[0]);
}
else if (self->childs[i].kind == sym_file_redirect)
printf("PAS ENCORE HANDLE FDP redirect!\n");
else if (self->childs[i].kind == sym_variable_assignment)
printf("PAS ENCORE HANDLE FDP asignement!\n");
else
{
}
i++;
}
spawn_info.stdin = inherited();
spawn_info.stdout = inherited();
spawn_info.stderr = inherited();
spawn_info.forked_free = handle_command_free_infork;
if (build_envp(shcat->env, &spawn_info.environement))
return (vec_str_free(spawn_info.arguments), ERROR);
if (spawn_process(spawn_info, &shcat->ret))
return (ERROR);
waitpid(shcat->ret.pid, NULL, 0);
close(shcat->ret.stdin.vals.ro.fd);
close(shcat->ret.stdout.vals.ro.fd);
close(shcat->ret.stderr.vals.ro.fd);
*out_exit_code = 0;
return (NO_ERROR);
}

View file

@ -1,52 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* handle_concat.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/02 15:05:06 by maiboyer #+# #+# */
/* Updated: 2024/05/07 14:59:27 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "app/node/handle_concat.h"
#include "app/node.h"
#include "app/node/handle_raw_word.h"
#include "app/node/handle_word.h"
#include "app/state.h"
#include "gmr/symbols.h"
#include "me/string/string.h"
#include "me/types.h"
t_error node_get_string(t_node *self, t_utils *shcat, t_str *ret)
{
if (self->kind == sym_word)
return (handle_word(self, shcat, ret));
if (self->kind == sym_raw_string)
return (handle_raw_string(self, shcat, ret));
return (ERROR);
}
t_error handle_concat(t_node *self, t_utils *shcat, t_str *ret)
{
t_string out;
t_usize i;
t_str tmp;
(void)(shcat);
if (self == NULL || ret == NULL || self->kind != sym_concatenation)
return (ERROR);
out = string_new(16);
i = 0;
while (i < self->childs_count)
{
if (node_get_string(&self->childs[i], shcat, &tmp))
return (string_free(out), ERROR);
string_push(&out, tmp);
mem_free(tmp);
i++;
}
*ret = out.buf;
return (NO_ERROR);
}

View file

@ -1,42 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* handle_expension.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/03 15:24:25 by maiboyer #+# #+# */
/* Updated: 2024/05/07 14:55:25 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "app/node/handle_expension.h"
#include "gmr/symbols.h"
#include "me/hashmap/hashmap_env.h"
#include "me/types.h"
t_error handle_expension_complex(t_node *self, t_utils *shcat, t_str *ret)
{
(void)(self);
(void)(shcat);
(void)(ret);
return (ERROR);
}
t_error handle_expension_simple(t_node *self, t_utils *shcat, t_str *ret)
{
(void)(self);
(void)(shcat);
(void)(ret);
//get_hashmap_env(shcat->env, (t_str *)&"fjdksf");
return (ERROR);
}
t_error handle_expension(t_node *self, t_utils *shcat, t_str *ret)
{
if (self->childs_count != 0 && self->childs[0].kind == anon_sym_DOLLAR)
return (handle_expension_simple(self, shcat, ret));
if (self->childs_count != 0 &&
self->childs[0].kind == anon_sym_DOLLAR_LBRACE)
return (handle_expension_complex(self, shcat, ret));
return (ERROR);
}

View file

@ -1,36 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* handle_program.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/09 14:34:48 by rparodi #+# #+# */
/* Updated: 2024/05/09 15:06:42 by rparodi ### ########.fr */
/* */
/* ************************************************************************** */
# include "app/state.h"
# include "me/types.h"
# include "gmr/symbols.h"
# include "app/node.h"
# include "app/node/handle_program.h"
# include "app/node/handle_command.h"
t_error handle_program(t_node *self, t_utils *shcat, t_i32 *out_exit_code)
{
t_usize i;
if (self->kind != sym_program)
return (ERROR);
i = 0;
while (i < self->childs_count)
{
if (self->childs[i].kind == sym_command)
if (handle_command(&self->childs[i], shcat, out_exit_code))
return (ERROR);
i++;
}
return (NO_ERROR);
}

View file

@ -1,33 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* handle_raw_word.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/02 15:57:33 by maiboyer #+# #+# */
/* Updated: 2024/05/02 16:03:09 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "app/node/handle_raw_word.h"
#include "app/node.h"
#include "app/state.h"
#include "gmr/symbols.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)
{
t_str tmp;
t_usize i;
(void)(shcat);
if (self == NULL || ret == NULL || self->kind != sym_raw_string)
return (ERROR);
tmp = node_getstr(self);
i = str_len(tmp);
*ret = str_substring(tmp, 1, i - 2);
return (NO_ERROR);
}

View file

@ -1,26 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* handle_word.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/02 15:59:04 by maiboyer #+# #+# */
/* Updated: 2024/05/02 16:00:00 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "app/node/handle_word.h"
#include "app/state.h"
#include "gmr/symbols.h"
#include "me/str/str.h"
#include "me/types.h"
t_error handle_word(t_node *self, t_utils *shcat, t_str *ret)
{
(void)(shcat);
if (self == NULL || ret == NULL || self->kind != sym_word)
return (ERROR);
*ret = str_clone(node_getstr(self));
return (NO_ERROR);
}

View file

@ -1,21 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* and_and.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/12 19:16:12 by rparodi #+# #+# */
/* Updated: 2024/05/18 17:48:43 by rparodi ### ########.fr */
/* */
/* ************************************************************************** */
#include "separator.h"
t_error and_and_exec(t_node *first, t_node *second, t_i32 *ret_value)
{
if (ft_command_exec(first, ret_value) == ERROR)
return (ERROR);
ft_command_exec(second, ret_value);
return (NO_ERROR);
}

View file

@ -1,23 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* pipe_pipe.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/12 19:21:01 by rparodi #+# #+# */
/* Updated: 2024/05/12 19:44:46 by rparodi ### ########.fr */
/* */
/* ************************************************************************** */
#include "separator.h"
t_error pipe_pipe(t_node *first, t_node *second, t_i32 *ret_value)
{
if (first || ft_command_exec(first, ret_value))
return (NO_ERROR);
else if (second || ft_command_exec(second, ret_value))
return (NO_ERROR);
else
return (ERROR);
}

View file

@ -1,41 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* semicolon.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/12 16:00:33 by rparodi #+# #+# */
/* Updated: 2024/05/22 15:04:52 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "app/env.h"
#include "app/state.h"
#include "me/types.h"
#include "gmr/symbols.h"
#include "app/node.h"
#include "me/vec/vec_str.h"
#include "app/node/handle_command.h"
#include "minishell.h"
#include "me/str/str.h"
t_error ft_command_exec(t_node *self, t_i32 *ret);
t_error ft_command_exec(t_node *self, t_i32 *ret);
t_error semicolon_exec(t_node *first, t_node *second, t_i32 *ret_value)
{
if (!first && !second)
return (ERROR);
else if (!first)
ft_command_exec(second, ret_value);
else if (!second)
ft_command_exec(first, ret_value);
else
{
ft_command_exec(first, ret_value);
ft_command_exec(second, ret_value);
}
return (NO_ERROR);
}

View file

@ -1,24 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* separator.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/12 16:53:15 by rparodi #+# #+# */
/* Updated: 2024/05/12 19:57:14 by rparodi ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef SEPARATOR_H
# define SEPARATOR_H
# include "minishell.h"
t_error ft_command_exec(t_node *node, t_i32 *ret_value);
t_error pipe_pipe(t_node *first, t_node *second, t_i32 *ret_value);
t_error and_and_exec(t_node *first, t_node *second, t_i32 *ret_value);
t_error semicolon_exec(t_node *first, t_node *second, t_i32 *ret_value);
#endif

View file

@ -1,20 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* simple_cmd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/12 19:13:42 by rparodi #+# #+# */
/* Updated: 2024/05/17 15:33:13 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "separator.h"
t_error ft_command_exec(t_node *node, t_i32 *ret_value)
{
printf("execve : %s\n", node->single_str);
(void)(ret_value);
return (NO_ERROR);
}

View file

@ -1,14 +1,4 @@
env.c env.c
exec/handle_command.c
exec/handle_concat.c
exec/handle_expension.c
exec/handle_program.c
exec/handle_raw_word.c
exec/handle_word.c
exec/separator/and_and.c
exec/separator/pipe_pipe.c
exec/separator/semicolon.c
exec/separator/simple_cmd.c
ft_cmd.c ft_cmd.c
ft_echo.c ft_echo.c
ft_exit.c ft_exit.c

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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