X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=chiark-tcl.git;a=blobdiff_plain;f=base%2Fchiark-tcl.h;h=2f80d58172904c0eea95e3feef49fe1e04e294da;hp=d4a5719eee94763cd73c77f3b8e6e021affa1168;hb=5dca360f2da544c9b6baf9d18ad8cd0b0e073e60;hpb=310a482133795d0bee9621003c0a0b3813a47037 diff --git a/base/chiark-tcl.h b/base/chiark-tcl.h index d4a5719..2f80d58 100644 --- a/base/chiark-tcl.h +++ b/base/chiark-tcl.h @@ -1,61 +1,144 @@ /* - */ -/* - * hbytes raw2h BINARY => hex - * hbytes h2raw HEX => binary + * base code for various Tcl extensions + * Copyright 2006 Ian Jackson * - * 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) + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. * - * hbytes pkcs5 pa|ua VAR ALG => worked? (always 1 for p) - * hbytes pkcs5 pn|un VAR BLOCKSIZE => worked? (always 1 for p) - * hbytes blockcipher d|e VAR ALG MODE [IV] => IV + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. * - * hbytes hash ALG MESSAGE => hash - * hbytes hmac ALG MESSAGE KEY [MACLENGTH] => mac - * - * Refs: HMAC: RFC2104 + * You should have received a copy of the GNU General Public License + * along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301, USA. */ -#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 { /* opaque; comments are for scriptinv.c impl'n only */ + /* states: Cancelled Set */ + Tcl_Interp *ipq; /* 0 valid, non-0, useable */ + Tcl_Obj *script; /* 0 valid, non-0 */ + Tcl_Obj *xargs; /* 0 valid, may be 0 */ + int llen; /* undefined llength of script + xargs */ +} ScriptToInvoke; + +void cht_scriptinv_init(ScriptToInvoke *si); /* undefined -> Cancelled */ +int cht_scriptinv_set(ScriptToInvoke *si, Tcl_Interp *ip, + Tcl_Obj *newscript, Tcl_Obj *xargs); + /* Cancelled/Set -> Set (newscript!=0, ok) / Cancelled (otherwise) */ +void cht_scriptinv_cancel(ScriptToInvoke *si); + /* Cancelled/Set -> Cancelled. No separate free function - just cancel. */ +#define cht_scriptinv_interp(si) ((si)->ipq) + /* int cht_scriptinv_interp(ScriptToInvoke *si); returns 0 if Cancelled */ + +int cht_scriptinv_invoke_fg(ScriptToInvoke *si, int argc, + Tcl_Obj *const *argv); + /* is a no-op if Cancelled rather than Set */ + /* if script fails, returns that error */ + +void cht_scriptinv_invoke(ScriptToInvoke *si, int argc, Tcl_Obj *const *argv); + /* if script fails, reports it with Tcl_BackgroundError */ + +/* 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; + +/* 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. */ -extern Tcl_ObjType hbytes_type; +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 */ -int staticerr(Tcl_Interp *ip, const char *m); -void objfreeir(Tcl_Obj *o); +/* from hook.c */ -void hbytes_set(HBytes_Value *upd, const Byte *array, int l); -Tcl_Obj *hbytes_set_obj(Tcl_Obj *overwrite, const Byte *array, int l); +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*. @@ -64,26 +147,14 @@ const void *enum_lookup_cached_func(Tcl_Interp *ip, Tcl_Obj *o, * set to the error message. */ -/* from crypto.c */ - -typedef struct { - int blocksize, hashsize; -} HashAlgInfo; - -typedef struct { - int blocksize; -} BlockCipherAlgInfo; - -typedef struct { - int dummy; -} BlockCipherModeInfo; +int cht_enum1_lookup_cached_func(Tcl_Interp *ip, Tcl_Obj *o, + const char *opts, const char *what); + /* -1 => error */ /* useful macros */ -#define HBYTES(o) (*(HBytes_Value*)&(o)->internalRep.twoPtrValue) -#define HBYTES_LEN(hb) ((hb).end - (hb).start) - #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*/