-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexport2.c
97 lines (86 loc) · 1.81 KB
/
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* export2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ethanlim <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/09/14 21:39:00 by ethanlim #+# #+# */
/* Updated: 2024/09/14 21:39:51 by ethanlim ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int total_strings(char **env)
{
int i;
i = 0;
while (env[i])
i++;
return (i);
}
void malloc_dup_env(char **dest, char **env)
{
int i;
i = 0;
while (env[i])
{
dest[i] = ft_strdup(env[i]);
i++;
}
dest[i] = NULL;
}
void sort_env(char ***envp)
{
int i;
int j;
char *temp;
char **env;
env = *envp;
i = 0;
while (env[i])
{
j = i + 1;
while (env[j])
{
if (ft_strcmp(env[i], env[j]) > 0)
{
temp = env[i];
env[i] = env[j];
env[j] = temp;
}
j++;
}
i++;
}
}
int check_str(char *str)
{
int i;
int flag;
i = 0;
flag = 0;
while (str[i])
{
if (str[i] == '=')
flag = 1;
if (ft_isalnum(str[i]) == 0 && flag == 0)
return (1);
i++;
}
if (flag == 0)
return (2);
return (0);
}
int print_sorted_env(char **tempenv)
{
int i;
i = 0;
sort_env(&tempenv);
while (tempenv[i])
{
printf("declare -x %s\n", tempenv[i]);
i++;
}
free_2d_array(tempenv);
return (0);
}