home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / hensa / programming / tcl / tclsrc / h / tclInt < prev    next >
Encoding:
Text File  |  1996-01-16  |  35.4 KB  |  935 lines

  1. /*
  2.  * tclInt.h --
  3.  *
  4.  *    Declarations of things used internally by the Tcl interpreter.
  5.  *
  6.  * Copyright (c) 1987-1993 The Regents of the University of California.
  7.  * Copyright (c) 1994-1995 Sun Microsystems, Inc.
  8.  *
  9.  * See the file "license.terms" for information on usage and redistribution
  10.  * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  11.  *
  12.  * @(#) tclInt.h 1.105 95/06/28 09:36:23
  13.  */
  14.  
  15. #ifndef _TCLINT
  16. #define _TCLINT
  17.  
  18. /*
  19.  * Common include files needed by most of the Tcl source files are
  20.  * included here, so that system-dependent personalizations for the
  21.  * include files only have to be made in once place.  This results
  22.  * in a few extra includes, but greater modularity.  The order of
  23.  * the three groups of #includes is important.  For example, stdio.h
  24.  * is needed by tcl.h, and the _ANSI_ARGS_ declaration in tcl.h is
  25.  * needed by stdlib.h in some configurations.
  26.  */
  27.  
  28. #include <stdio.h>
  29.  
  30. #ifndef _TCL
  31. #include "tcl.h"
  32. #endif
  33. #ifndef _REGEXP
  34. #include "tclRegexp.h"
  35. #endif
  36.  
  37. #include <ctype.h>
  38. #ifdef NO_LIMITS_H
  39. #   include "compat/limits.h"
  40. #else
  41. #   include <limits.h>
  42. #endif
  43. #ifdef NO_STDLIB_H
  44. #   include "compat/stdlib.h"
  45. #else
  46. #   include <stdlib.h>
  47. #endif
  48. #ifdef NO_STRING_H
  49. #include "compat/string.h"
  50. #else
  51. #include <string.h>
  52. #endif
  53. #include <stdarg.h>   /* for RISCOS */
  54. #include <errno.h>
  55.  
  56. /*
  57.  * At present (12/91) not all stdlib.h implementations declare strtod.
  58.  * The declaration below is here to ensure that it's declared, so that
  59.  * the compiler won't take the default approach of assuming it returns
  60.  * an int.  There's no ANSI prototype for it because there would end
  61.  * up being too many conflicts with slightly-different prototypes.
  62.  */
  63.  
  64. extern double strtod();
  65.  
  66. /*
  67.  *----------------------------------------------------------------
  68.  * Data structures related to variables.   These are used primarily
  69.  * in tclVar.c
  70.  *----------------------------------------------------------------
  71.  */
  72.  
  73. /*
  74.  * The following structure defines a variable trace, which is used to
  75.  * invoke a specific C procedure whenever certain operations are performed
  76.  * on a variable.
  77.  */
  78.  
  79. typedef struct VarTrace {
  80.     Tcl_VarTraceProc *traceProc;/* Procedure to call when operations given
  81.                  * by flags are performed on variable. */
  82.     ClientData clientData;    /* Argument to pass to proc. */
  83.     int flags;            /* What events the trace procedure is
  84.                  * interested in:  OR-ed combination of
  85.                  * TCL_TRACE_READS, TCL_TRACE_WRITES, and
  86.                  * TCL_TRACE_UNSETS. */
  87.     struct VarTrace *nextPtr;    /* Next in list of traces associated with
  88.                  * a particular variable. */
  89. } VarTrace;
  90.  
  91. /*
  92.  * When a variable trace is active (i.e. its associated procedure is
  93.  * executing), one of the following structures is linked into a list
  94.  * associated with the variable's interpreter.  The information in
  95.  * the structure is needed in order for Tcl to behave reasonably
  96.  * if traces are deleted while traces are active.
  97.  */
  98.  
  99. typedef struct ActiveVarTrace {
  100.     struct Var *varPtr;        /* Variable that's being traced. */
  101.     struct ActiveVarTrace *nextPtr;
  102.                 /* Next in list of all active variable
  103.                  * traces for the interpreter, or NULL
  104.                  * if no more. */
  105.     VarTrace *nextTracePtr;    /* Next trace to check after current
  106.                  * trace procedure returns;  if this
  107.                  * trace gets deleted, must update pointer
  108.                  * to avoid using free'd memory. */
  109. } ActiveVarTrace;
  110.  
  111. /*
  112.  * The following structure describes an enumerative search in progress on
  113.  * an array variable;  this are invoked with options to the "array"
  114.  * command.
  115.  */
  116.  
  117. typedef struct ArraySearch {
  118.     int id;            /* Integer id used to distinguish among
  119.                  * multiple concurrent searches for the
  120.                  * same array. */
  121.     struct Var *varPtr;        /* Pointer to array variable that's being
  122.                  * searched. */
  123.     Tcl_HashSearch search;    /* Info kept by the hash module about
  124.                  * progress through the array. */
  125.     Tcl_HashEntry *nextEntry;    /* Non-null means this is the next element
  126.                  * to be enumerated (it's leftover from
  127.                  * the Tcl_FirstHashEntry call or from
  128.                  * an "array anymore" command).  NULL
  129.                  * means must call Tcl_NextHashEntry
  130.                  * to get value to return. */
  131.     struct ArraySearch *nextPtr;/* Next in list of all active searches
  132.                  * for this variable, or NULL if this is
  133.                  * the last one. */
  134. } ArraySearch;
  135.  
  136. /*
  137.  * The structure below defines a variable, which associates a string name
  138.  * with a string value.  Pointers to these structures are kept as the
  139.  * values of hash table entries, and the name of each variable is stored
  140.  * in the hash entry.
  141.  */
  142.  
  143. typedef struct Var {
  144.     int valueLength;        /* Holds the number of non-null bytes
  145.                  * actually occupied by the variable's
  146.                  * current value in value.string (extra
  147.                  * space is sometimes left for expansion).
  148.                  * For array and global variables this is
  149.                  * meaningless. */
  150.     int valueSpace;        /* Total number of bytes of space allocated
  151.                  * at value.string.  0 means there is no
  152.                  * space allocated. */
  153.     union {
  154.     char *string;        /* String value of variable, used for scalar
  155.                  * variables and array elements.  Malloc-ed. */
  156.     Tcl_HashTable *tablePtr;/* For array variables, this points to
  157.                  * information about the hash table used
  158.                  * to implement the associative array.
  159.                  * Points to malloc-ed data. */
  160.     struct Var *upvarPtr;    /* If this is a global variable being
  161.                  * referred to in a procedure, or a variable
  162.                  * created by "upvar", this field points to
  163.                  * the record for the higher-level variable. */
  164.     } value;
  165.     Tcl_HashEntry *hPtr;    /* Hash table entry that refers to this
  166.                  * variable, or NULL if the variable has
  167.                  * been detached from its hash table (e.g.
  168.                  * an array is deleted, but some of its
  169.                  * elements are still referred to in upvars). */
  170.     int refCount;        /* Counts number of active uses of this
  171.                  * variable, not including its main hash
  172.                  * table entry: 1 for each additional variable
  173.                  * whose upVarPtr points here, 1 for each
  174.                  * nested trace active on variable.  This
  175.                  * record can't be deleted until refCount
  176.                  * becomes 0. */
  177.     VarTrace *tracePtr;        /* First in list of all traces set for this
  178.                  * variable. */
  179.     ArraySearch *searchPtr;    /* First in list of all searches active
  180.                  * for this variable, or NULL if none. */
  181.     int flags;            /* Miscellaneous bits of information about
  182.                  * variable.  See below for definitions. */
  183. } Var;
  184.  
  185. /*
  186.  * Flag bits for variables:
  187.  *
  188.  * VAR_ARRAY    -        1 means this is an array variable rather
  189.  *                than a scalar variable.
  190.  * VAR_UPVAR -             1 means this variable just contains a
  191.  *                pointer to another variable that has the
  192.  *                real value.  Variables like this come
  193.  *                about through the "upvar" and "global"
  194.  *                commands.
  195.  * VAR_UNDEFINED -        1 means that the variable is currently
  196.  *                undefined.  Undefined variables usually
  197.  *                go away completely, but if an undefined
  198.  *                variable has a trace on it, or if it is
  199.  *                a global variable being used by a procedure,
  200.  *                then it stays around even when undefined.
  201.  * VAR_TRACE_ACTIVE -        1 means that trace processing is currently
  202.  *                underway for a read or write access, so
  203.  *                new read or write accesses should not cause
  204.  *                trace procedures to be called and the
  205.  *                variable can't be deleted.
  206.  */
  207.  
  208. #define VAR_ARRAY        1
  209. #define VAR_UPVAR        2
  210. #define VAR_UNDEFINED        4
  211. #define VAR_TRACE_ACTIVE    0x10
  212.  
  213. /*
  214.  *----------------------------------------------------------------
  215.  * Data structures related to procedures.   These are used primarily
  216.  * in tclProc.c
  217.  *----------------------------------------------------------------
  218.  */
  219.  
  220. /*
  221.  * The structure below defines an argument to a procedure, which
  222.  * consists of a name and an (optional) default value.
  223.  */
  224.  
  225. typedef struct Arg {
  226.     struct Arg *nextPtr;    /* Next argument for this procedure,
  227.                  * or NULL if this is the last argument. */
  228.     char *defValue;        /* Pointer to arg's default value, or NULL
  229.                  * if no default value. */
  230.     char name[4];        /* Name of argument starts here.  The name
  231.                  * is followed by space for the default,
  232.                  * if there is one.  The actual size of this
  233.                  * field will be as large as necessary to
  234.                  * hold both name and default value.  THIS
  235.                  * MUST BE THE LAST FIELD IN THE STRUCTURE!! */
  236. } Arg;
  237.  
  238. /*
  239.  * The structure below defines a command procedure, which consists of
  240.  * a collection of Tcl commands plus information about arguments and
  241.  * variables.
  242.  */
  243.  
  244. typedef struct Proc {
  245.     struct Interp *iPtr;    /* Interpreter for which this command
  246.                  * is defined. */
  247.     int refCount;        /* Reference count:  1 if still present
  248.                  * in command table plus 1 for each call
  249.                  * to the procedure that is currently
  250.                  * active.  This structure can be freed
  251.                  * when refCount becomes zero. */
  252.     char *command;        /* Command that constitutes the body of
  253.                  * the procedure (dynamically allocated). */
  254.     Arg *argPtr;        /* Pointer to first of procedure's formal
  255.                  * arguments, or NULL if none. */
  256. } Proc;
  257.  
  258. /*
  259.  * The structure below defines a command trace.  This is used to allow Tcl
  260.  * clients to find out whenever a command is about to be executed.
  261.  */
  262.  
  263. typedef struct Trace {
  264.     int level;            /* Only trace commands at nesting level
  265.                  * less than or equal to this. */
  266.     Tcl_CmdTraceProc *proc;    /* Procedure to call to trace command. */
  267.     ClientData clientData;    /* Arbitrary value to pass to proc. */
  268.     struct Trace *nextPtr;    /* Next in list of traces for this interp. */
  269. } Trace;
  270.  
  271. /*
  272.  * The stucture below defines a deletion callback, which is
  273.  * a procedure to invoke just before an interpreter is deleted.
  274.  */
  275.  
  276. typedef struct DeleteCallback {
  277.     Tcl_InterpDeleteProc *proc;    /* Procedure to call. */
  278.     ClientData clientData;    /* Value to pass to procedure. */
  279.     struct DeleteCallback *nextPtr;
  280.                 /* Next in list of callbacks for this
  281.                  * interpreter (or NULL for end of list). */
  282. } DeleteCallback;
  283.  
  284. /*
  285.  * The structure below defines a frame, which is a procedure invocation.
  286.  * These structures exist only while procedures are being executed, and
  287.  * provide a sort of call stack.
  288.  */
  289.  
  290. typedef struct CallFrame {
  291.     Tcl_HashTable varTable;    /* Hash table containing all of procedure's
  292.                  * local variables. */
  293.     int level;            /* Level of this procedure, for "uplevel"
  294.                  * purposes (i.e. corresponds to nesting of
  295.                  * callerVarPtr's, not callerPtr's).  1 means
  296.                  * outer-most procedure, 0 means top-level. */
  297.     int argc;            /* This and argv below describe name and
  298.                  * arguments for this procedure invocation. */
  299.     char **argv;        /* Array of arguments. */
  300.     struct CallFrame *callerPtr;
  301.                 /* Value of interp->framePtr when this
  302.                  * procedure was invoked (i.e. next in
  303.                  * stack of all active procedures). */
  304.     struct CallFrame *callerVarPtr;
  305.                 /* Value of interp->varFramePtr when this
  306.                  * procedure was invoked (i.e. determines
  307.                  * variable scoping within caller;  same
  308.                  * as callerPtr unless an "uplevel" command
  309.                  * or something equivalent was active in
  310.                  * the caller). */
  311. } CallFrame;
  312.  
  313. /*
  314.  * The structure below defines one history event (a previously-executed
  315.  * command that can be re-executed in whole or in part).
  316.  */
  317.  
  318. typedef struct {
  319.     char *command;        /* String containing previously-executed
  320.                  * command. */
  321.     int bytesAvl;        /* Total # of bytes available at *event (not
  322.                  * all are necessarily in use now). */
  323. } HistoryEvent;
  324.  
  325. /*
  326.  *----------------------------------------------------------------
  327.  * Data structures related to history.   These are used primarily
  328.  * in tclHistory.c
  329.  *----------------------------------------------------------------
  330.  */
  331.  
  332. /*
  333.  * The structure below defines a pending revision to the most recent
  334.  * history event.  Changes are linked together into a list and applied
  335.  * during the next call to Tcl_RecordHistory.  See the comments at the
  336.  * beginning of tclHistory.c for information on revisions.
  337.  */
  338.  
  339. typedef struct HistoryRev {
  340.     int firstIndex;        /* Index of the first byte to replace in
  341.                  * current history event. */
  342.     int lastIndex;        /* Index of last byte to replace in
  343.                  * current history event. */
  344.     int newSize;        /* Number of bytes in newBytes. */
  345.     char *newBytes;        /* Replacement for the range given by
  346.                  * firstIndex and lastIndex (malloced). */
  347.     struct HistoryRev *nextPtr;    /* Next in chain of revisions to apply, or
  348.                  * NULL for end of list. */
  349. } HistoryRev;
  350.  
  351. /*
  352.  *----------------------------------------------------------------
  353.  * Data structures related to files.  These are used primarily in
  354.  * tclUnixUtil.c and tclUnixAZ.c.
  355.  *----------------------------------------------------------------
  356.  */
  357.  
  358. /*
  359.  * The data structure below defines an open file (or connection to
  360.  * a process pipeline) as returned by the "open" command.
  361.  */
  362.  
  363. typedef struct OpenFile {
  364.     FILE *f;            /* Stdio file to use for reading and/or
  365.                  * writing. */
  366.     FILE *f2;            /* Normally NULL.  In the special case of
  367.                  * a command pipeline with pipes for both
  368.                  * input and output, this is a stdio file
  369.                  * to use for writing to the pipeline. */
  370.     int permissions;        /* OR-ed combination of TCL_FILE_READABLE
  371.                  * and TCL_FILE_WRITABLE. */
  372.     int numPids;        /* If this is a connection to a process
  373.                  * pipeline, gives number of processes
  374.                  * in pidPtr array below;  otherwise it
  375.                  * is 0. */
  376.     int *pidPtr;        /* Pointer to malloc-ed array of child
  377.                  * process ids (numPids of them), or NULL
  378.                  * if this isn't a connection to a process
  379.                  * pipeline. */
  380.     int errorId;        /* File id of file that receives error
  381.                  * output from pipeline.  -1 means not
  382.                  * used (i.e. this is a normal file). */
  383. } OpenFile;
  384.  
  385. /*
  386.  *----------------------------------------------------------------
  387.  * Data structures related to expressions.  These are used only in
  388.  * tclExpr.c.
  389.  *----------------------------------------------------------------
  390.  */
  391.  
  392. /*
  393.  * The data structure below defines a math function (e.g. sin or hypot)
  394.  * for use in Tcl expressions.
  395.  */
  396.  
  397. #define MAX_MATH_ARGS 5
  398. typedef struct MathFunc {
  399.     int numArgs;        /* Number of arguments for function. */
  400.     Tcl_ValueType argTypes[MAX_MATH_ARGS];
  401.                 /* Acceptable types for each argument. */
  402.     Tcl_MathProc *proc;        /* Procedure that implements this function. */
  403.     ClientData clientData;    /* Additional argument to pass to the function
  404.                  * when invoking it. */
  405. } MathFunc;
  406.  
  407. /*
  408.  *----------------------------------------------------------------
  409.  * One of the following structures exists for each command in
  410.  * an interpreter.  The Tcl_Command opaque type actually refers
  411.  * to these structures.
  412.  *----------------------------------------------------------------
  413.  */
  414.  
  415. typedef struct Command {
  416.     Tcl_HashEntry *hPtr;    /* Pointer to the hash table entry in
  417.                  * interp->commandTable that refers to
  418.                  * this command.  Used to get a command's
  419.                  * name from its Tcl_Command handle. */
  420.     Tcl_CmdProc *proc;        /* Procedure to process command. */
  421.     ClientData clientData;    /* Arbitrary value to pass to proc. */
  422.     Tcl_CmdDeleteProc *deleteProc;
  423.                 /* Procedure to invoke when deleting
  424.                  * command. */
  425.     ClientData deleteData;    /* Arbitrary value to pass to deleteProc
  426.                  * (usually the same as clientData). */
  427. } Command;
  428.  
  429. /*
  430.  *----------------------------------------------------------------
  431.  * This structure defines an interpreter, which is a collection of
  432.  * commands plus other state information related to interpreting
  433.  * commands, such as variable storage.  Primary responsibility for
  434.  * this data structure is in tclBasic.c, but almost every Tcl
  435.  * source file uses something in here.
  436.  *----------------------------------------------------------------
  437.  */
  438.  
  439. typedef struct Interp {
  440.  
  441.     /*
  442.      * Note:  the first three fields must match exactly the fields in
  443.      * a Tcl_Interp struct (see tcl.h).  If you change one, be sure to
  444.      * change the other.
  445.      */
  446.  
  447.     char *result;        /* Points to result returned by last
  448.                  * command. */
  449.     Tcl_FreeProc *freeProc;    /* Zero means result is statically allocated.
  450.                  * If non-zero, gives address of procedure
  451.                  * to invoke to free the result.  Must be
  452.                  * freed by Tcl_Eval before executing next
  453.                  * command. */
  454.     int errorLine;        /* When TCL_ERROR is returned, this gives
  455.                  * the line number within the command where
  456.                  * the error occurred (1 means first line). */
  457.     Tcl_HashTable commandTable;    /* Contains all of the commands currently
  458.                  * registered in this interpreter.  Indexed
  459.                  * by strings; values have type (Command *). */
  460.     Tcl_HashTable mathFuncTable;/* Contains all of the math functions currently
  461.                  * defined for the interpreter.  Indexed by
  462.                  * strings (function names);  values have
  463.                  * type (MathFunc *). */
  464.  
  465.     /*
  466.      * Information related to procedures and variables.  See tclProc.c
  467.      * and tclvar.c for usage.
  468.      */
  469.  
  470.     Tcl_HashTable globalTable;    /* Contains all global variables for
  471.                  * interpreter. */
  472.     int numLevels;        /* Keeps track of how many nested calls to
  473.                  * Tcl_Eval are in progress for this
  474.                  * interpreter.  It's used to delay deletion
  475.                  * of the table until all Tcl_Eval invocations
  476.                  * are completed. */
  477.     int maxNestingDepth;    /* If numLevels exceeds this value then Tcl
  478.                  * assumes that infinite recursion has
  479.                  * occurred and it generates an error. */
  480.     CallFrame *framePtr;    /* Points to top-most in stack of all nested
  481.                  * procedure invocations.  NULL means there
  482.                  * are no active procedures. */
  483.     CallFrame *varFramePtr;    /* Points to the call frame whose variables
  484.                  * are currently in use (same as framePtr
  485.                  * unless an "uplevel" command is being
  486.                  * executed).  NULL means no procedure is
  487.                  * active or "uplevel 0" is being exec'ed. */
  488.     ActiveVarTrace *activeTracePtr;
  489.                 /* First in list of active traces for interp,
  490.                  * or NULL if no active traces. */
  491.     int returnCode;        /* Completion code to return if current
  492.                  * procedure exits with a TCL_RETURN code. */
  493.     char *errorInfo;        /* Value to store in errorInfo if returnCode
  494.                  * is TCL_ERROR.  Malloc'ed, may be NULL */
  495.     char *errorCode;        /* Value to store in errorCode if returnCode
  496.                  * is TCL_ERROR.  Malloc'ed, may be NULL */
  497.  
  498.     /*
  499.      * Information related to history:
  500.      */
  501.  
  502.     int numEvents;        /* Number of previously-executed commands
  503.                  * to retain. */
  504.     HistoryEvent *events;    /* Array containing numEvents entries
  505.                  * (dynamically allocated). */
  506.     int curEvent;        /* Index into events of place where current
  507.                  * (or most recent) command is recorded. */
  508.     int curEventNum;        /* Event number associated with the slot
  509.                  * given by curEvent. */
  510.     HistoryRev *revPtr;        /* First in list of pending revisions. */
  511.     char *historyFirst;        /* First char. of current command executed
  512.                  * from history module or NULL if none. */
  513.     int revDisables;        /* 0 means history revision OK;  > 0 gives
  514.                  * a count of number of times revision has
  515.                  * been disabled. */
  516.     char *evalFirst;        /* If TCL_RECORD_BOUNDS flag set, Tcl_Eval
  517.                  * sets this field to point to the first
  518.                  * char. of text from which the current
  519.                  * command came.  Otherwise Tcl_Eval sets
  520.                  * this to NULL. */
  521.     char *evalLast;        /* Similar to evalFirst, except points to
  522.                  * last character of current command. */
  523.  
  524.     /*
  525.      * Information used by Tcl_AppendResult to keep track of partial
  526.      * results.  See Tcl_AppendResult code for details.
  527.      */
  528.  
  529.     char *appendResult;        /* Storage space for results generated
  530.                  * by Tcl_AppendResult.  Malloc-ed.  NULL
  531.                  * means not yet allocated. */
  532.     int appendAvl;        /* Total amount of space available at
  533.                  * partialResult. */
  534.     int appendUsed;        /* Number of non-null bytes currently
  535.                  * stored at partialResult. */
  536.  
  537.     /*
  538.      * A cache of compiled regular expressions.  See Tcl_RegExpCompile
  539.      * in tclUtil.c for details.
  540.      */
  541.  
  542. #define NUM_REGEXPS 5
  543.     char *patterns[NUM_REGEXPS];/* Strings corresponding to compiled
  544.                  * regular expression patterns.  NULL
  545.                  * means that this slot isn't used.
  546.                  * Malloc-ed. */
  547.     int patLengths[NUM_REGEXPS];/* Number of non-null characters in
  548.                  * corresponding entry in patterns.
  549.                  * -1 means entry isn't used. */
  550.     regexp *regexps[NUM_REGEXPS];
  551.                 /* Compiled forms of above strings.  Also
  552.                  * malloc-ed, or NULL if not in use yet. */
  553.  
  554.     /*
  555.      * Information used by Tcl_PrintDouble:
  556.      */
  557.  
  558.     char pdFormat[10];        /* Format string used by Tcl_PrintDouble. */
  559.     int pdPrec;            /* Current precision (used to restore the
  560.                  * the tcl_precision variable after a bogus
  561.                  * value has been put into it). */
  562.  
  563.     /*
  564.      * Miscellaneous information:
  565.      */
  566.  
  567.     int cmdCount;        /* Total number of times a command procedure
  568.                  * has been called for this interpreter. */
  569.     int noEval;            /* Non-zero means no commands should actually
  570.                  * be executed:  just parse only.  Used in
  571.                  * expressions when the result is already
  572.                  * determined. */
  573.     int evalFlags;        /* Flags to control next call to Tcl_Eval.
  574.                  * Normally zero, but may be set before
  575.                  * calling Tcl_Eval.  See below for valid
  576.                  * values. */
  577.     char *termPtr;        /* Character just after the last one in
  578.                  * a command.  Set by Tcl_Eval before
  579.                  * returning. */
  580.     char *scriptFile;        /* NULL means there is no nested source
  581.                  * command active;  otherwise this points to
  582.                  * the name of the file being sourced (it's
  583.                  * not malloc-ed:  it points to an argument
  584.                  * to Tcl_EvalFile. */
  585.     int flags;            /* Various flag bits.  See below. */
  586.     Trace *tracePtr;        /* List of traces for this interpreter. */
  587.     DeleteCallback *deleteCallbackPtr;
  588.                 /* First in list of callbacks to invoke when
  589.                  * interpreter is deleted. */
  590.     char resultSpace[TCL_RESULT_SIZE+1];
  591.                 /* Static space for storing small results. */
  592. } Interp;
  593.  
  594. /*
  595.  * EvalFlag bits for Interp structures:
  596.  *
  597.  * TCL_BRACKET_TERM    1 means that the current script is terminated by
  598.  *            a close bracket rather than the end of the string.
  599.  * TCL_RECORD_BOUNDS    Tells Tcl_Eval to record information in the
  600.  *            evalFirst and evalLast fields for each command
  601.  *            executed directly from the string (top-level
  602.  *            commands and those from command substitution).
  603.  * TCL_ALLOW_EXCEPTIONS    1 means it's OK for the script to terminate with
  604.  *            a code other than TCL_OK or TCL_ERROR;  0 means
  605.  *            codes other than these should be turned into errors.
  606.  */
  607.  
  608. #define TCL_BRACKET_TERM    1
  609. #define TCL_RECORD_BOUNDS    2
  610. #define TCL_ALLOW_EXCEPTIONS    4
  611.  
  612. /*
  613.  * Flag bits for Interp structures:
  614.  *
  615.  * DELETED:        Non-zero means the interpreter has been deleted:
  616.  *            don't process any more commands for it, and destroy
  617.  *            the structure as soon as all nested invocations of
  618.  *            Tcl_Eval are done.
  619.  * ERR_IN_PROGRESS:    Non-zero means an error unwind is already in progress.
  620.  *            Zero means a command proc has been invoked since last
  621.  *            error occured.
  622.  * ERR_ALREADY_LOGGED:    Non-zero means information has already been logged
  623.  *            in $errorInfo for the current Tcl_Eval instance,
  624.  *            so Tcl_Eval needn't log it (used to implement the
  625.  *            "error message log" command).
  626.  * ERROR_CODE_SET:    Non-zero means that Tcl_SetErrorCode has been
  627.  *            called to record information for the current
  628.  *            error.  Zero means Tcl_Eval must clear the
  629.  *            errorCode variable if an error is returned.
  630.  * EXPR_INITIALIZED:    1 means initialization specific to expressions has
  631.  *            been carried out.
  632.  */
  633.  
  634. #define DELETED            1
  635. #define ERR_IN_PROGRESS        2
  636. #define ERR_ALREADY_LOGGED    4
  637. #define ERROR_CODE_SET        8
  638. #define EXPR_INITIALIZED    0x10
  639.  
  640. /*
  641.  * Default value for the pdPrec and pdFormat fields of interpreters:
  642.  */
  643.  
  644. #define DEFAULT_PD_PREC 6
  645. #define DEFAULT_PD_FORMAT "%g"
  646.  
  647. /*
  648.  *----------------------------------------------------------------
  649.  * Data structures related to command parsing.   These are used in
  650.  * tclParse.c and its clients.
  651.  *----------------------------------------------------------------
  652.  */
  653.  
  654. /*
  655.  * The following data structure is used by various parsing procedures
  656.  * to hold information about where to store the results of parsing
  657.  * (e.g. the substituted contents of a quoted argument, or the result
  658.  * of a nested command).  At any given time, the space available
  659.  * for output is fixed, but a procedure may be called to expand the
  660.  * space available if the current space runs out.
  661.  */
  662.  
  663. typedef struct ParseValue {
  664.     char *buffer;        /* Address of first character in
  665.                  * output buffer. */
  666.     char *next;            /* Place to store next character in
  667.                  * output buffer. */
  668.     char *end;            /* Address of the last usable character
  669.                  * in the buffer. */
  670.     void (*expandProc) _ANSI_ARGS_((struct ParseValue *pvPtr, int needed));
  671.                 /* Procedure to call when space runs out;
  672.                  * it will make more space. */
  673.     ClientData clientData;    /* Arbitrary information for use of
  674.                  * expandProc. */
  675. } ParseValue;
  676.  
  677. /*
  678.  * A table used to classify input characters to assist in parsing
  679.  * Tcl commands.  The table should be indexed with a signed character
  680.  * using the CHAR_TYPE macro.  The character may have a negative
  681.  * value.
  682.  */
  683.  
  684. extern char tclTypeTable[];
  685. #define CHAR_TYPE(c) (tclTypeTable+128)[c]
  686.  
  687. /*
  688.  * Possible values returned by CHAR_TYPE:
  689.  *
  690.  * TCL_NORMAL -        All characters that don't have special significance
  691.  *            to the Tcl language.
  692.  * TCL_SPACE -        Character is space, tab, or return.
  693.  * TCL_COMMAND_END -    Character is newline or null or semicolon or
  694.  *            close-bracket.
  695.  * TCL_QUOTE -        Character is a double-quote.
  696.  * TCL_OPEN_BRACKET -    Character is a "[".
  697.  * TCL_OPEN_BRACE -    Character is a "{".
  698.  * TCL_CLOSE_BRACE -    Character is a "}".
  699.  * TCL_BACKSLASH -    Character is a "\".
  700.  * TCL_DOLLAR -        Character is a "$".
  701.  */
  702.  
  703. #define TCL_NORMAL        0
  704. #define TCL_SPACE        1
  705. #define TCL_COMMAND_END        2
  706. #define TCL_QUOTE        3
  707. #define TCL_OPEN_BRACKET    4
  708. #define TCL_OPEN_BRACE        5
  709. #define TCL_CLOSE_BRACE        6
  710. #define TCL_BACKSLASH        7
  711. #define TCL_DOLLAR        8
  712.  
  713. /*
  714.  * Maximum number of levels of nesting permitted in Tcl commands (used
  715.  * to catch infinite recursion).
  716.  */
  717.  
  718. #define MAX_NESTING_DEPTH    1000
  719.  
  720. /*
  721.  * The macro below is used to modify a "char" value (e.g. by casting
  722.  * it to an unsigned character) so that it can be used safely with
  723.  * macros such as isspace.
  724.  */
  725.  
  726. #define UCHAR(c) ((unsigned char) (c))
  727.  
  728. /*
  729.  * Given a size or address, the macro below "aligns" it to the machine's
  730.  * memory unit size (e.g. an 8-byte boundary) so that anything can be
  731.  * placed at the aligned address without fear of an alignment error.
  732.  */
  733.  
  734. #define TCL_ALIGN(x) ((x + 7) & ~7)
  735.  
  736. /*
  737.  * Variables shared among Tcl modules but not used by the outside
  738.  * world:
  739.  */
  740.  
  741. extern int        tclNumFiles;
  742. extern OpenFile **    tclOpenFiles;
  743.  
  744. /*
  745.  *----------------------------------------------------------------
  746.  * Procedures shared among Tcl modules but not used by the outside
  747.  * world:
  748.  *----------------------------------------------------------------
  749.  */
  750.  
  751. extern void        panic();
  752. extern void        TclCopyAndCollapse _ANSI_ARGS_((int count, char *src,
  753.                 char *dst));
  754. extern void        TclDeleteVars _ANSI_ARGS_((Interp *iPtr,
  755.                 Tcl_HashTable *tablePtr));
  756. extern void        TclExpandParseValue _ANSI_ARGS_((ParseValue *pvPtr,
  757.                 int needed));
  758. extern void        TclExprFloatError _ANSI_ARGS_((Tcl_Interp *interp,
  759.                 double value));
  760. extern int        TclFindElement _ANSI_ARGS_((Tcl_Interp *interp,
  761.                 char *list, char **elementPtr, char **nextPtr,
  762.                 int *sizePtr, int *bracePtr));
  763. extern Proc *        TclFindProc _ANSI_ARGS_((Interp *iPtr,
  764.                 char *procName));
  765. extern int        TclGetFrame _ANSI_ARGS_((Tcl_Interp *interp,
  766.                 char *string, CallFrame **framePtrPtr));
  767. extern int        TclGetListIndex _ANSI_ARGS_((Tcl_Interp *interp,
  768.                 char *string, int *indexPtr));
  769. extern Proc *        TclIsProc _ANSI_ARGS_((Command *cmdPtr));
  770. extern int        TclNeedSpace _ANSI_ARGS_((char *start, char *end));
  771. extern int        TclParseBraces _ANSI_ARGS_((Tcl_Interp *interp,
  772.                 char *string, char **termPtr, ParseValue *pvPtr));
  773. extern int        TclParseNestedCmd _ANSI_ARGS_((Tcl_Interp *interp,
  774.                 char *string, int flags, char **termPtr,
  775.                 ParseValue *pvPtr));
  776. extern int        TclParseQuotes _ANSI_ARGS_((Tcl_Interp *interp,
  777.                 char *string, int termChar, int flags,
  778.                 char **termPtr, ParseValue *pvPtr));
  779. extern int        TclParseWords _ANSI_ARGS_((Tcl_Interp *interp,
  780.                 char *string, int flags, int maxWords,
  781.                 char **termPtr, int *argcPtr, char **argv,
  782.                 ParseValue *pvPtr));
  783. extern char *        TclPrecTraceProc _ANSI_ARGS_((ClientData clientData,
  784.                 Tcl_Interp *interp, char *name1, char *name2,
  785.                 int flags));
  786. extern void        TclSetupEnv _ANSI_ARGS_((Tcl_Interp *interp));
  787. extern int        TclUpdateReturnInfo _ANSI_ARGS_((Interp *iPtr));
  788. extern char *        TclWordEnd _ANSI_ARGS_((char *start, int nested,
  789.                 int *semiPtr));
  790.  
  791. /*
  792.  *----------------------------------------------------------------
  793.  * Command procedures in the generic core:
  794.  *----------------------------------------------------------------
  795.  */
  796.  
  797. extern int    Tcl_AppendCmd _ANSI_ARGS_((ClientData clientData,
  798.             Tcl_Interp *interp, int argc, char **argv));
  799. extern int    Tcl_ArrayCmd _ANSI_ARGS_((ClientData clientData,
  800.             Tcl_Interp *interp, int argc, char **argv));
  801. extern int    Tcl_BreakCmd _ANSI_ARGS_((ClientData clientData,
  802.             Tcl_Interp *interp, int argc, char **argv));
  803. extern int    Tcl_CaseCmd _ANSI_ARGS_((ClientData clientData,
  804.             Tcl_Interp *interp, int argc, char **argv));
  805. extern int    Tcl_CatchCmd _ANSI_ARGS_((ClientData clientData,
  806.             Tcl_Interp *interp, int argc, char **argv));
  807. extern int    Tcl_ConcatCmd _ANSI_ARGS_((ClientData clientData,
  808.             Tcl_Interp *interp, int argc, char **argv));
  809. extern int    Tcl_ContinueCmd _ANSI_ARGS_((ClientData clientData,
  810.             Tcl_Interp *interp, int argc, char **argv));
  811. extern int    Tcl_ErrorCmd _ANSI_ARGS_((ClientData clientData,
  812.             Tcl_Interp *interp, int argc, char **argv));
  813. extern int    Tcl_EvalCmd _ANSI_ARGS_((ClientData clientData,
  814.             Tcl_Interp *interp, int argc, char **argv));
  815. extern int    Tcl_ExprCmd _ANSI_ARGS_((ClientData clientData,
  816.             Tcl_Interp *interp, int argc, char **argv));
  817. extern int    Tcl_ForCmd _ANSI_ARGS_((ClientData clientData,
  818.             Tcl_Interp *interp, int argc, char **argv));
  819. extern int    Tcl_ForeachCmd _ANSI_ARGS_((ClientData clientData,
  820.             Tcl_Interp *interp, int argc, char **argv));
  821. extern int    Tcl_FormatCmd _ANSI_ARGS_((ClientData clientData,
  822.             Tcl_Interp *interp, int argc, char **argv));
  823. extern int    Tcl_GlobalCmd _ANSI_ARGS_((ClientData clientData,
  824.             Tcl_Interp *interp, int argc, char **argv));
  825. extern int    Tcl_HistoryCmd _ANSI_ARGS_((ClientData clientData,
  826.             Tcl_Interp *interp, int argc, char **argv));
  827. extern int    Tcl_IfCmd _ANSI_ARGS_((ClientData clientData,
  828.             Tcl_Interp *interp, int argc, char **argv));
  829. extern int    Tcl_IncrCmd _ANSI_ARGS_((ClientData clientData,
  830.             Tcl_Interp *interp, int argc, char **argv));
  831. extern int    Tcl_InfoCmd _ANSI_ARGS_((ClientData clientData,
  832.             Tcl_Interp *interp, int argc, char **argv));
  833. extern int    Tcl_JoinCmd _ANSI_ARGS_((ClientData clientData,
  834.             Tcl_Interp *interp, int argc, char **argv));
  835. extern int    Tcl_LappendCmd _ANSI_ARGS_((ClientData clientData,
  836.             Tcl_Interp *interp, int argc, char **argv));
  837. extern int    Tcl_LindexCmd _ANSI_ARGS_((ClientData clientData,
  838.             Tcl_Interp *interp, int argc, char **argv));
  839. extern int    Tcl_LinsertCmd _ANSI_ARGS_((ClientData clientData,
  840.             Tcl_Interp *interp, int argc, char **argv));
  841. extern int    Tcl_LlengthCmd _ANSI_ARGS_((ClientData clientData,
  842.             Tcl_Interp *interp, int argc, char **argv));
  843. extern int    Tcl_ListCmd _ANSI_ARGS_((ClientData clientData,
  844.             Tcl_Interp *interp, int argc, char **argv));
  845. extern int    Tcl_LrangeCmd _ANSI_ARGS_((ClientData clientData,
  846.             Tcl_Interp *interp, int argc, char **argv));
  847. extern int    Tcl_LreplaceCmd _ANSI_ARGS_((ClientData clientData,
  848.             Tcl_Interp *interp, int argc, char **argv));
  849. extern int    Tcl_LsearchCmd _ANSI_ARGS_((ClientData clientData,
  850.             Tcl_Interp *interp, int argc, char **argv));
  851. extern int    Tcl_LsortCmd _ANSI_ARGS_((ClientData clientData,
  852.             Tcl_Interp *interp, int argc, char **argv));
  853. extern int    Tcl_ProcCmd _ANSI_ARGS_((ClientData clientData,
  854.             Tcl_Interp *interp, int argc, char **argv));
  855. extern int    Tcl_RegexpCmd _ANSI_ARGS_((ClientData clientData,
  856.             Tcl_Interp *interp, int argc, char **argv));
  857. extern int    Tcl_RegsubCmd _ANSI_ARGS_((ClientData clientData,
  858.             Tcl_Interp *interp, int argc, char **argv));
  859. extern int    Tcl_RenameCmd _ANSI_ARGS_((ClientData clientData,
  860.             Tcl_Interp *interp, int argc, char **argv));
  861. extern int    Tcl_ReturnCmd _ANSI_ARGS_((ClientData clientData,
  862.             Tcl_Interp *interp, int argc, char **argv));
  863. extern int    Tcl_ScanCmd _ANSI_ARGS_((ClientData clientData,
  864.             Tcl_Interp *interp, int argc, char **argv));
  865. extern int    Tcl_SetCmd _ANSI_ARGS_((ClientData clientData,
  866.             Tcl_Interp *interp, int argc, char **argv));
  867. extern int    Tcl_SplitCmd _ANSI_ARGS_((ClientData clientData,
  868.             Tcl_Interp *interp, int argc, char **argv));
  869. extern int    Tcl_StringCmd _ANSI_ARGS_((ClientData clientData,
  870.             Tcl_Interp *interp, int argc, char **argv));
  871. extern int    Tcl_SubstCmd _ANSI_ARGS_((ClientData clientData,
  872.             Tcl_Interp *interp, int argc, char **argv));
  873. extern int    Tcl_SwitchCmd _ANSI_ARGS_((ClientData clientData,
  874.             Tcl_Interp *interp, int argc, char **argv));
  875. extern int    Tcl_TraceCmd _ANSI_ARGS_((ClientData clientData,
  876.             Tcl_Interp *interp, int argc, char **argv));
  877. extern int    Tcl_UnsetCmd _ANSI_ARGS_((ClientData clientData,
  878.             Tcl_Interp *interp, int argc, char **argv));
  879. extern int    Tcl_UplevelCmd _ANSI_ARGS_((ClientData clientData,
  880.             Tcl_Interp *interp, int argc, char **argv));
  881. extern int    Tcl_UpvarCmd _ANSI_ARGS_((ClientData clientData,
  882.             Tcl_Interp *interp, int argc, char **argv));
  883. extern int    Tcl_WhileCmd _ANSI_ARGS_((ClientData clientData,
  884.             Tcl_Interp *interp, int argc, char **argv));
  885. extern int    Tcl_Cmd _ANSI_ARGS_((ClientData clientData,
  886.             Tcl_Interp *interp, int argc, char **argv));
  887. extern int    Tcl_Cmd _ANSI_ARGS_((ClientData clientData,
  888.             Tcl_Interp *interp, int argc, char **argv));
  889.  
  890. /*
  891.  *----------------------------------------------------------------
  892.  * Command procedures in the UNIX core:
  893.  *----------------------------------------------------------------
  894.  */
  895. #ifdef TCL_GENERIC_ONLY /* for RISCOS */
  896. extern int    Tcl_CdCmd _ANSI_ARGS_((ClientData clientData,
  897.             Tcl_Interp *interp, int argc, char **argv));
  898. extern int    Tcl_CloseCmd _ANSI_ARGS_((ClientData clientData,
  899.             Tcl_Interp *interp, int argc, char **argv));
  900. extern int    Tcl_EofCmd _ANSI_ARGS_((ClientData clientData,
  901.             Tcl_Interp *interp, int argc, char **argv));
  902. extern int    Tcl_ExecCmd _ANSI_ARGS_((ClientData clientData,
  903.             Tcl_Interp *interp, int argc, char **argv));
  904. extern int    Tcl_ExitCmd _ANSI_ARGS_((ClientData clientData,
  905.             Tcl_Interp *interp, int argc, char **argv));
  906. extern int    Tcl_FileCmd _ANSI_ARGS_((ClientData clientData,
  907.             Tcl_Interp *interp, int argc, char **argv));
  908. extern int    Tcl_FlushCmd _ANSI_ARGS_((ClientData clientData,
  909.             Tcl_Interp *interp, int argc, char **argv));
  910. extern int    Tcl_GetsCmd _ANSI_ARGS_((ClientData clientData,
  911.             Tcl_Interp *interp, int argc, char **argv));
  912. extern int    Tcl_GlobCmd _ANSI_ARGS_((ClientData clientData,
  913.             Tcl_Interp *interp, int argc, char **argv));
  914. extern int    Tcl_OpenCmd _ANSI_ARGS_((ClientData clientData,
  915.             Tcl_Interp *interp, int argc, char **argv));
  916. extern int    Tcl_PutsCmd _ANSI_ARGS_((ClientData clientData,
  917.             Tcl_Interp *interp, int argc, char **argv));
  918. extern int    Tcl_PidCmd _ANSI_ARGS_((ClientData clientData,
  919.             Tcl_Interp *interp, int argc, char **argv));
  920. extern int    Tcl_PwdCmd _ANSI_ARGS_((ClientData clientData,
  921.             Tcl_Interp *interp, int argc, char **argv));
  922. extern int    Tcl_ReadCmd _ANSI_ARGS_((ClientData clientData,
  923.             Tcl_Interp *interp, int argc, char **argv));
  924. extern int    Tcl_SeekCmd _ANSI_ARGS_((ClientData clientData,
  925.             Tcl_Interp *interp, int argc, char **argv));
  926. extern int    Tcl_SourceCmd _ANSI_ARGS_((ClientData clientData,
  927.             Tcl_Interp *interp, int argc, char **argv));
  928. extern int    Tcl_TellCmd _ANSI_ARGS_((ClientData clientData,
  929.             Tcl_Interp *interp, int argc, char **argv));
  930. extern int    Tcl_TimeCmd _ANSI_ARGS_((ClientData clientData,
  931.             Tcl_Interp *interp, int argc, char **argv));
  932. #endif /* TCL_GENERIC_ONLY*/
  933.  
  934. #endif /* _TCLINT */
  935.