+int cht_do_hbytes_overwrite(ClientData cd, Tcl_Interp *ip,
+ HBytes_Var v, int start, HBytes_Value sub) {
+ int sub_l;
+
+ sub_l= cht_hb_len(&sub);
+ if (start < 0)
+ return cht_staticerr(ip, "hbytes overwrite start -ve",
+ "HBYTES LENGTH RANGE");
+ if (start + sub_l > cht_hb_len(v.hb))
+ return cht_staticerr(ip, "hbytes overwrite out of range",
+ "HBYTES LENGTH UNDERRUN");
+ memcpy(cht_hb_data(v.hb) + start, cht_hb_data(&sub), sub_l);
+ return TCL_OK;
+}
+
+int cht_do_hbytes_trimleft(ClientData cd, Tcl_Interp *ip, HBytes_Var v) {
+ const Byte *o, *p, *e;
+ o= p= cht_hb_data(v.hb);
+ e= p + cht_hb_len(v.hb);
+
+ while (p<e && !*p) p++;
+ if (p != o)
+ cht_hb_unprepend(v.hb, p-o);
+
+ return TCL_OK;
+}
+
+int cht_do_hbytes_repeat(ClientData cd, Tcl_Interp *ip,
+ HBytes_Value sub, int count, HBytes_Value *result) {
+ int sub_l;
+ Byte *data;
+ const Byte *sub_d;
+
+ sub_l= cht_hb_len(&sub);
+ if (count < 0) return cht_staticerr(ip, "hbytes repeat count -ve",
+ "HBYTES LENGTH RANGE");
+ if (count > INT_MAX/sub_l) return cht_staticerr(ip, "hbytes repeat too long", 0);
+
+ data= cht_hb_arrayspace(result, sub_l*count);
+ sub_d= cht_hb_data(&sub);
+ while (count) {
+ memcpy(data, sub_d, sub_l);
+ count--; data += sub_l;
+ }
+ return TCL_OK;
+}
+
+int cht_do_hbytes_xor(ClientData cd, Tcl_Interp *ip,
+ HBytes_Var v, HBytes_Value d) {
+ int l;
+ Byte *dest;
+ const Byte *source;
+
+ l= cht_hb_len(v.hb);
+ if (cht_hb_len(&d) != l) return
+ cht_staticerr(ip, "hbytes xor lengths do not match", "HBYTES LENGTH MISMATCH");
+
+ dest= cht_hb_data(v.hb);
+ source= cht_hb_data(&d);
+ memxor(dest,source,l);
+ return TCL_OK;
+}
+
+int cht_do_hbytes_zeroes(ClientData cd, Tcl_Interp *ip,