chiark / gitweb /
wiringpi: drop piFace
[chiark-tcl.git] / hbytes / hook.c
index 985122ecb1c912690aa612a58a5c623536597ab4..f570709494ce0588c29de51ed97ca254287cb794 100644 (file)
@@ -1,6 +1,22 @@
 /*
+ * hbytes - hex-stringrep efficient byteblocks for Tcl
+ * Copyright 2006-2012 Ian Jackson
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
+
 #include <errno.h>
 
 #include "chiark_tcl_hbytes.h"
@@ -49,12 +65,13 @@ static void hbytes_t_free(Tcl_Obj *o) {
   cht_hb_free(OBJ_HBYTES(o));
 }
 
-void obj_updatestr_array_prefix(Tcl_Obj *o, const Byte *byte,
+void cht_obj_updatestr_array_prefix(Tcl_Obj *o, const Byte *byte,
                                int l, const char *prefix) {
   char *str;
   int pl;
 
   pl= strlen(prefix);
+  assert(l < INT_MAX/2 - 1 - pl);
   o->length= l*2+pl;
   str= o->bytes= TALLOC(o->length+1);
   
@@ -68,19 +85,19 @@ void obj_updatestr_array_prefix(Tcl_Obj *o, const Byte *byte,
   *str= 0;
 }
 
-void obj_updatestr_array(Tcl_Obj *o, const Byte *byte, int l) {
-  obj_updatestr_array_prefix(o,byte,l,"");
+void cht_obj_updatestr_array(Tcl_Obj *o, const Byte *byte, int l) {
+  cht_obj_updatestr_array_prefix(o,byte,l,"");
 }
 
 static void hbytes_t_ustr(Tcl_Obj *o) {
-  obj_updatestr_array(o,
+  cht_obj_updatestr_array(o,
                      cht_hb_data(OBJ_HBYTES(o)),
                      cht_hb_len(OBJ_HBYTES(o)));
 }
 
 static int hbytes_t_sfa(Tcl_Interp *ip, Tcl_Obj *o) {
-  char *str, *ep, *os;
-  Byte *startbytes, *bytes;
+  char *str, *ep;
+  Byte *bytes;
   int l;
   char cbuf[3];
 
@@ -92,13 +109,13 @@ static int hbytes_t_sfa(Tcl_Interp *ip, Tcl_Obj *o) {
 
   } else {
   
-    os= str= Tcl_GetStringFromObj(o,&l);  assert(str);
+    str= Tcl_GetStringFromObj(o,&l);  assert(str);
     cht_objfreeir(o);
 
     if (l & 1) return cht_staticerr(ip, "hbytes: conversion from hex:"
                                " odd length in hex", "HBYTES SYNTAX");
 
-    startbytes= bytes= cht_hb_arrayspace(OBJ_HBYTES(o), l/2);
+    bytes= cht_hb_arrayspace(OBJ_HBYTES(o), l/2);
 
     cbuf[2]= 0;
     while (l>0) {
@@ -298,23 +315,6 @@ int cht_do_hbytes_ushort2h(ClientData cd, Tcl_Interp *ip,
 
 /* 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);
-}
+CHT_INIT(hbytes,
+        CHTI_TYPE(cht_hbytes_type) CHTI_TYPE(cht_ulong_type),
+        CHTI_COMMANDS(cht_hbytestoplevel_entries))