From af1fccb1e2bd7355f4e00d014ccad232240aced7 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Thu, 26 Dec 2019 20:31:35 +0100 Subject: WIP on copy and paste --- libstorycode/narrative.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'libstorycode/narrative.c') 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; ritems[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; -- cgit v1.2.3