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> +#+ +:+ +#+ */
|
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/05/14 18:02:12 by maiboyer #+# #+# */
|
/* Created: 2024/05/14 18:02:12 by maiboyer #+# #+# */
|
||||||
/* Updated: 2024/05/18 16:36:55 by maiboyer ### ########.fr */
|
/* Updated: 2024/05/18 18:22:32 by maiboyer ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -232,7 +232,7 @@ t_error alloc_new_page(struct s_allocator_melloc *alloc, t_usize page_size)
|
||||||
|
|
||||||
void *m_alloc_error(struct s_allocator_melloc *self, t_str msg)
|
void *m_alloc_error(struct s_allocator_melloc *self, t_str msg)
|
||||||
{
|
{
|
||||||
(void)(self);
|
self->uninit((void *)self);
|
||||||
me_abort(msg);
|
me_abort(msg);
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
|
|
@ -294,7 +294,7 @@ void *m_realloc(struct s_allocator_melloc *self, void *ptr, t_usize size)
|
||||||
old_size = chunk->size;
|
old_size = chunk->size;
|
||||||
chunk->size += next->size + sizeof(*next);
|
chunk->size += next->size + sizeof(*next);
|
||||||
vg_mem_defined(next, next->size + sizeof(*next));
|
vg_mem_defined(next, next->size + sizeof(*next));
|
||||||
//mem_set_zero(next, next->size + sizeof(*next));
|
mem_set_zero(next, next->size + sizeof(*next));
|
||||||
vg_block_resize((void *)chunk + sizeof(*chunk), old_size,
|
vg_block_resize((void *)chunk + sizeof(*chunk), old_size,
|
||||||
chunk->size);
|
chunk->size);
|
||||||
vg_mem_no_access(chunk, sizeof(*chunk));
|
vg_mem_no_access(chunk, sizeof(*chunk));
|
||||||
|
|
|
||||||
4
output/src/hashmap/env/env.c
vendored
4
output/src/hashmap/env/env.c
vendored
|
|
@ -111,5 +111,9 @@ void insert_hashmap_env(t_hashmap_env *hmap, t_str key,
|
||||||
prev->next = entry;
|
prev->next = entry;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
hmap->drop(entry->kv);
|
||||||
|
entry->kv.key = key;
|
||||||
entry->kv.val = value;
|
entry->kv.val = value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@
|
||||||
#define STACK_VERSION_NONE ((t_stack_version)-1)
|
#define STACK_VERSION_NONE ((t_stack_version)-1)
|
||||||
#define TS_DECODE_ERROR (-1)
|
#define TS_DECODE_ERROR (-1)
|
||||||
|
|
||||||
#if false
|
#if true
|
||||||
# undef malloc
|
# undef malloc
|
||||||
# undef calloc
|
# undef calloc
|
||||||
# undef realloc
|
# undef realloc
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/05/04 18:32:50 by maiboyer #+# #+# */
|
/* 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/buffered_str/buf_str.h"
|
||||||
#include "me/hash/hasher.h"
|
#include "me/hash/hasher.h"
|
||||||
#include "me/hashmap/hashmap_env.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_compare.h"
|
||||||
|
#include "me/string/str_len.h"
|
||||||
#include "me/types.h"
|
#include "me/types.h"
|
||||||
#include "me/vec/vec_str.h"
|
#include "me/vec/vec_str.h"
|
||||||
#include "me/mem/mem.h"
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
static void _hash_str(t_hasher *hasher, t_str *s)
|
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)
|
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)
|
static void _free_env(t_kv_env kv)
|
||||||
{
|
{
|
||||||
if (kv.key)
|
if (kv.key)
|
||||||
free(kv.key);
|
mem_free(kv.key);
|
||||||
if (kv.val)
|
if (kv.val)
|
||||||
free(kv.val);
|
mem_free(kv.val);
|
||||||
}
|
}
|
||||||
|
|
||||||
t_hashmap_env *create_env_map(void)
|
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)
|
void *ctx)
|
||||||
{
|
{
|
||||||
struct s_build_envp_state *s;
|
struct s_build_envp_state *s;
|
||||||
|
t_str push;
|
||||||
|
|
||||||
(void)(idx);
|
(void)(idx);
|
||||||
s = ctx;
|
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))
|
push_str_buffer(&s->buf, *val))
|
||||||
return (vec_str_free(s->out), ERROR);
|
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);
|
return (str_free(s->buf), ERROR);
|
||||||
s->buf = alloc_new_buffer(50);
|
str_clear(&s->buf);
|
||||||
return (NO_ERROR);
|
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;
|
struct s_build_envp_state state;
|
||||||
|
|
||||||
state.out = vec_str_new(envs->num_buckets, (void (*)(t_str))mem_free);
|
state.buf = alloc_new_buffer(8096);
|
||||||
state.buf = alloc_new_buffer(50);
|
state.out = vec_str_new(1024, (void (*)(t_str))mem_free);
|
||||||
if (hashmap_env_iter(envs, _build_envp_iterator, &state))
|
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))
|
if (vec_str_push(&state.out, NULL))
|
||||||
return (ERROR);
|
return (str_free(state.buf), printf("coun't push null\n"), ERROR);
|
||||||
*envp = state.out;
|
*envp = state.out;
|
||||||
str_free(state.buf);
|
str_free(state.buf);
|
||||||
return (NO_ERROR);
|
return (NO_ERROR);
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/05/09 15:00:53 by rparodi #+# #+# */
|
/* 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_spawn_info spawn_info;
|
||||||
t_str tmp;
|
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)
|
if (self->kind != sym_command)
|
||||||
return (ERROR);
|
return (ERROR);
|
||||||
i = 0;
|
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)
|
if (self->childs[i].kind == sym_command_name)
|
||||||
{
|
{
|
||||||
spawn_info.binary_path = str_clone(node_getstr(&self->childs[i]));
|
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]);
|
printf("%s\n", spawn_info.arguments.buffer[0]);
|
||||||
}
|
}
|
||||||
else if (self->childs[i].kind == sym_file_redirect)
|
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++;
|
i++;
|
||||||
}
|
}
|
||||||
printf("%zu\n", spawn_info.arguments.len);
|
// printf("%zu\n", spawn_info.arguments.len);
|
||||||
vec_str_push(&spawn_info.arguments, NULL);
|
vec_str_push(&spawn_info.arguments, NULL);
|
||||||
for (i = 0; i < spawn_info.arguments.len; i++)
|
// for (i = 0; i < spawn_info.arguments.len; i++)
|
||||||
printf("[%zu]\t%s\n", i, spawn_info.arguments.buffer[i]);
|
// printf("[%zu]\t%s\n", i, spawn_info.arguments.buffer[i]);
|
||||||
spawn_info.stdin = inherited();
|
spawn_info.stdin = inherited();
|
||||||
spawn_info.stdout = inherited();
|
spawn_info.stdout = inherited();
|
||||||
spawn_info.stderr = inherited();
|
spawn_info.stderr = inherited();
|
||||||
spawn_info.forked_free = NULL;
|
spawn_info.forked_free = NULL;
|
||||||
|
printf("building envp\n");
|
||||||
if (build_envp(shcat->env, &spawn_info.environement))
|
if (build_envp(shcat->env, &spawn_info.environement))
|
||||||
return (vec_str_free(spawn_info.arguments), ERROR);
|
return (vec_str_free(spawn_info.arguments), ERROR);
|
||||||
if (spawn_process(spawn_info, &shcat->ret))
|
if (spawn_process(spawn_info, &shcat->ret))
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/03/29 11:35:51 by rparodi #+# #+# */
|
/* 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 ft_free_utils(t_utils *s)
|
||||||
{
|
{
|
||||||
(void)(s);
|
|
||||||
if (s->str_input)
|
if (s->str_input)
|
||||||
free(s->str_input);
|
free(s->str_input);
|
||||||
if (s->path)
|
if (s->path)
|
||||||
ft_free_strs(s->path);
|
ft_free_strs(s->path);
|
||||||
if (s->env)
|
if (s->env)
|
||||||
|
{
|
||||||
|
printf("Dropping HashMap\n");
|
||||||
drop_hashmap_env(s->env);
|
drop_hashmap_env(s->env);
|
||||||
|
}
|
||||||
ts_parser_delete(s->parser.parser);
|
ts_parser_delete(s->parser.parser);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/03/28 14:40:38 by rparodi #+# #+# */
|
/* 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/hashmap/hashmap_env.h"
|
||||||
#include "me/mem/mem.h"
|
#include "me/mem/mem.h"
|
||||||
#include "me/string/str_len.h"
|
#include "me/string/str_len.h"
|
||||||
|
#include "me/string/str_split.h"
|
||||||
|
#include "me/string/str_substring.h"
|
||||||
#include "me/types.h"
|
#include "me/types.h"
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
#include "parser/api.h"
|
#include "parser/api.h"
|
||||||
#include <sys/_types/_null.h>
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include "me/string/str_split.h"
|
|
||||||
#include "me/mem/mem.h"
|
|
||||||
|
|
||||||
#undef free
|
#undef free
|
||||||
#undef malloc
|
#undef malloc
|
||||||
|
|
@ -45,22 +44,40 @@ void ts_parser_set_language(t_first_parser *self, t_language *lang);
|
||||||
// cle avant le =
|
// cle avant le =
|
||||||
// data apres le =
|
// data apres le =
|
||||||
|
|
||||||
|
t_error split_str_first(t_const_str s, char splitter, t_str *before,
|
||||||
|
t_str *after)
|
||||||
|
{
|
||||||
|
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_error populate_env(t_hashmap_env *env, t_str envp[])
|
||||||
{
|
{
|
||||||
t_usize i;
|
t_usize i;
|
||||||
t_str *temp;
|
t_str temp[2];
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
temp = NULL;
|
|
||||||
if (envp == NULL || env == NULL)
|
if (envp == NULL || env == NULL)
|
||||||
return (ERROR);
|
return (printf("given a nullptr\n"), ERROR);
|
||||||
while (envp[i] != NULL)
|
while (envp[i] != NULL)
|
||||||
{
|
{
|
||||||
temp = str_split(envp[i], '=');
|
if (split_str_first(envp[i], '=', &temp[0], &temp[1]))
|
||||||
if (temp[0] == NULL || temp[1] == NULL)
|
|
||||||
return (ERROR);
|
return (ERROR);
|
||||||
|
if (temp[0] == NULL || temp[1] == NULL)
|
||||||
|
return (printf("TEMP NULL\n"), ERROR);
|
||||||
insert_hashmap_env(env, temp[0], temp[1]);
|
insert_hashmap_env(env, temp[0], temp[1]);
|
||||||
mem_free(temp);
|
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
return (NO_ERROR);
|
return (NO_ERROR);
|
||||||
|
|
@ -224,8 +241,10 @@ t_i32 main(t_i32 argc, t_str argv[], t_str envp[])
|
||||||
utils = (t_utils){};
|
utils = (t_utils){};
|
||||||
utils.parser = create_myparser();
|
utils.parser = create_myparser();
|
||||||
utils.env = create_env_map();
|
utils.env = create_env_map();
|
||||||
if (install_signal())
|
// if (install_signal())
|
||||||
return (1);
|
// return (1);
|
||||||
|
if (populate_env(utils.env, envp))
|
||||||
|
me_abort("unable to build ENV hashmap");
|
||||||
utils.name_shell = "\001\x1B[93m\002"
|
utils.name_shell = "\001\x1B[93m\002"
|
||||||
"42sh"
|
"42sh"
|
||||||
"\001\x1B[32m\002"
|
"\001\x1B[32m\002"
|
||||||
|
|
|
||||||
|
|
@ -111,5 +111,9 @@ void insert_hashmap_C__PREFIX__(t_hashmap_C__PREFIX__ *hmap, C__KEYTYPE__ key,
|
||||||
prev->next = entry;
|
prev->next = entry;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
hmap->drop(entry->kv);
|
||||||
|
entry->kv.key = key;
|
||||||
entry->kv.val = value;
|
entry->kv.val = value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -34,18 +34,9 @@ t_vec_buf_str vec_buf_str_new(t_usize capacity,
|
||||||
/// Return true in case of an error
|
/// Return true in case of an error
|
||||||
t_error vec_buf_str_push(t_vec_buf_str *vec, t_buffer_str element)
|
t_error vec_buf_str_push(t_vec_buf_str *vec, t_buffer_str element)
|
||||||
{
|
{
|
||||||
size_t new_capacity;
|
|
||||||
|
|
||||||
if (vec == NULL)
|
if (vec == NULL)
|
||||||
return (ERROR);
|
return (ERROR);
|
||||||
if (vec->len + 1 > vec->capacity)
|
vec_buf_str_reserve(vec, vec->len + 1);
|
||||||
{
|
|
||||||
new_capacity = (vec->capacity * 3) / 2 + 1;
|
|
||||||
while (vec->len + 1 > new_capacity)
|
|
||||||
new_capacity = (new_capacity * 3) / 2 + 1;
|
|
||||||
vec->buffer = mem_realloc_array(vec->buffer, new_capacity, sizeof(t_buffer_str));
|
|
||||||
vec->capacity = new_capacity;
|
|
||||||
}
|
|
||||||
vec->buffer[vec->len] = element;
|
vec->buffer[vec->len] = element;
|
||||||
vec->len += 1;
|
vec->len += 1;
|
||||||
return (NO_ERROR);
|
return (NO_ERROR);
|
||||||
|
|
|
||||||
|
|
@ -34,18 +34,9 @@ t_vec_str vec_str_new(t_usize capacity,
|
||||||
/// Return true in case of an error
|
/// Return true in case of an error
|
||||||
t_error vec_str_push(t_vec_str *vec, t_str element)
|
t_error vec_str_push(t_vec_str *vec, t_str element)
|
||||||
{
|
{
|
||||||
size_t new_capacity;
|
|
||||||
|
|
||||||
if (vec == NULL)
|
if (vec == NULL)
|
||||||
return (ERROR);
|
return (ERROR);
|
||||||
if (vec->len + 1 > vec->capacity)
|
vec_str_reserve(vec, vec->len + 1);
|
||||||
{
|
|
||||||
new_capacity = (vec->capacity * 3) / 2 + 1;
|
|
||||||
while (vec->len + 1 > new_capacity)
|
|
||||||
new_capacity = (new_capacity * 3) / 2 + 1;
|
|
||||||
vec->buffer = mem_realloc_array(vec->buffer, new_capacity, sizeof(t_str));
|
|
||||||
vec->capacity = new_capacity;
|
|
||||||
}
|
|
||||||
vec->buffer[vec->len] = element;
|
vec->buffer[vec->len] = element;
|
||||||
vec->len += 1;
|
vec->len += 1;
|
||||||
return (NO_ERROR);
|
return (NO_ERROR);
|
||||||
|
|
|
||||||
|
|
@ -34,18 +34,9 @@ t_vec_u8 vec_u8_new(t_usize capacity,
|
||||||
/// Return true in case of an error
|
/// Return true in case of an error
|
||||||
t_error vec_u8_push(t_vec_u8 *vec, t_u8 element)
|
t_error vec_u8_push(t_vec_u8 *vec, t_u8 element)
|
||||||
{
|
{
|
||||||
size_t new_capacity;
|
|
||||||
|
|
||||||
if (vec == NULL)
|
if (vec == NULL)
|
||||||
return (ERROR);
|
return (ERROR);
|
||||||
if (vec->len + 1 > vec->capacity)
|
vec_u8_reserve(vec, vec->len + 1);
|
||||||
{
|
|
||||||
new_capacity = (vec->capacity * 3) / 2 + 1;
|
|
||||||
while (vec->len + 1 > new_capacity)
|
|
||||||
new_capacity = (new_capacity * 3) / 2 + 1;
|
|
||||||
vec->buffer = mem_realloc_array(vec->buffer, new_capacity, sizeof(t_u8));
|
|
||||||
vec->capacity = new_capacity;
|
|
||||||
}
|
|
||||||
vec->buffer[vec->len] = element;
|
vec->buffer[vec->len] = element;
|
||||||
vec->len += 1;
|
vec->len += 1;
|
||||||
return (NO_ERROR);
|
return (NO_ERROR);
|
||||||
|
|
|
||||||
|
|
@ -6,12 +6,13 @@
|
||||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/11/16 17:52:12 by maiboyer #+# #+# */
|
/* Created: 2023/11/16 17:52:12 by maiboyer #+# #+# */
|
||||||
/* Updated: 2024/05/14 15:33:43 by maiboyer ### ########.fr */
|
/* Updated: 2024/05/18 18:06:37 by maiboyer ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "me/mem/mem.h"
|
|
||||||
#include "me/buffered_str/buf_str.h"
|
#include "me/buffered_str/buf_str.h"
|
||||||
|
#include "me/mem/mem.h"
|
||||||
|
#include "me/mem/mem_copy.h"
|
||||||
#include "me/mem/mem_set_zero.h"
|
#include "me/mem/mem_set_zero.h"
|
||||||
#include "me/string/str_l_cat.h"
|
#include "me/string/str_l_cat.h"
|
||||||
#include "me/string/str_len.h"
|
#include "me/string/str_len.h"
|
||||||
|
|
@ -27,11 +28,15 @@ t_error str_reserve(t_buffer_str *buf, t_usize size)
|
||||||
return (ERROR);
|
return (ERROR);
|
||||||
if (buf->capacity >= size)
|
if (buf->capacity >= size)
|
||||||
return (NO_ERROR);
|
return (NO_ERROR);
|
||||||
while (size > buf->capacity)
|
new_capacity = buf->capacity;
|
||||||
new_capacity = (buf->capacity * 3) / 2 + 1;
|
while (size > new_capacity)
|
||||||
temp_buffer = mem_realloc_array(buf->buf, new_capacity, sizeof(char));
|
new_capacity = (new_capacity * 3) / 2 + 1;
|
||||||
|
temp_buffer = mem_alloc_array(new_capacity, sizeof(char));
|
||||||
if (temp_buffer == NULL)
|
if (temp_buffer == NULL)
|
||||||
return (ERROR);
|
return (ERROR);
|
||||||
|
mem_set_zero(temp_buffer, new_capacity);
|
||||||
|
mem_copy(temp_buffer, buf->buf, buf->len);
|
||||||
|
mem_free(buf->buf);
|
||||||
buf->buf = temp_buffer;
|
buf->buf = temp_buffer;
|
||||||
buf->capacity = new_capacity;
|
buf->capacity = new_capacity;
|
||||||
return (NO_ERROR);
|
return (NO_ERROR);
|
||||||
|
|
@ -46,8 +51,8 @@ t_error push_str_buffer(t_buffer_str *buf, t_const_str to_push)
|
||||||
to_push_len = str_len(to_push);
|
to_push_len = str_len(to_push);
|
||||||
if (str_reserve(buf, buf->len + to_push_len + 2))
|
if (str_reserve(buf, buf->len + to_push_len + 2))
|
||||||
return (ERROR);
|
return (ERROR);
|
||||||
buf->len += to_push_len;
|
|
||||||
str_l_cat(buf->buf, to_push, buf->capacity);
|
str_l_cat(buf->buf, to_push, buf->capacity);
|
||||||
|
buf->len += to_push_len;
|
||||||
return (NO_ERROR);
|
return (NO_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/05/14 18:26:27 by maiboyer #+# #+# */
|
/* Created: 2024/05/14 18:26:27 by maiboyer #+# #+# */
|
||||||
/* Updated: 2024/05/16 16:24:54 by maiboyer ### ########.fr */
|
/* Updated: 2024/05/18 18:48:25 by maiboyer ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -26,6 +26,7 @@ t_allocator *global_allocator(void)
|
||||||
{
|
{
|
||||||
init = true;
|
init = true;
|
||||||
global_alloc = m_init();
|
global_alloc = m_init();
|
||||||
|
// global_alloc = lc_init();
|
||||||
}
|
}
|
||||||
return (&global_alloc);
|
return (&global_alloc);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,16 +6,16 @@
|
||||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/01/03 16:22:41 by maiboyer #+# #+# */
|
/* Created: 2024/01/03 16:22:41 by maiboyer #+# #+# */
|
||||||
/* Updated: 2024/05/14 18:42:59 by maiboyer ### ########.fr */
|
/* Updated: 2024/05/18 18:33:53 by maiboyer ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "me/buffered_str/buf_str.h"
|
|
||||||
#include "me/os/pipe.h"
|
|
||||||
#include "me/os/process.h"
|
#include "me/os/process.h"
|
||||||
|
#include "me/buffered_str/buf_str.h"
|
||||||
|
#include "me/mem/mem.h"
|
||||||
|
#include "me/os/pipe.h"
|
||||||
#include "me/string/str_find_chr.h"
|
#include "me/string/str_find_chr.h"
|
||||||
#include "me/string/str_n_compare.h"
|
#include "me/string/str_n_compare.h"
|
||||||
#include "me/mem/mem.h"
|
|
||||||
#include "me/string/str_split.h"
|
#include "me/string/str_split.h"
|
||||||
#include "me/types.h"
|
#include "me/types.h"
|
||||||
#include "me/vec/vec_str.h"
|
#include "me/vec/vec_str.h"
|
||||||
|
|
@ -70,7 +70,7 @@ t_error in_path(t_spawn_info *info, t_process *process, t_const_str path,
|
||||||
push_str_buffer(s, info->binary_path);
|
push_str_buffer(s, info->binary_path);
|
||||||
sp_index++;
|
sp_index++;
|
||||||
if (access(s->buf, X_OK | R_OK) == 0)
|
if (access(s->buf, X_OK | R_OK) == 0)
|
||||||
break ;
|
break;
|
||||||
}
|
}
|
||||||
sp_index = 0;
|
sp_index = 0;
|
||||||
while (splitted_path[sp_index])
|
while (splitted_path[sp_index])
|
||||||
|
|
@ -88,13 +88,14 @@ t_error find_binary(t_spawn_info *info, t_process *process)
|
||||||
if (info->binary_path == NULL)
|
if (info->binary_path == NULL)
|
||||||
return (ERROR);
|
return (ERROR);
|
||||||
s = alloc_new_buffer(256);
|
s = alloc_new_buffer(256);
|
||||||
if (str_start_with(info->binary_path, "/")
|
if (str_start_with(info->binary_path, "/") ||
|
||||||
|| str_find_chr(info->binary_path, '/') != NULL)
|
str_find_chr(info->binary_path, '/') != NULL)
|
||||||
push_str_buffer(&s, info->binary_path);
|
push_str_buffer(&s, info->binary_path);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (vec_str_find(&info->environement, find_path, &p_idx))
|
if (vec_str_find(&info->environement, find_path, &p_idx))
|
||||||
return (str_free(s), ERROR);
|
return (str_free(s), ERROR);
|
||||||
|
printf("finding in path\n");
|
||||||
if (in_path(info, process, info->environement.buffer[p_idx], &s))
|
if (in_path(info, process, info->environement.buffer[p_idx], &s))
|
||||||
return (ERROR);
|
return (ERROR);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,12 +6,13 @@
|
||||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/01/04 22:25:44 by maiboyer #+# #+# */
|
/* Created: 2024/01/04 22:25:44 by maiboyer #+# #+# */
|
||||||
/* Updated: 2024/05/09 16:57:24 by rparodi ### ########.fr */
|
/* Updated: 2024/05/18 18:38:01 by maiboyer ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "me/types.h"
|
#include "me/types.h"
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
bool find_null(const t_str *s)
|
bool find_null(const t_str *s)
|
||||||
{
|
{
|
||||||
|
|
@ -30,7 +31,12 @@ bool str_start_with(t_const_str s, t_const_str prefix)
|
||||||
|
|
||||||
bool find_path(const t_str *s)
|
bool find_path(const t_str *s)
|
||||||
{
|
{
|
||||||
|
t_str ss;
|
||||||
|
|
||||||
if (*s == NULL)
|
if (*s == NULL)
|
||||||
return (false);
|
return (false);
|
||||||
return (str_start_with(*s, "PATH="));
|
ss = *s;
|
||||||
|
printf("%s\n", ss);
|
||||||
|
return (ss[0] == 'P' && ss[1] == 'A' && ss[2] == 'T' && ss[3] == 'H' &&
|
||||||
|
ss[4] == '=');
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue