update: should handle built-in variables

This commit is contained in:
maix0 2024-10-06 14:37:54 +02:00
parent b058348d35
commit d459a8b8dc
11 changed files with 81 additions and 24 deletions

View file

@ -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);
}