diff options
author | Thomas White <taw@bitwiz.org.uk> | 2017-03-02 22:40:58 +0100 |
---|---|---|
committer | Thomas White <taw@bitwiz.org.uk> | 2017-03-02 22:45:07 +0100 |
commit | e7eede3273394f3479bb63f92e57780dfc8f2e3d (patch) | |
tree | ad8467da22a4c1f2cdca113b77f096e5e643b98b | |
parent | 397fbd7032b57fec6aee9b8eac4ccf693aedc63a (diff) |
sc_block_delete() may change the top block
-rw-r--r-- | src/frame.c | 4 | ||||
-rw-r--r-- | src/narrative_window.c | 2 | ||||
-rw-r--r-- | src/sc_editor.c | 2 | ||||
-rw-r--r-- | src/sc_parse.c | 27 | ||||
-rw-r--r-- | src/sc_parse.h | 4 |
5 files changed, 27 insertions, 12 deletions
diff --git a/src/frame.c b/src/frame.c index 36a7983..5a7da8e 100644 --- a/src/frame.c +++ b/src/frame.c @@ -1021,7 +1021,9 @@ void merge_paragraphs(struct frame *fr, int para) const char *c = sc_block_contents(n); if ( strlen(c) == 1 ) { - sc_block_delete(scblock, n); + SCBlock *ss = scblock; + sc_block_delete(&scblock, n); + assert(ss == scblock); } else { scblock_delete_text(n, 0, 1); } diff --git a/src/narrative_window.c b/src/narrative_window.c index ec5d956..d53002a 100644 --- a/src/narrative_window.c +++ b/src/narrative_window.c @@ -153,7 +153,7 @@ static void delete_slide_sig(GSimpleAction *action, GVariant *parameter, return; } - sc_block_delete(nw->p->scblocks, ns); + sc_block_delete(&nw->p->scblocks, ns); /* Full rerender */ sc_editor_set_scblock(nw->sceditor, diff --git a/src/sc_editor.c b/src/sc_editor.c index 38b245d..cf6c594 100644 --- a/src/sc_editor.c +++ b/src/sc_editor.c @@ -397,7 +397,7 @@ void sc_editor_redraw(SCEditor *e) void sc_editor_delete_selected_frame(SCEditor *e) { - sc_block_delete(e->scblocks, e->selection->scblocks); + sc_block_delete(&e->scblocks, e->selection->scblocks); full_rerender(e); emit_change_sig(e); } diff --git a/src/sc_parse.c b/src/sc_parse.c index ccc6f6a..a497334 100644 --- a/src/sc_parse.c +++ b/src/sc_parse.c @@ -213,23 +213,34 @@ static SCBlock *sc_find_parent(SCBlock *top, SCBlock *find) void sc_block_substitute(SCBlock **top, SCBlock *old, SCBlock *new) { + if ( old == NULL ) { + fprintf(stderr, "Substituting nothing!\n"); + return; + } + if ( old == *top ) { /* It is the first block */ new->next = old->next; *top = new; } else { - sc_block_unlink(*top, old); - sc_block_append_p(new, *top); + sc_block_unlink(top, old); + sc_block_append_p(*top, new); } } -/* Delete "deleteme", which is somewhere under "top" */ -void sc_block_unlink(SCBlock *top, SCBlock *deleteme) +/* Unlink "deleteme", which is somewhere under "top" */ +void sc_block_unlink(SCBlock **top, SCBlock *deleteme) { - SCBlock *parent = sc_find_parent(top, deleteme); + SCBlock *parent = sc_find_parent(*top, deleteme); if ( parent == NULL ) { - fprintf(stderr, "Couldn't find block parent!\n"); + /* Maybe it's the first block? */ + if ( *top == deleteme ) { + fprintf(stderr, "Unlinking at top\n"); + *top = (*top)->next; + } else { + fprintf(stderr, "Couldn't find block parent!\n"); + } return; } @@ -243,12 +254,14 @@ void sc_block_unlink(SCBlock *top, SCBlock *deleteme) } -void sc_block_delete(SCBlock *top, SCBlock *deleteme) +/* Delete "deleteme", which is somewhere under "top" */ +void sc_block_delete(SCBlock **top, SCBlock *deleteme) { sc_block_unlink(top, deleteme); sc_block_free(deleteme); } + /* Frees "bl" and all its children (but not the blocks following it) */ void sc_block_free(SCBlock *bl) { diff --git a/src/sc_parse.h b/src/sc_parse.h index dfa3fab..4775996 100644 --- a/src/sc_parse.h +++ b/src/sc_parse.h @@ -59,8 +59,8 @@ extern SCBlock *sc_block_append_inside(SCBlock *parent, extern SCBlock *sc_block_insert_after(SCBlock *afterme, char *name, char *opt, char *contents); -extern void sc_block_delete(SCBlock *top, SCBlock *deleteme); -extern void sc_block_unlink(SCBlock *top, SCBlock *deleteme); +extern void sc_block_delete(SCBlock **top, SCBlock *deleteme); +extern void sc_block_unlink(SCBlock **top, SCBlock *deleteme); extern SCBlock *find_last_child(SCBlock *bl); |