fixes: first pass of norminette on easy stuff
This commit is contained in:
parent
1e4185a544
commit
85a327a0c4
7 changed files with 73 additions and 58 deletions
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/09/14 12:26:51 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/10/11 22:33:02 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/10/11 22:38:42 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -63,7 +63,7 @@ t_error _word_into_str(t_ast_node self, t_state *state, t_vec_str *append)
|
|||
|| self->kind != AST_WORD)
|
||||
return (ERROR);
|
||||
if (_word_is_star(&self->data.word))
|
||||
return (dprintf(2, "word is star !\n"), _word_handle_star(&self->data.word, state, append));
|
||||
return (_word_handle_star(&self->data.word, state, append));
|
||||
if (run_word(&self->data.word, state, &res))
|
||||
return (ERROR);
|
||||
if (res.kind == AST_WORD_NO_QUOTE)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/06 14:25:20 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/10/06 14:41:51 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/10/11 22:38:30 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -14,14 +14,17 @@
|
|||
#include "me/types.h"
|
||||
|
||||
#if BONUS
|
||||
t_pid get_self_pid(void)
|
||||
|
||||
t_pid get_self_pid(void)
|
||||
{
|
||||
return (getpid());
|
||||
}
|
||||
|
||||
#else
|
||||
t_pid get_self_pid(void)
|
||||
|
||||
t_pid get_self_pid(void)
|
||||
{
|
||||
return (1);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/09/14 12:38:38 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/10/11 22:16:10 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/10/11 22:41:10 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -15,8 +15,8 @@
|
|||
#include "me/str/str.h"
|
||||
#include "me/convert/numbers_to_str.h"
|
||||
|
||||
// non bonus only returns 1
|
||||
t_pid get_self_pid(void);
|
||||
// non bonus only returns -1
|
||||
t_pid get_self_pid(void);
|
||||
|
||||
bool _is_special_var(t_ast_expansion *self)
|
||||
{
|
||||
|
|
@ -35,6 +35,33 @@ bool _is_special_var(t_ast_expansion *self)
|
|||
return (false);
|
||||
}
|
||||
|
||||
static inline t_error _run_expansion_special_var_inner(\
|
||||
t_ast_expansion *self, t_state *state, \
|
||||
t_expansion_result *out, char name)
|
||||
{
|
||||
(void)(self);
|
||||
(void)(state);
|
||||
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);
|
||||
}
|
||||
|
||||
// return pid of last run program
|
||||
// return `argc - 1` bc we don't care about argv[0]
|
||||
// return pid of self (the shell)
|
||||
|
|
@ -54,26 +81,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)) // TODO: fix this shit
|
||||
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);
|
||||
return (_run_expansion_special_var_inner(self, state, out, name));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue