commit d07cc6e6353a8a76e5fcf9e7a81e757d165bf383
parent b442fd4df7588d5441d9efb9aa334d6edb192cdc
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Thu, 10 Dec 2015 22:10:12 +0100
Fix relative addressing
Ed accepts address in the form addr-num, addr+num and addr^num,
where ^ has the same meaning that - (this is a historical
behaviour not required by POSIX), but the code was inverting
the sign of the offset.
Diffstat:
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/ed.c b/ed.c
@@ -384,6 +384,7 @@ linenum(int *line)
compile(c);
ln = match(c);
break;
+ case '^':
case '-':
case '+':
ln = curln;
@@ -411,14 +412,14 @@ address(int *line)
for (;;) {
skipblank();
- if ((c = input()) != '+' && c != '-')
+ if ((c = input()) != '+' && c != '-' && c != '^')
break;
- sign = c == '+';
+ sign = c == '+' ? 1 : -1;
num = isdigit(back(input())) ? getnum() : 1;
num *= sign;
if (INT_MAX - ln < num)
goto invalid;
- ln += sign * num;
+ ln += num;
}
back(c);