diff options
author | Thomas White <taw@physics.org> | 2018-02-18 18:25:00 +0100 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2018-03-03 17:57:41 +0100 |
commit | 4b757f1f48643e9b049e4c868c94d127a6bc8c1c (patch) | |
tree | 2361a14bbd158677faef53c36dca790c3f45385f /src/sc_parse.c | |
parent | 2a80430b0e762e7ee3ccd0c8a620baf40fb30b12 (diff) |
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".
Diffstat (limited to 'src/sc_parse.c')
-rw-r--r-- | src/sc_parse.c | 13 |
1 files changed, 9 insertions, 4 deletions
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; } |