aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@hornquist.se>2019-02-10 18:55:06 +0100
committerHugo Hörnquist <hugo@lysator.liu.se>2019-02-15 20:03:40 +0100
commit78409a2251e345249316f3fcccb31d7b8ba97ccb (patch)
tree5ccac8f847b4f259456cb1055cae5afe61c454b7
parentMove trie->dot from trie to graphs. Add value printing. (diff)
downloadcalp-78409a2251e345249316f3fcccb31d7b8ba97ccb.tar.gz
calp-78409a2251e345249316f3fcccb31d7b8ba97ccb.tar.xz
Merge strbuf copy functions.
-rw-r--r--parse.c10
-rw-r--r--strbuf.c8
-rw-r--r--strbuf.h10
-rw-r--r--vcal.c4
4 files changed, 11 insertions, 21 deletions
diff --git a/parse.c b/parse.c
index 33dfde30..9605a163 100644
--- a/parse.c
+++ b/parse.c
@@ -68,7 +68,7 @@ int parse_file(char* filename, FILE* f, vcomponent* root) {
exit (2);
}
- strbuf_copy(cline.vals.cur->value, &ctx.str);
+ DEEP_COPY(strbuf)(cline.vals.cur->value, &ctx.str);
strbuf_cap(cline.vals.cur->value);
strbuf_soft_reset(&ctx.str);
@@ -85,7 +85,7 @@ int parse_file(char* filename, FILE* f, vcomponent* root) {
* Border between param {key, value}
*/
} else if (p_ctx == p_param_name && c == '=') {
- strbuf_copy(&kv.key, &ctx.str);
+ DEEP_COPY(strbuf)(&kv.key, &ctx.str);
strbuf_cap(&kv.key);
strbuf_soft_reset(&ctx.str);
@@ -103,7 +103,7 @@ int parse_file(char* filename, FILE* f, vcomponent* root) {
if (p_ctx == p_key) dest = &cline.key;
else if (p_ctx == p_param_value) dest = &kv.val;
- strbuf_copy(dest, &ctx.str);
+ DEEP_COPY(strbuf)(dest, &ctx.str);
strbuf_cap(dest);
strbuf_soft_reset(&ctx.str);
@@ -132,7 +132,7 @@ int parse_file(char* filename, FILE* f, vcomponent* root) {
* the end here.
*/
- strbuf_copy(cline.vals.cur->value, &ctx.str);
+ DEEP_COPY(strbuf)(cline.vals.cur->value, &ctx.str);
strbuf_cap(cline.vals.cur->value);
handle_kv(&cline, &ctx);
@@ -163,7 +163,7 @@ int handle_kv (
*/
NEW(strbuf, s);
- strbuf_copy(s, cline->vals.cur->value);
+ DEEP_COPY(strbuf)(s, cline->vals.cur->value);
PUSH(LLIST(strbuf))(&ctx->key_stack, s);
NEW(vcomponent, e,
diff --git a/strbuf.c b/strbuf.c
index 0d6fd7e5..8cc624e5 100644
--- a/strbuf.c
+++ b/strbuf.c
@@ -62,8 +62,7 @@ int strbuf_cap(strbuf* s) {
return strbuf_append(s, 0);
}
-
-int strbuf_copy(strbuf* dest, strbuf* src) {
+int DEEP_COPY(strbuf)(strbuf* dest, strbuf* src) {
int retval = 0;
if (dest->alloc < src->len) {
@@ -110,11 +109,6 @@ char* strbuf_cur(strbuf* s) {
return &s->mem[s->ptr];
}
-/* TODO merge this and strbuf_copy */
-int DEEP_COPY(strbuf)(strbuf* dest, strbuf* src) {
- return strbuf_copy(dest, src);
-}
-
char* strbuf_end(strbuf* s) {
return &s->mem[s->len];
}
diff --git a/strbuf.h b/strbuf.h
index d88a6f16..35ff9543 100644
--- a/strbuf.h
+++ b/strbuf.h
@@ -39,17 +39,13 @@ int strbuf_realloc(strbuf* str, size_t len);
*/
FREE_F(strbuf);
+int strbuf_cmp(strbuf* a, strbuf* b);
+int strbuf_c(strbuf* a, char* b);
+
/*
* Copy contents from src to dest.
* Assumes that dest is already initialized.
- *
- * also see: strbuf_alloc_copy
*/
-int strbuf_copy(strbuf* dest, strbuf* src);
-
-int strbuf_cmp(strbuf* a, strbuf* b);
-int strbuf_c(strbuf* a, char* b);
-
int DEEP_COPY(strbuf)(strbuf*, strbuf*);
/*
diff --git a/vcal.c b/vcal.c
index a61d3d9f..e1df1f30 100644
--- a/vcal.c
+++ b/vcal.c
@@ -178,7 +178,7 @@ FMT_F(key_val) {
}
int DEEP_COPY(key_val) (key_val* dest, key_val* src) {
- strbuf_copy(&dest->key, &src->key);
- strbuf_copy(&dest->val, &src->val);
+ DEEP_COPY(strbuf)(&dest->key, &src->key);
+ DEEP_COPY(strbuf)(&dest->val, &src->val);
return 0;
}