aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@hornquist.se>2019-02-10 15:40:05 +0100
committerHugo Hörnquist <hugo@hornquist.se>2019-02-10 15:40:05 +0100
commit1fbf9ba8efc8612e0fc309bfe9aa2b95891915d4 (patch)
tree39258374fe23ec90a7d574cb5647bc5e4cf670b5
parentReplace printf/puts with INFO/ERR. (diff)
downloadcalp-1fbf9ba8efc8612e0fc309bfe9aa2b95891915d4.tar.gz
calp-1fbf9ba8efc8612e0fc309bfe9aa2b95891915d4.tar.xz
Clean up vcal, add key_val type.
-rw-r--r--vcal.c61
-rw-r--r--vcal.h13
2 files changed, 55 insertions, 19 deletions
diff --git a/vcal.c b/vcal.c
index 369e1016..a61d3d9f 100644
--- a/vcal.c
+++ b/vcal.c
@@ -59,12 +59,7 @@ content_line* RESOLVE(content_line)
*/
APPEND(LLIST(strbuf)) (&dest->vals, &new->vals);
- INFO_F("param length = %i", SIZE(LLIST(strbuf))(&new->params));
- FOR(LLIST(strbuf), link, &new->params) {
- INFO_F("| %s", link->value->mem);
- }
-
- APPEND(LLIST(strbuf)) (&dest->params, &new->params);
+ APPEND(LLIST(key_val)) (&dest->params, &new->params);
FREE(strbuf)(&new->key);
free(new);
@@ -80,7 +75,7 @@ INIT_F(content_line) {
INIT(strbuf, &this->key);
INIT( LLIST(strbuf), &this->vals );
- INIT( LLIST(strbuf), &this->params );
+ INIT( LLIST(key_val), &this->params );
return 0;
}
@@ -91,7 +86,7 @@ INIT_F(content_line, int keylen, int vallen) {
NEW(strbuf, s, vallen);
PUSH(LLIST(strbuf))(&this->vals, s);
- INIT( LLIST(strbuf), &this->params );
+ INIT( LLIST(key_val), &this->params );
return 0;
}
@@ -100,19 +95,15 @@ FREE_F(content_line) {
FREE(strbuf)(&this->key);
FREE(LLIST(strbuf))(&this->vals);
- FREE(LLIST(strbuf))(&this->params);
+ FREE(LLIST(key_val))(&this->params);
return 0;
}
int content_line_copy (content_line* dest, content_line* src) {
- if (! EMPTY(LLIST(strbuf))(&src->params)) {
- INFO_F("[%s] : %s", src->key.mem, FIRST_V(&src->params)->mem);
- }
-
DEEP_COPY(strbuf)(&dest->key, &src->key);
DEEP_COPY(LLIST(strbuf))(&dest->vals, &src->vals);
- DEEP_COPY(LLIST(strbuf))(&dest->params, &src->params);
+ DEEP_COPY(LLIST(key_val))(&dest->params, &src->params);
return 0;
}
@@ -142,14 +133,52 @@ int DEEP_COPY(vcomponent)(vcomponent* a, vcomponent* b) {
return -1;
}
+/*
+ * TODO this doesn't seem to work.
+ */
FMT_F(vcomponent) {
- return sprintf(buf, "vcomp (%p)", this);
+ int seek = 0;
+ FOR(int, i, 40) fmtf("-");
+
+ seek += sprintf(buf, _YELLOW);
+ seek += sprintf(buf, "VComponet (Type := %s)\n", this->type);
+ seek += FMT(TRIE(content_line))(&this->clines, buf + seek);
+ seek += sprintf(buf, _RESET);
+
+ return seek;
}
FMT_F(content_line) {
char str_a[100], str_b[100], str_c[100];;
FMT(strbuf)(&this->key, str_a);
- FMT(LLIST(strbuf))(&this->params, str_b);
+ FMT(LLIST(key_val))(&this->params, str_b);
FMT(LLIST(strbuf))(&this->vals, str_c);
return sprintf(buf, "[[cl|%s] params := %s vals := %s]", str_a, str_b, str_c);
}
+
+INIT_F(key_val) {
+ INIT(strbuf, &this->key, 100);
+ INIT(strbuf, &this->val, 100);
+ return 0;
+}
+
+FREE_F(key_val) {
+ FREE(strbuf)(&this->key);
+ FREE(strbuf)(&this->val);
+ return 0;
+}
+
+FMT_F(key_val) {
+ char keybuf[100];
+ char valbuf[100];
+ FMT(strbuf)(&this->key, keybuf);
+ FMT(strbuf)(&this->val, valbuf);
+
+ return sprintf(buf, "[[%s] := [%s]]", keybuf, valbuf);
+}
+
+int DEEP_COPY(key_val) (key_val* dest, key_val* src) {
+ strbuf_copy(&dest->key, &src->key);
+ strbuf_copy(&dest->val, &src->val);
+ return 0;
+}
diff --git a/vcal.h b/vcal.h
index a27bd648..c86144f6 100644
--- a/vcal.h
+++ b/vcal.h
@@ -15,14 +15,21 @@ typedef struct {
strbuf val;
} key_val;
+INIT_F(key_val);
+FREE_F(key_val);
+FMT_F(key_val);
+int DEEP_COPY(key_val) (key_val* dest, key_val* src);
+
+#define TYPE key_val
+#include "linked_list.h"
+#undef TYPE
+
typedef struct {
strbuf key;
LLIST(strbuf) vals;
- /* parcams NULL by default, since most content lines doesn't have
- * any properties */
- LLIST(strbuf) params;
+ LLIST(key_val) params;
} content_line;
INIT_F(content_line);