aboutsummaryrefslogtreecommitdiff
path: root/src/frame.c
diff options
context:
space:
mode:
authorThomas White <taw@bitwiz.org.uk>2015-06-10 10:48:56 +0200
committerThomas White <taw@bitwiz.org.uk>2015-06-10 10:48:56 +0200
commit4b34db513bf93b1a425fb7567d220ba751092b17 (patch)
tree2d7c69a48ac83cd967452fe2058187f684b49297 /src/frame.c
parent5b78853e0bbecd26c43f9cab7c4f61867644f83d (diff)
Clear up unused frames
Diffstat (limited to 'src/frame.c')
-rw-r--r--src/frame.c58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/frame.c b/src/frame.c
index f7f0e83..8c670bc 100644
--- a/src/frame.c
+++ b/src/frame.c
@@ -98,6 +98,11 @@ void renew_frame(struct frame *fr)
}
fr->boxes = malloc(sizeof(struct wrap_line));
initialise_line(fr->boxes);
+
+ fr->visited = 0;
+ for ( i=0; i<fr->num_children; i++ ) {
+ renew_frame(fr->children[i]);
+ }
}
@@ -134,3 +139,56 @@ void show_hierarchy(struct frame *fr, const char *t)
}
}
+
+
+static struct frame *find_parent(struct frame *fr, struct frame *search)
+{
+ int i;
+
+ for ( i=0; i<fr->num_children; i++ ) {
+ if ( fr->children[i] == search ) {
+ return fr;
+ }
+ }
+
+ for ( i=0; i<fr->num_children; i++ ) {
+ struct frame *tt;
+ tt = find_parent(fr->children[i], search);
+ if ( tt != NULL ) return tt;
+ }
+
+ return NULL;
+}
+
+
+void delete_subframe(struct frame *top, struct frame *fr)
+{
+ struct frame *parent;
+ int i, idx, found;
+
+ parent = find_parent(top, fr);
+ if ( parent == NULL ) {
+ fprintf(stderr, "Couldn't find parent when deleting frame.\n");
+ return;
+ }
+
+ found = 0;
+ for ( i=0; i<parent->num_children; i++ ) {
+ if ( parent->children[i] == fr ) {
+ idx = i;
+ found = 1;
+ break;
+ }
+ }
+
+ if ( !found ) {
+ fprintf(stderr, "Couldn't find child when deleting frame.\n");
+ return;
+ }
+
+ for ( i=idx; i<parent->num_children-1; i++ ) {
+ parent->children[i] = parent->children[i+1];
+ }
+
+ parent->num_children--;
+}