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