-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils_export_bis.c
64 lines (57 loc) · 1.8 KB
/
utils_export_bis.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utils_export_bis.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: zhabri <zhabri@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/06 10:38:28 by zhabri #+# #+# */
/* Updated: 2023/01/12 13:17:06 by zhabri ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
bool plus_end_str(char *str)
{
int i;
i = 0;
while (str && str[i] && str[i + 1])
i++;
if (str && str[i] == '+')
return (true);
return (false);
}
void free_and_set_exit_ret(char **var_split, int ret)
{
free_tab(var_split);
g_glob->exit_ret = ret;
}
void init_new_var(bool plus_char, char *var, char **var_split)
{
char *tmp;
if (!plus_char)
ft_lstadd_back(g_glob->envp, ft_lstnew(ft_strdup(var)));
else
{
tmp = ft_strjoin(var_split[0], var_split[1]);
ft_lstadd_back(g_glob->envp, \
ft_lstnew(ft_strdup(tmp)));
free(tmp);
}
}
void edit_var(bool plus_char, char *var, char **var_split, t_list *env_cpy)
{
if (!plus_char)
{
free(env_cpy->content);
env_cpy->content = ft_strdup(var);
}
else
{
if (ft_strchr(env_cpy->content, '='))
env_cpy->content = ft_strjoinf(env_cpy->content, \
var_split[1] + 1);
else
env_cpy->content = ft_strjoinf(env_cpy->content, \
var_split[1]);
}
}