aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@bitwiz.me.uk>2018-04-29 21:01:08 +0200
committerThomas White <taw@bitwiz.me.uk>2018-04-29 21:01:08 +0200
commit447184ed2c2cdfdc91b36e46b0a46db1e61f29b1 (patch)
tree00cb64c8dbf75a4ba1b4875f3deb47cf9d17d12a
parent9eb793a14ed92f0eaaa57fa6bb09d35a51f4c8e2 (diff)
Add serialise_sc_block_chain()
-rw-r--r--src/sc_parse.c31
-rw-r--r--src/sc_parse.h1
2 files changed, 32 insertions, 0 deletions
diff --git a/src/sc_parse.c b/src/sc_parse.c
index a13c876..b66dc1f 100644
--- a/src/sc_parse.c
+++ b/src/sc_parse.c
@@ -337,6 +337,7 @@ void sc_block_free(SCBlock *bl)
}
+/* Serialise one block (including children) */
char *serialise_sc_block(const SCBlock *bl)
{
char *a;
@@ -412,6 +413,36 @@ char *serialise_sc_block(const SCBlock *bl)
}
+/* Serialise an entire chain of blocks */
+char *serialise_sc_block_chain(const SCBlock *bl)
+{
+ char *a = strdup("");
+ size_t len = 1;
+
+ if ( a == NULL ) return NULL;
+
+ while ( bl != NULL ) {
+
+ char *c = serialise_sc_block(bl);
+ if ( c == NULL ) {
+ free(a);
+ return NULL;
+ }
+
+ len += strlen(c);
+ a = realloc(a, len);
+ if ( a == NULL ) return NULL;
+ strcat(a, c);
+ free(c);
+
+ bl = bl->next;
+
+ }
+
+ return a;
+}
+
+
int save_sc_block(GOutputStream *fh, const SCBlock *bl)
{
while ( bl != NULL ) {
diff --git a/src/sc_parse.h b/src/sc_parse.h
index 981299f..9277ee6 100644
--- a/src/sc_parse.h
+++ b/src/sc_parse.h
@@ -84,6 +84,7 @@ extern void show_sc_blocks(const SCBlock *bl);
extern void show_sc_block(const SCBlock *bl, const char *prefix);
extern char *serialise_sc_block(const SCBlock *bl);
+extern char *serialise_sc_block_chain(const SCBlock *bl);
extern int save_sc_block(GOutputStream *fh, const SCBlock *bl);
extern size_t scblock_delete_text(SCBlock *b, ssize_t o1, ssize_t o2);