-
Notifications
You must be signed in to change notification settings - Fork 0
/
rdr_utils3.c
99 lines (90 loc) · 2.46 KB
/
rdr_utils3.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* rdr_utils3.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: btaha <btaha@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/10 17:53:09 by btaha #+# #+# */
/* Updated: 2023/01/14 21:32:17 by btaha ### ########.fr */
/* */
/* ************************************************************************** */
#include "./includes/minishell.h"
int checking_rdr(t_tree *tree, t_tree **tmp)
{
int j;
j = check_left(tree, 0);
if ((*tmp)->type == DGREATER_THAN || (*tmp)->type == GREATER_THAN)
{
while (j > 1)
if (check_rdr_o(tree, j, tmp, &j) == -1)
return (-1);
}
else if ((*tmp)->type == LOWER_THAN || (*tmp)->type == DLOWER_THAN)
while (j > 1)
if (check_rdr_i(tree, j, tmp, &j) == -1)
return (-1);
if (tree->type == DGREATER_THAN || tree->type == GREATER_THAN)
{
if (check_rdr_oi(tree) == -1 || check_rdr(tree, g_shell.fd, NULL) == -1)
return (-1);
}
else
{
if (check_rdr_io(tree) == -1 || check_rdr(tree, g_shell.fd, NULL) == -1)
return (-1);
}
return (0);
}
int check_if_l(t_tree **tree)
{
while ((*tree))
{
if ((*tree)->type == LOWER_THAN || (*tree)->type == DLOWER_THAN)
return (1);
(*tree) = (*tree)->left;
}
return (0);
}
int check_if_g(t_tree **tree)
{
while ((*tree))
{
if ((*tree)->type == GREATER_THAN || (*tree)->type == DGREATER_THAN)
return (1);
(*tree) = (*tree)->left;
}
return (0);
}
int check_rdr_oi(t_tree *tree)
{
t_tree *tmp;
int j;
if (check_if_l(&tree))
{
tmp = tree;
j = check_left(tree, 0);
while (j > 1)
if (check_rdr_i(tree, j, &tmp, &j) == -1)
return (-1);
if (check_rdr(tree, g_shell.fd, NULL) == -1)
return (-1);
}
return (1);
}
int check_rdr_io(t_tree *tree)
{
t_tree *tmp;
int j;
if (check_if_g(&tree))
{
tmp = tree;
j = check_left(tree, 0);
while (j > 1)
if (check_rdr_o(tree, j, &tmp, &j) == -1)
return (-1);
if (check_rdr(tree, g_shell.fd, NULL) == -1)
return (-1);
}
return (1);
}