Updated: normed everything except the big ass file

This commit is contained in:
Maieul BOYER 2024-08-30 19:30:20 +02:00
parent fa5990b00c
commit 0ebc161857
No known key found for this signature in database
6 changed files with 53 additions and 86 deletions

View file

@ -6,7 +6,7 @@
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/27 21:13:15 by rparodi #+# #+# */
/* Updated: 2024/08/14 16:38:32 by rparodi ### ########.fr */
/* Updated: 2024/08/30 19:29:43 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
@ -54,4 +54,8 @@ t_ast_node _arith_postfix_to_ast_node(t_ast_arithmetic_postfix *self);
t_ast_node _arith_ternary_to_ast_node(t_ast_arithmetic_ternary *self);
t_ast_node _arith_unary_to_ast_node(t_ast_arithmetic_unary *self);
t_error _unary_get_op(t_ast_arithmetic_operator op, t_arith_op_func *out);
t_error _binary_get_op(t_ast_arithmetic_operator op, t_arith_op_func *out);
t_error _postfix_get_op(t_ast_arithmetic_operator op, t_arith_op_func *out);
#endif

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/30 19:12:38 by maiboyer #+# #+# */
/* Updated: 2024/08/30 19:13:26 by maiboyer ### ########.fr */
/* Updated: 2024/08/30 19:25:57 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
@ -16,4 +16,11 @@
# include "exec/_builtins.h"
# include "exec/_builtins_func.h"
struct s_assign_export_state
{
t_state *state;
t_builtin_spawn_info *info;
t_error err;
};
#endif /* BUILTINS_H */

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/10 18:43:18 by maiboyer #+# #+# */
/* Updated: 2024/08/30 16:51:53 by rparodi ### ########.fr */
/* Updated: 2024/08/30 19:17:18 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
@ -17,9 +17,7 @@
#include "me/string/string.h"
#include "me/types.h"
/*#define DEBUG_USAGE\*/
/* "Usage:\n"\*/
/* " - print_fd: print the opened file descritors informations"*/
#define USG "Usage:\n - print_fd: print the opened file descritors informations"
static t_error _debug_fd(\
t_state *state, t_builtin_spawn_info info, t_i32 *exit_code)
@ -50,7 +48,7 @@ t_error builtin_debug_(\
t_state *state, t_builtin_spawn_info info, t_i32 *exit_code)
{
if (info.args.len != 2)
return (me_printf_fd(info.stdout, DEBUG_USAGE), *exit_code = 1, ERROR);
return (me_printf_fd(info.stdout, USG), *exit_code = 1, ERROR);
if (str_compare(info.args.buffer[1], "print_fd"))
return (_debug_fd(state, info, exit_code));
*exit_code = 2;

View file

@ -6,7 +6,7 @@
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/07 14:22:50 by rparodi #+# #+# */
/* Updated: 2024/08/30 17:53:25 by rparodi ### ########.fr */
/* Updated: 2024/08/30 19:23:36 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
@ -16,7 +16,11 @@
#include "me/str/str.h"
#include "me/types.h"
static t_error _append_key_to_vec(\
t_error _append_key_to_vec(t_usize _, const t_str *key, t_str *v, void *vec);
bool _sort_str(t_str *_lhs, t_str *_rhs);
t_error get_uniq_keys(t_state *state, t_vec_str *out);
t_error _append_key_to_vec(\
t_usize _idx, const t_str *key, t_str *value, void *vec)
{
(void)(value);
@ -27,7 +31,7 @@ static t_error _append_key_to_vec(\
return (NO_ERROR);
}
static bool _sort_str(t_str *_lhs, t_str *_rhs)
bool _sort_str(t_str *_lhs, t_str *_rhs)
{
t_str lhs;
t_str rhs;
@ -48,13 +52,11 @@ static bool _sort_str(t_str *_lhs, t_str *_rhs)
return (*lhs < *rhs);
}
t_error builtin_env___(\
t_state *state, t_builtin_spawn_info info, t_i32 *exit_code)
t_error get_uniq_keys(t_state *state, t_vec_str *out)
{
t_usize i;
t_vec_str keys;
t_vec_str keys_uniq;
t_usize i;
t_str *value;
keys = vec_str_new(16, NULL);
hmap_env_iter(state->env, _append_key_to_vec, &keys);
@ -62,7 +64,7 @@ t_error builtin_env___(\
keys_uniq = vec_str_new(keys.len, NULL);
i = 0;
if (keys.len == 0)
return (NO_ERROR);
return (vec_str_free(keys), *out = keys_uniq, NO_ERROR);
vec_str_sort(&keys, _sort_str);
while (i < keys.len)
{
@ -73,6 +75,18 @@ t_error builtin_env___(\
i++;
}
vec_str_free(keys);
return (*out = keys_uniq, NO_ERROR);
}
t_error builtin_env___(\
t_state *state, t_builtin_spawn_info info, t_i32 *exit_code)
{
t_usize i;
t_str *value;
t_vec_str keys_uniq;
if (get_uniq_keys(state, &keys_uniq))
return (ERROR);
i = 0;
while (i < keys_uniq.len)
{

View file

@ -6,7 +6,7 @@
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/07 14:13:41 by rparodi #+# #+# */
/* Updated: 2024/08/30 16:59:21 by rparodi ### ########.fr */
/* Updated: 2024/08/30 19:25:49 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
@ -18,12 +18,9 @@
#include "me/types.h"
#include "me/vec/vec_str.h"
struct s_assign_export_state
{
t_state *state;
t_builtin_spawn_info *info;
t_error err;
};
t_error _append_key_to_vec(t_usize _, const t_str *key, t_str *v, void *vec);
bool _sort_str(t_str *_lhs, t_str *_rhs);
t_error get_uniq_keys(t_state *state, t_vec_str *out);
static void _assign_export(t_usize idx, t_str *arg, void *vctx)
{
@ -44,38 +41,6 @@ static void _assign_export(t_usize idx, t_str *arg, void *vctx)
ctx->err = ERROR;
}
static t_error _append_key_to_vec(\
t_usize _idx, const t_str *key, t_str *value, void *vec)
{
(void)(value);
(void)(_idx);
if (key == NULL || *key == NULL)
return (NO_ERROR);
vec_str_push(vec, *key);
return (NO_ERROR);
}
static bool _sort_str(t_str *_lhs, t_str *_rhs)
{
t_str lhs;
t_str rhs;
if (_lhs == NULL && _rhs != NULL)
return (true);
if (_lhs != NULL && _rhs == NULL)
return (true);
if (_lhs == NULL && _rhs == NULL)
return (false);
lhs = *_lhs;
rhs = *_rhs;
while (*lhs && *lhs == *rhs)
{
lhs++;
rhs++;
}
return (*lhs < *rhs);
}
static t_error handle_quotes(t_str raw, t_string *out)
{
t_usize i;
@ -99,51 +64,30 @@ static t_error handle_quotes(t_str raw, t_string *out)
t_error _print_export_env(\
t_state *state, t_builtin_spawn_info info, t_i32 *exit_code)
{
t_vec_str keys;
t_vec_str keys_uniq;
t_vec_str uniq;
t_usize i;
t_str *value;
t_string buf;
keys = vec_str_new(16, NULL);
hmap_env_iter(state->env, _append_key_to_vec, &keys);
hmap_env_iter(state->tmp_var, _append_key_to_vec, &keys);
keys_uniq = vec_str_new(keys.len, NULL);
if (get_uniq_keys(state, &uniq))
return (ERROR);
i = 0;
if (keys.len == 0)
return (NO_ERROR);
vec_str_sort(&keys, _sort_str);
while (i < keys.len)
while (i < uniq.len)
{
while (i < keys.len - 1 && \
str_compare(keys.buffer[i], keys.buffer[i + 1]))
i++;
vec_str_push(&keys_uniq, keys.buffer[i]);
i++;
}
vec_str_free(keys);
i = 0;
while (i < keys_uniq.len)
{
value = hmap_env_get(state->tmp_var, &keys_uniq.buffer[i]);
value = hmap_env_get(state->tmp_var, &uniq.buffer[i]);
if (value == NULL)
value = hmap_env_get(state->env, &keys_uniq.buffer[i]);
value = hmap_env_get(state->env, &uniq.buffer[i]);
if (value == NULL || *value == NULL)
me_printf_fd(info.stdout, "export %s\n", keys_uniq.buffer[i]);
me_printf_fd(info.stdout, "export %s\n", uniq.buffer[i]);
else
{
if (!handle_quotes(*value, &buf))
{
me_printf_fd(\
info.stdout, "export %s='%s'\n", keys_uniq.buffer[i], buf.buf);
string_free(buf);
}
(me_printf_fd(\
info.stdout, "export %s='%s'\n", uniq.buffer[i], buf.buf), string_free(buf));
}
i++;
}
vec_str_free(keys_uniq);
*exit_code = 0;
return (NO_ERROR);
return (vec_str_free(uniq), *exit_code = 0, NO_ERROR);
}
t_error builtin_export(\

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/26 15:14:50 by maiboyer #+# #+# */
/* Updated: 2024/08/30 18:02:38 by rparodi ### ########.fr */
/* Updated: 2024/08/30 19:26:44 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */