1library(n) Tcl Built-In Commands library(n)
2
3
4
5______________________________________________________________________________
6
8 auto_execok, auto_import, auto_load, auto_mkindex, auto_qualify,
9 auto_reset, tcl_findLibrary, parray, tcl_endOfWord,
10 tcl_startOfNextWord, tcl_startOfPreviousWord, tcl_wordBreakAfter,
11 tcl_wordBreakBefore - standard library of Tcl procedures
12
14 auto_execok cmd
15 auto_import pattern
16 auto_load cmd
17 auto_mkindex dir pattern pattern ...
18 auto_qualify command namespace
19 auto_reset
20 tcl_findLibrary basename version patch initScript enVarName varName
21 parray arrayName ?pattern?
22 tcl_endOfWord str start
23 tcl_startOfNextWord str start
24 tcl_startOfPreviousWord str start
25 tcl_wordBreakAfter str start
26 tcl_wordBreakBefore str start
27______________________________________________________________________________
28
30 Tcl includes a library of Tcl procedures for commonly-needed functions.
31 The procedures defined in the Tcl library are generic ones suitable for
32 use by many different applications. The location of the Tcl library is
33 returned by the info library command. In addition to the Tcl library,
34 each application will normally have its own library of support proce‐
35 dures as well; the location of this library is normally given by the
36 value of the $app_library global variable, where app is the name of the
37 application. For example, the location of the Tk library is kept in
38 the variable tk_library.
39
40 To access the procedures in the Tcl library, an application should
41 source the file init.tcl in the library, for example with the Tcl com‐
42 mand
43
44 source [file join [info library] init.tcl]
45
46 If the library procedure Tcl_Init is invoked from an application's
47 Tcl_AppInit procedure, this happens automatically. The code in
48 init.tcl will define the unknown procedure and arrange for the other
49 procedures to be loaded on-demand using the auto-load mechanism defined
50 below.
51
53 The following procedures are provided in the Tcl library:
54
55 auto_execok cmd
56 Determines whether there is an executable file or shell builtin
57 by the name cmd. If so, it returns a list of arguments to be
58 passed to exec to execute the executable file or shell builtin
59 named by cmd. If not, it returns an empty string. This command
60 examines the directories in the current search path (given by
61 the PATH environment variable) in its search for an executable
62 file named cmd. On Windows platforms, the search is expanded
63 with the same directories and file extensions as used by exec.
64 Auto_execok remembers information about previous searches in an
65 array named auto_execs; this avoids the path search in future
66 calls for the same cmd. The command auto_reset may be used to
67 force auto_execok to forget its cached information.
68
69 auto_import pattern
70 Auto_import is invoked during namespace import to see if the
71 imported commands specified by pattern reside in an autoloaded
72 library. If so, the commands are loaded so that they will be
73 available to the interpreter for creating the import links. If
74 the commands do not reside in an autoloaded library, auto_import
75 does nothing. The pattern matching is performed according to
76 the matching rules of namespace import.
77
78 auto_load cmd
79 This command attempts to load the definition for a Tcl command
80 named cmd. To do this, it searches an auto-load path, which is
81 a list of one or more directories. The auto-load path is given
82 by the global variable auto_path if it exists. If there is no
83 auto_path variable, then the TCLLIBPATH environment variable is
84 used, if it exists. Otherwise the auto-load path consists of
85 just the Tcl library directory. Within each directory in the
86 auto-load path there must be a file tclIndex that describes one
87 or more commands defined in that directory and a script to eval‐
88 uate to load each of the commands. The tclIndex file should be
89 generated with the auto_mkindex command. If cmd is found in an
90 index file, then the appropriate script is evaluated to create
91 the command. The auto_load command returns 1 if cmd was suc‐
92 cessfully created. The command returns 0 if there was no index
93 entry for cmd or if the script did not actually define cmd (e.g.
94 because index information is out of date). If an error occurs
95 while processing the script, then that error is returned.
96 Auto_load only reads the index information once and saves it in
97 the array auto_index; future calls to auto_load check for cmd
98 in the array rather than re-reading the index files. The cached
99 index information may be deleted with the command auto_reset.
100 This will force the next auto_load command to reload the index
101 database from disk.
102
103 auto_mkindex dir pattern pattern ...
104 Generates an index suitable for use by auto_load. The command
105 searches dir for all files whose names match any of the pattern
106 arguments (matching is done with the glob command), generates an
107 index of all the Tcl command procedures defined in all the
108 matching files, and stores the index information in a file named
109 tclIndex in dir. If no pattern is given a pattern of *.tcl will
110 be assumed. For example, the command
111
112 auto_mkindex foo *.tcl
113
114 will read all the .tcl files in subdirectory foo and generate a
115 new index file foo/tclIndex.
116
117 Auto_mkindex parses the Tcl scripts by sourcing them into a
118 slave interpreter and monitoring the proc and namespace commands
119 that are executed. Extensions can use the (undocumented)
120 auto_mkindex_parser package to register other commands that can
121 contribute to the auto_load index. You will have to read through
122 auto.tcl to see how this works.
123
124 Auto_mkindex_old (which has the same syntax as auto_mkindex)
125 parses the Tcl scripts in a relatively unsophisticated way: if
126 any line contains the word “proc” as its first characters then
127 it is assumed to be a procedure definition and the next word of
128 the line is taken as the procedure's name. Procedure defini‐
129 tions that do not appear in this way (e.g. they have spaces
130 before the proc) will not be indexed. If your script contains
131 “dangerous” code, such as global initialization code or proce‐
132 dure names with special characters like $, *, [ or ], you are
133 safer using auto_mkindex_old.
134
135 auto_reset
136 Destroys all the information cached by auto_execok and
137 auto_load. This information will be re-read from disk the next
138 time it is needed. Auto_reset also deletes any procedures
139 listed in the auto-load index, so that fresh copies of them will
140 be loaded the next time that they are used.
141
142 auto_qualify command namespace
143 Computes a list of fully qualified names for command. This list
144 mirrors the path a standard Tcl interpreter follows for command
145 lookups: first it looks for the command in the current names‐
146 pace, and then in the global namespace. Accordingly, if command
147 is relative and namespace is not ::, the list returned has two
148 elements: command scoped by namespace, as if it were a command
149 in the namespace namespace; and command as if it were a command
150 in the global namespace. Otherwise, if either command is abso‐
151 lute (it begins with ::), or namespace is ::, the list contains
152 only command as if it were a command in the global namespace.
153
154 Auto_qualify is used by the auto-loading facilities in Tcl, both
155 for producing auto-loading indexes such as pkgIndex.tcl, and for
156 performing the actual auto-loading of functions at runtime.
157
158 tcl_findLibrary basename version patch initScript enVarName varName
159 This is a standard search procedure for use by extensions during
160 their initialization. They call this procedure to look for
161 their script library in several standard directories. The last
162 component of the name of the library directory is normally base‐
163 nameversion (e.g., tk8.0), but it might be “library” when in the
164 build hierarchies. The initScript file will be sourced into the
165 interpreter once it is found. The directory in which this file
166 is found is stored into the global variable varName. If this
167 variable is already defined (e.g., by C code during application
168 initialization) then no searching is done. Otherwise the search
169 looks in these directories: the directory named by the environ‐
170 ment variable enVarName; relative to the Tcl library directory;
171 relative to the executable file in the standard installation bin
172 or bin/arch directory; relative to the executable file in the
173 current build tree; relative to the executable file in a paral‐
174 lel build tree.
175
176 parray arrayName ?pattern?
177 Prints on standard output the names and values of all the ele‐
178 ments in the array arrayName, or just the names that match pat‐
179 tern (using the matching rules of string match) and their values
180 if pattern is given. ArrayName must be an array accessible to
181 the caller of parray. It may be either local or global.
182
183 tcl_endOfWord str start
184 Returns the index of the first end-of-word location that occurs
185 after a starting index start in the string str. An end-of-word
186 location is defined to be the first non-word character following
187 the first word character after the starting point. Returns -1
188 if there are no more end-of-word locations after the starting
189 point. See the description of tcl_wordchars and tcl_nonword‐
190 chars below for more details on how Tcl determines which charac‐
191 ters are word characters.
192
193 tcl_startOfNextWord str start
194 Returns the index of the first start-of-word location that
195 occurs after a starting index start in the string str. A start-
196 of-word location is defined to be the first word character fol‐
197 lowing a non-word character. Returns -1 if there are no more
198 start-of-word locations after the starting point.
199
200 tcl_startOfPreviousWord str start
201 Returns the index of the first start-of-word location that
202 occurs before a starting index start in the string str. Returns
203 -1 if there are no more start-of-word locations before the
204 starting point.
205
206 tcl_wordBreakAfter str start
207 Returns the index of the first word boundary after the starting
208 index start in the string str. Returns -1 if there are no more
209 boundaries after the starting point in the given string. The
210 index returned refers to the second character of the pair that
211 comprises a boundary.
212
213 tcl_wordBreakBefore str start
214 Returns the index of the first word boundary before the starting
215 index start in the string str. Returns -1 if there are no more
216 boundaries before the starting point in the given string. The
217 index returned refers to the second character of the pair that
218 comprises a boundary.
219
221 The following global variables are defined or used by the procedures in
222 the Tcl library. They fall into two broad classes, handling unknown
223 commands and packages, and determining what are words.
224
225 AUTOLOADING AND PACKAGE MANAGEMENT VARIABLES
226 auto_execs
227 Used by auto_execok to record information about whether particu‐
228 lar commands exist as executable files.
229
230 auto_index
231 Used by auto_load to save the index information read from disk.
232
233 auto_noexec
234 If set to any value, then unknown will not attempt to auto-exec
235 any commands.
236
237 auto_noload
238 If set to any value, then unknown will not attempt to auto-load
239 any commands.
240
241 auto_path
242 If set, then it must contain a valid Tcl list giving directories
243 to search during auto-load operations (including for package
244 index files when using the default package unknown handler).
245 This variable is initialized during startup to contain, in
246 order: the directories listed in the TCLLIBPATH environment
247 variable, the directory named by the tcl_library global vari‐
248 able, the parent directory of tcl_library, the directories
249 listed in the tcl_pkgPath variable. Additional locations to
250 look for files and package indices should normally be added to
251 this variable using lappend.
252
253 env(TCL_LIBRARY)
254 If set, then it specifies the location of the directory contain‐
255 ing library scripts (the value of this variable will be assigned
256 to the tcl_library variable and therefore returned by the com‐
257 mand info library). If this variable is not set then a default
258 value is used.
259
260 env(TCLLIBPATH)
261 If set, then it must contain a valid Tcl list giving directories
262 to search during auto-load operations. Directories must be
263 specified in Tcl format, using “/” as the path separator,
264 regardless of platform. This variable is only used when ini‐
265 tializing the auto_path variable.
266
267 WORD BOUNDARY DETERMINATION VARIABLES
268 These variables are only used in the tcl_endOfWord,
269 tcl_startOfNextWord, tcl_startOfPreviousWord, tcl_wordBreakAfter, and
270 tcl_wordBreakBefore commands.
271
272 tcl_nonwordchars
273 This variable contains a regular expression that is used by rou‐
274 tines like tcl_endOfWord to identify whether a character is part
275 of a word or not. If the pattern matches a character, the char‐
276 acter is considered to be a non-word character. On Windows
277 platforms, spaces, tabs, and newlines are considered non-word
278 characters. Under Unix, everything but numbers, letters and
279 underscores are considered non-word characters.
280
281 tcl_wordchars
282 This variable contains a regular expression that is used by rou‐
283 tines like tcl_endOfWord to identify whether a character is part
284 of a word or not. If the pattern matches a character, the char‐
285 acter is considered to be a word character. On Windows plat‐
286 forms, words are comprised of any character that is not a space,
287 tab, or newline. Under Unix, words are comprised of numbers,
288 letters or underscores.
289
291 env(n), info(n), re_syntax(n)
292
294 auto-exec, auto-load, library, unknown, word, whitespace
295
296
297
298Tcl 8.0 library(n)