-
Notifications
You must be signed in to change notification settings - Fork 0
/
rdr_utils2.c
92 lines (83 loc) · 2.24 KB
/
rdr_utils2.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* rdr_utils2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: btaha <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/08 14:46:15 by btaha #+# #+# */
/* Updated: 2023/01/12 20:57:13 by btaha ### ########.fr */
/* */
/* ************************************************************************** */
#include "./includes/minishell.h"
int check_left(t_tree *tree, int n)
{
while (check_if_rdr(tree) && tree)
{
n++;
tree = tree->left;
}
return (n);
}
void check_args(void)
{
if (g_shell.args)
g_shell.args = NULL;
}
int check_rdr_i(t_tree *tmp, int n, t_tree **temp, int *j)
{
char *file;
while (n > 1)
{
n--;
tmp = tmp->left;
}
if (tmp->type == LOWER_THAN)
{
file = tmp->right->value->content;
if (open_file(file, tmp->type) == -1)
return (-1);
}
else if (tmp->type == DLOWER_THAN)
{
file = filename(tmp->right->value->content);
if (open_file(file, tmp->type) == -1)
return (-1);
}
if (tmp->right->value->next)
ft_lstadd_back(&g_shell.args, tmp->right->value->next);
*j -= 1;
(*temp) = (*temp)->left;
return (1);
}
int check_rdr_o(t_tree *tmp, int n, t_tree **temp, int *j)
{
char *file;
file = NULL;
while (n > 1)
{
n--;
tmp = tmp->left;
}
if (tmp->type == GREATER_THAN || tmp->type == DGREATER_THAN)
{
file = tmp->right->value->content;
if (open_file(file, tmp->type) == -1)
return (-1);
}
if (tmp->right->value->next)
ft_lstadd_back(&g_shell.args, tmp->right->value->next);
(*temp) = (*temp)->left;
*j -= 1;
return (1);
}
int check_if_rdr(t_tree *tree)
{
t_type type;
type = tree->type;
if (type == GREATER_THAN || type == DGREATER_THAN
|| type == LOWER_THAN || type == DLOWER_THAN)
return (1);
else
return (0);
}