From 4b757f1f48643e9b049e4c868c94d127a6bc8c1c Mon Sep 17 00:00:00 2001 From: Thomas White Date: Sun, 18 Feb 2018 18:25:00 +0100 Subject: Remove macro_real_block and friends, and delete text based on SCBlocks instead of runs macro_real_block was a pain because it meant we needed to look somewhere else every time we needed the SCBlock for something. The new way is to have two SCBlocks for each run, one which is the block from the flow of the actual document (i.e. for blocks within macros, this is the macro_real_block, otherwise it's the same as before). The second block ("rscblock") is whichever run actually contains the text for the run. It might be from the document, within the macro definition or within the macro's "\contents". --- src/sc_parse.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'src/sc_parse.c') diff --git a/src/sc_parse.c b/src/sc_parse.c index f2814b6..2607031 100644 --- a/src/sc_parse.c +++ b/src/sc_parse.c @@ -58,6 +58,7 @@ SCBlock *sc_block_new() SCBlock *sc_block_next(const SCBlock *bl) { + assert(bl != NULL); return bl->next; } @@ -734,23 +735,27 @@ void sc_insert_block(SCBlock *b1, int o1, SCBlock *ins) } -void scblock_delete_text(SCBlock *b, size_t o1, size_t o2) +/* Delete text from SCBlock contents. o2=-1 means "to the end". + * Returns the number of bytes deleted. */ +size_t scblock_delete_text(SCBlock *b, ssize_t o1, ssize_t o2) { - size_t len; if ( b->contents == NULL ) { fprintf(stderr, "Deleting text from block \\%s\n", b->name); - return; + return 0; } len = strlen(b->contents); + if ( o2 < 0 ) o2 = len; if ( (o1 >= o2) || (o1 > len) || (o2 > len) ) { fprintf(stderr, "Invalid delete: %i %i %i\n", (int)o1, (int)o2, (int)len); - return; + return 0; } memmove(b->contents+o1, b->contents+o2, len-o2+1); + + return o2-o1; } -- cgit v1.2.3