diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2016-11-08 22:35:42 +0100 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2016-11-08 22:35:42 +0100 |
| commit | 0e74ee26ef3d441a559ea18bec08018c0c2ef461 (patch) | |
| tree | 7f9c2321f968c59561f7bd179d791adf6d392a10 /sam.c | |
| parent | dcc453ee3a20dd09df20de8c3ff26099b87598b3 (diff) | |
| download | vis-0e74ee26ef3d441a559ea18bec08018c0c2ef461.tar.gz vis-0e74ee26ef3d441a559ea18bec08018c0c2ef461.tar.xz | |
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 (limited to 'sam.c')
| -rw-r--r-- | sam.c | 9 |
1 files changed, 6 insertions, 3 deletions
@@ -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; |
