-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoperators_utils.c
99 lines (88 loc) · 2.09 KB
/
operators_utils.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* operators_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: csweetin <csweetin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/04 17:19:32 by cdomet-d #+# #+# */
/* Updated: 2024/05/22 17:17:28 by csweetin ### ########.fr */
/* */
/* ************************************************************************** */
#include "exec.h"
size_t count_pipes(t_input *in)
{
t_input *tmp;
size_t npip;
npip = 0;
tmp = in;
while (tmp)
{
if (tmp->tok == pip)
npip++;
tmp = tmp->next;
}
if (npip == 0)
return (npip);
return (npip + 1);
}
bool op_true(t_input *in, t_tok op)
{
t_input *tmp;
tmp = in;
if (tmp && tmp->tok == pip)
tmp = tmp->next;
while (tmp && tmp->tok != pip)
{
if (tmp->tok == op)
return (true);
tmp = tmp->next;
}
return (false);
}
t_input *find_tok(t_input *in, t_tok op, bool next)
{
t_input *tmp;
tmp = in;
if (!tmp)
return (NULL);
if (tmp && tmp->tok == pip)
tmp = tmp->next;
if (next)
tmp = tmp->next;
while (tmp && tmp->tok != pip)
{
if (tmp->tok == op)
return (tmp);
tmp = tmp->next;
}
return (NULL);
}
t_input *find_next_pipe(t_input *in, t_fd *fd)
{
t_input *tmp;
tmp = in;
if (fd->pnb <= 0)
return (NULL);
if (tmp && tmp->tok == pip)
tmp = tmp->next;
while (tmp && tmp->tok != pip)
tmp = tmp->next;
return (tmp);
}
t_input *find_prev_tok(t_input *in, t_tok op)
{
t_input *tmp;
tmp = in;
if (!tmp)
return (NULL);
if (in->prev == NULL)
return (NULL);
while (tmp && tmp->tok != pip)
{
if (tmp->tok == op)
return (tmp);
tmp = tmp->prev;
}
return (NULL);
}