-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathparser_utils.c
More file actions
54 lines (49 loc) · 2.1 KB
/
parser_utils.c
File metadata and controls
54 lines (49 loc) · 2.1 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* parser_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jaesjeon <jaesjeon@student.42seoul.kr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/09/19 00:48:19 by jaesjeon #+# #+# */
/* Updated: 2022/09/19 00:54:31 by jaesjeon ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell_info.h"
#include "minishell.h"
#include "ft_token.h"
#include "ft_tree.h"
static t_lx_token *_find_tree_node(t_lx_token *cur_node, \
unsigned char *tree_type, unsigned char (*is_tree_type)(int))
{
t_lx_token *const last = cur_node;
int subshell_flag;
subshell_flag = 0;
while (cur_node->prev != last)
{
subshell_flag += (cur_node->token_type == PARENTHESES_CLOSE) \
- (cur_node->token_type == PARENTHESES_OPEN);
*tree_type = is_tree_type(cur_node->token_type);
if (!subshell_flag && *tree_type != TREE_UNDEFINED \
&& *tree_type != TREE_CMD)
return (cur_node);
cur_node = cur_node->prev;
}
*tree_type = is_tree_type(cur_node->token_type);
return (NULL);
}
void making_tree_node(t_tree *const cur, unsigned char (*is_tree_type)(int))
{
t_lx_token *find_node;
const int first_type = is_tree_type(UNDEFINED);
if (!cur)
return ;
find_node = _find_tree_node(get_last_token(cur->token_data), \
&cur->type, is_tree_type);
if (!find_node)
return ;
cur->right = make_tree_node(first_type, cur, cut_back_token(find_node));
cur->left = make_tree_node(first_type, cur, cur->token_data);
cur->token_data = cut_back_token(find_node->prev);
making_tree_node(cur->left, is_tree_type);
}