commit 79d88c885f270196b1148bc946abc5da7739825f
parent dd873168e8451f83d9f16a87afb4578ba236f571
Author: Byron Torres <b@torresjrjr.com>
Date: Mon, 12 Dec 2022 04:05:54 +0000
fix lineoffset; add debug()
Diffstat:
4 files changed, 13 insertions(+), 8 deletions(-)
diff --git a/buffer.ha b/buffer.ha
@@ -27,7 +27,7 @@ fn buf_deleteall(buf: *buffer) void = {
};
fn buf_delete(buf: *buffer, a: size, b: size) void = {
- fmt::errorfln("DEBUG: buf_delete(a={}, b={})", a, b)!;
+ debug("buf_delete(a={}, b={})", a, b);
buf_wipetrash(buf);
insert(buf.trash[0], buf.lines[a..b+1]...);
diff --git a/command.ha b/command.ha
@@ -59,10 +59,9 @@ fn exec_addrs(s: *session, cmd: *command) (void | error) = {
case let m: rune =>
yield addr_mark(&s.buf, m)?;
};
- n = (n: int + addr.lineoffset): size;
- fmt::errorfln("DEBUG: exec_addrs() n={}", n)!;
+ n = n + addr.lineoffset: size; // beware of negatives
+ debug("exec_addrs(): n={}", n);
append(cmd.linenums, n);
- // fmt::errorfln("DEBUG: exec_addrs() ...[i]={}", cmd.linenums[i])!;
if (addr.setcurrentline) {
s.buf.cursor = n;
@@ -79,7 +78,7 @@ fn get_range(s: *session, lns: *[]size, a: size, b: size) ((size, size) | badadd
} else {
yield (lns[len(lns)-2], lns[len(lns)-1]);
};
- fmt::errorfln("DEBUG: get_range() (a, b)=({}, {})", a, b)!;
+ debug("get_range(): (a, b)=({}, {})", a, b);
if (a > b) {
errormsg(s, "Invalid address");
return badaddress;
diff --git a/parse.ha b/parse.ha
@@ -88,7 +88,7 @@ fn scan_addrs(iter: *strings::iterator) []address = {
};
};
- // fmt::errorfln("DEBUG: scan_addrs() len(addrs)={}", len(addrs))!;
+ // debug("scan_addrs(): len(addrs)={}", len(addrs))!;
return addrs;
};
@@ -102,7 +102,7 @@ fn scan_addr(iter: *strings::iterator) (address | void) = {
yield r;
};
- // fmt::errorfln("DEBUG: scan_addr() r={}", r)!;
+ // debug("scan_addr(): r={}", r)!;
const addrtype: (addresstype | void) =
if (r == '.') {
@@ -166,7 +166,7 @@ fn scan_offsets(iter: *strings::iterator) []int = {
if (r == '+') {
append(offs, scan_offset(iter));
} else if (r == '-') {
- append(offs, scan_offset(iter));
+ append(offs, -scan_offset(iter));
} else if (ascii::isdigit(r)) {
strings::prev(iter);
append(offs, scan_uint(iter): int);
diff --git a/util.ha b/util.ha
@@ -9,3 +9,9 @@ fn dumpbuffer(buf: *buffer) void = {
fmt::printfln("{}\t{}", n, buf.lines[n].text)!;
};
};
+
+fn debug(fmtstr: str, args: fmt::field...) void = {
+ fmt::error("\x1b[31mdebug: ")!;
+ fmt::errorf(fmtstr, args...)!;
+ fmt::errorln("\x1b[m")!;
+};