From 0ebc1618575066b9973073f38656c11ed32bc667 Mon Sep 17 00:00:00 2001 From: Maieul BOYER Date: Fri, 30 Aug 2024 19:30:20 +0200 Subject: [PATCH] Updated: normed everything except the big ass file --- exec/include/exec/_run_arith.h | 6 +- exec/include/exec/builtins.h | 9 ++- exec/src/builtins/_debug.c | 8 +-- exec/src/builtins/env.c | 30 +++++++--- exec/src/builtins/export.c | 84 +++++----------------------- exec/src/run_arithmetic/arithmetic.c | 2 +- 6 files changed, 53 insertions(+), 86 deletions(-) diff --git a/exec/include/exec/_run_arith.h b/exec/include/exec/_run_arith.h index 69b6a72f..722c3db5 100644 --- a/exec/include/exec/_run_arith.h +++ b/exec/include/exec/_run_arith.h @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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 diff --git a/exec/include/exec/builtins.h b/exec/include/exec/builtins.h index 4bfa1815..0a7d7930 100644 --- a/exec/include/exec/builtins.h +++ b/exec/include/exec/builtins.h @@ -6,7 +6,7 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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 */ diff --git a/exec/src/builtins/_debug.c b/exec/src/builtins/_debug.c index f14da4eb..c8038553 100644 --- a/exec/src/builtins/_debug.c +++ b/exec/src/builtins/_debug.c @@ -6,7 +6,7 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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; diff --git a/exec/src/builtins/env.c b/exec/src/builtins/env.c index f9f7b240..47fd6f4a 100644 --- a/exec/src/builtins/env.c +++ b/exec/src/builtins/env.c @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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) { diff --git a/exec/src/builtins/export.c b/exec/src/builtins/export.c index c1255b2d..b88bdf65 100644 --- a/exec/src/builtins/export.c +++ b/exec/src/builtins/export.c @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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(\ diff --git a/exec/src/run_arithmetic/arithmetic.c b/exec/src/run_arithmetic/arithmetic.c index 2a10ddd3..37ba0be2 100644 --- a/exec/src/run_arithmetic/arithmetic.c +++ b/exec/src/run_arithmetic/arithmetic.c @@ -6,7 +6,7 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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 */ /* */ /* ************************************************************************** */