chiark / gitweb /
all compiles again. more pat to do.
[chiark-tcl.git] / hbytes / parse.c
1 /*
2  */
3
4 #include "tables.h"
5
6 int pat_charfrom(Tcl_Interp *ip, Tcl_Obj *obj, int *val,
7                  const char *opts, const char *what) {
8   *val= enum1_lookup_cached_func(ip,obj,opts,what);
9   if (*val==-1) return TCL_ERROR;
10   return TCL_OK;
11 }
12
13 int pat_enum(Tcl_Interp *ip, Tcl_Obj *obj, const void **val,
14              const void *opts, size_t sz, const char *what) {
15   *val= enum_lookup_cached_func(ip,obj,opts,sz,what);
16   if (!*val) return TCL_ERROR;
17   return TCL_OK;
18 }
19   
20 int pat_obj(Tcl_Interp *ip, Tcl_Obj *obj, Tcl_Obj **val) {
21   *val= obj;
22   return TCL_OK;
23 }
24
25 int pat_hbv(Tcl_Interp *ip, Tcl_Obj *var, HBytes_Var *agg) {
26   int rc;
27   Tcl_Obj *val;
28
29   Tcl_IncrRefCount(var);
30   agg->var= var;
31
32   val= Tcl_ObjGetVar2(ip,var,0,TCL_LEAVE_ERR_MSG);
33   if (!val) return TCL_ERROR;
34   if (Tcl_IsShared(val)) val= Tcl_DuplicateObj(val);
35   Tcl_IncrRefCount(val);
36   agg->obj= val;
37   
38   rc= Tcl_ConvertToType(ip,val,&hbytes_type);
39   if (rc) return rc;
40
41   agg->hb= &HBYTES(val);
42   return TCL_OK;
43 }
44
45 void fini_hbv(Tcl_Interp *ip, int rc, HBytes_Var *agg) {
46   Tcl_Obj *ro;
47   
48   if (!rc) {
49     assert(agg->obj);
50     ro= Tcl_ObjSetVar2(ip,agg->var,0,agg->obj,TCL_LEAVE_ERR_MSG);
51     if (!ro) rc= TCL_ERROR;
52   }
53   if (agg->obj) Tcl_DecrRefCount(agg->obj);
54   if (agg->var) Tcl_DecrRefCount(agg->var);
55 }
56
57 int pat_hb(Tcl_Interp *ip, Tcl_Obj *obj, HBytes_Value *val) {
58   int rc;
59   rc= Tcl_ConvertToType(ip,obj,&hbytes_type);  if (rc) return rc;
60   *val= HBYTES(obj);
61   return TCL_OK;
62 }
63
64 Tcl_Obj *ret_hb(Tcl_Interp *ip, HBytes_Value val) {
65   return hbytes_set_obj(0, val.start, HBYTES_LEN(val));
66 }