From 0e74ee26ef3d441a559ea18bec08018c0c2ef461 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Tue, 8 Nov 2016 22:35:42 +0100 Subject: 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- --- sam.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'sam.c') diff --git a/sam.c b/sam.c index 4d20f4a..984b63b 100644 --- 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; -- cgit v1.2.3