⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 library.n

📁 tcl是工具命令语言
💻 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.'\" '\" RCS: @(#) $Id: library.n,v 1.16 2001/08/24 06:03:15 dgp Exp $.so man.macros.TH library n "8.0" Tcl "Tcl Built-In Commands".BS.SH NAMEauto_execok, auto_import, auto_load, auto_mkindex, auto_mkindex_old, auto_qualify, auto_reset, tcl_findLibrary, parray, tcl_endOfWord, tcl_startOfNextWord, tcl_startOfPreviousWord, tcl_wordBreakAfter, tcl_wordBreakBefore \- standard library of Tcl procedures.SH SYNOPSIS.nf\fBauto_execok \fIcmd\fR\fBauto_import \fIpattern\fR\fBauto_load \fIcmd\fR\fBauto_mkindex \fIdir pattern pattern ...\fR\fBauto_mkindex_old \fIdir pattern pattern ...\fR\fBauto_qualify \fIcommand namespace\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 or shell builtinby the name \fIcmd\fR.  If so, it returns a list of arguments to bepassed to \fBexec\fR to execute the executable file or shell builtinnamed by \fIcmd\fR.  If not, it returns an empty string.  This commandexamines the directories in the current search path (given by the PATHenvironment variable) in its search for an executable file named\fIcmd\fR.  On Windows platforms, the search is expanded with the samedirectories and file extensions as used by \fBexec\fR. \fBAuto_exec\fRremembers information about previous searches in an array named\fBauto_execs\fR;  this avoids the path search in future calls for thesame \fIcmd\fR.  The command \fBauto_reset\fR may be used to force\fBauto_execok\fR to forget its cached information..TP\fBauto_import \fIpattern\fR\fBAuto_import\fR is invoked during \fBnamespace import\fR to see ifthe imported commands specified by \fIpattern\fR reside in anautoloaded library.  If so, the commands are loaded so that they willbe available to the interpreter for creating the import links.  If thecommands do not reside in an autoloaded library, \fBauto_import\fRdoes nothing.  The pattern matching is performed according to thematching rules of \fBnamespace import\fR..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 isa list of one or more directories.  The auto-load path is given by theglobal variable \fB$auto_path\fR if it exists.  If there is no\fB$auto_path\fR variable, then the TCLLIBPATH environment variable isused, if it exists.  Otherwise the auto-load path consists of just theTcl library directory.  Within each directory in the auto-load paththere must be a file \fBtclIndex\fR that describes one or morecommands defined in that directory and a script to evaluate to loadeach of the commands.  The \fBtclIndex\fR file should be generatedwith the \fBauto_mkindex\fR command.  If \fIcmd\fR is found in anindex file, then the appropriate script is evaluated to create thecommand.  The \fBauto_load\fR command returns 1 if \fIcmd\fR wassuccessfully created.  The command returns 0 if there was no indexentry for \fIcmd\fR or if the script didn't actually define \fIcmd\fR(e.g. because index information is out of date).  If an error occurswhile processing the script, then that error is returned.\fBAuto_load\fR only reads the index information once and saves it inthe array \fBauto_index\fR;  future calls to \fBauto_load\fR check for\fIcmd\fR in the array rather than re-reading the index files.  Thecached index information may be deleted with the command\fBauto_reset\fR.  This will force the next \fBauto_load\fR command toreload the index database from disk..TP\fBauto_mkindex \fIdir pattern pattern ...\fRGenerates an index suitable for use by \fBauto_load\fR.  The commandsearches \fIdir\fR for all files whose names match any of the\fIpattern\fR arguments (matching is done with the \fBglob\fRcommand), generates an index of all the Tcl command procedures definedin all the matching files, and stores the index information in a filenamed \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\fR andgenerate a new index file \fBfoo/tclIndex\fR..PP\fBAuto_mkindex\fR parses the Tcl scripts by sourcing them into aslave interpreter and monitoring the proc and namespace commands thatare executed.  Extensions can use the (undocumented)auto_mkindex_parser package to register other commands that cancontribute to the auto_load index. You will have to read throughauto.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.  If your script contains "dangerous" code, such as global initializationcode or procedure names with special characters like \fB$\fR,\fB*\fR, \fB[\fR or \fB]\fR, you are safer using auto_mkindex_old..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 nexttime it is needed.  \fBAuto_reset\fR also deletes any procedureslisted in the auto-load index, so that fresh copies of them will beloaded the next time that they're used..TP\fBauto_qualify \fIcommand namespace\fRComputes a list of fully qualified names for \fIcommand\fR.  This listmirrors the path a standard Tcl interpreter follows for commandlookups:  first it looks for the command in the current namespace, andthen in the global namespace.  Accordingly, if \fIcommand\fR isrelative and \fInamespace\fR is not \fB::\fR, the list returned hastwo elements:  \fIcommand\fR scoped by \fInamespace\fR, as if it werea command in the \fInamespace\fR namespace; and \fIcommand\fR as if itwere a command in the global namespace.  Otherwise, if either\fIcommand\fR is absolute (it begins with \fB::\fR), or\fInamespace\fR is \fB::\fR, the list contains only \fIcommand\fR asif it were a command in the global namespace..RS.PP\fBAuto_qualify\fR is used by the auto-loading facilities in Tcl, bothfor producing auto-loading indexes such as \fIpkgIndex.tcl\fR, and forperforming the actual auto-loading of functions at runtime..RE.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.This variable is initialized during startup to contain, in order:the directories listed in the TCLLIBPATH environment variable,the directory named by the $tcl_library variable,the parent directory of $tcl_library,the directories listed in the $tcl_pkgPath variable..TP\fBenv(TCL_LIBRARY)\fRIf set, then it specifies the location of the directory containinglibrary scripts (the value of this variable will beassigned to the \fBtcl_library\fR variable and therefore 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.  Directories must be specified in Tcl format, using "/" as the path separator, regardless of platform.This variable is only used when initializing the \fBauto_path\fR variable..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_pending\fRUsed by \fBunknown\fR to record the command(s) for which it issearching.It is used to detect errors where \fBunknown\fR recurses on itselfinfinitely.The variable is unset before \fBunknown\fR returns..SH "SEE ALSO"info(n), re_syntax(n).SH KEYWORDSauto-exec, auto-load, library, unknown, word, whitespace 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -