update stuff

This commit is contained in:
Maix0 2024-05-20 00:35:39 +02:00
parent 5973022688
commit 544ed8b045
194 changed files with 2060 additions and 1464 deletions

View file

@ -6,18 +6,18 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/04 18:32:50 by maiboyer #+# #+# */
/* Updated: 2024/05/18 18:44:24 by maiboyer ### ########.fr */
/* Updated: 2024/05/19 14:55:56 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "app/env.h"
#include "me/buffered_str/buf_str.h"
#include "me/string/string.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/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>
@ -47,7 +47,7 @@ static void _free_env(t_kv_env kv)
t_hashmap_env *create_env_map(void)
{
return (new_hashmap_env(_hash_str, _cmp_str, _free_env));
return (hmap_new_env(_hash_str, _cmp_str, _free_env));
}
t_error _build_envp_iterator(t_usize idx, const t_str *key, t_str *val,
@ -58,13 +58,13 @@ t_error _build_envp_iterator(t_usize idx, const t_str *key, t_str *val,
(void)(idx);
s = ctx;
if (push_str_buffer(&s->buf, *key) || push_str_buffer(&s->buf, "=") ||
push_str_buffer(&s->buf, *val))
if (string_push(&s->buf, *key) || string_push(&s->buf, "=") ||
string_push(&s->buf, *val))
return (vec_str_free(s->out), ERROR);
push = str_clone(s->buf.buf);
if (vec_str_push(&s->out, push))
return (str_free(s->buf), ERROR);
str_clear(&s->buf);
return (string_free(s->buf), ERROR);
string_clear(&s->buf);
return (NO_ERROR);
}
@ -72,13 +72,13 @@ t_error build_envp(t_hashmap_env *envs, t_vec_str *envp)
{
struct s_build_envp_state state;
state.buf = alloc_new_buffer(8096);
state.buf = string_new(8096);
state.out = vec_str_new(1024, (void (*)(t_str))mem_free);
if (hashmap_env_iter(envs, _build_envp_iterator, &state))
return (str_free(state.buf), printf("iter failed\n"), ERROR);
if (hmap_env_iter(envs, _build_envp_iterator, &state))
return (string_free(state.buf), ERROR);
if (vec_str_push(&state.out, NULL))
return (str_free(state.buf), printf("coun't push null\n"), ERROR);
return (string_free(state.buf), ERROR);
*envp = state.out;
str_free(state.buf);
string_free(state.buf);
return (NO_ERROR);
}

View file

@ -6,7 +6,7 @@
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/09 15:00:53 by rparodi #+# #+# */
/* Updated: 2024/05/18 18:31:34 by maiboyer ### ########.fr */
/* Updated: 2024/05/19 14:56:22 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
@ -18,7 +18,7 @@
#include "me/vec/vec_str.h"
// #include "app/node/handle_program.h"
#include "app/node/handle_command.h"
#include "me/string/str_clone.h"
#include "me/str/str.h"
#include "minishell.h"
#include <time.h>
@ -48,8 +48,6 @@ t_error handle_command(t_node *self, t_utils *shcat, t_i32 *out_exit_code)
printf("PAS ENCORE HANDLE FDP asignement!\n");
else
{
printf("arg %s %s\n", self->childs[i].kind_str,
node_getstr(&self->childs[i]));
if (handle_node_getstr(&self->childs[i], shcat, &tmp))
return (vec_str_free(spawn_info.arguments), ERROR);
if (vec_str_push(&spawn_info.arguments, str_clone(tmp)))
@ -57,15 +55,11 @@ t_error handle_command(t_node *self, t_utils *shcat, t_i32 *out_exit_code)
}
i++;
}
// 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]);
// vec_str_push(&spawn_info.arguments, NULL);
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))

View file

@ -16,7 +16,7 @@
#include "app/node/handle_word.h"
#include "app/state.h"
#include "gmr/symbols.h"
#include "me/buffered_str/buf_str.h"
#include "me/string/string.h"
#include "me/types.h"
t_error node_get_string(t_node *self, t_utils *shcat, t_str *ret)
@ -30,20 +30,20 @@ t_error node_get_string(t_node *self, t_utils *shcat, t_str *ret)
t_error handle_concat(t_node *self, t_utils *shcat, t_str *ret)
{
t_buffer_str out;
t_string out;
t_usize i;
t_str tmp;
(void)(shcat);
if (self == NULL || ret == NULL || self->kind != sym_concatenation)
return (ERROR);
out = alloc_new_buffer(16);
out = string_new(16);
i = 0;
while (i < self->childs_count)
{
if (node_get_string(&self->childs[i], shcat, &tmp))
return (str_free(out), ERROR);
push_str_buffer(&out, tmp);
return (string_free(out), ERROR);
string_push(&out, tmp);
mem_free(tmp);
i++;
}

View file

@ -14,8 +14,8 @@
#include "app/node.h"
#include "app/state.h"
#include "gmr/symbols.h"
#include "me/string/str_len.h"
#include "me/string/str_substring.h"
#include "me/str/str.h"
#include "me/str/str.h"
#include "me/types.h"
t_error handle_raw_string(t_node *self, t_utils *shcat, t_str *ret)

View file

@ -13,7 +13,7 @@
#include "app/node/handle_word.h"
#include "app/state.h"
#include "gmr/symbols.h"
#include "me/string/str_clone.h"
#include "me/str/str.h"
#include "me/types.h"
t_error handle_word(t_node *self, t_utils *shcat, t_str *ret)

View file

@ -18,7 +18,7 @@
#include "me/vec/vec_str.h"
#include "app/node/handle_command.h"
#include "minishell.h"
#include "me/string/str_clone.h"
#include "me/str/str.h"
t_error ft_command_exec(t_node *self, t_i32 *ret);

View file

@ -6,7 +6,7 @@
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/29 11:35:51 by rparodi #+# #+# */
/* Updated: 2024/05/18 18:11:59 by maiboyer ### ########.fr */
/* Updated: 2024/05/19 14:51:28 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
@ -40,10 +40,7 @@ void ft_free_utils(t_utils *s)
if (s->path)
ft_free_strs(s->path);
if (s->env)
{
printf("Dropping HashMap\n");
drop_hashmap_env(s->env);
}
hmap_free_env(s->env);
ts_parser_delete(s->parser.parser);
}

View file

@ -6,7 +6,7 @@
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/28 14:40:38 by rparodi #+# #+# */
/* Updated: 2024/05/18 18:37:39 by maiboyer ### ########.fr */
/* Updated: 2024/05/19 14:55:28 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
@ -17,10 +17,8 @@
#include "app/signal_handler.h"
#include "gmr/symbols.h"
#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/str/str.h"
#include "me/str/str.h"
#include "me/types.h"
#include "minishell.h"
#include "parser/api.h"
@ -77,7 +75,7 @@ t_error populate_env(t_hashmap_env *env, t_str envp[])
return (ERROR);
if (temp[0] == NULL || temp[1] == NULL)
return (printf("TEMP NULL\n"), ERROR);
insert_hashmap_env(env, temp[0], temp[1]);
hmap_insert_env(env, temp[0], temp[1]);
i++;
}
return (NO_ERROR);
@ -172,7 +170,7 @@ void exec_shcat(t_utils *shcat)
{
t_i32 ret;
print_node_data(&shcat->current_node, 0);
// print_node_data(&shcat->current_node, 0);
handle_program(&shcat->current_node, shcat, &ret);
free_node(shcat->current_node);
(void)ret;
@ -193,24 +191,6 @@ void ft_take_args(t_utils *shcat)
}
}
void ft_find_path(t_str arge[], t_utils *utils)
{
t_i32 i;
i = 0;
while (arge[i] != NULL)
{
if (arge[i][0] == 'P' && arge[i][1] == 'A' && arge[i][2] == 'T' &&
arge[i][3] == 'H' && arge[i][4] == '=')
{
utils->path = ft_split(arge[i] + 5, ':');
return;
}
i++;
}
utils->path = ft_split(PATH_FILES, ':');
}
t_language *tree_sitter_bash(void);
t_parser create_myparser(void)
@ -237,14 +217,12 @@ t_i32 main(t_i32 argc, t_str argv[], t_str envp[])
(void)argv;
(void)envp;
if (install_signal())
return (1);
me_abort("Unable to install signals");
utils = (t_utils){};
utils.parser = create_myparser();
utils.env = create_env_map();
// if (install_signal())
// return (1);
if (populate_env(utils.env, envp))
me_abort("unable to build ENV hashmap");
me_abort("Unable to build env hashmap");
utils.name_shell = "\001\x1B[93m\002"
"42sh"
"\001\x1B[32m\002"

View file

@ -11,9 +11,9 @@
/* ************************************************************************** */
#include "app/node.h"
#include "me/mem/mem_alloc.h"
#include "me/mem/mem_alloc_array.h"
#include "me/string/str_l_copy.h"
#include "me/mem/mem.h"
#include "me/mem/mem.h"
#include "me/str/str.h"
#include "parser/api.h"
#include <stdio.h>