diff --git a/Filelist.sh.mk b/Filelist.sh.mk index e53a653b..47da9e72 100644 --- a/Filelist.sh.mk +++ b/Filelist.sh.mk @@ -7,6 +7,7 @@ signal_handler \ GEN_FILES = \ src/hashmap/env/env \ +src/hashmap/env/env_clear \ src/hashmap/env/env_clone \ src/hashmap/env/env_iter \ src/hashmap/env/env_utils \ diff --git a/Makefile b/Makefile index 11e94d37..d082ff5a 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ # By: rparodi +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2023/11/12 11:05:05 by rparodi #+# #+# # -# Updated: 2024/08/01 07:16:16 by maiboyer ### ########.fr # +# Updated: 2024/08/02 22:42:24 by maiboyer ### ########.fr # # # # **************************************************************************** # diff --git a/exec/include/exec/_run_ast.h b/exec/include/exec/_run_ast.h index 29ba2f15..c27dbefd 100644 --- a/exec/include/exec/_run_ast.h +++ b/exec/include/exec/_run_ast.h @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/08/02 14:41:48 by rparodi #+# #+# */ -/* Updated: 2024/08/02 18:51:16 by maiboyer ### ########.fr */ +/* Updated: 2024/08/02 21:13:33 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ @@ -73,7 +73,7 @@ struct s_cmd_pipe }; t_error run_arithmetic_expansion(t_ast_arithmetic_expansion *arithmetic_expansion, t_state *state, t_i64 *out); -t_error run_command(t_ast_command *command, t_state *state, t_command_result *out); +t_error run_command(t_ast_command *command, t_state *state, t_cmd_pipe cmd_pipe, t_command_result *out); t_error run_expansion(t_ast_expansion *self, t_state *state, t_expansion_result *out); t_error run_word(t_ast_word *word, t_state *state, t_word_result *out); @@ -97,7 +97,7 @@ t_error run_raw_string(t_ast_raw_string *raw_string, t_state *state, void *out); t_error run_regex(t_ast_regex *regex, t_state *state, void *out); t_error run_subshell(t_ast_subshell *subshell, t_state *state, void *out); t_error run_until(t_ast_until *until, t_state *state, void *out); -t_error run_variable_assignment(t_ast_variable_assignment *variable_assignment, t_state *state, void *out); +t_error run_variable_assignment(t_ast_variable_assignment *variable_assignment, t_state *state, bool is_temporary, void *out); t_error run_while_(t_ast_while *while_, t_state *state, void *out); #endif diff --git a/exec/src/run_ast.c b/exec/src/run_ast.c index 6e5769a5..4ce61a4d 100644 --- a/exec/src/run_ast.c +++ b/exec/src/run_ast.c @@ -6,13 +6,14 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/07/11 17:22:29 by maiboyer #+# #+# */ -/* Updated: 2024/08/02 19:04:30 by maiboyer ### ########.fr */ +/* Updated: 2024/08/02 23:17:47 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ #include "app/state.h" #include "ast/ast.h" #include "exec/_run_ast.h" +#include "app/env.h" #include "exec/run.h" #include "me/convert/numbers_to_str.h" #include "me/fs/fs.h" @@ -22,6 +23,7 @@ #include "me/str/str.h" #include "me/string/string.h" #include "me/types.h" +#include "me/vec/vec_ast.h" #include "me/vec/vec_estr.h" #include "me/vec/vec_str.h" @@ -77,7 +79,9 @@ t_error _get_expansion_value(t_ast_expansion *self, t_state *state, t_expansion_ if (self == NULL || state == NULL || out == NULL) return (ERROR); - hmap_ret = hmap_env_get(state->env, &self->var_name); + hmap_ret = hmap_env_get(state->tmp_var, &self->var_name); + if (hmap_ret == NULL) + hmap_ret = hmap_env_get(state->env, &self->var_name); ret = (t_expansion_result){.exists = hmap_ret == NULL, .value = NULL}; if (ret.exists) ret.value = str_clone(*hmap_ret); @@ -455,7 +459,6 @@ t_error _ast_into_str(t_ast_node self, t_state *state, t_vec_str *append) // End Internals funcs t_error run_expansion(t_ast_expansion *self, t_state *state, t_expansion_result *out); -t_error run_command(t_ast_command *command, t_state *state, t_command_result *out); t_error run_word(t_ast_word *word, t_state *state, t_word_result *out); t_error run_arithmetic_expansion(t_ast_arithmetic_expansion *arithmetic_expansion, t_state *state, t_i64 *out); @@ -479,7 +482,7 @@ t_error run_raw_string(t_ast_raw_string *raw_string, t_state *state, void *out) t_error run_regex(t_ast_regex *regex, t_state *state, void *out) NOT_DONE; t_error run_subshell(t_ast_subshell *subshell, t_state *state, void *out) NOT_DONE; t_error run_until(t_ast_until *until, t_state *state, void *out) NOT_DONE; -t_error run_variable_assignment(t_ast_variable_assignment *variable_assignment, t_state *state, void *out) NOT_DONE; +t_error run_variable_assignment(t_ast_variable_assignment *variable_assignment, t_state *state, bool is_temporary, void *out) NOT_DONE; t_error run_while_(t_ast_while *while_, t_state *state, void *out) NOT_DONE; // FUNCTIONS @@ -606,11 +609,23 @@ t_error _spawn_cmd_and_run(t_vec_str args, t_vec_ast redirection, t_state *state i++; } + redirection.len = 0; + vec_ast_free(redirection); vec_str_free(filename_args); + info.arguments = args; + //if (build_envp(state, info.arguments)); + if (args.len == 0) + { + vec_str_free(args); + return (ERROR); + } + //if (_is_builtin(args.buffer[0])) + // return (_handle_builtin(args, info)); + return (ERROR); } -t_error run_command(t_ast_command *command, t_state *state, t_command_result *out) +t_error run_command(t_ast_command *command, t_state *state, t_cmd_pipe cmd_pipe, t_command_result *out) { t_vec_str args; t_vec_str split; @@ -622,9 +637,6 @@ t_error run_command(t_ast_command *command, t_state *state, t_command_result *ou if (command == NULL || state == NULL || out == NULL) return (ERROR); - env_bck = state->env; - if (hmap_env_clone(env_bck, _clone_env, NULL, &state->env)) - return (state->env = env_bck, ERROR); args = vec_str_new(command->cmd_word.len, str_free); redirection = vec_ast_new(command->suffixes_redirections.len, ast_free); i = 0; @@ -635,7 +647,7 @@ t_error run_command(t_ast_command *command, t_state *state, t_command_result *ou vec_ast_push(&redirection, tmp); if (tmp->kind == AST_VARIABLE_ASSIGNMENT) { - if (run_variable_assignment(&tmp->data.variable_assignment, state, NULL)) + if (run_variable_assignment(&tmp->data.variable_assignment, state, true, NULL)) return (ERROR); } i++; @@ -655,7 +667,7 @@ t_error run_command(t_ast_command *command, t_state *state, t_command_result *ou i++; } i = 0; - if (_spawn_cmd_and_run(args, redirection, state, (t_cmd_pipe){0, 0}, out)) + if (_spawn_cmd_and_run(args, redirection, state, cmd_pipe, out)) return (ERROR); return (NO_ERROR); } diff --git a/includes/app/env.h b/includes/app/env.h index ffb4fabb..5ef4902f 100644 --- a/includes/app/env.h +++ b/includes/app/env.h @@ -6,7 +6,7 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/05/04 18:41:01 by maiboyer #+# #+# */ -/* Updated: 2024/05/09 14:28:42 by rparodi ### ########.fr */ +/* Updated: 2024/08/02 22:11:14 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,14 +18,17 @@ # include "me/types.h" # include "me/vec/vec_str.h" + t_hashmap_env *create_env_map(void); -t_error build_envp(t_hashmap_env *envs, t_vec_str *out); +t_error build_envp(t_hashmap_env *envs, t_hashmap_env *tmp_vars, \ + t_vec_str *out); struct s_build_envp_state { - t_vec_str out; - t_string buf; + t_hashmap_env *tmp_vars; + t_vec_str out; + t_string buf; }; #endif /* ENV_H */ diff --git a/includes/app/state.h b/includes/app/state.h index c15e2736..5a95a90e 100644 --- a/includes/app/state.h +++ b/includes/app/state.h @@ -6,7 +6,7 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/05/02 15:49:56 by maiboyer #+# #+# */ -/* Updated: 2024/07/20 13:45:21 by maiboyer ### ########.fr */ +/* Updated: 2024/08/02 22:26:20 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,12 +18,16 @@ # include "me/os/os.h" # include "me/types.h" -typedef struct s_parser +typedef struct s_state t_state; +typedef struct s_parser t_parser; + +struct s_parser { t_first_parser *parser; -} t_parser; +}; -typedef struct s_state + +struct s_state { t_str prompt; t_str str_input; @@ -31,8 +35,9 @@ typedef struct s_state t_str *path; t_parser parser; t_hashmap_env *env; + t_hashmap_env *tmp_var; t_node current_node; t_process ret; -} t_state; +}; #endif /* STATE_H */ diff --git a/input.toml b/input.toml index 634a2d7c..7fce45eb 100644 --- a/input.toml +++ b/input.toml @@ -18,6 +18,7 @@ sources = [ "stdme/generic_sources/src/hashmap/C__PREFIX___utils.c__TEMPLATE__", "stdme/generic_sources/src/hashmap/C__PREFIX___iter.c__TEMPLATE__", "stdme/generic_sources/src/hashmap/C__PREFIX___clone.c__TEMPLATE__", + "stdme/generic_sources/src/hashmap/C__PREFIX___clear.c__TEMPLATE__", ] replace.C__VALTYPE__ = "type" replace.C__KEYTYPE__ = "type" diff --git a/output/include/me/hashmap/hashmap_env.h b/output/include/me/hashmap/hashmap_env.h index 0be349c7..b36c130e 100644 --- a/output/include/me/hashmap/hashmap_env.h +++ b/output/include/me/hashmap/hashmap_env.h @@ -35,7 +35,7 @@ typedef struct s_kv_env /// @typedef A function that hashes a key typedef void (*t_hash_env_fn)(t_hasher *hasher, t_str *key); /// @typedef A function that drops a key-value pair -typedef void (*t_drop_env_fn)(t_kv_env val); +typedef void (*t_free_env_fn)(t_kv_env val); /// @typedef A function that compares two keys and returns true if they are equal typedef bool (*t_eq_env_fn)(t_str *lhs, t_str *rhs); @@ -57,7 +57,7 @@ typedef struct s_entry_env /// @var hasher The hasher function /// @var hfunc The hash function /// @var cfunc The comparison function -/// @var drop The drop function +/// @var free The free function typedef struct s_hashmap_env { t_entry_env **buckets; @@ -65,28 +65,32 @@ typedef struct s_hashmap_env t_hasher hasher; t_hash_env_fn hfunc; t_eq_env_fn cfunc; - t_drop_env_fn drop; + t_free_env_fn free; } t_hashmap_env; -/// @brief Creates a new hashmap with the given hash, comparison, and drop functions +/// @brief Creates a new hashmap with the given hash, comparison, and free functions /// @param hash The hash function /// @param cmp The comparison function -/// @param drop The drop function +/// @param free The free function /// @return A new hashmap -t_hashmap_env *hmap_env_new(t_hash_env_fn hash, t_eq_env_fn cmp, t_drop_env_fn drop); +t_hashmap_env *hmap_env_new(t_hash_env_fn hash, t_eq_env_fn cmp, t_free_env_fn free); -/// @brief Creates a new hashmap with the given hash, comparison, and drop functions +/// @brief Creates a new hashmap with the given hash, comparison, and free functions /// @param hash The hash function /// @param cmp The comparison function -/// @param drop The drop function +/// @param free The free function /// @param cap The number of buckets /// @return A new hashmap -t_hashmap_env *hmap_env_new_with_buckets(t_hash_env_fn hash, t_eq_env_fn cmp, t_drop_env_fn drop, size_t cap); +t_hashmap_env *hmap_env_new_with_buckets(t_hash_env_fn hash, t_eq_env_fn cmp, t_free_env_fn free, size_t cap); /// @brief Free the hashmap and all of its entries /// @param hmap The hashmap to free void hmap_env_free(t_hashmap_env *hmap); +/// @brief Clear the hashmap, removing all of its entries +/// @param hmap The hashmap to clear +void hmap_env_clear(t_hashmap_env *hmap); + /// @brief Inserts a key-value pair into the hashmap /// @param hmap The hashmap /// @param key The key diff --git a/output/src/hashmap/env/env.c b/output/src/hashmap/env/env.c index 96e2c227..3e3ccc93 100644 --- a/output/src/hashmap/env/env.c +++ b/output/src/hashmap/env/env.c @@ -19,15 +19,15 @@ t_hashmap_env *hmap_env_new(t_hash_env_fn hfunc, t_eq_env_fn cfunc, - t_drop_env_fn drop) + t_free_env_fn free) { return ( - hmap_env_new_with_buckets(hfunc, cfunc, drop, DEFAULT_BUCKETS)); + hmap_env_new_with_buckets(hfunc, cfunc, free, DEFAULT_BUCKETS)); } t_hashmap_env *hmap_env_new_with_buckets( t_hash_env_fn hfunc, t_eq_env_fn cfunc, - t_drop_env_fn drop, t_usize buckets) + t_free_env_fn free, t_usize buckets) { t_hashmap_env *hmap; @@ -39,7 +39,7 @@ t_hashmap_env *hmap_env_new_with_buckets( hmap->hasher = hasher_sip13_new(); hmap->hfunc = hfunc; hmap->cfunc = cfunc; - hmap->drop = drop; + hmap->free = free; if (hmap->buckets == NULL) return ((void)mem_free(hmap), NULL); return (hmap); @@ -57,7 +57,7 @@ void hmap_env_free(t_hashmap_env *hmap) entry = hmap->buckets[index]; while (entry != NULL) { - hmap->drop(entry->kv); + hmap->free(entry->kv); tmp = entry->next; mem_free(entry); entry = tmp; @@ -117,7 +117,7 @@ bool hmap_env_insert(t_hashmap_env *hmap, t_str key, } else { - hmap->drop(entry->kv); + hmap->free(entry->kv); entry->kv.key = key; entry->kv.val = value; return (true); diff --git a/output/src/hashmap/env/env_clear.c b/output/src/hashmap/env/env_clear.c new file mode 100644 index 00000000..6da7c16d --- /dev/null +++ b/output/src/hashmap/env/env_clear.c @@ -0,0 +1,40 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* hashmap_env.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: maiboyer +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/12/06 11:00:22 by maiboyer #+# #+# */ +/* Updated: 2023/12/11 15:24:44 by maiboyer ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "me/types.h" + + + +#include "me/hashmap/hashmap_env.h" +#include "me/mem/mem.h" + + +void hmap_env_clear(t_hashmap_env *self) +{ + t_usize bucket_id; + t_entry_env *cur; + t_entry_env *next; + + bucket_id = 0; + while (bucket_id < self->num_buckets) + { + cur = self->buckets[bucket_id]; + while (cur != NULL) + { + next = cur->next; + self->free(cur->kv); + mem_free(cur); + cur = next; + } + bucket_id++; + } +} diff --git a/output/src/hashmap/env/env_clone.c b/output/src/hashmap/env/env_clone.c index e41dfb55..08898d7d 100644 --- a/output/src/hashmap/env/env_clone.c +++ b/output/src/hashmap/env/env_clone.c @@ -27,7 +27,7 @@ t_error hmap_env_clone(t_hashmap_env *self, t_hashmap_env *ret; bucket_id = 0; - ret = hmap_env_new_with_buckets(self->hfunc, self->cfunc, self->drop, self->num_buckets); + ret = hmap_env_new_with_buckets(self->hfunc, self->cfunc, self->free, self->num_buckets); if (ret == NULL) return (ERROR); while (bucket_id < self->num_buckets) diff --git a/output/src/hashmap/env/env_utils.c b/output/src/hashmap/env/env_utils.c index b02bf13e..4e2e99cd 100644 --- a/output/src/hashmap/env/env_utils.c +++ b/output/src/hashmap/env/env_utils.c @@ -48,7 +48,7 @@ void hmap_env_remove(t_hashmap_env *hmap, t_str *key) hmap->buckets[hashed_key % hmap->num_buckets] = entry->next; else prev->next = entry->next; - hmap->drop(entry->kv); + hmap->free(entry->kv); mem_free(entry); hmap->buckets[hashed_key % hmap->num_buckets] = NULL; } diff --git a/sources/env.c b/sources/env.c index 67ce19cc..6375a256 100644 --- a/sources/env.c +++ b/sources/env.c @@ -6,7 +6,7 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/05/04 18:32:50 by maiboyer #+# #+# */ -/* Updated: 2024/08/02 12:09:05 by rparodi ### ########.fr */ +/* Updated: 2024/08/02 22:37:23 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ @@ -68,10 +68,11 @@ t_error _build_envp_iterator(t_usize idx, const t_str *key, t_str *val, return (NO_ERROR); } -t_error build_envp(t_hashmap_env *envs, t_vec_str *envp) +t_error build_envp(t_hashmap_env *envs, t_hashmap_env *tmp_vars, t_vec_str *envp) { struct s_build_envp_state state; + state.tmp_vars = tmp_vars; state.buf = string_new(8096); state.out = vec_str_new(1024, (void (*)(t_str))mem_free); if (hmap_env_iter(envs, _build_envp_iterator, &state)) diff --git a/sources/main.c b/sources/main.c index 6906f10c..2fe93f1d 100644 --- a/sources/main.c +++ b/sources/main.c @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/28 14:40:38 by rparodi #+# #+# */ -/* Updated: 2024/08/02 12:16:09 by rparodi ### ########.fr */ +/* Updated: 2024/08/02 23:00:50 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ @@ -184,6 +184,7 @@ t_i32 main(t_i32 argc, t_str argv[], t_str envp[]) (void)argc; (void)argv; (void)envp; + me_abort("abort"); if (install_signal()) me_abort("Unable to install signals"); state = (t_state){}; diff --git a/stdme/generic_sources/header/hashmap_C__PREFIX__.h__TEMPLATE__ b/stdme/generic_sources/header/hashmap_C__PREFIX__.h__TEMPLATE__ index 9c4a932b..4ccdcd90 100644 --- a/stdme/generic_sources/header/hashmap_C__PREFIX__.h__TEMPLATE__ +++ b/stdme/generic_sources/header/hashmap_C__PREFIX__.h__TEMPLATE__ @@ -35,7 +35,7 @@ typedef struct s_kv_C__PREFIX__ /// @typedef A function that hashes a key typedef void (*t_hash_C__PREFIX___fn)(t_hasher *hasher, C__KEYTYPE__ *key); /// @typedef A function that drops a key-value pair -typedef void (*t_drop_C__PREFIX___fn)(t_kv_C__PREFIX__ val); +typedef void (*t_free_C__PREFIX___fn)(t_kv_C__PREFIX__ val); /// @typedef A function that compares two keys and returns true if they are equal typedef bool (*t_eq_C__PREFIX___fn)(C__KEYTYPE__ *lhs, C__KEYTYPE__ *rhs); @@ -57,7 +57,7 @@ typedef struct s_entry_C__PREFIX__ /// @var hasher The hasher function /// @var hfunc The hash function /// @var cfunc The comparison function -/// @var drop The drop function +/// @var free The free function typedef struct s_hashmap_C__PREFIX__ { t_entry_C__PREFIX__ **buckets; @@ -65,28 +65,32 @@ typedef struct s_hashmap_C__PREFIX__ t_hasher hasher; t_hash_C__PREFIX___fn hfunc; t_eq_C__PREFIX___fn cfunc; - t_drop_C__PREFIX___fn drop; + t_free_C__PREFIX___fn free; } t_hashmap_C__PREFIX__; -/// @brief Creates a new hashmap with the given hash, comparison, and drop functions +/// @brief Creates a new hashmap with the given hash, comparison, and free functions /// @param hash The hash function /// @param cmp The comparison function -/// @param drop The drop function +/// @param free The free function /// @return A new hashmap -t_hashmap_C__PREFIX__ *hmap_C__PREFIX___new(t_hash_C__PREFIX___fn hash, t_eq_C__PREFIX___fn cmp, t_drop_C__PREFIX___fn drop); +t_hashmap_C__PREFIX__ *hmap_C__PREFIX___new(t_hash_C__PREFIX___fn hash, t_eq_C__PREFIX___fn cmp, t_free_C__PREFIX___fn free); -/// @brief Creates a new hashmap with the given hash, comparison, and drop functions +/// @brief Creates a new hashmap with the given hash, comparison, and free functions /// @param hash The hash function /// @param cmp The comparison function -/// @param drop The drop function +/// @param free The free function /// @param cap The number of buckets /// @return A new hashmap -t_hashmap_C__PREFIX__ *hmap_C__PREFIX___new_with_buckets(t_hash_C__PREFIX___fn hash, t_eq_C__PREFIX___fn cmp, t_drop_C__PREFIX___fn drop, size_t cap); +t_hashmap_C__PREFIX__ *hmap_C__PREFIX___new_with_buckets(t_hash_C__PREFIX___fn hash, t_eq_C__PREFIX___fn cmp, t_free_C__PREFIX___fn free, size_t cap); /// @brief Free the hashmap and all of its entries /// @param hmap The hashmap to free void hmap_C__PREFIX___free(t_hashmap_C__PREFIX__ *hmap); +/// @brief Clear the hashmap, removing all of its entries +/// @param hmap The hashmap to clear +void hmap_C__PREFIX___clear(t_hashmap_C__PREFIX__ *hmap); + /// @brief Inserts a key-value pair into the hashmap /// @param hmap The hashmap /// @param key The key diff --git a/stdme/generic_sources/src/hashmap/C__PREFIX__.c__TEMPLATE__ b/stdme/generic_sources/src/hashmap/C__PREFIX__.c__TEMPLATE__ index c84aeca3..ffe04ab7 100644 --- a/stdme/generic_sources/src/hashmap/C__PREFIX__.c__TEMPLATE__ +++ b/stdme/generic_sources/src/hashmap/C__PREFIX__.c__TEMPLATE__ @@ -19,15 +19,15 @@ t_hashmap_C__PREFIX__ *hmap_C__PREFIX___new(t_hash_C__PREFIX___fn hfunc, t_eq_C__PREFIX___fn cfunc, - t_drop_C__PREFIX___fn drop) + t_free_C__PREFIX___fn free) { return ( - hmap_C__PREFIX___new_with_buckets(hfunc, cfunc, drop, DEFAULT_BUCKETS)); + hmap_C__PREFIX___new_with_buckets(hfunc, cfunc, free, DEFAULT_BUCKETS)); } t_hashmap_C__PREFIX__ *hmap_C__PREFIX___new_with_buckets( t_hash_C__PREFIX___fn hfunc, t_eq_C__PREFIX___fn cfunc, - t_drop_C__PREFIX___fn drop, t_usize buckets) + t_free_C__PREFIX___fn free, t_usize buckets) { t_hashmap_C__PREFIX__ *hmap; @@ -39,7 +39,7 @@ t_hashmap_C__PREFIX__ *hmap_C__PREFIX___new_with_buckets( hmap->hasher = hasher_sip13_new(); hmap->hfunc = hfunc; hmap->cfunc = cfunc; - hmap->drop = drop; + hmap->free = free; if (hmap->buckets == NULL) return ((void)mem_free(hmap), NULL); return (hmap); @@ -57,7 +57,7 @@ void hmap_C__PREFIX___free(t_hashmap_C__PREFIX__ *hmap) entry = hmap->buckets[index]; while (entry != NULL) { - hmap->drop(entry->kv); + hmap->free(entry->kv); tmp = entry->next; mem_free(entry); entry = tmp; @@ -117,7 +117,7 @@ bool hmap_C__PREFIX___insert(t_hashmap_C__PREFIX__ *hmap, C__KEYTYPE__ key, } else { - hmap->drop(entry->kv); + hmap->free(entry->kv); entry->kv.key = key; entry->kv.val = value; return (true); diff --git a/stdme/generic_sources/src/hashmap/C__PREFIX___clear.c__TEMPLATE__ b/stdme/generic_sources/src/hashmap/C__PREFIX___clear.c__TEMPLATE__ new file mode 100644 index 00000000..28327bf9 --- /dev/null +++ b/stdme/generic_sources/src/hashmap/C__PREFIX___clear.c__TEMPLATE__ @@ -0,0 +1,40 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* hashmap_C__PREFIX__.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: maiboyer +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/12/06 11:00:22 by maiboyer #+# #+# */ +/* Updated: 2023/12/11 15:24:44 by maiboyer ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "me/types.h" + + + +#include "me/hashmap/hashmap_C__PREFIX__.h" +#include "me/mem/mem.h" + + +void hmap_C__PREFIX___clear(t_hashmap_C__PREFIX__ *self) +{ + t_usize bucket_id; + t_entry_C__PREFIX__ *cur; + t_entry_C__PREFIX__ *next; + + bucket_id = 0; + while (bucket_id < self->num_buckets) + { + cur = self->buckets[bucket_id]; + while (cur != NULL) + { + next = cur->next; + self->free(cur->kv); + mem_free(cur); + cur = next; + } + bucket_id++; + } +} diff --git a/stdme/generic_sources/src/hashmap/C__PREFIX___clone.c__TEMPLATE__ b/stdme/generic_sources/src/hashmap/C__PREFIX___clone.c__TEMPLATE__ index 72a54285..b80db4b0 100644 --- a/stdme/generic_sources/src/hashmap/C__PREFIX___clone.c__TEMPLATE__ +++ b/stdme/generic_sources/src/hashmap/C__PREFIX___clone.c__TEMPLATE__ @@ -27,7 +27,7 @@ t_error hmap_C__PREFIX___clone(t_hashmap_C__PREFIX__ *self, t_hashmap_C__PREFIX__ *ret; bucket_id = 0; - ret = hmap_C__PREFIX___new_with_buckets(self->hfunc, self->cfunc, self->drop, self->num_buckets); + ret = hmap_C__PREFIX___new_with_buckets(self->hfunc, self->cfunc, self->free, self->num_buckets); if (ret == NULL) return (ERROR); while (bucket_id < self->num_buckets) diff --git a/stdme/generic_sources/src/hashmap/C__PREFIX___utils.c__TEMPLATE__ b/stdme/generic_sources/src/hashmap/C__PREFIX___utils.c__TEMPLATE__ index ca6ace48..7235ceb0 100644 --- a/stdme/generic_sources/src/hashmap/C__PREFIX___utils.c__TEMPLATE__ +++ b/stdme/generic_sources/src/hashmap/C__PREFIX___utils.c__TEMPLATE__ @@ -48,7 +48,7 @@ void hmap_C__PREFIX___remove(t_hashmap_C__PREFIX__ *hmap, C__KEYTYPE__ *key) hmap->buckets[hashed_key % hmap->num_buckets] = entry->next; else prev->next = entry->next; - hmap->drop(entry->kv); + hmap->free(entry->kv); mem_free(entry); hmap->buckets[hashed_key % hmap->num_buckets] = NULL; } diff --git a/stdme/src/os/process_iterator_function.c b/stdme/src/os/process_iterator_function.c index b40d07ba..40652f9f 100644 --- a/stdme/src/os/process_iterator_function.c +++ b/stdme/src/os/process_iterator_function.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* process_inner.c :+: :+: :+: */ +/* process_iterator_function.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/01/04 22:25:44 by maiboyer #+# #+# */ -/* Updated: 2024/08/01 06:37:51 by maiboyer ### ########.fr */ +/* Updated: 2024/08/02 20:26:13 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,12 +14,12 @@ #include #include -bool find_null(const t_str *s) +bool _find_null(const t_str *s) { return (s == NULL); } -bool find_path(const t_str *s) +bool _find_path(const t_str *s) { t_str ss;