aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2019-02-26 21:14:34 +0100
committerHugo Hörnquist <hugo@lysator.liu.se>2019-02-26 21:14:34 +0100
commit20b1ec5f84f0292845fb8b276300057a4646f17d (patch)
tree5f9099ebecd1b6c1f19efe552fd5f61525a4d37f
parentStrbuf remove init_1, add strbuf_load. (diff)
downloadcalp-20b1ec5f84f0292845fb8b276300057a4646f17d.tar.gz
calp-20b1ec5f84f0292845fb8b276300057a4646f17d.tar.xz
Made filename attribute of all objects.
-rw-r--r--calendar.c1
-rw-r--r--graphs.c2
-rw-r--r--main.c5
-rw-r--r--parse.c4
-rw-r--r--vcal.c35
-rw-r--r--vcal.h4
6 files changed, 39 insertions, 12 deletions
diff --git a/calendar.c b/calendar.c
index a60d8ea2..c9ebef0b 100644
--- a/calendar.c
+++ b/calendar.c
@@ -117,4 +117,3 @@ int open_ics (char* resolved_path, vcomponent* cal) {
return 0;
}
-
diff --git a/graphs.c b/graphs.c
index 9d87c70a..945821d7 100644
--- a/graphs.c
+++ b/graphs.c
@@ -19,7 +19,7 @@ int create_graph_trie (vcomponent* ev, char* filename) {
fclose(f);
- INFO_F("Wrote '%s' to '%s'", ev->filename, filename);
+ INFO_F("Wrote '%s' to '%s'", vcomponent_get_val(ev, "X-HH-FILENAME"), filename);
return 0;
}
diff --git a/main.c b/main.c
index 3e0d005e..6cfeab75 100644
--- a/main.c
+++ b/main.c
@@ -48,7 +48,8 @@ int main (int argc, char** argv) {
vcomponent* cal = GET(VECT(vcomponent))(&root.components, i);
assert(strcmp(cal->type, "VCALENDAR") == 0);
- char* filename = cal->filename;
+ char* filename = vcomponent_get_val(cal, "X-HH-FILENAME");
+
/* This loop over all VEVENT's in the current VCALENDAR */
for (size_t j = 0; j < cal->components.length; j++) {
vcomponent* ev = GET(VECT(vcomponent))(&cal->components, j);
@@ -73,7 +74,7 @@ int main (int argc, char** argv) {
char target[0xFF];
target[0] = '\0';
strcat(target, "/tmp/dot/");
- strcat(target, ev->filename);
+ strcat(target, vcomponent_get_val(ev, "X-HH-FILENAME"));
strcat(target, ".dot");
// create_graph(ev, target);
}
diff --git a/parse.c b/parse.c
index 035781ea..97e63305 100644
--- a/parse.c
+++ b/parse.c
@@ -198,7 +198,9 @@ int handle_kv (
ERR_P(ctx, "Expected END:%s, got END:%s.\n%s line",
expected_key->mem,
CLINE_CUR_VAL(cline)->mem,
- PEEK(LLIST(vcomponent))(&ctx->comp_stack)->filename);
+ vcomponent_get_val(
+ PEEK(LLIST(vcomponent))(&ctx->comp_stack),
+ "X-HH-FILENAME"));
PUSH(LLIST(strbuf))(&ctx->key_stack, expected_key);
return -1;
diff --git a/vcal.c b/vcal.c
index 42342d93..61d6fbb8 100644
--- a/vcal.c
+++ b/vcal.c
@@ -44,10 +44,8 @@ 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);
+ vcomponent_push_val (self, "X-HH-FILENAME", filename);
}
self->type = (char*) calloc(sizeof(*type), strlen(type) + 1);
@@ -71,12 +69,10 @@ content_line* get_property (vcomponent* ev, const char* key) {
}
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);
+ ERR("Error freeing vcomponent");
}
FREE(VECT(vcomponent))(&self->components);
@@ -112,3 +108,30 @@ FMT_F(vcomponent) {
return seek;
}
+
+int vcomponent_push_val (vcomponent* comp, const char* key, const char* val) {
+ NEW(content_line, cl);
+ NEW(content_set, cs);
+ strbuf_load(&cs->key, val);
+ PUSH(content_line)(cl, cs);
+
+ char* key_cpy = calloc(sizeof(*key_cpy), strlen(key));
+ strcpy (key_cpy, key);
+ PUSH(TRIE(content_line))(&comp->clines, key_cpy, cl);
+ free (key_cpy);
+
+ return 0;
+}
+
+char* vcomponent_get_val (vcomponent* comp, const char* key) {
+ char* key_cpy = calloc(sizeof(*key_cpy), strlen(key));
+ strcpy (key_cpy, key);
+ content_line* cl = GET(TRIE(content_line))(&comp->clines, key_cpy);
+ free (key_cpy);
+
+ if (cl != NULL && cl->cur->value != NULL) {
+ return cl->cur->value->key.mem;
+ }
+
+ return NULL;
+}
diff --git a/vcal.h b/vcal.h
index 1d643a40..451d4463 100644
--- a/vcal.h
+++ b/vcal.h
@@ -67,7 +67,6 @@ typedef struct s_vcomponent vcomponent;
#undef TYPE
struct s_vcomponent {
- char* filename;
char* type;
vcomponent* parent;
TRIE(content_line) clines;
@@ -87,6 +86,9 @@ content_line* get_property (vcomponent* ev, const char* key);
int add_content_line (vcomponent* ev, content_line* c);
+int vcomponent_push_val (vcomponent*, const char* key, const char* val);
+char* vcomponent_get_val (vcomponent*, const char* key);
+
/*
* Appends ev to cal. Doesn't copy ev. So make sure that it wont go
* out of scope.