did env, exit and export (only env printing)
This commit is contained in:
parent
3f08544384
commit
85910da2fd
3 changed files with 43 additions and 16 deletions
|
|
@ -6,14 +6,42 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/08/07 14:22:50 by rparodi #+# #+# */
|
||||
/* Updated: 2024/08/10 19:44:43 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/08/10 19:57:32 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/types.h"
|
||||
#include "exec/builtins.h"
|
||||
#include "me/hashmap/hashmap_env.h"
|
||||
#include "me/printf/printf.h"
|
||||
#include "me/types.h"
|
||||
|
||||
struct s_print_env_state
|
||||
{
|
||||
t_state *state;
|
||||
t_spawn_info *info;
|
||||
};
|
||||
|
||||
static t_error _print_env(t_usize _idx, const t_str *key, t_str *value, void *vctx)
|
||||
{
|
||||
const struct s_print_env_state *ctx = vctx;
|
||||
t_str *val;
|
||||
|
||||
val = hmap_env_get(ctx->state->tmp_var, (t_str *)key);
|
||||
if (val == NULL)
|
||||
val = value;
|
||||
if (val == NULL || *val == NULL)
|
||||
return (NO_ERROR);
|
||||
// TODO: Fix this to handle the corrrect output
|
||||
me_printf_fd(NULL, "%s=%s\n", *key, *val);
|
||||
return (NO_ERROR);
|
||||
}
|
||||
|
||||
t_error builtin_env___(t_state *state, t_spawn_info info)
|
||||
{
|
||||
struct s_print_env_state ctx;
|
||||
|
||||
ctx.info = &info;
|
||||
ctx.state = state;
|
||||
hmap_env_iter(state->env, _print_env, &ctx);
|
||||
return (NO_ERROR);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,18 +6,22 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/08/10 18:43:18 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/08/10 19:49:14 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/08/10 20:01:36 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "exec/builtins.h"
|
||||
#include "me/printf/printf.h"
|
||||
#include "me/str/str.h"
|
||||
#include "me/string/string.h"
|
||||
#include "me/convert/str_to_numbers.h"
|
||||
#include "me/types.h"
|
||||
|
||||
t_error builtin_exit__(t_state *state, t_spawn_info info)
|
||||
{
|
||||
return (ERROR);
|
||||
}
|
||||
t_i32 exit_code;
|
||||
|
||||
if (info.arguments.len < 2)
|
||||
exit_code = 0;
|
||||
else if (str_to_i32(info.arguments.buffer[1], 10, &exit_code))
|
||||
return (ERROR);
|
||||
me_exit(exit_code);
|
||||
return (NO_ERROR);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/08/07 14:13:41 by rparodi #+# #+# */
|
||||
/* Updated: 2024/08/10 19:43:58 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/08/10 19:58:12 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -16,12 +16,7 @@
|
|||
t_error builtin_export(t_state *state, t_spawn_info info)
|
||||
{
|
||||
if (info.arguments.len == 1)
|
||||
{
|
||||
// print env
|
||||
}
|
||||
else
|
||||
{
|
||||
// assign variable
|
||||
}
|
||||
return (builtin_env___(state, info));
|
||||
|
||||
return (NO_ERROR);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue