-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_utils23.c
99 lines (93 loc) · 2.31 KB
/
ft_utils23.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
98
99
#include "minishell.h"
void parsing_dol_2(t_struct *d, t_list *l)
{
if (d->l.line[d->l.i] && d->l.line[d->l.i] == '\''
&& d->l.line[d->l.i + 1])
{
d->l.i++;
while (d->l.line[d->l.i] && d->l.line[d->l.i] != '\'')
{
if (d->l.line[d->l.i] == '<' || d->l.line[d->l.i] == '>')
d->l.chev_echo = 1;
d->l.tmp = cat_char_malloc(d->l.tmp, d->l.line[d->l.i++]);
}
}
else if (d->l.line[d->l.i] && d->l.line[d->l.i] == '"'
&& d->l.line[d->l.i + 1])
parsing_dol_5(d, l);
else
parsing_dol_4(d, l);
}
void parsing_dol_3(t_struct *d)
{
d->l.teub = ft_itoa(d, g_global.g_build_error_exec);
d->l.sub = ft_itoa(d, g_global.g_build_error_exec);
d->l.tmp2 = ft_strjoin(d->l.tmp, d->l.sub);
free_str(d->l.sub);
free_str(d->l.tmp);
d->l.tmp = d->l.tmp2;
free_str(d->l.teub);
d->l.i++;
}
void parsing_dol_6(t_struct *d, t_list *l, int count)
{
d->l.i++;
while (d->l.line[d->l.i] && d->l.line[d->l.i] != '$'
&& d->l.line[d->l.i] != ' ')
{
count++;
d->l.i++;
}
d->l.sub = ft_substr(d->l.line, d->l.i - count, count);
d->l.env = search_env(l, d->l.sub);
if (d->l.env != NULL)
{
d->l.tmp2 = ft_strjoin(d->l.tmp, d->l.env);
free_str(d->l.tmp);
d->l.tmp = d->l.tmp2;
}
free_str(d->l.env);
free_str(d->l.sub);
d->l.i--;
}
void parsing_dol_4(t_struct *d, t_list *l)
{
int count;
count = 0;
if (d->l.line[d->l.i] == '<' || d->l.line[d->l.i] == '>')
d->l.chev_echo = 0;
if (d->l.line[d->l.i] == '$' && d->l.line[d->l.i + 1]
&& d->l.line[d->l.i + 1] == '?')
parsing_dol_3(d);
else if (d->l.line[d->l.i] == '$' && d->l.line[d->l.i + 1])
parsing_dol_6(d, l, count);
else if (d->l.line[d->l.i] && d->l.line[d->l.i] == ' ')
{
d->l.tmp = cat_char_malloc(d->l.tmp, d->l.line[d->l.i++]);
while (d->l.line[d->l.i] && d->l.line[d->l.i] == ' ')
d->l.i++;
d->l.i--;
}
else
d->l.tmp = cat_char_malloc(d->l.tmp, d->l.line[d->l.i]);
}
void parsing_dol_5(t_struct *d, t_list *l)
{
d->l.i++;
while (d->l.line[d->l.i] && d->l.line[d->l.i] != '"')
{
d->l.c = 0;
if (d->l.line[d->l.i] == '<' || d->l.line[d->l.i] == '>')
d->l.chev_echo = 1;
if (d->l.line[d->l.i] == '$' && d->l.line[d->l.i + 1]
&& d->l.line[d->l.i + 1] == '?')
{
parsing_dol_3(d);
d->l.i++;
}
else if (d->l.line[d->l.i] == '$')
parsing_dol_7(d, l);
else
d->l.tmp = cat_char_malloc(d->l.tmp, d->l.line[d->l.i++]);
}
}