-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdollar2.c
86 lines (82 loc) · 2.46 KB
/
dollar2.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* dollar2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: zwalad <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/08/03 12:11:59 by zwalad #+# #+# */
/* Updated: 2022/08/23 22:36:21 by zwalad ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
t_list *dollar_init(t_list *p)
{
p->l = 1;
p->k = 1;
p->i = 0;
if (p->line2)
{
while (p->line2[p->i])
{
if (p->line2[p->i] == '$' && p->line2[p->i + 1] == '$')
p->line = put_char(p->line, p->line2[p->i++]);
else if (p->line2[p->i] == '\'')
p = dollar_init1(p);
else if (p->line2[p->i] == '"')
p = dollar_init2(p);
else if (p->line2[p->i] == '$' && p->line2[p->i + 1] != '$')
p = grep_dollar(p);
else if (p->line2[p->i] && p->line2[p->i] != '"'
&& p->line2[p->i] != '\'')
p->line = put_char(p->line, p->line2[p->i++]);
}
}
return (p);
}
t_list *dollar_init1(t_list *p)
{
p->line = put_char(p->line, p->line2[p->i++]);
if (p->line2[p->i] == '\'')
{
p->line = put_char(p->line, p->line2[p->i++]);
p->l = 0;
}
else
p->l = 1;
while (p->line2[p->i] != '\'' && p->line2[p->i] && p->l)
{
if (p->line2[p->i] != '\'' && p->line2[p->i])
p->line = put_char(p->line, p->line2[p->i++]);
if (p->line2[p->i] == '\'')
{
p->line = put_char(p->line, p->line2[p->i++]);
break ;
}
}
return (p);
}
t_list *dollar_init2(t_list *p)
{
p->line = put_char(p->line, p->line2[p->i++]);
if (p->line2[p->i] == '"')
{
p->line = put_char(p->line, p->line2[p->i++]);
p->k = 0;
}
else
p->k = 1;
while (p->line2[p->i] != '"' && p->line2[p->i] && p->k)
{
if (p->line2[p->i] != '"' && p->line2[p->i] != '$' && p->line2[p->i])
p->line = put_char(p->line, p->line2[p->i++]);
if (p->line2[p->i] == '$')
p = grep_dollar(p);
if (p->line2[p->i] == '"')
{
p->line = put_char(p->line, p->line2[p->i++]);
break ;
}
}
return (p);
}