-int do_hbytes_rep_info(ClientData cd, Tcl_Interp *ip,
- Tcl_Obj *obj, Tcl_Obj **result) {
- const char *tn;
- int nums[3], i, lnl;
- Tcl_Obj *objl[4];
-
- if (obj->typePtr == &hbytes_type) {
- HBytes_Value *v= OBJ_HBYTES(obj);
- memset(nums,0,sizeof(nums));
- nums[1]= hbytes_len(v);
-
- if (HBYTES_ISEMPTY(v)) tn= "empty";
- else if (HBYTES_ISSENTINEL(v)) tn= "sentinel!";
- else if (HBYTES_ISSIMPLE(v)) tn= "simple";
- else {
- HBytes_ComplexValue *cx= v->begin_complex;
- tn= "complex";
- nums[0]= cx->prespace;
- nums[2]= cx->avail - cx->len;
- }
- lnl= 3;
- } else {
- tn= "other";
- lnl= 0;
- }
-
- objl[0]= Tcl_NewStringObj((char*)tn,-1);
- for (i=0; i<lnl; i++) objl[i+1]= Tcl_NewIntObj(nums[i]);
- *result= Tcl_NewListObj(lnl+1,objl);
-
- return TCL_OK;
-}
-
-static void hbytes_t_dup(Tcl_Obj *src, Tcl_Obj *dup) {
- objfreeir(dup);
- hbytes_array(OBJ_HBYTES(dup),
- hbytes_data(OBJ_HBYTES(src)),
- hbytes_len(OBJ_HBYTES(src)));
-}
-
-static void hbytes_t_free(Tcl_Obj *o) {
- hbytes_free(OBJ_HBYTES(o));
-}
-
-void obj_updatestr_array_prefix(Tcl_Obj *o, const Byte *byte,
- int l, const char *prefix) {
- char *str;
- int pl;
-
- pl= strlen(prefix);
- o->length= l*2+pl;
- str= o->bytes= TALLOC(o->length+1);
-
- memcpy(str,prefix,pl);
- str += pl;
-
- while (l>0) {
- sprintf(str,"%02x",*byte);
- str+=2; byte++; l--;
- }
- *str= 0;
-}
-
-void obj_updatestr_array(Tcl_Obj *o, const Byte *byte, int l) {
- obj_updatestr_array_prefix(o,byte,l,"");
-}
-
-static void hbytes_t_ustr(Tcl_Obj *o) {
- obj_updatestr_array(o,
- hbytes_data(OBJ_HBYTES(o)),
- hbytes_len(OBJ_HBYTES(o)));
-}
-
-static int hbytes_t_sfa(Tcl_Interp *ip, Tcl_Obj *o) {
- char *str, *ep, *os;
- Byte *startbytes, *bytes;
- int l;
- char cbuf[3];
-
- os= str= Tcl_GetStringFromObj(o,&l); assert(str);
- objfreeir(o);
-
- if (l & 1) return staticerr(ip, "hbytes: conversion from hex:"
- " odd length in hex");
-
- startbytes= bytes= hbytes_arrayspace(OBJ_HBYTES(o), l/2);
-
- cbuf[2]= 0;
- while (l>0) {
- cbuf[0]= *str++;
- cbuf[1]= *str++;
- *bytes++= strtoul(cbuf,&ep,16);
- if (ep != cbuf+2) {
- hbytes_free(OBJ_HBYTES(o));
- return staticerr(ip, "hbytes: conversion from hex:"
- " bad hex digit");
- }
- l -= 2;
- }
-
- o->typePtr = &hbytes_type;
- return TCL_OK;
-}
-
-Tcl_ObjType hbytes_type = {
- "hbytes",
- hbytes_t_free, hbytes_t_dup, hbytes_t_ustr, hbytes_t_sfa
-};