Called the function to handle single quotes in the export builtin

This commit is contained in:
Maix0 2024-08-18 21:52:07 +02:00
parent 7329c95ba0
commit 1d4ff310d0

View file

@ -6,7 +6,7 @@
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/07 14:13:41 by rparodi #+# #+# */
/* Updated: 2024/08/18 18:06:32 by rparodi ### ########.fr */
/* Updated: 2024/08/18 21:51:31 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
@ -109,16 +109,14 @@ t_error handle_quotes(t_str raw, t_string *out)
if (!raw)
return (ERROR);
ret = string_new(16);
string_push_char(&ret, '\'');
while (raw[i] != '\0')
{
if (raw[i] == '\'')
string_push(&ret, "'\"'\"'");
printf("Pushing stuff\n"), string_push(&ret, "'\"'\"'");
else
string_push_char(&ret, raw[i]);
i++;
}
string_push_char(&ret, '\'');
return (*out = ret, NO_ERROR);
}
@ -152,9 +150,19 @@ t_error _print_export_env(t_state *state, t_builtin_spawn_info info, t_i32 *exit
value = hmap_env_get(state->tmp_var, &keys_uniq.buffer[i]);
if (value == NULL)
value = hmap_env_get(state->env, &keys_uniq.buffer[i]);
if (*value == NULL)
me_printf_fd(info.stdout, "export %s=''\n", keys_uniq.buffer[i]);
me_printf_fd(info.stdout, "export %s='%s'\n", keys_uniq.buffer[i], *value);
if (value == NULL || *value == NULL)
{
me_printf_fd(info.stdout, "export %s\n", keys_uniq.buffer[i]);
}
else
{
t_string buf;
if (!handle_quotes(*value, &buf))
{
me_printf_fd(info.stdout, "export %s='%s'\n", keys_uniq.buffer[i], buf.buf);
string_free(buf);
}
}
i++;
}
vec_str_free(keys_uniq);