aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/frame.c58
-rw-r--r--src/frame.h4
-rw-r--r--src/presentation.c52
-rw-r--r--src/presentation.h3
-rw-r--r--src/sc_interp.c26
5 files changed, 85 insertions, 58 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--;
+}
diff --git a/src/frame.h b/src/frame.h
index 8f70c33..68d8649 100644
--- a/src/frame.h
+++ b/src/frame.h
@@ -1,7 +1,7 @@
/*
* frame.h
*
- * Copyright © 2013-2014 Thomas White <taw@bitwiz.org.uk>
+ * Copyright © 2013-2015 Thomas White <taw@bitwiz.org.uk>
*
* This file is part of Colloquium.
*
@@ -56,6 +56,7 @@ struct frame
SCBlock *scblocks;
struct wrap_line *boxes; /* The unwrapped boxes */
+ int visited;
int n_lines;
int max_lines;
@@ -95,5 +96,6 @@ extern struct frame *frame_new(void);
extern struct frame *add_subframe(struct frame *fr);
extern void renew_frame(struct frame *fr);
extern void show_hierarchy(struct frame *fr, const char *t);
+extern void delete_subframe(struct frame *top, struct frame *fr);
#endif /* FRAME_H */
diff --git a/src/presentation.c b/src/presentation.c
index 039f61a..e95bd92 100644
--- a/src/presentation.c
+++ b/src/presentation.c
@@ -387,55 +387,3 @@ next:
return 0;
}
-
-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--;
-}
diff --git a/src/presentation.h b/src/presentation.h
index fd78a11..b1f6e2c 100644
--- a/src/presentation.h
+++ b/src/presentation.h
@@ -90,9 +90,6 @@ extern int insert_slide(struct presentation *p, struct slide *s, int pos);
extern void free_slide(struct slide *s);
extern void delete_slide(struct presentation *p, struct slide *s);
-extern void delete_subframe(struct frame *top, struct frame *fr);
-
-
extern char *packed_sc(struct frame *fr);
extern int slide_number(struct presentation *p, struct slide *s);
diff --git a/src/sc_interp.c b/src/sc_interp.c
index e1a5df7..86e2329 100644
--- a/src/sc_interp.c
+++ b/src/sc_interp.c
@@ -811,8 +811,6 @@ static int check_outputs(SCBlock *bl, SCInterpreter *scin)
struct frame *fr = sc_block_frame(bl);
- renew_frame(fr);
-
if ( fr == NULL ) {
fr = add_subframe(sc_interp_get_frame(scin));
sc_block_set_frame(bl, fr);
@@ -827,6 +825,7 @@ static int check_outputs(SCBlock *bl, SCInterpreter *scin)
fprintf(stderr, "Failed to add frame.\n");
return 1;
}
+ fr->visited = 1;
parse_frame_options(fr, sc_interp_get_frame(scin),
options);
@@ -897,6 +896,27 @@ static void run_macro_contents(SCInterpreter *scin)
}
+static void delete_unused_subframes(struct frame *fr)
+{
+ int i;
+ int done = 1;
+
+ do {
+ printf("checking %i children of %p\n", fr->num_children, fr);
+ for ( i=0; i<fr->num_children; i++ ) {
+ if ( !fr->children[i]->visited ) {
+ delete_subframe(fr, fr->children[i]);
+ done = 0;
+ printf("deleting %p\n", fr->children[i]);
+ break;
+ } else {
+ delete_unused_subframes(fr->children[i]);
+ }
+ }
+ } while ( !done );
+}
+
+
int sc_interp_add_blocks(SCInterpreter *scin, SCBlock *bl)
{
//printf("Running this --------->\n");
@@ -975,6 +995,8 @@ int sc_interp_add_blocks(SCInterpreter *scin, SCBlock *bl)
}
+ delete_unused_subframes(sc_interp_get_frame(scin));
+
return 0;
}