aboutsummaryrefslogtreecommitdiff
path: root/src/sc_parse.c
diff options
context:
space:
mode:
authorThomas White <taw@bitwiz.org.uk>2015-06-09 00:07:03 +0200
committerThomas White <taw@bitwiz.org.uk>2015-06-09 00:07:03 +0200
commit5b78853e0bbecd26c43f9cab7c4f61867644f83d (patch)
tree98fe7e2b4a21393a3bbacb886cc36791adc81b0d /src/sc_parse.c
parent0ae0bfab5fc1a8c4807123490448babc651f253b (diff)
Frame deletion stuff
Diffstat (limited to 'src/sc_parse.c')
-rw-r--r--src/sc_parse.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/sc_parse.c b/src/sc_parse.c
index ed7d7b8..4aab2af 100644
--- a/src/sc_parse.c
+++ b/src/sc_parse.c
@@ -224,6 +224,44 @@ SCBlock *sc_block_insert_after(SCBlock *afterme,
}
+static SCBlock *sc_find_parent(SCBlock *top, SCBlock *find)
+{
+ if ( top->child == find ) return top;
+ if ( top->next == find ) return top;
+
+ if ( top->child != NULL ) {
+ SCBlock *t = sc_find_parent(top->child, find);
+ if ( t != NULL ) return t;
+ }
+ if ( top->next != NULL ) {
+ SCBlock *t = sc_find_parent(top->next, find);
+ if ( t != NULL ) return t;
+ }
+ return NULL;
+}
+
+
+/* Delete "deleteme", which is somewhere under "top" */
+void sc_block_delete(SCBlock *top, SCBlock *deleteme)
+{
+ SCBlock *parent = sc_find_parent(top, deleteme);
+ if ( parent == NULL ) {
+ fprintf(stderr, "Couldn't find block parent!\n");
+ return;
+ }
+
+ if ( parent->next == deleteme ) {
+ parent->next = deleteme->next;
+ }
+
+ if ( parent->child == deleteme ) {
+ parent->child = NULL;
+ }
+
+ sc_block_free(deleteme);
+}
+
+
/* Frees "bl" and all its children */
void sc_block_free(SCBlock *bl)
{