blob: ee7633e25dc9a2f73a086f86ecfd6932f5226076 (
plain)
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
/* fornax - distributed network
*
* by team teso
*
* scripting element routines
*/
#include <string.h>
#include <stdlib.h>
#include "../../shared/common.h"
#include "call.h"
#include "branch.h"
#include "element.h"
#include "symbol.h"
/* static function declarations
*/
static int elem_count (element **el);
void
elem_list_free (element **el)
{
if (el == NULL)
return;
while (elem_count (el) > 0) {
elem_free (el[0]);
memmove (&el[0], &el[1], (elem_count (&el[1]) + 1) * sizeof (element *));
}
if (el != NULL)
free (el);
}
static int
elem_count (element **el)
{
int count;
if (el == NULL)
return (0);
for (count = 0 ; el[count] != NULL ; ++count)
;
return (count);
}
element **
elem_add (element **el, element *e)
{
int ec = elem_count (el);
el = xrealloc (el, (ec + 2) * sizeof (element *));
el[ec] = e;
el[ec + 1] = NULL;
return (el);
}
element *
elem_create (void)
{
element * new = xcalloc (1, sizeof (element));
return (new);
}
void
elem_free (element *e)
{
switch (e->type) {
case (ELEM_TYPE_CALL):
call_free ((call *) e->data);
break;
case (ELEM_TYPE_BRANCH):
br_free ((branch *) e->data);
break;
case (ELEM_TYPE_SET):
sym_elem_free ((sym_elem *) e->data);
break;
default:
break;
}
free (e);
return;
}
element *
elem_set_type (element *e, int type)
{
e->type = type;
return (e);
}
element *
elem_set_data (element *e, void *data)
{
e->data = data;
return (e);
}
|