chiark / gitweb /
Debian package wip
[chiark-tcl.git] / hbytes / parse.c
index 125dd61eb9e182a2fbfd36f46ac824f38a9f006e..1b23e93ca420a83afa3fa758a3baae98944266ab 100644 (file)
@@ -1,16 +1,44 @@
-  sc= enum_lookup_cached(ip,objv[1],subcommands,"hbytes subcommand");
+/*
+ * hbytes - hex-stringrep efficient byteblocks for Tcl
+ * Copyright 2006 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
 
+#include "chiark_tcl_hbytes.h"
 
-static Tcl_Obj *hb_getvar(Tcl_Interp *ip, Tcl_Obj *varname) {
-  int ec;
-  Tcl_Obj *value;
-  
-  value= Tcl_ObjGetVar2(ip,varname,0,TCL_LEAVE_ERR_MSG);
-  if (!value) return 0;
-
-  ec= Tcl_ConvertToType(ip,value,&hbytes_type);
-  if (ec) return 0;
-
-  return value;
+int cht_pat_hbv(Tcl_Interp *ip, Tcl_Obj *var, HBytes_Var *agg) {
+  int rc;
+  rc= cht_pat_somethingv(ip,var,&agg->sth,&cht_hbytes_type);
+  if (rc) return rc;
+  agg->hb= OBJ_HBYTES(agg->sth.obj);
+  return TCL_OK;
+}
+int cht_pat_hb(Tcl_Interp *ip, Tcl_Obj *obj, HBytes_Value *val) {
+  int rc;
+  rc= Tcl_ConvertToType(ip,obj,&cht_hbytes_type);  if (rc) return rc;
+  *val= *OBJ_HBYTES(obj);
+  return TCL_OK;
 }
 
+Tcl_Obj *cht_ret_hb(Tcl_Interp *ip, HBytes_Value val) {
+  Tcl_Obj *obj;
+  obj= Tcl_NewObj();
+  Tcl_InvalidateStringRep(obj);
+  *OBJ_HBYTES(obj)= val;
+  obj->typePtr= &cht_hbytes_type;
+  return obj;
+}