diff options
author | Thomas White <taw@physics.org> | 2018-01-18 22:53:55 +0100 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2018-01-18 22:53:55 +0100 |
commit | 7b0d0bf3e125018e1cf191ec36e823d797a91f8c (patch) | |
tree | d46415be71632855f914a82f614dc4c212b4bf1d | |
parent | 53830f66ca3cd8573340b4f43945aeedf60e5f5f (diff) |
sc_block_delete/unlink: Pass error condition back up if parent block can't be found
-rw-r--r-- | src/sc_parse.c | 16 | ||||
-rw-r--r-- | src/sc_parse.h | 4 |
2 files changed, 13 insertions, 7 deletions
diff --git a/src/sc_parse.c b/src/sc_parse.c index a8b2c09..39f6ad5 100644 --- a/src/sc_parse.c +++ b/src/sc_parse.c @@ -243,7 +243,7 @@ void sc_block_substitute(SCBlock **top, SCBlock *old, SCBlock *new) /* Unlink "deleteme", which is somewhere under "top" */ -void sc_block_unlink(SCBlock **top, SCBlock *deleteme) +int sc_block_unlink(SCBlock **top, SCBlock *deleteme) { SCBlock *parent = sc_find_parent(*top, deleteme); if ( parent == NULL ) { @@ -251,10 +251,11 @@ void sc_block_unlink(SCBlock **top, SCBlock *deleteme) if ( *top == deleteme ) { fprintf(stderr, "Unlinking at top\n"); *top = (*top)->next; + return 0; } else { fprintf(stderr, "Couldn't find block parent!\n"); + return 1; } - return; } if ( parent->next == deleteme ) { @@ -264,14 +265,19 @@ void sc_block_unlink(SCBlock **top, SCBlock *deleteme) if ( parent->child == deleteme ) { parent->child = NULL; } + return 0; } /* Delete "deleteme", which is somewhere under "top" */ -void sc_block_delete(SCBlock **top, SCBlock *deleteme) +int sc_block_delete(SCBlock **top, SCBlock *deleteme) { - sc_block_unlink(top, deleteme); - sc_block_free(deleteme); + int r; + r = sc_block_unlink(top, deleteme); + if ( !r ) { + sc_block_free(deleteme); + } + return r; } diff --git a/src/sc_parse.h b/src/sc_parse.h index 6f8cb51..3c2c599 100644 --- a/src/sc_parse.h +++ b/src/sc_parse.h @@ -61,8 +61,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 int sc_block_delete(SCBlock **top, SCBlock *deleteme); +extern int sc_block_unlink(SCBlock **top, SCBlock *deleteme); extern SCBlock *find_last_child(SCBlock *bl); |