-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclean.c
71 lines (60 loc) · 1.23 KB
/
clean.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
#include "structures.h"
#include <stdlib.h>
#include <stdio.h>
void cleanIds(listID* ids){
listID* aux;
listID* current;
aux = ids;
while(aux!=NULL){
free(aux->id);
current = aux;
aux = aux->next;
free(current);
}
}
void cleanNodes(Node* ast){
if(ast!=NULL){
if(ast->n_type==NODE_NULL)
return;
if(ast->n1 !=NULL){
cleanNodes(ast->n1);
}
if(ast->n2 !=NULL){
cleanNodes(ast->n2);
}
if(ast->n3 !=NULL){
cleanNodes(ast->n3);
}
if(ast->value !=NULL){
free(ast->value);
}
if(ast->id !=NULL){
cleanIds(ast->id);
}
if(ast->next !=NULL){
cleanNodes(ast->next);
}
free(ast);
}
}
void cleanTableNode(TableNode* tnode){
TableNode* aux;
TableNode* current;
aux = tnode;
while(aux!=NULL){
current = aux;
aux = aux->next;
free(current);
}
}
void cleanTable(Table* tbl){
Table* aux;
Table* current;
aux = tbl;
while(aux!=NULL){
current = aux;
aux = aux->next;
cleanTableNode(current->table);
free(current);
}
}