chiark / gitweb /
tuntap: Do not build on non-Linux platforms.
[chiark-tcl.git] / base / enum.c
index 8041cd378a5b05f1c486f2f4049700299f91c631..28189c77e264d489693a74b32e0f4a4f8218564a 100644 (file)
@@ -1,13 +1,26 @@
 /*
+ * base code for various Tcl extensions
+ * 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 <string.h>
-
-#include "hbytes.h"
+#include "chiark-tcl-base.h"
 
 static void enum_nt_dup(Tcl_Obj *src, Tcl_Obj *dup) {
   dup->internalRep= src->internalRep;
+  dup->typePtr= src->typePtr;
 }
 
 static void enum_nt_ustr(Tcl_Obj *o) {
@@ -18,12 +31,12 @@ static int enum_nt_sfa(Tcl_Interp *ip, Tcl_Obj *o) {
   abort();
 }
 
-Tcl_ObjType enum_nearlytype = {
+Tcl_ObjType cht_enum_nearlytype = {
   "enum-nearly",
   0, enum_nt_dup, enum_nt_ustr, enum_nt_sfa
 };
 
-Tcl_ObjType enum1_nearlytype = {
+Tcl_ObjType cht_enum1_nearlytype = {
   "enum1-nearly",
   0, enum_nt_dup, enum_nt_ustr, enum_nt_sfa
 };
@@ -57,13 +70,13 @@ static void appres_enum(Tcl_Interp *ip, const void *p) {
   Tcl_AppendResult(ip, enum_str(p), (char*)0);
 }
 
-const void *enum_lookup_cached_func(Tcl_Interp *ip, Tcl_Obj *o,
+const void *cht_enum_lookup_cached_func(Tcl_Interp *ip, Tcl_Obj *o,
                                    const void *firstentry, size_t entrysize,
                                    const char *what) {
   const char *supplied, *found;
   const char *ep;
   
-  if (o->typePtr == &enum_nearlytype &&
+  if (o->typePtr == &cht_enum_nearlytype &&
       o->internalRep.twoPtrValue.ptr1 == firstentry)
     return o->internalRep.twoPtrValue.ptr2;
 
@@ -73,8 +86,8 @@ const void *enum_lookup_cached_func(Tcl_Interp *ip, Tcl_Obj *o,
        ep += entrysize);
 
   if (found) {
-    objfreeir(o);
-    o->typePtr= &enum_nearlytype;
+    cht_objfreeir(o);
+    o->typePtr= &cht_enum_nearlytype;
     o->internalRep.twoPtrValue.ptr1= (void*)firstentry;
     o->internalRep.twoPtrValue.ptr2= (void*)ep;
     return ep;
@@ -92,11 +105,11 @@ static void appres_enum1(Tcl_Interp *ip, const void *p) {
   Tcl_AppendResult(ip, buf, (char*)0);
 }
 
-int enum1_lookup_cached_func(Tcl_Interp *ip, Tcl_Obj *o,
+int cht_enum1_lookup_cached_func(Tcl_Interp *ip, Tcl_Obj *o,
                             const char *opts, const char *what) {
   const char *supplied, *fp;
   
-  if (o->typePtr != &enum1_nearlytype ||
+  if (o->typePtr != &cht_enum1_nearlytype ||
       o->internalRep.twoPtrValue.ptr1 != opts) {
 
     supplied= Tcl_GetStringFromObj(o,0);  assert(supplied);
@@ -107,8 +120,8 @@ int enum1_lookup_cached_func(Tcl_Interp *ip, Tcl_Obj *o,
       return -1;
     }
     
-    objfreeir(o);
-    o->typePtr= &enum1_nearlytype;
+    cht_objfreeir(o);
+    o->typePtr= &cht_enum1_nearlytype;
     o->internalRep.twoPtrValue.ptr1= (void*)opts;
     o->internalRep.twoPtrValue.ptr2= (void*)fp;
   }