* hbytes chopto VAR NEWVARLENGTH => suffix (removed from VAR)
* (too short? error)
*
+ * hbytes compare A B
+ * => -2 A is lexically earlier than B and not a prefix of B (A<B)
+ * -1 A is prefix of B but not equal (A<B)
+ * 0 A == B
+ * +1 A is B plus a nonempty suffix (ie, A has B as a prefix)
+ * +2 A is lexically later than B and does not have B as a prefix
+ *
* hbytes pkcs5 pa|ua VAR ALG => worked? (always 1 for p)
* hbytes pkcs5 pn|un VAR BLOCKSIZE => worked? (always 1 for p)
* hbytes blockcipher d|e VAR ALG KEY MODE [IV] => IV
return TCL_OK;
}
+int do_hbytes_compare(ClientData cd, Tcl_Interp *ip,
+ HBytes_Value a, HBytes_Value b, int *result) {
+ int al, bl, minl, r;
+
+ al= hbytes_len(&a);
+ bl= hbytes_len(&b);
+ minl= al<bl ? al : bl;
+
+ r= memcmp(hbytes_data(&a), hbytes_data(&b), minl);
+
+ if (r<0) *result= -2;
+ else if (r>0) *result= +2;
+ else {
+ if (al<bl) *result= -1;
+ else if (al>bl) *result= +1;
+ else *result= 0;
+ }
+ return TCL_OK;
+}
+
int do__hbytes(ClientData cd, Tcl_Interp *ip,
const HBytes_SubCommand *subcmd,
int objc, Tcl_Obj *const *objv) {
length
v hb
=> int
+ compare
+ a hb
+ b hb
+ => int
prepend
v hbv
str ...
* hbytes chopto VAR NEWVARLENGTH => suffix (removed from VAR)
* (too short? error)
*
+ * hbytes compare A B
+ * => -2 A is lexically earlier than B and not a prefix of B (A<B)
+ * -1 A is prefix of B but not equal (A<B)
+ * 0 A == B
+ * +1 A is B plus a nonempty suffix (ie, A has B as a prefix)
+ * +2 A is lexically later than B and does not have B as a prefix
+ *
* hbytes pkcs5 pa|ua VAR ALG => worked? (always 1 for p)
* hbytes pkcs5 pn|un VAR BLOCKSIZE => worked? (always 1 for p)
* hbytes blockcipher d|e VAR ALG KEY MODE [IV] => IV
return TCL_OK;
}
+int do_hbytes_compare(ClientData cd, Tcl_Interp *ip,
+ HBytes_Value a, HBytes_Value b, int *result) {
+ int al, bl, minl, r;
+
+ al= hbytes_len(&a);
+ bl= hbytes_len(&b);
+ minl= al<bl ? al : bl;
+
+ r= memcmp(hbytes_data(&a), hbytes_data(&b), minl);
+
+ if (r<0) *result= -2;
+ else if (r>0) *result= +2;
+ else {
+ if (al<bl) *result= -1;
+ else if (al>bl) *result= +1;
+ else *result= 0;
+ }
+ return TCL_OK;
+}
+
int do__hbytes(ClientData cd, Tcl_Interp *ip,
const HBytes_SubCommand *subcmd,
int objc, Tcl_Obj *const *objv) {