-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathparse_utils2.c
More file actions
56 lines (48 loc) · 1.09 KB
/
Copy pathparse_utils2.c
File metadata and controls
56 lines (48 loc) · 1.09 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
55
56
#include <stdlib.h>
#include "parse.h"
static t_parse_ast_list **get_ast_list(void)
{
static t_parse_ast_list *list;
return (&list);
}
static t_parse_ast_list *create_ast_on_list(void)
{
t_parse_ast_list *list;
list = malloc(sizeof(t_parse_ast_list));
if (!list)
parse_fatal_error();
list->next = *get_ast_list();
*get_ast_list() = list;
return (list);
}
void parse_free_all_ast(void)
{
t_parse_ast_list *list;
t_parse_ast_list *next;
list = *get_ast_list();
parse_free_heredocs(list->ast.heredocs);
while (list)
{
next = list->next;
if (list->ast.type == ASTNODE_STRING)
free(list->ast.content.string->text);
free(list->ast.content.void_ptr);
free(list);
list = next;
}
*get_ast_list() = NULL;
}
t_parse_ast *parse_new_ast_node(t_parse_ast_type type, void *content)
{
t_parse_ast_list *list;
if (!(type > ASTNODE_NONE && type < ASTNODE_INVALID))
parse_fatal_error();
if (!content)
parse_fatal_error();
list = create_ast_on_list();
list->ast.error = 0;
list->ast.heredocs = NULL;
list->ast.type = type;
list->ast.content.void_ptr = content;
return (&list->ast);
}