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

📄 reftcl.tex

📁 很不错的tcl编程实例
💻 TEX
📖 第 1 页 / 共 2 页
字号:

\Xi{\kwd{puts} [|-nonewline|] [<fileId>] <string>}
Write string to <fileId> (default |stdout|) optionally omitting newline char.

\Xi{\kwd{read} [|-nonewline|] <fileId>}
Read all remaining bytes from <fileId>, optionally discarding last
character if it is a newline.

\Xi{\kwd{read} <fileId> <numBytes>}
Read <numBytes> bytes from <fileId>.

\Xi{\kwd{seek} <fileId> <offset> [<origin>]}
Change current access position on <fileId>  to <offset> bytes from <origin>
which may be |start|, |current|, or |end|.

\Xi{\kwd{tell} <fileId>}
Return current access position in <fileId>.

\end{enum}

\section{Lists}

\begin{enum}{1cm}

\Xi{\kwd{concat} [<arg> <arg> ...]}
Returns concatenation of each list <arg> as a single list.

\Xi{\kwd{join} <list> [<joinString>]}
Returns string created by joining all elements of <list> with <joinString>.

\Xi{\kwd{lappend} <varName> [<value> <value> ...]}
Appends each <value> to the end of the list stored in <varName>.

\Xi{\kwd{lindex} <list> <index>}
Returns value of element at <index> in <list>.

\Xi{\kwd{linsert} <list> <index> <element> [<element> ...]}
Returns new list formed by inserting given new elements at <index> in <list>.

\Xi{\kwd{list} [<arg> <arg> ...]}
Returns new list formed by using each <arg> as an element.

\Xi{\kwd{llength} <list>}
Returns number of elements in <list>.

\Xi{\kwd{lrange} <list> <first> <last>}
Returns new list from slice of <list> at indices <first> through
<last> inclusive.

\Xi{\kwd{lsearch} [<mode>] <list> <pattern>}
Returns index of first element in <list> that matches <pattern> (-1 for 
no match).  Mode may be |-exact|, |-glob| (default), or |-regexp|.

\Xi{\kwd{lsort} [<switches>] <list>}
Returns new list formed by sorting <list> according to <switches>. These are

\begin{enum}{3.5cm}
\Xi{\quad |-ascii|} string comparsion (default)
\Xi{\quad |-integer|} integer comparison 
\Xi{\quad |-real|} floating-point comparision
\Xi{\quad |-increasing|} sort in increasing order (default)
\Xi{\quad |-decreasing|} sort in decreasing order
\Xi{\quad |-command| <cmd>} Use <command> which takes two arguments
and returns an integer less than, equal to, or greater than zero.
\end{enum}

\Xi{\kwd{split} <string> [<splitChars>]}
Returns a list formed by splitting <string> at each character in <splitChars>.

\end{enum}

{\bf Note:} list indices start at 0 and the word |end| may be
used to reference the last element in the list.

\section{Arrays}

\begin{enum}{1cm}

\Xi{\kwd{array anymore} <arrayName> <searchId>}
Returns 1 if anymore elements are left to be processed in array search
<searchId> on <arrayName>, 0 otherwise.

\Xi{\kwd{array donesearch} <arrayName> <searchId>}
Terminates the array search <searchId> on <arrayName>.

\Xi{\kwd{array exists} <arrayName>}
Returns 1 if <arrayName> is an array variable, 0 otherwise.

\Xi{\kwd{array get} <arrayName>}
Returns a list where each odd element is an element name and the
following even element its corresponding value.

\Xi{\kwd{array names} <arrayName> [<pattern>]}
Returns list of all element names in <arrayName> that match glob <pattern>.

\Xi{\kwd{array nextelement} <arrayName> <searchId>}
Returns name of next element in <arrayName> for the search <searchId>.

\Xi{\kwd{array set} <arrayName> <list>}
Sets values of elements in <arrayName> for list in \kwd{array get} format.

\Xi{\kwd{array size} <arrayName>}
Return number of elements in <arrayName>.

\Xi{\kwd{array startsearch} <arrayName>}
Returns a search id to use for an element-by-element search of <arrayName>.

\Xi{\kwd{parray} <arrayName>}
Print to standard output the names and values in <arrayName>.

\end{enum}

\section{Strings}

\begin{enum}{1cm}

\Xi{\kwd{append} <varName> [<value> <value> ...]}
Appends each of the given values to the string stored in <varName>.

\Xi{\kwd{format} <formatString> [<arg> <arg> ...]}
Returns a formated string generated in the ANSI C {\bf sprintf} manner.

