aboutsummaryrefslogtreecommitdiff
path: root/src/frame.c
diff options
context:
space:
mode:
authorThomas White <taw@bitwiz.org.uk>2012-11-23 23:20:45 +0100
committerThomas White <taw@bitwiz.org.uk>2012-11-23 23:20:45 +0100
commit26b9654f1090cbe02915a501c3976192e7f029d3 (patch)
treebb027eefd8259045f317fbb0045c1411b1c767d8 /src/frame.c
parentc127216f2f7bc6e33252e08ee98782fefcaf7b8b (diff)
Break storycode stuff off into a separate library
Diffstat (limited to 'src/frame.c')
-rw-r--r--src/frame.c59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/frame.c b/src/frame.c
index 637fff1..75a9810 100644
--- a/src/frame.c
+++ b/src/frame.c
@@ -82,3 +82,62 @@ struct frame *add_subframe(struct frame *fr)
return n;
}
+
+static void show_heirarchy(struct frame *fr, const char *t)
+{
+ int i;
+ char tn[1024];
+
+ strcpy(tn, t);
+ strcat(tn, " |-> ");
+
+ printf("%s%p %s\n", t, fr, fr->sc);
+
+ for ( i=0; i<fr->num_ro; i++ ) {
+ if ( fr->rendering_order[i] != fr ) {
+ show_heirarchy(fr->rendering_order[i], tn);
+ } else {
+ printf("%s<this frame>\n", tn);
+ }
+ }
+
+}
+
+
+static void recursive_unpack(struct frame *fr, const char *sc)
+{
+ SCBlockList *bl;
+ SCBlockListIterator *iter;
+ struct scblock *b;
+
+ bl = sc_find_blocks(sc, "f");
+
+ for ( b = sc_block_list_first(bl, &iter);
+ b != NULL;
+ b = sc_block_list_next(bl, iter) )
+ {
+ struct frame *sfr;
+ sfr = add_subframe(fr);
+ sfr->sc = remove_blocks(b->contents, "f");
+ recursive_unpack(sfr, b->contents);
+ }
+ sc_block_list_free(bl);
+}
+
+
+/* Unpack level 2 StoryCode (content + subframes) into frames */
+struct frame *sc_unpack(const char *sc)
+{
+ struct frame *fr;
+
+ fr = frame_new();
+ if ( fr == NULL ) return NULL;
+
+ fr->sc = remove_blocks(sc, "f");
+ recursive_unpack(fr, sc);
+
+ show_heirarchy(fr, "");
+
+ return fr;
+}
+