12 #include <sys/socket.h>
15 #include <arpa/inet.h>
17 #include <tcl8.3/tcl.h>
21 typedef unsigned char Byte;
23 /* for assisting tcmdifgen and tcmdiflib.c */
25 typedef struct TopLevel_Command TopLevel_Command;
27 struct TopLevel_Command {
32 void cht_setstringresult(Tcl_Interp*, const char*);
33 int cht_pat_enum(Tcl_Interp*, Tcl_Obj*, const void**,
34 const void*, size_t, const char *what);
36 /* from scriptinv.c */
38 typedef struct { /* semi-opaque - read only, and then only where commented */
39 Tcl_Interp *ip; /* valid, non-0 and useable if set */
40 Tcl_Obj *obj; /* non-0 iff set (but only test for 0/non-0) */
42 int llength; /* after set, is llength of script + xargs */
45 void cht_scriptinv_init(ScriptToInvoke *si);
46 int cht_scriptinv_set(ScriptToInvoke *si, Tcl_Interp *ip,
47 Tcl_Obj *newscript, Tcl_Obj *xargs);
48 void cht_scriptinv_cancel(ScriptToInvoke *si); /* then don't invoke */
49 /* no separate free function - just cancel */
51 int cht_scriptinv_invoke_fg(ScriptToInvoke *si, int argc,
52 Tcl_Obj *const *argv);
53 /* if script fails, returns that error */
55 void cht_scriptinv_invoke(ScriptToInvoke *si, int argc, Tcl_Obj *const *argv);
56 /* if script fails, reports it with Tcl_BackgroundError */
61 const char *valprefix, *assockey;
62 void (*destroyitem)(Tcl_Interp *ip, void *val);
65 /* The stored struct must start with a single int, conventionally
66 * named `ix'. When the struct is returned for the first time ix must
67 * be -1; on subsequent occasions it must be >=0. ix will be -1 iff
68 * the struct is registered by the iddatatable machinery. */
70 extern Tcl_ObjType cht_tabledataid_nearlytype;
71 int cht_tabledataid_parse(Tcl_Interp *ip, Tcl_Obj *o, const IdDataSpec *idds);
72 void cht_tabledataid_disposing(Tcl_Interp *ip, void *val, const IdDataSpec *idds);
73 /* call this when you destroy the struct, to remove its name;
74 * _disposing is idempotent */
78 int cht_initextension(Tcl_Interp *ip, const TopLevel_Command *cmds,
79 int *donep /* or 0, meaning no types follow */,
80 ... /* types, terminated by 0 */);
82 int cht_staticerr(Tcl_Interp *ip, const char *m, const char *ec);
83 int cht_posixerr(Tcl_Interp *ip, int errnoval, const char *m);
84 int cht_newfdposixerr(Tcl_Interp *ip, int fd, const char *m);
85 void cht_objfreeir(Tcl_Obj *o);
86 int cht_get_urandom(Tcl_Interp *ip, Byte *buffer, int l);
88 void cht_obj_updatestr_array(Tcl_Obj *o, const Byte *array, int l);
89 void cht_obj_updatestr_array_prefix(Tcl_Obj *o, const Byte *byte,
90 int l, const char *prefix);
92 void cht_obj_updatestr_vstringls(Tcl_Obj *o, ...);
93 /* const char*, int, const char*, int, ..., (const char*)0 */
94 void cht_obj_updatestr_string_len(Tcl_Obj *o, const char *str, int l);
95 void cht_obj_updatestr_string(Tcl_Obj *o, const char *str);
104 void cht_init_somethingv(Something_Var *sth);
105 void cht_fini_somethingv(Tcl_Interp *ip, int rc, Something_Var *sth);
106 int cht_pat_somethingv(Tcl_Interp *ip, Tcl_Obj *var,
107 Something_Var *sth, Tcl_ObjType *type);
111 extern Tcl_ObjType cht_enum_nearlytype;
112 extern Tcl_ObjType cht_enum1_nearlytype;
114 const void *cht_enum_lookup_cached_func(Tcl_Interp *ip, Tcl_Obj *o,
115 const void *firstentry, size_t entrysize,
117 #define enum_lookup_cached(ip,o,table,what) \
118 (cht_enum_lookup_cached_func((ip),(o), \
119 &(table)[0],sizeof((table)[0]), \
121 /* table should be a pointer to an array of structs of size
122 * entrysize, the first member of which should be a const char*.
123 * The table should finish with a null const char *.
124 * On error, 0 is returned and the ip->result will have been
125 * set to the error message.
128 int cht_enum1_lookup_cached_func(Tcl_Interp *ip, Tcl_Obj *o,
129 const char *opts, const char *what);
134 #define TALLOC(s) ((void*)Tcl_Alloc((s)))
135 #define TFREE(f) (Tcl_Free((void*)(f)))
136 #define TREALLOC(p,l) ((void*)Tcl_Realloc((void*)(p),(l)))
138 #endif /*CHIARK_TCL_H*/