OSDN Git Service

Please enter the commit message for your changes. Lines starting
[eos/base.git] / util / src / TclTk / tcl8.6.12 / doc / tclvars.n
1 '\"
2 '\" Copyright (c) 1993 The Regents of the University of California.
3 '\" Copyright (c) 1994-1997 Sun Microsystems, Inc.
4 '\"
5 '\" See the file "license.terms" for information on usage and redistribution
6 '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
7 '\"
8 .TH tclvars n 8.0 Tcl "Tcl Built-In Commands"
9 .so man.macros
10 .BS
11 '\" Note:  do not modify the .SH NAME line immediately below!
12 .SH NAME
13 argc, argv, argv0, auto_path, env, errorCode, errorInfo, tcl_interactive, tcl_library, tcl_nonwordchars, tcl_patchLevel, tcl_pkgPath, tcl_platform, tcl_precision, tcl_rcFileName, tcl_traceCompile, tcl_traceExec, tcl_wordchars, tcl_version \- Variables used by Tcl
14 .BE
15 .SH DESCRIPTION
16 .PP
17 The following global variables are created and managed automatically
18 by the Tcl library.  Except where noted below, these variables should
19 normally be treated as read-only by application-specific code and by users.
20 .TP
21 \fBauto_path\fR
22 .
23 If set, then it must contain a valid Tcl list giving directories to
24 search during auto-load operations (including for package index
25 files when using the default \fBpackage unknown\fR handler).
26 This variable is initialized during startup to contain, in order:
27 the directories listed in the \fBTCLLIBPATH\fR environment variable,
28 the directory named by the \fBtcl_library\fR global variable,
29 the parent directory of \fBtcl_library\fR,
30 the directories listed in the \fBtcl_pkgPath\fR variable.
31 Additional locations to look for files and package indices should
32 normally be added to this variable using \fBlappend\fR.
33 .RS
34 .PP
35 Additional variables relating to package management exist. More
36 details are listed in the \fBVARIABLES\fR section of the \fBlibrary\fR
37 manual page.
38 .RE
39 .TP
40 \fBenv\fR
41 .
42 This variable is maintained by Tcl as an array
43 whose elements are the environment variables for the process.
44 Reading an element will return the value of the corresponding
45 environment variable.
46 Setting an element of the array will modify the corresponding
47 environment variable or create a new one if it does not already
48 exist.
49 Unsetting an element of \fBenv\fR will remove the corresponding
50 environment variable.
51 Changes to the \fBenv\fR array will affect the environment
52 passed to children by commands like \fBexec\fR.
53 If the entire \fBenv\fR array is unset then Tcl will stop
54 monitoring \fBenv\fR accesses and will not update environment
55 variables.
56 .RS
57 .PP
58 Under Windows, the environment variables PATH and COMSPEC in any
59 capitalization are converted automatically to upper case.  For instance, the
60 PATH variable could be exported by the operating system as
61 .QW path ,
62 .QW Path ,
63 .QW PaTh ,
64 etc., causing otherwise simple Tcl code to have to
65 support many special cases.  All other environment variables inherited by
66 Tcl are left unmodified.  Setting an env array variable to blank is the
67 same as unsetting it as this is the behavior of the underlying Windows OS.
68 It should be noted that relying on an existing and empty environment variable
69 will not work on Windows and is discouraged for cross-platform usage.
70 .PP
71 The following elements of \fBenv\fR are special to Tcl:
72 .TP
73 \fBenv(HOME)\fR
74 .
75 This environment variable, if set, gives the location of the directory
76 considered to be the current user's home directory, and to which a
77 call of \fBcd\fR without arguments or with just
78 .QW ~
79 as an argument will change into. Most platforms set this correctly by
80 default; it does not normally need to be set by user code.
81 .TP
82 \fBenv(TCL_LIBRARY)\fR
83 .
84 If set, then it specifies the location of the directory containing
85 library scripts (the value of this variable will be
86 assigned to the \fBtcl_library\fR variable and therefore returned by
87 the command \fBinfo library\fR).  If this variable is not set then
88 a default value is used.
89 .RS
90 .PP
91 Note that this environment variable should \fInot\fR normally be set.
92 .RE
93 .TP
94 \fBenv(TCLLIBPATH)\fR
95 .
96 If set, then it must contain a valid Tcl list giving directories to
97 search during auto-load operations.  Directories must be specified in
98 Tcl format, using
99 .QW /
100 as the path separator, regardless of platform.
101 This variable is only used when initializing the \fBauto_path\fR variable.
102 .TP
103 \fBenv(TCL_TZ)\fR, \fBenv(TZ)\fR
104 .
105 These specify the default timezone used for parsing and formatting times and
106 dates in the \fBclock\fR command. On many platforms, the TZ environment
107 variable is set up by the operating system.
108 .TP
109 \fBenv(LC_ALL)\fR, \fBenv(LC_MESSAGES)\fR, \fBenv(LANG)\fR
110 .
111 These environment variables are used by the \fBmsgcat\fR package to
112 determine what locale to format messages using.
113 .TP
114 \fBenv(TCL_INTERP_DEBUG_FRAME)\fR
115 .
116 If existing, it has the same effect as running \fBinterp debug\fR
117 \fB{} -frame 1\fR
118 as the very first command of each new Tcl interpreter.
119 .RE
120 .TP
121 \fBerrorCode\fR
122 .
123 This variable holds the value of the \fB\-errorcode\fR return option
124 set by the most recent error that occurred in this interpreter.
125 This list value represents additional information about the error
126 in a form that is easy to process with programs.
127 The first element of the list identifies a general class of
128 errors, and determines the format of the rest of the list.
129 The following formats for \fB\-errorcode\fR return options
130 are used by the Tcl core; individual applications may define
131 additional formats.
132 .RS
133 .TP
134 \fBARITH\fI code msg\fR
135 .
136 This format is used when an arithmetic error occurs (e.g. an attempt
137 to divide zero by zero in the \fBexpr\fR command).
138 \fICode\fR identifies the precise error and \fImsg\fR provides a
139 human-readable description of the error.  \fICode\fR will be either
140 DIVZERO (for an attempt to divide by zero),
141 DOMAIN (if an argument is outside the domain of a function, such as acos(\-3)),
142 IOVERFLOW (for integer overflow),
143 OVERFLOW (for a floating-point overflow),
144 or UNKNOWN (if the cause of the error cannot be determined).
145 .RS
146 .PP
147 Detection of these errors depends in part on the underlying hardware
148 and system libraries.
149 .RE
150 .TP
151 \fBCHILDKILLED\fI pid sigName msg\fR
152 .
153 This format is used when a child process has been killed because of
154 a signal.  The \fIpid\fR element will be the process's identifier (in decimal).
155 The \fIsigName\fR element will be the symbolic name of the signal that caused
156 the process to terminate; it will be one of the names from the
157 include file signal.h, such as \fBSIGPIPE\fR.
158 The \fImsg\fR element will be a short human-readable message
159 describing the signal, such as
160 .QW "write on pipe with no readers"
161 for \fBSIGPIPE\fR.
162 .TP
163 \fBCHILDSTATUS\fI pid code\fR
164 .
165 This format is used when a child process has exited with a non-zero
166 exit status.  The \fIpid\fR element will be the
167 process's identifier (in decimal) and the \fIcode\fR element will be the exit
168 code returned by the process (also in decimal).
169 .TP
170 \fBCHILDSUSP\fI pid sigName msg\fR
171 .
172 This format is used when a child process has been suspended because
173 of a signal.
174 The \fIpid\fR element will be the process's identifier, in decimal.
175 The \fIsigName\fR element will be the symbolic name of the signal that caused
176 the process to suspend; this will be one of the names from the
177 include file signal.h, such as \fBSIGTTIN\fR.
178 The \fImsg\fR element will be a short human-readable message
179 describing the signal, such as
180 .QW "background tty read"
181 for \fBSIGTTIN\fR.
182 .TP
183 \fBNONE\fR
184 .
185 This format is used for errors where no additional information is
186 available for an error besides the message returned with the
187 error.  In these cases the \fB\-errorcode\fR return option
188 will consist of a list containing a single element whose
189 contents are \fBNONE\fR.
190 .TP
191 \fBPOSIX \fIerrName msg\fR
192 .
193 If the first element is \fBPOSIX\fR, then
194 the error occurred during a POSIX kernel call.
195 The \fIerrName\fR element will contain the symbolic name
196 of the error that occurred, such as \fBENOENT\fR; this will
197 be one of the values defined in the include file errno.h.
198 The \fImsg\fR element will be a human-readable
199 message corresponding to \fIerrName\fR, such as
200 .QW "no such file or directory"
201 for the \fBENOENT\fR case.
202 .TP
203 \fBTCL\fR ...
204 .
205 Indicates some sort of problem generated in relation to Tcl itself, e.g. a
206 failure to look up a channel or variable.
207 .PP
208 To set the \fB\-errorcode\fR return option, applications should use library
209 procedures such as \fBTcl_SetObjErrorCode\fR, \fBTcl_SetReturnOptions\fR,
210 and \fBTcl_PosixError\fR, or they may invoke the \fB\-errorcode\fR
211 option of the \fBreturn\fR command.
212 If none of these methods for setting the error code has been used,
213 the Tcl interpreter will reset the variable to \fBNONE\fR after
214 the next error.
215 .RE
216 .TP
217 \fBerrorInfo\fR
218 .
219 This variable holds the value of the \fB\-errorinfo\fR return option
220 set by the most recent error that occurred in this interpreter.
221 This string value will contain one or more lines
222 identifying the Tcl commands and procedures that were being executed
223 when the most recent error occurred.
224 Its contents take the form of a stack trace showing the various
225 nested Tcl commands that had been invoked at the time of the error.
226 .TP
227 \fBtcl_library\fR
228 .
229 This variable holds the name of a directory containing the
230 system library of Tcl scripts, such as those used for auto-loading.
231 The value of this variable is returned by the \fBinfo library\fR command.
232 See the \fBlibrary\fR manual entry for details of the facilities
233 provided by the Tcl script library.
234 Normally each application or package will have its own application-specific
235 script library in addition to the Tcl script library;
236 each application should set a global variable with a name like
237 \fB$\fIapp\fB_library\fR (where \fIapp\fR is the application's name)
238 to hold the network file name for that application's library directory.
239 The initial value of \fBtcl_library\fR is set when an interpreter
240 is created by searching several different directories until one is
241 found that contains an appropriate Tcl startup script.
242 If the \fBTCL_LIBRARY\fR environment variable exists, then
243 the directory it names is checked first.
244 If \fBTCL_LIBRARY\fR is not set or doesn't refer to an appropriate
245 directory, then Tcl checks several other directories based on a
246 compiled-in default location, the location of the binary containing
247 the application, and the current working directory.
248 .TP
249 \fBtcl_patchLevel\fR
250 .
251 When an interpreter is created Tcl initializes this variable to
252 hold a string giving the current patch level for Tcl, such as
253 \fB8.4.16\fR for Tcl 8.4 with the first sixteen official patches, or
254 \fB8.5b3\fR for the third beta release of Tcl 8.5.
255 The value of this variable is returned by the \fBinfo patchlevel\fR
256 command.
257 .TP
258 \fBtcl_pkgPath\fR
259 .
260 This variable holds a list of directories indicating where packages are
261 normally installed.  It is not used on Windows.  It typically contains
262 either one or two entries; if it contains two entries, the first is
263 normally a directory for platform-dependent packages (e.g., shared library
264 binaries) and the second is normally a directory for platform-independent
265 packages (e.g., script files). Typically a package is installed as a
266 subdirectory of one of the entries in the \fBtcl_pkgPath\fR
267 variable. The directories in the \fBtcl_pkgPath\fR variable are
268 included by default in the \fBauto_path\fR
269 variable, so they and their immediate subdirectories are automatically
270 searched for packages during \fBpackage require\fR commands.  Note:
271 \fBtcl_pkgPath\fR is not intended to be modified by the application.  Its
272 value is added to \fBauto_path\fR at startup; changes to \fBtcl_pkgPath\fR
273 are not reflected in \fBauto_path\fR.  If you want Tcl to search additional
274 directories for packages you should add the names of those directories to
275 \fBauto_path\fR, not \fBtcl_pkgPath\fR.
276 .TP
277 \fBtcl_platform\fR
278 .
279 This is an associative array whose elements contain information about
280 the platform on which the application is running, such as the name of
281 the operating system, its current release number, and the machine's
282 instruction set.  The elements listed below will always
283 be defined, but they may have empty strings as values if Tcl could not
284 retrieve any relevant information.  In addition, extensions
285 and applications may add additional values to the array.  The
286 predefined elements are:
287 .RS
288 .TP
289 \fBbyteOrder\fR
290 .
291 The native byte order of this machine: either \fBlittleEndian\fR or
292 \fBbigEndian\fR.
293 .TP
294 \fBdebug\fR
295 .
296 If this variable exists, then the interpreter was compiled with and linked
297 to a debug-enabled C run-time.  This variable will only exist on Windows,
298 so extension writers can specify which package to load depending on the
299 C run-time library that is in use.  This is not an indication that this core
300 contains symbols.
301 .TP
302 \fBengine\fR
303 .
304 The name of the Tcl language implementation.  When the interpreter is first
305 created, this is always set to the string \fBTcl\fR.
306 .TP
307 \fBmachine\fR
308 .
309 The instruction set executed by this machine, such as
310 \fBintel\fR, \fBPPC\fR, \fB68k\fR, or \fBsun4m\fR.  On UNIX machines, this
311 is the value returned by \fBuname -m\fR.
312 .TP
313 \fBos\fR
314 .
315 The name of the operating system running on this machine,
316 such as \fBWindows NT\fR or \fBSunOS\fR.
317 On UNIX machines, this is the value returned by \fBuname -s\fR.
318 .TP
319 \fBosVersion\fR
320 .
321 The version number for the operating system running on this machine.
322 On UNIX machines, this is the value returned by \fBuname -r\fR.
323 .TP
324 \fBpathSeparator\fR
325 .VS 8.6
326 '\" Defined by TIP #315
327 The character that should be used to \fBsplit\fR PATH-like environment
328 variables into their corresponding list of directory names.
329 .VE 8.6
330 .TP
331 \fBplatform\fR
332 .
333 Either \fBwindows\fR, or \fBunix\fR.  This identifies the
334 general operating environment of the machine.
335 .TP
336 \fBpointerSize\fR
337 .
338 This gives the size of the native-machine pointer in bytes (strictly, it
339 is same as the result of evaluating \fIsizeof(void*)\fR in C.)
340 .TP
341 \fBthreaded\fR
342 .
343 If this variable exists, then the interpreter
344 was compiled with threads enabled.
345 .TP
346 \fBuser\fR
347 .
348 This identifies the
349 current user based on the login information available on the platform.
350 This value comes from the getuid() and getpwuid() system calls on Unix,
351 and the value from the GetUserName() system call on Windows.
352 .TP
353 \fBwordSize\fR
354 .
355 This gives the size of the native-machine word in bytes (strictly, it
356 is same as the result of evaluating \fIsizeof(long)\fR in C.)
357 .RE
358 .TP
359 \fBtcl_precision\fR
360 .
361 This variable controls the number of digits to generate
362 when converting floating-point values to strings.  It defaults
363 to 0.  \fIApplications should not change this value;\fR it is
364 provided for compatibility with legacy code.
365 .PP
366 .RS
367 The default value of 0 is special, meaning that Tcl should
368 convert numbers using as few digits as possible while still
369 distinguishing any floating point number from its nearest
370 neighbours.  It differs from using an arbitrarily high value
371 for \fItcl_precision\fR in that an inexact number like \fI1.4\fR
372 will convert as \fI1.4\fR rather than \fI1.3999999999999999\fR
373 even though the latter is nearer to the exact value of the
374 binary number.
375 .RE
376 .PP
377 .RS
378 If \fBtcl_precision\fR is not zero, then when Tcl converts a floating
379 point number, it creates a decimal representation of at most
380 \fBtcl_precision\fR significant digits; the result may be shorter if
381 the shorter result represents the original number exactly. If no
382 result of at most \fBtcl_precision\fR digits is an exact representation
383 of the original number, the one that is closest to the original
384 number is chosen.
385 If the original number lies precisely between two equally accurate
386 decimal representations, then the one with an even value for the least
387 significant digit is chosen; for instance, if \fBtcl_precision\fR is 3, then
388 0.3125 will convert to 0.312, not 0.313, while 0.6875 will convert to
389 0.688, not 0.687. Any string of trailing zeroes that remains is trimmed.
390 .RE
391 .PP
392 .RS
393 a \fBtcl_precision\fR value of 17 digits is
394 .QW perfect
395 for IEEE floating-point in that it allows
396 double-precision values to be converted to strings and back to
397 binary with no loss of information. For this reason, you will often
398 see it as a value in legacy code that must run on Tcl versions before
399 8.5. It is no longer recommended; as noted above, a zero value is the
400 preferred method.
401 .RE
402 .PP
403 .RS
404 All interpreters in a thread share a single \fBtcl_precision\fR value:
405 changing it in one interpreter will affect all other interpreters as
406 well.  Safe interpreters are not allowed to modify the
407 variable.
408 .RE
409 .PP
410 .RS
411 Valid values for \fBtcl_precision\fR range from 0 to 17.
412 .RE
413 .TP
414 \fBtcl_rcFileName\fR
415 .
416 This variable is used during initialization to indicate the name of a
417 user-specific startup file.  If it is set by application-specific
418 initialization, then the Tcl startup code will check for the existence
419 of this file and \fBsource\fR it if it exists.  For example, for \fBwish\fR
420 the variable is set to \fB~/.wishrc\fR for Unix and \fB~/wishrc.tcl\fR
421 for Windows.
422 .TP
423 \fBtcl_traceCompile\fR
424 .
425 The value of this variable can be set to control
426 how much tracing information
427 is displayed during bytecode compilation.
428 By default, \fBtcl_traceCompile\fR is zero and no information is displayed.
429 Setting \fBtcl_traceCompile\fR to 1 generates a one-line summary in \fBstdout\fR
430 whenever a procedure or top-level command is compiled.
431 Setting it to 2 generates a detailed listing in \fBstdout\fR of the
432 bytecode instructions emitted during every compilation.
433 This variable is useful in
434 tracking down suspected problems with the Tcl compiler.
435 .PP
436 .RS
437 This variable and functionality only exist if
438 \fBTCL_COMPILE_DEBUG\fR was defined during Tcl's compilation.
439 .RE
440 .TP
441 \fBtcl_traceExec\fR
442 .
443 The value of this variable can be set to control
444 how much tracing information
445 is displayed during bytecode execution.
446 By default, \fBtcl_traceExec\fR is zero and no information is displayed.
447 Setting \fBtcl_traceExec\fR to 1 generates a one-line trace in \fBstdout\fR
448 on each call to a Tcl procedure.
449 Setting it to 2 generates a line of output
450 whenever any Tcl command is invoked
451 that contains the name of the command and its arguments.
452 Setting it to 3 produces a detailed trace showing the result of
453 executing each bytecode instruction.
454 Note that when \fBtcl_traceExec\fR is 2 or 3,
455 commands such as \fBset\fR and \fBincr\fR
456 that have been entirely replaced by a sequence
457 of bytecode instructions are not shown.
458 Setting this variable is useful in
459 tracking down suspected problems with the bytecode compiler
460 and interpreter.
461 .PP
462 .RS
463 This variable and functionality only exist if
464 \fBTCL_COMPILE_DEBUG\fR was defined during Tcl's compilation.
465 .RE
466 .TP
467 \fBtcl_wordchars\fR
468 .
469 The value of this variable is a regular expression that can be set to
470 control what are considered
471 .QW word
472 characters, for instances like
473 selecting a word by double-clicking in text in Tk.  It is platform
474 dependent.  On Windows, it defaults to \fB\eS\fR, meaning anything
475 but a Unicode space character.  Otherwise it defaults to \fB\ew\fR,
476 which is any Unicode word character (number, letter, or underscore).
477 .TP
478 \fBtcl_nonwordchars\fR
479 .
480 The value of this variable is a regular expression that can be set to
481 control what are considered
482 .QW non-word
483 characters, for instances like
484 selecting a word by double-clicking in text in Tk.  It is platform
485 dependent.  On Windows, it defaults to \fB\es\fR, meaning any Unicode space
486 character.  Otherwise it defaults to \fB\eW\fR, which is anything but a
487 Unicode word character (number, letter, or underscore).
488 .TP
489 \fBtcl_version\fR
490 .
491 When an interpreter is created Tcl initializes this variable to
492 hold the version number for this version of Tcl in the form \fIx.y\fR.
493 Changes to \fIx\fR represent major changes with probable
494 incompatibilities and changes to \fIy\fR represent small enhancements and
495 bug fixes that retain backward compatibility.
496 The value of this variable is returned by the \fBinfo tclversion\fR
497 command.
498 .SH "OTHER GLOBAL VARIABLES"
499 .PP
500 The following variables are only guaranteed to exist in \fBtclsh\fR
501 and \fBwish\fR executables; the Tcl library does not define them
502 itself but many Tcl environments do.
503 .TP 6
504 \fBargc\fR
505 .
506 The number of arguments to \fBtclsh\fR or \fBwish\fR.
507 .TP 6
508 \fBargv\fR
509 .
510 Tcl list of arguments to \fBtclsh\fR or \fBwish\fR.
511 .TP 6
512 \fBargv0\fR
513 .
514 The script that \fBtclsh\fR or \fBwish\fR started executing (if it was
515 specified) or otherwise the name by which \fBtclsh\fR or \fBwish\fR
516 was invoked.
517 .TP 6
518 \fBtcl_interactive\fR
519 .
520 Contains 1 if \fBtclsh\fR or \fBwish\fR is running interactively (no
521 script was specified and standard input is a terminal-like device), 0
522 otherwise.
523 .SH EXAMPLES
524 .PP
525 To add a directory to the collection of locations searched by
526 \fBpackage require\fR, e.g., because of some application-specific
527 packages that are used, the \fBauto_path\fR variable needs to be
528 updated:
529 .PP
530 .CS
531 lappend ::\fBauto_path\fR [file join [pwd] "theLibDir"]
532 .CE
533 .PP
534 A simple though not very robust way to handle command line arguments
535 of the form
536 .QW "\-foo 1 \-bar 2"
537 is to load them into an array having first loaded in the default settings:
538 .CS
539 array set arguments {-foo 0 -bar 0 -grill 0}
540 array set arguments $::\fBargv\fR
541 puts "foo is $arguments(-foo)"
542 puts "bar is $arguments(-bar)"
543 puts "grill is $arguments(-grill)"
544 .CE
545 .PP
546 The \fBargv0\fR global variable can be used (in conjunction with the
547 \fBinfo script\fR command) to determine whether the current script is
548 being executed as the main script or loaded as a library.  This is
549 useful because it allows a single script to be used as both a library
550 and a demonstration of that library:
551 .PP
552 .CS
553 if {$::\fBargv0\fR eq [info script]} {
554     # running as: tclsh example.tcl
555 } else {
556     package provide Example 1.0
557 }
558 .CE
559 .SH "SEE ALSO"
560 eval(n), library(n), tclsh(1), tkvars(n), wish(1)
561 .SH KEYWORDS
562 arithmetic, bytecode, compiler, error, environment, POSIX, precision,
563 subprocess, user, variables
564 '\" Local Variables:
565 '\" mode: nroff
566 '\" End: