summaryrefslogtreecommitdiffstats
path: root/lib.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2019-09-20 07:46:52 -0700
committerKaz Kylheku <kaz@kylheku.com>2019-09-20 07:46:52 -0700
commit7a9ab728565c650e0631744e79e7e8a77f57e347 (patch)
treeace13a75f84dd65698821027fc081fd66c474222 /lib.c
parentdfc6ac6ad22e1d4c86ce7c201c5d42085ae29137 (diff)
downloadtxr-7a9ab728565c650e0631744e79e7e8a77f57e347.tar.gz
txr-7a9ab728565c650e0631744e79e7e8a77f57e347.tar.bz2
txr-7a9ab728565c650e0631744e79e7e8a77f57e347.zip
buffers: allow inequality comparison with less.
* lib.c (less_tab_init): Assign category 6 to BUF type, so buffers are sorted after other types. (less): Add BUF case. * txr.1: Documented.
Diffstat (limited to 'lib.c')
-rw-r--r--lib.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/lib.c b/lib.c
index f4f47b76..862bb1ce 100644
--- a/lib.c
+++ b/lib.c
@@ -4563,6 +4563,7 @@ static void less_tab_init(void)
type_prec[BGNUM] = 1;
type_prec[FLNUM] = 1;
type_prec[RNG] = 2;
+ type_prec[BUF] = 6;
for (l = 0; l <= MAXTYPE; l++)
for (r = 0; r <= MAXTYPE; r++) {
@@ -4689,6 +4690,19 @@ tail:
return nil;
}
+ case BUF:
+ {
+ cnum ll = c_num(left->b.len);
+ cnum rl = c_num(right->b.len);
+ cnum len = min(ll, rl);
+ int cmp = memcmp(left->b.data, right->b.data, len);
+
+ if (cmp < 0 || (cmp == 0 && ll < rl))
+ return t;
+
+ return nil;
+ }
+ break;
default:
internal_error("unhandled case in less function");
}