From 2b5a62afc87f70fe9b9334b081fffe783ef323d0 Mon Sep 17 00:00:00 2001 From: maix0 Date: Thu, 24 Oct 2024 23:02:37 +0200 Subject: [PATCH] update: fixed some issues --- ast/Filelist.ast.mk | 2 +- ...t_print_subshell.c => ast_print_general.c} | 2 +- ast/src/print_ast/ast_print_redirection.c | 6 ++- exec/src/run_ast/_ast_into_str_main.c | 48 ++++++++++++------- exec/src/run_ast/_spawn_cmd.c | 3 +- sources/_helper_main.c | 3 +- 6 files changed, 40 insertions(+), 24 deletions(-) rename ast/src/print_ast/{ast_print_subshell.c => ast_print_general.c} (97%) diff --git a/ast/Filelist.ast.mk b/ast/Filelist.ast.mk index f0254bfb..ca332e85 100644 --- a/ast/Filelist.ast.mk +++ b/ast/Filelist.ast.mk @@ -6,9 +6,9 @@ ast_free/ast_free_scripting \ print_ast/ast_print \ print_ast/ast_print_arithmetic \ print_ast/ast_print_command \ +print_ast/ast_print_general \ print_ast/ast_print_global \ print_ast/ast_print_helper_function \ print_ast/ast_print_node \ print_ast/ast_print_redirection \ -print_ast/ast_print_subshell \ diff --git a/ast/src/print_ast/ast_print_subshell.c b/ast/src/print_ast/ast_print_general.c similarity index 97% rename from ast/src/print_ast/ast_print_subshell.c rename to ast/src/print_ast/ast_print_general.c index f82d3bd9..5d7cc619 100644 --- a/ast/src/print_ast/ast_print_subshell.c +++ b/ast/src/print_ast/ast_print_general.c @@ -1,7 +1,7 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* ast_print_subshell.c :+: :+: :+: */ +/* ast_print_general.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ diff --git a/ast/src/print_ast/ast_print_redirection.c b/ast/src/print_ast/ast_print_redirection.c index 3d480316..38a93e37 100644 --- a/ast/src/print_ast/ast_print_redirection.c +++ b/ast/src/print_ast/ast_print_redirection.c @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/07/26 13:07:12 by rparodi #+# #+# */ -/* Updated: 2024/10/14 14:12:49 by maiboyer ### ########.fr */ +/* Updated: 2024/10/24 22:30:02 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,7 +14,9 @@ void ast_print_node_file_redirection_heredoc(t_ast_node self) { - (void)(self); + if (self == NULL || self->kind != AST_HEREDOC_REDIRECTION) + return; + printf("<<%s", self->data.heredoc_redirection.delimiter); } //{ // if (self->data.file_redirection.op == AST_REDIR_HEREDOC) diff --git a/exec/src/run_ast/_ast_into_str_main.c b/exec/src/run_ast/_ast_into_str_main.c index 723c5212..f414fbf4 100644 --- a/exec/src/run_ast/_ast_into_str_main.c +++ b/exec/src/run_ast/_ast_into_str_main.c @@ -6,7 +6,7 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/09/14 12:26:51 by maiboyer #+# #+# */ -/* Updated: 2024/10/15 21:30:02 by maiboyer ### ########.fr */ +/* Updated: 2024/10/24 22:48:26 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,27 +21,39 @@ t_error _word_handle_star(t_ast_word *word, t_state *state, t_vec_str *out); t_error list_files_in_current_directory(t_vec_str *out); t_error _word_into_str_inner(struct s_word_str_args args); -t_error _word_split_loop(\ - bool do_split, t_expandable_str val, t_vec_str *append, t_string *tmp) +t_error _word_split_loop_expand(\ + t_expandable_str val, t_vec_str *append, t_string *tmp) { t_vec_str split; t_str stmp; + + if (val.do_expand) + { + if (val.value == NULL) + val.value = ""; + if (str_split(val.value, " \t\n\r\v", &split)) + return (ERROR); + if (split.len != 0) + { + vec_str_push(append, tmp->buf); + *tmp = string_new(16); + } + while (!vec_str_pop_front(&split, &stmp)) + vec_str_push(append, stmp); + vec_str_free(split); + } + else + string_push(tmp, val.value); + return (NO_ERROR); +} + + +t_error _word_split_loop(\ + bool do_split, t_expandable_str val, t_vec_str *append, t_string *tmp) +{ if (do_split) - { - if (val.do_expand) - { - if (val.value == NULL) - val.value = ""; - if (str_split(val.value, " ", &split)) - return (ERROR); - while (!vec_str_pop_front(&split, &stmp)) - vec_str_push(append, stmp); - vec_str_free(split); - } - else - vec_str_push(append, str_clone(val.value)); - } + return (_word_split_loop_expand(val, append, tmp)); else string_push(tmp, val.value); return (NO_ERROR); @@ -60,7 +72,7 @@ t_error _word_split(\ if (_word_split_loop(do_split, res->value.buffer[i++], append, &tmp)) return (string_free(tmp), ERROR); } - if (!do_split) + if (!do_split || tmp.len != 0) vec_str_push(append, tmp.buf); else string_free(tmp); diff --git a/exec/src/run_ast/_spawn_cmd.c b/exec/src/run_ast/_spawn_cmd.c index e830e3af..c53b0a9f 100644 --- a/exec/src/run_ast/_spawn_cmd.c +++ b/exec/src/run_ast/_spawn_cmd.c @@ -6,7 +6,7 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/09/14 12:30:09 by maiboyer #+# #+# */ -/* Updated: 2024/10/14 15:07:42 by maiboyer ### ########.fr */ +/* Updated: 2024/10/24 22:57:49 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ @@ -79,6 +79,7 @@ t_error _spawn_cmd_and_run_end(\ bpath = str_clone(info.binary_path); if (spawn_process(info, &out->process)) return (close_fd(cmd_pipe.input), out->exit = 127, _err_cmd(bpath)); + close_fd(cmd_pipe.input); str_free(bpath); if (cmd_pipe.create_output || cmd_pipe.input != NULL) return (out->exit = -1, NO_ERROR); diff --git a/sources/_helper_main.c b/sources/_helper_main.c index f6fda511..77dbf754 100644 --- a/sources/_helper_main.c +++ b/sources/_helper_main.c @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/09/06 16:31:41 by rparodi #+# #+# */ -/* Updated: 2024/10/14 15:03:01 by maiboyer ### ########.fr */ +/* Updated: 2024/10/24 22:31:52 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ @@ -64,6 +64,7 @@ void exec_shcat(t_state *state) vec_ast_push(&prog->data.program.body, state->ast); state->ast = prog; } + ast_print(state->ast); if (state->ast != NULL && run_program(&state->ast->data.program, state, &prog_res)) {