diff options
author | Thomas White <taw@bitwiz.org.uk> | 2015-08-16 22:19:54 +0200 |
---|---|---|
committer | Thomas White <taw@bitwiz.org.uk> | 2015-08-16 22:19:54 +0200 |
commit | fa25a674476f748f8fe498080b3163601a9912c3 (patch) | |
tree | 4d0b78209a32e60b044af0644498716d1911d08c /src/sc_parse.c | |
parent | 1f26293c25e0c788a46305e300023c35af62de1c (diff) |
Add new slide
Diffstat (limited to 'src/sc_parse.c')
-rw-r--r-- | src/sc_parse.c | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/src/sc_parse.c b/src/sc_parse.c index 89253f6..f3c3b4e 100644 --- a/src/sc_parse.c +++ b/src/sc_parse.c @@ -438,7 +438,7 @@ SCBlock *sc_parse(const char *sc) if ( strlen(sc) == 0 ) { SCBlock *bl = sc_block_new(); - sc_block_set_contents(bl, strdup("")); + sc_block_set_contents(bl, g_strdup("")); return bl; } @@ -538,7 +538,7 @@ void sc_block_set_options(SCBlock *bl, char *opt) void sc_block_set_contents(SCBlock *bl, char *con) { - free(bl->contents); + g_free(bl->contents); bl->contents = con; } @@ -571,12 +571,21 @@ void sc_insert_text(SCBlock *b1, int o1, const char *t) void sc_insert_block(SCBlock *b1, int o1, SCBlock *ins) { + SCBlock *second; char *p1 = g_utf8_offset_to_pointer(b1->contents, o1); + + /* Create a new block containing the second half of b1 */ + second = sc_block_new(); + sc_block_set_contents(second, g_strdup(p1)); + + /* Chop off b1 at the insertion point */ + sc_block_set_contents(b1, g_utf8_substring(b1->contents, 0, o1)); + + /* Link the new block into the chain */ SCBlock *old_next = b1->next; b1->next = ins; - if ( strlen(p1) > 0 ) { - // sc_block_append_end(b1, NULL, NULL, p1); - } + ins->next = second; + second->next = old_next; } |