From 1d7112f9829733f39ec892f4bdfd996a9463cabe Mon Sep 17 00:00:00 2001 From: Maix0 Date: Sat, 18 May 2024 16:42:03 +0200 Subject: [PATCH] update --- allocator/src/me_alloc/functions1.c | 4 +-- output/src/hashmap/env/env.c | 7 ++-- output/src/hashmap/env/env_utils.c | 4 +-- .../src/vec/parser_heredoc/parser_heredoc.c | 11 +----- output/src/vec/parser_range/parser_range.c | 11 +----- output/src/vec/reduce_action/reduce_action.c | 11 +----- output/src/vec/str/str.c | 11 +----- sources/exec/handle_command.c | 35 +++++++++++-------- sources/main.c | 22 ++++++------ sources/node/node.c | 2 +- .../src/hashmap/C__PREFIX__.c__TEMPLATE__ | 3 +- .../hashmap/C__PREFIX___utils.c__TEMPLATE__ | 3 +- .../src/vec/C__PREFIX__.c__TEMPLATE__ | 11 +----- stdme/src/string/str_clone.c | 10 +++--- 14 files changed, 54 insertions(+), 91 deletions(-) diff --git a/allocator/src/me_alloc/functions1.c b/allocator/src/me_alloc/functions1.c index c765f705..8af7c0f5 100644 --- a/allocator/src/me_alloc/functions1.c +++ b/allocator/src/me_alloc/functions1.c @@ -6,7 +6,7 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/05/14 18:02:12 by maiboyer #+# #+# */ -/* Updated: 2024/05/17 15:21:57 by maiboyer ### ########.fr */ +/* Updated: 2024/05/18 16:36:55 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ @@ -294,7 +294,7 @@ void *m_realloc(struct s_allocator_melloc *self, void *ptr, t_usize size) old_size = chunk->size; chunk->size += next->size + sizeof(*next); vg_mem_defined(next, next->size + sizeof(*next)); - mem_set_zero(next, next->size + sizeof(*next)); + //mem_set_zero(next, next->size + sizeof(*next)); vg_block_resize((void *)chunk + sizeof(*chunk), old_size, chunk->size); vg_mem_no_access(chunk, sizeof(*chunk)); diff --git a/output/src/hashmap/env/env.c b/output/src/hashmap/env/env.c index a01165c1..a5a4a3d1 100644 --- a/output/src/hashmap/env/env.c +++ b/output/src/hashmap/env/env.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* env.c :+: :+: :+: */ +/* hashmap_env.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/12/06 10:58:20 by maiboyer #+# #+# */ -/* Updated: 2024/05/14 18:46:51 by maiboyer ### ########.fr */ +/* Updated: 2023/12/11 15:32:51 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,6 +14,7 @@ #include "me/hash/sip.h" #include "me/hashmap/hashmap_env.h" #include "me/mem/mem.h" +#include "me/mem/mem_copy.h" #include "me/types.h" #include @@ -80,7 +81,9 @@ t_entry_env *hashmap_get_entry_env(t_hashmap_env *hmap, entry = entry->next; } else + { return (entry); + } } return (NULL); } diff --git a/output/src/hashmap/env/env_utils.c b/output/src/hashmap/env/env_utils.c index 51060b63..a388fd4b 100644 --- a/output/src/hashmap/env/env_utils.c +++ b/output/src/hashmap/env/env_utils.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* env_utils.c :+: :+: :+: */ +/* hashmap_env_utils.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/12/06 10:58:20 by maiboyer #+# #+# */ -/* Updated: 2024/05/14 18:47:08 by maiboyer ### ########.fr */ +/* Updated: 2023/12/11 15:35:37 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/output/src/vec/parser_heredoc/parser_heredoc.c b/output/src/vec/parser_heredoc/parser_heredoc.c index cb6a69ff..b3eb5831 100644 --- a/output/src/vec/parser_heredoc/parser_heredoc.c +++ b/output/src/vec/parser_heredoc/parser_heredoc.c @@ -34,18 +34,9 @@ t_vec_parser_heredoc vec_parser_heredoc_new(t_usize capacity, /// Return true in case of an error t_error vec_parser_heredoc_push(t_vec_parser_heredoc *vec, t_heredoc element) { - size_t new_capacity; - if (vec == NULL) return (ERROR); - if (vec->len + 1 > vec->capacity) - { - new_capacity = (vec->capacity * 3) / 2 + 1; - while (vec->len + 1 > 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; - } + vec_parser_heredoc_reserve(vec, vec->len + 1); vec->buffer[vec->len] = element; vec->len += 1; return (NO_ERROR); diff --git a/output/src/vec/parser_range/parser_range.c b/output/src/vec/parser_range/parser_range.c index f75cfc7b..b333182b 100644 --- a/output/src/vec/parser_range/parser_range.c +++ b/output/src/vec/parser_range/parser_range.c @@ -34,18 +34,9 @@ t_vec_parser_range vec_parser_range_new(t_usize capacity, /// Return true in case of an error t_error vec_parser_range_push(t_vec_parser_range *vec, t_parser_range element) { - size_t new_capacity; - if (vec == NULL) return (ERROR); - if (vec->len + 1 > vec->capacity) - { - new_capacity = (vec->capacity * 3) / 2 + 1; - while (vec->len + 1 > 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; - } + vec_parser_range_reserve(vec, vec->len + 1); vec->buffer[vec->len] = element; vec->len += 1; return (NO_ERROR); diff --git a/output/src/vec/reduce_action/reduce_action.c b/output/src/vec/reduce_action/reduce_action.c index 4b170aba..e2de73c4 100644 --- a/output/src/vec/reduce_action/reduce_action.c +++ b/output/src/vec/reduce_action/reduce_action.c @@ -34,18 +34,9 @@ t_vec_reduce_action vec_reduce_action_new(t_usize capacity, /// Return true in case of an error t_error vec_reduce_action_push(t_vec_reduce_action *vec, t_reduce_action element) { - size_t new_capacity; - if (vec == NULL) return (ERROR); - if (vec->len + 1 > vec->capacity) - { - new_capacity = (vec->capacity * 3) / 2 + 1; - while (vec->len + 1 > 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; - } + vec_reduce_action_reserve(vec, vec->len + 1); vec->buffer[vec->len] = element; vec->len += 1; return (NO_ERROR); diff --git a/output/src/vec/str/str.c b/output/src/vec/str/str.c index 18070e48..048f64c8 100644 --- a/output/src/vec/str/str.c +++ b/output/src/vec/str/str.c @@ -34,18 +34,9 @@ t_vec_str vec_str_new(t_usize capacity, /// Return true in case of an error t_error vec_str_push(t_vec_str *vec, t_str element) { - size_t new_capacity; - if (vec == NULL) return (ERROR); - if (vec->len + 1 > vec->capacity) - { - new_capacity = (vec->capacity * 3) / 2 + 1; - while (vec->len + 1 > new_capacity) - new_capacity = (new_capacity * 3) / 2 + 1; - vec->buffer = mem_realloc_array(vec->buffer, new_capacity, sizeof(t_str)); - vec->capacity = new_capacity; - } + vec_str_reserve(vec, vec->len + 1); vec->buffer[vec->len] = element; vec->len += 1; return (NO_ERROR); diff --git a/sources/exec/handle_command.c b/sources/exec/handle_command.c index bfe4c7fd..d403b00f 100644 --- a/sources/exec/handle_command.c +++ b/sources/exec/handle_command.c @@ -6,56 +6,63 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/05/09 15:00:53 by rparodi #+# #+# */ -/* Updated: 2024/05/18 14:32:02 by rparodi ### ########.fr */ +/* Updated: 2024/05/18 16:41:54 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ #include "app/env.h" -#include "app/state.h" -#include "me/types.h" -#include "gmr/symbols.h" #include "app/node.h" +#include "app/state.h" +#include "gmr/symbols.h" +#include "me/types.h" #include "me/vec/vec_str.h" // #include "app/node/handle_program.h" #include "app/node/handle_command.h" -#include "minishell.h" #include "me/string/str_clone.h" +#include "minishell.h" #include t_error handle_command(t_node *self, t_utils *shcat, t_i32 *out_exit_code) { - t_usize i; + t_usize i; t_spawn_info spawn_info; - t_str tmp; + t_str tmp; - spawn_info.arguments = vec_str_new(self->childs_count, (void (*)(t_str))mem_free); + spawn_info.arguments = vec_str_new(64, (void (*)(t_str))mem_free); // TODO: FIX VECTOR if (self->kind != sym_command) - return (ERROR); + 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 { - printf("%s %s\n", self->childs[i].kind_str, node_getstr(&self->childs[i])); + printf("arg %s %s\n", self->childs[i].kind_str, + node_getstr(&self->childs[i])); if (handle_node_getstr(&self->childs[i], shcat, &tmp)) return (vec_str_free(spawn_info.arguments), ERROR); - if (vec_str_push(&spawn_info.arguments, tmp)) + if (vec_str_push(&spawn_info.arguments, str_clone(tmp))) return (ERROR); - } + } i++; } - vec_str_push_front(&spawn_info.arguments, str_clone(spawn_info.binary_path)); + printf("%zu\n", spawn_info.arguments.len); vec_str_push(&spawn_info.arguments, NULL); + for (i = 0; i < spawn_info.arguments.len; i++) + printf("[%zu]\t%s\n", i, spawn_info.arguments.buffer[i]); spawn_info.stdin = inherited(); spawn_info.stdout = inherited(); spawn_info.stderr = inherited(); - spawn_info.forked_free = NULL; + spawn_info.forked_free = NULL; if (build_envp(shcat->env, &spawn_info.environement)) return (vec_str_free(spawn_info.arguments), ERROR); if (spawn_process(spawn_info, &shcat->ret)) diff --git a/sources/main.c b/sources/main.c index 4cf23696..aeb8e97b 100644 --- a/sources/main.c +++ b/sources/main.c @@ -6,12 +6,13 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/28 14:40:38 by rparodi #+# #+# */ -/* Updated: 2024/05/08 19:22:47 by maiboyer ### ########.fr */ +/* Updated: 2024/05/18 16:15:44 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ #include "app/env.h" #include "app/node.h" +#include "app/node/handle_concat.h" #include "app/node/handle_program.h" #include "app/signal_handler.h" #include "gmr/symbols.h" @@ -19,7 +20,6 @@ #include "me/string/str_len.h" #include "minishell.h" #include "parser/api.h" -#include "app/node/handle_concat.h" #include #undef free @@ -35,19 +35,19 @@ t_first_tree *ts_parser_parse_string(t_first_parser *, t_first_tree *oldtree, void ts_parser_delete(t_first_parser *self); void ts_parser_set_language(t_first_parser *self, t_language *lang); - t_error handle_node_getstr(t_node *self, t_utils *shcat, t_str *out) { - switch (self->kind) + *out = NULL; + if (self->kind == sym_word) { - case sym_word: - *out = node_getstr(self); - return (NO_ERROR); - case sym_concatenation: - return (handle_concat(self, shcat, out)); - default: - return (ERROR); + printf("word!!!\n"); + *out = node_getstr(self); + return (NO_ERROR); } + if (self->kind == sym_concatenation) + return (handle_concat(self, shcat, out)); + + return (ERROR); } void print_node_data(t_node *t, t_usize depth) diff --git a/sources/node/node.c b/sources/node/node.c index 221a527d..96251183 100644 --- a/sources/node/node.c +++ b/sources/node/node.c @@ -6,7 +6,7 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/04/28 18:36:40 by maiboyer #+# #+# */ -/* Updated: 2024/05/08 18:35:15 by maiboyer ### ########.fr */ +/* Updated: 2024/05/18 16:14:55 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/stdme/generic_sources/src/hashmap/C__PREFIX__.c__TEMPLATE__ b/stdme/generic_sources/src/hashmap/C__PREFIX__.c__TEMPLATE__ index 242103f4..0875b550 100644 --- a/stdme/generic_sources/src/hashmap/C__PREFIX__.c__TEMPLATE__ +++ b/stdme/generic_sources/src/hashmap/C__PREFIX__.c__TEMPLATE__ @@ -13,8 +13,7 @@ #include "me/hash/hasher.h" #include "me/hash/sip.h" #include "me/hashmap/hashmap_C__PREFIX__.h" -#include "me/mem/mem_alloc.h" -#include "me/mem/mem_alloc_array.h" +#include "me/mem/mem.h" #include "me/mem/mem_copy.h" #include "me/types.h" #include 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 43ccc8ce..33dbefbe 100644 --- a/stdme/generic_sources/src/hashmap/C__PREFIX___utils.c__TEMPLATE__ +++ b/stdme/generic_sources/src/hashmap/C__PREFIX___utils.c__TEMPLATE__ @@ -12,8 +12,7 @@ #include "me/hash/sip.h" #include "me/hashmap/hashmap_C__PREFIX__.h" -#include "me/mem/mem_alloc.h" -#include "me/mem/mem_alloc_array.h" +#include "me/mem/mem.h" #include "me/mem/mem_copy.h" #include "me/types.h" #include diff --git a/stdme/generic_sources/src/vec/C__PREFIX__.c__TEMPLATE__ b/stdme/generic_sources/src/vec/C__PREFIX__.c__TEMPLATE__ index 4696c27c..364225d7 100644 --- a/stdme/generic_sources/src/vec/C__PREFIX__.c__TEMPLATE__ +++ b/stdme/generic_sources/src/vec/C__PREFIX__.c__TEMPLATE__ @@ -34,18 +34,9 @@ t_vec_C__PREFIX__ vec_C__PREFIX___new(t_usize capacity, /// Return true in case of an error t_error vec_C__PREFIX___push(t_vec_C__PREFIX__ *vec, C__TYPENAME__ element) { - size_t new_capacity; - if (vec == NULL) return (ERROR); - if (vec->len + 1 > vec->capacity) - { - new_capacity = (vec->capacity * 3) / 2 + 1; - while (vec->len + 1 > new_capacity) - new_capacity = (new_capacity * 3) / 2 + 1; - vec->buffer = mem_realloc_array(vec->buffer, new_capacity, sizeof(C__TYPENAME__)); - vec->capacity = new_capacity; - } + vec_C__PREFIX___reserve(vec, vec->len + 1); vec->buffer[vec->len] = element; vec->len += 1; return (NO_ERROR); diff --git a/stdme/src/string/str_clone.c b/stdme/src/string/str_clone.c index 70fd9428..731c6185 100644 --- a/stdme/src/string/str_clone.c +++ b/stdme/src/string/str_clone.c @@ -6,23 +6,23 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/11/06 16:05:48 by maiboyer #+# #+# */ -/* Updated: 2023/12/09 18:15:57 by maiboyer ### ########.fr */ +/* Updated: 2024/05/18 16:34:33 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ -#include "me/mem/mem_alloc.h" #include "me/string/str_clone.h" +#include "me/mem/mem.h" #include "me/string/str_l_copy.h" #include "me/string/str_len.h" #include -t_str str_clone(t_const_str source) +t_str str_clone(t_const_str source) { t_str res; - t_usize len; + t_usize len; len = str_len(source) + 1; - res = mem_alloc(sizeof(unsigned char) * len); + res = mem_alloc_array(sizeof(*res), len); if (res == NULL) return (NULL); str_l_copy(res, source, len);