-
Notifications
You must be signed in to change notification settings - Fork 0
/
expansions_vars_2.c
58 lines (53 loc) · 1.74 KB
/
expansions_vars_2.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* expansions_vars_1.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ngasco <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/14 11:27:49 by ngasco #+# #+# */
/* Updated: 2022/03/14 11:27:51 by ngasco ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
/* Look for env vars declarations separated by quotes expansion */
int ft_find_quoted_vars(t_cdata *t_cdata)
{
struct s_tnode *curr;
curr = t_cdata->tokens_list;
while (1)
{
if (curr->str[curr->len - 1] == '=')
{
if (curr->next)
{
ft_join_var_name_value(curr);
return (1);
}
}
if (curr->next == NULL)
break ;
else
curr = curr->next;
}
return (0);
}
/* Join the two nodes making up the env var declaration */
void ft_join_var_name_value(struct s_tnode *curr)
{
char *str_temp;
struct s_tnode *node_temp;
str_temp = ft_strjoin(curr->str, curr->next->str);
free(curr->str);
curr->str = str_temp;
curr->len = ft_strlen(str_temp);
if (curr->next->next)
node_temp = curr->next->next;
else
node_temp = NULL;
if (node_temp)
node_temp->prev = curr;
free(curr->next->str);
free(curr->next);
curr->next = node_temp;
}