-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtoken_splits.c
58 lines (52 loc) · 1.75 KB
/
token_splits.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* token_splits.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bmachado <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/12/13 11:44:57 by bmachado #+# #+# */
/* Updated: 2022/02/23 10:52:38 by bmachado ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int is_operator(int token_type)
{
if (token_type == PIPE || token_type == SPACE
|| redir_type(token_type) || token_type == EQUAL)
return (1);
return (0);
}
int is_empty_var(t_shell *table, char *str)
{
if (str[0] == '$' && !expanded_var(str, table))
return (1);
return (0);
}
int check_operator(t_token *tk)
{
if (tk->next->type == PIPE || redir_type(tk->next->type))
return (1);
return (0);
}
int send_operator(t_token *tk)
{
if (!tk->next || !tk->prev)
return (0);
if (!is_operator(tk->next->type)
&& (tk->type == PIPE || redir_type(tk->type)))
return (1);
if (!is_operator(tk->prev->type) && is_operator(tk->next->type)
&& (tk->type == PIPE || redir_type(tk->type)))
return (1);
return (0);
}
int get_operator(t_token *token, char **cmd, int i)
{
if (send_operator(token))
{
cmd[i] = ft_strdup(token->value);
return (1);
}
return (0);
}