+
+/* hbytes representing uint16_t's */
+
+int cht_do_hbytes_h2ushort(ClientData cd, Tcl_Interp *ip,
+ HBytes_Value hex, long *result) {
+ const Byte *data;
+ int l;
+
+ l= cht_hb_len(&hex);
+ if (l>2)
+ return cht_staticerr(ip, "hbytes h2ushort input more than 4 hex digits",
+ "HBYTES VALUE OVERFLOW");
+
+ data= cht_hb_data(&hex);
+ *result= data[l-1] | (l>1 ? data[0]<<8 : 0);
+ return TCL_OK;
+}
+
+int cht_do_hbytes_ushort2h(ClientData cd, Tcl_Interp *ip,
+ long input, HBytes_Value *result) {
+ uint16_t us;
+
+ if (input > 0x0ffff)
+ return cht_staticerr(ip, "hbytes ushort2h input >2^16",
+ "HBYTES VALUE OVERFLOW");
+
+ us= htons(input);
+ cht_hb_array(result,(const Byte*)&us,2);
+ return TCL_OK;
+}
+
+/* toplevel functions */
+
+int cht_do_hbytestoplevel_hbytes(ClientData cd, Tcl_Interp *ip,
+ const HBytes_SubCommand *subcmd,
+ int objc, Tcl_Obj *const *objv) {
+ return subcmd->func(0,ip,objc,objv);
+}
+
+int cht_do_hbytestoplevel_ulong(ClientData cd, Tcl_Interp *ip,
+ const ULong_SubCommand *subcmd,
+ int objc, Tcl_Obj *const *objv) {
+ return subcmd->func(0,ip,objc,objv);
+}
+
+int Chiark_tcl_hbytes_Init(Tcl_Interp *ip) {
+ static int initd;
+
+ return cht_initextension(ip, cht_hbytestoplevel_entries, &initd,
+ &cht_hbytes_type,
+ &cht_ulong_type,
+ (Tcl_ObjType*)0);
+}