diff --git a/Makefile b/Makefile index fcea30c4..89fd3425 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ # By: rparodi +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2023/11/12 11:05:05 by rparodi #+# #+# # -# Updated: 2024/08/04 14:28:29 by maiboyer ### ########.fr # +# Updated: 2024/08/05 14:52:59 by maiboyer ### ########.fr # # # # **************************************************************************** # diff --git a/exec/include/exec/_tuple_expanded_str.h b/exec/include/exec/_tuple_expanded_str.h index c415ba4a..6905e68a 100644 --- a/exec/include/exec/_tuple_expanded_str.h +++ b/exec/include/exec/_tuple_expanded_str.h @@ -6,7 +6,7 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/07/24 15:45:08 by maiboyer #+# #+# */ -/* Updated: 2024/07/24 16:02:04 by maiboyer ### ########.fr */ +/* Updated: 2024/08/05 15:13:17 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ @@ -24,7 +24,7 @@ struct s_expandable_str { static inline void free_expandable_str(t_expandable_str self) { - void mem_free(void *ptr); + void mem_free(void *str); mem_free(self.value); } diff --git a/exec/src/run_ast.c b/exec/src/run_ast.c index 547760db..e4adf1d2 100644 --- a/exec/src/run_ast.c +++ b/exec/src/run_ast.c @@ -6,7 +6,7 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/07/11 17:22:29 by maiboyer #+# #+# */ -/* Updated: 2024/08/03 16:20:04 by maiboyer ### ########.fr */ +/* Updated: 2024/08/05 15:29:40 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ @@ -196,7 +196,7 @@ t_error _ast_get_str__raw__no_quote(t_ast_node elem, t_word_iterator *state, t_v last_backslash = true; i++; } - return (vec_estr_push(out, (t_expandable_str){.do_expand = false, .value = str_clone(ret.buf)}), NO_ERROR); + return (vec_estr_push(out, (t_expandable_str){.do_expand = false, .value = ret.buf}), NO_ERROR); } t_error _ast_get_str__raw__single_quote(t_ast_node elem, t_word_iterator *state, t_vec_estr *out) @@ -211,7 +211,7 @@ t_error _ast_get_str__raw__single_quote(t_ast_node elem, t_word_iterator *state, while (elem->data.raw_string.str[i]) string_push_char(&ret, elem->data.raw_string.str[i++]); string_pop(&ret); - return (vec_estr_push(out, (t_expandable_str){.do_expand = false, .value = str_clone(ret.buf)}), NO_ERROR); + return (vec_estr_push(out, (t_expandable_str){.do_expand = false, .value = ret.buf}), NO_ERROR); } t_error _ast_get_str__raw__double_quote(t_ast_node elem, t_word_iterator *state, t_vec_estr *out) @@ -234,7 +234,7 @@ t_error _ast_get_str__raw__double_quote(t_ast_node elem, t_word_iterator *state, last_backslash = true; i++; } - return (vec_estr_push(out, (t_expandable_str){.do_expand = false, .value = str_clone(ret.buf)}), NO_ERROR); + return (vec_estr_push(out, (t_expandable_str){.do_expand = false, .value = ret.buf}), NO_ERROR); } t_error _ast_get_str__raw(t_ast_node elem, t_word_iterator *state, t_vec_estr *out) @@ -396,7 +396,7 @@ t_error _word_into_str(t_ast_node self, t_state *state, t_vec_str *append) { ifs = _get_ifs_value(state); if (str_split(res.value.buffer[i].value, ifs, &splitted)) - return (ERROR); + return (vec_estr_free(res.value), ERROR); if (!vec_str_pop_front(&splitted, &tmp_str)) { if (str_find_chr(ifs, res.value.buffer[i].value[0]) == NULL) @@ -414,7 +414,7 @@ t_error _word_into_str(t_ast_node self, t_state *state, t_vec_str *append) while (j + 1 < splitted.len) { if (vec_str_pop_front(&splitted, &tmp_str)) - return (ERROR); + return (vec_estr_free(res.value), ERROR); vec_str_push(append, tmp_str); j++; } @@ -438,6 +438,7 @@ t_error _word_into_str(t_ast_node self, t_state *state, t_vec_str *append) string_push(&tmp, res.value.buffer[i++].value); vec_str_push(append, tmp.buf); } + vec_estr_free(res.value); return (NO_ERROR); } @@ -484,9 +485,6 @@ 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, bool is_temporary, void *out) NOT_DONE; t_error run_while_(t_ast_while *while_, t_state *state, void *out) NOT_DONE; -/// TODO: remove this -void mem_free(void *ptr); - t_error run_program(t_ast_program *self, t_state *state, t_program_result *out) { t_usize i; diff --git a/sources/main.c b/sources/main.c index be4d0db2..8b4c1b83 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/04 16:39:16 by rparodi ### ########.fr */ +/* Updated: 2024/08/05 14:50:22 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ @@ -85,11 +85,11 @@ void print_node_data(t_node *t, t_usize depth) idx = 0; if (t->kind == 7) return; - printf("\x1b[%im[%-6s](%llu)\x1b[0m", t->field_str == NULL ? 90 : 32, t->field_str == NULL ? "nil" : t->field_str, t->field); + printf("\x1b[%im[%-6s](%lu)\x1b[0m", t->field_str == NULL ? 90 : 32, t->field_str == NULL ? "nil" : t->field_str, t->field); while (idx++ < depth + 1) printf("\t"); idx = 0; - printf("%s(%llu) = %s\n", t->kind_str, t->kind, node_getstr(t)); + printf("%s(%lu) = %s\n", t->kind_str, t->kind, node_getstr(t)); while (idx < t->childs_count) print_node_data(&t->childs[idx++], depth + 1); } @@ -103,7 +103,6 @@ t_node parse_str(t_state *state) tree = ts_parser_parse_string(state->parser, NULL, state->str_input, str_len(state->str_input)); node = ts_tree_root_node(tree); - printf("BUILDING AST\n"); if (ast_from_node(node, state->str_input, &out)) (state->ast = NULL, printf("Error when building node\n")); else @@ -115,13 +114,13 @@ t_node parse_str(t_state *state) void exec_shcat(t_state *state) { - /* t_program_result prog_res; */ + t_program_result prog_res; /* */ - /* prog_res = (t_program_result){.exit = 0}; */ + prog_res = (t_program_result){.exit = 0}; print_node_data(&state->current_node, 0); free_node(state->current_node); - /* if (state->ast != NULL && run_program(&state->ast->data.program, state, &prog_res)) */ - /* printf("Error when execting the Command \n"); */ + if (state->ast != NULL && run_program(&state->ast->data.program, state, &prog_res)) + printf("Error when execting the Command \n"); ast_free(state->ast); } diff --git a/stdme/src/fs/directory.c b/stdme/src/fs/directory.c index 67c74b9a..5b950b04 100644 --- a/stdme/src/fs/directory.c +++ b/stdme/src/fs/directory.c @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/07/30 16:24:53 by rparodi #+# #+# */ -/* Updated: 2024/07/30 16:25:23 by rparodi ### ########.fr */ +/* Updated: 2024/08/05 15:19:12 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ @@ -59,6 +59,9 @@ void close_dir(t_dir *dir) return ; if (closedir(dir->ptr) == -1) return ; + if (dir->name != NULL) + mem_free(dir->name); slot = (void *)(dir)-offsetof(struct s_file_slot, slot.dir); mem_set_zero(slot, sizeof(*slot)); + slot->ty = SLOT_UNUSED; } diff --git a/stdme/src/fs/fd.c b/stdme/src/fs/fd.c index a69b9762..c9c4560c 100644 --- a/stdme/src/fs/fd.c +++ b/stdme/src/fs/fd.c @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/07/30 16:17:17 by rparodi #+# #+# */ -/* Updated: 2024/07/30 16:23:47 by rparodi ### ########.fr */ +/* Updated: 2024/08/05 15:19:17 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ @@ -99,6 +99,9 @@ void close_fd(t_fd *fd) return ; if (close(fd->fd) == -1) return ; + if (fd->name != NULL) + mem_free(fd->name); slot = (void *)(fd)-offsetof(struct s_file_slot, slot.fd); mem_set_zero(slot, sizeof(*slot)); + slot->ty = SLOT_UNUSED; } diff --git a/stdme/src/fs/file.c b/stdme/src/fs/file.c index 8c9a3538..22ede943 100644 --- a/stdme/src/fs/file.c +++ b/stdme/src/fs/file.c @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/07/30 16:26:32 by rparodi #+# #+# */ -/* Updated: 2024/07/30 16:27:06 by rparodi ### ########.fr */ +/* Updated: 2024/08/05 15:19:21 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ @@ -76,6 +76,9 @@ void close_file(t_file *file) return ; if (fclose(file->ptr) == -1) return ; + if (file->name != NULL) + mem_free(file->name); slot = (void *)(file)-offsetof(struct s_file_slot, slot.file); mem_set_zero(slot, sizeof(*slot)); + slot->ty = SLOT_UNUSED; } diff --git a/stdme/src/fs/fs_internal.c b/stdme/src/fs/fs_internal.c index 35d249f3..06c61dbb 100644 --- a/stdme/src/fs/fs_internal.c +++ b/stdme/src/fs/fs_internal.c @@ -6,7 +6,7 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/05/19 15:53:50 by maiboyer #+# #+# */ -/* Updated: 2024/07/30 16:28:09 by rparodi ### ########.fr */ +/* Updated: 2024/08/05 15:18:22 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ @@ -64,11 +64,11 @@ void close_slot(struct s_file_slot *slot) if (slot->ty == SLOT_UNUSED) ; else if (slot->ty == SLOT_FD) - (mem_free(slot->slot.fd.name), close_fd(&slot->slot.fd)); + close_fd(&slot->slot.fd); else if (slot->ty == SLOT_DIR) - (mem_free(slot->slot.dir.name), close_dir(&slot->slot.dir)); + close_dir(&slot->slot.dir); else if (slot->ty == SLOT_FILE) - (mem_free(slot->slot.file.name), close_file(&slot->slot.file)); + close_file(&slot->slot.file); else (void)!write(2, "Unknown SLOT type", 17); mem_set_zero(slot, sizeof(*slot)); diff --git a/stdme/src/os/exit.c b/stdme/src/os/exit.c index dc63f570..43986ec7 100644 --- a/stdme/src/os/exit.c +++ b/stdme/src/os/exit.c @@ -6,7 +6,7 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/05/07 13:08:52 by maiboyer #+# #+# */ -/* Updated: 2024/07/10 17:54:22 by maiboyer ### ########.fr */ +/* Updated: 2024/08/05 15:14:46 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,5 +22,6 @@ void me_exit(t_i32 exit_code) { (get_stdin(), get_stdout(), get_stderr()); + close_all_slots(); exit(exit_code); }