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