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,12 +11,12 @@
/* ************************************************************************** */ /* ************************************************************************** */
#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);

View file

@ -11,10 +11,10 @@
/* ************************************************************************** */ /* ************************************************************************** */
#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
{ {

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,11 +11,11 @@
/* ************************************************************************** */ /* ************************************************************************** */
#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;

View file

@ -11,12 +11,12 @@
/* ************************************************************************** */ /* ************************************************************************** */
#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
{ {

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,9 +11,9 @@
/* ************************************************************************** */ /* ************************************************************************** */
#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

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 # endif
# define FILE_SLOT_LEN 512 # define FILE_SLOT_LEN 512
#endif # 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
@ -91,7 +91,6 @@ 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,
@ -132,7 +131,8 @@ typedef struct s_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_fd fd;
t_dir dir; t_dir dir;
t_file file; t_file file;
@ -208,7 +208,8 @@ 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_open_option open_options,
t_file_perm file_perm); t_file_perm file_perm);
/// @brief Read from a file descriptor /// @brief Read from a 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,7 +228,8 @@ 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
@ -325,7 +328,7 @@ 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);

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,9 +11,9 @@
/* ************************************************************************** */ /* ************************************************************************** */
#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);

View file

@ -6,14 +6,14 @@
/* 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
@ -30,7 +30,8 @@ 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);
@ -39,7 +40,8 @@ void *mem_realloc(void *ptr, t_usize size);
/// @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);
@ -48,8 +50,6 @@ void *mem_realloc_array(void *ptr, t_usize size, t_usize count);
/// @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
@ -88,7 +88,8 @@ 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

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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -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
@ -115,9 +117,9 @@ 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}, \
}}); }});
} }
@ -161,7 +163,6 @@ 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

View file

@ -6,16 +6,16 @@
/* 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;
@ -24,8 +24,8 @@ 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
{ {
@ -74,8 +74,9 @@ struct s_printf_args
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,23 +6,25 @@
/* 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; typedef struct s_fd t_fd;
#endif # endif
# ifndef STRING_H
#ifndef STRING_H
typedef struct s_string t_string; typedef struct s_string t_string;
#endif # 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
@ -52,13 +54,13 @@ t_usize me_veprintf(t_const_str fmt, va_list *args);
/// @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
@ -72,6 +74,6 @@ t_usize me_printf_str(t_string *buffer, t_const_str fmt, ...);
/// @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,13 +47,15 @@ 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,
/// or NULL if not found
char *str_find_chr(t_const_str str, char chr); 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,
/// or NULL if not found
char *str_find_rev_chr(t_const_str str, char chr); 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

View file

@ -6,13 +6,13 @@
/* 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
{ {

View file

@ -6,21 +6,17 @@
/* 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;
@ -69,8 +65,8 @@ void me_exit(t_i32 code);
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