normed: folder sources to the norm
This commit is contained in:
parent
9ee2fa851c
commit
b36e835dfb
3 changed files with 74 additions and 49 deletions
40
sources/_env_norm_helper.c
Normal file
40
sources/_env_norm_helper.c
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* _env_norm_helper.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/09/06 15:39:47 by rparodi #+# #+# */
|
||||
/* Updated: 2024/09/06 15:40:16 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "app/env.h"
|
||||
#include "me/string/string.h"
|
||||
#include "me/hash/hasher.h"
|
||||
#include "me/hashmap/hashmap_env.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/str/str.h"
|
||||
#include "me/str/str.h"
|
||||
#include "me/str/str.h"
|
||||
#include "me/types.h"
|
||||
#include "me/vec/vec_str.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
t_error build_envp(\
|
||||
t_hashmap_env *envs, t_hashmap_env *tmp_vars, t_vec_str *envp)
|
||||
{
|
||||
struct s_build_envp_state state;
|
||||
|
||||
state.tmp_vars = tmp_vars;
|
||||
state.buf = string_new(8096);
|
||||
state.out = vec_str_new(1024, (void (*)(t_str))mem_free);
|
||||
if (hmap_env_iter(envs, _build_envp_iterator, &state))
|
||||
return (string_free(state.buf), ERROR);
|
||||
if (vec_str_push(&state.out, NULL))
|
||||
return (string_free(state.buf), ERROR);
|
||||
*envp = state.out;
|
||||
string_free(state.buf);
|
||||
return (NO_ERROR);
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/04 18:32:50 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/08/03 16:31:34 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/09/06 15:40:19 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -71,19 +71,3 @@ t_error _build_envp_iterator(t_usize idx, const t_str *key, t_str *val,
|
|||
string_clear(&s->buf);
|
||||
return (NO_ERROR);
|
||||
}
|
||||
|
||||
t_error build_envp(t_hashmap_env *envs, t_hashmap_env *tmp_vars, t_vec_str *envp)
|
||||
{
|
||||
struct s_build_envp_state state;
|
||||
|
||||
state.tmp_vars = tmp_vars;
|
||||
state.buf = string_new(8096);
|
||||
state.out = vec_str_new(1024, (void (*)(t_str))mem_free);
|
||||
if (hmap_env_iter(envs, _build_envp_iterator, &state))
|
||||
return (string_free(state.buf), ERROR);
|
||||
if (vec_str_push(&state.out, NULL))
|
||||
return (string_free(state.buf), ERROR);
|
||||
*envp = state.out;
|
||||
string_free(state.buf);
|
||||
return (NO_ERROR);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/03/28 14:40:38 by rparodi #+# #+# */
|
||||
/* Updated: 2024/08/19 14:22:34 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/09/06 15:46:18 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -39,7 +39,8 @@ void ft_exit(t_state *maiboyerlpb, t_u8 exit_status);
|
|||
t_language *tree_sitter_sh(void);
|
||||
void ast_free(t_ast_node node);
|
||||
|
||||
t_error split_str_first(t_const_str s, char splitter, t_str *before, t_str *after)
|
||||
t_error split_str_first(\
|
||||
t_const_str s, char splitter, t_str *before, t_str *after)
|
||||
{
|
||||
t_usize i;
|
||||
|
||||
|
|
@ -101,7 +102,8 @@ t_node parse_str(t_state *state)
|
|||
t_node ret;
|
||||
t_ast_node out;
|
||||
|
||||
tree = ts_parser_parse_string(state->parser, state->str_input, str_len(state->str_input));
|
||||
tree = ts_parser_parse_string(\
|
||||
state->parser, state->str_input, str_len(state->str_input));
|
||||
node = ts_tree_root_node(tree);
|
||||
if (ast_from_node(node, state->str_input, &out))
|
||||
(state->ast = NULL, printf("Error when building node\n"));
|
||||
|
|
@ -115,11 +117,12 @@ t_node parse_str(t_state *state)
|
|||
void exec_shcat(t_state *state)
|
||||
{
|
||||
t_program_result prog_res;
|
||||
/* */
|
||||
|
||||
prog_res = (t_program_result){.exit = 0};
|
||||
print_node_data(&state->current_node, 0);
|
||||
free_node(state->current_node);
|
||||
if (state->ast != NULL && run_program(&state->ast->data.program, state, &prog_res))
|
||||
if (state->ast != NULL && run_program(\
|
||||
&state->ast->data.program, state, &prog_res))
|
||||
printf("Error when execting the Command \n");
|
||||
ast_free(state->ast);
|
||||
}
|
||||
|
|
@ -157,7 +160,6 @@ void ft_take_args(t_state *state)
|
|||
line_history_add(state->str_input);
|
||||
state->current_node = parse_str(state);
|
||||
exec_shcat(state);
|
||||
/* ft_exit(state, 42); */
|
||||
mem_free(state->str_input);
|
||||
}
|
||||
}
|
||||
|
|
@ -179,7 +181,6 @@ t_i32 main(t_i32 argc, t_str argv[], t_str envp[])
|
|||
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
(void)envp;
|
||||
if (install_signal())
|
||||
me_abort("Unable to install signals");
|
||||
state = (t_state){};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue