/*
*/
-#include <string.h>
-
-#include "tables.h"
-#include "hbytes.h"
-
-typedef struct {
- Byte *start; /* byl bytes */
- Tcl_Obj *data; /* may be 0 to mean empty */
-} AddrMap_Entry;
-
-struct AddrMap_Value {
- int byl, used, space;
- AddrMap_Entry *entries;
- /* Entries are sorted by start. Each entry gives value (or lack of
- * it) for all A st START <= A < NEXT-START. Last entry has value
- * (or lack of it) for all A >= START. First entry is always
- * present and always has start all-bits-0. */
-}; /* internalRep.otherValuePtr */
+#include "chiark_tcl_hbytes.h"
/*---------- operations on AddrMap_Entry ----------*/
static const Byte *ame_parsecheck_addr(Tcl_Interp *ip, const AddrMap_Value *am,
const HBytes_Value *hb) {
- int hbl= hbytes_len(hb);
+ int hbl= cht_hb_len(hb);
if (hbl < am->byl) {
- staticerr(ip,"addr-map address too short","HBYTES ADDRMAP UNDERRUN");
+ cht_staticerr(ip,"addr-map address too short","HBYTES ADDRMAP UNDERRUN");
return 0;
}
if (hbl > am->byl) {
- staticerr(ip,"addr-map address too long","HBYTES ADDRMAP OVERRUN");
+ cht_staticerr(ip,"addr-map address too long","HBYTES ADDRMAP OVERRUN");
return 0;
}
- return hbytes_data(hb);
+ return cht_hb_data(hb);
}
static int ame_parsecheck_range(Tcl_Interp *ip, const AddrMap_Value *am,
p_r[0]= ame_parsecheck_addr(ip,am,starthb); if (!p_r[0]) return TCL_ERROR;
p_r[1]= ame_parsecheck_addr(ip,am,endhb); if (!p_r[0]) return TCL_ERROR;
if (memcmp(p_r[0],p_r[1],am->byl) > 0)
- return staticerr(ip, "addr-map range start is after end",
+ return cht_staticerr(ip, "addr-map range start is after end",
"HBYTES ADDRMAP BADRANGE");
return TCL_OK;
}
/*---------- Tcl type and arg parsing functions ----------*/
-int pat_addrmapv(Tcl_Interp *ip, Tcl_Obj *var, AddrMap_Var *agg) {
+int cht_pat_addrmapv(Tcl_Interp *ip, Tcl_Obj *var, AddrMap_Var *agg) {
int rc;
- rc= pat_somethingv(ip,var,&agg->sth,&addrmap_type); if (rc) return rc;
+ rc= cht_pat_somethingv(ip,var,&agg->sth,&cht_addrmap_type);
+ if (rc) return rc;
agg->am= agg->sth.obj->internalRep.otherValuePtr;
return TCL_OK;
}
AddrMap_Entry *sme, *dme;
int i;
- assert(sob->typePtr == &addrmap_type);
- objfreeir(dob);
+ assert(sob->typePtr == &cht_addrmap_type);
+ cht_objfreeir(dob);
dm= TALLOC(sizeof(*dm));
am_init0(dm,sm->byl);
Tcl_IncrRefCount(dme->data);
}
dob->internalRep.otherValuePtr= dm;
- dob->typePtr= &addrmap_type;
+ dob->typePtr= &cht_addrmap_type;
}
static void addrmap_t_ustr(Tcl_Obj *so) {
AddrMap_Entry *sme;
int entnum, listlength;
- assert(so->typePtr == &addrmap_type);
+ assert(so->typePtr == &cht_addrmap_type);
mainlobjsl= TALLOC(sizeof(*mainlobjsl) * (sm->used+1)); assert(mainlobjsl);
mainlobjsl[0]= Tcl_NewIntObj(sm->byl * 8);
listlength= 1;
if (!sme->data) continue;
- hbytes_array(&hb, sme->start, sm->byl);
- subl[0]= ret_hb(0, hb); assert(subl[0]);
+ cht_hb_array(&hb, sme->start, sm->byl);
+ subl[0]= cht_ret_hb(0, hb); assert(subl[0]);
if (entnum+1 < sm->used) {
- ame_ba_addsubtractone(hbytes_arrayspace(&hb, sm->byl),
+ ame_ba_addsubtractone(cht_hb_arrayspace(&hb, sm->byl),
(sme+1)->start, sm->byl,
/*subtract:*/ 0x0ffu, 0x0ffu);
} else {
- memset(hbytes_arrayspace(&hb, sm->byl),
+ memset(cht_hb_arrayspace(&hb, sm->byl),
0x0ffu, sm->byl);
}
- subl[1]= ret_hb(0, hb); assert(subl[1]);
+ subl[1]= cht_ret_hb(0, hb); assert(subl[1]);
subl[2]= sme->data;
sublo= Tcl_NewListObj(3,subl); assert(sublo);
rc= Tcl_ListObjLength(ip,o,&inlen); if (rc) goto x_badvalue_rc;
if (inlen<0) {
- rc= staticerr(ip, "addr-map overall length < 1", 0);
+ rc= cht_staticerr(ip, "addr-map overall length < 1", 0);
goto x_badvalue_rc;
}
rc= Tcl_GetIntFromObj(ip,eo,&bitlen); if (rc) goto x_badvalue_rc;
if (bitlen<0 || bitlen % 8) {
- rc= staticerr(ip, "addr-map overall length < 1", 0);
+ rc= cht_staticerr(ip, "addr-map overall length < 1", 0);
goto x_badvalue_rc;
}
rc= Tcl_ListObjLength(ip,eo,&eol); if (rc) goto x_badvalue_rc;
if (eol != 3) {
- rc= staticerr(ip, "addr-map entry length != 3", 0);
+ rc= cht_staticerr(ip, "addr-map entry length != 3", 0);
goto x_badvalue_rc;
}
rc= Tcl_ListObjIndex(ip,eo,0,&starto); if (rc) goto x_badvalue_rc;
rc= Tcl_ListObjIndex(ip,eo,1,&endo); if (rc) goto x_badvalue_rc;
- rc= pat_hb(ip,starto,&starthb); if (rc) goto x_badvalue_rc;
- rc= pat_hb(ip,endo,&endhb); if (rc) goto x_badvalue_rc;
+ rc= cht_pat_hb(ip,starto,&starthb); if (rc) goto x_badvalue_rc;
+ rc= cht_pat_hb(ip,endo,&endhb); if (rc) goto x_badvalue_rc;
rc= ame_parsecheck_range(ip,am,&starthb,&endhb,rangeptrs);
if (rc) goto x_badvalue_rc;
cmp= memcmp(ame->start, rangeptrs[0], am->byl);
if (cmp < 0) {
- rc= staticerr(ip, "addr-map entries out of order", 0);
+ rc= cht_staticerr(ip, "addr-map entries out of order", 0);
goto x_badvalue_rc;
}
if (cmp > 0) {
if (rc) {
/* we've overflowed. it must have been ffffffff.... */
if (innum != inlen-1) {
- rc= staticerr(ip, "addr-map non-last entry end is all-bits-1", 0);
+ rc= cht_staticerr(ip, "addr-map non-last entry end is all-bits-1", 0);
goto x_badvalue_rc;
}
TFREE(ame->start);
}
/* we commit now */
- objfreeir(o);
+ cht_objfreeir(o);
o->internalRep.otherValuePtr= am;
- o->typePtr= &addrmap_type;
+ o->typePtr= &cht_addrmap_type;
return TCL_OK;
x_badvalue_rc:
return rc;
}
-Tcl_ObjType addrmap_type = {
+Tcl_ObjType cht_addrmap_type = {
"addr-map",
addrmap_t_free, addrmap_t_dup, addrmap_t_ustr, addrmap_t_sfa
};