\Xi{\kwd{regexp} [<switches>] <exp> <string> [<matchVar>] [<subMatchVar> ...]}
Returns 1 if the regular expression <exp> matches part or all of
<string> , 0 otherwise. If specified, <matchVar> will be set to all the
characters in the match and the following <subMatchVar>'s will be set to
matched parenthesized subexpressions. The |-nocase| switch can be
specified to ignore case in matching. The |-indices| switch can be
specified so that <matchVar> and <subMatchVar> will be set to the
start and ending indices in <string> of their corresponding match.

\Xi{\kwd{regsub} [<switches>] <exp> <string> <subSpec> <varName>}
Replaces the first portion of <string> that matches the regular expression
<exp> with <subSpec> and places results in <varName>. Returns count
of number of replacements made. The |-nocase| switch can be
specified to ignore case in matching. The |-all| switch will cause
all matches to be substituted for.

\Xi{\kwd{scan} <string> <formatString> <varName> [<varName> ...]}
Extracts values into given variables using ANSI C {\bf sscanf} behavior.

\Xi{\kwd{string compare} <string1> <string2>}
Returns -1, 0, or 1, depending on whether <string1> is lexicographically
less than, equal to, or greater than <string2>.

\Xi{\kwd{string first} <string1> <string2>}
Return index in <string2> of first occurance of <string1> (-1 if not found).

\Xi{\kwd{string index} <string> <charIndex>}
Returns the <charIndex>'th character in <string>.

\Xi{\kwd{string last} <string1> <string2>}
Return index in <string2> of last occurance of <string1> (-1 if not found).

\Xi{\kwd{string length} <string>}
Returns the number of characters in <string>.

\Xi{\kwd{string match} <pattern> <string>}
Returns 1 if glob <pattern> matches <string>, 0 otherwise.

\Xi{\kwd{string range} <string> <first> <last>}
Returns characters from <string> at indices <first> through <last> inclusive.

\Xi{\kwd{string tolower} <string>}
Returns new string formed by converting all chars in <string> to lower case.

\Xi{\kwd{string toupper} <string>}
Returns new string formed by converting all chars in <string> to upper case.

\Xi{\kwd{string trim} <string> [<chars>]}
Returns new string formed by removing from <string> any leading or trailing 
characters present in the set <chars>.

\Xi{\kwd{string trimleft} <string> [<chars>]}
Same as \kwd{string trim} for leading characters only.

\Xi{\kwd{string trimright} <string> [<chars>]}
Same as \kwd{string trim} for trailing  characters only.

\Xi{\kwd{string wordend} <string> <index>}
Returns index of character just after last one in word at <index> in <string>.

\Xi{\kwd{string wordstart} <string> <index>}
Returns index of first character of word at <index> in <string>.

\Xi{\kwd{subst} <string>}
Returns result of backslash, command, and variable
substitutions on <string>.

\end{enum}

\section{System Interaction}

\begin{enum}{1cm}

\Xi{\kwd{cd} [<dirName>]}
Change working directory to <dirName>.

\Xi{\kwd{exec} [|-keepnew|] <arg> [<arg> ...]}
Execute subprocess using each <arg> as word for a shell pipeline and
return results written to standard out, optionally retaining the final
newline char.  The following constructs can be used to control I/O flow.
\begin{enum}{4cm}
\Xi{\quad \|}			 pipe (stdout)
\Xi{\quad \|\&}		 	 pipe (stdout and stderr)
\Xi{\quad \lt <fileName>}	 stdin from file
\Xi{\quad {\lt}@ <fileId>}	 stdin from open file
\Xi{\quad \lt\lt <value>}	 pass value to stdin
\Xi{\quad \gt <fileName>}	 stdout to file
\Xi{\quad 2\gt <fileName>}	 stderr to file
\Xi{\quad \gt\& <fileName>}	 stdout and stderr to file
\Xi{\quad \gt\gt <fileName>}	 append stdout to file
\Xi{\quad 2\gt\gt <fileName>}	 append stderr to file
\Xi{\quad \gt\gt\& <fileName>}   stdout and stderr to file
\Xi{\quad {\gt}@ <fileId>}	 stdout to open file
\Xi{\quad 2{\gt}@ <fileId>}	 stderr to open file
\Xi{\quad \gt\&@ <fileId>}	 stdout and stderr to open file
\Xi{\quad \&}			 run in background
\end{enum}


\Xi{\kwd{glob} [|-nocomplain|] <pattern> [<pattern> ...]}
Returns list of all files in current directory that match any of
the given csh-style glob patterns, optionally suppressing error on no match.

\Xi{\kwd{pid} [<fileId>]}
Return process id of process pipeline <fileId> if given, otherwise
return process id of interpreter process.

\Xi{\kwd{pwd}}
Returns the current working directory.

\end{enum}

\section{Command History}

\begin{enum}{1cm}

\Xi{\kwd{history}}
Same as \kwd{history info}.

\Xi{\kwd{history add} <command> [|exec|]}
Adds <command> to history list, optionally executing it.

\Xi{\kwd{history change} <newValue> [<event>]}
Replaces value of <event> (default current) in history with <newValue>.

\Xi{\kwd{history event} [<event>]}
Returns value of <event> (default -1) in history.

\Xi{\kwd{history info} [<count>]}
Returns event number and contents of the last <count> events.

\Xi{\kwd{history keep} [<count>]}
Set number of events to retain in history to <count>.

\Xi{\kwd{history nextid}}
Returns number for next event to be recorded in history.

\Xi{\kwd{history redo} [<event>]}
Re-executes <event> (default -1).

\Xi{\kwd{history substitute} <old> <new> [<event>]}
Re-executes <event> (default -1) replacing any occurance of string
<old> with <new> in <event>'s value.

\Xi{\kwd{history words} <selector> [<event>]}
Returns the <selector>'th word in value of <event> if <selector> is
a number or the last word if <selector> is \$. Otherwise, <selector>
is treated as a glob pattern, and words that match it are returned.

\end{enum}

\section{Other Tcl Commands}

\begin{enum}{1cm}

\Xi{\kwd{auto\_execok} <execFile>}
Returns 1 if an executable file by the name <execFile> exists in user's PATH.

\Xi{\kwd{auto\_load} <cmd>}
Attempts to load definition for <cmd> by searching {\tt \$auto\_path} and
{\tt \$env(TCLLIBPATH)} for a tclIndex file which will inform the interpreter
where it can find <cmd>'s definition.

\Xi{\kwd{auto\_mkindex} <directory> <pattern> [<pattern> ...]}
Generate a tclIndex file by search all files in <directory> that match
<pattern> for Tcl procedure definitions.

\Xi{\kwd{auto\_reset}}
Destroys cached information used by \kwd{auto\_execok} and \kwd{auto\_load}.

\Xi{\kwd{catch} <script> [<varName>]}
Evaluate <script> storing results into <varName>. If there is an error in
evaluation, a non-zero error code is returned and an error message stored in <varName>.

\Xi{\kwd{error} <message> [<info>] [<code>]}
Interrupt command interpretation with an error described in
<message>. Global variables |errorInfo| and |errorCode| will be set to
<info> and <code> respectively, if given.

\Xi{\kwd{eval} <arg> [<arg> ...]}
Returns result of evaluating the concatenation of <args>'s as a Tcl command.

\Xi{\kwd{expr} <arg> [<arg> ...]}
Returns result of evaluating the concatenation of <arg>'s as an
operator expression. See {\sl Operators} for more info.

\Xi{\kwd{global} <varName> [<varName> ...]}
Declares given <varName>'s as global variables.

\Xi{\kwd{incr} <varName> [<increment>]}
Increment the integer value stored in <varName> by <increment> (default 1).

\Xi{\kwd{proc} <name> <args> <body>}
Create a new Tcl procedure or replace existing one.

\Xi{\kwd{rename} <oldName> <newName>}
Rename command <oldName> so it is now called <newName>. If <newName> is
the empty string, command is deleted.

\Xi{\kwd{set} <varName> [<value>]}
Store <value> in <varName> if given. Returns the current value of
<varName>.

\Xi{\kwd{source} <fileName>}
Read file <fileName> and evaluate its contents as a Tcl <script>.

\Xi{\kwd{time} <script> [<count>]}
Call interpreter <count> (default 1) times to evaluate <script>. Returns
string of the form ``{\tt 503 micoseconds per iteration}''.

\Xi{\kwd{trace variable} <varName> <ops> <command>}
Arrange for <command> to be executed whenever <varName> is accessed in
one of the ways specified with <ops>. Possbile values are |r| for read,
|w| for written, |u| for unset, and any combination of the three.

\Xi{\kwd{trace vdelete} <varName> <ops> <command>}
Remove any previous trace specified with the given arguments.

\Xi{\kwd{trace vinfo} <varName>}
Returns list where each element is sublist containing the <ops> and <command>
arguments for each trace on <varName>.

\Xi{\kwd{unknown} <cmdName> [<arg> <arg> ...]}
Called when the Tcl interpreter encounters an undefined command name.

\Xi{\kwd{unset} <varName> [<varName> ...]}
Removes the given variables and arrays from scope.

\Xi{\kwd{uplevel} [<level>] <arg> [<arg> ...]}
Evaluates concatenation of <arg>'s in the variable context indicated by
<level>, an integer that gives the distance up the calling stack.  If
<level> is preceded by ``\#'', then it gives the distance down the
calling stack from toplevel.

\Xi{\kwd{upvar} [<level>] <otherVar> <myVar> [<otherVar> <myVar> ...]}
Makes <myVar> in local scope equivalent to <otherVar> at context <level>
so they share the same storage space.

\end{enum}

⌨️ 快捷键说明

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