9 static void enum_nt_dup(Tcl_Obj *src, Tcl_Obj *dup) {
10 dup->internalRep= src->internalRep;
13 static void enum_nt_ustr(Tcl_Obj *o) {
17 static int enum_nt_sfa(Tcl_Interp *ip, Tcl_Obj *o) {
21 Tcl_ObjType enum_nearlytype = {
23 0, enum_nt_dup, enum_nt_ustr, enum_nt_sfa
26 Tcl_ObjType enum1_nearlytype = {
28 0, enum_nt_dup, enum_nt_ustr, enum_nt_sfa
31 static void report_bad(Tcl_Interp *ip, const char *what, const char *supplied,
32 const void *first, size_t each,
33 int (*isvalid)(const void *entry),
34 void (*appres)(Tcl_Interp *ip, const void *entry)) {
38 for (entry=first; isvalid(entry); entry+=each);
39 count= (entry - (const Byte*)first) / each;
42 Tcl_AppendResult(ip, "bad ",what," \"",supplied,"\": must be",(char*)0);
44 for (i=0, entry=first; i<count; i++, entry+=each) {
47 i+1==count ? ", or " :
54 static const char *enum_str(const void *p) { return *(const char*const*)p; }
55 static int isvalid_enum(const void *p) { return !!enum_str(p); }
56 static void appres_enum(Tcl_Interp *ip, const void *p) {
57 Tcl_AppendResult(ip, enum_str(p), (char*)0);
60 const void *enum_lookup_cached_func(Tcl_Interp *ip, Tcl_Obj *o,
61 const void *firstentry, size_t entrysize,
63 const char *supplied, *found;
66 if (o->typePtr == &enum_nearlytype &&
67 o->internalRep.twoPtrValue.ptr1 == firstentry)
68 return o->internalRep.twoPtrValue.ptr2;
70 supplied= Tcl_GetStringFromObj(o,0); assert(supplied);
72 (found= *(const char*const*)ep) && strcmp(supplied,found);
77 o->typePtr= &enum_nearlytype;
78 o->internalRep.twoPtrValue.ptr1= (void*)firstentry;
79 o->internalRep.twoPtrValue.ptr2= (void*)ep;
83 report_bad(ip,what,supplied, firstentry,entrysize, isvalid_enum,appres_enum);
87 static int isvalid_enum1(const void *p) { return !!*(const char*)p; }
88 static void appres_enum1(Tcl_Interp *ip, const void *p) {
90 buf[0]= *(const char*)p;
92 Tcl_AppendResult(ip, buf, (char*)0);
95 int enum1_lookup_cached_func(Tcl_Interp *ip, Tcl_Obj *o,
96 const char *opts, const char *what) {
97 const char *supplied, *fp;
99 if (o->typePtr != &enum1_nearlytype ||
100 o->internalRep.twoPtrValue.ptr1 != opts) {
102 supplied= Tcl_GetStringFromObj(o,0); assert(supplied);
104 if (!(strlen(supplied) == 1 &&
105 (fp= strchr(opts, supplied[0])))) {
106 report_bad(ip,what,supplied, opts,1, isvalid_enum1,appres_enum1);
111 o->typePtr= &enum1_nearlytype;
112 o->internalRep.twoPtrValue.ptr1= (void*)opts;
113 o->internalRep.twoPtrValue.ptr2= (void*)fp;
115 return (const char*)o->internalRep.twoPtrValue.ptr2 - opts;