-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparsing_utils.c
93 lines (85 loc) · 2.69 KB
/
parsing_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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* parsing_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mthiry <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/22 14:22:06 by mthiry #+# #+# */
/* Updated: 2022/08/11 09:31:42 by mthiry ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int redirection_in(t_node *args, t_cmd *elem, t_input *data)
{
if (!args->next || is_the_next_is_in_arg(args) == 1)
return (print_syntax_error_bool(args, data));
if (args->next && args->next->type == IN_ARG)
{
if (init_in(args, elem, data) == 1)
return (1);
}
else if (args->next->next && args->next->next->type == IN_ARG)
{
args = args->next;
if (init_in(args, elem, data) == 1)
return (1);
}
else if (args->next && (args->next->type == REDIR_OUT
|| args->next->type == REDIR_AP))
return (0);
else
return (print_syntax_error_bool(args, data));
return (0);
}
int redirection_out(t_node *args, t_cmd *elem, t_input *data)
{
if (!args->next || is_the_next_is_out_arg(args) == 1)
return (print_syntax_error_bool(args, data));
if (args->next && args->next->type == OUT_ARG)
{
if (init_out(args, elem, data) == 1)
return (1);
}
else if (args->next->next && args->next->next->type == OUT_ARG)
{
if (init_out(args, elem, data) == 1)
return (1);
}
else if (args->next && (args->next->type == REDIR_IN
|| args->next->type == REDIR_HD))
return (0);
else
return (print_syntax_error_bool(args, data));
return (0);
}
int redirection_check(t_node *args, t_cmd *elem, t_input *data)
{
if (args->value && (args->type == REDIR_IN || args->type == REDIR_HD))
return (redirection_in(args, elem, data));
else if (args->value && (args->type == REDIR_OUT || args->type == REDIR_AP))
return (redirection_out(args, elem, data));
return (0);
}
t_node *next_elem(t_node *args)
{
t_node *next_elem;
next_elem = args;
while (next_elem)
{
if (!next_elem->next)
return (NULL);
next_elem = next_elem->next;
if (next_elem->prev && next_elem->prev->type == PIPE)
break ;
}
return (next_elem);
}
int get_len_cmd(char **str)
{
int i;
i = 0;
while (str[i])
i++;
return (i);
}