-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse.c
100 lines (91 loc) · 2.2 KB
/
parse.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
100
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* parse.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jeongmin <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/15 17:20:31 by wonyang #+# #+# */
/* Updated: 2023/01/17 13:40:35 by jeongmin ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
#include "token.h"
#include "make_tree.h"
#include "ds_tree.h"
#include "libft.h"
#include "minishell.h"
extern t_global g_var;
static void del_t_paren(void *content)
{
t_token *token;
if (!content)
return ;
token = (t_token *)(content);
if (!is_this_symbol(token, T_PAREN))
return ;
if (token->str)
free(token->str);
free(content);
content = NULL;
}
static t_list *pre_processing(char *str)
{
t_list *lst;
lst = tokenization(str);
if (!lst)
return (NULL);
if (lst->next == NULL)
{
ft_lstclear(&lst, &del_t_token);
return (NULL);
}
if (!is_correct_syntax(lst->next))
{
ft_lstclear(&lst, &del_t_token);
return (NULL);
}
return (lst);
}
static t_error post_processing(t_tnode *node)
{
if (subst(node) == ERROR)
{
g_var.status = 1;
return (ERROR);
}
if (del_quote(node) == ERROR)
{
g_var.status = 1;
return (ERROR);
}
if (wildcard(node) == ERROR)
{
g_var.status = 1;
return (ERROR);
}
if (!node)
return (ERROR);
return (SCS);
}
t_tnode *parse_line(char *str)
{
t_list *lst;
t_tnode *node;
lst = pre_processing(str);
if (!lst)
{
free(str);
g_var.status = 1;
return (NULL);
}
node = make_tree(lst->next);
ft_lstclear(&lst, &del_t_paren);
if (post_processing(node) == ERROR)
{
free(str);
clear_node(node, &del_t_token);
return (NULL);
}
return (node);
}