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
|
#include "vcal.h"
#include <string.h>
#define TYPE strbuf
#include "linked_list.inc.h"
#undef TYPE
#define TYPE param_set
#include "trie.inc.h"
#undef TYPE
#define TYPE content_set
#include "linked_list.inc.h"
#undef TYPE
#define T strbuf
#define V TRIE(param_set)
#include "pair.inc.h"
#undef V
#undef T
#define TYPE content_line
// #include "hash.inc"
#include "trie.inc.h"
#undef TYPE
#define TYPE vcomponent
#include "vector.inc.h"
#undef TYPE
INIT_F(vcomponent) {
(void) self;
ERR("Do not use");
return 0;
}
INIT_F(vcomponent, const char* type) {
return INIT(vcomponent, self, type, NULL);
}
INIT_F(vcomponent, const char* type, const char* filename) {
INIT(TRIE(content_line), &self->clines);
INIT(VECT(vcomponent), &self->components);
self->filename = NULL;
if (filename != NULL) {
self->filename = (char*) calloc(sizeof(*filename), strlen(filename) + 1);
strcpy(self->filename, filename);
}
self->type = (char*) calloc(sizeof(*type), strlen(type) + 1);
strcpy(self->type, type);
self->parent = NULL;
self->scm = NULL;
return 0;
}
content_line* get_property (vcomponent* ev, const char* key) {
size_t len = strlen(key) + 1;
char* cpy = (char*) (calloc(sizeof(*cpy), len));
strncpy (cpy, key, len);
content_line* ret = GET(TRIE(content_line))(&ev->clines, cpy);
free (cpy);
return ret;
}
FREE_F(vcomponent) {
if (self->filename != NULL) free(self->filename);
free(self->type);
if (FREE(TRIE(content_line))(&self->clines) != 0) {
fprintf(stderr, "Error freeing vcomponent belonging to file \n %s \n",
self->filename);
}
FREE(VECT(vcomponent))(&self->components);
return 0;
}
int PUSH(vcomponent)(vcomponent* parent, vcomponent* child) {
child->parent = parent;
return PUSH(VECT(vcomponent))(&parent->components, child);
}
int DEEP_COPY(vcomponent)(vcomponent* a, vcomponent* b) {
(void) a;
(void) b;
ERR("Deep copy not implemented for vcomponent");
return -1;
}
FMT_F(vcomponent) {
int seek = 0;
for (int i = 0; i < 40; i++) fmtf("_");
seek += sprintf(buf + seek, _YELLOW);
seek += sprintf(buf + seek, "\nVComponet (Type := %s)\n", self->type);
seek += sprintf(buf + seek, _RESET);
seek += FMT(TRIE(content_line))(&self->clines, buf + seek);
seek += sprintf(buf + seek, "\nComponents:\n");
FOR(VECT, vcomponent, comp, &self->components) {
seek += FMT(vcomponent)(comp, buf + seek);
}
return seek;
}
|