4 #include "chiark-tcl-base.h"
6 int cht_pat_charfrom(Tcl_Interp *ip, Tcl_Obj *obj, int *val,
7 const char *opts, const char *what) {
8 *val= cht_enum1_lookup_cached_func(ip,obj,opts,what);
9 if (*val==-1) return TCL_ERROR;
13 int cht_pat_int(Tcl_Interp *ip, Tcl_Obj *obj, int *val) {
14 return Tcl_GetIntFromObj(ip, obj, val);
17 int cht_pat_long(Tcl_Interp *ip, Tcl_Obj *obj, long *val) {
18 return Tcl_GetLongFromObj(ip, obj, val);
21 int cht_pat_string(Tcl_Interp *ip, Tcl_Obj *obj, const char **val) {
22 *val= Tcl_GetString(obj);
26 int cht_pat_constv(Tcl_Interp *ip, Tcl_Obj *var,
27 Tcl_Obj **val_r, Tcl_ObjType *type) {
31 val= Tcl_ObjGetVar2(ip,var,0,TCL_LEAVE_ERR_MSG);
32 if (!val) return TCL_ERROR;
35 rc= Tcl_ConvertToType(ip,val,type);
43 void cht_init_somethingv(Something_Var *sth) {
44 sth->obj=0; sth->var=0; sth->copied=0;
47 int cht_pat_somethingv(Tcl_Interp *ip, Tcl_Obj *var,
48 Something_Var *sth, Tcl_ObjType *type) {
54 val= Tcl_ObjGetVar2(ip,var,0,TCL_LEAVE_ERR_MSG);
55 if (!val) return TCL_ERROR;
57 rc= Tcl_ConvertToType(ip,val,type);
60 if (Tcl_IsShared(val)) {
61 val= Tcl_DuplicateObj(val);
64 Tcl_InvalidateStringRep(val);
70 void cht_fini_somethingv(Tcl_Interp *ip, int rc, Something_Var *sth) {
75 ro= Tcl_ObjSetVar2(ip,sth->var,0,sth->obj,TCL_LEAVE_ERR_MSG);
76 if (!ro) rc= TCL_ERROR;
78 if (rc && sth->copied)
79 Tcl_DecrRefCount(sth->obj);
82 Tcl_Obj *cht_ret_long(Tcl_Interp *ip, long val) {
83 return Tcl_NewLongObj(val);
86 Tcl_Obj *cht_ret_string(Tcl_Interp *ip, const char *val) {
87 return Tcl_NewStringObj(val,-1);