X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?a=blobdiff_plain;f=base%2Fchiark-tcl.h;h=4c022cb82c8c5922ecf2ac7046af64643a8e4216;hb=40a4738e440a8412c61a12eca34ed6aa98d71a5a;hp=c6fe050b8d675f29a6a6bfb8162391c2e08518d5;hpb=bdab939bce799bf55ccd401543f5f13a3203b047;p=chiark-tcl.git diff --git a/base/chiark-tcl.h b/base/chiark-tcl.h index c6fe050..4c022cb 100644 --- a/base/chiark-tcl.h +++ b/base/chiark-tcl.h @@ -1,60 +1,117 @@ /* */ -/* - * hbytes raw2h BINARY => hex - * hbytes h2raw HEX => binary - * - * hbytes prefix VAR [VALUE ...] = set VAR [concat VALUE ... $VAR] - * hbytes append VAR [VALUE ...] = set VAR [concat $VAR VALUE ...] - * hbytes concat VAR [VALUE ...] = set VAR [concat VALUE ...] - * hbytes unprepend VAR PREFIXLENGTH => prefix (removed from VAR) - * hbytes unappend VAR SUFFIXLENGTH => suffix (removed from VAR) - * hbytes chopto VAR NEWVARLENGTH => suffix (removed from VAR) - * (too short? error) - * - * hbytes pkcs5 pa|ua VAR ALG => worked? (always 1 for p) - * hbytes pkcs5 pn|un VAR BLOCKSIZE => worked? (always 1 for p) - * hbytes blockcipher e|d VAR ALG MODE [IV] => IV - * - * hbytes hash ALG VALUE => hash - * hbytes hmac ALG VALUE KEY [MACLENGTH] => mac - * - * Refs: HMAC: RFC2104 - */ -#ifndef HBYTES_H -#define HBYTES_H +#ifndef CHIARK_TCL_H +#define CHIARK_TCL_H #include #include +#include +#include +#include +#include +#include +#include +#include + +#include -#include +#include typedef unsigned char Byte; -/* from hbytes.c */ +/* for assisting tcmdifgen and tcmdiflib.c */ + +typedef struct TopLevel_Command TopLevel_Command; + +struct TopLevel_Command { + const char *name; + Tcl_ObjCmdProc *func; +}; + +void cht_setstringresult(Tcl_Interp*, const char*); +int cht_pat_enum(Tcl_Interp*, Tcl_Obj*, const void**, + const void*, size_t, const char *what); + +/* from scriptinv.c */ + +typedef struct { /* semi-opaque - read only, and then only where commented */ + Tcl_Interp *ip; /* valid, non-0 and useable if set */ + Tcl_Obj *obj; /* non-0 iff set (but only test for 0/non-0) */ + Tcl_Obj *xargs; + int llength; +} ScriptToInvoke; + +void cht_scriptinv_init(ScriptToInvoke *si); +int cht_scriptinv_set(ScriptToInvoke *si, Tcl_Interp *ip, + Tcl_Obj *newscript, Tcl_Obj *xargs); +void cht_scriptinv_cancel(ScriptToInvoke *si); /* then don't invoke */ + /* no separate free function - just cancel */ + +void cht_scriptinv_invoke(ScriptToInvoke *si, int argc, Tcl_Obj *const *argv); + +/* from idtable.c */ typedef struct { - Byte *start, *end; /* always allocated dynamically */ -} HBytes_Value; /* overlays internalRep */ + const char *valprefix, *assockey; + void (*destroyitem)(Tcl_Interp *ip, void *val); +} IdDataSpec; -extern Tcl_ObjType hbytes_type; +/* The stored struct must start with a single int, conventionally + * named `ix'. When the struct is returned for the first time ix must + * be -1; on subsequent occasions it must be >=0. ix will be -1 iff + * the struct is registered by the iddatatable machinery. */ -int staticerr(Tcl_Interp *ip, const char *m); -void objfreeir(Tcl_Obj *o); +extern Tcl_ObjType cht_tabledataid_nearlytype; +int cht_tabledataid_parse(Tcl_Interp *ip, Tcl_Obj *o, const IdDataSpec *idds); +void cht_tabledataid_disposing(Tcl_Interp *ip, void *val, const IdDataSpec *idds); + /* call this when you destroy the struct, to remove its name; + * _disposing is idempotent */ -Tcl_Obj *hbytes_set(Tcl_Obj *overwrite, const Byte *array, int l); +/* from hook.c */ + +int cht_initextension(Tcl_Interp *ip, const TopLevel_Command *cmds, + int *donep /* or 0, meaning no types follow */, + ... /* types, terminated by 0 */); + +int cht_staticerr(Tcl_Interp *ip, const char *m, const char *ec); +int cht_posixerr(Tcl_Interp *ip, int errnoval, const char *m); +int cht_newfdposixerr(Tcl_Interp *ip, int fd, const char *m); +void cht_objfreeir(Tcl_Obj *o); +int cht_get_urandom(Tcl_Interp *ip, Byte *buffer, int l); + +void cht_obj_updatestr_array(Tcl_Obj *o, const Byte *array, int l); +void cht_obj_updatestr_array_prefix(Tcl_Obj *o, const Byte *byte, + int l, const char *prefix); + +void cht_obj_updatestr_vstringls(Tcl_Obj *o, ...); + /* const char*, int, const char*, int, ..., (const char*)0 */ +void cht_obj_updatestr_string_len(Tcl_Obj *o, const char *str, int l); +void cht_obj_updatestr_string(Tcl_Obj *o, const char *str); + +/* from parse.c */ + +typedef struct { + Tcl_Obj *obj, *var; + int copied; +} Something_Var; + +void cht_init_somethingv(Something_Var *sth); +void cht_fini_somethingv(Tcl_Interp *ip, int rc, Something_Var *sth); +int cht_pat_somethingv(Tcl_Interp *ip, Tcl_Obj *var, + Something_Var *sth, Tcl_ObjType *type); /* from enum.c */ -extern Tcl_ObjType enum_nearlytype; +extern Tcl_ObjType cht_enum_nearlytype; +extern Tcl_ObjType cht_enum1_nearlytype; -const void *enum_lookup_cached_func(Tcl_Interp *ip, Tcl_Obj *o, - size_t entrysize, const void *firstentry, +const void *cht_enum_lookup_cached_func(Tcl_Interp *ip, Tcl_Obj *o, + const void *firstentry, size_t entrysize, const char *what); #define enum_lookup_cached(ip,o,table,what) \ - (enum_lookup_cached_func((ip),(o), \ - sizeof((table)[0]),&(table)[0], \ + (cht_enum_lookup_cached_func((ip),(o), \ + &(table)[0],sizeof((table)[0]), \ (what))) /* table should be a pointer to an array of structs of size * entrysize, the first member of which should be a const char*. @@ -63,12 +120,14 @@ const void *enum_lookup_cached_func(Tcl_Interp *ip, Tcl_Obj *o, * set to the error message. */ -/* useful macros */ +int cht_enum1_lookup_cached_func(Tcl_Interp *ip, Tcl_Obj *o, + const char *opts, const char *what); + /* -1 => error */ -#define HBYTES(o) ((HBytes_Value*)&(o)->internalRep.twoPtrValue) -#define HBYTES_LEN(o) (HBYTES((o))->end - HBYTES((o))->start) +/* useful macros */ #define TALLOC(s) ((void*)Tcl_Alloc((s))) #define TFREE(f) (Tcl_Free((void*)(f))) +#define TREALLOC(p,l) ((void*)Tcl_Realloc((void*)(p),(l))) -#endif /*HBYTES_H*/ +#endif /*CHIARK_TCL_H*/