vis
a vi-like editor based on Plan 9's structural regular expressions
git clone https://9o.is/git/vis.git
commit 71c1c1be3a42797a3b2a813f4515abcd455f390b parent 6fcda63079afffb53f410610003892e8ae550725 Author: Marc André Tanner <mat@brain-dump.org> Date: Tue, 8 Nov 2016 22:35:42 +0100 sam: fix default value handling of +/- addresses We need to distinguish between an explicit given zero and an omitted value which should default to 1. This should fix the following constructs which rounds up/down an existing selection to whole lines -0,+0 and -0+,+0- Diffstat:
| M | sam.c | | | 9 | ++++++--- |
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/sam.c b/sam.c @@ -249,7 +249,10 @@ const char *sam_error(enum SamError err) { } static Address *address_new(void) { - return calloc(1, sizeof(Address)); + Address *addr = calloc(1, sizeof *addr); + if (addr) + addr->number = EPOS; + return addr; } static void address_free(Address *addr) { @@ -397,7 +400,7 @@ static Address *address_parse_simple(Vis *vis, const char **s, enum SamError *er Address addr = { .type = **s, .regex = NULL, - .number = 0, + .number = EPOS, .left = NULL, .right = NULL, }; @@ -659,7 +662,7 @@ static Command *sam_parse(Vis *vis, const char *cmd, enum SamError *err) { static Filerange address_line_evaluate(Address *addr, File *file, Filerange *range, int sign) { Text *txt = file->text; - size_t offset = addr->number != 0 ? addr->number : 1; + size_t offset = addr->number != EPOS ? addr->number : 1; size_t start = range->start, end = range->end, line; if (sign > 0) { char c;