home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tcl2-73c.zip / tcl7.3 / doc / library.n < prev    next >
Text File  |  1993-08-28  |  9KB  |  240 lines

  1. '\"
  2. '\" Copyright (c) 1991-1993 The Regents of the University of California.
  3. '\" All rights reserved.
  4. '\"
  5. '\" Permission is hereby granted, without written agreement and without
  6. '\" license or royalty fees, to use, copy, modify, and distribute this
  7. '\" documentation for any purpose, provided that the above copyright
  8. '\" notice and the following two paragraphs appear in all copies.
  9. '\"
  10. '\" IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY
  11. '\" FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
  12. '\" ARISING OUT OF THE USE OF THIS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
  13. '\" CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  14. '\"
  15. '\" THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
  16. '\" INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
  17. '\" AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
  18. '\" ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
  19. '\" PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  20. '\" 
  21. '\" $Header: /user6/ouster/tcl/man/RCS/library.n,v 1.11 93/08/28 16:05:59 ouster Exp $ SPRITE (Berkeley)
  22. '
  23. .so man.macros
  24. .de UL
  25. \\$1\l'|0\(ul'\\$2
  26. ..
  27. .HS library tcl
  28. .BS
  29. .SH NAME
  30. library \- standard library of Tcl procedures
  31. .SH SYNOPSIS
  32. .nf
  33. \fBauto_execok \fIcmd\fR
  34. \fBauto_load \fIcmd\fR
  35. \fBauto_mkindex \fIdir pattern pattern ...\fR
  36. \fBauto_reset\fR
  37. \fBparray \fIarrayName\fR
  38. \fBunknown \fIcmd \fR?\fIarg arg ...\fR?
  39. .fi
  40. .BE
  41.  
  42. .SH INTRODUCTION
  43. .PP
  44. Tcl includes a library of Tcl procedures for commonly-needed functions.
  45. The procedures defined in the Tcl library are generic ones suitable
  46. for use by many different applications.
  47. The location of the Tcl library is returned by the \fBinfo library\fR
  48. command.
  49. In addition to the Tcl library, each application will normally have
  50. its own library of support procedures as well;  the location of this
  51. library is normally given by the value of the \fB$\fIapp\fB_library\fR
  52. global variable, where \fIapp\fR is the name of the application.
  53. For example, the location of the Tk library is kept in the variable
  54. \fB$tk_library\fR.
  55. .PP
  56. To access the procedures in the Tcl library, an application should
  57. source the file \fBinit.tcl\fR in the library, for example with
  58. the Tcl command
  59. .DS
  60. \fBsource [info library]/init.tcl
  61. .DE
  62. This will define the \fBunknown\fR procedure and arrange for the
  63. other procedures to be loaded on-demand using the auto-load
  64. mechanism defined below.
  65.  
  66. .SH "COMMAND PROCEDURES"
  67. .PP
  68. The following procedures are provided in the Tcl library:
  69. .TP
  70. \fBauto_execok \fIcmd\fR
  71. Determines whether there is an executable file by the name \fIcmd\fR.
  72. This command examines the directories in the current search path
  73. (given by the PATH enviornment variable) to see if there is an
  74. executable file named \fIcmd\fR in any of those directories.
  75. If so, it returns 1;  if not it returns 0.  \fBAuto_exec\fR
  76. remembers information about previous searches in an array
  77. named \fBauto_execs\fR;  this avoids the path search in
  78. future calls for the same \fIcmd\fR.  The command \fBauto_reset\fR
  79. may be used to force \fBauto_execok\fR to forget its cached
  80. information.
  81. .TP
  82. \fBauto_load \fIcmd\fR
  83. This command attempts to load the definition for a Tcl command named
  84. \fIcmd\fR.
  85. To do this, it searches an \fIauto-load path\fR, which is a list of
  86. one or more directories.
  87. The auto-load path is given by the global variable \fB$auto_path\fR
  88. if it exists.
  89. If there is no \fB$auto_path\fR variable, then the TCLLIBPATH environment
  90. variable is used, if it exists.
  91. Otherwise the auto-load path consists of just the Tcl library directory.
  92. Within each directory in the auto-load path there must be a file
  93. \fBtclIndex\fR that describes one
  94. .VS
  95. or more commands defined in that directory
  96. and a script to evaluate to load each of the commands.
  97. The \fBtclIndex\fR file should be generated with the
  98. \fBauto_mkindex\fR command.
  99. If \fIcmd\fR is found in an index file, then the appropriate
  100. script is evaluated to create the command.
  101. .VE
  102. The \fBauto_load\fR command returns 1 if \fIcmd\fR was successfully
  103. created.
  104. The command returns 0 if there was no index entry for \fIcmd\fR
  105. or if the script didn't actually define \fIcmd\fR (e.g. because
  106. index information is out of date).
  107. If an error occurs while processing the script, then that error
  108. is returned.
  109. \fBAuto_load\fR only reads the index information once and saves it
  110. in the array \fBauto_index\fR;  future calls to \fBauto_load\fR
  111. check for \fIcmd\fR in the array rather than re-reading the index
  112. files.
  113. The cached index information may be deleted with the command
  114. \fBauto_reset\fR.
  115. This will force the next \fBauto_load\fR command to reload the
  116. index database from disk.
  117. .TP
  118. \fBauto_mkindex \fIdir pattern pattern ...\fR
  119. .VS
  120. Generates an index suitable for use by \fBauto_load\fR.
  121. The command searches \fIdir\fR for all files whose names match
  122. any of the \fIpattern\fR arguments
  123. .VE
  124. (matching is done with the \fBglob\fR command),
  125. generates an index of all the Tcl command
  126. procedures defined in all the matching files, and stores the
  127. index information in a file named \fBtclIndex\fR in \fIdir\fR.
  128. For example, the command
  129. .RS
  130. .DS
  131. \fBauto_mkindex foo *.tcl\fR
  132. .DE
  133. .LP
  134. will read all the \fB.tcl\fR files in subdirectory \fBfoo\fR
  135. and generate a new index file \fBfoo/tclIndex\fR.
  136. .PP
  137. \fBAuto_mkindex\fR parses the Tcl scripts in a relatively
  138. unsophisticated way:  if any line contains the word \fBproc\fR
  139. as its first characters then it is assumed to be a procedure
  140. definition and the next word of the line is taken as the
  141. procedure's name.
  142. Procedure definitions that don't appear in this way (e.g. they
  143. have spaces before the \fBproc\fR) will not be indexed.
  144. .RE
  145. .TP
  146. \fBauto_reset\fR
  147. Destroys all the information cached by \fBauto_execok\fR and
  148. \fBauto_load\fR.
  149. This information will be re-read from disk the next time it is
  150. needed.
  151. \fBAuto_reset\fR also deletes any procedures listed in the auto-load
  152. index, so that fresh copies of them will be loaded the next time
  153. that they're used.
  154. .TP
  155. \fBparray \fIarrayName\fR
  156. Prints on standard output the names and values of all the elements
  157. in the array \fIarrayName\fR.
  158. \fBArrayName\fR must be an array accessible to the caller of \fBparray\fR.
  159. It may be either local or global.
  160. .TP
  161. \fBunknown \fIcmd \fR?\fIarg arg ...\fR?
  162. This procedure is invoked automatically by the Tcl interpreter
  163. whenever the name of a command doesn't exist.
  164. The \fBunknown\fR procedure receives as its arguments the
  165. name and arguments of the missing command.
  166. .VS
  167. \fBUnknown\fR first calls \fBauto_load\fR to load the command.
  168. .VE
  169. If this succeeds, then it executes the original command with its
  170. original arguments.
  171. If the auto-load fails then \fBunknown\fR calls \fBauto_execok\fR
  172. to see if there is an executable file by the name \fIcmd\fR.
  173. If so, it invokes the Tcl \fBexec\fR command
  174. with \fIcmd\fR and all the \fIargs\fR as arguments.
  175. If \fIcmd\fR can't be auto-executed, \fBunknown\fR checks to
  176. see if the command was invoked at top-level and outside of any
  177. script.  If so, then \fBunknown\fR takes takes two additional steps.
  178. First, it sees if \fIcmd\fR has one of the following three forms:
  179. \fB!!\fR, \fB!\fIevent\fR, or \fB^\fIold\fB^\fInew\fR?\fB^\fR?.
  180. If so, then \fBunknown\fR carries out history substitution
  181. in the same way that \fBcsh\fR would for these constructs.
  182. Second, and last, \fBunknown\fR checks to see if \fIcmd\fR is
  183. a unique abbreviation for an existing Tcl command.
  184. If so, it expands the command name and executes the command with
  185. the original arguments.
  186. If none of the above efforts has been able to execute
  187. the command, \fBunknown\fR generates an error return.
  188. If the global variable \fBauto_noload\fR is defined, then the auto-load
  189. step is skipped.
  190. If the global variable \fBauto_noexec\fR is defined then the
  191. auto-exec step is skipped.
  192. Under normal circumstances the return value from \fBunknown\fR
  193. is the return value from the command that was eventually
  194. executed.
  195.  
  196. .SH "VARIABLES"
  197. .PP
  198. The following global variables are defined or used by the procedures in
  199. the Tcl library:
  200. .TP
  201. \fBauto_execs\fR
  202. Used by \fBauto_execok\fR to record information about whether
  203. particular commands exist as executable files.
  204. .TP
  205. \fBauto_index\fR
  206. Used by \fBauto_load\fR to save the index information read from
  207. disk.
  208. .TP
  209. \fBauto_noexec\fR
  210. If set to any value, then \fBunknown\fR will not attempt to auto-exec
  211. any commands.
  212. .TP
  213. \fBauto_noload\fR
  214. If set to any value, then \fBunknown\fR will not attempt to auto-load
  215. any commands.
  216. .TP
  217. \fBauto_path\fR
  218. If set, then it must contain a valid Tcl list giving directories to
  219. search during auto-load operations.
  220. .TP
  221. \fBenv(TCL_LIBRARY)\fR
  222. If set, then it specifies the location of the directory containing
  223. library scripts (the value of this variable will be returned by
  224. the command \fBinfo library\fR).  If this variable isn't set then
  225. a default value is used.
  226. .TP
  227. \fBenv(TCLLIBPATH)\fR
  228. If set, then it must contain a valid Tcl list giving directories to
  229. search during auto-load operations.
  230. This variable is only used if \fBauto_path\fR is not defined.
  231. .TP
  232. \fBunknown_active\fR
  233. This variable is set by \fBunknown\fR to indicate that it is active.
  234. It is used to detect errors where \fBunknown\fR recurses on itself
  235. infinitely.
  236. The variable is unset before \fBunknown\fR returns.
  237.  
  238. .SH KEYWORDS
  239. auto-exec, auto-load, library, unknown
  240.