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