-
Notifications
You must be signed in to change notification settings - Fork 1
/
export_two.c
87 lines (80 loc) · 1.2 KB
/
export_two.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
#include "minishell.h"
int check_exsyn(char *src)
{
int i;
if (src[0] == '_' || ft_isalpha(src[0]))
{
i = 1;
while (src[i] != '=' && src[i])
{
if (!ft_isalnum(src[i]) && src[i] != '_')
return (1);
i++;
}
}
else
return (1);
return (0);
}
int ft_alloc_count(char **envp, char **args)
{
int i;
int j;
i = 0;
j = 0;
while (envp[i])
i++;
while (args[j] != NULL)
{
if (ft_search(envp, args[j]))
i++;
j++;
}
return (i);
}
void free2DArray(char **array)
{
int i;
i = 0;
while (array[i] != NULL)
{
free(array[i]);
i++;
}
free(array);
}
void ft_expn_add_two(char **tmp1, char **tmp2, int option, int i)
{
if (option == 1)
{
while (tmp1[i] != NULL && tmp1[i][0] != 0)
{
free(tmp1[i]);
i++;
}
free(tmp1);
i = 0;
while (tmp2[i] != NULL && tmp2[i][0] != 0)
{
free(tmp2[i]);
i++;
}
free(tmp2);
}
else if (option == 2)
{
while (tmp1[i] != NULL)
{
free(tmp1[i]);
i++;
}
free(tmp1);
}
}
void ft_expn_add_else(char *add, t_source *src, char **args)
{
src->export = our_realloc(src->export,
sizeof(char *) * (ft_alloc_count(src->export, args) + 2));
src->export[src->lastexp++] = ft_strdup(add);
src->export[src->lastexp] = NULL;
}