forked from MaroIsLife/Minishell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse_two.c
77 lines (69 loc) · 1.16 KB
/
parse_two.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
#include "minishell.h"
void init_arg_pipe(char **arg, t_pipe *p, int tmp2)
{
int b;
int i;
char c;
i = 0;
b = 0;
if (tmp2 == 1)
c = 0;
else
c = 127;
while (arg[i] != NULL)
{
if (arg[i++][0] != c)
b++;
}
p->arg = malloc((b + 1) * sizeof(char *));
i = 0;
b = 0;
while (arg[i] != NULL)
{
if (arg[i][0] != c)
p->arg[b++] = ft_strdup(arg[i]);
i++;
}
p->arg[b] = NULL;
}
t_filename *new_file(char *s, t_source *src)
{
t_filename *tmp;
tmp = (t_filename *) malloc(sizeof(t_filename));
tmp->next = NULL;
tmp->filename = ft_strdup(s);
tmp->c = src->p->c;
return (tmp);
}
t_filename *get_last_node(t_filename *tmp)
{
while (tmp)
{
if (tmp->next == NULL)
return (tmp);
tmp = tmp->next;
}
return (tmp);
}
t_pipe *get_last_node_p(t_pipe *tmp)
{
while (tmp)
{
if (tmp->next == NULL)
return (tmp);
tmp = tmp->next;
}
return (tmp);
}
void init_filee(t_source *src)
{
t_filename *tmp;
if (src->npipe > 0 && src->foundred == 1 && src->ispipered == 1)
{
tmp = get_last_node(src->ptemp->pipef);
if (tmp == NULL)
src->ptemp->pipef = new_file(src->p->filename, src);
else
tmp->next = new_file(src->p->filename, src);
}
}