-
Notifications
You must be signed in to change notification settings - Fork 0
/
dollar_herdo1.c
92 lines (85 loc) · 2.14 KB
/
dollar_herdo1.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* dollar_herdo1.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: zwalad <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/08/21 00:41:07 by zwalad #+# #+# */
/* Updated: 2022/08/25 02:31:05 by zwalad ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
t_list *grep_dollar_h(t_list *p)
{
char *dollo;
int j;
dollo = pr_strdup("");
p->i++;
if (!pr_isalnum(p->line2[p->i]) && p->line2[p->i] != '_')
p = dollar_help_h(p);
else if (pr_alph(p->line2[p->i]) || p->line2[p->i] == '_')
{
while (pr_isalnum(p->line2[p->i]) && p->line2[p->i]
&& p->line2[p->i] != '$')
dollo = put_char(dollo, p->line2[p->i++]);
}
else
p->i++;
j = 0;
if (check_dollar_h(p, dollo))
{
while (p->valo[j])
p->line = put_char(p->line, p->valo[j++]);
free(p->valo);
}
free(dollo);
return (p);
}
int check_dollar_h(t_list *p, char *dollo)
{
int i;
int j;
t_var *tmp;
i = 0;
tmp = p->var;
if (dollo == NULL)
return (0);
j = pr_strlen(dollo);
while (p->var != NULL)
{
if (pr_strncmpp(p->var->key, dollo) == 0)
{
p->valo = pr_strdup(p->var->value);
p->var = tmp;
return (1);
}
p->var = p->var->next;
}
p->var = tmp;
return (0);
}
t_list *dollar_help_h(t_list *p)
{
int j;
char *exit;
j = 0;
p->i -= 1;
exit = ft_itoa(g_glo.exit);
if (p->line2[p->i] == '$' && p->line2[p->i + 1] == '?')
{
while (exit[j])
p->line = put_char(p->line, exit[j++]);
p->i += 2;
}
else
{
while (j < 2)
{
p->line = put_char(p->line, p->line2[p->i++]);
j++;
}
}
free(exit);
return (p);
}