chiark / gitweb /
add misc:Depends
[chiark-tcl.git] / hbytes / parse.c
1 /*
2  * hbytes - hex-stringrep efficient byteblocks for Tcl
3  * Copyright 2006 Ian Jackson
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License as
7  * published by the Free Software Foundation; either version 2 of the
8  * License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18  * 02110-1301, USA.
19  */
20
21 #include "chiark_tcl_hbytes.h"
22
23 int cht_pat_hbv(Tcl_Interp *ip, Tcl_Obj *var, HBytes_Var *agg) {
24   int rc;
25   rc= cht_pat_somethingv(ip,var,&agg->sth,&cht_hbytes_type);
26   if (rc) return rc;
27   agg->hb= OBJ_HBYTES(agg->sth.obj);
28   return TCL_OK;
29 }
30 int cht_pat_hb(Tcl_Interp *ip, Tcl_Obj *obj, HBytes_Value *val) {
31   int rc;
32   rc= Tcl_ConvertToType(ip,obj,&cht_hbytes_type);  if (rc) return rc;
33   *val= *OBJ_HBYTES(obj);
34   return TCL_OK;
35 }
36
37 Tcl_Obj *cht_ret_hb(Tcl_Interp *ip, HBytes_Value val) {
38   Tcl_Obj *obj;
39   obj= Tcl_NewObj();
40   Tcl_InvalidateStringRep(obj);
41   *OBJ_HBYTES(obj)= val;
42   obj->typePtr= &cht_hbytes_type;
43   return obj;
44 }