update: should handle built-in variables
This commit is contained in:
parent
b058348d35
commit
d459a8b8dc
11 changed files with 81 additions and 24 deletions
29
exec/src/run_ast/_get_pid.c
Normal file
29
exec/src/run_ast/_get_pid.c
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* _get_pid.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/06 14:25:20 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/10/06 14:27:40 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/os/os.h"
|
||||
#include "me/types.h"
|
||||
|
||||
#define BONUS 1
|
||||
|
||||
#if BONUS
|
||||
t_pid get_self_pid(void)
|
||||
{
|
||||
return (getpid());
|
||||
}
|
||||
#else
|
||||
t_pid get_self_pid(void)
|
||||
{
|
||||
return (1);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/09/14 12:31:28 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/09/16 18:28:48 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/10/06 14:22:08 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -26,6 +26,7 @@ t_error _run_cmd(t_ast_node self, t_state *state, int *out)
|
|||
if (cmd_res.process.stderr != NULL)
|
||||
close_fd(cmd_res.process.stderr);
|
||||
*out = cmd_res.exit;
|
||||
state->last_exit = *out;
|
||||
return (NO_ERROR);
|
||||
}
|
||||
|
||||
|
|
@ -54,6 +55,7 @@ t_error _run_other(t_ast_node self, t_state *state, int *out)
|
|||
return (ERROR);
|
||||
*out = subshell_res.exit;
|
||||
}
|
||||
state->last_exit = *out;
|
||||
return (NO_ERROR);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/09/14 12:30:09 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/09/18 21:50:18 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/10/06 14:19:40 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -76,6 +76,7 @@ t_error _spawn_cmd_and_run_end(\
|
|||
out->exit = WEXITSTATUS(status);
|
||||
if (WIFSIGNALED(status))
|
||||
out->exit = WTERMSIG(status);
|
||||
state->last_exit = out->exit;
|
||||
return (NO_ERROR);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/09/14 12:38:38 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/09/14 12:42:53 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/10/06 14:28:10 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -15,6 +15,9 @@
|
|||
#include "me/str/str.h"
|
||||
#include "me/convert/numbers_to_str.h"
|
||||
|
||||
// non bonus only returns 1
|
||||
t_pid get_self_pid(void);
|
||||
|
||||
bool _is_special_var(t_ast_expansion *self)
|
||||
{
|
||||
char name;
|
||||
|
|
@ -50,7 +53,27 @@ t_error _run_expansion_special_var(t_ast_expansion *self, t_state *state,
|
|||
*out = (t_expansion_result){.exists = false, .value = NULL};
|
||||
if (name == '?')
|
||||
{
|
||||
printf("PLEASE MAKE SURE TO FINISH THE SPECIAL VAR HANDLING !");
|
||||
*out = (t_expansion_result){.exists = true, .value = NULL};
|
||||
if (i32_to_str(state->last_exit, &out->value))
|
||||
return (ERROR);
|
||||
}
|
||||
if (name == '#')
|
||||
{
|
||||
*out = (t_expansion_result){.exists = true, .value = NULL};
|
||||
if (i32_to_str(1, &out->value))
|
||||
return (ERROR);
|
||||
}
|
||||
if (name == '!')
|
||||
{
|
||||
*out = (t_expansion_result){.exists = true, .value = NULL};
|
||||
if (i32_to_str(1, &out->value))
|
||||
return (ERROR);
|
||||
}
|
||||
if (name == '$')
|
||||
{
|
||||
*out = (t_expansion_result){.exists = true, .value = NULL};
|
||||
if (i32_to_str(get_self_pid(), &out->value))
|
||||
return (ERROR);
|
||||
}
|
||||
return (NO_ERROR);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/09/14 12:34:33 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/09/16 19:09:53 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/10/06 14:20:55 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -56,5 +56,6 @@ t_error run_list(t_ast_list *list, t_state *state, t_list_result *out)
|
|||
}
|
||||
else
|
||||
out->exit = left;
|
||||
state->last_exit = out->exit;
|
||||
return (NO_ERROR);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/09/14 12:32:37 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/09/18 21:45:48 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/10/06 14:20:43 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -41,7 +41,7 @@ void _append_redir_to_pipeline(t_ast_pipeline *pipeline)
|
|||
vec_ast_push(append, tmp_ast);
|
||||
}
|
||||
|
||||
void _wait_pipeline(t_vec_pid pids, t_pipeline_result *out)
|
||||
void _wait_pipeline(t_vec_pid pids, t_state *state, t_pipeline_result *out)
|
||||
{
|
||||
int waitpid_status;
|
||||
|
||||
|
|
@ -59,6 +59,7 @@ void _wait_pipeline(t_vec_pid pids, t_pipeline_result *out)
|
|||
}
|
||||
else
|
||||
out->exit = 127;
|
||||
state->last_exit = out->exit;
|
||||
vec_pid_free(pids);
|
||||
}
|
||||
|
||||
|
|
@ -133,5 +134,5 @@ t_error run_pipeline(t_ast_pipeline *pipeline, t_state *state,
|
|||
ret |= ((void)(printf("List in pipelines are unsupported,"\
|
||||
" use a subshell !\n")), ERROR);
|
||||
}
|
||||
return (_wait_pipeline(pids, out), ret);
|
||||
return (_wait_pipeline(pids, state, out), ret);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/09/14 12:35:02 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/09/16 19:02:01 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/10/06 14:21:41 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue