Fixed stuff
This commit is contained in:
parent
be1d3ff2d3
commit
f4e8596f3b
15 changed files with 130 additions and 103 deletions
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/04 18:32:50 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/05/14 18:46:13 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/05/18 18:44:24 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -14,15 +14,22 @@
|
|||
#include "me/buffered_str/buf_str.h"
|
||||
#include "me/hash/hasher.h"
|
||||
#include "me/hashmap/hashmap_env.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/string/str_clone.h"
|
||||
#include "me/string/str_compare.h"
|
||||
#include "me/string/str_len.h"
|
||||
#include "me/types.h"
|
||||
#include "me/vec/vec_str.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
static void _hash_str(t_hasher *hasher, t_str *s)
|
||||
{
|
||||
hasher_write_str(hasher, *s);
|
||||
t_usize len;
|
||||
|
||||
len = str_len(*s);
|
||||
hasher_write_u64(hasher, (t_u64)len);
|
||||
hasher_write_bytes(hasher, (t_u8 *)*s, len);
|
||||
hasher_write_u8(hasher, 0);
|
||||
}
|
||||
|
||||
static bool _cmp_str(t_str *s1, t_str *s2)
|
||||
|
|
@ -33,9 +40,9 @@ static bool _cmp_str(t_str *s1, t_str *s2)
|
|||
static void _free_env(t_kv_env kv)
|
||||
{
|
||||
if (kv.key)
|
||||
free(kv.key);
|
||||
mem_free(kv.key);
|
||||
if (kv.val)
|
||||
free(kv.val);
|
||||
mem_free(kv.val);
|
||||
}
|
||||
|
||||
t_hashmap_env *create_env_map(void)
|
||||
|
|
@ -47,15 +54,17 @@ t_error _build_envp_iterator(t_usize idx, const t_str *key, t_str *val,
|
|||
void *ctx)
|
||||
{
|
||||
struct s_build_envp_state *s;
|
||||
t_str push;
|
||||
|
||||
(void)(idx);
|
||||
s = ctx;
|
||||
if (push_str_buffer(&s->buf, *key) && push_str_char(&s->buf, '=') &&
|
||||
if (push_str_buffer(&s->buf, *key) || push_str_buffer(&s->buf, "=") ||
|
||||
push_str_buffer(&s->buf, *val))
|
||||
return (vec_str_free(s->out), ERROR);
|
||||
if (vec_str_push(&s->out, s->buf.buf))
|
||||
push = str_clone(s->buf.buf);
|
||||
if (vec_str_push(&s->out, push))
|
||||
return (str_free(s->buf), ERROR);
|
||||
s->buf = alloc_new_buffer(50);
|
||||
str_clear(&s->buf);
|
||||
return (NO_ERROR);
|
||||
}
|
||||
|
||||
|
|
@ -63,12 +72,12 @@ t_error build_envp(t_hashmap_env *envs, t_vec_str *envp)
|
|||
{
|
||||
struct s_build_envp_state state;
|
||||
|
||||
state.out = vec_str_new(envs->num_buckets, (void (*)(t_str))mem_free);
|
||||
state.buf = alloc_new_buffer(50);
|
||||
state.buf = alloc_new_buffer(8096);
|
||||
state.out = vec_str_new(1024, (void (*)(t_str))mem_free);
|
||||
if (hashmap_env_iter(envs, _build_envp_iterator, &state))
|
||||
return (ERROR);
|
||||
return (str_free(state.buf), printf("iter failed\n"), ERROR);
|
||||
if (vec_str_push(&state.out, NULL))
|
||||
return (ERROR);
|
||||
return (str_free(state.buf), printf("coun't push null\n"), ERROR);
|
||||
*envp = state.out;
|
||||
str_free(state.buf);
|
||||
return (NO_ERROR);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/09 15:00:53 by rparodi #+# #+# */
|
||||
/* Updated: 2024/05/18 16:54:29 by rparodi ### ########.fr */
|
||||
/* Updated: 2024/05/18 18:31:34 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -28,7 +28,8 @@ t_error handle_command(t_node *self, t_utils *shcat, t_i32 *out_exit_code)
|
|||
t_spawn_info spawn_info;
|
||||
t_str tmp;
|
||||
|
||||
spawn_info.arguments = vec_str_new(64, (void (*)(t_str))mem_free); // TODO: FIX VECTOR
|
||||
spawn_info.arguments =
|
||||
vec_str_new(64, (void (*)(t_str))mem_free); // TODO: FIX VECTOR
|
||||
if (self->kind != sym_command)
|
||||
return (ERROR);
|
||||
i = 0;
|
||||
|
|
@ -37,7 +38,8 @@ t_error handle_command(t_node *self, t_utils *shcat, t_i32 *out_exit_code)
|
|||
if (self->childs[i].kind == sym_command_name)
|
||||
{
|
||||
spawn_info.binary_path = str_clone(node_getstr(&self->childs[i]));
|
||||
vec_str_push(&spawn_info.arguments, str_clone(spawn_info.binary_path));
|
||||
vec_str_push(&spawn_info.arguments,
|
||||
str_clone(spawn_info.binary_path));
|
||||
printf("%s\n", spawn_info.arguments.buffer[0]);
|
||||
}
|
||||
else if (self->childs[i].kind == sym_file_redirect)
|
||||
|
|
@ -55,14 +57,15 @@ t_error handle_command(t_node *self, t_utils *shcat, t_i32 *out_exit_code)
|
|||
}
|
||||
i++;
|
||||
}
|
||||
printf("%zu\n", spawn_info.arguments.len);
|
||||
// printf("%zu\n", spawn_info.arguments.len);
|
||||
vec_str_push(&spawn_info.arguments, NULL);
|
||||
for (i = 0; i < spawn_info.arguments.len; i++)
|
||||
printf("[%zu]\t%s\n", i, spawn_info.arguments.buffer[i]);
|
||||
// for (i = 0; i < spawn_info.arguments.len; i++)
|
||||
// printf("[%zu]\t%s\n", i, spawn_info.arguments.buffer[i]);
|
||||
spawn_info.stdin = inherited();
|
||||
spawn_info.stdout = inherited();
|
||||
spawn_info.stderr = inherited();
|
||||
spawn_info.forked_free = NULL;
|
||||
printf("building envp\n");
|
||||
if (build_envp(shcat->env, &spawn_info.environement))
|
||||
return (vec_str_free(spawn_info.arguments), ERROR);
|
||||
if (spawn_process(spawn_info, &shcat->ret))
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/03/29 11:35:51 by rparodi #+# #+# */
|
||||
/* Updated: 2024/05/14 18:46:30 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/05/18 18:11:59 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -35,13 +35,15 @@ void ft_free_strs(t_str *strs)
|
|||
|
||||
void ft_free_utils(t_utils *s)
|
||||
{
|
||||
(void)(s);
|
||||
if (s->str_input)
|
||||
free(s->str_input);
|
||||
if (s->path)
|
||||
ft_free_strs(s->path);
|
||||
if (s->env)
|
||||
{
|
||||
printf("Dropping HashMap\n");
|
||||
drop_hashmap_env(s->env);
|
||||
}
|
||||
ts_parser_delete(s->parser.parser);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/03/28 14:40:38 by rparodi #+# #+# */
|
||||
/* Updated: 2024/05/18 17:09:37 by rparodi ### ########.fr */
|
||||
/* Updated: 2024/05/18 18:37:39 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -19,13 +19,12 @@
|
|||
#include "me/hashmap/hashmap_env.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/string/str_len.h"
|
||||
#include "me/string/str_split.h"
|
||||
#include "me/string/str_substring.h"
|
||||
#include "me/types.h"
|
||||
#include "minishell.h"
|
||||
#include "parser/api.h"
|
||||
#include <sys/_types/_null.h>
|
||||
#include <sys/types.h>
|
||||
#include "me/string/str_split.h"
|
||||
#include "me/mem/mem.h"
|
||||
|
||||
#undef free
|
||||
#undef malloc
|
||||
|
|
@ -41,26 +40,44 @@ void ts_parser_delete(t_first_parser *self);
|
|||
void ts_parser_set_language(t_first_parser *self, t_language *lang);
|
||||
|
||||
// Foutre envp dans env
|
||||
// Chaque elemenet d'envp split au premier =
|
||||
// Chaque elemenet d'envp split au premier =
|
||||
// cle avant le =
|
||||
// data apres le =
|
||||
|
||||
t_error populate_env(t_hashmap_env *env, t_str envp[])
|
||||
t_error split_str_first(t_const_str s, char splitter, t_str *before,
|
||||
t_str *after)
|
||||
{
|
||||
t_usize i;
|
||||
t_str *temp;
|
||||
t_usize i;
|
||||
|
||||
if (s == NULL || before == NULL || after == NULL || splitter == '\0')
|
||||
return (ERROR);
|
||||
i = 0;
|
||||
while (s[i] != '\0' && s[i] != splitter)
|
||||
i++;
|
||||
if (s[i] == '\0')
|
||||
return (ERROR);
|
||||
if (i == 0)
|
||||
i = 1;
|
||||
*before = str_substring(s, 0, i);
|
||||
*after = str_substring(s, i + 1, ~(t_usize)0);
|
||||
return (NO_ERROR);
|
||||
}
|
||||
|
||||
t_error populate_env(t_hashmap_env *env, t_str envp[])
|
||||
{
|
||||
t_usize i;
|
||||
t_str temp[2];
|
||||
|
||||
i = 0;
|
||||
temp = NULL;
|
||||
if (envp == NULL || env == NULL)
|
||||
return (ERROR);
|
||||
return (printf("given a nullptr\n"), ERROR);
|
||||
while (envp[i] != NULL)
|
||||
{
|
||||
temp = str_split(envp[i], '=');
|
||||
if (temp[0] == NULL || temp[1] == NULL)
|
||||
if (split_str_first(envp[i], '=', &temp[0], &temp[1]))
|
||||
return (ERROR);
|
||||
if (temp[0] == NULL || temp[1] == NULL)
|
||||
return (printf("TEMP NULL\n"), ERROR);
|
||||
insert_hashmap_env(env, temp[0], temp[1]);
|
||||
mem_free(temp);
|
||||
i++;
|
||||
}
|
||||
return (NO_ERROR);
|
||||
|
|
@ -224,8 +241,10 @@ t_i32 main(t_i32 argc, t_str argv[], t_str envp[])
|
|||
utils = (t_utils){};
|
||||
utils.parser = create_myparser();
|
||||
utils.env = create_env_map();
|
||||
if (install_signal())
|
||||
return (1);
|
||||
// if (install_signal())
|
||||
// return (1);
|
||||
if (populate_env(utils.env, envp))
|
||||
me_abort("unable to build ENV hashmap");
|
||||
utils.name_shell = "\001\x1B[93m\002"
|
||||
"42sh"
|
||||
"\001\x1B[32m\002"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue