'\" '\" 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.2 2003/11/24 05:09:59 bbbush Exp $ '\" The definitions below are for supplemental macros used in Tcl/Tk '\" manual entries. '\" '\" .AP type name in/out ?indent? '\" Start paragraph describing an argument to a library procedure. '\" type is type of argument (int, etc.), in/out is either "in", "out", '\" or "in/out" to describe whether procedure reads or modifies arg, '\" and indent is equivalent to second arg of .IP (shouldn't ever be '\" needed; use .AS below instead) '\" '\" .AS ?type? ?name? '\" Give maximum sizes of arguments for setting tab stops. Type and '\" name are examples of largest possible arguments that will be passed '\" to .AP later. If args are omitted, default tab stops are used. '\" '\" .BS '\" Start box enclosure. From here until next .BE, everything will be '\" enclosed in one large box. '\" '\" .BE '\" End of box enclosure. '\" '\" .CS '\" Begin code excerpt. '\" '\" .CE '\" End code excerpt. '\" '\" .VS ?version? ?br? '\" Begin vertical sidebar, for use in marking newly-changed parts '\" of man pages. The first argument is ignored and used for recording '\" the version when the .VS was added, so that the sidebars can be '\" found and removed when they reach a certain age. If another argument '\" is present, then a line break is forced before starting the sidebar. '\" '\" .VE '\" End of vertical sidebar. '\" '\" .DS '\" Begin an indented unfilled display. '\" '\" .DE '\" End of indented unfilled display. '\" '\" .SO '\" Start of list of standard options for a Tk widget. The '\" options follow on successive lines, in four columns separated '\" by tabs. '\" '\" .SE '\" End of list of standard options for a Tk widget. '\" '\" .OP cmdName dbName dbClass '\" Start of description of a specific option. cmdName gives the '\" option's name as specified in the class command, dbName gives '\" the option's name in the option database, and dbClass gives '\" the option's class in the option database. '\" '\" .UL arg1 arg2 '\" Print arg1 underlined, then print arg2 normally. '\" '\" RCS: @(#) $Id: library.n,v 1.2 2003/11/24 05:09:59 bbbush Exp $ '\" '\" # Set up traps and other miscellaneous stuff for Tcl/Tk man pages. .if t .wh -1.3i ^B .nr ^l \n(.l .ad b '\" # Start an argument description .de AP .ie !"\\$4"" .TP \\$4 .el \{\ . ie !"\\$2"" .TP \\n()Cu . el .TP 15 .\} .ta \\n()Au \\n()Bu .ie !"\\$3"" \{\ \&\\$1 \\fI\\$2\\fP (\\$3) .\".b .\} .el \{\ .br .ie !"\\$2"" \{\ \&\\$1 \\fI\\$2\\fP .\} .el \{\ \&\\fI\\$1\\fP .\} .\} .. '\" # define tabbing values for .AP .de AS .nr )A 10n .if !"\\$1"" .nr )A \\w'\\$1'u+3n .nr )B \\n()Au+15n .\" .if !"\\$2"" .nr )B \\w'\\$2'u+\\n()Au+3n .nr )C \\n()Bu+\\w'(in/out)'u+2n .. .AS Tcl_Interp Tcl_CreateInterp in/out '\" # BS - start boxed text '\" # ^y = starting y location '\" # ^b = 1 .de BS .br .mk ^y .nr ^b 1u .if n .nf .if n .ti 0 .if n \l'\\n(.lu\(ul' .if n .fi .. '\" # BE - end boxed text (draw box now) .de BE .nf .ti 0 .mk ^t .ie n \l'\\n(^lu\(ul' .el \{\ .\" Draw four-sided box normally, but don't draw top of .\" box if the box started on an earlier page. .ie !\\n(^b-1 \{\ \h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul' .\} .el \}\ \h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul' .\} .\} .fi .br .nr ^b 0 .. '\" # VS - start vertical sidebar '\" # ^Y = starting y location '\" # ^v = 1 (for troff; for nroff this doesn't matter) .de VS .if !"\\$2"" .br .mk ^Y .ie n 'mc \s12\(br\s0 .el .nr ^v 1u .. '\" # VE - end of vertical sidebar .de VE .ie n 'mc .el \{\ .ev 2 .nf .ti 0 .mk ^t \h'|\\n(^lu+3n'\L'|\\n(^Yu-1v\(bv'\v'\\n(^tu+1v-\\n(^Yu'\h'-|\\n(^lu+3n' .sp -1 .fi .ev .\} .nr ^v 0 .. '\" # Special macro to handle page bottom: finish off current '\" # box/sidebar if in box/sidebar mode, then invoked standard '\" # page bottom macro. .de ^B .ev 2 'ti 0 'nf .mk ^t .if \\n(^b \{\ .\" Draw three-sided box if this is the box's first page, .\" draw two sides but no top otherwise. .ie !\\n(^b-1 \h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\h'|0u'\c .el \h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\h'|0u'\c .\} .if \\n(^v \{\ .nr ^x \\n(^tu+1v-\\n(^Yu \kx\h'-\\nxu'\h'|\\n(^lu+3n'\ky\L'-\\n(^xu'\v'\\n(^xu'\h'|0u'\c .\} .bp 'fi .ev .if \\n(^b \{\ .mk ^y .nr ^b 2 .\} .if \\n(^v \{\ .mk ^Y .\} .. '\" # DS - begin display .de DS .RS .nf .sp .. '\" # DE - end display .de DE .fi .RE .sp .. '\" # SO - start of list of standard options .de SO .SH "STANDARD OPTIONS" .LP .nf .ta 5.5c 11c .ft B .. '\" # SE - end of list of standard options .de SE .fi .ft R .LP See the \\fBoptions\\fR manual entry for details on the standard options. .. '\" # OP - start of full description for a single option .de OP .LP .nf .ta 4c Command-Line Name: \\fB\\$1\\fR Database Name: \\fB\\$2\\fR Database Class: \\fB\\$3\\fR .fi .IP .. '\" # CS - begin code excerpt .de CS .RS .nf .ta .25i .5i .75i 1i .. '\" # CE - end code excerpt .de CE .fi .RE .. .de UL \\$1\l'|0\(ul'\\$2 .. .TH library 3tcl "8.0" Tcl "Tcl Built-In Commands" .BS .SH NAME auto_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" .PP Tcl 爲公共需求的功能包含了一個 Tcl 過程庫。在 Tcl 庫中定義的過程是適用於多種不同的應用的通用過程。用 \fBinfo library\fR 命令返回 Tcl 庫的位置。除了這個 Tcl 庫之外,每個應用通常都有它自己的支持過程庫;這個庫的位置通常用 \fB$\fIapp\fB_library\fR 全局變量的值給出,這裏 \fIapp\fR 是應用的名字。例如,Tk 庫的位置保持在變量 \fB$tk_library\fR 中。 .PP 要訪問在 Tcl 庫中的過程,一個應用應該 source (載入)庫中的文件 \fBinit.tcl\fR,例如,Tcl 命令 .CS \fBsource [file join [info library] init.tcl]\fR .CE 如果在一個應用的 \fBTcl_AppInit \fR過程中調用了庫過程 \fBTcl_Init\fR,則這(個加載)將自動發生。在 \fBinit.tcl\fR 中的代碼將定義 \fBunknown\fR 過程和使用下面定義的自動裝載機制安排其他過程在需要時裝載。 .SH "命令過程 COMMAND PROCEDURES" .PP 在 Tcl 庫中提供了下列過程: .TP \fBauto_execok \fIcmd\fR 確定是否有一個叫 \fIcmd \fR的一個可執行文件或 shell 內置命令。如果有,它返回要傳遞給 \fBexec\fR 來執行這個叫 \fIcmd\fR\fI \fR的可執行文件或 shell 內置命令的那些參數的一個列表。如果沒有,它返回一個空串。這個命令檢查在當前查找路徑中目錄(由 PATH 環境變量給出),在其中查找叫 \fIcmd\fR 的一個可執行文件。在 Windows 平臺上,查找被展開爲相同的目錄和與 \fBexec\fR 使用相同的文件名擴展。 \fBAuto_exec\fR 在一個叫 \fBauto_execs\fR\fB \fR的數組中記住以前查找的信息;這避免在將來調用相同的 \fIcmd\fR 時進行路徑查找。可以使用命令 \fBauto_reset\fR 來強迫 \fBauto_execok\fR 忘掉緩存的信息。 .TP \fBauto_import \fIpattern\fR 在 \fBnamespace import\fR 期間調用 \fBAuto_import\fR 來查看用 \fIpattern\fR 指定的導入命令是否駐留在一個 自動裝載的庫中。如果是,則裝載這個命令,這樣要建立導入連接的解釋器就可以獲得它們。如果這個命令不駐留在自動裝載庫中,\fBauto_import\fR 什麼都不做。 .TP \fBauto_load \fIcmd\fR 這個命令嘗試裝載一個叫做 \fIcmd\fR 的 Tcl 命令的定義,它查找一個\fB自動裝載路徑\fR,它是一個或多個目錄的一個列表。如果全局變量 \fB$auto_path\fR 存在的話,則它給出這個自動裝載路徑。如果沒有 \fB$auto_path\fR 變量,則若 TCLLIBPATH 環境變量存在則使用它。否則自動裝載路徑只包含 Tcl 庫目錄。在自動裝載路徑中的每個目錄中必須有描述在這個目錄中定義的一個或多個命令的一個文件 \fBtclIndex\fR,和要被求值來裝載每個命令的一個腳本。應當使用 \fBauto_mkindex\fR 命令來自動生成 \fBtclIndex\fR 文件。如果在一個索引文件中找到 \fIcmd\fR ,則求值適當的腳本來建立這個命令。如果成功的建立了 \fIcmd\fR,則 \fBauto_load\fR 命令返回 1。如果沒有給 \fIcmd\fR 的索引條目或這個腳本實際上定義的不是 \fIcmd\fR(例如,因爲索引信息過時了),這個命令返回 0。如果在處理這個腳本的時候發生了一個錯誤,則返回這個錯誤。\fBAuto_load\fR 只讀這個索引文件一次並把它保存到數組 \fBauto_index\fR\fB \fR中;以後對 \fBauto_load\fR 的調用將在這個數組中檢查 \fIcmd\fR 而不是重讀索引文件。可以用命令 \fBauto_reset \fR刪除緩存的索引信息。這將強制下一個 \fBauto_load\fR 命令從磁盤重新裝載索引數據庫。 .TP \fBauto_mkindex \fIdir pattern pattern ...\fR 生成適合於 \fBauto_load \fR使用的一個索引。這個命令在 \fIdir\fR 中查找名字匹配任何 \fIpattern\fR 參數的所有文件(使用 \fBglob\fR 命令進行匹配),生成在所有匹配的文件的中定義的所有 Tcl 命令過程的一個索引,並且在 \fIdir\fR 中的一個叫 \fBtclIndex \fR的文件中存儲索引信息。如果未給出模式,則假定模式是 \fB*.tcl\fR,例如 .RS .CS \fBauto_mkindex foo *.tcl\fR .CE .LP 將在子目錄讀 \fBfoo\fR 中讀取所有 \fB.tcl\fR 文件並生成一個新索引文件 \fBfoo/tclIndex\fR。 .PP \fBAuto_mkindex\fR 通過把 Tcl 腳本載入(source)到一個從解釋器中來分析它們並監視執行的 proc 和 namespace 命令。擴展可以使用(沒有文檔) auto_mkindex_parser 包來註冊對 auto_load 索引有所貢獻的其他命令。你必須閱讀 auto.tcl 來查看這是如何工作的。 .PP \fBAuto_mkindex_old\fR 在一個相對不復雜的方式分析 Tcl 腳本: 如果任何一行包含字 \fBproc\fR 爲它的第一個字,則假定它爲一個過程定義並接受這一行的下一個字爲這個過程的名字。不是以這種方式出現的過程定義(比如,在 \fBproc \fR前面有空格)將不被編排索引。如果你的腳本包含“危險”代碼,比如全局初始化代碼或有特殊字符如 \fB$\fR、\fB*\fR、\fB[\fR 或 \fB]\fR 的過程名字,則你使用 auto_mkindex_old 是更安全的。 .RE .TP \fBauto_reset\fR 銷燬被 \fBauto_execok\fR 和 \fBauto_load \fR緩存的所有信息。下次需要這些信息的時候將從磁盤重新讀取。\fBAuto_reset\fR 還刪除在 auto-load 中列出的所有過程,這樣下次使用它們的時候將裝載它們的刷新了的複本。 .TP \fBauto_qualify \fIcommand namespace\fR 計算 \fIcommand \fR的完全限定的名字的一個列表。這個列表鏡像標準 Tcl 解釋器用以查找命令的那個路徑: 首先它在當前名字空間中查找這個命令,接着在全局名字空間中。相應的,如果 \fIcommand\fR 是相對的並且 \fInamespace\fR 不是 \fB::\fR,則返回的這個列表兩個元素: 一個是由 \fInamespace\fR 界定範圍的\fIcommand\fR,如同它是一個在 \fInamespace\fR 名字空間中的命令一樣;而另一個 \fIcommand\fR 如同在全局名字空間中的一個命令一樣。否則,如果 \fIcommand\fR 是絕對的(它以 \fB:: \fR爲開始),或者 \fInamespace\fR 是 \fB::\fR,則這個列表只包含一個 \fIcommand\fR ,如同它是一個在全局名字空間中的命令一樣。 .RS .PP 在 Tcl 中自動裝載設施使用 \fBAuto_qualify\fR,用來生成自動裝載索引如 \fIpkgIndex.tcl\fR,和用來在運行時進行實際的函數自動裝載。 .RE .TP \fBtcl_findLibrary \fIbasename version patch initScript enVarName varName\fR 這個命令是擴展在它們的初始化期間使用的一個標準查找過程。擴展調用這個過程來在多個標準路徑中查找它們的過程。目錄名字的最後的構成部分通常是 \fIbasenameversion\fR (例如,tk8.0),但在建造等級上他可能是“庫”。一旦找到就把 \fIinitScript\fR 文件 source(加載)到解釋器中。把在其中找到文件的那個目錄保存到全局變量 \fIvarName\fR 中。如果已經定義這個變量(比如,在應用初始化期間用 C 代碼),則不進行查找。否則在以下這些目錄中進行查找: 由環境變量 \fIenVarName \fR給出名字的目錄;相對於 Tcl 庫的目錄;相對於(??? relative to)在標準安裝 bin 或 bin/\fIarch\fR 中的可執行文件的目錄;相對於在當前建造樹中的可執行文件的目錄;相對於在並行建造樹中的可執行文件的目錄。 .TP \fBparray \fIarrayName\fR 把數組 \fIarrayName\fR 中的所有元素的名字和值輸出到標準輸出上。\fBArrayName\fR 必須是一個對於 \fBparray \fR的調用者是可以訪問的一個數組。它可以是局部的或全局的。 .TP \fBtcl_endOfWord \fIstr start\fR .VS 返回字符串 \fIstr\fR 中在起始索引 \fIstart\fR 之後出現的第一個字結束(end-of-word)位置的的索引。定義字結束位置爲在起始點之後跟隨在第一個單字字符後面的第一個非字字符。如果在起始點之後沒有字結束位置則返回 -1。關於 Tcl 如何確定哪個字符是單字字符的詳情參見下面對 \fBtcl_wordchars\fR 和 \fBtcl_nonwordchars\fR 的描述。 .TP \fBtcl_startOfNextWord \fIstr start\fR 返回字符串 \fIstr\fR 中在起始索引 \fIstart\fR 之後出現的第一個字開始(start-of-word)位置的的索引。定義字開始位置爲跟隨在一個非字字符後面的第一個單字字符。如果在起始點之後沒有字開始位置則返回 -1。 .TP \fBtcl_startOfPreviousWord \fIstr start\fR 返回字符串 \fIstr\fR 中在起始索引 \fIstart\fR 之前出現的第一個字開始(start-of-word)位置的的索引。如果在起始點之前沒有字開始位置則返回 -1。 .TP \fBtcl_wordBreakAfter \fIstr start\fR 返回字符串 \fIstr\fR 中在起始索引 \fIstart\fR 之後出現的第一個字邊界的索引。如果在給定字符串中在起始點之後沒有邊界則返回 -1。返回的索引參照組成一個邊界(字符)對的第二個字符。 .TP \fBtcl_wordBreakBefore \fIstr start\fR 返回字符串 \fIstr\fR 中在起始索引 \fIstart\fR 之前出現的第一個字邊界的索引。如果在給定字符串中在起始點之前沒有邊界則返回 -1。返回的索引參照組成一個邊界(字符)對的第二個字符。 .VE .SH "變量 VARIABLES" .PP 在 Tcl 庫中的過程定義或使用下列全局變量: .TP \fBauto_execs\fR 用它來記錄關於特定命令是否存在爲可執行文件的信息。 .TP \fBauto_index\fR \fBauto_load\fR 用它來保存從磁盤讀來的索引信息。 .TP \fBauto_noexec\fR 如果設置了任何值,則 \fBunknown\fR 不嘗試自動執行任何命令。 .TP \fBauto_noload\fR 如果設置了任何值,則 \fBunknown\fR 不嘗試自動裝載任何命令。 .TP \fBauto_path\fR 如果設置了它,則它必須包含一個有效的 Tcl 列表,給出在自動裝載操作中要查找的目錄。在啓動期間初始化這個變量爲依次包含: 在 TCLLIBPATH 環境變量中列出的目錄,由 $tcl_library 變量命名的目錄,$tcl_library 的父目錄,在 $tcl_pkgPath 變量中列出的目錄。 .TP \fBenv(TCL_LIBRARY)\fR 如果設置了它,則它指定包含庫腳本的目錄的位置(這個變量的值將被賦予 \fBtcl_library\fR 變量並被 \fBinfo library \fR命令所返回)。如果這個變量未被設置,則使用缺省的值。 .TP \fBenv(TCLLIBPATH)\fR 如果設置了它,則它必須包含一個有效的 Tcl 列表,給出在自動裝載操作期間要查找的目錄。必須用 Tcl 格式指定目錄,使用“/”作爲分隔符而不管是在什麼平臺上。只在初始化 \fBauto_path\fR 的時候使用這個變量。 .TP \fBtcl_nonwordchars\fR .VS 這個變量包含一個正則表達式,用於象 \fBtcl_endOfWord\fR 這樣的例程來識別一個字符是否是一個字的一部分。如果這個模式匹配一個字符,則把這個字符作爲一個非字(non-word)字符對待。在 Windows 平臺上,空格、tab、和換行被作爲非字字符對待。在 Unix 下,除了數字、字母和下劃線之外,所有字符都是非字字符。 .TP \fBtcl_wordchars\fR 這個變量包含一個正則表達式,用於象 \fBtcl_endOfWord\fR 這樣的例程來識別一個字符是否是一個字的一部分。如果這個模式匹配一個字符,則把這個字符作爲一個單字字符對待。在 Windows 平臺上,字有任何不是空格、tab、或換行的字符組成。在 Unix 下,字由數字、字母或下劃線組成。 .VE .TP \fBunknown_pending\fR \fB unknown\fR 用它來記錄正在查找的命令。在 \fBunknown\fR 在自身上無窮遞歸的地方,使用它來檢測錯誤。在 \fBunknown\fR 返回前刪除它的值。 .SH "參見 SEE ALSO" info(n), re_syntax(n) .SH "關鍵字 KEYWORDS" auto-exec, auto-load, library, unknown, word, whitespace .SH "[中文版維護人]" .B 寒蟬退士 .SH "[中文版最新更新]" .B 2001/12/06 .SH "《中國 Linux 論壇 man 手冊頁翻譯計劃》:" .BI http://cmpp.linuxforum.net .SH "跋" .br 本頁面中文版由中文 man 手冊頁計劃提供。 .br 中文 man 手冊頁計劃:\fBhttps://github.com/man-pages-zh/manpages-zh\fR