update: tried to fix $?, the error is in the int_to_str stuff
This commit is contained in:
parent
a567a5323b
commit
bac90251fe
8 changed files with 23 additions and 11 deletions
|
|
@ -6,7 +6,7 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 == '#')
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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,
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue