From 1a74bb38d3ec9a30f5c824d3f6cad45f6ccbecce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl?= Date: Sun, 18 Aug 2024 18:11:32 +0200 Subject: [PATCH] Adding the simple quotes management --- exec/src/builtins/export.c | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/exec/src/builtins/export.c b/exec/src/builtins/export.c index 09b2457b..8e169b34 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/15 14:01:44 by maiboyer ### ########.fr */ +/* Updated: 2024/08/18 18:06:32 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,6 +14,7 @@ #include "me/hashmap/hashmap_env.h" #include "me/printf/printf.h" #include "me/str/str.h" +#include "me/string/string.h" #include "me/types.h" #include "me/vec/vec_str.h" @@ -22,12 +23,14 @@ struct s_print_export_state t_state *state; t_builtin_spawn_info *info; }; + struct s_assign_export_state { t_state *state; t_builtin_spawn_info *info; t_error err; }; + static void _assign_export(t_usize idx, t_str *arg, void *vctx) { struct s_assign_export_state *ctx; @@ -97,6 +100,28 @@ bool _sort_str(t_str *_lhs, t_str *_rhs) return (*lhs < *rhs); } +t_error handle_quotes(t_str raw, t_string *out) +{ + t_usize i; + t_string ret; + + i = 0; + if (!raw) + return (ERROR); + ret = string_new(16); + string_push_char(&ret, '\''); + while (raw[i] != '\0') + { + if (raw[i] == '\'') + string_push(&ret, "'\"'\"'"); + else + string_push_char(&ret, raw[i]); + i++; + } + string_push_char(&ret, '\''); + return (*out = ret, NO_ERROR); +} + t_error _print_export_env(t_state *state, t_builtin_spawn_info info, t_i32 *exit_code) { t_vec_str keys; @@ -134,7 +159,7 @@ t_error _print_export_env(t_state *state, t_builtin_spawn_info info, t_i32 *exit } vec_str_free(keys_uniq); *exit_code = 0; -return (NO_ERROR); + return (NO_ERROR); } t_error builtin_export(t_state *state, t_builtin_spawn_info info, t_i32 *exit_code)