📄 library.n
字号:
'\"'\" Copyright (c) 1991-1993 The Regents of the University of California.'\" Copyright (c) 1994-1996 Sun Microsystems, Inc.'\"'\" See the file "license.terms" for information on usage and redistribution'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.'\" '\" SCCS: @(#) library.n 1.23 96/11/20 14:07:04.so man.macros.TH library n "8.0" Tcl "Tcl Built-In Commands".BS.SH NAMElibrary \- standard library of Tcl procedures.SH SYNOPSIS.nf\fBauto_execok \fIcmd\fR\fBauto_load \fIcmd\fR\fBauto_mkindex \fIdir pattern pattern ...\fR\fBauto_mkindex_old \fIdir pattern pattern ...\fR\fBauto_reset\fR\fBtcl_findLibrary \fIbasename version patch initScript enVarName varName\fR\fBparray \fIarrayName\fR.VS\fBtcl_endOfWord \fIstr start\fR\fBtcl_startOfNextWord \fIstr start\fR\fBtcl_startOfPreviousWord \fIstr start\fR\fBtcl_wordBreakAfter \fIstr start\fR\fBtcl_wordBreakBefore \fIstr start\fR.VE.BE.SH INTRODUCTION.PPTcl includes a library of Tcl procedures for commonly-needed functions.The procedures defined in the Tcl library are generic ones suitablefor use by many different applications.The location of the Tcl library is returned by the \fBinfo library\fRcommand.In addition to the Tcl library, each application will normally haveits own library of support procedures as well; the location of thislibrary is normally given by the value of the \fB$\fIapp\fB_library\fRglobal variable, where \fIapp\fR is the name of the application.For example, the location of the Tk library is kept in the variable\fB$tk_library\fR..PPTo access the procedures in the Tcl library, an application shouldsource the file \fBinit.tcl\fR in the library, for example withthe Tcl command.CS\fBsource [file join [info library] init.tcl]\fR.CEIf the library procedure \fBTcl_Init\fR is invoked from an application's\fBTcl_AppInit\fR procedure, this happens automatically.The code in \fBinit.tcl\fR will define the \fBunknown\fR procedureand arrange for the other procedures to be loaded on-demand usingthe auto-load mechanism defined below..SH "COMMAND PROCEDURES".PPThe following procedures are provided in the Tcl library:.TP\fBauto_execok \fIcmd\fRDetermines whether there is an executable file by the name \fIcmd\fR.This command examines the directories in the current search path(given by the PATH environment variable) to see if there is anexecutable file named \fIcmd\fR in any of those directories.If so, it returns 1; if not it returns 0. \fBAuto_exec\fRremembers information about previous searches in an arraynamed \fBauto_execs\fR; this avoids the path search infuture calls for the same \fIcmd\fR. The command \fBauto_reset\fRmay be used to force \fBauto_execok\fR to forget its cachedinformation..TP\fBauto_load \fIcmd\fRThis command attempts to load the definition for a Tcl command named\fIcmd\fR.To do this, it searches an \fIauto-load path\fR, which is a list ofone or more directories.The auto-load path is given by the global variable \fB$auto_path\fRif it exists.If there is no \fB$auto_path\fR variable, then the TCLLIBPATH environmentvariable is used, if it exists.Otherwise the auto-load path consists of just the Tcl library directory.Within each directory in the auto-load path there must be a file\fBtclIndex\fR that describes oneor more commands defined in that directoryand a script to evaluate to load each of the commands.The \fBtclIndex\fR file should be generated with the\fBauto_mkindex\fR command.If \fIcmd\fR is found in an index file, then the appropriatescript is evaluated to create the command.The \fBauto_load\fR command returns 1 if \fIcmd\fR was successfullycreated.The command returns 0 if there was no index entry for \fIcmd\fRor if the script didn't actually define \fIcmd\fR (e.g. becauseindex information is out of date).If an error occurs while processing the script, then that erroris returned.\fBAuto_load\fR only reads the index information once and saves itin the array \fBauto_index\fR; future calls to \fBauto_load\fRcheck for \fIcmd\fR in the array rather than re-reading the indexfiles.The cached index information may be deleted with the command\fBauto_reset\fR.This will force the next \fBauto_load\fR command to reload theindex database from disk..TP\fBauto_mkindex \fIdir pattern pattern ...\fRGenerates an index suitable for use by \fBauto_load\fR.The command searches \fIdir\fR for all files whose names matchany of the \fIpattern\fR arguments(matching is done with the \fBglob\fR command),generates an index of all the Tcl commandprocedures defined in all the matching files, and stores theindex information in a file named \fBtclIndex\fR in \fIdir\fR.If no pattern is given a pattern of \fB*.tcl\fR will be assumed. For example, the command.RS.CS\fBauto_mkindex foo *.tcl\fR.CE.LPwill read all the \fB.tcl\fR files in subdirectory \fBfoo\fRand generate a new index file \fBfoo/tclIndex\fR..PP\fBAuto_mkindex\fR parses the Tcl scripts by sourcing theminto a slave interpreter and monitoring the proc andnamespace commands that are executed.Extensions can use the (undocumented)auto_mkindex_parser package to register other commands thatcan contribute to the auto_load index.You will have to read through init.tcl to see how this works..PP\fBAuto_mkindex_old\fR parses the Tcl scripts in a relativelyunsophisticated way: if any line contains the word \fBproc\fRas its first characters then it is assumed to be a proceduredefinition and the next word of the line is taken as theprocedure's name.Procedure definitions that don't appear in this way (e.g. theyhave spaces before the \fBproc\fR) will not be indexed..RE.TP\fBauto_reset\fRDestroys all the information cached by \fBauto_execok\fR and\fBauto_load\fR.This information will be re-read from disk the next time it isneeded.\fBAuto_reset\fR also deletes any procedures listed in the auto-loadindex, so that fresh copies of them will be loaded the next timethat they're used..TP\fBtcl_findLibrary \fIbasename version patch initScript enVarName varName\fRThis is a standard search procedure for use by extensions duringtheir initialization. They call this procedure to look for theirscript library in several standard directories.The last component of the name of the library directory is normally \fIbasenameversion\fP(e.g., tk8.0), but it might be "library" when in the build hierarchies.The \fIinitScript\fR file will be sourced into the interpreteronce it is found. The directory in which this file is found isstored into the global variable \fIvarName\fP.If this variable is already defined (e.g., by C code duringapplication initialization) then no searching is done.Otherwise the search looks in these directories:the directory named by the environment variable \fIenVarName\fP;relative to the Tcl library directory;relative to the executable file in the standard installationbin or bin/\fIarch\fP directory;relative to the executable file in the current build tree;relative to the executable file in a parallel build tree..TP\fBparray \fIarrayName\fRPrints on standard output the names and values of all the elementsin the array \fIarrayName\fR.\fBArrayName\fR must be an array accessible to the caller of \fBparray\fR.It may be either local or global..TP\fBtcl_endOfWord \fIstr start\fR.VSReturns the index of the first end-of-word location that occurs aftera starting index \fIstart\fR in the string \fIstr\fR. An end-of-wordlocation is defined to be the first non-word character following thefirst word character after the starting point. Returns -1 if thereare no more end-of-word locations after the starting point. See thedescription of \fBtcl_wordchars\fR and \fBtcl_nonwordchars\fR belowfor more details on how Tcl determines which characters are wordcharacters..TP\fBtcl_startOfNextWord \fIstr start\fRReturns the index of the first start-of-word location that occursafter a starting index \fIstart\fR in the string \fIstr\fR. Astart-of-word location is defined to be the first word characterfollowing a non-word character. Returns \-1 if there are no morestart-of-word locations after the starting point..TP\fBtcl_startOfPreviousWord \fIstr start\fRReturns the index of the first start-of-word location that occursbefore a starting index \fIstart\fR in the string \fIstr\fR. Returns\-1 if there are no more start-of-word locations before the startingpoint..TP\fBtcl_wordBreakAfter \fIstr start\fRReturns the index of the first word boundary after the starting index\fIstart\fR in the string \fIstr\fR. Returns \-1 if there are no moreboundaries after the starting point in the given string. The indexreturned refers to the second character of the pair that comprises aboundary..TP\fBtcl_wordBreakBefore \fIstr start\fRReturns the index of the first word boundary before the starting index\fIstart\fR in the string \fIstr\fR. Returns \-1 if there are no moreboundaries before the starting point in the given string. The indexreturned refers to the second character of the pair that comprises aboundary..VE.SH "VARIABLES".PPThe following global variables are defined or used by the procedures inthe Tcl library:.TP\fBauto_execs\fRUsed by \fBauto_execok\fR to record information about whetherparticular commands exist as executable files..TP\fBauto_index\fRUsed by \fBauto_load\fR to save the index information read fromdisk..TP\fBauto_noexec\fRIf set to any value, then \fBunknown\fR will not attempt to auto-execany commands..TP\fBauto_noload\fRIf set to any value, then \fBunknown\fR will not attempt to auto-loadany commands..TP\fBauto_path\fRIf set, then it must contain a valid Tcl list giving directories tosearch during auto-load operations..TP\fBenv(TCL_LIBRARY)\fRIf set, then it specifies the location of the directory containinglibrary scripts (the value of this variable will be returned bythe command \fBinfo library\fR). If this variable isn't set thena default value is used..TP\fBenv(TCLLIBPATH)\fRIf set, then it must contain a valid Tcl list giving directories tosearch during auto-load operations.This variable is only used if \fBauto_path\fR is not defined..TP\fBtcl_nonwordchars\fR.VSThis variable contains a regular expression that is used by routineslike \fBtcl_endOfWord\fR to identify whether a character is part of aword or not. If the pattern matches a character, the character isconsidered to be a non-word character. On Windows platforms, spaces,tabs, and newlines are considered non-word characters. Under Unix,everything but numbers, letters and underscores are considerednon-word characters..TP\fBtcl_wordchars\fRThis variable contains a regular expression that is used by routineslike \fBtcl_endOfWord\fR to identify whether a character is part of aword or not. If the pattern matches a character, the character isconsidered to be a word character. On Windows platforms, words arecomprised of any character that is not a space, tab, or newline. UnderUnix, words are comprised of numbers, letters or underscores..VE.TP\fBunknown_active\fRThis variable is set by \fBunknown\fR to indicate that it is active.It is used to detect errors where \fBunknown\fR recurses on itselfinfinitely.The variable is unset before \fBunknown\fR returns..SH KEYWORDSauto-exec, auto-load, library, unknown, word, whitespace
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -