-
Notifications
You must be signed in to change notification settings - Fork 1
/
builtin_export2.c
52 lines (48 loc) · 1004 Bytes
/
builtin_export2.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdbool.h>
#include "libft/libft.h"
#include "builtin.h"
#include "env.h"
#include "minishell.h"
#include "utils.h"
static void print_escaped_value(char *str)
{
int i;
i = 0;
while (str[i])
{
if (str[i] == '"' || str[i] == '$' || str[i] == '`' || str[i] == '\\')
{
ft_putchar_fd('\\', STDOUT_FILENO);
ft_putchar_fd(str[i], STDOUT_FILENO);
}
else
ft_putchar_fd(str[i], STDOUT_FILENO);
i++;
}
}
int print_envs_with_declaration(void)
{
t_var *tmp_var;
tmp_var = g_shell.vars;
while (tmp_var)
{
if (!tmp_var->is_shell_var)
{
write(STDOUT_FILENO, "declare -x ", 11);
write(STDOUT_FILENO, tmp_var->key, ft_strlen(tmp_var->key));
if (tmp_var->value)
{
write(STDOUT_FILENO, "=", 1);
write(STDOUT_FILENO, "\"", 1);
print_escaped_value((char *)tmp_var->value);
write(STDOUT_FILENO, "\"", 1);
}
write(STDOUT_FILENO, "\n", 1);
}
tmp_var = tmp_var->next;
}
return (0);
}