-
Notifications
You must be signed in to change notification settings - Fork 0
/
dollar_herdo2.c
86 lines (82 loc) · 2.4 KB
/
dollar_herdo2.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* dollar_herdo2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: zwalad <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/08/21 00:40:27 by zwalad #+# #+# */
/* Updated: 2022/08/25 01:27:05 by zwalad ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
t_list *dollar_init_h(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 = dollar_init1_h(p);
if (p->line2[p->i] == '"')
p = dollar_init2_h(p);
if (p->line2[p->i] == '$')
p = grep_dollar_h(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_h(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->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_h(p);
if (p->line2[p->i] == '\'')
{
p->line = put_char(p->line, p->line2[p->i++]);
break ;
}
}
return (p);
}
t_list *dollar_init2_h(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_h(p);
if (p->line2[p->i] == '"')
{
p->line = put_char(p->line, p->line2[p->i++]);
break ;
}
}
return (p);
}