From 70bfc710f37bd3f134fa201299efa7bdf098a399 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Tue, 1 Jul 2014 23:40:35 +0200 Subject: Restore saving --- src/presentation.c | 3 ++- src/sc_parse.c | 35 +++++++++++++++++++++++++++++++++++ src/sc_parse.h | 4 ++++ 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/presentation.c b/src/presentation.c index 4b89126..9fbefb2 100644 --- a/src/presentation.c +++ b/src/presentation.c @@ -320,7 +320,8 @@ int save_presentation(struct presentation *p, const char *filename) fh = fopen(filename, "w"); if ( fh == NULL ) return 1; - /* FIXME: Save based on SCBlocks */ + show_sc_blocks(p->scblocks); + save_sc_block(fh, p->scblocks); /* Slightly fiddly because someone might * do save_presentation(p, p->filename) */ diff --git a/src/sc_parse.c b/src/sc_parse.c index 51f55de..510f097 100644 --- a/src/sc_parse.c +++ b/src/sc_parse.c @@ -147,6 +147,41 @@ void sc_block_free(SCBlock *bl) } +void save_sc_block(FILE *fh, const SCBlock *bl) +{ + while ( bl != NULL ) { + + if ( bl->name == NULL ) { + fprintf(fh, "%s", bl->contents); + } else { + + fprintf(fh, "\\%s", bl->name); + if ( bl->options != NULL ) { + fprintf(fh, "[%s]", bl->options); + } + if ( (bl->contents != NULL) || (bl->child != NULL) ) { + fprintf(fh, "{"); + } + if ( bl->contents != NULL ) { + fprintf(fh, "%s", bl->contents); + } + + } + + if ( bl->child != NULL ) { + save_sc_block(fh, bl->child); + } + + if ( (bl->name != NULL) && + ((bl->contents != NULL) || (bl->child != NULL)) ) { + fprintf(fh, "}"); + } + + bl = bl->next; + } +} + + static void recursive_show_sc_blocks(const char *prefix, const SCBlock *bl) { while ( bl != NULL ) { diff --git a/src/sc_parse.h b/src/sc_parse.h index b774c26..44301df 100644 --- a/src/sc_parse.h +++ b/src/sc_parse.h @@ -27,6 +27,8 @@ #include #endif +#include + typedef struct _scblock SCBlock; extern SCBlock *sc_parse(const char *sc); @@ -48,4 +50,6 @@ extern void sc_delete_text(SCBlock *b1, int o1, SCBlock *b2, int o2); extern void show_sc_blocks(const SCBlock *bl); extern void show_sc_block(const SCBlock *bl, const char *prefix); +extern void save_sc_block(FILE *fh, const SCBlock *bl); + #endif /* SC_PARSE_H */ -- cgit v1.2.3