diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/sc_parse.c | 31 | ||||
-rw-r--r-- | src/sc_parse.h | 1 |
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); |