From bac90251fef7dc86f952e3535fa6039b99f1e48e Mon Sep 17 00:00:00 2001 From: maix0 Date: Thu, 10 Oct 2024 18:59:49 +0200 Subject: [PATCH] update: tried to fix $?, the error is in the int_to_str stuff --- exec/include/exec/_run_ast.h | 3 ++- exec/src/run_ast/_run_exit_code.c | 3 ++- exec/src/run_ast/run_builtins.c | 3 ++- exec/src/run_ast/run_expansion_builtin.c | 5 +++-- exec/src/run_ast/run_subshell.c | 5 ++++- sources/_helper_main.c | 3 ++- stdme/output/src/convert/i32_to_str.c | 4 ++-- stdme/src/convert/numbers_to_str.c | 8 ++++++-- 8 files changed, 23 insertions(+), 11 deletions(-) diff --git a/exec/include/exec/_run_ast.h b/exec/include/exec/_run_ast.h index 4cd3f6af..58b55e07 100644 --- a/exec/include/exec/_run_ast.h +++ b/exec/include/exec/_run_ast.h @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/08/14 17:57:57 by rparodi #+# #+# */ -/* Updated: 2024/10/09 15:37:28 by maiboyer ### ########.fr */ +/* Updated: 2024/10/10 18:51:29 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ @@ -97,6 +97,7 @@ struct s_ffree_state struct s_subshell_info { + t_state *state; t_fd *stdin; t_fd *stderr; t_fd *stdout; diff --git a/exec/src/run_ast/_run_exit_code.c b/exec/src/run_ast/_run_exit_code.c index ee0b734a..88fc0c20 100644 --- a/exec/src/run_ast/_run_exit_code.c +++ b/exec/src/run_ast/_run_exit_code.c @@ -6,7 +6,7 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/09/14 12:31:28 by maiboyer #+# #+# */ -/* Updated: 2024/10/06 14:22:08 by maiboyer ### ########.fr */ +/* Updated: 2024/10/10 18:54:14 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ @@ -56,6 +56,7 @@ t_error _run_other(t_ast_node self, t_state *state, int *out) *out = subshell_res.exit; } state->last_exit = *out; + printf("state->last_exit = %i\n", state->last_exit); return (NO_ERROR); } diff --git a/exec/src/run_ast/run_builtins.c b/exec/src/run_ast/run_builtins.c index 8b625074..e18fdf15 100644 --- a/exec/src/run_ast/run_builtins.c +++ b/exec/src/run_ast/run_builtins.c @@ -6,7 +6,7 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/09/14 12:24:49 by maiboyer #+# #+# */ -/* Updated: 2024/10/10 16:25:43 by maiboyer ### ########.fr */ +/* Updated: 2024/10/10 18:56:40 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ @@ -117,6 +117,7 @@ t_error _handle_builtin(t_spawn_info info, t_state *state, t_cmd_pipe cmd_pipe, return (ERROR); if (_setup_binfo(&info, &binfo, out)) return (ERROR); + printf("last_exit = %i\n", state->last_exit); _run_builtin(&binfo, actual_func, cmd_pipe, out); if (binfo.stdin) close_fd(binfo.stdin); diff --git a/exec/src/run_ast/run_expansion_builtin.c b/exec/src/run_ast/run_expansion_builtin.c index 62115ed6..94caca41 100644 --- a/exec/src/run_ast/run_expansion_builtin.c +++ b/exec/src/run_ast/run_expansion_builtin.c @@ -6,7 +6,7 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/09/14 12:38:38 by maiboyer #+# #+# */ -/* Updated: 2024/10/06 14:28:10 by maiboyer ### ########.fr */ +/* Updated: 2024/10/10 18:58:52 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ @@ -54,7 +54,8 @@ t_error _run_expansion_special_var(t_ast_expansion *self, t_state *state, if (name == '?') { *out = (t_expansion_result){.exists = true, .value = NULL}; - if (i32_to_str(state->last_exit, &out->value)) + printf("state->last_exit in exp = %i \n", state->last_exit); + if (i32_to_str(state->last_exit, &out->value)) // TODO: fix this shit return (ERROR); } if (name == '#') diff --git a/exec/src/run_ast/run_subshell.c b/exec/src/run_ast/run_subshell.c index f9eed801..6d367a8a 100644 --- a/exec/src/run_ast/run_subshell.c +++ b/exec/src/run_ast/run_subshell.c @@ -6,7 +6,7 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/09/14 12:35:02 by maiboyer #+# #+# */ -/* Updated: 2024/10/10 16:31:30 by maiboyer ### ########.fr */ +/* Updated: 2024/10/10 18:52:39 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ @@ -81,6 +81,8 @@ t_error _wait_subshell(\ out->exit = WEXITSTATUS(status); if (WIFSIGNALED(status)) out->exit = WTERMSIG(status); + printf("out->exit for subshell is %i\n", out->exit); + sinfo.state->last_exit = out->exit; return (NO_ERROR); } @@ -94,6 +96,7 @@ t_error run_subshell(t_ast_subshell *subshell, t_state *state, if (subshell == NULL || state == NULL || out == NULL) return (ERROR); mem_set_zero(&sinfo, sizeof(sinfo)); + sinfo.state = state; if (_setup_redirection(&info, state, cmd_pipe, \ &subshell->suffixes_redirections)) return (ERROR); diff --git a/sources/_helper_main.c b/sources/_helper_main.c index 8c3ad1c9..d43121b2 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/10 17:48:06 by maiboyer ### ########.fr */ +/* Updated: 2024/10/10 18:50:37 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ @@ -41,6 +41,7 @@ t_error get_user_input(t_state *state) { errno = 0; lstate.pos = 0; + state->last_exit = 127; string_clear(&lstate.buf); write_fd(lstate.output_fd, (void *)"^C\n", 3, NULL); line_refresh_line(&lstate); diff --git a/stdme/output/src/convert/i32_to_str.c b/stdme/output/src/convert/i32_to_str.c index 0e5a04b9..383c7bb9 100644 --- a/stdme/output/src/convert/i32_to_str.c +++ b/stdme/output/src/convert/i32_to_str.c @@ -6,7 +6,7 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/01 21:15:19 by maiboyer #+# #+# */ -/* Updated: 2024/07/30 16:31:39 by rparodi ### ########.fr */ +/* Updated: 2024/10/10 18:38:50 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ @@ -25,7 +25,7 @@ t_error i32_to_str_base_prefix(t_i32 val, t_str base, t_str prefix, t_str *out) if (out == NULL || base == NULL || prefix == NULL) return (ERROR); value.i32 = val; - is_nonnegative = val & 0x80000000; + is_nonnegative = value.u32 & 0x80000000; if (is_nonnegative) value.u32 = ~value.u32 + 1; return (_format_u64((t_num_str){.value = value.u64, diff --git a/stdme/src/convert/numbers_to_str.c b/stdme/src/convert/numbers_to_str.c index b669fcce..6b1590df 100644 --- a/stdme/src/convert/numbers_to_str.c +++ b/stdme/src/convert/numbers_to_str.c @@ -6,7 +6,7 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/07/16 18:15:57 by maiboyer #+# #+# */ -/* Updated: 2024/07/16 19:39:57 by maiboyer ### ########.fr */ +/* Updated: 2024/10/10 18:49:27 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,6 +15,7 @@ #include "me/str/str.h" #include "me/types.h" #include +#include static t_error _check_base(t_str base) { @@ -41,7 +42,9 @@ static void _set_modulus(t_num_str_state *s) { s->modulus = 0; s->base_len = str_len(s->base); - while (UINT64_MAX - s->modulus >= s->base_len) + if (s->base_len == 10) + return ((void)(s->modulus = 10000000000000000000lu)); + while (UINT64_MAX - s->modulus > s->base_len) s->modulus += s->base_len; } @@ -85,6 +88,7 @@ t_error _format_u64(t_num_str args, t_str *out) args.prefix = ""; mem_set_zero(&s, sizeof(s)); s.idx = 0; + s.base = args.base; if (args.is_nonnegative) s.buffer[s.idx++] = '-'; _set_modulus(&s);