#pragma prototyped1#ifndef __TKSH_H_2#define __TKSH_H_34#include <ast/shell.h> /* X11 has Shell.h that clashes on case ignorant systems */5#include <tcl.h>6#include <errno.h>78/*9* The structure below defines a deletion callback, which is10* a procedure to invoke just before an interpreter is deleted.11*/1213typedef struct DeleteCallback {14Tcl_InterpDeleteProc *proc; /* Procedure to call. */15ClientData clientData; /* Value to pass to procedure. */16struct DeleteCallback *nextPtr;17/* Next in list of callbacks for this18* interpreter (or NULL for end of list). */19} DeleteCallback;2021typedef struct Interp {2223/*24* Note: the first three fields must match exactly the fields in25* a Tcl_Interp struct (see tcl.h). If you change one, be sure to26* change the other.27*/2829char *result; /* Points to result returned by last30* command. */31Tcl_FreeProc *freeProc; /* Zero means result is statically allocated.32* If non-zero, gives address of procedure33* to invoke to free the result. Must be34* freed by Tcl_Eval before executing next35* command. */36int errorLine; /* When TCL_ERROR is returned, this gives37* the line number within the command where38* the error occurred (1 means first line). */39Tcl_HashTable xxxcommandTable; /* Contains all of the commands currently40* registered in this interpreter. Indexed41* by strings; values have type (Command *). */42Tcl_HashTable mathFuncTable;/* Contains all of the math functions currently43* defined for the interpreter. Indexed by44* strings (function names); values have45* type (MathFunc *). */4647/*48* Information related to procedures and variables. See tclProc.c49* and tclvar.c for usage.50*/5152Tcl_HashTable xxxglobalTable; /* Contains all global variables for53* interpreter. */54#ifndef NO_TCL_INTERP55int numLevels; /* Keeps track of how many nested calls to56* Tcl_Eval are in progress for this57* interpreter. It's used to delay deletion58* of the table until all Tcl_Eval invocations59* are completed. */60int maxNestingDepth; /* If numLevels exceeds this value then Tcl61* assumes that infinite recursion has62* occurred and it generates an error. */63#endif64void * /* CallFrame */ xxxframePtr; /* Points to top-most in stack of all nested65* procedure invocations. NULL means there66* are no active procedures. */67void * /* CallFrame */ xxxvarFramePtr; /* Points to the call frame whose variables68* are currently in use (same as framePtr69* unless an "uplevel" command is being70* executed). NULL means no procedure is71* active or "uplevel 0" is being exec'ed. */72void * /* ActiveVarTrace */ xxxactiveTracePtr;73/* First in list of active traces for interp,74* or NULL if no active traces. */7576int returnCode; /* Completion code to return if current77* procedure exits with a TCL_RETURN code. */78char *errorInfo; /* Value to store in errorInfo if returnCode79* is TCL_ERROR. Malloc'ed, may be NULL */80char *errorCode; /* Value to store in errorCode if returnCode81* is TCL_ERROR. Malloc'ed, may be NULL */8283/*84* Information related to history:85*/8687#ifdef TCL_CODE88int xxxnumEvents; /* Number of previously-executed commands89* to retain. */90#else91int interpType;92#endif93void * /*HistoryEvent */ xxxevents; /* Array containing numEvents entries94* (dynamically allocated). */95int xxxcurEvent; /* Index into events of place where current96* (or most recent) command is recorded. */97int xxxcurEventNum; /* Event number associated with the slot98* given by curEvent. */99void * /*HistoryRev */ xxxrevPtr; /* First in list of pending revisions. */100char *xxxhistoryFirst; /* First char. of current command executed101* from history module or NULL if none. */102int xxxrevDisables; /* 0 means history revision OK; > 0 gives103* a count of number of times revision has104* been disabled. */105char *xxxevalFirst; /* If TCL_RECORD_BOUNDS flag set, Tcl_Eval106* sets this field to point to the first107* char. of text from which the current108* command came. Otherwise Tcl_Eval sets109* this to NULL. */110char *xxxevalLast; /* Similar to evalFirst, except points to111* last character of current command. */112113114/*115* Information used by Tcl_AppendResult to keep track of partial116* results. See Tcl_AppendResult code for details.117*/118119char *appendResult; /* Storage space for results generated120* by Tcl_AppendResult. Malloc-ed. NULL121* means not yet allocated. */122int appendAvl; /* Total amount of space available at123* partialResult. */124int appendUsed; /* Number of non-null bytes currently125* stored at partialResult. */126127/*128* A cache of compiled regular expressions. See TclCompileRegexp129* in tclUtil.c for details.130*/131132#define NUM_REGEXPS 5133char *xxxpatterns[NUM_REGEXPS];/* Strings corresponding to compiled134* regular expression patterns. NULL135* means that this slot isn't used.136* Malloc-ed. */137int xxxpatLengths[NUM_REGEXPS];/* Number of non-null characters in138* corresponding entry in patterns.139* -1 means entry isn't used. */140void * /* regexp */ xxxregexps[NUM_REGEXPS];141/* Compiled forms of above strings. Also142* malloc-ed, or NULL if not in use yet. */143144145/*146* Information used by Tcl_PrintDouble:147*/148149char pdFormat[10]; /* Format string used by Tcl_PrintDouble. */150int pdPrec; /* Current precision (used to restore the151* the tcl_precision variable after a bogus152* value has been put into it). */153154#ifndef NO_TCL_INTERP155156/*157* Miscellaneous information:158*/159160int cmdCount; /* Total number of times a command procedure161* has been called for this interpreter. */162int noEval; /* Non-zero means no commands should actually163* be executed: just parse only. Used in164* expressions when the result is already165* determined. */166int evalFlags; /* Flags to control next call to Tcl_Eval.167* Normally zero, but may be set before168* calling Tcl_Eval to an OR'ed combination169* of TCL_BRACKET_TERM and TCL_RECORD_BOUNDS. */170char *termPtr; /* Character just after the last one in171* a command. Set by Tcl_Eval before172* returning. */173char *scriptFile; /* NULL means there is no nested source174* command active; otherwise this points to175* the name of the file being sourced (it's176* not malloc-ed: it points to an argument177* to Tcl_EvalFile. */178int flags; /* Various flag bits. See below. */179void * /* Trace */ tracePtr; /* List of traces for this interpreter. */180DeleteCallback* deleteCallbackPtr;181/* First in list of callbacks to invoke when182* interpreter is deleted. */183184#endif185/*186* Information about packages. Used only in tclPkg.c.187*/188189Tcl_HashTable packageTable; /* Describes all of the packages loaded190* in or available to this interpreter.191* Keys are package names, values are192* (Package *) pointers. */193char *packageUnknown; /* Command to invoke during "package194* require" commands for packages that195* aren't described in packageTable.196* Malloc'ed, may be NULL. */197198Tcl_HashTable *assocData; /* Hash table for associating data with199* this interpreter. Cleaned up when200* this interpreter is deleted. */201202void* shbltin; /* shell (Shbltin_t*) */203204char resultSpace[TCL_RESULT_SIZE+1];205/* Static space for storing small results. */206} Interp;207208/*209* Flag bits for Interp structures:210*211* DELETED: Non-zero means the interpreter has been deleted:212* don't process any more commands for it, and destroy213* the structure as soon as all nested invocations of214* Tcl_Eval are done.215* ERR_IN_PROGRESS: Non-zero means an error unwind is already in progress.216* Zero means a command proc has been invoked since last217* error occured.218* ERR_ALREADY_LOGGED: Non-zero means information has already been logged219* in $errorInfo for the current Tcl_Eval instance,220* so Tcl_Eval needn't log it (used to implement the221* "error message log" command).222* ERROR_CODE_SET: Non-zero means that Tcl_SetErrorCode has been223* called to record information for the current224* error. Zero means Tcl_Eval must clear the225* errorCode variable if an error is returned.226*/227228#define DELETED 1229#define ERR_IN_PROGRESS 2230#define ERR_ALREADY_LOGGED 4231#define ERROR_CODE_SET 8232233#define INTERP_KSH 0234#define INTERP_TCL 1235#define INTERP_MASK 3236#define INTERP_CURRENT 2237238#define TKSH_TRACE_RUNNING 0x400 /* Set when trace is running */239#define COMMAND_ACTIVE 4 /* Used in commandType field */240#define NV_FUNC (NV_NOADD | NV_NOASSIGN)241242#ifndef LIB_DIR_ENV243#define LIB_DIR_ENV "TKSH_LIBRARY"244#endif245246#ifndef LIB_DIR247#define LIB_DIR "lib/tksh7.6"248#endif249250#define SPLIT_CMD_NAME "_tksh_split_list"251252typedef struct TkshArrayInfo253{254ClientData clientData;255} TkshArrayInfo;256257typedef struct TkshCommandData258{259Tcl_Interp *interp;260Tcl_CmdInfo info;261char commandType;262} TkshCommandData;263264#define Tksh_MapReturn(i) ((((i) >= 0) && ((i) <= TCL_CONTINUE)) ? (i) \265: TCL_ERROR)266#define Tksh_ReturnVal() (Tksh_MapReturn(sh.exitval))267#define Tksh_OkOrErr() ((sh.exitval == 0) ? TCL_OK : TCL_ERROR)268#define Tksh_InterpString(i) (((i)==INTERP_TCL)? "tcl": (((i)==INTERP_KSH) \269? "ksh" : "either"))270271#define Tksh_BeginBlock(interp, kind) do { int oldInterp = ((Interp *)interp)->interpType; ((Interp *)interp)->interpType = kind272#define Tksh_EndBlock(interp) ((Interp *)interp)->interpType = oldInterp; } while(0)273274#if _BLD_tcl && defined(__EXPORT__)275#define extern __EXPORT__276#endif277278extern void TkshDeleteSearches(TkshArrayInfo *);279extern TkshArrayInfo* TkshArrayData(Namval_t *namval);280extern void TkshTracesOff(void);281282extern int tksh_waitevent(int, long, int);283extern int nv_getlevel(void);284285extern int Tksh_Eval(Tcl_Interp *interp, char *cmd, int flag);286extern int Tksh_SetCommandType(Tcl_Interp *, char *, int tp);287extern int Tksh_Init(Tcl_Interp *interp);288extern char* Tksh_ConvertList(Tcl_Interp *interp, char *lst, int to);289extern void TkshCreateInterp(Tcl_Interp *interp, void *data);290extern void TkshSubShell(void);291extern int Tksh_CreatePipeline(Tcl_Interp*, int, char**, Tcl_DString*);292293extern int b_print(int argc, char *argv[], Shbltin_t *);294extern int b_tclinit(int argc, char *argv[], Shbltin_t *);295extern int b_tkinit(int argc, char *argv[], Shbltin_t *);296297#undef extern298299#endif /* __TKSH_H_ */300301302