aboutsummaryrefslogtreecommitdiff
path: root/libstorycode/narrative.c
diff options
context:
space:
mode:
Diffstat (limited to 'libstorycode/narrative.c')
-rw-r--r--libstorycode/narrative.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/libstorycode/narrative.c b/libstorycode/narrative.c
index 67fe9e9..cd4b10e 100644
--- a/libstorycode/narrative.c
+++ b/libstorycode/narrative.c
@@ -589,6 +589,45 @@ Slide *narrative_get_slide_by_number(Narrative *n, int pos)
}
+/* Return the text between item p1/offset o1 and p2/o2 */
+char *narrative_range_as_text(Narrative *n, int p1, size_t o1, int p2, size_t o2)
+{
+ int i;
+ char *t;
+ size_t len = 0;
+ size_t size = 256;
+
+ t = malloc(size);
+ if ( t == NULL ) return NULL;
+
+ t[0] = '\0';
+
+ for ( i=p1; i<=p2; i++ ) {
+ int r;
+ if ( !narrative_item_is_text(n, i) ) continue;
+ for ( r=0; r<n->items[i].n_runs; r++ ) {
+ size_t this_len = strlen(n->items[i].runs[r].text);
+ if ( this_len + len + 2 > size ) {
+ char *nt;
+ size += 256 + this_len;
+ nt = realloc(t, size);
+ if ( nt == NULL ) {
+ fprintf(stderr, "Failed to allocate\n");
+ return NULL;
+ }
+ t = nt;
+ }
+ memcpy(&t[len], n->items[i].runs[r].text, this_len+1);
+ len += this_len;
+ }
+ t[len++] = '\n';
+ t[len] = '\0';
+ }
+
+ return t;
+}
+
+
static void debug_runs(struct narrative_item *item)
{
int j;
@@ -597,6 +636,7 @@ static void debug_runs(struct narrative_item *item)
}
}
+
void narrative_debug(Narrative *n)
{
int i;