chiark / gitweb /
working on compiling out of troglodyte; before relegage maskmap
[chiark-tcl.git] / maskmap / addrmap.c
index 2eb489843d148758209cb559f6580c59f84b1e39..33eeda42390c1dab9db0adef5eba40efcd962d0a 100644 (file)
@@ -1,24 +1,7 @@
 /*
  */
 
-#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 ----------*/
 
@@ -29,16 +12,16 @@ static void ame_free(AddrMap_Entry *ame) {
 
 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,
@@ -48,7 +31,7 @@ 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;
 }
@@ -114,9 +97,10 @@ static void am_free(AddrMap_Value *am) {
 
 /*---------- 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;
 }
@@ -132,8 +116,8 @@ static void addrmap_t_dup(Tcl_Obj *sob, Tcl_Obj *dob) {
   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);
@@ -148,7 +132,7 @@ static void addrmap_t_dup(Tcl_Obj *sob, Tcl_Obj *dob) {
     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) {
@@ -157,7 +141,7 @@ 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;
@@ -168,19 +152,19 @@ static void addrmap_t_ustr(Tcl_Obj *so) {
 
     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);
@@ -221,7 +205,7 @@ static int addrmap_t_sfa(Tcl_Interp *ip, Tcl_Obj *o) {
   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;
   }
 
@@ -229,7 +213,7 @@ static int addrmap_t_sfa(Tcl_Interp *ip, Tcl_Obj *o) {
   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;
   }
 
@@ -244,21 +228,21 @@ static int addrmap_t_sfa(Tcl_Interp *ip, Tcl_Obj *o) {
     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) {
@@ -276,7 +260,7 @@ static int addrmap_t_sfa(Tcl_Interp *ip, Tcl_Obj *o) {
     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);
@@ -286,9 +270,9 @@ static int addrmap_t_sfa(Tcl_Interp *ip, Tcl_Obj *o) {
   }
     
   /* 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:
@@ -299,7 +283,7 @@ static int addrmap_t_sfa(Tcl_Interp *ip, Tcl_Obj *o) {
   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
 };