aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@bitwiz.org.uk>2014-07-01 23:40:35 +0200
committerThomas White <taw@bitwiz.org.uk>2014-07-01 23:40:35 +0200
commit70bfc710f37bd3f134fa201299efa7bdf098a399 (patch)
treedfb3abae8447166829eadd733d14cdacdf54d518
parent2c6cd610074fc9d0ed3050d4bfa39b5031de876a (diff)
Restore saving
-rw-r--r--src/presentation.c3
-rw-r--r--src/sc_parse.c35
-rw-r--r--src/sc_parse.h4
3 files changed, 41 insertions, 1 deletions
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 <config.h>
#endif
+#include <stdio.h>
+
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 */