1 /*
2  * tcl.h --
3  *
4  *	This header file describes the externally-visible facilities
5  *	of the Tcl interpreter.
6  *
7  * Copyright (c) 1987-1994 The Regents of the University of California.
8  * Copyright (c) 1993-1996 Lucent Technologies.
9  * Copyright (c) 1994-1998 Sun Microsystems, Inc.
10  * Copyright (c) 1998-2000 by Scriptics Corporation.
11  * Copyright (c) 2002 by Kevin B. Kenny.  All rights reserved.
12  *
13  * See the file "license.terms" for information on usage and redistribution
14  * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
15  *
16  * RCS: @(#) $Id: tcl.h,v 1.153.2.8 2003/10/22 22:35:46 andreas_kupries Exp $
17  */
18 #ifndef _TCL
19 #define _TCL
20 
21 /*
22  * For C++ compilers, use extern "C"
23  */
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
29 /*
30  * The following defines are used to indicate the various release levels.
31  */
32 
33 #define TCL_ALPHA_RELEASE	0
34 #define TCL_BETA_RELEASE	1
35 #define TCL_FINAL_RELEASE	2
36 
37 /*
38  * When version numbers change here, must also go into the following files
39  * and update the version numbers:
40  *
41  * library/init.tcl	(only if Major.minor changes, not patchlevel) 1 LOC
42  * unix/configure.in	(2 LOC Major, 2 LOC minor, 1 LOC patch)
43  * win/configure.in	(as above)
44  * win/tcl.m4		(not patchlevel)
45  * win/makefile.vc	(not patchlevel) 2 LOC
46  * README		(sections 0 and 2)
47  * mac/README		(2 LOC, not patchlevel)
48  * macosx/Tcl.pbproj/project.pbxproj (not patchlevel) 2 LOC
49  * win/README.binary	(sections 0-4)
50  * win/README		(not patchlevel) (sections 0 and 2)
51  * unix/tcl.spec	(2 LOC Major/Minor, 1 LOC patch)
52  * tests/basic.test	(1 LOC M/M, not patchlevel)
53  * tools/tcl.hpj.in	(not patchlevel, for windows installer)
54  * tools/tcl.wse.in	(for windows installer)
55  * tools/tclSplash.bmp	(not patchlevel)
56  */
57 #define TCL_MAJOR_VERSION   8
58 #define TCL_MINOR_VERSION   4
59 #define TCL_RELEASE_LEVEL   TCL_FINAL_RELEASE
60 #define TCL_RELEASE_SERIAL  5
61 
62 #define TCL_VERSION	    "8.4"
63 #define TCL_PATCH_LEVEL	    "8.4.5"
64 
65 /*
66  * The following definitions set up the proper options for Windows
67  * compilers.  We use this method because there is no autoconf equivalent.
68  */
69 
70 #ifndef __WIN32__
71 #   if defined(_WIN32) || defined(WIN32) || defined(__MINGW32__) || defined(__BORLANDC__)
72 #	define __WIN32__
73 #	ifndef WIN32
74 #	    define WIN32
75 #	endif
76 #   endif
77 #endif
78 
79 /*
80  * STRICT: See MSDN Article Q83456
81  */
82 #ifdef __WIN32__
83 #   ifndef STRICT
84 #	define STRICT
85 #   endif
86 #endif /* __WIN32__ */
87 
88 /*
89  * The following definitions set up the proper options for Macintosh
90  * compilers.  We use this method because there is no autoconf equivalent.
91  */
92 
93 #ifdef MAC_TCL
94 #include <ConditionalMacros.h>
95 #   ifndef USE_TCLALLOC
96 #	define USE_TCLALLOC 1
97 #   endif
98 #   ifndef NO_STRERROR
99 #	define NO_STRERROR 1
100 #   endif
101 #   define INLINE
102 #endif
103 
104 
105 /*
106  * Utility macros: STRINGIFY takes an argument and wraps it in "" (double
107  * quotation marks), JOIN joins two arguments.
108  */
109 #ifndef STRINGIFY
110 #  define STRINGIFY(x) STRINGIFY1(x)
111 #  define STRINGIFY1(x) #x
112 #endif
113 #ifndef JOIN
114 #  define JOIN(a,b) JOIN1(a,b)
115 #  define JOIN1(a,b) a##b
116 #endif
117 
118 /*
119  * A special definition used to allow this header file to be included
120  * from windows or mac resource files so that they can obtain version
121  * information.  RC_INVOKED is defined by default by the windows RC tool
122  * and manually set for macintosh.
123  *
124  * Resource compilers don't like all the C stuff, like typedefs and
125  * procedure declarations, that occur below, so block them out.
126  */
127 
128 #ifndef RC_INVOKED
129 
130 /*
131  * Special macro to define mutexes, that doesn't do anything
132  * if we are not using threads.
133  */
134 
135 #ifdef TCL_THREADS
136 #define TCL_DECLARE_MUTEX(name) static Tcl_Mutex name;
137 #else
138 #define TCL_DECLARE_MUTEX(name)
139 #endif
140 
141 /*
142  * Macros that eliminate the overhead of the thread synchronization
143  * functions when compiling without thread support.
144  */
145 
146 #ifndef TCL_THREADS
147 #define Tcl_MutexLock(mutexPtr)
148 #define Tcl_MutexUnlock(mutexPtr)
149 #define Tcl_MutexFinalize(mutexPtr)
150 #define Tcl_ConditionNotify(condPtr)
151 #define Tcl_ConditionWait(condPtr, mutexPtr, timePtr)
152 #define Tcl_ConditionFinalize(condPtr)
153 #endif /* TCL_THREADS */
154 
155 
156 #ifndef BUFSIZ
157 #   include <stdio.h>
158 #endif
159 
160 
161 /*
162  * Definitions that allow Tcl functions with variable numbers of
163  * arguments to be used with either varargs.h or stdarg.h.  TCL_VARARGS
164  * is used in procedure prototypes.  TCL_VARARGS_DEF is used to declare
165  * the arguments in a function definiton: it takes the type and name of
166  * the first argument and supplies the appropriate argument declaration
167  * string for use in the function definition.  TCL_VARARGS_START
168  * initializes the va_list data structure and returns the first argument.
169  */
170 #if !defined(NO_STDARG)
171 #   include <stdarg.h>
172 #   define TCL_VARARGS(type, name) (type name, ...)
173 #   define TCL_VARARGS_DEF(type, name) (type name, ...)
174 #   define TCL_VARARGS_START(type, name, list) (va_start(list, name), name)
175 #else
176 #   include <varargs.h>
177 #      define TCL_VARARGS(type, name) ()
178 #      define TCL_VARARGS_DEF(type, name) (va_alist)
179 #   define TCL_VARARGS_START(type, name, list) \
180 	(va_start(list), va_arg(list, type))
181 #endif
182 
183 /*
184  * Macros used to declare a function to be exported by a DLL.
185  * Used by Windows, maps to no-op declarations on non-Windows systems.
186  * The default build on windows is for a DLL, which causes the DLLIMPORT
187  * and DLLEXPORT macros to be nonempty. To build a static library, the
188  * macro STATIC_BUILD should be defined.
189  */
190 
191 #ifdef STATIC_BUILD
192 #   define DLLIMPORT
193 #   define DLLEXPORT
194 #else
195 #   if (defined(__WIN32__) && (defined(_MSC_VER) || (__BORLANDC__ >= 0x0550) || (defined(__GNUC__) && defined(__declspec)))) || (defined(MAC_TCL) && FUNCTION_DECLSPEC)
196 #	define DLLIMPORT __declspec(dllimport)
197 #	define DLLEXPORT __declspec(dllexport)
198 #   else
199 #	define DLLIMPORT
200 #	define DLLEXPORT
201 #   endif
202 #endif
203 
204 /*
205  * These macros are used to control whether functions are being declared for
206  * import or export.  If a function is being declared while it is being built
207  * to be included in a shared library, then it should have the DLLEXPORT
208  * storage class.  If is being declared for use by a module that is going to
209  * link against the shared library, then it should have the DLLIMPORT storage
210  * class.  If the symbol is beind declared for a static build or for use from a
211  * stub library, then the storage class should be empty.
212  *
213  * The convention is that a macro called BUILD_xxxx, where xxxx is the
214  * name of a library we are building, is set on the compile line for sources
215  * that are to be placed in the library.  When this macro is set, the
216  * storage class will be set to DLLEXPORT.  At the end of the header file, the
217  * storage class will be reset to DLLIMPORT.
218  */
219 #undef TCL_STORAGE_CLASS
220 #ifdef BUILD_tcl
221 #   define TCL_STORAGE_CLASS DLLEXPORT
222 #else
223 #   ifdef USE_TCL_STUBS
224 #      define TCL_STORAGE_CLASS
225 #   else
226 #      define TCL_STORAGE_CLASS DLLIMPORT
227 #   endif
228 #endif
229 
230 
231 /*
232  * Definitions that allow this header file to be used either with or
233  * without ANSI C features like function prototypes.
234  */
235 #undef _ANSI_ARGS_
236 #undef CONST
237 #ifndef INLINE
238 #   define INLINE
239 #endif
240 
241 #ifndef NO_CONST
242 #   define CONST const
243 #else
244 #   define CONST
245 #endif
246 
247 #ifndef NO_PROTOTYPES
248 #   define _ANSI_ARGS_(x)	x
249 #else
250 #   define _ANSI_ARGS_(x)	()
251 #endif
252 
253 #ifdef USE_NON_CONST
254 #   ifdef USE_COMPAT_CONST
255 #      error define at most one of USE_NON_CONST and USE_COMPAT_CONST
256 #   endif
257 #   define CONST84
258 #   define CONST84_RETURN
259 #else
260 #   ifdef USE_COMPAT_CONST
261 #      define CONST84
262 #      define CONST84_RETURN CONST
263 #   else
264 #      define CONST84 CONST
265 #      define CONST84_RETURN CONST
266 #   endif
267 #endif
268 
269 
270 /*
271  * Make sure EXTERN isn't defined elsewhere
272  */
273 #ifdef EXTERN
274 #   undef EXTERN
275 #endif /* EXTERN */
276 
277 #ifdef __cplusplus
278 #   define EXTERN extern "C" TCL_STORAGE_CLASS
279 #else
280 #   define EXTERN extern TCL_STORAGE_CLASS
281 #endif
282 
283 
284 /*
285  * The following code is copied from winnt.h.
286  * If we don't replicate it here, then <windows.h> can't be included
287  * after tcl.h, since tcl.h also defines VOID.
288  * This block is skipped under Cygwin and Mingw.
289  *
290  *
291  */
292 #if defined(__WIN32__) && !defined(HAVE_WINNT_IGNORE_VOID)
293 #ifndef VOID
294 #define VOID void
295 typedef char CHAR;
296 typedef short SHORT;
297 typedef long LONG;
298 #endif
299 #endif /* __WIN32__ && !HAVE_WINNT_IGNORE_VOID */
300 
301 /*
302  * Macro to use instead of "void" for arguments that must have
303  * type "void *" in ANSI C;  maps them to type "char *" in
304  * non-ANSI systems.
305  */
306 
307 #ifndef NO_VOID
308 #         define VOID void
309 #else
310 #         define VOID char
311 #endif
312 
313 /*
314  * Miscellaneous declarations.
315  */
316 #ifndef NULL
317 #   define NULL 0
318 #endif
319 
320 #ifndef _CLIENTDATA
321 #   ifndef NO_VOID
322 	typedef void *ClientData;
323 #   else
324 	typedef int *ClientData;
325 #   endif
326 #   define _CLIENTDATA
327 #endif
328 
329 /*
330  * Define Tcl_WideInt to be a type that is (at least) 64-bits wide,
331  * and define Tcl_WideUInt to be the unsigned variant of that type
332  * (assuming that where we have one, we can have the other.)
333  *
334  * Also defines the following macros:
335  * TCL_WIDE_INT_IS_LONG - if wide ints are really longs (i.e. we're on
336  *	a real 64-bit system.)
337  * Tcl_WideAsLong - forgetful converter from wideInt to long.
338  * Tcl_LongAsWide - sign-extending converter from long to wideInt.
339  * Tcl_WideAsDouble - converter from wideInt to double.
340  * Tcl_DoubleAsWide - converter from double to wideInt.
341  *
342  * The following invariant should hold for any long value 'longVal':
343  *	longVal == Tcl_WideAsLong(Tcl_LongAsWide(longVal))
344  *
345  * Note on converting between Tcl_WideInt and strings.  This
346  * implementation (in tclObj.c) depends on the functions strtoull()
347  * and sprintf(...,"%" TCL_LL_MODIFIER "d",...).  TCL_LL_MODIFIER_SIZE
348  * is the length of the modifier string, which is "ll" on most 32-bit
349  * Unix systems.  It has to be split up like this to allow for the more
350  * complex formats sometimes needed (e.g. in the format(n) command.)
351  */
352 
353 #if !defined(TCL_WIDE_INT_TYPE)&&!defined(TCL_WIDE_INT_IS_LONG)
354 #   if defined(__CYGWIN__)
355 #      define TCL_WIDE_INT_TYPE long long
356 #      define TCL_LL_MODIFIER	"L"
357 typedef struct stat	Tcl_StatBuf;
358 #      define TCL_LL_MODIFIER_SIZE	1
359 #   elif defined(__WIN32__)
360 #      define TCL_WIDE_INT_TYPE __int64
361 #      ifdef __BORLANDC__
362 typedef struct stati64 Tcl_StatBuf;
363 #         define TCL_LL_MODIFIER	"L"
364 #         define TCL_LL_MODIFIER_SIZE	1
365 #      else /* __BORLANDC__ */
366 typedef struct _stati64	Tcl_StatBuf;
367 #         define TCL_LL_MODIFIER	"I64"
368 #         define TCL_LL_MODIFIER_SIZE	3
369 #      endif /* __BORLANDC__ */
370 #   else /* __WIN32__ */
371 /*
372  * Don't know what platform it is and configure hasn't discovered what
373  * is going on for us.  Try to guess...
374  */
375 #      ifdef NO_LIMITS_H
376 #	  error please define either TCL_WIDE_INT_TYPE or TCL_WIDE_INT_IS_LONG
377 #      else /* !NO_LIMITS_H */
378 #	  include <limits.h>
379 #	  if (INT_MAX < LONG_MAX)
380 #	     define TCL_WIDE_INT_IS_LONG	1
381 #	  else
382 #	     define TCL_WIDE_INT_TYPE long long
383 #         endif
384 #      endif /* NO_LIMITS_H */
385 #   endif /* __WIN32__ */
386 #endif /* !TCL_WIDE_INT_TYPE & !TCL_WIDE_INT_IS_LONG */
387 #ifdef TCL_WIDE_INT_IS_LONG
388 #   undef TCL_WIDE_INT_TYPE
389 #   define TCL_WIDE_INT_TYPE	long
390 #endif /* TCL_WIDE_INT_IS_LONG */
391 
392 typedef TCL_WIDE_INT_TYPE		Tcl_WideInt;
393 typedef unsigned TCL_WIDE_INT_TYPE	Tcl_WideUInt;
394 
395 #ifdef TCL_WIDE_INT_IS_LONG
396 typedef struct stat	Tcl_StatBuf;
397 #   define Tcl_WideAsLong(val)		((long)(val))
398 #   define Tcl_LongAsWide(val)		((long)(val))
399 #   define Tcl_WideAsDouble(val)	((double)((long)(val)))
400 #   define Tcl_DoubleAsWide(val)	((long)((double)(val)))
401 #   ifndef TCL_LL_MODIFIER
402 #      define TCL_LL_MODIFIER		"l"
403 #      define TCL_LL_MODIFIER_SIZE	1
404 #   endif /* !TCL_LL_MODIFIER */
405 #else /* TCL_WIDE_INT_IS_LONG */
406 /*
407  * The next short section of defines are only done when not running on
408  * Windows or some other strange platform.
409  */
410 #   ifndef TCL_LL_MODIFIER
411 #      ifdef HAVE_STRUCT_STAT64
412 typedef struct stat64	Tcl_StatBuf;
413 #      else
414 typedef struct stat	Tcl_StatBuf;
415 #      endif /* HAVE_STRUCT_STAT64 */
416 #      define TCL_LL_MODIFIER		"ll"
417 #      define TCL_LL_MODIFIER_SIZE	2
418 #   endif /* !TCL_LL_MODIFIER */
419 #   define Tcl_WideAsLong(val)		((long)((Tcl_WideInt)(val)))
420 #   define Tcl_LongAsWide(val)		((Tcl_WideInt)((long)(val)))
421 #   define Tcl_WideAsDouble(val)	((double)((Tcl_WideInt)(val)))
422 #   define Tcl_DoubleAsWide(val)	((Tcl_WideInt)((double)(val)))
423 #endif /* TCL_WIDE_INT_IS_LONG */
424 
425 
426 /*
427  * This flag controls whether binary compatability is maintained with
428  * extensions built against a previous version of Tcl. This is true
429  * by default.
430  */
431 #ifndef TCL_PRESERVE_BINARY_COMPATABILITY
432 #   define TCL_PRESERVE_BINARY_COMPATABILITY 1
433 #endif
434 
435 
436 /*
437  * Data structures defined opaquely in this module. The definitions below
438  * just provide dummy types. A few fields are made visible in Tcl_Interp
439  * structures, namely those used for returning a string result from
440  * commands. Direct access to the result field is discouraged in Tcl 8.0.
441  * The interpreter result is either an object or a string, and the two
442  * values are kept consistent unless some C code sets interp->result
443  * directly. Programmers should use either the procedure Tcl_GetObjResult()
444  * or Tcl_GetStringResult() to read the interpreter's result. See the
445  * SetResult man page for details.
446  *
447  * Note: any change to the Tcl_Interp definition below must be mirrored
448  * in the "real" definition in tclInt.h.
449  *
450  * Note: Tcl_ObjCmdProc procedures do not directly set result and freeProc.
451  * Instead, they set a Tcl_Obj member in the "real" structure that can be
452  * accessed with Tcl_GetObjResult() and Tcl_SetObjResult().
453  */
454 
455 #ifndef Tcl_Interp
456 typedef struct Tcl_Interp
457 #ifdef USE_TCL_STRUCT
458 {
459     char *result;		/* If the last command returned a string
460 				 * result, this points to it. */
461     void (*freeProc) _ANSI_ARGS_((char *blockPtr));
462 				/* Zero means the string result is
463 				 * statically allocated. TCL_DYNAMIC means
464 				 * it was allocated with ckalloc and should
465 				 * be freed with ckfree. Other values give
466 				 * the address of procedure to invoke to
467 				 * free the result. Tcl_Eval must free it
468 				 * before executing next command. */
469     int errorLine;              /* When TCL_ERROR is returned, this gives
470                                  * the line number within the command where
471                                  * the error occurred (1 if first line). */
472 }
473 #endif
474 Tcl_Interp;
475 #endif
476 
477 typedef struct Tcl_AsyncHandler_ *Tcl_AsyncHandler;
478 #ifndef Tcl_Channel
479 typedef struct Tcl_Channel_ *Tcl_Channel;
480 #endif
481 #ifndef Tcl_Command
482 typedef struct Tcl_Command_ *Tcl_Command;
483 #endif
484 typedef struct Tcl_Condition_ *Tcl_Condition;
485 typedef struct Tcl_EncodingState_ *Tcl_EncodingState;
486 typedef struct Tcl_Encoding_ *Tcl_Encoding;
487 typedef struct Tcl_Event Tcl_Event;
488 typedef struct Tcl_Mutex_ *Tcl_Mutex;
489 typedef struct Tcl_Pid_ *Tcl_Pid;
490 #ifndef Tcl_RegExp
491 typedef struct Tcl_RegExp_ *Tcl_RegExp;
492 #endif
493 typedef struct Tcl_ThreadDataKey_ *Tcl_ThreadDataKey;
494 typedef struct Tcl_ThreadId_ *Tcl_ThreadId;
495 typedef struct Tcl_TimerToken_ *Tcl_TimerToken;
496 typedef struct Tcl_Trace_ *Tcl_Trace;
497 typedef struct Tcl_Var_ *Tcl_Var;
498 typedef struct Tcl_ChannelTypeVersion_ *Tcl_ChannelTypeVersion;
499 typedef struct Tcl_LoadHandle_ *Tcl_LoadHandle;
500 
501 /*
502  * Definition of the interface to procedures implementing threads.
503  * A procedure following this definition is given to each call of
504  * 'Tcl_CreateThread' and will be called as the main fuction of
505  * the new thread created by that call.
506  */
507 #ifdef MAC_TCL
508 typedef pascal void *(Tcl_ThreadCreateProc) _ANSI_ARGS_((ClientData clientData));
509 #elif defined __WIN32__
510 typedef unsigned (__stdcall Tcl_ThreadCreateProc) _ANSI_ARGS_((ClientData clientData));
511 #else
512 typedef void (Tcl_ThreadCreateProc) _ANSI_ARGS_((ClientData clientData));
513 #endif
514 
515 
516 /*
517  * Threading function return types used for abstracting away platform
518  * differences when writing a Tcl_ThreadCreateProc.  See the NewThread
519  * function in generic/tclThreadTest.c for it's usage.
520  */
521 #ifdef MAC_TCL
522 #   define Tcl_ThreadCreateType		pascal void *
523 #   define TCL_THREAD_CREATE_RETURN	return NULL
524 #elif defined __WIN32__
525 #   define Tcl_ThreadCreateType		unsigned __stdcall
526 #   define TCL_THREAD_CREATE_RETURN	return 0
527 #else
528 #   define Tcl_ThreadCreateType		void
529 #   define TCL_THREAD_CREATE_RETURN
530 #endif
531 
532 
533 /*
534  * Definition of values for default stacksize and the possible flags to be
535  * given to Tcl_CreateThread.
536  */
537 #define TCL_THREAD_STACK_DEFAULT (0)    /* Use default size for stack */
538 #define TCL_THREAD_NOFLAGS       (0000) /* Standard flags, default behaviour */
539 #define TCL_THREAD_JOINABLE      (0001) /* Mark the thread as joinable */
540 
541 /*
542  * Flag values passed to Tcl_GetRegExpFromObj.
543  */
544 #define	TCL_REG_BASIC		000000	/* BREs (convenience) */
545 #define	TCL_REG_EXTENDED	000001	/* EREs */
546 #define	TCL_REG_ADVF		000002	/* advanced features in EREs */
547 #define	TCL_REG_ADVANCED	000003	/* AREs (which are also EREs) */
548 #define	TCL_REG_QUOTE		000004	/* no special characters, none */
549 #define	TCL_REG_NOCASE		000010	/* ignore case */
550 #define	TCL_REG_NOSUB		000020	/* don't care about subexpressions */
551 #define	TCL_REG_EXPANDED	000040	/* expanded format, white space &
552 					 * comments */
553 #define	TCL_REG_NLSTOP		000100  /* \n doesn't match . or [^ ] */
554 #define	TCL_REG_NLANCH		000200  /* ^ matches after \n, $ before */
555 #define	TCL_REG_NEWLINE		000300  /* newlines are line terminators */
556 #define	TCL_REG_CANMATCH	001000  /* report details on partial/limited
557 					 * matches */
558 
559 /*
560  * The following flag is experimental and only intended for use by Expect.  It
561  * will probably go away in a later release.
562  */
563 #define TCL_REG_BOSONLY		002000	/* prepend \A to pattern so it only
564 					 * matches at the beginning of the
565 					 * string. */
566 
567 /*
568  * Flags values passed to Tcl_RegExpExecObj.
569  */
570 #define	TCL_REG_NOTBOL	0001	/* Beginning of string does not match ^.  */
571 #define	TCL_REG_NOTEOL	0002	/* End of string does not match $. */
572 
573 /*
574  * Structures filled in by Tcl_RegExpInfo.  Note that all offset values are
575  * relative to the start of the match string, not the beginning of the
576  * entire string.
577  */
578 typedef struct Tcl_RegExpIndices {
579     long start;		/* character offset of first character in match */
580     long end;		/* character offset of first character after the
581 			 * match. */
582 } Tcl_RegExpIndices;
583 
584 typedef struct Tcl_RegExpInfo {
585     int nsubs;			/* number of subexpressions in the
586 				 * compiled expression */
587     Tcl_RegExpIndices *matches;	/* array of nsubs match offset
588 				 * pairs */
589     long extendStart;		/* The offset at which a subsequent
590 				 * match might begin. */
591     long reserved;		/* Reserved for later use. */
592 } Tcl_RegExpInfo;
593 
594 /*
595  * Picky compilers complain if this typdef doesn't appear before the
596  * struct's reference in tclDecls.h.
597  */
598 typedef Tcl_StatBuf *Tcl_Stat_;
599 typedef struct stat *Tcl_OldStat_;
600 
601 /*
602  * When a TCL command returns, the interpreter contains a result from the
603  * command. Programmers are strongly encouraged to use one of the
604  * procedures Tcl_GetObjResult() or Tcl_GetStringResult() to read the
605  * interpreter's result. See the SetResult man page for details. Besides
606  * this result, the command procedure returns an integer code, which is
607  * one of the following:
608  *
609  * TCL_OK		Command completed normally; the interpreter's
610  *			result contains	the command's result.
611  * TCL_ERROR		The command couldn't be completed successfully;
612  *			the interpreter's result describes what went wrong.
613  * TCL_RETURN		The command requests that the current procedure
614  *			return; the interpreter's result contains the
615  *			procedure's return value.
616  * TCL_BREAK		The command requests that the innermost loop
617  *			be exited; the interpreter's result is meaningless.
618  * TCL_CONTINUE		Go on to the next iteration of the current loop;
619  *			the interpreter's result is meaningless.
620  */
621 #define TCL_OK		0
622 #define TCL_ERROR	1
623 #define TCL_RETURN	2
624 #define TCL_BREAK	3
625 #define TCL_CONTINUE	4
626 
627 #define TCL_RESULT_SIZE 200
628 
629 /*
630  * Flags to control what substitutions are performed by Tcl_SubstObj():
631  */
632 #define TCL_SUBST_COMMANDS	001
633 #define TCL_SUBST_VARIABLES	002
634 #define TCL_SUBST_BACKSLASHES	004
635 #define TCL_SUBST_ALL		007
636 
637 
638 /*
639  * Argument descriptors for math function callbacks in expressions:
640  */
641 typedef enum {
642     TCL_INT, TCL_DOUBLE, TCL_EITHER, TCL_WIDE_INT
643 } Tcl_ValueType;
644 typedef struct Tcl_Value {
645     Tcl_ValueType type;		/* Indicates intValue or doubleValue is
646 				 * valid, or both. */
647     long intValue;		/* Integer value. */
648     double doubleValue;		/* Double-precision floating value. */
649     Tcl_WideInt wideValue;	/* Wide (min. 64-bit) integer value. */
650 } Tcl_Value;
651 
652 /*
653  * Forward declaration of Tcl_Obj to prevent an error when the forward
654  * reference to Tcl_Obj is encountered in the procedure types declared
655  * below.
656  */
657 #ifndef Tcl_Obj
658 typedef struct Tcl_Obj Tcl_Obj;
659 #endif
660 
661 /*
662  * Procedure types defined by Tcl:
663  */
664 
665 typedef int (Tcl_AppInitProc) _ANSI_ARGS_((Tcl_Interp *interp));
666 typedef int (Tcl_AsyncProc) _ANSI_ARGS_((ClientData clientData,
667 	Tcl_Interp *interp, int code));
668 typedef void (Tcl_ChannelProc) _ANSI_ARGS_((ClientData clientData, int mask));
669 typedef void (Tcl_CloseProc) _ANSI_ARGS_((ClientData data));
670 typedef void (Tcl_CmdDeleteProc) _ANSI_ARGS_((ClientData clientData));
671 typedef int (Tcl_CmdProc) _ANSI_ARGS_((ClientData clientData,
672 	Tcl_Interp *interp, int argc, CONST84 char *argv[]));
673 typedef void (Tcl_CmdTraceProc) _ANSI_ARGS_((ClientData clientData,
674 	Tcl_Interp *interp, int level, char *command, Tcl_CmdProc *proc,
675 	ClientData cmdClientData, int argc, CONST84 char *argv[]));
676 typedef int (Tcl_CmdObjTraceProc) _ANSI_ARGS_((ClientData clientData,
677 	Tcl_Interp *interp, int level, CONST char *command,
678 	Tcl_Command commandInfo, int objc, Tcl_Obj * CONST * objv));
679 typedef void (Tcl_CmdObjTraceDeleteProc) _ANSI_ARGS_((ClientData clientData));
680 typedef void (Tcl_DupInternalRepProc) _ANSI_ARGS_((Tcl_Obj *srcPtr,
681         Tcl_Obj *dupPtr));
682 typedef int (Tcl_EncodingConvertProc)_ANSI_ARGS_((ClientData clientData,
683 	CONST char *src, int srcLen, int flags, Tcl_EncodingState *statePtr,
684 	char *dst, int dstLen, int *srcReadPtr, int *dstWrotePtr,
685 	int *dstCharsPtr));
686 typedef void (Tcl_EncodingFreeProc)_ANSI_ARGS_((ClientData clientData));
687 typedef int (Tcl_EventProc) _ANSI_ARGS_((Tcl_Event *evPtr, int flags));
688 typedef void (Tcl_EventCheckProc) _ANSI_ARGS_((ClientData clientData,
689 	int flags));
690 typedef int (Tcl_EventDeleteProc) _ANSI_ARGS_((Tcl_Event *evPtr,
691         ClientData clientData));
692 typedef void (Tcl_EventSetupProc) _ANSI_ARGS_((ClientData clientData,
693 	int flags));
694 typedef void (Tcl_ExitProc) _ANSI_ARGS_((ClientData clientData));
695 typedef void (Tcl_FileProc) _ANSI_ARGS_((ClientData clientData, int mask));
696 typedef void (Tcl_FileFreeProc) _ANSI_ARGS_((ClientData clientData));
697 typedef void (Tcl_FreeInternalRepProc) _ANSI_ARGS_((Tcl_Obj *objPtr));
698 typedef void (Tcl_FreeProc) _ANSI_ARGS_((char *blockPtr));
699 typedef void (Tcl_IdleProc) _ANSI_ARGS_((ClientData clientData));
700 typedef void (Tcl_InterpDeleteProc) _ANSI_ARGS_((ClientData clientData,
701 	Tcl_Interp *interp));
702 typedef int (Tcl_MathProc) _ANSI_ARGS_((ClientData clientData,
703 	Tcl_Interp *interp, Tcl_Value *args, Tcl_Value *resultPtr));
704 typedef void (Tcl_NamespaceDeleteProc) _ANSI_ARGS_((ClientData clientData));
705 typedef int (Tcl_ObjCmdProc) _ANSI_ARGS_((ClientData clientData,
706 	Tcl_Interp *interp, int objc, Tcl_Obj * CONST * objv));
707 typedef int (Tcl_PackageInitProc) _ANSI_ARGS_((Tcl_Interp *interp));
708 typedef void (Tcl_PanicProc) _ANSI_ARGS_(TCL_VARARGS(CONST char *, format));
709 typedef void (Tcl_TcpAcceptProc) _ANSI_ARGS_((ClientData callbackData,
710         Tcl_Channel chan, char *address, int port));
711 typedef void (Tcl_TimerProc) _ANSI_ARGS_((ClientData clientData));
712 typedef int (Tcl_SetFromAnyProc) _ANSI_ARGS_((Tcl_Interp *interp,
713 	Tcl_Obj *objPtr));
714 typedef void (Tcl_UpdateStringProc) _ANSI_ARGS_((Tcl_Obj *objPtr));
715 typedef char *(Tcl_VarTraceProc) _ANSI_ARGS_((ClientData clientData,
716 	Tcl_Interp *interp, CONST84 char *part1, CONST84 char *part2, int flags));
717 typedef void (Tcl_CommandTraceProc) _ANSI_ARGS_((ClientData clientData,
718 	Tcl_Interp *interp, CONST char *oldName, CONST char *newName,
719 	int flags));
720 typedef void (Tcl_CreateFileHandlerProc) _ANSI_ARGS_((int fd, int mask,
721 	Tcl_FileProc *proc, ClientData clientData));
722 typedef void (Tcl_DeleteFileHandlerProc) _ANSI_ARGS_((int fd));
723 typedef void (Tcl_AlertNotifierProc) _ANSI_ARGS_((ClientData clientData));
724 typedef void (Tcl_ServiceModeHookProc) _ANSI_ARGS_((int mode));
725 typedef ClientData (Tcl_InitNotifierProc) _ANSI_ARGS_((VOID));
726 typedef void (Tcl_FinalizeNotifierProc) _ANSI_ARGS_((ClientData clientData));
727 typedef void (Tcl_MainLoopProc) _ANSI_ARGS_((void));
728 
729 
730 /*
731  * The following structure represents a type of object, which is a
732  * particular internal representation for an object plus a set of
733  * procedures that provide standard operations on objects of that type.
734  */
735 
736 typedef struct Tcl_ObjType
737 {
738     char *name;			/* Name of the type, e.g. "int". */
739     Tcl_FreeInternalRepProc *freeIntRepProc;
740 				/* Called to free any storage for the type's
741 				 * internal rep. NULL if the internal rep
742 				 * does not need freeing. */
743     Tcl_DupInternalRepProc *dupIntRepProc;
744     				/* Called to create a new object as a copy
745 				 * of an existing object. */
746     Tcl_UpdateStringProc *updateStringProc;
747     				/* Called to update the string rep from the
748 				 * type's internal representation. */
749     Tcl_SetFromAnyProc *setFromAnyProc;
750     				/* Called to convert the object's internal
751 				 * rep to this type. Frees the internal rep
752 				 * of the old type. Returns TCL_ERROR on
753 				 * failure. */
754 }
755 Tcl_ObjType;
756 
757 
758 /*
759  * One of the following structures exists for each object in the Tcl
760  * system. An object stores a value as either a string, some internal
761  * representation, or both.
762  */
763 
764 #ifndef Tcl_Obj
765 #ifdef USE_TCL_STRUCT
766 struct Tcl_Obj {
767     int refCount;		/* When 0 the object will be freed. */
768     char *bytes;		/* This points to the first byte of the
769 				 * object's string representation. The array
770 				 * must be followed by a null byte (i.e., at
771 				 * offset length) but may also contain
772 				 * embedded null characters. The array's
773 				 * storage is allocated by ckalloc. NULL
774 				 * means the string rep is invalid and must
775 				 * be regenerated from the internal rep.
776 				 * Clients should use Tcl_GetStringFromObj
777 				 * or Tcl_GetString to get a pointer to the
778 				 * byte array as a readonly value. */
779     int length;			/* The number of bytes at *bytes, not
780 				 * including the terminating null. */
781     Tcl_ObjType *typePtr;	/* Denotes the object's type. Always
782 				 * corresponds to the type of the object's
783 				 * internal rep. NULL indicates the object
784 				 * has no internal rep (has no type). */
785     union {			/* The internal representation: */
786 	long longValue;		/*   - an long integer value */
787 	double doubleValue;	/*   - a double-precision floating value */
788 	VOID *otherValuePtr;	/*   - another, type-specific value */
789 	Tcl_WideInt wideValue;	/*   - a long long value */
790 	struct {		/*   - internal rep as two pointers */
791 	    VOID *ptr1;
792 	    VOID *ptr2;
793 	} twoPtrValue;
794     } internalRep;
795 };
796 
797 #define TclObjInternal(o)	(&((o)->internalRep))
798 #define TclObjGetType(o)	((o)->typePtr)
799 #define TclObjSetType(o,t)	((o)->typePtr = (t))
800 #define TclObjLength(o)		((o)->length)
801 
802 #endif
803 #endif
804 
805 #ifndef USE_TCL_STRUCT
806 typedef union  {		/* The internal representation: */
807     long longValue;		/*   - an long integer value */
808     double doubleValue;		/*   - a double-precision floating value */
809     VOID *otherValuePtr;	/*   - another, type-specific value */
810     struct {			/*   - internal rep as two pointers */
811         VOID *ptr1;
812         VOID *ptr2;
813     } twoPtrValue;
814 } Tcl_InternalRep;
815 #endif
816 
817 #ifndef TclObjGetType
818 EXTERN Tcl_ObjType *	TclObjGetType _ANSI_ARGS_((Tcl_Obj *objPtr));
819 #endif
820 #ifndef TclObjLength
821 EXTERN int		TclObjLength  _ANSI_ARGS_((Tcl_Obj *objPtr));
822 #endif
823 #ifndef TclObjSetType
824 EXTERN void		TclObjSetType _ANSI_ARGS_((Tcl_Obj *objPtr,Tcl_ObjType *newType));
825 #endif
826 #ifndef TclObjInternal
827 EXTERN Tcl_InternalRep *	TclObjInternal _ANSI_ARGS_((Tcl_Obj *objPtr));
828 #endif
829 
830 
831 /*
832  * Macros to increment and decrement a Tcl_Obj's reference count, and to
833  * test whether an object is shared (i.e. has reference count > 1).
834  * Note: clients should use Tcl_DecrRefCount() when they are finished using
835  * an object, and should never call TclFreeObj() directly. TclFreeObj() is
836  * only defined and made public in tcl.h to support Tcl_DecrRefCount's macro
837  * definition. Note also that Tcl_DecrRefCount() refers to the parameter
838  * "obj" twice. This means that you should avoid calling it with an
839  * expression that is expensive to compute or has side effects.
840  */
841 
842 EXTERN void		Tcl_IncrRefCount _ANSI_ARGS_((Tcl_Obj *objPtr));
843 EXTERN void		Tcl_DecrRefCount _ANSI_ARGS_((Tcl_Obj *objPtr));
844 EXTERN int		Tcl_IsShared _ANSI_ARGS_((Tcl_Obj *objPtr));
845 
846 #ifdef USE_TCL_STRUCT
847 #ifdef TCL_MEM_DEBUG
848 #   define Tcl_IncrRefCount(objPtr) \
849 	Tcl_DbIncrRefCount(objPtr, __FILE__, __LINE__)
850 #   define Tcl_DecrRefCount(objPtr) \
851 	Tcl_DbDecrRefCount(objPtr, __FILE__, __LINE__)
852 #   define Tcl_IsShared(objPtr) \
853 	Tcl_DbIsShared(objPtr, __FILE__, __LINE__)
854 #else
855 #   define Tcl_IncrRefCount(objPtr) \
856 	++(objPtr)->refCount
857 #   define Tcl_DecrRefCount(objPtr) \
858 	if (--(objPtr)->refCount <= 0) TclFreeObj(objPtr)
859 #   define Tcl_IsShared(objPtr) \
860 	((objPtr)->refCount > 1)
861 #endif
862 #endif
863 
864 /*
865  * Macros and definitions that help to debug the use of Tcl objects.
866  * When TCL_MEM_DEBUG is defined, the Tcl_New declarations are
867  * overridden to call debugging versions of the object creation procedures.
868  */
869 
870 #ifndef _LANG
871 #ifdef TCL_MEM_DEBUG
872 #  define Tcl_NewBooleanObj(val) \
873      Tcl_DbNewBooleanObj(val, __FILE__, __LINE__)
874 #  define Tcl_NewByteArrayObj(bytes, len) \
875      Tcl_DbNewByteArrayObj(bytes, len, __FILE__, __LINE__)
876 #  define Tcl_NewDoubleObj(val) \
877      Tcl_DbNewDoubleObj(val, __FILE__, __LINE__)
878 #  define Tcl_NewIntObj(val) \
879      Tcl_DbNewLongObj(val, __FILE__, __LINE__)
880 #  define Tcl_NewListObj(objc, objv) \
881      Tcl_DbNewListObj(objc, objv, __FILE__, __LINE__)
882 #  define Tcl_NewLongObj(val) \
883      Tcl_DbNewLongObj(val, __FILE__, __LINE__)
884 #  define Tcl_NewObj() \
885      Tcl_DbNewObj(__FILE__, __LINE__)
886 #  define Tcl_NewStringObj(bytes, len) \
887      Tcl_DbNewStringObj(bytes, len, __FILE__, __LINE__)
888 #  define Tcl_NewWideIntObj(val) \
889      Tcl_DbNewWideIntObj(val, __FILE__, __LINE__)
890 #endif /* TCL_MEM_DEBUG */
891 #endif
892 
893 
894 /*
895  * The following structure contains the state needed by
896  * Tcl_SaveResult.  No-one outside of Tcl should access any of these
897  * fields.  This structure is typically allocated on the stack.
898  */
899 typedef struct Tcl_SavedResult
900 #ifdef USE_TCL_STRUCT
901 {
902     char *result;
903     Tcl_FreeProc *freeProc;
904     Tcl_Obj *objResultPtr;
905     char *appendResult;
906     int appendAvl;
907     int appendUsed;
908     char resultSpace[TCL_RESULT_SIZE+1];
909 }
910 #endif
911 Tcl_SavedResult;
912 
913 
914 /*
915  * The following definitions support Tcl's namespace facility.
916  * Note: the first five fields must match exactly the fields in a
917  * Namespace structure (see tclInt.h).
918  */
919 
920 typedef struct Tcl_Namespace
921 #ifdef USE_TCL_STRUCT
922 {
923     char *name;                 /* The namespace's name within its parent
924 				 * namespace. This contains no ::'s. The
925 				 * name of the global namespace is ""
926 				 * although "::" is an synonym. */
927     char *fullName;             /* The namespace's fully qualified name.
928 				 * This starts with ::. */
929     ClientData clientData;      /* Arbitrary value associated with this
930 				 * namespace. */
931     Tcl_NamespaceDeleteProc* deleteProc;
932                                 /* Procedure invoked when deleting the
933 				 * namespace to, e.g., free clientData. */
934     struct Tcl_Namespace* parentPtr;
935                                 /* Points to the namespace that contains
936 				 * this one. NULL if this is the global
937 				 * namespace. */
938 }
939 #endif
940 Tcl_Namespace;
941 
942 
943 /*
944  * The following structure represents a call frame, or activation record.
945  * A call frame defines a naming context for a procedure call: its local
946  * scope (for local variables) and its namespace scope (used for non-local
947  * variables; often the global :: namespace). A call frame can also define
948  * the naming context for a namespace eval or namespace inscope command:
949  * the namespace in which the command's code should execute. The
950  * Tcl_CallFrame structures exist only while procedures or namespace
951  * eval/inscope's are being executed, and provide a Tcl call stack.
952  *
953  * A call frame is initialized and pushed using Tcl_PushCallFrame and
954  * popped using Tcl_PopCallFrame. Storage for a Tcl_CallFrame must be
955  * provided by the Tcl_PushCallFrame caller, and callers typically allocate
956  * them on the C call stack for efficiency. For this reason, Tcl_CallFrame
957  * is defined as a structure and not as an opaque token. However, most
958  * Tcl_CallFrame fields are hidden since applications should not access
959  * them directly; others are declared as "dummyX".
960  *
961  * WARNING!! The structure definition must be kept consistent with the
962  * CallFrame structure in tclInt.h. If you change one, change the other.
963  */
964 
965 typedef struct Tcl_CallFrame
966 #ifdef USE_TCL_STRUCT
967 {
968     Tcl_Namespace *nsPtr;
969     int dummy1;
970     int dummy2;
971     char *dummy3;
972     char *dummy4;
973     char *dummy5;
974     int dummy6;
975     char *dummy7;
976     char *dummy8;
977     int dummy9;
978     char* dummy10;
979 }
980 #endif
981 Tcl_CallFrame;
982 
983 
984 /*
985  * Information about commands that is returned by Tcl_GetCommandInfo and
986  * passed to Tcl_SetCommandInfo. objProc is an objc/objv object-based
987  * command procedure while proc is a traditional Tcl argc/argv
988  * string-based procedure. Tcl_CreateObjCommand and Tcl_CreateCommand
989  * ensure that both objProc and proc are non-NULL and can be called to
990  * execute the command. However, it may be faster to call one instead of
991  * the other. The member isNativeObjectProc is set to 1 if an
992  * object-based procedure was registered by Tcl_CreateObjCommand, and to
993  * 0 if a string-based procedure was registered by Tcl_CreateCommand.
994  * The other procedure is typically set to a compatibility wrapper that
995  * does string-to-object or object-to-string argument conversions then
996  * calls the other procedure.
997  */
998 
999 typedef struct Tcl_CmdInfo {
1000     int isNativeObjectProc;	 /* 1 if objProc was registered by a call to
1001 				  * Tcl_CreateObjCommand; 0 otherwise.
1002 				  * Tcl_SetCmdInfo does not modify this
1003 				  * field. */
1004     Tcl_ObjCmdProc *objProc;	 /* Command's object-based procedure. */
1005     ClientData objClientData;	 /* ClientData for object proc. */
1006     Tcl_CmdProc *proc;		 /* Command's string-based procedure. */
1007     ClientData clientData;	 /* ClientData for string proc. */
1008     Tcl_CmdDeleteProc *deleteProc;
1009                                  /* Procedure to call when command is
1010                                   * deleted. */
1011     ClientData deleteData;	 /* Value to pass to deleteProc (usually
1012 				  * the same as clientData). */
1013     Tcl_Namespace *namespacePtr; /* Points to the namespace that contains
1014 				  * this command. Note that Tcl_SetCmdInfo
1015 				  * will not change a command's namespace;
1016 				  * use Tcl_RenameCommand to do that. */
1017 
1018 } Tcl_CmdInfo;
1019 
1020 /*
1021  * The structure defined below is used to hold dynamic strings.  The only
1022  * field that clients should use is the string field, accessible via the
1023  * macro Tcl_DStringValue.
1024  */
1025 
1026 #ifndef Tcl_DString
1027 #define TCL_DSTRING_STATIC_SIZE 200
1028 #ifdef USE_TCL_STRUCT
1029 typedef struct Tcl_DString {
1030     char *string;		/* Points to beginning of string:  either
1031 				 * staticSpace below or a malloced array. */
1032     int length;			/* Number of non-NULL characters in the
1033 				 * string. */
1034     int spaceAvl;		/* Total number of bytes available for the
1035 				 * string and its terminating NULL char. */
1036     char staticSpace[TCL_DSTRING_STATIC_SIZE];
1037 				/* Space to use in common case where string
1038 				 * is small. */
1039 } Tcl_DString;
1040 #else
1041 typedef Tcl_Obj *Tcl_DString;
1042 #endif
1043 #endif
1044 
1045 #ifdef USE_TCL_STRUCT
1046 #define Tcl_DStringLength(dsPtr) ((dsPtr)->length)
1047 #define Tcl_DStringValue(dsPtr) ((dsPtr)->string)
1048 #endif
1049 #define Tcl_DStringTrunc Tcl_DStringSetLength
1050 
1051 /*
1052  * Definitions for the maximum number of digits of precision that may
1053  * be specified in the "tcl_precision" variable, and the number of
1054  * bytes of buffer space required by Tcl_PrintDouble.
1055  */
1056 #define TCL_MAX_PREC 17
1057 #define TCL_DOUBLE_SPACE (TCL_MAX_PREC+10)
1058 
1059 /*
1060  * Definition for a number of bytes of buffer space sufficient to hold the
1061  * string representation of an integer in base 10 (assuming the existence
1062  * of 64-bit integers).
1063  */
1064 #define TCL_INTEGER_SPACE	24
1065 
1066 /*
1067  * Flag that may be passed to Tcl_ConvertElement to force it not to
1068  * output braces (careful!  if you change this flag be sure to change
1069  * the definitions at the front of tclUtil.c).
1070  */
1071 #define TCL_DONT_USE_BRACES	1
1072 
1073 /*
1074  * Flag that may be passed to Tcl_GetIndexFromObj to force it to disallow
1075  * abbreviated strings.
1076  */
1077 #define TCL_EXACT	1
1078 
1079 /*
1080  * Flag values passed to Tcl_RecordAndEval and/or Tcl_EvalObj.
1081  * WARNING: these bit choices must not conflict with the bit choices
1082  * for evalFlag bits in tclInt.h!!
1083  */
1084 #define TCL_NO_EVAL		0x10000
1085 #define TCL_EVAL_GLOBAL		0x20000
1086 #define TCL_EVAL_DIRECT		0x40000
1087 #define TCL_EVAL_INVOKE	        0x80000
1088 
1089 /*
1090  * Special freeProc values that may be passed to Tcl_SetResult (see
1091  * the man page for details):
1092  */
1093 #define TCL_VOLATILE	((Tcl_FreeProc *) 1)
1094 #define TCL_STATIC	((Tcl_FreeProc *) 0)
1095 #define TCL_DYNAMIC	((Tcl_FreeProc *) 3)
1096 
1097 /*
1098  * Flag values passed to variable-related procedures.
1099  */
1100 #define TCL_GLOBAL_ONLY		 1
1101 #define TCL_NAMESPACE_ONLY	 2
1102 #define TCL_APPEND_VALUE	 4
1103 #define TCL_LIST_ELEMENT	 8
1104 #define TCL_TRACE_READS		 0x10
1105 #define TCL_TRACE_WRITES	 0x20
1106 #define TCL_TRACE_UNSETS	 0x40
1107 #define TCL_TRACE_DESTROYED	 0x80
1108 #define TCL_INTERP_DESTROYED	 0x100
1109 #define TCL_LEAVE_ERR_MSG	 0x200
1110 #define TCL_TRACE_ARRAY		 0x800
1111 #ifndef TCL_REMOVE_OBSOLETE_TRACES
1112 /* Required to support old variable/vdelete/vinfo traces */
1113 #define TCL_TRACE_OLD_STYLE	 0x1000
1114 #endif
1115 /* Indicate the semantics of the result of a trace */
1116 #define TCL_TRACE_RESULT_DYNAMIC 0x8000
1117 #define TCL_TRACE_RESULT_OBJECT  0x10000
1118 
1119 /*
1120  * Flag values passed to command-related procedures.
1121  */
1122 
1123 #define TCL_TRACE_RENAME 0x2000
1124 #define TCL_TRACE_DELETE 0x4000
1125 
1126 #define TCL_ALLOW_INLINE_COMPILATION 0x20000
1127 
1128 /*
1129  * Flag values passed to Tcl_CreateObjTrace, and used internally
1130  * by command execution traces.  Slots 4,8,16 and 32 are
1131  * used internally by execution traces (see tclCmdMZ.c)
1132  */
1133 #define TCL_TRACE_ENTER_EXEC		1
1134 #define TCL_TRACE_LEAVE_EXEC		2
1135 
1136 /*
1137  * The TCL_PARSE_PART1 flag is deprecated and has no effect.
1138  * The part1 is now always parsed whenever the part2 is NULL.
1139  * (This is to avoid a common error when converting code to
1140  *  use the new object based APIs and forgetting to give the
1141  *  flag)
1142  */
1143 #ifndef TCL_NO_DEPRECATED
1144 #   define TCL_PARSE_PART1      0x400
1145 #endif
1146 
1147 
1148 /*
1149  * Types for linked variables:
1150  */
1151 #define TCL_LINK_INT		1
1152 #define TCL_LINK_DOUBLE		2
1153 #define TCL_LINK_BOOLEAN	3
1154 #define TCL_LINK_STRING		4
1155 #define TCL_LINK_WIDE_INT	5
1156 #define TCL_LINK_READ_ONLY	0x80
1157 
1158 
1159 /*
1160  * Forward declarations of Tcl_HashTable and related types.
1161  */
1162 typedef struct Tcl_HashKeyType Tcl_HashKeyType;
1163 typedef struct Tcl_HashTable Tcl_HashTable;
1164 typedef struct Tcl_HashEntry Tcl_HashEntry;
1165 
1166 typedef unsigned int (Tcl_HashKeyProc) _ANSI_ARGS_((Tcl_HashTable *tablePtr,
1167 	VOID *keyPtr));
1168 typedef int (Tcl_CompareHashKeysProc) _ANSI_ARGS_((VOID *keyPtr,
1169 	Tcl_HashEntry *hPtr));
1170 typedef Tcl_HashEntry *(Tcl_AllocHashEntryProc) _ANSI_ARGS_((
1171 	Tcl_HashTable *tablePtr, VOID *keyPtr));
1172 typedef void (Tcl_FreeHashEntryProc) _ANSI_ARGS_((Tcl_HashEntry *hPtr));
1173 
1174 /*
1175  * This flag controls whether the hash table stores the hash of a key, or
1176  * recalculates it. There should be no reason for turning this flag off
1177  * as it is completely binary and source compatible unless you directly
1178  * access the bucketPtr member of the Tcl_HashTableEntry structure. This
1179  * member has been removed and the space used to store the hash value.
1180  */
1181 #ifndef TCL_HASH_KEY_STORE_HASH
1182 #   define TCL_HASH_KEY_STORE_HASH 1
1183 #endif
1184 
1185 /*
1186  * Structure definition for an entry in a hash table.  No-one outside
1187  * Tcl should access any of these fields directly;  use the macros
1188  * defined below.
1189  */
1190 
1191 struct Tcl_HashEntry {
1192     Tcl_HashEntry *nextPtr;		/* Pointer to next entry in this
1193 					 * hash bucket, or NULL for end of
1194 					 * chain. */
1195     Tcl_HashTable *tablePtr;		/* Pointer to table containing entry. */
1196 #if TCL_HASH_KEY_STORE_HASH
1197 #   if TCL_PRESERVE_BINARY_COMPATABILITY
1198     VOID *hash;				/* Hash value, stored as pointer to
1199 					 * ensure that the offsets of the
1200 					 * fields in this structure are not
1201 					 * changed. */
1202 #   else
1203     unsigned int hash;			/* Hash value. */
1204 #   endif
1205 #else
1206     Tcl_HashEntry **bucketPtr;		/* Pointer to bucket that points to
1207 					 * first entry in this entry's chain:
1208 					 * used for deleting the entry. */
1209 #endif
1210     ClientData clientData;		/* Application stores something here
1211 					 * with Tcl_SetHashValue. */
1212     union {				/* Key has one of these forms: */
1213 	char *oneWordValue;		/* One-word value for key. */
1214         Tcl_Obj *objPtr;		/* Tcl_Obj * key value. */
1215 	int words[1];			/* Multiple integer words for key.
1216 					 * The actual size will be as large
1217 					 * as necessary for this table's
1218 					 * keys. */
1219 	char string[4];			/* String for key.  The actual size
1220 					 * will be as large as needed to hold
1221 					 * the key. */
1222     } key;				/* MUST BE LAST FIELD IN RECORD!! */
1223 };
1224 
1225 /*
1226  * Flags used in Tcl_HashKeyType.
1227  *
1228  * TCL_HASH_KEY_RANDOMIZE_HASH:
1229  *				There are some things, pointers for example
1230  *				which don't hash well because they do not use
1231  *				the lower bits. If this flag is set then the
1232  *				hash table will attempt to rectify this by
1233  *				randomising the bits and then using the upper
1234  *				N bits as the index into the table.
1235  */
1236 #define TCL_HASH_KEY_RANDOMIZE_HASH 0x1
1237 
1238 /*
1239  * Structure definition for the methods associated with a hash table
1240  * key type.
1241  */
1242 #define TCL_HASH_KEY_TYPE_VERSION 1
1243 struct Tcl_HashKeyType {
1244     int version;		/* Version of the table. If this structure is
1245 				 * extended in future then the version can be
1246 				 * used to distinguish between different
1247 				 * structures.
1248 				 */
1249 
1250     int flags;			/* Flags, see above for details. */
1251 
1252     /* Calculates a hash value for the key. If this is NULL then the pointer
1253      * itself is used as a hash value.
1254      */
1255     Tcl_HashKeyProc *hashKeyProc;
1256 
1257     /* Compares two keys and returns zero if they do not match, and non-zero
1258      * if they do. If this is NULL then the pointers are compared.
1259      */
1260     Tcl_CompareHashKeysProc *compareKeysProc;
1261 
1262     /* Called to allocate memory for a new entry, i.e. if the key is a
1263      * string then this could allocate a single block which contains enough
1264      * space for both the entry and the string. Only the key field of the
1265      * allocated Tcl_HashEntry structure needs to be filled in. If something
1266      * else needs to be done to the key, i.e. incrementing a reference count
1267      * then that should be done by this function. If this is NULL then Tcl_Alloc
1268      * is used to allocate enough space for a Tcl_HashEntry and the key pointer
1269      * is assigned to key.oneWordValue.
1270      */
1271     Tcl_AllocHashEntryProc *allocEntryProc;
1272 
1273     /* Called to free memory associated with an entry. If something else needs
1274      * to be done to the key, i.e. decrementing a reference count then that
1275      * should be done by this function. If this is NULL then Tcl_Free is used
1276      * to free the Tcl_HashEntry.
1277      */
1278     Tcl_FreeHashEntryProc *freeEntryProc;
1279 };
1280 
1281 /*
1282  * Structure definition for a hash table.  Must be in tcl.h so clients
1283  * can allocate space for these structures, but clients should never
1284  * access any fields in this structure.
1285  */
1286 
1287 #define TCL_SMALL_HASH_TABLE 4
1288 struct Tcl_HashTable {
1289     Tcl_HashEntry **buckets;		/* Pointer to bucket array.  Each
1290 					 * element points to first entry in
1291 					 * bucket's hash chain, or NULL. */
1292     Tcl_HashEntry *staticBuckets[TCL_SMALL_HASH_TABLE];
1293 					/* Bucket array used for small tables
1294 					 * (to avoid mallocs and frees). */
1295     int numBuckets;			/* Total number of buckets allocated
1296 					 * at **bucketPtr. */
1297     int numEntries;			/* Total number of entries present
1298 					 * in table. */
1299     int rebuildSize;			/* Enlarge table when numEntries gets
1300 					 * to be this large. */
1301     int downShift;			/* Shift count used in hashing
1302 					 * function.  Designed to use high-
1303 					 * order bits of randomized keys. */
1304     int mask;				/* Mask value used in hashing
1305 					 * function. */
1306     int keyType;			/* Type of keys used in this table.
1307 					 * It's either TCL_CUSTOM_KEYS,
1308 					 * TCL_STRING_KEYS, TCL_ONE_WORD_KEYS,
1309 					 * or an integer giving the number of
1310 					 * ints that is the size of the key.
1311 					 */
1312 #if TCL_PRESERVE_BINARY_COMPATABILITY
1313     Tcl_HashEntry *(*findProc) _ANSI_ARGS_((Tcl_HashTable *tablePtr,
1314 	    CONST char *key));
1315     Tcl_HashEntry *(*createProc) _ANSI_ARGS_((Tcl_HashTable *tablePtr,
1316 	    CONST char *key, int *newPtr));
1317 #endif
1318     Tcl_HashKeyType *typePtr;		/* Type of the keys used in the
1319 					 * Tcl_HashTable. */
1320 };
1321 
1322 /*
1323  * Structure definition for information used to keep track of searches
1324  * through hash tables:
1325  */
1326 
1327 typedef struct Tcl_HashSearch {
1328     Tcl_HashTable *tablePtr;		/* Table being searched. */
1329     int nextIndex;			/* Index of next bucket to be
1330 					 * enumerated after present one. */
1331     Tcl_HashEntry *nextEntryPtr;	/* Next entry to be enumerated in the
1332 					 * the current bucket. */
1333 } Tcl_HashSearch;
1334 
1335 /*
1336  * Acceptable key types for hash tables:
1337  *
1338  * TCL_STRING_KEYS:		The keys are strings, they are copied into
1339  *				the entry.
1340  * TCL_ONE_WORD_KEYS:		The keys are pointers, the pointer is stored
1341  *				in the entry.
1342  * TCL_CUSTOM_TYPE_KEYS:	The keys are arbitrary types which are copied
1343  *				into the entry.
1344  * TCL_CUSTOM_PTR_KEYS:		The keys are pointers to arbitrary types, the
1345  *				pointer is stored in the entry.
1346  *
1347  * While maintaining binary compatability the above have to be distinct
1348  * values as they are used to differentiate between old versions of the
1349  * hash table which don't have a typePtr and new ones which do. Once binary
1350  * compatability is discarded in favour of making more wide spread changes
1351  * TCL_STRING_KEYS can be the same as TCL_CUSTOM_TYPE_KEYS, and
1352  * TCL_ONE_WORD_KEYS can be the same as TCL_CUSTOM_PTR_KEYS because they
1353  * simply determine how the key is accessed from the entry and not the
1354  * behaviour.
1355  */
1356 
1357 #define TCL_STRING_KEYS		0
1358 #define TCL_ONE_WORD_KEYS	1
1359 
1360 #if TCL_PRESERVE_BINARY_COMPATABILITY
1361 #   define TCL_CUSTOM_TYPE_KEYS		-2
1362 #   define TCL_CUSTOM_PTR_KEYS		-1
1363 #else
1364 #   define TCL_CUSTOM_TYPE_KEYS		TCL_STRING_KEYS
1365 #   define TCL_CUSTOM_PTR_KEYS		TCL_ONE_WORD_KEYS
1366 #endif
1367 
1368 /*
1369  * Macros for clients to use to access fields of hash entries:
1370  */
1371 
1372 #define Tcl_GetHashValue(h) ((h)->clientData)
1373 #define Tcl_SetHashValue(h, value) ((h)->clientData = (ClientData) (value))
1374 #if TCL_PRESERVE_BINARY_COMPATABILITY
1375 #   define Tcl_GetHashKey(tablePtr, h) \
1376 	((char *) (((tablePtr)->keyType == TCL_ONE_WORD_KEYS || \
1377 		    (tablePtr)->keyType == TCL_CUSTOM_PTR_KEYS) \
1378 		   ? (h)->key.oneWordValue \
1379 		   : (h)->key.string))
1380 #else
1381 #   define Tcl_GetHashKey(tablePtr, h) \
1382 	((char *) (((tablePtr)->keyType == TCL_ONE_WORD_KEYS) \
1383 		   ? (h)->key.oneWordValue \
1384 		   : (h)->key.string))
1385 #endif
1386 
1387 /*
1388  * Macros to use for clients to use to invoke find and create procedures
1389  * for hash tables:
1390  */
1391 
1392 #if TCL_PRESERVE_BINARY_COMPATABILITY
1393 #   define Tcl_FindHashEntry(tablePtr, key) \
1394 	(*((tablePtr)->findProc))(tablePtr, key)
1395 #   define Tcl_CreateHashEntry(tablePtr, key, newPtr) \
1396 	(*((tablePtr)->createProc))(tablePtr, key, newPtr)
1397 #else /* !TCL_PRESERVE_BINARY_COMPATABILITY */
1398 /*
1399  * Macro to use new extended version of Tcl_InitHashTable.
1400  */
1401 #   define Tcl_InitHashTable(tablePtr, keyType) \
1402 	Tcl_InitHashTableEx(tablePtr, keyType, NULL)
1403 #endif /* TCL_PRESERVE_BINARY_COMPATABILITY */
1404 
1405 
1406 /*
1407  * Flag values to pass to Tcl_DoOneEvent to disable searches
1408  * for some kinds of events:
1409  */
1410 #define TCL_DONT_WAIT		(1<<1)
1411 #define TCL_WINDOW_EVENTS	(1<<2)
1412 #define TCL_FILE_EVENTS		(1<<3)
1413 #define TCL_TIMER_EVENTS	(1<<4)
1414 #define TCL_IDLE_EVENTS		(1<<5)	/* WAS 0x10 ???? */
1415 #define TCL_ALL_EVENTS		(~TCL_DONT_WAIT)
1416 
1417 /*
1418  * The following structure defines a generic event for the Tcl event
1419  * system.  These are the things that are queued in calls to Tcl_QueueEvent
1420  * and serviced later by Tcl_DoOneEvent.  There can be many different
1421  * kinds of events with different fields, corresponding to window events,
1422  * timer events, etc.  The structure for a particular event consists of
1423  * a Tcl_Event header followed by additional information specific to that
1424  * event.
1425  */
1426 struct Tcl_Event {
1427     Tcl_EventProc *proc;	/* Procedure to call to service this event. */
1428     struct Tcl_Event *nextPtr;	/* Next in list of pending events, or NULL. */
1429 };
1430 
1431 /*
1432  * Positions to pass to Tcl_QueueEvent:
1433  */
1434 typedef enum {
1435     TCL_QUEUE_TAIL, TCL_QUEUE_HEAD, TCL_QUEUE_MARK
1436 } Tcl_QueuePosition;
1437 
1438 /*
1439  * Values to pass to Tcl_SetServiceMode to specify the behavior of notifier
1440  * event routines.
1441  */
1442 #define TCL_SERVICE_NONE 0
1443 #define TCL_SERVICE_ALL 1
1444 
1445 
1446 /*
1447  * The following structure keeps is used to hold a time value, either as
1448  * an absolute time (the number of seconds from the epoch) or as an
1449  * elapsed time. On Unix systems the epoch is Midnight Jan 1, 1970 GMT.
1450  * On Macintosh systems the epoch is Midnight Jan 1, 1904 GMT.
1451  */
1452 typedef struct Tcl_Time {
1453     long sec;			/* Seconds. */
1454     long usec;			/* Microseconds. */
1455 } Tcl_Time;
1456 
1457 typedef void (Tcl_SetTimerProc) _ANSI_ARGS_((Tcl_Time *timePtr));
1458 typedef int (Tcl_WaitForEventProc) _ANSI_ARGS_((Tcl_Time *timePtr));
1459 
1460 
1461 /*
1462  * Bits to pass to Tcl_CreateFileHandler and Tcl_CreateChannelHandler
1463  * to indicate what sorts of events are of interest:
1464  */
1465 #define TCL_READABLE	(1<<1)
1466 #define TCL_WRITABLE	(1<<2)
1467 #define TCL_EXCEPTION	(1<<3)
1468 
1469 /*
1470  * Flag values to pass to Tcl_OpenCommandChannel to indicate the
1471  * disposition of the stdio handles.  TCL_STDIN, TCL_STDOUT, TCL_STDERR,
1472  * are also used in Tcl_GetStdChannel.
1473  */
1474 #define TCL_STDIN		(1<<1)
1475 #define TCL_STDOUT		(1<<2)
1476 #define TCL_STDERR		(1<<3)
1477 #define TCL_ENFORCE_MODE	(1<<4)
1478 
1479 /*
1480  * Bits passed to Tcl_DriverClose2Proc to indicate which side of a channel
1481  * should be closed.
1482  */
1483 #define TCL_CLOSE_READ		(1<<1)
1484 #define TCL_CLOSE_WRITE	(1<<2)
1485 
1486 /*
1487  * Value to use as the closeProc for a channel that supports the
1488  * close2Proc interface.
1489  */
1490 #define TCL_CLOSE2PROC	((Tcl_DriverCloseProc *)1)
1491 
1492 /*
1493  * Channel version tag.  This was introduced in 8.3.2/8.4.
1494  */
1495 #define TCL_CHANNEL_VERSION_1	((Tcl_ChannelTypeVersion) 0x1)
1496 #define TCL_CHANNEL_VERSION_2	((Tcl_ChannelTypeVersion) 0x2)
1497 #define TCL_CHANNEL_VERSION_3	((Tcl_ChannelTypeVersion) 0x3)
1498 
1499 /*
1500  * Typedefs for the various operations in a channel type:
1501  */
1502 typedef int	(Tcl_DriverBlockModeProc) _ANSI_ARGS_((
1503 		    ClientData instanceData, int mode));
1504 typedef int	(Tcl_DriverCloseProc) _ANSI_ARGS_((ClientData instanceData,
1505 		    Tcl_Interp *interp));
1506 typedef int	(Tcl_DriverClose2Proc) _ANSI_ARGS_((ClientData instanceData,
1507 		    Tcl_Interp *interp, int flags));
1508 typedef int	(Tcl_DriverInputProc) _ANSI_ARGS_((ClientData instanceData,
1509 		    char *buf, int toRead, int *errorCodePtr));
1510 typedef int	(Tcl_DriverOutputProc) _ANSI_ARGS_((ClientData instanceData,
1511 		    CONST84 char *buf, int toWrite, int *errorCodePtr));
1512 typedef int	(Tcl_DriverSeekProc) _ANSI_ARGS_((ClientData instanceData,
1513 		    long offset, int mode, int *errorCodePtr));
1514 typedef int	(Tcl_DriverSetOptionProc) _ANSI_ARGS_((
1515 		    ClientData instanceData, Tcl_Interp *interp,
1516 	            CONST char *optionName, CONST char *value));
1517 typedef int	(Tcl_DriverGetOptionProc) _ANSI_ARGS_((
1518 		    ClientData instanceData, Tcl_Interp *interp,
1519 		    CONST84 char *optionName, Tcl_DString *dsPtr));
1520 typedef void	(Tcl_DriverWatchProc) _ANSI_ARGS_((
1521 		    ClientData instanceData, int mask));
1522 typedef int	(Tcl_DriverGetHandleProc) _ANSI_ARGS_((
1523 		    ClientData instanceData, int direction,
1524 		    ClientData *handlePtr));
1525 typedef int	(Tcl_DriverFlushProc) _ANSI_ARGS_((
1526 		    ClientData instanceData));
1527 typedef int	(Tcl_DriverHandlerProc) _ANSI_ARGS_((
1528 		    ClientData instanceData, int interestMask));
1529 typedef Tcl_WideInt (Tcl_DriverWideSeekProc) _ANSI_ARGS_((
1530 		    ClientData instanceData, Tcl_WideInt offset,
1531 		    int mode, int *errorCodePtr));
1532 
1533 
1534 /*
1535  * The following declarations either map ckalloc and ckfree to
1536  * malloc and free, or they map them to procedures with all sorts
1537  * of debugging hooks defined in tclCkalloc.c.
1538  */
1539 #ifdef TCL_MEM_DEBUG
1540 
1541 #   define ckalloc(x) Tcl_DbCkalloc(x, __FILE__, __LINE__)
1542 #   define ckfree(x)  Tcl_DbCkfree(x, __FILE__, __LINE__)
1543 #   define ckrealloc(x,y) Tcl_DbCkrealloc((x), (y),__FILE__, __LINE__)
1544 #   define attemptckalloc(x) Tcl_AttemptDbCkalloc(x, __FILE__, __LINE__)
1545 #   define attemptckrealloc(x,y) Tcl_AttemptDbCkrealloc((x), (y), __FILE__, __LINE__)
1546 #else /* !TCL_MEM_DEBUG */
1547 
1548 /*
1549  * If we are not using the debugging allocator, we should call the
1550  * Tcl_Alloc, et al. routines in order to guarantee that every module
1551  * is using the same memory allocator both inside and outside of the
1552  * Tcl library.
1553  */
1554 #   define ckalloc(x) Tcl_Alloc(x)
1555 #   define ckfree(x) Tcl_Free(x)
1556 #   define ckrealloc(x,y) Tcl_Realloc(x,y)
1557 #   define attemptckalloc(x) Tcl_AttemptAlloc(x)
1558 #   define attemptckrealloc(x,y) Tcl_AttemptRealloc(x,y)
1559 #   define Tcl_InitMemory(x)
1560 #   define Tcl_DumpActiveMemory(x)
1561 #   define Tcl_ValidateAllMemory(x,y)
1562 
1563 #endif /* !TCL_MEM_DEBUG */
1564 
1565 /*
1566  * struct Tcl_ChannelType:
1567  *
1568  * One such structure exists for each type (kind) of channel.
1569  * It collects together in one place all the functions that are
1570  * part of the specific channel type.
1571  *
1572  * It is recommend that the Tcl_Channel* functions are used to access
1573  * elements of this structure, instead of direct accessing.
1574  */
1575 typedef struct Tcl_ChannelType
1576 #ifdef USE_TCL_STRUCT
1577 {
1578     char *typeName;			/* The name of the channel type in Tcl
1579                                          * commands. This storage is owned by
1580                                          * channel type. */
1581     Tcl_ChannelTypeVersion version;	/* Version of the channel type. */
1582     Tcl_DriverCloseProc *closeProc;	/* Procedure to call to close the
1583 					 * channel, or TCL_CLOSE2PROC if the
1584 					 * close2Proc should be used
1585 					 * instead. */
1586     Tcl_DriverInputProc *inputProc;	/* Procedure to call for input
1587 					 * on channel. */
1588     Tcl_DriverOutputProc *outputProc;	/* Procedure to call for output
1589 					 * on channel. */
1590     Tcl_DriverSeekProc *seekProc;	/* Procedure to call to seek
1591 					 * on the channel. May be NULL. */
1592     Tcl_DriverSetOptionProc *setOptionProc;
1593 					/* Set an option on a channel. */
1594     Tcl_DriverGetOptionProc *getOptionProc;
1595 					/* Get an option from a channel. */
1596     Tcl_DriverWatchProc *watchProc;	/* Set up the notifier to watch
1597 					 * for events on this channel. */
1598     Tcl_DriverGetHandleProc *getHandleProc;
1599 					/* Get an OS handle from the channel
1600 					 * or NULL if not supported. */
1601     Tcl_DriverClose2Proc *close2Proc;	/* Procedure to call to close the
1602 					 * channel if the device supports
1603 					 * closing the read & write sides
1604 					 * independently. */
1605     Tcl_DriverBlockModeProc *blockModeProc;
1606 					/* Set blocking mode for the
1607 					 * raw channel. May be NULL. */
1608     /*
1609      * Only valid in TCL_CHANNEL_VERSION_2 channels or later
1610      */
1611     Tcl_DriverFlushProc *flushProc;	/* Procedure to call to flush a
1612 					 * channel. May be NULL. */
1613     Tcl_DriverHandlerProc *handlerProc;	/* Procedure to call to handle a
1614 					 * channel event.  This will be passed
1615 					 * up the stacked channel chain. */
1616     /*
1617      * Only valid in TCL_CHANNEL_VERSION_3 channels or later
1618      */
1619     Tcl_DriverWideSeekProc *wideSeekProc;
1620 					/* Procedure to call to seek
1621 					 * on the channel which can
1622 					 * handle 64-bit offsets. May be
1623 					 * NULL, and must be NULL if
1624 					 * seekProc is NULL. */
1625 }
1626 #endif
1627 Tcl_ChannelType;
1628 
1629 /*
1630  * The following flags determine whether the blockModeProc above should
1631  * set the channel into blocking or nonblocking mode. They are passed
1632  * as arguments to the blockModeProc procedure in the above structure.
1633  */
1634 #define TCL_MODE_BLOCKING 0		/* Put channel into blocking mode. */
1635 #define TCL_MODE_NONBLOCKING 1		/* Put channel into nonblocking
1636 					 * mode. */
1637 
1638 /*
1639  * Enum for different types of file paths.
1640  */
1641 typedef enum Tcl_PathType {
1642     TCL_PATH_ABSOLUTE,
1643     TCL_PATH_RELATIVE,
1644     TCL_PATH_VOLUME_RELATIVE
1645 } Tcl_PathType;
1646 
1647 
1648 /*
1649  * The following structure is used to pass glob type data amongst
1650  * the various glob routines and Tcl_FSMatchInDirectory.
1651  */
1652 typedef struct Tcl_GlobTypeData {
1653     /* Corresponds to bcdpfls as in 'find -t' */
1654     int type;
1655     /* Corresponds to file permissions */
1656     int perm;
1657     /* Acceptable mac type */
1658     Tcl_Obj* macType;
1659     /* Acceptable mac creator */
1660     Tcl_Obj* macCreator;
1661 } Tcl_GlobTypeData;
1662 
1663 /*
1664  * type and permission definitions for glob command
1665  */
1666 #define TCL_GLOB_TYPE_BLOCK		(1<<0)
1667 #define TCL_GLOB_TYPE_CHAR		(1<<1)
1668 #define TCL_GLOB_TYPE_DIR		(1<<2)
1669 #define TCL_GLOB_TYPE_PIPE		(1<<3)
1670 #define TCL_GLOB_TYPE_FILE		(1<<4)
1671 #define TCL_GLOB_TYPE_LINK		(1<<5)
1672 #define TCL_GLOB_TYPE_SOCK		(1<<6)
1673 #define TCL_GLOB_TYPE_MOUNT		(1<<7)
1674 
1675 #define TCL_GLOB_PERM_RONLY		(1<<0)
1676 #define TCL_GLOB_PERM_HIDDEN		(1<<1)
1677 #define TCL_GLOB_PERM_R			(1<<2)
1678 #define TCL_GLOB_PERM_W			(1<<3)
1679 #define TCL_GLOB_PERM_X			(1<<4)
1680 
1681 
1682 /*
1683  * Typedefs for the various filesystem operations:
1684  */
1685 typedef int (Tcl_FSStatProc) _ANSI_ARGS_((Tcl_Obj *pathPtr, Tcl_StatBuf *buf));
1686 typedef int (Tcl_FSAccessProc) _ANSI_ARGS_((Tcl_Obj *pathPtr, int mode));
1687 typedef Tcl_Channel (Tcl_FSOpenFileChannelProc)
1688 	_ANSI_ARGS_((Tcl_Interp *interp, Tcl_Obj *pathPtr,
1689 	int mode, int permissions));
1690 typedef int (Tcl_FSMatchInDirectoryProc) _ANSI_ARGS_((Tcl_Interp* interp,
1691 	Tcl_Obj *result, Tcl_Obj *pathPtr, CONST char *pattern,
1692 	Tcl_GlobTypeData * types));
1693 typedef Tcl_Obj* (Tcl_FSGetCwdProc) _ANSI_ARGS_((Tcl_Interp *interp));
1694 typedef int (Tcl_FSChdirProc) _ANSI_ARGS_((Tcl_Obj *pathPtr));
1695 typedef int (Tcl_FSLstatProc) _ANSI_ARGS_((Tcl_Obj *pathPtr,
1696 					   Tcl_StatBuf *buf));
1697 typedef int (Tcl_FSCreateDirectoryProc) _ANSI_ARGS_((Tcl_Obj *pathPtr));
1698 typedef int (Tcl_FSDeleteFileProc) _ANSI_ARGS_((Tcl_Obj *pathPtr));
1699 typedef int (Tcl_FSCopyDirectoryProc) _ANSI_ARGS_((Tcl_Obj *srcPathPtr,
1700 	   Tcl_Obj *destPathPtr, Tcl_Obj **errorPtr));
1701 typedef int (Tcl_FSCopyFileProc) _ANSI_ARGS_((Tcl_Obj *srcPathPtr,
1702 			    Tcl_Obj *destPathPtr));
1703 typedef int (Tcl_FSRemoveDirectoryProc) _ANSI_ARGS_((Tcl_Obj *pathPtr,
1704 			    int recursive, Tcl_Obj **errorPtr));
1705 typedef int (Tcl_FSRenameFileProc) _ANSI_ARGS_((Tcl_Obj *srcPathPtr,
1706 			    Tcl_Obj *destPathPtr));
1707 typedef void (Tcl_FSUnloadFileProc) _ANSI_ARGS_((Tcl_LoadHandle loadHandle));
1708 typedef Tcl_Obj* (Tcl_FSListVolumesProc) _ANSI_ARGS_((void));
1709 /* We have to declare the utime structure here. */
1710 struct utimbuf;
1711 typedef int (Tcl_FSUtimeProc) _ANSI_ARGS_((Tcl_Obj *pathPtr,
1712 					   struct utimbuf *tval));
1713 typedef int (Tcl_FSNormalizePathProc) _ANSI_ARGS_((Tcl_Interp *interp,
1714 			 Tcl_Obj *pathPtr, int nextCheckpoint));
1715 typedef int (Tcl_FSFileAttrsGetProc) _ANSI_ARGS_((Tcl_Interp *interp,
1716 			    int index, Tcl_Obj *pathPtr,
1717 			    Tcl_Obj **objPtrRef));
1718 typedef CONST char** (Tcl_FSFileAttrStringsProc) _ANSI_ARGS_((Tcl_Obj *pathPtr,
1719 			    Tcl_Obj** objPtrRef));
1720 typedef int (Tcl_FSFileAttrsSetProc) _ANSI_ARGS_((Tcl_Interp *interp,
1721 			    int index, Tcl_Obj *pathPtr,
1722 			    Tcl_Obj *objPtr));
1723 typedef Tcl_Obj* (Tcl_FSLinkProc) _ANSI_ARGS_((Tcl_Obj *pathPtr,
1724 					       Tcl_Obj *toPtr, int linkType));
1725 typedef int (Tcl_FSLoadFileProc) _ANSI_ARGS_((Tcl_Interp * interp,
1726 			    Tcl_Obj *pathPtr,
1727 			    Tcl_LoadHandle *handlePtr,
1728 			    Tcl_FSUnloadFileProc **unloadProcPtr));
1729 typedef int (Tcl_FSPathInFilesystemProc) _ANSI_ARGS_((Tcl_Obj *pathPtr,
1730 			    ClientData *clientDataPtr));
1731 typedef Tcl_Obj* (Tcl_FSFilesystemPathTypeProc)
1732 			    _ANSI_ARGS_((Tcl_Obj *pathPtr));
1733 typedef Tcl_Obj* (Tcl_FSFilesystemSeparatorProc)
1734 			    _ANSI_ARGS_((Tcl_Obj *pathPtr));
1735 typedef void (Tcl_FSFreeInternalRepProc) _ANSI_ARGS_((ClientData clientData));
1736 typedef ClientData (Tcl_FSDupInternalRepProc)
1737 			    _ANSI_ARGS_((ClientData clientData));
1738 typedef Tcl_Obj* (Tcl_FSInternalToNormalizedProc)
1739 			    _ANSI_ARGS_((ClientData clientData));
1740 typedef ClientData (Tcl_FSCreateInternalRepProc) _ANSI_ARGS_((Tcl_Obj *pathPtr));
1741 
1742 typedef struct Tcl_FSVersion_ *Tcl_FSVersion;
1743 
1744 /*
1745  *----------------------------------------------------------------
1746  * Data structures related to hooking into the filesystem
1747  *----------------------------------------------------------------
1748  */
1749 
1750 /*
1751  * Filesystem version tag.  This was introduced in 8.4.
1752  */
1753 #define TCL_FILESYSTEM_VERSION_1	((Tcl_FSVersion) 0x1)
1754 
1755 /*
1756  * struct Tcl_Filesystem:
1757  *
1758  * One such structure exists for each type (kind) of filesystem.
1759  * It collects together in one place all the functions that are
1760  * part of the specific filesystem.  Tcl always accesses the
1761  * filesystem through one of these structures.
1762  *
1763  * Not all entries need be non-NULL; any which are NULL are simply
1764  * ignored.  However, a complete filesystem should provide all of
1765  * these functions.  The explanations in the structure show
1766  * the importance of each function.
1767  */
1768 
1769 typedef struct Tcl_Filesystem {
1770     CONST char *typeName;   /* The name of the filesystem. */
1771     int structureLength;    /* Length of this structure, so future
1772 			     * binary compatibility can be assured. */
1773     Tcl_FSVersion version;
1774 			    /* Version of the filesystem type. */
1775     Tcl_FSPathInFilesystemProc *pathInFilesystemProc;
1776 			    /* Function to check whether a path is in
1777 			     * this filesystem.  This is the most
1778 			     * important filesystem procedure. */
1779     Tcl_FSDupInternalRepProc *dupInternalRepProc;
1780 			    /* Function to duplicate internal fs rep.  May
1781 			     * be NULL (but then fs is less efficient). */
1782     Tcl_FSFreeInternalRepProc *freeInternalRepProc;
1783 			    /* Function to free internal fs rep.  Must
1784 			     * be implemented, if internal representations
1785 			     * need freeing, otherwise it can be NULL. */
1786     Tcl_FSInternalToNormalizedProc *internalToNormalizedProc;
1787 			    /* Function to convert internal representation
1788 			     * to a normalized path.  Only required if
1789 			     * the fs creates pure path objects with no
1790 			     * string/path representation. */
1791     Tcl_FSCreateInternalRepProc *createInternalRepProc;
1792 			    /* Function to create a filesystem-specific
1793 			     * internal representation.  May be NULL
1794 			     * if paths have no internal representation,
1795 			     * or if the Tcl_FSPathInFilesystemProc
1796 			     * for this filesystem always immediately
1797 			     * creates an internal representation for
1798 			     * paths it accepts. */
1799     Tcl_FSNormalizePathProc *normalizePathProc;
1800 			    /* Function to normalize a path.  Should
1801 			     * be implemented for all filesystems
1802 			     * which can have multiple string
1803 			     * representations for the same path
1804 			     * object. */
1805     Tcl_FSFilesystemPathTypeProc *filesystemPathTypeProc;
1806 			    /* Function to determine the type of a
1807 			     * path in this filesystem.  May be NULL. */
1808     Tcl_FSFilesystemSeparatorProc *filesystemSeparatorProc;
1809 			    /* Function to return the separator
1810 			     * character(s) for this filesystem.  Must
1811 			     * be implemented. */
1812     Tcl_FSStatProc *statProc;
1813 			    /*
1814 			     * Function to process a 'Tcl_FSStat()'
1815 			     * call.  Must be implemented for any
1816 			     * reasonable filesystem.
1817 			     */
1818     Tcl_FSAccessProc *accessProc;
1819 			    /*
1820 			     * Function to process a 'Tcl_FSAccess()'
1821 			     * call.  Must be implemented for any
1822 			     * reasonable filesystem.
1823 			     */
1824     Tcl_FSOpenFileChannelProc *openFileChannelProc;
1825 			    /*
1826 			     * Function to process a
1827 			     * 'Tcl_FSOpenFileChannel()' call.  Must be
1828 			     * implemented for any reasonable
1829 			     * filesystem.
1830 			     */
1831     Tcl_FSMatchInDirectoryProc *matchInDirectoryProc;
1832 			    /* Function to process a
1833 			     * 'Tcl_FSMatchInDirectory()'.  If not
1834 			     * implemented, then glob and recursive
1835 			     * copy functionality will be lacking in
1836 			     * the filesystem. */
1837     Tcl_FSUtimeProc *utimeProc;
1838 			    /* Function to process a
1839 			     * 'Tcl_FSUtime()' call.  Required to
1840 			     * allow setting (not reading) of times
1841 			     * with 'file mtime', 'file atime' and
1842 			     * the open-r/open-w/fcopy implementation
1843 			     * of 'file copy'. */
1844     Tcl_FSLinkProc *linkProc;
1845 			    /* Function to process a
1846 			     * 'Tcl_FSLink()' call.  Should be
1847 			     * implemented only if the filesystem supports
1848 			     * links (reading or creating). */
1849     Tcl_FSListVolumesProc *listVolumesProc;
1850 			    /* Function to list any filesystem volumes
1851 			     * added by this filesystem.  Should be
1852 			     * implemented only if the filesystem adds
1853 			     * volumes at the head of the filesystem. */
1854     Tcl_FSFileAttrStringsProc *fileAttrStringsProc;
1855 			    /* Function to list all attributes strings
1856 			     * which are valid for this filesystem.
1857 			     * If not implemented the filesystem will
1858 			     * not support the 'file attributes' command.
1859 			     * This allows arbitrary additional information
1860 			     * to be attached to files in the filesystem. */
1861     Tcl_FSFileAttrsGetProc *fileAttrsGetProc;
1862 			    /* Function to process a
1863 			     * 'Tcl_FSFileAttrsGet()' call, used by
1864 			     * 'file attributes'. */
1865     Tcl_FSFileAttrsSetProc *fileAttrsSetProc;
1866 			    /* Function to process a
1867 			     * 'Tcl_FSFileAttrsSet()' call, used by
1868 			     * 'file attributes'.  */
1869     Tcl_FSCreateDirectoryProc *createDirectoryProc;
1870 			    /* Function to process a
1871 			     * 'Tcl_FSCreateDirectory()' call. Should
1872 			     * be implemented unless the FS is
1873 			     * read-only. */
1874     Tcl_FSRemoveDirectoryProc *removeDirectoryProc;
1875 			    /* Function to process a
1876 			     * 'Tcl_FSRemoveDirectory()' call. Should
1877 			     * be implemented unless the FS is
1878 			     * read-only. */
1879     Tcl_FSDeleteFileProc *deleteFileProc;
1880 			    /* Function to process a
1881 			     * 'Tcl_FSDeleteFile()' call.  Should
1882 			     * be implemented unless the FS is
1883 			     * read-only. */
1884     Tcl_FSCopyFileProc *copyFileProc;
1885 			    /* Function to process a
1886 			     * 'Tcl_FSCopyFile()' call.  If not
1887 			     * implemented Tcl will fall back
1888 			     * on open-r, open-w and fcopy as
1889 			     * a copying mechanism, for copying
1890 			     * actions initiated in Tcl (not C). */
1891     Tcl_FSRenameFileProc *renameFileProc;
1892 			    /* Function to process a
1893 			     * 'Tcl_FSRenameFile()' call.  If not
1894 			     * implemented, Tcl will fall back on
1895 			     * a copy and delete mechanism, for
1896 			     * rename actions initiated in Tcl (not C). */
1897     Tcl_FSCopyDirectoryProc *copyDirectoryProc;
1898 			    /* Function to process a
1899 			     * 'Tcl_FSCopyDirectory()' call.  If
1900 			     * not implemented, Tcl will fall back
1901 			     * on a recursive create-dir, file copy
1902 			     * mechanism, for copying actions
1903 			     * initiated in Tcl (not C). */
1904     Tcl_FSLstatProc *lstatProc;
1905 			    /* Function to process a
1906 			     * 'Tcl_FSLstat()' call.  If not implemented,
1907 			     * Tcl will attempt to use the 'statProc'
1908 			     * defined above instead. */
1909     Tcl_FSLoadFileProc *loadFileProc;
1910 			    /* Function to process a
1911 			     * 'Tcl_FSLoadFile()' call.  If not
1912 			     * implemented, Tcl will fall back on
1913 			     * a copy to native-temp followed by a
1914 			     * Tcl_FSLoadFile on that temporary copy. */
1915     Tcl_FSGetCwdProc *getCwdProc;
1916 			    /*
1917 			     * Function to process a 'Tcl_FSGetCwd()'
1918 			     * call.  Most filesystems need not
1919 			     * implement this.  It will usually only be
1920 			     * called once, if 'getcwd' is called
1921 			     * before 'chdir'.  May be NULL.
1922 			     */
1923     Tcl_FSChdirProc *chdirProc;
1924 			    /*
1925 			     * Function to process a 'Tcl_FSChdir()'
1926 			     * call.  If filesystems do not implement
1927 			     * this, it will be emulated by a series of
1928 			     * directory access checks.  Otherwise,
1929 			     * virtual filesystems which do implement
1930 			     * it need only respond with a positive
1931 			     * return result if the dirName is a valid
1932 			     * directory in their filesystem.  They
1933 			     * need not remember the result, since that
1934 			     * will be automatically remembered for use
1935 			     * by GetCwd.  Real filesystems should
1936 			     * carry out the correct action (i.e. call
1937 			     * the correct system 'chdir' api).  If not
1938 			     * implemented, then 'cd' and 'pwd' will
1939 			     * fail inside the filesystem.
1940 			     */
1941 } Tcl_Filesystem;
1942 
1943 /*
1944  * The following definitions are used as values for the 'linkAction' flag
1945  * to Tcl_FSLink, or the linkProc of any filesystem.  Any combination
1946  * of flags can be given.  For link creation, the linkProc should create
1947  * a link which matches any of the types given.
1948  *
1949  * TCL_CREATE_SYMBOLIC_LINK:  Create a symbolic or soft link.
1950  * TCL_CREATE_HARD_LINK:      Create a hard link.
1951  */
1952 #define TCL_CREATE_SYMBOLIC_LINK   0x01
1953 #define TCL_CREATE_HARD_LINK       0x02
1954 
1955 /*
1956  * The following structure represents the Notifier functions that
1957  * you can override with the Tcl_SetNotifier call.
1958  */
1959 typedef struct Tcl_NotifierProcs {
1960     Tcl_SetTimerProc *setTimerProc;
1961     Tcl_WaitForEventProc *waitForEventProc;
1962     Tcl_CreateFileHandlerProc *createFileHandlerProc;
1963     Tcl_DeleteFileHandlerProc *deleteFileHandlerProc;
1964     Tcl_InitNotifierProc *initNotifierProc;
1965     Tcl_FinalizeNotifierProc *finalizeNotifierProc;
1966     Tcl_AlertNotifierProc *alertNotifierProc;
1967     Tcl_ServiceModeHookProc *serviceModeHookProc;
1968 } Tcl_NotifierProcs;
1969 
1970 
1971 /*
1972  * The following structure represents a user-defined encoding.  It collects
1973  * together all the functions that are used by the specific encoding.
1974  */
1975 typedef struct Tcl_EncodingType
1976 #ifdef USE_TCL_STRUCT
1977 {
1978     CONST char *encodingName;	/* The name of the encoding, e.g.  "euc-jp".
1979 				 * This name is the unique key for this
1980 				 * encoding type. */
1981     Tcl_EncodingConvertProc *toUtfProc;
1982 				/* Procedure to convert from external
1983 				 * encoding into UTF-8. */
1984     Tcl_EncodingConvertProc *fromUtfProc;
1985 				/* Procedure to convert from UTF-8 into
1986 				 * external encoding. */
1987     Tcl_EncodingFreeProc *freeProc;
1988 				/* If non-NULL, procedure to call when this
1989 				 * encoding is deleted. */
1990     ClientData clientData;	/* Arbitrary value associated with encoding
1991 				 * type.  Passed to conversion procedures. */
1992     int nullSize;		/* Number of zero bytes that signify
1993 				 * end-of-string in this encoding.  This
1994 				 * number is used to determine the source
1995 				 * string length when the srcLen argument is
1996 				 * negative.  Must be 1 or 2. */
1997 }
1998 #endif
1999 Tcl_EncodingType;
2000 
2001 /*
2002  * The following definitions are used as values for the conversion control
2003  * flags argument when converting text from one character set to another:
2004  *
2005  * TCL_ENCODING_START:	     	Signifies that the source buffer is the first
2006  *				block in a (potentially multi-block) input
2007  *				stream.  Tells the conversion procedure to
2008  *				reset to an initial state and perform any
2009  *				initialization that needs to occur before the
2010  *				first byte is converted.  If the source
2011  *				buffer contains the entire input stream to be
2012  *				converted, this flag should be set.
2013  *
2014  * TCL_ENCODING_END:		Signifies that the source buffer is the last
2015  *				block in a (potentially multi-block) input
2016  *				stream.  Tells the conversion routine to
2017  *				perform any finalization that needs to occur
2018  *				after the last byte is converted and then to
2019  *				reset to an initial state.  If the source
2020  *				buffer contains the entire input stream to be
2021  *				converted, this flag should be set.
2022  *
2023  * TCL_ENCODING_STOPONERROR:	If set, then the converter will return
2024  *				immediately upon encountering an invalid
2025  *				byte sequence or a source character that has
2026  *				no mapping in the target encoding.  If clear,
2027  *				then the converter will skip the problem,
2028  *				substituting one or more "close" characters
2029  *				in the destination buffer and then continue
2030  *				to sonvert the source.
2031  */
2032 #define TCL_ENCODING_START		0x01
2033 #define TCL_ENCODING_END		0x02
2034 #define TCL_ENCODING_STOPONERROR	0x04
2035 
2036 
2037 /*
2038  * The following data structures and declarations are for the new Tcl
2039  * parser.
2040  */
2041 
2042 /*
2043  * For each word of a command, and for each piece of a word such as a
2044  * variable reference, one of the following structures is created to
2045  * describe the token.
2046  */
2047 typedef struct Tcl_Token
2048 #ifdef USE_TCL_STRUCT
2049 {
2050     int type;			/* Type of token, such as TCL_TOKEN_WORD;
2051 				 * see below for valid types. */
2052     CONST char *start;		/* First character in token. */
2053     int size;			/* Number of bytes in token. */
2054     int numComponents;		/* If this token is composed of other
2055 				 * tokens, this field tells how many of
2056 				 * them there are (including components of
2057 				 * components, etc.).  The component tokens
2058 				 * immediately follow this one. */
2059 }
2060 #endif
2061 Tcl_Token;
2062 
2063 /*
2064  * Type values defined for Tcl_Token structures.  These values are
2065  * defined as mask bits so that it's easy to check for collections of
2066  * types.
2067  *
2068  * TCL_TOKEN_WORD -		The token describes one word of a command,
2069  *				from the first non-blank character of
2070  *				the word (which may be " or {) up to but
2071  *				not including the space, semicolon, or
2072  *				bracket that terminates the word.
2073  *				NumComponents counts the total number of
2074  *				sub-tokens that make up the word.  This
2075  *				includes, for example, sub-tokens of
2076  *				TCL_TOKEN_VARIABLE tokens.
2077  * TCL_TOKEN_SIMPLE_WORD -	This token is just like TCL_TOKEN_WORD
2078  *				except that the word is guaranteed to
2079  *				consist of a single TCL_TOKEN_TEXT
2080  *				sub-token.
2081  * TCL_TOKEN_TEXT -		The token describes a range of literal
2082  *				text that is part of a word.
2083  *				NumComponents is always 0.
2084  * TCL_TOKEN_BS -		The token describes a backslash sequence
2085  *				that must be collapsed.	 NumComponents
2086  *				is always 0.
2087  * TCL_TOKEN_COMMAND -		The token describes a command whose result
2088  *				must be substituted into the word.  The
2089  *				token includes the enclosing brackets.
2090  *				NumComponents is always 0.
2091  * TCL_TOKEN_VARIABLE -		The token describes a variable
2092  *				substitution, including the dollar sign,
2093  *				variable name, and array index (if there
2094  *				is one) up through the right
2095  *				parentheses.  NumComponents tells how
2096  *				many additional tokens follow to
2097  *				represent the variable name.  The first
2098  *				token will be a TCL_TOKEN_TEXT token
2099  *				that describes the variable name.  If
2100  *				the variable is an array reference then
2101  *				there will be one or more additional
2102  *				tokens, of type TCL_TOKEN_TEXT,
2103  *				TCL_TOKEN_BS, TCL_TOKEN_COMMAND, and
2104  *				TCL_TOKEN_VARIABLE, that describe the
2105  *				array index; numComponents counts the
2106  *				total number of nested tokens that make
2107  *				up the variable reference, including
2108  *				sub-tokens of TCL_TOKEN_VARIABLE tokens.
2109  * TCL_TOKEN_SUB_EXPR -		The token describes one subexpression of a
2110  *				expression, from the first non-blank
2111  *				character of the subexpression up to but not
2112  *				including the space, brace, or bracket
2113  *				that terminates the subexpression.
2114  *				NumComponents counts the total number of
2115  *				following subtokens that make up the
2116  *				subexpression; this includes all subtokens
2117  *				for any nested TCL_TOKEN_SUB_EXPR tokens.
2118  *				For example, a numeric value used as a
2119  *				primitive operand is described by a
2120  *				TCL_TOKEN_SUB_EXPR token followed by a
2121  *				TCL_TOKEN_TEXT token. A binary subexpression
2122  *				is described by a TCL_TOKEN_SUB_EXPR token
2123  *				followed by the	TCL_TOKEN_OPERATOR token
2124  *				for the operator, then TCL_TOKEN_SUB_EXPR
2125  *				tokens for the left then the right operands.
2126  * TCL_TOKEN_OPERATOR -		The token describes one expression operator.
2127  *				An operator might be the name of a math
2128  *				function such as "abs". A TCL_TOKEN_OPERATOR
2129  *				token is always preceeded by one
2130  *				TCL_TOKEN_SUB_EXPR token for the operator's
2131  *				subexpression, and is followed by zero or
2132  *				more TCL_TOKEN_SUB_EXPR tokens for the
2133  *				operator's operands. NumComponents is
2134  *				always 0.
2135  */
2136 #define TCL_TOKEN_WORD		1
2137 #define TCL_TOKEN_SIMPLE_WORD	2
2138 #define TCL_TOKEN_TEXT		4
2139 #define TCL_TOKEN_BS		8
2140 #define TCL_TOKEN_COMMAND	16
2141 #define TCL_TOKEN_VARIABLE	32
2142 #define TCL_TOKEN_SUB_EXPR	64
2143 #define TCL_TOKEN_OPERATOR	128
2144 
2145 /*
2146  * Parsing error types.  On any parsing error, one of these values
2147  * will be stored in the error field of the Tcl_Parse structure
2148  * defined below.
2149  */
2150 #define TCL_PARSE_SUCCESS		0
2151 #define TCL_PARSE_QUOTE_EXTRA		1
2152 #define TCL_PARSE_BRACE_EXTRA		2
2153 #define TCL_PARSE_MISSING_BRACE		3
2154 #define TCL_PARSE_MISSING_BRACKET	4
2155 #define TCL_PARSE_MISSING_PAREN		5
2156 #define TCL_PARSE_MISSING_QUOTE		6
2157 #define TCL_PARSE_MISSING_VAR_BRACE	7
2158 #define TCL_PARSE_SYNTAX		8
2159 #define TCL_PARSE_BAD_NUMBER		9
2160 
2161 /*
2162  * A structure of the following type is filled in by Tcl_ParseCommand.
2163  * It describes a single command parsed from an input string.
2164  */
2165 #define NUM_STATIC_TOKENS 20
2166 
2167 typedef struct Tcl_Parse
2168 #ifdef USE_TCL_STRUCT
2169 {
2170     CONST char *commentStart;	/* Pointer to # that begins the first of
2171 				 * one or more comments preceding the
2172 				 * command. */
2173     int commentSize;		/* Number of bytes in comments (up through
2174 				 * newline character that terminates the
2175 				 * last comment).  If there were no
2176 				 * comments, this field is 0. */
2177     CONST char *commandStart;	/* First character in first word of command. */
2178     int commandSize;		/* Number of bytes in command, including
2179 				 * first character of first word, up
2180 				 * through the terminating newline,
2181 				 * close bracket, or semicolon. */
2182     int numWords;		/* Total number of words in command.  May
2183 				 * be 0. */
2184     Tcl_Token *tokenPtr;	/* Pointer to first token representing
2185 				 * the words of the command.  Initially
2186 				 * points to staticTokens, but may change
2187 				 * to point to malloc-ed space if command
2188 				 * exceeds space in staticTokens. */
2189     int numTokens;		/* Total number of tokens in command. */
2190     int tokensAvailable;	/* Total number of tokens available at
2191 				 * *tokenPtr. */
2192     int errorType;		/* One of the parsing error types defined
2193 				 * above. */
2194 
2195     /*
2196      * The fields below are intended only for the private use of the
2197      * parser.	They should not be used by procedures that invoke
2198      * Tcl_ParseCommand.
2199      */
2200 
2201     CONST char *string;		/* The original command string passed to
2202 				 * Tcl_ParseCommand. */
2203     CONST char *end;		/* Points to the character just after the
2204 				 * last one in the command string. */
2205     Tcl_Interp *interp;		/* Interpreter to use for error reporting,
2206 				 * or NULL. */
2207     CONST char *term;		/* Points to character in string that
2208 				 * terminated most recent token.  Filled in
2209 				 * by ParseTokens.  If an error occurs,
2210 				 * points to beginning of region where the
2211 				 * error occurred (e.g. the open brace if
2212 				 * the close brace is missing). */
2213     int incomplete;		/* This field is set to 1 by Tcl_ParseCommand
2214 				 * if the command appears to be incomplete.
2215 				 * This information is used by
2216 				 * Tcl_CommandComplete. */
2217     Tcl_Token staticTokens[NUM_STATIC_TOKENS];
2218 				/* Initial space for tokens for command.
2219 				 * This space should be large enough to
2220 				 * accommodate most commands; dynamic
2221 				 * space is allocated for very large
2222 				 * commands that don't fit here. */
2223 }
2224 #endif
2225 Tcl_Parse;
2226 
2227 /*
2228  * The following definitions are the error codes returned by the conversion
2229  * routines:
2230  *
2231  * TCL_OK:			All characters were converted.
2232  *
2233  * TCL_CONVERT_NOSPACE:		The output buffer would not have been large
2234  *				enough for all of the converted data; as many
2235  *				characters as could fit were converted though.
2236  *
2237  * TCL_CONVERT_MULTIBYTE:	The last few bytes in the source string were
2238  *				the beginning of a multibyte sequence, but
2239  *				more bytes were needed to complete this
2240  *				sequence.  A subsequent call to the conversion
2241  *				routine should pass the beginning of this
2242  *				unconverted sequence plus additional bytes
2243  *				from the source stream to properly convert
2244  *				the formerly split-up multibyte sequence.
2245  *
2246  * TCL_CONVERT_SYNTAX:		The source stream contained an invalid
2247  *				character sequence.  This may occur if the
2248  *				input stream has been damaged or if the input
2249  *				encoding method was misidentified.  This error
2250  *				is reported only if TCL_ENCODING_STOPONERROR
2251  *				was specified.
2252  *
2253  * TCL_CONVERT_UNKNOWN:		The source string contained a character
2254  *				that could not be represented in the target
2255  *				encoding.  This error is reported only if
2256  *				TCL_ENCODING_STOPONERROR was specified.
2257  */
2258 #define TCL_CONVERT_MULTIBYTE		-1
2259 #define TCL_CONVERT_SYNTAX		-2
2260 #define TCL_CONVERT_UNKNOWN		-3
2261 #define TCL_CONVERT_NOSPACE		-4
2262 
2263 /*
2264  * The maximum number of bytes that are necessary to represent a single
2265  * Unicode character in UTF-8.  The valid values should be 3 or 6 (or
2266  * perhaps 1 if we want to support a non-unicode enabled core).
2267  * If 3, then Tcl_UniChar must be 2-bytes in size (UCS-2). (default)
2268  * If 6, then Tcl_UniChar must be 4-bytes in size (UCS-4).
2269  * At this time UCS-2 mode is the default and recommended mode.
2270  * UCS-4 is experimental and not recommended.  It works for the core,
2271  * but most extensions expect UCS-2.
2272  */
2273 #ifndef TCL_UTF_MAX
2274 #define TCL_UTF_MAX		3
2275 #endif
2276 
2277 /*
2278  * This represents a Unicode character.  Any changes to this should
2279  * also be reflected in regcustom.h.
2280  */
2281 #if TCL_UTF_MAX > 3
2282     /*
2283      * unsigned int isn't 100% accurate as it should be a strict 4-byte
2284      * value (perhaps wchar_t).  64-bit systems may have troubles.  The
2285      * size of this value must be reflected correctly in regcustom.h.
2286      */
2287 typedef unsigned int Tcl_UniChar;
2288 #else
2289 typedef unsigned short Tcl_UniChar;
2290 #endif
2291 
2292 
2293 /*
2294  * Deprecated Tcl procedures:
2295  */
2296 #ifndef TCL_NO_DEPRECATED
2297 #   define Tcl_EvalObj(interp,objPtr) \
2298 	Tcl_EvalObjEx((interp),(objPtr),0)
2299 #   define Tcl_GlobalEvalObj(interp,objPtr) \
2300 	Tcl_EvalObjEx((interp),(objPtr),TCL_EVAL_GLOBAL)
2301 #endif
2302 
2303 
2304 /*
2305  * These function have been renamed. The old names are deprecated, but we
2306  * define these macros for backwards compatibilty.
2307  */
2308 #define Tcl_Ckalloc Tcl_Alloc
2309 #define Tcl_Ckfree Tcl_Free
2310 #define Tcl_Ckrealloc Tcl_Realloc
2311 #define Tcl_Return Tcl_SetResult
2312 #define Tcl_TildeSubst Tcl_TranslateFileName
2313 #ifndef _LANG
2314 #define panic Tcl_Panic
2315 #endif
2316 #define panicVA Tcl_PanicVA
2317 
2318 
2319 /*
2320  * The following constant is used to test for older versions of Tcl
2321  * in the stubs tables.
2322  *
2323  * Jan Nijtman's plus patch uses 0xFCA1BACF, so we need to pick a different
2324  * value since the stubs tables don't match.
2325  */
2326 
2327 #define TCL_STUB_MAGIC ((int)0xFCA3BACF)
2328 
2329 /*
2330  * The following function is required to be defined in all stubs aware
2331  * extensions.  The function is actually implemented in the stub
2332  * library, not the main Tcl library, although there is a trivial
2333  * implementation in the main library in case an extension is statically
2334  * linked into an application.
2335  */
2336 
2337 EXTERN CONST char *	Tcl_InitStubs _ANSI_ARGS_((Tcl_Interp *interp,
2338 			    CONST char *version, int exact));
2339 
2340 #ifndef USE_TCL_STUBS
2341 
2342 /*
2343  * When not using stubs, make it a macro.
2344  */
2345 
2346 #define Tcl_InitStubs(interp, version, exact) \
2347     Tcl_PkgRequire(interp, "Tcl", version, exact)
2348 
2349 #endif
2350 
2351 
2352 /*
2353  * Include the public function declarations that are accessible via
2354  * the stubs table.
2355  */
2356 
2357 #include "tclDecls.h"
2358 
2359 /*
2360  * Include platform specific public function declarations that are
2361  * accessible via the stubs table.
2362  */
2363 
2364 /*
2365  * tclPlatDecls.h can't be included here on the Mac, as we need
2366  * Mac specific headers to define the Mac types used in this file,
2367  * but these Mac haders conflict with a number of tk types
2368  * and thus can't be included in the globally read tcl.h
2369  * This header was originally added here as a fix for bug 5241
2370  * (stub link error for symbols in TclPlatStubs table), as a work-
2371  * around for the bug on the mac, tclMac.h is included immediately
2372  * after tcl.h in the tcl precompiled header (with DLLEXPORT set).
2373  */
2374 
2375 #if !defined(MAC_TCL)
2376 #include "tclPlatDecls.h"
2377 #endif
2378 
2379 /*
2380  * Public functions that are not accessible via the stubs table.
2381  */
2382 
2383 EXTERN void Tcl_Main _ANSI_ARGS_((int argc, char **argv,
2384 	Tcl_AppInitProc *appInitProc));
2385 
2386 /*
2387  * Convenience declaration of Tcl_AppInit for backwards compatibility.
2388  * This function is not *implemented* by the tcl library, so the storage
2389  * class is neither DLLEXPORT nor DLLIMPORT
2390  */
2391 #undef TCL_STORAGE_CLASS
2392 #define TCL_STORAGE_CLASS
2393 
2394 EXTERN int		Tcl_AppInit _ANSI_ARGS_((Tcl_Interp *interp));
2395 
2396 #undef TCL_STORAGE_CLASS
2397 #define TCL_STORAGE_CLASS DLLIMPORT
2398 
2399 #endif /* RC_INVOKED */
2400 
2401 /*
2402  * end block for C++
2403  */
2404 #ifdef __cplusplus
2405 }
2406 #endif
2407 
2408 #endif /* _TCL */
2409 
2410 
2411 
2412