diff options
author | Thomas White <taw@bitwiz.org.uk> | 2011-12-25 23:56:20 +0000 |
---|---|---|
committer | Thomas White <taw@bitwiz.org.uk> | 2011-12-25 23:56:20 +0000 |
commit | 683e72ae5fa90fd14101bd6ec8921468e96a50f5 (patch) | |
tree | 0f8512f7894294e08a23d6a877309e566cdc1817 /src | |
parent | 3c75a65b5ba707353874cd737d73d782e23d00ac (diff) |
Load and save the slide notes
Diffstat (limited to 'src')
-rw-r--r-- | src/loadsave.c | 8 | ||||
-rw-r--r-- | src/notes.c | 94 | ||||
-rw-r--r-- | src/notes.h | 3 |
3 files changed, 104 insertions, 1 deletions
diff --git a/src/loadsave.c b/src/loadsave.c index b85f4d0..a4c2891 100644 --- a/src/loadsave.c +++ b/src/loadsave.c @@ -36,6 +36,7 @@ #include "stylesheet.h" #include "slide_render.h" #include "mainwindow.h" +#include "notes.h" static int alloc_children(struct ds_node *node) @@ -366,7 +367,6 @@ int get_field_s(struct ds_node *root, const char *key, char **val) node = find_node(root, key, 0); if ( node == NULL ) { - fprintf(stderr, "Couldn't find field '%s'\n", key); *val = NULL; return 1; } @@ -469,6 +469,8 @@ static struct slide *tree_to_slide(struct presentation *p, struct ds_node *root) s = new_slide(); s->parent = p; + load_notes(root, s); + /* Loop over objects */ for ( i=0; i<root->n_children; i++ ) { @@ -746,6 +748,7 @@ void serialize_end(struct serializer *ser) { free(ser->stack[--ser->stack_depth]); rebuild_prefix(ser); + ser->empty_set = 1; } @@ -801,6 +804,9 @@ int save_presentation(struct presentation *p, const char *filename) serialize_end(&ser); } + + write_notes(s, &ser); + serialize_end(&ser); } diff --git a/src/notes.c b/src/notes.c index 026612b..58ca008 100644 --- a/src/notes.c +++ b/src/notes.c @@ -90,6 +90,100 @@ static gint close_notes_sig(GtkWidget *w, struct presentation *p) } +static char *escape_text(const char *a) +{ + char *b; + size_t l1, l, i; + + l1 = strlen(a); + + b = malloc(2*l1 + 1); + l = 0; + + for ( i=0; i<l1; i++ ) { + + char c = a[i]; + + /* Yes, this is horribly confusing */ + if ( c == '\n' ) { + b[l++] = '\\'; b[l++] = 'n'; + } else if ( c == '\r' ) { + b[l++] = '\\'; b[l++] = 'r'; + } else if ( c == '\"' ) { + b[l++] = '\\'; b[l++] = '\"'; + } else if ( c == '\t' ) { + b[l++] = '\\'; b[l++] = 't'; + } else { + b[l++] = c; + } + + } + b[l++] = '\0'; + + return realloc(b, l); +} + + +static char *unescape_text(const char *a) +{ + char *b; + size_t l1, l, i; + int escape; + + l1 = strlen(a); + + b = malloc(l1 + 1); + l = 0; + escape = 0; + + for ( i=0; i<l1; i++ ) { + + char c = a[i]; + + if ( escape ) { + if ( c == 'r' ) b[l++] = '\r'; + if ( c == 'n' ) b[l++] = '\n'; + if ( c == '\"' ) b[l++] = '\"'; + if ( c == 't' ) b[l++] = '\t'; + escape = 0; + continue; + } + + if ( c == '\\' ) { + escape = 1; + continue; + } + + b[l++] = c; + + } + b[l++] = '\0'; + + return realloc(b, l); +} + + +void write_notes(struct slide *s, struct serializer *ser) +{ + char *es; + + es = escape_text(s->notes); + serialize_s(ser, "notes", es); + free(es); +} + + +void load_notes(struct ds_node *node, struct slide *s) +{ + char *v; + + if ( get_field_s(node, "notes", &v) ) return; + + s->notes = unescape_text(v); + free(v); +} + + void open_notes(struct presentation *p) { struct notes *n; diff --git a/src/notes.h b/src/notes.h index b739acb..f6fba5c 100644 --- a/src/notes.h +++ b/src/notes.h @@ -34,4 +34,7 @@ extern void open_notes(struct presentation *p); extern void notify_notes_slide_changed(struct presentation *p, struct slide *np); +extern void write_notes(struct slide *s, struct serializer *ser); +extern void load_notes(struct ds_node *node, struct slide *s); + #endif /* NOTES_H */ |