diff options
Diffstat (limited to 'tcl8.6/doc')
234 files changed, 46113 insertions, 0 deletions
diff --git a/tcl8.6/doc/Access.3 b/tcl8.6/doc/Access.3 new file mode 100644 index 0000000..699d7ed --- /dev/null +++ b/tcl8.6/doc/Access.3 @@ -0,0 +1,71 @@ +'\" +'\" Copyright (c) 1998-1999 Scriptics Corporation +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH Tcl_Access 3 8.1 Tcl "Tcl Library Procedures" +.so man.macros +.BS +.SH NAME +Tcl_Access, Tcl_Stat \- check file permissions and other attributes +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +int +\fBTcl_Access\fR(\fIpath\fR, \fImode\fR) +.sp +int +\fBTcl_Stat\fR(\fIpath\fR, \fIstatPtr\fR) +.SH ARGUMENTS +.AS "struct stat" *statPtr out +.AP char *path in +Native name of the file to check the attributes of. +.AP int mode in +Mask consisting of one or more of \fBR_OK\fR, \fBW_OK\fR, \fBX_OK\fR and +\fBF_OK\fR. \fBR_OK\fR, \fBW_OK\fR and \fBX_OK\fR request checking whether the +file exists and has read, write and execute permissions, respectively. +\fBF_OK\fR just requests a check for the existence of the file. +.AP "struct stat" *statPtr out +The structure that contains the result. +.BE +.SH DESCRIPTION +.PP +As of Tcl 8.4, the object-based APIs \fBTcl_FSAccess\fR and \fBTcl_FSStat\fR +should be used in preference to \fBTcl_Access\fR and \fBTcl_Stat\fR, wherever +possible. Those functions also support Tcl's virtual filesystem layer, which +these do not. +.SS "OBSOLETE FUNCTIONS" +.PP +There are two reasons for calling \fBTcl_Access\fR and \fBTcl_Stat\fR rather +than calling system level functions \fBaccess\fR and \fBstat\fR directly. +First, the Windows implementation of both functions fixes some bugs in the +system level calls. Second, both \fBTcl_Access\fR and \fBTcl_Stat\fR (as well +as \fBTcl_OpenFileChannelProc\fR) hook into a linked list of functions. This +allows the possibility to reroute file access to alternative media or access +methods. +.PP +\fBTcl_Access\fR checks whether the process would be allowed to read, write or +test for existence of the file (or other file system object) whose name is +\fIpath\fR. If \fIpath\fR is a symbolic link on Unix, then permissions of the +file referred by this symbolic link are tested. +.PP +On success (all requested permissions granted), zero is returned. On error (at +least one bit in mode asked for a permission that is denied, or some other +error occurred), -1 is returned. +.PP +\fBTcl_Stat\fR fills the stat structure \fIstatPtr\fR with information about +the specified file. You do not need any access rights to the file to get this +information but you need search rights to all directories named in the path +leading to the file. The stat structure includes info regarding device, inode +(always 0 on Windows), privilege mode, nlink (always 1 on Windows), user id +(always 0 on Windows), group id (always 0 on Windows), rdev (same as device on +Windows), size, last access time, last modification time, and creation time. +.PP +If \fIpath\fR exists, \fBTcl_Stat\fR returns 0 and the stat structure is +filled with data. Otherwise, -1 is returned, and no stat info is given. +.SH KEYWORDS +stat, access +.SH "SEE ALSO" +Tcl_FSAccess(3), Tcl_FSStat(3) diff --git a/tcl8.6/doc/AddErrInfo.3 b/tcl8.6/doc/AddErrInfo.3 new file mode 100644 index 0000000..caba125 --- /dev/null +++ b/tcl8.6/doc/AddErrInfo.3 @@ -0,0 +1,312 @@ +'\" +'\" Copyright (c) 1989-1993 The Regents of the University of California. +'\" Copyright (c) 1994-1997 Sun Microsystems, Inc. +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH Tcl_AddErrorInfo 3 8.5 Tcl "Tcl Library Procedures" +.so man.macros +.BS +.SH NAME +Tcl_GetReturnOptions, Tcl_SetReturnOptions, Tcl_AddErrorInfo, Tcl_AppendObjToErrorInfo, Tcl_AddObjErrorInfo, Tcl_SetObjErrorCode, Tcl_SetErrorCode, Tcl_SetErrorCodeVA, Tcl_SetErrorLine, Tcl_GetErrorLine, Tcl_PosixError, Tcl_LogCommandInfo \- retrieve or record information about errors and other return options +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +Tcl_Obj * +\fBTcl_GetReturnOptions\fR(\fIinterp, code\fR) +.sp +int +\fBTcl_SetReturnOptions\fR(\fIinterp, options\fR) +.sp +\fBTcl_AddErrorInfo\fR(\fIinterp, message\fR) +.sp +\fBTcl_AppendObjToErrorInfo\fR(\fIinterp, objPtr\fR) +.sp +\fBTcl_AddObjErrorInfo\fR(\fIinterp, message, length\fR) +.sp +\fBTcl_SetObjErrorCode\fR(\fIinterp, errorObjPtr\fR) +.sp +\fBTcl_SetErrorCode\fR(\fIinterp, element, element, ... \fB(char *) NULL\fR) +.sp +\fBTcl_SetErrorCodeVA\fR(\fIinterp, argList\fR) +.sp +\fBTcl_GetErrorLine\fR(\fIinterp\fR) +.sp +\fBTcl_SetErrorLine\fR(\fIinterp, lineNum\fR) +.sp +const char * +\fBTcl_PosixError\fR(\fIinterp\fR) +.sp +void +\fBTcl_LogCommandInfo\fR(\fIinterp, script, command, commandLength\fR) +.SH ARGUMENTS +.AS Tcl_Interp commandLength +.AP Tcl_Interp *interp in +Interpreter in which to record information. +.AP int code +The code returned from script evaluation. +.AP Tcl_Obj *options +A dictionary of return options. +.AP char *message in +For \fBTcl_AddErrorInfo\fR, +this is a conventional C string to append to the \fB\-errorinfo\fR return option. +For \fBTcl_AddObjErrorInfo\fR, +this points to the first byte of an array of \fIlength\fR bytes +containing a string to append to the \fB\-errorinfo\fR return option. +This byte array may contain embedded null bytes +unless \fIlength\fR is negative. +.AP Tcl_Obj *objPtr in +A message to be appended to the \fB\-errorinfo\fR return option +in the form of a Tcl_Obj value. +.AP int length in +The number of bytes to copy from \fImessage\fR when +appending to the \fB\-errorinfo\fR return option. +If negative, all bytes up to the first null byte are used. +.AP Tcl_Obj *errorObjPtr in +The \fB\-errorcode\fR return option will be set to this value. +.AP char *element in +String to record as one element of the \fB\-errorcode\fR return option. +Last \fIelement\fR argument must be NULL. +.AP va_list argList in +An argument list which must have been initialized using +\fBva_start\fR, and cleared using \fBva_end\fR. +.AP int lineNum +The line number of a script where an error occurred. +.AP "const char" *script in +Pointer to first character in script containing command (must be <= command) +.AP "const char" *command in +Pointer to first character in command that generated the error +.AP int commandLength in +Number of bytes in command; -1 means use all bytes up to first null byte +.BE +.SH DESCRIPTION +.PP +The \fBTcl_SetReturnOptions\fR and \fBTcl_GetReturnOptions\fR +routines expose the same capabilities as the \fBreturn\fR and +\fBcatch\fR commands, respectively, in the form of a C interface. +.PP +\fBTcl_GetReturnOptions\fR retrieves the dictionary of return options +from an interpreter following a script evaluation. +Routines such as \fBTcl_Eval\fR are called to evaluate a +script in an interpreter. These routines return an integer +completion code. These routines also leave in the interpreter +both a result and a dictionary of return options generated +by script evaluation. Just as \fBTcl_GetObjResult\fR retrieves +the result, \fBTcl_GetReturnOptions\fR retrieves the dictionary +of return options. The integer completion code should be +passed as the \fIcode\fR argument to \fBTcl_GetReturnOptions\fR +so that all required options will be present in the dictionary. +Specifically, a \fIcode\fR value of \fBTCL_ERROR\fR will +ensure that entries for the keys \fB\-errorinfo\fR, +\fB\-errorcode\fR, and \fB\-errorline\fR will appear in the +dictionary. Also, the entries for the keys \fB\-code\fR +and \fB\-level\fR will be adjusted if necessary to agree +with the value of \fIcode\fR. The \fB(Tcl_Obj *)\fR returned +by \fBTcl_GetReturnOptions\fR points to an unshared +\fBTcl_Obj\fR with reference count of zero. The dictionary +may be written to, either adding, removing, or overwriting +any entries in it, without the need to check for a shared value. +As with any \fBTcl_Obj\fR with reference count of zero, it is up to +the caller to arrange for its disposal with \fBTcl_DecrRefCount\fR or +to a reference to it via \fBTcl_IncrRefCount\fR (or one of the many +functions that call that, notably including \fBTcl_SetObjResult\fR and +\fBTcl_SetVar2Ex\fR). +.PP +A typical usage for \fBTcl_GetReturnOptions\fR is to +retrieve the stack trace when script evaluation returns +\fBTCL_ERROR\fR, like so: +.PP +.CS +int code = Tcl_Eval(interp, script); +if (code == TCL_ERROR) { + Tcl_Obj *options = \fBTcl_GetReturnOptions\fR(interp, code); + Tcl_Obj *key = Tcl_NewStringObj("-errorinfo", -1); + Tcl_Obj *stackTrace; + Tcl_IncrRefCount(key); + Tcl_DictObjGet(NULL, options, key, &stackTrace); + Tcl_DecrRefCount(key); + /* Do something with stackTrace */ + Tcl_DecrRefCount(options); +} +.CE +.PP +\fBTcl_SetReturnOptions\fR sets the return options +of \fIinterp\fR to be \fIoptions\fR. If \fIoptions\fR +contains any invalid value for any key, TCL_ERROR will +be returned, and the interp result will be set to an +appropriate error message. Otherwise, a completion code +in agreement with the \fB\-code\fR and \fB\-level\fR +keys in \fIoptions\fR will be returned. +.PP +As an example, Tcl's \fBreturn\fR command itself could +be implemented in terms of \fBTcl_SetReturnOptions\fR +like so: +.PP +.CS +if ((objc % 2) == 0) { /* explicit result argument */ + objc--; + Tcl_SetObjResult(interp, objv[objc]); +} +return \fBTcl_SetReturnOptions\fR(interp, Tcl_NewListObj(objc-1, objv+1)); +.CE +.PP +(It is not really implemented that way. Internal access +privileges allow for a more efficient alternative that meshes +better with the bytecode compiler.) +.PP +Note that a newly created \fBTcl_Obj\fR may be passed +in as the \fIoptions\fR argument without the need to tend +to any reference counting. This is analogous to +\fBTcl_SetObjResult\fR. +.PP +While \fBTcl_SetReturnOptions\fR provides a general interface +to set any collection of return options, there are a handful +of return options that are very frequently used. Most +notably the \fB\-errorinfo\fR and \fB\-errorcode\fR return +options should be set properly when the command procedure +of a command returns \fBTCL_ERROR\fR. The \fB\-errorline\fR +return option is also read by commands that evaluate scripts +and wish to supply detailed error location information in +the stack trace text they append to the \fB\-errorinfo\fR option. +Tcl provides several simpler interfaces to more directly set +these return options. +.PP +The \fB\-errorinfo\fR option holds a stack trace of the +operations that were in progress when an error occurred, +and is intended to be human-readable. +The \fB\-errorcode\fR option holds a Tcl list of items that +are intended to be machine-readable. +The first item in the \fB\-errorcode\fR value identifies the class of +error that occurred +(e.g., POSIX means an error occurred in a POSIX system call) +and additional elements hold additional pieces +of information that depend on the class. +See the manual entry on the \fBerrorCode\fR variable for details on the +various formats for the \fB\-errorcode\fR option used by Tcl's built-in +commands. +.PP +The \fB\-errorinfo\fR option value is gradually built up as an +error unwinds through the nested operations. +Each time an error code is returned to \fBTcl_Eval\fR, or +any of the routines that performs script evaluation, +the procedure \fBTcl_AddErrorInfo\fR is called to add +additional text to the \fB\-errorinfo\fR value describing the +command that was being executed when the error occurred. +By the time the error has been passed all the way back +to the application, it will contain a complete trace +of the activity in progress when the error occurred. +.PP +It is sometimes useful to add additional information to +the \fB\-errorinfo\fR value beyond what can be supplied automatically +by the script evaluation routines. +\fBTcl_AddErrorInfo\fR may be used for this purpose: +its \fImessage\fR argument is an additional +string to be appended to the \fB\-errorinfo\fR option. +For example, when an error arises during the \fBsource\fR command, +the procedure \fBTcl_AddErrorInfo\fR is called to +record the name of the file being processed and the +line number on which the error occurred. +Likewise, when an error arises during evaluation of a +Tcl procedures, the procedure name and line number +within the procedure are recorded, and so on. +The best time to call \fBTcl_AddErrorInfo\fR is just after +a script evaluation routine has returned \fBTCL_ERROR\fR. +The value of the \fB\-errorline\fR return option (retrieved +via a call to \fBTcl_GetReturnOptions\fR) often makes up +a useful part of the \fImessage\fR passed to \fBTcl_AddErrorInfo\fR. +.PP +\fBTcl_AppendObjToErrorInfo\fR is an alternative interface to the +same functionality as \fBTcl_AddErrorInfo\fR. \fBTcl_AppendObjToErrorInfo\fR +is called when the string value to be appended to the \fB\-errorinfo\fR option +is available as a \fBTcl_Obj\fR instead of as a \fBchar\fR array. +.PP +\fBTcl_AddObjErrorInfo\fR is nearly identical +to \fBTcl_AddErrorInfo\fR, except that it has an additional \fIlength\fR +argument. This allows the \fImessage\fR string to contain +embedded null bytes. This is essentially never a good idea. +If the \fImessage\fR needs to contain the null character \fBU+0000\fR, +Tcl's usual internal encoding rules should be used to avoid +the need for a null byte. If the \fBTcl_AddObjErrorInfo\fR +interface is used at all, it should be with a negative \fIlength\fR value. +.PP +The procedure \fBTcl_SetObjErrorCode\fR is used to set the +\fB\-errorcode\fR return option to the list value \fIerrorObjPtr\fR +built up by the caller. +\fBTcl_SetObjErrorCode\fR is typically invoked just +before returning an error. If an error is +returned without calling \fBTcl_SetObjErrorCode\fR or +\fBTcl_SetErrorCode\fR the Tcl interpreter automatically sets +the \fB\-errorcode\fR return option to \fBNONE\fR. +.PP +The procedure \fBTcl_SetErrorCode\fR is also used to set the +\fB\-errorcode\fR return option. However, it takes one or more strings to +record instead of a value. Otherwise, it is similar to +\fBTcl_SetObjErrorCode\fR in behavior. +.PP +\fBTcl_SetErrorCodeVA\fR is the same as \fBTcl_SetErrorCode\fR except that +instead of taking a variable number of arguments it takes an argument list. +.PP +The procedure \fBTcl_GetErrorLine\fR is used to read the integer value +of the \fB\-errorline\fR return option without the overhead of a full +call to \fBTcl_GetReturnOptions\fR. Likewise, \fBTcl_SetErrorLine\fR +sets the \fB\-errorline\fR return option value. +.PP +\fBTcl_PosixError\fR +sets the \fB\-errorcode\fR variable after an error in a POSIX kernel call. +It reads the value of the \fBerrno\fR C variable and calls +\fBTcl_SetErrorCode\fR to set the \fB\-errorcode\fR return +option in the \fBPOSIX\fR format. +The caller must previously have called \fBTcl_SetErrno\fR to set +\fBerrno\fR; this is necessary on some platforms (e.g. Windows) where Tcl +is linked into an application as a shared library, or when the error +occurs in a dynamically loaded extension. See the manual entry for +\fBTcl_SetErrno\fR for more information. +.PP +\fBTcl_PosixError\fR returns a human-readable diagnostic message +for the error +(this is the same value that will appear as the third element +in the \fB\-errorcode\fR value). +It may be convenient to include this string as part of the +error message returned to the application in +the interpreter's result. +.PP +\fBTcl_LogCommandInfo\fR is invoked after an error occurs in an +interpreter. It adds information about the command that was being +executed when the error occurred to the \fB\-errorinfo\fR value, and +the line number stored internally in the interpreter is set. +.PP +In older releases of Tcl, there was no \fBTcl_GetReturnOptions\fR +routine. In its place, the global Tcl variables \fBerrorInfo\fR +and \fBerrorCode\fR were the only place to retrieve the error +information. Much existing code written for older Tcl releases +still access this information via those global variables. +.PP +It is important to realize that while reading from those +global variables remains a supported way to access these +return option values, it is important not to assume that +writing to those global variables will properly set the +corresponding return options. It has long been emphasized +in this manual page that it is important to +call the procedures described here rather than +setting \fBerrorInfo\fR or \fBerrorCode\fR directly with +\fBTcl_ObjSetVar2\fR. +.PP +If the procedure \fBTcl_ResetResult\fR is called, +it clears all of the state of the interpreter associated with +script evaluation, including the entire return options dictionary. +In particular, the \fB\-errorinfo\fR and \fB\-errorcode\fR options +are reset. +If an error had occurred, the \fBTcl_ResetResult\fR call will +clear the error state to make it appear as if no error had +occurred after all. +The global variables \fBerrorInfo\fR and +\fBerrorCode\fR are not modified by \fBTcl_ResetResult\fR +so they continue to hold a record of information about the +most recent error seen in an interpreter. +.SH "SEE ALSO" +Tcl_DecrRefCount(3), Tcl_IncrRefCount(3), Tcl_Interp(3), Tcl_ResetResult(3), +Tcl_SetErrno(3), errorCode(n), errorInfo(n) +.SH KEYWORDS +error, value, value result, stack, trace, variable diff --git a/tcl8.6/doc/Alloc.3 b/tcl8.6/doc/Alloc.3 new file mode 100644 index 0000000..8f25c52 --- /dev/null +++ b/tcl8.6/doc/Alloc.3 @@ -0,0 +1,92 @@ +'\" +'\" Copyright (c) 1995-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. +'\" +.TH Tcl_Alloc 3 7.5 Tcl "Tcl Library Procedures" +.so man.macros +.BS +.SH NAME +Tcl_Alloc, Tcl_Free, Tcl_Realloc, Tcl_AttemptAlloc, Tcl_AttemptRealloc, ckalloc, ckfree, ckrealloc, attemptckalloc, attemptckrealloc \- allocate or free heap memory +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +char * +\fBTcl_Alloc\fR(\fIsize\fR) +.sp +void +\fBTcl_Free\fR(\fIptr\fR) +.sp +char * +\fBTcl_Realloc\fR(\fIptr, size\fR) +.sp +char * +\fBTcl_AttemptAlloc\fR(\fIsize\fR) +.sp +char * +\fBTcl_AttemptRealloc\fR(\fIptr, size\fR) +.sp +char * +\fBckalloc\fR(\fIsize\fR) +.sp +void +\fBckfree\fR(\fIptr\fR) +.sp +char * +\fBckrealloc\fR(\fIptr, size\fR) +.sp +char * +\fBattemptckalloc\fR(\fIsize\fR) +.sp +char * +\fBattemptckrealloc\fR(\fIptr, size\fR) +.SH ARGUMENTS +.AS char *size +.AP "unsigned int" size in +Size in bytes of the memory block to allocate. +.AP char *ptr in +Pointer to memory block to free or realloc. +.BE + +.SH DESCRIPTION +.PP +These procedures provide a platform and compiler independent interface +for memory allocation. Programs that need to transfer ownership of +memory blocks between Tcl and other modules should use these routines +rather than the native \fBmalloc()\fR and \fBfree()\fR routines +provided by the C run-time library. +.PP +\fBTcl_Alloc\fR returns a pointer to a block of at least \fIsize\fR +bytes suitably aligned for any use. +.PP +\fBTcl_Free\fR makes the space referred to by \fIptr\fR available for +further allocation. +.PP +\fBTcl_Realloc\fR changes the size of the block pointed to by +\fIptr\fR to \fIsize\fR bytes and returns a pointer to the new block. +The contents will be unchanged up to the lesser of the new and old +sizes. The returned location may be different from \fIptr\fR. If +\fIptr\fR is NULL, this is equivalent to calling \fBTcl_Alloc\fR with +just the \fIsize\fR argument. +.PP +\fBTcl_AttemptAlloc\fR and \fBTcl_AttemptRealloc\fR are identical in +function to \fBTcl_Alloc\fR and \fBTcl_Realloc\fR, except that +\fBTcl_AttemptAlloc\fR and \fBTcl_AttemptRealloc\fR will not cause the Tcl +interpreter to \fBpanic\fR if the memory allocation fails. If the +allocation fails, these functions will return NULL. Note that on some +platforms, but not all, attempting to allocate a zero-sized block of +memory will also cause these functions to return NULL. +.PP +The procedures \fBckalloc\fR, \fBckfree\fR, \fBckrealloc\fR, +\fBattemptckalloc\fR, and \fBattemptckrealloc\fR are implemented +as macros. Normally, they are synonyms for the corresponding +procedures documented on this page. When Tcl and all modules +calling Tcl are compiled with \fBTCL_MEM_DEBUG\fR defined, however, +these macros are redefined to be special debugging versions +of these procedures. To support Tcl's memory debugging within a +module, use the macros rather than direct calls to \fBTcl_Alloc\fR, etc. + +.SH KEYWORDS +alloc, allocation, free, malloc, memory, realloc, TCL_MEM_DEBUG diff --git a/tcl8.6/doc/AllowExc.3 b/tcl8.6/doc/AllowExc.3 new file mode 100644 index 0000000..172bb30 --- /dev/null +++ b/tcl8.6/doc/AllowExc.3 @@ -0,0 +1,44 @@ +'\" +'\" Copyright (c) 1989-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. +'\" +.TH Tcl_AllowExceptions 3 7.4 Tcl "Tcl Library Procedures" +.so man.macros +.BS +.SH NAME +Tcl_AllowExceptions \- allow all exceptions in next script evaluation +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +\fBTcl_AllowExceptions\fR(\fIinterp\fR) +.SH ARGUMENTS +.AS Tcl_Interp *interp +.AP Tcl_Interp *interp in +Interpreter in which script will be evaluated. +.BE + +.SH DESCRIPTION +.PP +If a script is evaluated at top-level (i.e. no other scripts are +pending evaluation when the script is invoked), and if the script +terminates with a completion code other than \fBTCL_OK\fR, \fBTCL_ERROR\fR +or \fBTCL_RETURN\fR, then Tcl normally converts this into a \fBTCL_ERROR\fR +return with an appropriate message. The particular script +evaluation procedures of Tcl that act in the manner are +\fBTcl_EvalObjEx\fR, \fBTcl_EvalObjv\fR, \fBTcl_Eval\fR, \fBTcl_EvalEx\fR, +\fBTcl_GlobalEval\fR, \fBTcl_GlobalEvalObj\fR, \fBTcl_VarEval\fR and +\fBTcl_VarEvalVA\fR. +.PP +However, if \fBTcl_AllowExceptions\fR is invoked immediately before +calling one of those a procedures, then arbitrary completion +codes are permitted from the script, and they are returned without +modification. +This is useful in cases where the caller can deal with exceptions +such as \fBTCL_BREAK\fR or \fBTCL_CONTINUE\fR in a meaningful way. + +.SH KEYWORDS +continue, break, exception, interpreter diff --git a/tcl8.6/doc/AppInit.3 b/tcl8.6/doc/AppInit.3 new file mode 100644 index 0000000..44b2d6b --- /dev/null +++ b/tcl8.6/doc/AppInit.3 @@ -0,0 +1,83 @@ +'\" +'\" Copyright (c) 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. +'\" +.TH Tcl_AppInit 3 7.0 Tcl "Tcl Library Procedures" +.so man.macros +.BS +.SH NAME +Tcl_AppInit \- perform application-specific initialization +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +int +\fBTcl_AppInit\fR(\fIinterp\fR) +.SH ARGUMENTS +.AS Tcl_Interp *interp +.AP Tcl_Interp *interp in +Interpreter for the application. +.BE + +.SH DESCRIPTION +.PP +\fBTcl_AppInit\fR is a +.QW hook +procedure that is invoked by +the main programs for Tcl applications such as \fBtclsh\fR and \fBwish\fR. +Its purpose is to allow new Tcl applications to be created without +modifying the main programs provided as part of Tcl and Tk. +To create a new application you write a new version of +\fBTcl_AppInit\fR to replace the default version provided by Tcl, +then link your new \fBTcl_AppInit\fR with the Tcl library. +.PP +\fBTcl_AppInit\fR is invoked by \fBTcl_Main\fR and \fBTk_Main\fR +after their own initialization and before entering the main loop +to process commands. +Here are some examples of things that \fBTcl_AppInit\fR might do: +.IP [1] +Call initialization procedures for various packages used by +the application. +Each initialization procedure adds new commands to \fIinterp\fR +for its package and performs other package-specific initialization. +.IP [2] +Process command-line arguments, which can be accessed from the +Tcl variables \fBargv\fR and \fBargv0\fR in \fIinterp\fR. +.IP [3] +Invoke a startup script to initialize the application. +.IP [4] +Use the routines \fBTcl_SetStartupScript\fR and +\fBTcl_GetStartupScript\fR to set or query the file and encoding +that the active \fBTcl_Main\fR or \fBTk_Main\fR routine will +use as a startup script. +.LP +\fBTcl_AppInit\fR returns \fBTCL_OK\fR or \fBTCL_ERROR\fR. +If it returns \fBTCL_ERROR\fR then it must leave an error message in +for the interpreter's result; otherwise the result is ignored. +.PP +In addition to \fBTcl_AppInit\fR, your application should also contain +a procedure \fBmain\fR that calls \fBTcl_Main\fR as follows: +.PP +.CS +Tcl_Main(argc, argv, Tcl_AppInit); +.CE +.PP +The third argument to \fBTcl_Main\fR gives the address of the +application-specific initialization procedure to invoke. +This means that you do not have to use the name \fBTcl_AppInit\fR +for the procedure, but in practice the name is nearly always +\fBTcl_AppInit\fR (in versions before Tcl 7.4 the name \fBTcl_AppInit\fR +was implicit; there was no way to specify the procedure explicitly). +The best way to get started is to make a copy of the file +\fBtclAppInit.c\fR from the Tcl library or source directory. +It already contains a \fBmain\fR procedure and a template for +\fBTcl_AppInit\fR that you can modify for your application. + +.SH "SEE ALSO" +Tcl_Main(3) + +.SH KEYWORDS +application, argument, command, initialization, interpreter diff --git a/tcl8.6/doc/AssocData.3 b/tcl8.6/doc/AssocData.3 new file mode 100644 index 0000000..d4fa3d7 --- /dev/null +++ b/tcl8.6/doc/AssocData.3 @@ -0,0 +1,87 @@ +'\" +'\" Copyright (c) 1995-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. +'\" +.TH Tcl_SetAssocData 3 7.5 Tcl "Tcl Library Procedures" +.so man.macros +.BS +.SH NAME +Tcl_GetAssocData, Tcl_SetAssocData, Tcl_DeleteAssocData \- manage associations of string keys and user specified data with Tcl interpreters +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +ClientData +\fBTcl_GetAssocData\fR(\fIinterp, key, delProcPtr\fR) +.sp +\fBTcl_SetAssocData\fR(\fIinterp, key, delProc, clientData\fR) +.sp +\fBTcl_DeleteAssocData\fR(\fIinterp, key\fR) +.SH ARGUMENTS +.AS Tcl_InterpDeleteProc **delProcPtr +.AP Tcl_Interp *interp in +Interpreter in which to execute the specified command. +.AP "const char" *key in +Key for association with which to store data or from which to delete or +retrieve data. Typically the module prefix for a package. +.AP Tcl_InterpDeleteProc *delProc in +Procedure to call when \fIinterp\fR is deleted. +.AP Tcl_InterpDeleteProc **delProcPtr in +Pointer to location in which to store address of current deletion procedure +for association. Ignored if NULL. +.AP ClientData clientData in +Arbitrary one-word value associated with the given key in this +interpreter. This data is owned by the caller. +.BE + +.SH DESCRIPTION +.PP +These procedures allow extensions to associate their own data with +a Tcl interpreter. +An association consists of a string key, typically the name of +the extension, and a one-word value, which is typically a pointer +to a data structure holding data specific to the extension. +Tcl makes no interpretation of either the key or the value for +an association. +.PP +Storage management is facilitated by storing with each association a +procedure to call when the interpreter is deleted. This +procedure can dispose of the storage occupied by the client's data in any +way it sees fit. +.PP +\fBTcl_SetAssocData\fR creates an association between a string +key and a user specified datum in the given interpreter. +If there is already an association with the given \fIkey\fR, +\fBTcl_SetAssocData\fR overwrites it with the new information. +It is up to callers to organize their use of names to avoid conflicts, +for example, by using package names as the keys. +If the \fIdeleteProc\fR argument is non-NULL it specifies the address of a +procedure to invoke if the interpreter is deleted before the association +is deleted. \fIDeleteProc\fR should have arguments and result that match +the type \fBTcl_InterpDeleteProc\fR: +.PP +.CS +typedef void \fBTcl_InterpDeleteProc\fR( + ClientData \fIclientData\fR, + Tcl_Interp *\fIinterp\fR); +.CE +.PP +When \fIdeleteProc\fR is invoked the \fIclientData\fR and \fIinterp\fR +arguments will be the same as the corresponding arguments passed to +\fBTcl_SetAssocData\fR. +The deletion procedure will \fInot\fR be invoked if the association +is deleted before the interpreter is deleted. +.PP +\fBTcl_GetAssocData\fR returns the datum stored in the association with the +specified key in the given interpreter, and if the \fIdelProcPtr\fR field +is non-\fBNULL\fR, the address indicated by it gets the address of the +delete procedure stored with this association. If no association with the +specified key exists in the given interpreter \fBTcl_GetAssocData\fR +returns \fBNULL\fR. +.PP +\fBTcl_DeleteAssocData\fR deletes an association with a specified key in +the given interpreter. Then it calls the deletion procedure. +.SH KEYWORDS +association, data, deletion procedure, interpreter, key diff --git a/tcl8.6/doc/Async.3 b/tcl8.6/doc/Async.3 new file mode 100644 index 0000000..347ba3d --- /dev/null +++ b/tcl8.6/doc/Async.3 @@ -0,0 +1,161 @@ +'\" +'\" Copyright (c) 1989-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. +'\" +.TH Tcl_AsyncCreate 3 7.0 Tcl "Tcl Library Procedures" +.so man.macros +.BS +.SH NAME +Tcl_AsyncCreate, Tcl_AsyncMark, Tcl_AsyncInvoke, Tcl_AsyncDelete, Tcl_AsyncReady \- handle asynchronous events +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +Tcl_AsyncHandler +\fBTcl_AsyncCreate\fR(\fIproc, clientData\fR) +.sp +\fBTcl_AsyncMark\fR(\fIasync\fR) +.sp +int +\fBTcl_AsyncInvoke\fR(\fIinterp, code\fR) +.sp +\fBTcl_AsyncDelete\fR(\fIasync\fR) +.sp +int +\fBTcl_AsyncReady\fR() +.SH ARGUMENTS +.AS Tcl_AsyncHandler clientData +.AP Tcl_AsyncProc *proc in +Procedure to invoke to handle an asynchronous event. +.AP ClientData clientData in +One-word value to pass to \fIproc\fR. +.AP Tcl_AsyncHandler async in +Token for asynchronous event handler. +.AP Tcl_Interp *interp in +Tcl interpreter in which command was being evaluated when handler was +invoked, or NULL if handler was invoked when there was no interpreter +active. +.AP int code in +Completion code from command that just completed in \fIinterp\fR, +or 0 if \fIinterp\fR is NULL. +.BE + +.SH DESCRIPTION +.PP +These procedures provide a safe mechanism for dealing with +asynchronous events such as signals. +If an event such as a signal occurs while a Tcl script is being +evaluated then it is not safe to take any substantive action to +process the event. +For example, it is not safe to evaluate a Tcl script since the +interpreter may already be in the middle of evaluating a script; +it may not even be safe to allocate memory, since a memory +allocation could have been in progress when the event occurred. +The only safe approach is to set a flag indicating that the event +occurred, then handle the event later when the world has returned +to a clean state, such as after the current Tcl command completes. +.PP +\fBTcl_AsyncCreate\fR, \fBTcl_AsyncDelete\fR, and \fBTcl_AsyncReady\fR +are thread sensitive. They access and/or set a thread-specific data +structure in the event of a core built with \fI\-\-enable\-threads\fR. The token +created by \fBTcl_AsyncCreate\fR contains the needed thread information it +was called from so that calling \fBTcl_AsyncMark\fR(\fItoken\fR) will only yield +the origin thread into the asynchronous handler. +.PP +\fBTcl_AsyncCreate\fR creates an asynchronous handler and returns +a token for it. +The asynchronous handler must be created before +any occurrences of the asynchronous event that it is intended +to handle (it is not safe to create a handler at the time of +an event). +When an asynchronous event occurs the code that detects the event +(such as a signal handler) should call \fBTcl_AsyncMark\fR with the +token for the handler. +\fBTcl_AsyncMark\fR will mark the handler as ready to execute, but it +will not invoke the handler immediately. +Tcl will call the \fIproc\fR associated with the handler later, when +the world is in a safe state, and \fIproc\fR can then carry out +the actions associated with the asynchronous event. +\fIProc\fR should have arguments and result that match the +type \fBTcl_AsyncProc\fR: +.PP +.CS +typedef int \fBTcl_AsyncProc\fR( + ClientData \fIclientData\fR, + Tcl_Interp *\fIinterp\fR, + int \fIcode\fR); +.CE +.PP +The \fIclientData\fR will be the same as the \fIclientData\fR +argument passed to \fBTcl_AsyncCreate\fR when the handler was +created. +If \fIproc\fR is invoked just after a command has completed +execution in an interpreter, then \fIinterp\fR will identify +the interpreter in which the command was evaluated and +\fIcode\fR will be the completion code returned by that +command. +The command's result will be present in the interpreter's result. +When \fIproc\fR returns, whatever it leaves in the interpreter's result +will be returned as the result of the command and the integer +value returned by \fIproc\fR will be used as the new completion +code for the command. +.PP +It is also possible for \fIproc\fR to be invoked when no interpreter +is active. +This can happen, for example, if an asynchronous event occurs while +the application is waiting for interactive input or an X event. +In this case \fIinterp\fR will be NULL and \fIcode\fR will be +0, and the return value from \fIproc\fR will be ignored. +.PP +The procedure \fBTcl_AsyncInvoke\fR is called to invoke all of the +handlers that are ready. +The procedure \fBTcl_AsyncReady\fR will return non-zero whenever any +asynchronous handlers are ready; it can be checked to avoid calls +to \fBTcl_AsyncInvoke\fR when there are no ready handlers. +Tcl calls \fBTcl_AsyncReady\fR after each command is evaluated +and calls \fBTcl_AsyncInvoke\fR if needed. +Applications may also call \fBTcl_AsyncInvoke\fR at interesting +times for that application. +For example, Tcl's event handler calls \fBTcl_AsyncReady\fR +after each event and calls \fBTcl_AsyncInvoke\fR if needed. +The \fIinterp\fR and \fIcode\fR arguments to \fBTcl_AsyncInvoke\fR +have the same meaning as for \fIproc\fR: they identify the active +interpreter, if any, and the completion code from the command +that just completed. +.PP +\fBTcl_AsyncDelete\fR removes an asynchronous handler so that +its \fIproc\fR will never be invoked again. +A handler can be deleted even when ready, and it will still +not be invoked. +.PP +If multiple handlers become active at the same time, the +handlers are invoked in the order they were created (oldest +handler first). +The \fIcode\fR and the interpreter's result for later handlers +reflect the values returned by earlier handlers, so that +the most recently created handler has last say about +the interpreter's result and completion code. +If new handlers become ready while handlers are executing, +\fBTcl_AsyncInvoke\fR will invoke them all; at each point it +invokes the highest-priority (oldest) ready handler, repeating +this over and over until there are no longer any ready handlers. +.SH WARNING +.PP +It is almost always a bad idea for an asynchronous event +handler to modify the interpreter's result or return a code different +from its \fIcode\fR argument. +This sort of behavior can disrupt the execution of scripts in +subtle ways and result in bugs that are extremely difficult +to track down. +If an asynchronous event handler needs to evaluate Tcl scripts +then it should first save the interpreter's state by calling +\fBTcl_SaveInterpState\fR, passing in the \fIcode\fR argument. +When the asynchronous handler is finished it should restore +the interpreter's state by calling \fBTcl_RestoreInterpState\fR, +and then returning the \fIcode\fR argument. + +.SH KEYWORDS +asynchronous event, handler, signal, Tcl_SaveInterpState, thread diff --git a/tcl8.6/doc/BackgdErr.3 b/tcl8.6/doc/BackgdErr.3 new file mode 100644 index 0000000..adbe33c --- /dev/null +++ b/tcl8.6/doc/BackgdErr.3 @@ -0,0 +1,78 @@ +'\" +'\" Copyright (c) 1992-1994 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. +'\" +.TH Tcl_BackgroundError 3 7.5 Tcl "Tcl Library Procedures" +.so man.macros +.BS +.SH NAME +Tcl_BackgroundException, Tcl_BackgroundError \- report Tcl exception that occurred in background processing +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +\fBTcl_BackgroundException\fR(\fIinterp, code\fR) +.sp +\fBTcl_BackgroundError\fR(\fIinterp\fR) +.SH ARGUMENTS +.AS Tcl_Interp *interp +.AP Tcl_Interp *interp in +Interpreter in which the exception occurred. +.AP int code in +The exceptional return code to be reported. +.BE + +.SH DESCRIPTION +.PP +This procedure is typically invoked when a Tcl exception (any +return code other than TCL_OK) occurs during +.QW "background processing" +such as executing an event handler. +When such an exception occurs, the condition is reported to Tcl +or to a widget or some other C code, and there is not usually any +obvious way for that code to report the exception to the user. +In these cases the code calls \fBTcl_BackgroundException\fR with an +\fIinterp\fR argument identifying the interpreter in which the +exception occurred, and a \fIcode\fR argument holding the return +code value of the exception. The state of the interpreter, including +any error message in the interpreter result, and the values of +any entries in the return options dictionary, is captured and +saved. \fBTcl_BackgroundException\fR then arranges for the event +loop to invoke at some later time the command registered +in that interpreter to handle background errors by the +\fBinterp bgerror\fR command, passing the captured values as +arguments. +The registered handler command is meant to report the exception +in an application-specific fashion. The handler command +receives two arguments, the result of the interp, and the +return options of the interp at the time the error occurred. +If the application registers no handler command, the default +handler command will attempt to call \fBbgerror\fR to report +the error. If an error condition arises while invoking the +handler command, then \fBTcl_BackgroundException\fR reports the +error itself by printing a message on the standard error file. +.PP +\fBTcl_BackgroundException\fR does not invoke the handler command immediately +because this could potentially interfere with scripts that are in process +at the time the error occurred. +Instead, it invokes the handler command later as an idle callback. +.PP +It is possible for many background exceptions to accumulate before +the handler command is invoked. When this happens, each of the exceptions +is processed in order. However, if the handler command returns a +break exception, then all remaining error reports for the +interpreter are skipped. +.PP +The \fBTcl_BackgroundError\fR routine is an older and simpler interface +useful when the exception code reported is \fBTCL_ERROR\fR. It is +equivalent to: +.PP +.CS +Tcl_BackgroundException(interp, TCL_ERROR); +.CE + +.SH KEYWORDS +background, bgerror, error, interp diff --git a/tcl8.6/doc/Backslash.3 b/tcl8.6/doc/Backslash.3 new file mode 100644 index 0000000..0805f8e --- /dev/null +++ b/tcl8.6/doc/Backslash.3 @@ -0,0 +1,47 @@ +'\" +'\" Copyright (c) 1989-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. +'\" +.TH Tcl_Backslash 3 "8.1" Tcl "Tcl Library Procedures" +.so man.macros +.BS +.SH NAME +Tcl_Backslash \- parse a backslash sequence +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +char +\fBTcl_Backslash\fR(\fIsrc, countPtr\fR) +.SH ARGUMENTS +.AS char *countPtr out +.AP char *src in +Pointer to a string starting with a backslash. +.AP int *countPtr out +If \fIcountPtr\fR is not NULL, \fI*countPtr\fR gets filled +in with number of characters in the backslash sequence, including +the backslash character. +.BE + +.SH DESCRIPTION +.PP +The use of \fBTcl_Backslash\fR is deprecated in favor of +\fBTcl_UtfBackslash\fR. +.PP +This is a utility procedure provided for backwards compatibility with +non-internationalized Tcl extensions. It parses a backslash sequence and +returns the low byte of the Unicode character corresponding to the sequence. +\fBTcl_Backslash\fR modifies \fI*countPtr\fR to contain the number of +characters in the backslash sequence. +.PP +See the Tcl manual entry for information on the valid backslash sequences. +All of the sequences described in the Tcl manual entry are supported by +\fBTcl_Backslash\fR. +.SH "SEE ALSO" +Tcl(n), Tcl_UtfBackslash(3) + +.SH KEYWORDS +backslash, parse diff --git a/tcl8.6/doc/BoolObj.3 b/tcl8.6/doc/BoolObj.3 new file mode 100644 index 0000000..7268e1f --- /dev/null +++ b/tcl8.6/doc/BoolObj.3 @@ -0,0 +1,95 @@ +'\" +'\" Copyright (c) 1996-1997 Sun Microsystems, Inc. +'\" Contributions from Don Porter, NIST, 2005. (not subject to US copyright) +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH Tcl_BooleanObj 3 8.5 Tcl "Tcl Library Procedures" +.so man.macros +.BS +.SH NAME +Tcl_NewBooleanObj, Tcl_SetBooleanObj, Tcl_GetBooleanFromObj \- store/retrieve boolean value in a Tcl_Obj +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +Tcl_Obj * +\fBTcl_NewBooleanObj\fR(\fIboolValue\fR) +.sp +\fBTcl_SetBooleanObj\fR(\fIobjPtr, boolValue\fR) +.sp +int +\fBTcl_GetBooleanFromObj\fR(\fIinterp, objPtr, boolPtr\fR) +.SH ARGUMENTS +.AS Tcl_Interp boolValue in/out +.AP int boolValue in +Integer value to be stored as a boolean value in a Tcl_Obj. +.AP Tcl_Obj *objPtr in/out +Points to the Tcl_Obj in which to store, or from which to +retrieve a boolean value. +.AP Tcl_Interp *interp in/out +If a boolean value cannot be retrieved, +an error message is left in the interpreter's result value +unless \fIinterp\fR is NULL. +.AP int *boolPtr out +Points to place where \fBTcl_GetBooleanFromObj\fR +stores the boolean value (0 or 1) obtained from \fIobjPtr\fR. +.BE + +.SH DESCRIPTION +.PP +These procedures are used to pass boolean values to and from +Tcl as Tcl_Obj's. When storing a boolean value into a Tcl_Obj, +any non-zero integer value in \fIboolValue\fR is taken to be +the boolean value \fB1\fR, and the integer value \fB0\fR is +taken to be the boolean value \fB0\fR. +.PP +\fBTcl_NewBooleanObj\fR creates a new Tcl_Obj, stores the boolean +value \fIboolValue\fR in it, and returns a pointer to the new Tcl_Obj. +The new Tcl_Obj has reference count of zero. +.PP +\fBTcl_SetBooleanObj\fR accepts \fIobjPtr\fR, a pointer to +an existing Tcl_Obj, and stores in the Tcl_Obj \fI*objPtr\fR +the boolean value \fIboolValue\fR. This is a write operation +on \fI*objPtr\fR, so \fIobjPtr\fR must be unshared. Attempts to +write to a shared Tcl_Obj will panic. A successful write +of \fIboolValue\fR into \fI*objPtr\fR implies the freeing of +any former value stored in \fI*objPtr\fR. +.PP +\fBTcl_GetBooleanFromObj\fR attempts to retrieve a boolean value +from the value stored in \fI*objPtr\fR. +If \fIobjPtr\fR holds a string value recognized by \fBTcl_GetBoolean\fR, +then the recognized boolean value is written at the address given +by \fIboolPtr\fR. +If \fIobjPtr\fR holds any value recognized as +a number by Tcl, then if that value is zero a 0 is written at +the address given by \fIboolPtr\fR and if that +value is non-zero a 1 is written at the address given by \fIboolPtr\fR. +In all cases where a value is written at the address given +by \fIboolPtr\fR, \fBTcl_GetBooleanFromObj\fR returns \fBTCL_OK\fR. +If the value of \fIobjPtr\fR does not meet any of the conditions +above, then \fBTCL_ERROR\fR is returned and an error message is +left in the interpreter's result unless \fIinterp\fR is NULL. +\fBTcl_GetBooleanFromObj\fR may also make changes to the internal +fields of \fI*objPtr\fR so that future calls to +\fBTcl_GetBooleanFromObj\fR on the same \fIobjPtr\fR can be +performed more efficiently. +.PP +Note that the routines \fBTcl_GetBooleanFromObj\fR and +\fBTcl_GetBoolean\fR are not functional equivalents. +The set of values for which \fBTcl_GetBooleanFromObj\fR +will return \fBTCL_OK\fR is strictly larger than +the set of values for which \fBTcl_GetBoolean\fR will do the same. +For example, the value +.QW 5 +passed to \fBTcl_GetBooleanFromObj\fR +will lead to a \fBTCL_OK\fR return (and the boolean value 1), +while the same value passed to \fBTcl_GetBoolean\fR will lead to +a \fBTCL_ERROR\fR return. + +.SH "SEE ALSO" +Tcl_NewObj, Tcl_IsShared, Tcl_GetBoolean + +.SH KEYWORDS +boolean, value diff --git a/tcl8.6/doc/ByteArrObj.3 b/tcl8.6/doc/ByteArrObj.3 new file mode 100644 index 0000000..ff0b4e1 --- /dev/null +++ b/tcl8.6/doc/ByteArrObj.3 @@ -0,0 +1,91 @@ +'\" +'\" Copyright (c) 1997 Sun Microsystems, Inc. +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH Tcl_ByteArrayObj 3 8.1 Tcl "Tcl Library Procedures" +.so man.macros +.BS +.SH NAME +Tcl_NewByteArrayObj, Tcl_SetByteArrayObj, Tcl_GetByteArrayFromObj, Tcl_SetByteArrayLength \- manipulate Tcl values as a arrays of bytes +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +Tcl_Obj * +\fBTcl_NewByteArrayObj\fR(\fIbytes, length\fR) +.sp +void +\fBTcl_SetByteArrayObj\fR(\fIobjPtr, bytes, length\fR) +.sp +unsigned char * +\fBTcl_GetByteArrayFromObj\fR(\fIobjPtr, lengthPtr\fR) +.sp +unsigned char * +\fBTcl_SetByteArrayLength\fR(\fIobjPtr, length\fR) +.SH ARGUMENTS +.AS "const unsigned char" *lengthPtr in/out +.AP "const unsigned char" *bytes in +The array of bytes used to initialize or set a byte-array value. May be NULL +even if \fIlength\fR is non-zero. +.AP int length in +The length of the array of bytes. It must be >= 0. +.AP Tcl_Obj *objPtr in/out +For \fBTcl_SetByteArrayObj\fR, this points to the value to be converted to +byte-array type. For \fBTcl_GetByteArrayFromObj\fR and +\fBTcl_SetByteArrayLength\fR, this points to the value from which to get +the byte-array value; if \fIobjPtr\fR does not already point to a byte-array +value, it will be converted to one. +.AP int *lengthPtr out +If non-NULL, filled with the length of the array of bytes in the value. +.BE + +.SH DESCRIPTION +.PP +These procedures are used to create, modify, and read Tcl byte-array values +from C code. Byte-array values are typically used to hold the +results of binary IO operations or data structures created with the +\fBbinary\fR command. In Tcl, an array of bytes is not equivalent to a +string. Conceptually, a string is an array of Unicode characters, while a +byte-array is an array of 8-bit quantities with no implicit meaning. +Accessor functions are provided to get the string representation of a +byte-array or to convert an arbitrary value to a byte-array. Obtaining the +string representation of a byte-array value (by calling +\fBTcl_GetStringFromObj\fR) produces a properly formed UTF-8 sequence with a +one-to-one mapping between the bytes in the internal representation and the +UTF-8 characters in the string representation. +.PP +\fBTcl_NewByteArrayObj\fR and \fBTcl_SetByteArrayObj\fR will +create a new value of byte-array type or modify an existing value to have a +byte-array type. Both of these procedures set the value's type to be +byte-array and set the value's internal representation to a copy of the +array of bytes given by \fIbytes\fR. \fBTcl_NewByteArrayObj\fR returns a +pointer to a newly allocated value with a reference count of zero. +\fBTcl_SetByteArrayObj\fR invalidates any old string representation and, if +the value is not already a byte-array value, frees any old internal +representation. If \fIbytes\fR is NULL then the new byte array contains +arbitrary values. +.PP +\fBTcl_GetByteArrayFromObj\fR converts a Tcl value to byte-array type and +returns a pointer to the value's new internal representation as an array of +bytes. The length of this array is stored in \fIlengthPtr\fR if +\fIlengthPtr\fR is non-NULL. The storage for the array of bytes is owned by +the value and should not be freed. The contents of the array may be +modified by the caller only if the value is not shared and the caller +invalidates the string representation. +.PP +\fBTcl_SetByteArrayLength\fR converts the Tcl value to byte-array type +and changes the length of the value's internal representation as an +array of bytes. If \fIlength\fR is greater than the space currently +allocated for the array, the array is reallocated to the new length; the +newly allocated bytes at the end of the array have arbitrary values. If +\fIlength\fR is less than the space currently allocated for the array, +the length of array is reduced to the new length. The return value is a +pointer to the value's new array of bytes. + +.SH "SEE ALSO" +Tcl_GetStringFromObj, Tcl_NewObj, Tcl_IncrRefCount, Tcl_DecrRefCount + +.SH KEYWORDS +value, binary data, byte array, utf, unicode, internationalization diff --git a/tcl8.6/doc/CallDel.3 b/tcl8.6/doc/CallDel.3 new file mode 100644 index 0000000..766621a --- /dev/null +++ b/tcl8.6/doc/CallDel.3 @@ -0,0 +1,67 @@ +'\" +'\" Copyright (c) 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. +'\" +.TH Tcl_CallWhenDeleted 3 7.0 Tcl "Tcl Library Procedures" +.so man.macros +.BS +.SH NAME +Tcl_CallWhenDeleted, Tcl_DontCallWhenDeleted \- Arrange for callback when interpreter is deleted +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +\fBTcl_CallWhenDeleted\fR(\fIinterp\fR, \fIproc\fR, \fIclientData\fR) +.sp +\fBTcl_DontCallWhenDeleted\fR(\fIinterp\fR, \fIproc\fR, \fIclientData\fR) +.SH ARGUMENTS +.AS Tcl_InterpDeleteProc clientData +.AP Tcl_Interp *interp in +Interpreter with which to associated callback. +.AP Tcl_InterpDeleteProc *proc in +Procedure to call when \fIinterp\fR is deleted. +.AP ClientData clientData in +Arbitrary one-word value to pass to \fIproc\fR. +.BE +.SH DESCRIPTION +.PP +\fBTcl_CallWhenDeleted\fR arranges for \fIproc\fR to be called by +\fBTcl_DeleteInterp\fR if/when \fIinterp\fR is deleted at some future +time. \fIProc\fR will be invoked just before the interpreter +is deleted, but the interpreter will still be valid at the +time of the call. +\fIProc\fR should have arguments and result that match the +type \fBTcl_InterpDeleteProc\fR: +.PP +.CS +typedef void \fBTcl_InterpDeleteProc\fR( + ClientData \fIclientData\fR, + Tcl_Interp *\fIinterp\fR); +.CE +.PP +The \fIclientData\fR and \fIinterp\fR parameters are +copies of the \fIclientData\fR and \fIinterp\fR arguments given +to \fBTcl_CallWhenDeleted\fR. +Typically, \fIclientData\fR points to an application-specific +data structure that \fIproc\fR uses to perform cleanup when an +interpreter is about to go away. +\fIProc\fR does not return a value. +.PP +\fBTcl_DontCallWhenDeleted\fR cancels a previous call to +\fBTcl_CallWhenDeleted\fR with the same arguments, so that +\fIproc\fR will not be called after all when \fIinterp\fR is +deleted. +If there is no deletion callback that matches \fIinterp\fR, +\fIproc\fR, and \fIclientData\fR then the call to +\fBTcl_DontCallWhenDeleted\fR has no effect. +.PP +Note that if the callback is being used to delete a resource that \fImust\fR +be released on exit, \fBTcl_CreateExitHandler\fR should be used to ensure that +a callback is received even if the application terminates without deleting the interpreter. +.SH "SEE ALSO" +Tcl_CreateExitHandler(3), Tcl_CreateThreadExitHandler(3) +.SH KEYWORDS +callback, cleanup, delete, interpreter diff --git a/tcl8.6/doc/Cancel.3 b/tcl8.6/doc/Cancel.3 new file mode 100644 index 0000000..847707e --- /dev/null +++ b/tcl8.6/doc/Cancel.3 @@ -0,0 +1,74 @@ +'\" +'\" Copyright (c) 2006-2008 Joe Mistachkin. +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH Tcl_Cancel 3 8.6 Tcl "Tcl Library Procedures" +.so man.macros +.BS +.SH NAME +Tcl_CancelEval, Tcl_Canceled \- cancel Tcl scripts +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +int +\fBTcl_CancelEval\fR(\fIinterp, resultObjPtr, clientData, flags\fR) +.sp +int +\fBTcl_Canceled\fR(\fIinterp, flags\fR) +.SH ARGUMENTS +.AS Tcl_Interp *interp +.AP Tcl_Interp *interp in +Interpreter in which to cancel the script. +.AP Tcl_Obj *resultObjPtr in +Error message to use in the cancellation, or NULL to use a default message. If +not NULL, this object will have its reference count decremented before +\fBTcl_CancelEval\fR returns. +.AP int flags in +ORed combination of flag bits that specify additional options. +For \fBTcl_CancelEval\fR, only \fBTCL_CANCEL_UNWIND\fR is currently +supported. For \fBTcl_Canceled\fR, only \fBTCL_LEAVE_ERR_MSG\fR and +\fBTCL_CANCEL_UNWIND\fR are currently supported. +.AP ClientData clientData in +Currently reserved for future use. +It should be set to NULL. +.BE +.SH DESCRIPTION +.PP +\fBTcl_CancelEval\fR cancels or unwinds the script in progress soon after +the next invocation of asynchronous handlers, causing \fBTCL_ERROR\fR to be +the return code for that script. This function is thread-safe and may be +called from any thread in the process. +.PP +\fBTcl_Canceled\fR checks if the script in progress has been canceled and +returns \fBTCL_ERROR\fR if it has. Otherwise, \fBTCL_OK\fR is returned. +Extensions can use this function to check to see if they should abort a long +running command. This function is thread sensitive and may only be called +from the thread the interpreter was created in. +.SS "FLAG BITS" +Any ORed combination of the following values may be used for the +\fIflags\fR argument to procedures such as \fBTcl_CancelEval\fR: +.TP 20 +\fBTCL_CANCEL_UNWIND\fR +. +This flag is used by \fBTcl_CancelEval\fR and \fBTcl_Canceled\fR. +For \fBTcl_CancelEval\fR, if this flag is set, the script in progress +is canceled and the evaluation stack for the interpreter is unwound. +For \fBTcl_Canceled\fR, if this flag is set, the script in progress +is considered to be canceled only if the evaluation stack for the +interpreter is being unwound. +.TP 20 +\fBTCL_LEAVE_ERR_MSG\fR +. +This flag is only used by \fBTcl_Canceled\fR; it is ignored by +other procedures. If an error is returned and this bit is set in +\fIflags\fR, then an error message will be left in the interpreter's +result, where it can be retrieved with \fBTcl_GetObjResult\fR or +\fBTcl_GetStringResult\fR. If this flag bit is not set then no error +message is left and the interpreter's result will not be modified. +.SH "SEE ALSO" +interp(n), Tcl_Eval(3), +TIP 285 +.SH KEYWORDS +cancel, unwind diff --git a/tcl8.6/doc/ChnlStack.3 b/tcl8.6/doc/ChnlStack.3 new file mode 100644 index 0000000..b046cd2 --- /dev/null +++ b/tcl8.6/doc/ChnlStack.3 @@ -0,0 +1,97 @@ +'\" +'\" Copyright (c) 1999-2000 Ajuba Solutions. +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +.TH Tcl_StackChannel 3 8.3 Tcl "Tcl Library Procedures" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +Tcl_StackChannel, Tcl_UnstackChannel, Tcl_GetStackedChannel, Tcl_GetTopChannel \- manipulate stacked I/O channels +.SH SYNOPSIS +.nf +.nf +\fB#include <tcl.h>\fR +.sp +Tcl_Channel +\fBTcl_StackChannel\fR(\fIinterp, typePtr, clientData, mask, channel\fR) +.sp +int +\fBTcl_UnstackChannel\fR(\fIinterp, channel\fR) +.sp +Tcl_Channel +\fBTcl_GetStackedChannel\fR(\fIchannel\fR) +.sp +Tcl_Channel +\fBTcl_GetTopChannel\fR(\fIchannel\fR) +.sp +.SH ARGUMENTS +.AS Tcl_ChannelType clientData +.AP Tcl_Interp *interp in +Interpreter for error reporting. +.AP "const Tcl_ChannelType" *typePtr in +The new channel I/O procedures to use for \fIchannel\fR. +.AP ClientData clientData in +Arbitrary one-word value to pass to channel I/O procedures. +.AP int mask in +Conditions under which \fIchannel\fR will be used: OR-ed combination of +\fBTCL_READABLE\fR, \fBTCL_WRITABLE\fR and \fBTCL_EXCEPTION\fR. +This can be a subset of the operations currently allowed on \fIchannel\fR. +.AP Tcl_Channel channel in +An existing Tcl channel such as returned by \fBTcl_CreateChannel\fR. +.BE + +.SH DESCRIPTION +.PP +These functions are for use by extensions that add processing layers to Tcl +I/O channels. Examples include compression and encryption modules. These +functions transparently stack and unstack a new channel on top of an +existing one. Any number of channels can be stacked together. +.PP +The implementation of the Tcl channel code was rewritten in 8.3.2 to +correct some problems with the previous implementation with regard to +stacked channels. Anyone using stacked channels or creating stacked +channel drivers should update to the new \fBTCL_CHANNEL_VERSION_2\fR +\fBTcl_ChannelType\fR structure. See \fBTcl_CreateChannel\fR for details. +.PP +\fBTcl_StackChannel\fR stacks a new \fIchannel\fR on an existing channel +with the same name that was registered for \fIchannel\fR by +\fBTcl_RegisterChannel\fR. +.PP +\fBTcl_StackChannel\fR works by creating a new channel structure and +placing itself on top of the channel stack. EOL translation, encoding and +buffering options are shared between all channels in the stack. The hidden +channel does no buffering, newline translations, or character set encoding. +Instead, the buffering, newline translations, and encoding functions all +remain at the top of the channel stack. A pointer to the new top channel +structure is returned. If an error occurs when stacking the channel, NULL +is returned instead. +.PP +The \fImask\fR parameter specifies the operations that are allowed on the +new channel. These can be a subset of the operations allowed on the +original channel. For example, a read-write channel may become read-only +after the \fBTcl_StackChannel\fR call. +.PP +Closing a channel closes the channels stacked below it. The close of +stacked channels is executed in a way that allows buffered data to be +properly flushed. +.PP +\fBTcl_UnstackChannel\fR reverses the process. The old channel is +associated with the channel name, and the processing module added by +\fBTcl_StackChannel\fR is destroyed. If there is no old channel, then +\fBTcl_UnstackChannel\fR is equivalent to \fBTcl_Close\fR. If an error +occurs unstacking the channel, \fBTCL_ERROR\fR is returned, otherwise +\fBTCL_OK\fR is returned. +.PP +\fBTcl_GetTopChannel\fR returns the top channel in the stack of +channels the supplied channel is part of. +.PP +\fBTcl_GetStackedChannel\fR returns the channel in the stack of +channels which is just below the supplied channel. + +.SH "SEE ALSO" +Notifier(3), Tcl_CreateChannel(3), Tcl_OpenFileChannel(3), vwait(n). + +.SH KEYWORDS +channel, compression diff --git a/tcl8.6/doc/Class.3 b/tcl8.6/doc/Class.3 new file mode 100644 index 0000000..1c3fe08 --- /dev/null +++ b/tcl8.6/doc/Class.3 @@ -0,0 +1,237 @@ +'\" +'\" Copyright (c) 2007 Donal K. Fellows +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH Tcl_Class 3 0.1 TclOO "TclOO Library Functions" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +Tcl_ClassGetMetadata, Tcl_ClassSetMetadata, Tcl_CopyObjectInstance, Tcl_GetClassAsObject, Tcl_GetObjectAsClass, Tcl_GetObjectCommand, Tcl_GetObjectFromObj, Tcl_GetObjectName, Tcl_GetObjectNamespace, Tcl_NewObjectInstance, Tcl_ObjectDeleted, Tcl_ObjectGetMetadata, Tcl_ObjectGetMethodNameMapper, Tcl_ObjectSetMetadata, Tcl_ObjectSetMethodNameMapper \- manipulate objects and classes +.SH SYNOPSIS +.nf +\fB#include <tclOO.h>\fR +.sp +Tcl_Object +\fBTcl_GetObjectFromObj\fR(\fIinterp, objPtr\fR) +.sp +Tcl_Object +\fBTcl_GetClassAsObject\fR(\fIclass\fR) +.sp +Tcl_Class +\fBTcl_GetObjectAsClass\fR(\fIobject\fR) +.sp +Tcl_Obj * +\fBTcl_GetObjectName\fR(\fIinterp, object\fR) +.sp +Tcl_Command +\fBTcl_GetObjectCommand\fR(\fIobject\fR) +.sp +Tcl_Namespace * +\fBTcl_GetObjectNamespace\fR(\fIobject\fR) +.sp +Tcl_Object +\fBTcl_NewObjectInstance\fR(\fIinterp, class, name, nsName, objc, objv, skip\fR) +.sp +Tcl_Object +\fBTcl_CopyObjectInstance\fR(\fIinterp, object, name, nsName\fR) +.sp +int +\fBTcl_ObjectDeleted\fR(\fIobject\fR) +.sp +ClientData +\fBTcl_ObjectGetMetadata\fR(\fIobject, metaTypePtr\fR) +.sp +\fBTcl_ObjectSetMetadata\fR(\fIobject, metaTypePtr, metadata\fR) +.sp +ClientData +\fBTcl_ClassGetMetadata\fR(\fIclass, metaTypePtr\fR) +.sp +\fBTcl_ClassSetMetadata\fR(\fIclass, metaTypePtr, metadata\fR) +.sp +Tcl_ObjectMapMethodNameProc +\fBTcl_ObjectGetMethodNameMapper\fR(\fIobject\fR) +.sp +\fBTcl_ObjectSetMethodNameMapper\fR(\fIobject\fR, \fImethodNameMapper\fR) +.SH ARGUMENTS +.AS ClientData metadata in/out +.AP Tcl_Interp *interp in/out +Interpreter providing the context for looking up or creating an object, and +into whose result error messages will be written on failure. +.AP Tcl_Obj *objPtr in +The name of the object to look up. +.AP Tcl_Object object in +Reference to the object to operate upon. +.AP Tcl_Class class in +Reference to the class to operate upon. +.AP "const char" *name in +The name of the object to create, or NULL if a new unused name is to be +automatically selected. +.AP "const char" *nsName in +The name of the namespace to create for the object's private use, or NULL if a +new unused name is to be automatically selected. The namespace must not +already exist. +.AP int objc in +The number of elements in the \fIobjv\fR array. +.AP "Tcl_Obj *const" *objv in +The arguments to the command to create the instance of the class. +.AP int skip in +The number of arguments at the start of the argument array, \fIobjv\fR, that +are not arguments to any constructors. +.AP Tcl_ObjectMetadataType *metaTypePtr in +The type of \fImetadata\fR being set with \fBTcl_ClassSetMetadata\fR or +retrieved with \fBTcl_ClassGetMetadata\fR. +.AP ClientData metadata in +An item of metadata to attach to the class, or NULL to remove the metadata +associated with a particular \fImetaTypePtr\fR. +.AP "Tcl_ObjectMapMethodNameProc" "methodNameMapper" in +A pointer to a function to call to adjust the mapping of objects and method +names to implementations, or NULL when no such mapping is required. +.BE +.SH DESCRIPTION +.PP +Objects are typed entities that have a set of operations ("methods") +associated with them. Classes are objects that can manufacture objects. Each +class can be viewed as an object itself; the object view can be retrieved +using \fBTcl_GetClassAsObject\fR which always returns the object when applied +to a non-destroyed class, and an object can be viewed as a class with the aid +of the \fBTcl_GetObjectAsClass\fR (which either returns the class, or NULL if +the object is not a class). An object may be looked up using the +\fBTcl_GetObjectFromObj\fR function, which either returns an object or NULL +(with an error message in the interpreter result) if the object cannot be +found. The correct way to look up a class by name is to look up the object +with that name, and then to use \fBTcl_GetObjectAsClass\fR. +.PP +Every object has its own command and namespace associated with it. The command +may be retrieved using the \fBTcl_GetObjectCommand\fR function, the name of +the object (and hence the name of the command) with \fBTcl_GetObjectName\fR, +and the namespace may be retrieved using the \fBTcl_GetObjectNamespace\fR +function. Note that the Tcl_Obj reference returned by \fBTcl_GetObjectName\fR +is a shared reference. +.PP +Instances of classes are created using \fBTcl_NewObjectInstance\fR, which +creates an object from any class (and which is internally called by both +the \fBcreate\fR and \fBnew\fR methods of the \fBoo::class\fR class). It takes +parameters that optionally give the name of the object and namespace to +create, and which describe the arguments to pass to the class's constructor +(if any). The result of the function will be either a reference to the newly +created object, or NULL if the creation failed (when an error message will be +left in the interpreter result). In addition, objects may be copied by using +\fBTcl_CopyObjectInstance\fR which creates a copy of an object without running +any constructors. +.SH "OBJECT AND CLASS METADATA" +.PP +Every object and every class may have arbitrary amounts of metadata attached +to it, which the object or class attaches no meaning to beyond what is +described in a Tcl_ObjectMetadataType structure instance. Metadata to be +attached is described by the type of the metadata (given in the +\fImetaTypePtr\fR argument) and an arbitrary pointer (the \fImetadata\fR +argument) that are given to \fBTcl_ObjectSetMetadata\fR and +\fBTcl_ClassSetMetadata\fR, and a particular piece of metadata can be +retrieved given its type using \fBTcl_ObjectGetMetadata\fR and +\fBTcl_ClassGetMetadata\fR. If the \fImetadata\fR parameter to either +\fBTcl_ObjectSetMetadata\fR or \fBTcl_ClassSetMetadata\fR is NULL, the +metadata is removed if it was attached, and the results of +\fBTcl_ObjectGetMetadata\fR and \fBTcl_ClassGetMetadata\fR are NULL if the +given type of metadata was not attached. It is not an error to request or +remove a piece of metadata that was not attached. +.SS "TCL_OBJECTMETADATATYPE STRUCTURE" +.PP +The contents of the Tcl_ObjectMetadataType structure are as follows: +.PP +.CS +typedef const struct { + int \fIversion\fR; + const char *\fIname\fR; + Tcl_ObjectMetadataDeleteProc *\fIdeleteProc\fR; + Tcl_CloneProc *\fIcloneProc\fR; +} \fBTcl_ObjectMetadataType\fR; +.CE +.PP +The \fIversion\fR field allows for future expansion of the structure, and +should always be declared equal to TCL_OO_METADATA_VERSION_CURRENT. The +\fIname\fR field provides a human-readable name for the type, and is reserved +for debugging. +.PP +The \fIdeleteProc\fR field gives a function of type +Tcl_ObjectMetadataDeleteProc that is used to delete a particular piece of +metadata, and is called when the attached metadata is replaced or removed; the +field must not be NULL. +.PP +The \fIcloneProc\fR field gives a function that is used to copy a piece of +metadata (used when a copy of an object is created using +\fBTcl_CopyObjectInstance\fR); if NULL, the metadata will be just directly +copied. +.SS "TCL_OBJECTMETADATADELETEPROC FUNCTION SIGNATURE" +.PP +Functions matching this signature are used to delete metadata associated with +a class or object. +.PP +.CS +typedef void \fBTcl_ObjectMetadataDeleteProc\fR( + ClientData \fImetadata\fR); +.CE +.PP +The \fImetadata\fR argument gives the address of the metadata to be +deleted. +.SS "TCL_CLONEPROC FUNCTION SIGNATURE" +.PP +Functions matching this signature are used to create copies of metadata +associated with a class or object. +.PP +.CS +typedef int \fBTcl_CloneProc\fR( + Tcl_Interp *\fIinterp\fR, + ClientData \fIsrcMetadata\fR, + ClientData *\fIdstMetadataPtr\fR); +.CE +.PP +The \fIinterp\fR argument gives a place to write an error message when the +attempt to clone the object is to fail, in which case the clone procedure must +also return TCL_ERROR; it should return TCL_OK otherwise. +The \fIsrcMetadata\fR argument gives the address of the metadata to be cloned, +and the cloned metadata should be written into the variable pointed to by +\fIdstMetadataPtr\fR; a NULL should be written if the metadata is to not be +cloned but the overall object copy operation is still to succeed. +.SH "OBJECT METHOD NAME MAPPING" +It is possible to control, on a per-object basis, what methods are invoked +when a particular method is invoked. Normally this is done by looking up the +method name in the object and then in the class hierarchy, but fine control of +exactly what the value used to perform the look up is afforded through the +ability to set a method name mapper callback via +\fBTcl_ObjectSetMethodNameMapper\fR (and its introspection counterpart, +\fBTcl_ObjectGetMethodNameMapper\fR, which returns the current mapper). The +current mapper (if any) is invoked immediately before looking up what chain of +method implementations is to be used. +.SS "TCL_OBJECTMAPMETHODNAMEPROC FUNCTION SIGNATURE" +The \fITcl_ObjectMapMethodNameProc\fR callback is defined as follows: +.PP +.CS +typedef int \fBTcl_ObjectMapMethodNameProc\fR( + Tcl_Interp *\fIinterp\fR, + Tcl_Object \fIobject\fR, + Tcl_Class *\fIstartClsPtr\fR, + Tcl_Obj *\fImethodNameObj\fR); +.CE +.PP +If the result is TCL_OK, the remapping is assumed to have been done. If the +result is TCL_ERROR, an error message will have been left in \fIinterp\fR and +the method call will fail. If the result is TCL_BREAK, the standard method +name lookup rules will be used; the behavior of other result codes is +currently undefined. The \fIobject\fR parameter says which object is being +processed. The \fIstartClsPtr\fR parameter points to a variable that contains +the first class to provide a definition in the method chain to process, or +NULL if the whole chain is to be processed (the argument itself is never +NULL); this variable may be updated by the callback. The \fImethodNameObj\fR +parameter gives an unshared object containing the name of the method being +invoked, as provided by the user; this object may be updated by the callback. +.SH "SEE ALSO" +Method(3), oo::class(n), oo::copy(n), oo::define(n), oo::object(n) +.SH KEYWORDS +class, constructor, object +.\" Local variables: +.\" mode: nroff +.\" fill-column: 78 +.\" End: diff --git a/tcl8.6/doc/CmdCmplt.3 b/tcl8.6/doc/CmdCmplt.3 new file mode 100644 index 0000000..25b372e --- /dev/null +++ b/tcl8.6/doc/CmdCmplt.3 @@ -0,0 +1,34 @@ +'\" +'\" Copyright (c) 1989-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. +'\" +.TH Tcl_CommandComplete 3 "" Tcl "Tcl Library Procedures" +.so man.macros +.BS +.SH NAME +Tcl_CommandComplete \- Check for unmatched braces in a Tcl command +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +int +\fBTcl_CommandComplete\fR(\fIcmd\fR) +.SH ARGUMENTS +.AS "const char" *cmd +.AP "const char" *cmd in +Command string to test for completeness. +.BE + +.SH DESCRIPTION +.PP +\fBTcl_CommandComplete\fR takes a Tcl command string +as argument and determines whether it contains one or more +complete commands (i.e. there are no unclosed quotes, braces, +brackets, or variable references). +If the command string is complete then it returns 1; otherwise it returns 0. + +.SH KEYWORDS +complete command, partial command diff --git a/tcl8.6/doc/Concat.3 b/tcl8.6/doc/Concat.3 new file mode 100644 index 0000000..58a0fb6 --- /dev/null +++ b/tcl8.6/doc/Concat.3 @@ -0,0 +1,51 @@ +'\" +'\" Copyright (c) 1989-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. +'\" +.TH Tcl_Concat 3 7.5 Tcl "Tcl Library Procedures" +.so man.macros +.BS +.SH NAME +Tcl_Concat \- concatenate a collection of strings +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +const char * +\fBTcl_Concat\fR(\fIargc, argv\fR) +.SH ARGUMENTS +.AS "const char *const" argv[] +.AP int argc in +Number of strings. +.AP "const char *const" argv[] in +Array of strings to concatenate. Must have \fIargc\fR entries. +.BE + +.SH DESCRIPTION +.PP +\fBTcl_Concat\fR is a utility procedure used by several of the +Tcl commands. Given a collection of strings, it concatenates +them together into a single string, with the original strings +separated by spaces. This procedure behaves differently than +\fBTcl_Merge\fR, in that the arguments are simply concatenated: +no effort is made to ensure proper list structure. +However, in most common usage the arguments will all be proper +lists themselves; if this is true, then the result will also have +proper list structure. +.PP +\fBTcl_Concat\fR eliminates leading and trailing white space as it +copies strings from \fBargv\fR to the result. If an element of +\fBargv\fR consists of nothing but white space, then that string +is ignored entirely. This white-space removal was added to make +the output of the \fBconcat\fR command cleaner-looking. +.PP +The result string is dynamically allocated +using \fBTcl_Alloc\fR; the caller must eventually release the space +by calling \fBTcl_Free\fR. +.SH "SEE ALSO" +Tcl_ConcatObj +.SH KEYWORDS +concatenate, strings diff --git a/tcl8.6/doc/CrtChannel.3 b/tcl8.6/doc/CrtChannel.3 new file mode 100644 index 0000000..6ef94b5 --- /dev/null +++ b/tcl8.6/doc/CrtChannel.3 @@ -0,0 +1,928 @@ +'\" +'\" Copyright (c) 1996-1997 Sun Microsystems, Inc. +'\" Copyright (c) 1997-2000 Ajuba Solutions. +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +.TH Tcl_CreateChannel 3 8.4 Tcl "Tcl Library Procedures" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +Tcl_CreateChannel, Tcl_GetChannelInstanceData, Tcl_GetChannelType, Tcl_GetChannelName, Tcl_GetChannelHandle, Tcl_GetChannelMode, Tcl_GetChannelBufferSize, Tcl_SetChannelBufferSize, Tcl_NotifyChannel, Tcl_BadChannelOption, Tcl_ChannelName, Tcl_ChannelVersion, Tcl_ChannelBlockModeProc, Tcl_ChannelCloseProc, Tcl_ChannelClose2Proc, Tcl_ChannelInputProc, Tcl_ChannelOutputProc, Tcl_ChannelSeekProc, Tcl_ChannelWideSeekProc, Tcl_ChannelTruncateProc, Tcl_ChannelSetOptionProc, Tcl_ChannelGetOptionProc, Tcl_ChannelWatchProc, Tcl_ChannelGetHandleProc, Tcl_ChannelFlushProc, Tcl_ChannelHandlerProc, Tcl_ChannelThreadActionProc, Tcl_IsChannelShared, Tcl_IsChannelRegistered, Tcl_CutChannel, Tcl_SpliceChannel, Tcl_IsChannelExisting, Tcl_ClearChannelHandlers, Tcl_GetChannelThread, Tcl_ChannelBuffered \- procedures for creating and manipulating channels +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +Tcl_Channel +\fBTcl_CreateChannel\fR(\fItypePtr, channelName, instanceData, mask\fR) +.sp +ClientData +\fBTcl_GetChannelInstanceData\fR(\fIchannel\fR) +.sp +const Tcl_ChannelType * +\fBTcl_GetChannelType\fR(\fIchannel\fR) +.sp +const char * +\fBTcl_GetChannelName\fR(\fIchannel\fR) +.sp +int +\fBTcl_GetChannelHandle\fR(\fIchannel, direction, handlePtr\fR) +.sp +Tcl_ThreadId +\fBTcl_GetChannelThread\fR(\fIchannel\fR) +.sp +int +\fBTcl_GetChannelMode\fR(\fIchannel\fR) +.sp +int +\fBTcl_GetChannelBufferSize\fR(\fIchannel\fR) +.sp +\fBTcl_SetChannelBufferSize\fR(\fIchannel, size\fR) +.sp +\fBTcl_NotifyChannel\fR(\fIchannel, mask\fR) +.sp +int +\fBTcl_BadChannelOption\fR(\fIinterp, optionName, optionList\fR) +.sp +int +\fBTcl_IsChannelShared\fR(\fIchannel\fR) +.sp +int +\fBTcl_IsChannelRegistered\fR(\fIinterp, channel\fR) +.sp +int +\fBTcl_IsChannelExisting\fR(\fIchannelName\fR) +.sp +void +\fBTcl_CutChannel\fR(\fIchannel\fR) +.sp +void +\fBTcl_SpliceChannel\fR(\fIchannel\fR) +.sp +void +\fBTcl_ClearChannelHandlers\fR(\fIchannel\fR) +.sp +int +\fBTcl_ChannelBuffered\fR(\fIchannel\fR) +.sp +const char * +\fBTcl_ChannelName\fR(\fItypePtr\fR) +.sp +Tcl_ChannelTypeVersion +\fBTcl_ChannelVersion\fR(\fItypePtr\fR) +.sp +Tcl_DriverBlockModeProc * +\fBTcl_ChannelBlockModeProc\fR(\fItypePtr\fR) +.sp +Tcl_DriverCloseProc * +\fBTcl_ChannelCloseProc\fR(\fItypePtr\fR) +.sp +Tcl_DriverClose2Proc * +\fBTcl_ChannelClose2Proc\fR(\fItypePtr\fR) +.sp +Tcl_DriverInputProc * +\fBTcl_ChannelInputProc\fR(\fItypePtr\fR) +.sp +Tcl_DriverOutputProc * +\fBTcl_ChannelOutputProc\fR(\fItypePtr\fR) +.sp +Tcl_DriverSeekProc * +\fBTcl_ChannelSeekProc\fR(\fItypePtr\fR) +.sp +Tcl_DriverWideSeekProc * +\fBTcl_ChannelWideSeekProc\fR(\fItypePtr\fR) +.sp +Tcl_DriverThreadActionProc * +\fBTcl_ChannelThreadActionProc\fR(\fItypePtr\fR) +.sp +Tcl_DriverTruncateProc * +\fBTcl_ChannelTruncateProc\fR(\fItypePtr\fR) +.sp +Tcl_DriverSetOptionProc * +\fBTcl_ChannelSetOptionProc\fR(\fItypePtr\fR) +.sp +Tcl_DriverGetOptionProc * +\fBTcl_ChannelGetOptionProc\fR(\fItypePtr\fR) +.sp +Tcl_DriverWatchProc * +\fBTcl_ChannelWatchProc\fR(\fItypePtr\fR) +.sp +Tcl_DriverGetHandleProc * +\fBTcl_ChannelGetHandleProc\fR(\fItypePtr\fR) +.sp +Tcl_DriverFlushProc * +\fBTcl_ChannelFlushProc\fR(\fItypePtr\fR) +.sp +Tcl_DriverHandlerProc * +\fBTcl_ChannelHandlerProc\fR(\fItypePtr\fR) +.sp +.SH ARGUMENTS +.AS "const Tcl_ChannelType" *channelName +.AP "const Tcl_ChannelType" *typePtr in +Points to a structure containing the addresses of procedures that +can be called to perform I/O and other functions on the channel. +.AP "const char" *channelName in +The name of this channel, such as \fBfile3\fR; must not be in use +by any other channel. Can be NULL, in which case the channel is +created without a name. If the created channel is assigned to one +of the standard channels (\fBstdin\fR, \fBstdout\fR or \fBstderr\fR), +the assigned channel name will be the name of the standard channel. +.AP ClientData instanceData in +Arbitrary one-word value to be associated with this channel. This +value is passed to procedures in \fItypePtr\fR when they are invoked. +.AP int mask in +OR-ed combination of \fBTCL_READABLE\fR and \fBTCL_WRITABLE\fR to indicate +whether a channel is readable and writable. +.AP Tcl_Channel channel in +The channel to operate on. +.AP int direction in +\fBTCL_READABLE\fR means the input handle is wanted; \fBTCL_WRITABLE\fR +means the output handle is wanted. +.AP ClientData *handlePtr out +Points to the location where the desired OS-specific handle should be +stored. +.AP int size in +The size, in bytes, of buffers to allocate in this channel. +.AP int mask in +An OR-ed combination of \fBTCL_READABLE\fR, \fBTCL_WRITABLE\fR +and \fBTCL_EXCEPTION\fR that indicates events that have occurred on +this channel. +.AP Tcl_Interp *interp in +Current interpreter. (can be NULL) +.AP "const char" *optionName in +Name of the invalid option. +.AP "const char" *optionList in +Specific options list (space separated words, without +.QW \- ) +to append to the standard generic options list. +Can be NULL for generic options error message only. +.BE +.SH DESCRIPTION +.PP +Tcl uses a two-layered channel architecture. It provides a generic upper +layer to enable C and Tcl programs to perform input and output using the +same APIs for a variety of files, devices, sockets etc. The generic C APIs +are described in the manual entry for \fBTcl_OpenFileChannel\fR. +.PP +The lower layer provides type-specific channel drivers for each type +of device supported on each platform. This manual entry describes the +C APIs used to communicate between the generic layer and the +type-specific channel drivers. It also explains how new types of +channels can be added by providing new channel drivers. +.PP +Channel drivers consist of a number of components: First, each channel +driver provides a \fBTcl_ChannelType\fR structure containing pointers to +functions implementing the various operations used by the generic layer to +communicate with the channel driver. The \fBTcl_ChannelType\fR structure +and the functions referenced by it are described in the section +\fBTCL_CHANNELTYPE\fR, below. +.PP +Second, channel drivers usually provide a Tcl command to create +instances of that type of channel. For example, the Tcl \fBopen\fR +command creates channels that use the file and command channel +drivers, and the Tcl \fBsocket\fR command creates channels that use +TCP sockets for network communication. +.PP +Third, a channel driver optionally provides a C function to open +channel instances of that type. For example, \fBTcl_OpenFileChannel\fR +opens a channel that uses the file channel driver, and +\fBTcl_OpenTcpClient\fR opens a channel that uses the TCP network +protocol. These creation functions typically use +\fBTcl_CreateChannel\fR internally to open the channel. +.PP +To add a new type of channel you must implement a C API or a Tcl command +that opens a channel by invoking \fBTcl_CreateChannel\fR. +When your driver calls \fBTcl_CreateChannel\fR it passes in +a \fBTcl_ChannelType\fR structure describing the driver's I/O +procedures. +The generic layer will then invoke the functions referenced in that +structure to perform operations on the channel. +.PP +\fBTcl_CreateChannel\fR opens a new channel and associates the supplied +\fItypePtr\fR and \fIinstanceData\fR with it. The channel is opened in the +mode indicated by \fImask\fR. +For a discussion of channel drivers, their operations and the +\fBTcl_ChannelType\fR structure, see the section \fBTCL_CHANNELTYPE\fR, below. +.PP +\fBTcl_CreateChannel\fR interacts with the code managing the standard +channels. Once a standard channel was initialized either through a +call to \fBTcl_GetStdChannel\fR or a call to \fBTcl_SetStdChannel\fR +closing this standard channel will cause the next call to +\fBTcl_CreateChannel\fR to make the new channel the new standard +channel too. See \fBTcl_StandardChannels\fR for a general treatise +about standard channels and the behavior of the Tcl library with +regard to them. +.PP +\fBTcl_GetChannelInstanceData\fR returns the instance data associated with +the channel in \fIchannel\fR. This is the same as the \fIinstanceData\fR +argument in the call to \fBTcl_CreateChannel\fR that created this channel. +.PP +\fBTcl_GetChannelType\fR returns a pointer to the \fBTcl_ChannelType\fR +structure used by the channel in the \fIchannel\fR argument. This is +the same as the \fItypePtr\fR argument in the call to +\fBTcl_CreateChannel\fR that created this channel. +.PP +\fBTcl_GetChannelName\fR returns a string containing the name associated +with the channel, or NULL if the \fIchannelName\fR argument to +\fBTcl_CreateChannel\fR was NULL. +.PP +\fBTcl_GetChannelHandle\fR places the OS-specific device handle +associated with \fIchannel\fR for the given \fIdirection\fR in the +location specified by \fIhandlePtr\fR and returns \fBTCL_OK\fR. If +the channel does not have a device handle for the specified direction, +then \fBTCL_ERROR\fR is returned instead. Different channel drivers +will return different types of handle. Refer to the manual entries +for each driver to determine what type of handle is returned. +.PP +\fBTcl_GetChannelThread\fR returns the id of the thread currently managing +the specified \fIchannel\fR. This allows channel drivers to send their file +events to the correct event queue even for a multi-threaded core. +.PP +\fBTcl_GetChannelMode\fR returns an OR-ed combination of \fBTCL_READABLE\fR +and \fBTCL_WRITABLE\fR, indicating whether the channel is open for input +and output. +.PP +\fBTcl_GetChannelBufferSize\fR returns the size, in bytes, of buffers +allocated to store input or output in \fIchannel\fR. If the value was not set +by a previous call to \fBTcl_SetChannelBufferSize\fR, described below, then +the default value of 4096 is returned. +.PP +\fBTcl_SetChannelBufferSize\fR sets the size, in bytes, of buffers that +will be allocated in subsequent operations on the channel to store input or +output. The \fIsize\fR argument should be between one and one million, +allowing buffers of one byte to one million bytes. If \fIsize\fR is +outside this range, \fBTcl_SetChannelBufferSize\fR sets the buffer size to +4096. +.PP +\fBTcl_NotifyChannel\fR is called by a channel driver to indicate to +the generic layer that the events specified by \fImask\fR have +occurred on the channel. Channel drivers are responsible for invoking +this function whenever the channel handlers need to be called for the +channel. See \fBWATCHPROC\fR below for more details. +.PP +\fBTcl_BadChannelOption\fR is called from driver specific +\fIsetOptionProc\fR or \fIgetOptionProc\fR to generate a complete +error message. +.PP +\fBTcl_ChannelBuffered\fR returns the number of bytes of input +currently buffered in the internal buffer (push back area) of the +channel itself. It does not report about the data in the overall +buffers for the stack of channels the supplied channel is part of. +.PP +\fBTcl_IsChannelShared\fR checks the refcount of the specified +\fIchannel\fR and returns whether the \fIchannel\fR was shared among +multiple interpreters (result == 1) or not (result == 0). +.PP +\fBTcl_IsChannelRegistered\fR checks whether the specified \fIchannel\fR is +registered in the given \fIinterp\fRreter (result == 1) or not +(result == 0). +.PP +\fBTcl_IsChannelExisting\fR checks whether a channel with the specified +name is registered in the (thread)-global list of all channels (result +== 1) or not (result == 0). +.PP +\fBTcl_CutChannel\fR removes the specified \fIchannel\fR from the +(thread)global list of all channels (of the current thread). +Application to a channel still registered in some interpreter +is not allowed. +Also notifies the driver if the \fBTcl_ChannelType\fR version is +\fBTCL_CHANNEL_VERSION_4\fR (or higher), and +\fBTcl_DriverThreadActionProc\fR is defined for it. +.PP +\fBTcl_SpliceChannel\fR adds the specified \fIchannel\fR to the +(thread)global list of all channels (of the current thread). +Application to a channel registered in some interpreter is not allowed. +Also notifies the driver if the \fBTcl_ChannelType\fR version is +\fBTCL_CHANNEL_VERSION_4\fR (or higher), and +\fBTcl_DriverThreadActionProc\fR is defined for it. +.PP +\fBTcl_ClearChannelHandlers\fR removes all channel handlers and event +scripts associated with the specified \fIchannel\fR, thus shutting +down all event processing for this channel. +.SH TCL_CHANNELTYPE +.PP +A channel driver provides a \fBTcl_ChannelType\fR structure that contains +pointers to functions that implement the various operations on a channel; +these operations are invoked as needed by the generic layer. The structure +was versioned starting in Tcl 8.3.2/8.4 to correct a problem with stacked +channel drivers. See the \fBOLD CHANNEL TYPES\fR section below for +details about the old structure. +.PP +The \fBTcl_ChannelType\fR structure contains the following fields: +.PP +.CS +typedef struct Tcl_ChannelType { + const char *\fItypeName\fR; + Tcl_ChannelTypeVersion \fIversion\fR; + Tcl_DriverCloseProc *\fIcloseProc\fR; + Tcl_DriverInputProc *\fIinputProc\fR; + Tcl_DriverOutputProc *\fIoutputProc\fR; + Tcl_DriverSeekProc *\fIseekProc\fR; + Tcl_DriverSetOptionProc *\fIsetOptionProc\fR; + Tcl_DriverGetOptionProc *\fIgetOptionProc\fR; + Tcl_DriverWatchProc *\fIwatchProc\fR; + Tcl_DriverGetHandleProc *\fIgetHandleProc\fR; + Tcl_DriverClose2Proc *\fIclose2Proc\fR; + Tcl_DriverBlockModeProc *\fIblockModeProc\fR; + Tcl_DriverFlushProc *\fIflushProc\fR; + Tcl_DriverHandlerProc *\fIhandlerProc\fR; + Tcl_DriverWideSeekProc *\fIwideSeekProc\fR; + Tcl_DriverThreadActionProc *\fIthreadActionProc\fR; + Tcl_DriverTruncateProc *\fItruncateProc\fR; +} \fBTcl_ChannelType\fR; +.CE +.PP +It is not necessary to provide implementations for all channel +operations. Those which are not necessary may be set to NULL in the +struct: \fIblockModeProc\fR, \fIseekProc\fR, \fIsetOptionProc\fR, +\fIgetOptionProc\fR, \fIgetHandleProc\fR, and \fIclose2Proc\fR, in addition to +\fIflushProc\fR, \fIhandlerProc\fR, \fIthreadActionProc\fR, and +\fItruncateProc\fR. Other functions that cannot be implemented in a +meaningful way should return \fBEINVAL\fR when called, to indicate +that the operations they represent are not available. Also note that +\fIwideSeekProc\fR can be NULL if \fIseekProc\fR is. +.PP +The user should only use the above structure for \fBTcl_ChannelType\fR +instantiation. When referencing fields in a \fBTcl_ChannelType\fR +structure, the following functions should be used to obtain the values: +\fBTcl_ChannelName\fR, \fBTcl_ChannelVersion\fR, +\fBTcl_ChannelBlockModeProc\fR, \fBTcl_ChannelCloseProc\fR, +\fBTcl_ChannelClose2Proc\fR, \fBTcl_ChannelInputProc\fR, +\fBTcl_ChannelOutputProc\fR, \fBTcl_ChannelSeekProc\fR, +\fBTcl_ChannelWideSeekProc\fR, \fBTcl_ChannelThreadActionProc\fR, +\fBTcl_ChannelTruncateProc\fR, +\fBTcl_ChannelSetOptionProc\fR, \fBTcl_ChannelGetOptionProc\fR, +\fBTcl_ChannelWatchProc\fR, \fBTcl_ChannelGetHandleProc\fR, +\fBTcl_ChannelFlushProc\fR, or \fBTcl_ChannelHandlerProc\fR. +.PP +The change to the structures was made in such a way that standard channel +types are binary compatible. However, channel types that use stacked +channels (i.e. TLS, Trf) have new versions to correspond to the above change +since the previous code for stacked channels had problems. +.SS TYPENAME +.PP +The \fItypeName\fR field contains a null-terminated string that +identifies the type of the device implemented by this driver, e.g. +\fBfile\fR or \fBsocket\fR. +.PP +This value can be retrieved with \fBTcl_ChannelName\fR, which returns +a pointer to the string. +.SS VERSION +.PP + +The \fIversion\fR field should be set to the version of the structure +that you require. \fBTCL_CHANNEL_VERSION_2\fR is the minimum recommended. +\fBTCL_CHANNEL_VERSION_3\fR must be set to specify the \fIwideSeekProc\fR member. +\fBTCL_CHANNEL_VERSION_4\fR must be set to specify the \fIthreadActionProc\fR member +(includes \fIwideSeekProc\fR). +\fBTCL_CHANNEL_VERSION_5\fR must be set to specify the +\fItruncateProc\fR members (includes +\fIwideSeekProc\fR and \fIthreadActionProc\fR). +If it is not set to any of these, then this +\fBTcl_ChannelType\fR is assumed to have the original structure. See +\fBOLD CHANNEL TYPES\fR for more details. While Tcl will recognize +and function with either structures, stacked channels must be of at +least \fBTCL_CHANNEL_VERSION_2\fR to function correctly. +.PP +This value can be retrieved with \fBTcl_ChannelVersion\fR, which returns +one of +\fBTCL_CHANNEL_VERSION_5\fR, +\fBTCL_CHANNEL_VERSION_4\fR, +\fBTCL_CHANNEL_VERSION_3\fR, +\fBTCL_CHANNEL_VERSION_2\fR or \fBTCL_CHANNEL_VERSION_1\fR. +.SS BLOCKMODEPROC +.PP +The \fIblockModeProc\fR field contains the address of a function called by +the generic layer to set blocking and nonblocking mode on the device. +\fIBlockModeProc\fR should match the following prototype: +.PP +.CS +typedef int \fBTcl_DriverBlockModeProc\fR( + ClientData \fIinstanceData\fR, + int \fImode\fR); +.CE +.PP +The \fIinstanceData\fR is the same as the value passed to +\fBTcl_CreateChannel\fR when this channel was created. The \fImode\fR +argument is either \fBTCL_MODE_BLOCKING\fR or \fBTCL_MODE_NONBLOCKING\fR to +set the device into blocking or nonblocking mode. The function should +return zero if the operation was successful, or a nonzero POSIX error code +if the operation failed. +.PP +If the operation is successful, the function can modify the supplied +\fIinstanceData\fR to record that the channel entered blocking or +nonblocking mode and to implement the blocking or nonblocking behavior. +For some device types, the blocking and nonblocking behavior can be +implemented by the underlying operating system; for other device types, the +behavior must be emulated in the channel driver. +.PP +This value can be retrieved with \fBTcl_ChannelBlockModeProc\fR, which returns +a pointer to the function. +.PP +A channel driver \fBnot\fR supplying a \fIblockModeProc\fR has to be +very, very careful. It has to tell the generic layer exactly which +blocking mode is acceptable to it, and should this also document for +the user so that the blocking mode of the channel is not changed to an +unacceptable value. Any confusion here may lead the interpreter into a +(spurious and difficult to find) deadlock. +.SS "CLOSEPROC AND CLOSE2PROC" +.PP +The \fIcloseProc\fR field contains the address of a function called by the +generic layer to clean up driver-related information when the channel is +closed. \fICloseProc\fR must match the following prototype: +.PP +.CS +typedef int \fBTcl_DriverCloseProc\fR( + ClientData \fIinstanceData\fR, + Tcl_Interp *\fIinterp\fR); +.CE +.PP +The \fIinstanceData\fR argument is the same as the value provided to +\fBTcl_CreateChannel\fR when the channel was created. The function should +release any storage maintained by the channel driver for this channel, and +close the input and output devices encapsulated by this channel. All queued +output will have been flushed to the device before this function is called, +and no further driver operations will be invoked on this instance after +calling the \fIcloseProc\fR. If the close operation is successful, the +procedure should return zero; otherwise it should return a nonzero POSIX +error code. In addition, if an error occurs and \fIinterp\fR is not NULL, +the procedure should store an error message in the interpreter's result. +.PP +Alternatively, channels that support closing the read and write sides +independently may set \fIcloseProc\fR to \fBTCL_CLOSE2PROC\fR and set +\fIclose2Proc\fR to the address of a function that matches the +following prototype: +.PP +.CS +typedef int \fBTcl_DriverClose2Proc\fR( + ClientData \fIinstanceData\fR, + Tcl_Interp *\fIinterp\fR, + int \fIflags\fR); +.CE +.PP +The \fIclose2Proc\fR will be called with \fIflags\fR set to an OR'ed +combination of \fBTCL_CLOSE_READ\fR or \fBTCL_CLOSE_WRITE\fR to +indicate that the driver should close the read and/or write side of +the channel. The channel driver may be invoked to perform +additional operations on the channel after \fIclose2Proc\fR is +called to close one or both sides of the channel. If \fIflags\fR is +\fB0\fR (zero), the driver should close the channel in the manner +described above for \fIcloseProc\fR. No further operations will be +invoked on this instance after \fIclose2Proc\fR is called with all +flags cleared. In all cases, the \fIclose2Proc\fR function should +return zero if the close operation was successful; otherwise it should +return a nonzero POSIX error code. In addition, if an error occurs and +\fIinterp\fR is not NULL, the procedure should store an error message +in the interpreter's result. +.PP +The \fIcloseProc\fR and \fIclose2Proc\fR values can be retrieved with +\fBTcl_ChannelCloseProc\fR or \fBTcl_ChannelClose2Proc\fR, which +return a pointer to the respective function. +.SS INPUTPROC +.PP +The \fIinputProc\fR field contains the address of a function called by the +generic layer to read data from the file or device and store it in an +internal buffer. \fIInputProc\fR must match the following prototype: +.PP +.CS +typedef int \fBTcl_DriverInputProc\fR( + ClientData \fIinstanceData\fR, + char *\fIbuf\fR, + int \fIbufSize\fR, + int *\fIerrorCodePtr\fR); +.CE +.PP +\fIInstanceData\fR is the same as the value passed to +\fBTcl_CreateChannel\fR when the channel was created. The \fIbuf\fR +argument points to an array of bytes in which to store input from the +device, and the \fIbufSize\fR argument indicates how many bytes are +available at \fIbuf\fR. +.PP +The \fIerrorCodePtr\fR argument points to an integer variable provided by +the generic layer. If an error occurs, the function should set the variable +to a POSIX error code that identifies the error that occurred. +.PP +The function should read data from the input device encapsulated by the +channel and store it at \fIbuf\fR. On success, the function should return +a nonnegative integer indicating how many bytes were read from the input +device and stored at \fIbuf\fR. On error, the function should return -1. If +an error occurs after some data has been read from the device, that data is +lost. +.PP +If \fIinputProc\fR can determine that the input device has some data +available but less than requested by the \fIbufSize\fR argument, the +function should only attempt to read as much data as is available and +return without blocking. If the input device has no data available +whatsoever and the channel is in nonblocking mode, the function should +return an \fBEAGAIN\fR error. If the input device has no data available +whatsoever and the channel is in blocking mode, the function should block +for the shortest possible time until at least one byte of data can be read +from the device; then, it should return as much data as it can read without +blocking. +.PP +This value can be retrieved with \fBTcl_ChannelInputProc\fR, which returns +a pointer to the function. +.SS OUTPUTPROC +.PP +The \fIoutputProc\fR field contains the address of a function called by the +generic layer to transfer data from an internal buffer to the output device. +\fIOutputProc\fR must match the following prototype: +.PP +.CS +typedef int \fBTcl_DriverOutputProc\fR( + ClientData \fIinstanceData\fR, + const char *\fIbuf\fR, + int \fItoWrite\fR, + int *\fIerrorCodePtr\fR); +.CE +.PP +\fIInstanceData\fR is the same as the value passed to +\fBTcl_CreateChannel\fR when the channel was created. The \fIbuf\fR +argument contains an array of bytes to be written to the device, and the +\fItoWrite\fR argument indicates how many bytes are to be written from the +\fIbuf\fR argument. +.PP +The \fIerrorCodePtr\fR argument points to an integer variable provided by +the generic layer. If an error occurs, the function should set this +variable to a POSIX error code that identifies the error. +.PP +The function should write the data at \fIbuf\fR to the output device +encapsulated by the channel. On success, the function should return a +nonnegative integer indicating how many bytes were written to the output +device. The return value is normally the same as \fItoWrite\fR, but may be +less in some cases such as if the output operation is interrupted by a +signal. If an error occurs the function should return -1. In case of +error, some data may have been written to the device. +.PP +If the channel is nonblocking and the output device is unable to absorb any +data whatsoever, the function should return -1 with an \fBEAGAIN\fR error +without writing any data. +.PP +This value can be retrieved with \fBTcl_ChannelOutputProc\fR, which returns +a pointer to the function. +.SS "SEEKPROC AND WIDESEEKPROC" +.PP +The \fIseekProc\fR field contains the address of a function called by the +generic layer to move the access point at which subsequent input or output +operations will be applied. \fISeekProc\fR must match the following +prototype: +.PP +.CS +typedef int \fBTcl_DriverSeekProc\fR( + ClientData \fIinstanceData\fR, + long \fIoffset\fR, + int \fIseekMode\fR, + int *\fIerrorCodePtr\fR); +.CE +.PP +The \fIinstanceData\fR argument is the same as the value given to +\fBTcl_CreateChannel\fR when this channel was created. \fIOffset\fR and +\fIseekMode\fR have the same meaning as for the \fBTcl_Seek\fR +procedure (described in the manual entry for \fBTcl_OpenFileChannel\fR). +.PP +The \fIerrorCodePtr\fR argument points to an integer variable provided by +the generic layer for returning \fBerrno\fR values from the function. The +function should set this variable to a POSIX error code if an error occurs. +The function should store an \fBEINVAL\fR error code if the channel type +does not implement seeking. +.PP +The return value is the new access point or -1 in case of error. If an +error occurred, the function should not move the access point. +.PP +If there is a non-NULL \fIseekProc\fR field, the \fIwideSeekProc\fR +field may contain the address of an alternative function to use which +handles wide (i.e. larger than 32-bit) offsets, so allowing seeks +within files larger than 2GB. The \fIwideSeekProc\fR will be called +in preference to the \fIseekProc\fR, but both must be defined if the +\fIwideSeekProc\fR is defined. \fIWideSeekProc\fR must match the +following prototype: +.PP +.CS +typedef Tcl_WideInt \fBTcl_DriverWideSeekProc\fR( + ClientData \fIinstanceData\fR, + Tcl_WideInt \fIoffset\fR, + int \fIseekMode\fR, + int *\fIerrorCodePtr\fR); +.CE +.PP +The arguments and return values mean the same thing as with +\fIseekProc\fR above, except that the type of offsets and the return +type are different. +.PP +The \fIseekProc\fR value can be retrieved with +\fBTcl_ChannelSeekProc\fR, which returns a pointer to the function, +and similarly the \fIwideSeekProc\fR can be retrieved with +\fBTcl_ChannelWideSeekProc\fR. +.SS SETOPTIONPROC +.PP +The \fIsetOptionProc\fR field contains the address of a function called by +the generic layer to set a channel type specific option on a channel. +\fIsetOptionProc\fR must match the following prototype: +.PP +.CS +typedef int \fBTcl_DriverSetOptionProc\fR( + ClientData \fIinstanceData\fR, + Tcl_Interp *\fIinterp\fR, + const char *\fIoptionName\fR, + const char *\fInewValue\fR); +.CE +.PP +\fIoptionName\fR is the name of an option to set, and \fInewValue\fR is +the new value for that option, as a string. The \fIinstanceData\fR is the +same as the value given to \fBTcl_CreateChannel\fR when this channel was +created. The function should do whatever channel type specific action is +required to implement the new value of the option. +.PP +Some options are handled by the generic code and this function is never +called to set them, e.g. \fB\-blockmode\fR. Other options are specific to +each channel type and the \fIsetOptionProc\fR procedure of the channel +driver will get called to implement them. The \fIsetOptionProc\fR field can +be NULL, which indicates that this channel type supports no type specific +options. +.PP +If the option value is successfully modified to the new value, the function +returns \fBTCL_OK\fR. +It should call \fBTcl_BadChannelOption\fR which itself returns +\fBTCL_ERROR\fR if the \fIoptionName\fR is +unrecognized. +If \fInewValue\fR specifies a value for the option that +is not supported or if a system call error occurs, +the function should leave an error message in the +\fIresult\fR field of \fIinterp\fR if \fIinterp\fR is not NULL. The +function should also call \fBTcl_SetErrno\fR to store an appropriate POSIX +error code. +.PP +This value can be retrieved with \fBTcl_ChannelSetOptionProc\fR, which returns +a pointer to the function. +.SS GETOPTIONPROC +.PP +The \fIgetOptionProc\fR field contains the address of a function called by +the generic layer to get the value of a channel type specific option on a +channel. \fIgetOptionProc\fR must match the following prototype: +.PP +.CS +typedef int \fBTcl_DriverGetOptionProc\fR( + ClientData \fIinstanceData\fR, + Tcl_Interp *\fIinterp\fR, + const char *\fIoptionName\fR, + Tcl_DString *\fIoptionValue\fR); +.CE +.PP +\fIOptionName\fR is the name of an option supported by this type of +channel. If the option name is not NULL, the function stores its current +value, as a string, in the Tcl dynamic string \fIoptionValue\fR. +If \fIoptionName\fR is NULL, the function stores in \fIoptionValue\fR an +alternating list of all supported options and their current values. +On success, the function returns \fBTCL_OK\fR. +It should call \fBTcl_BadChannelOption\fR which itself returns +\fBTCL_ERROR\fR if the \fIoptionName\fR is +unrecognized. If a system call error occurs, +the function should leave an error message in the +result of \fIinterp\fR if \fIinterp\fR is not NULL. The +function should also call \fBTcl_SetErrno\fR to store an appropriate POSIX +error code. +.PP +Some options are handled by the generic code and this function is never +called to retrieve their value, e.g. \fB\-blockmode\fR. Other options are +specific to each channel type and the \fIgetOptionProc\fR procedure of the +channel driver will get called to implement them. The \fIgetOptionProc\fR +field can be NULL, which indicates that this channel type supports no type +specific options. +.PP +This value can be retrieved with \fBTcl_ChannelGetOptionProc\fR, which returns +a pointer to the function. +.SS WATCHPROC +.PP +The \fIwatchProc\fR field contains the address of a function called +by the generic layer to initialize the event notification mechanism to +notice events of interest on this channel. +\fIWatchProc\fR should match the following prototype: +.PP +.CS +typedef void \fBTcl_DriverWatchProc\fR( + ClientData \fIinstanceData\fR, + int \fImask\fR); +.CE +.PP +The \fIinstanceData\fR is the same as the value passed to +\fBTcl_CreateChannel\fR when this channel was created. The \fImask\fR +argument is an OR-ed combination of \fBTCL_READABLE\fR, \fBTCL_WRITABLE\fR +and \fBTCL_EXCEPTION\fR; it indicates events the caller is interested in +noticing on this channel. +.PP +The function should initialize device type specific mechanisms to +notice when an event of interest is present on the channel. When one +or more of the designated events occurs on the channel, the channel +driver is responsible for calling \fBTcl_NotifyChannel\fR to inform +the generic channel module. The driver should take care not to starve +other channel drivers or sources of callbacks by invoking +Tcl_NotifyChannel too frequently. Fairness can be insured by using +the Tcl event queue to allow the channel event to be scheduled in sequence +with other events. See the description of \fBTcl_QueueEvent\fR for +details on how to queue an event. +.PP +This value can be retrieved with \fBTcl_ChannelWatchProc\fR, which returns +a pointer to the function. +.SS GETHANDLEPROC +.PP +The \fIgetHandleProc\fR field contains the address of a function called by +the generic layer to retrieve a device-specific handle from the channel. +\fIGetHandleProc\fR should match the following prototype: +.PP +.CS +typedef int \fBTcl_DriverGetHandleProc\fR( + ClientData \fIinstanceData\fR, + int \fIdirection\fR, + ClientData *\fIhandlePtr\fR); +.CE +.PP +\fIInstanceData\fR is the same as the value passed to +\fBTcl_CreateChannel\fR when this channel was created. The \fIdirection\fR +argument is either \fBTCL_READABLE\fR to retrieve the handle used +for input, or \fBTCL_WRITABLE\fR to retrieve the handle used for +output. +.PP +If the channel implementation has device-specific handles, the +function should retrieve the appropriate handle associated with the +channel, according the \fIdirection\fR argument. The handle should be +stored in the location referred to by \fIhandlePtr\fR, and +\fBTCL_OK\fR should be returned. If the channel is not open for the +specified direction, or if the channel implementation does not use +device handles, the function should return \fBTCL_ERROR\fR. +.PP +This value can be retrieved with \fBTcl_ChannelGetHandleProc\fR, which returns +a pointer to the function. +.SS FLUSHPROC +.PP +The \fIflushProc\fR field is currently reserved for future use. +It should be set to NULL. +\fIFlushProc\fR should match the following prototype: +.PP +.CS +typedef int \fBTcl_DriverFlushProc\fR( + ClientData \fIinstanceData\fR); +.CE +.PP +This value can be retrieved with \fBTcl_ChannelFlushProc\fR, which returns +a pointer to the function. +.SS HANDLERPROC +.PP +The \fIhandlerProc\fR field contains the address of a function called by +the generic layer to notify the channel that an event occurred. It should +be defined for stacked channel drivers that wish to be notified of events +that occur on the underlying (stacked) channel. +\fIHandlerProc\fR should match the following prototype: +.PP +.CS +typedef int \fBTcl_DriverHandlerProc\fR( + ClientData \fIinstanceData\fR, + int \fIinterestMask\fR); +.CE +.PP +\fIInstanceData\fR is the same as the value passed to \fBTcl_CreateChannel\fR +when this channel was created. The \fIinterestMask\fR is an OR-ed +combination of \fBTCL_READABLE\fR or \fBTCL_WRITABLE\fR; it indicates what +type of event occurred on this channel. +.PP +This value can be retrieved with \fBTcl_ChannelHandlerProc\fR, which returns +a pointer to the function. + +.SS "THREADACTIONPROC" +.PP +The \fIthreadActionProc\fR field contains the address of the function +called by the generic layer when a channel is created, closed, or +going to move to a different thread, i.e. whenever thread-specific +driver state might have to initialized or updated. It can be NULL. +The action \fITCL_CHANNEL_THREAD_REMOVE\fR is used to notify the +driver that it should update or remove any thread-specific data it +might be maintaining for the channel. +.PP +The action \fITCL_CHANNEL_THREAD_INSERT\fR is used to notify the +driver that it should update or initialize any thread-specific data it +might be maintaining using the calling thread as the associate. See +\fBTcl_CutChannel\fR and \fBTcl_SpliceChannel\fR for more detail. +.PP +.CS +typedef void \fBTcl_DriverThreadActionProc\fR( + ClientData \fIinstanceData\fR, + int \fIaction\fR); +.CE +.PP +\fIInstanceData\fR is the same as the value passed to +\fBTcl_CreateChannel\fR when this channel was created. +.PP +These values can be retrieved with \fBTcl_ChannelThreadActionProc\fR, +which returns a pointer to the function. +.SS "TRUNCATEPROC" +.PP +The \fItruncateProc\fR field contains the address of the function +called by the generic layer when a channel is truncated to some +length. It can be NULL. +.PP +.CS +typedef int \fBTcl_DriverTruncateProc\fR( + ClientData \fIinstanceData\fR, + Tcl_WideInt \fIlength\fR); +.CE +.PP +\fIInstanceData\fR is the same as the value passed to +\fBTcl_CreateChannel\fR when this channel was created, and +\fIlength\fR is the new length of the underlying file, which should +not be negative. The result should be 0 on success or an errno code +(suitable for use with \fBTcl_SetErrno\fR) on failure. +.PP +These values can be retrieved with \fBTcl_ChannelTruncateProc\fR, +which returns a pointer to the function. +.SH TCL_BADCHANNELOPTION +.PP +This procedure generates a +.QW "bad option" +error message in an +(optional) interpreter. It is used by channel drivers when +an invalid Set/Get option is requested. Its purpose is to concatenate +the generic options list to the specific ones and factorize +the generic options error message string. +.PP +It always returns \fBTCL_ERROR\fR +.PP +An error message is generated in \fIinterp\fR's result value to +indicate that a command was invoked with a bad option. +The message has the form +.CS + bad option "blah": should be one of + <...generic options...>+<...specific options...> +.CE +so you get for instance: +.CS + bad option "-blah": should be one of -blocking, + -buffering, -buffersize, -eofchar, -translation, + -peername, or -sockname +.CE +when called with \fIoptionList\fR equal to +.QW "peername sockname" +.PP +.QW blah +is the \fIoptionName\fR argument and +.QW "<specific options>" +is a space separated list of specific option words. +The function takes good care of inserting minus signs before +each option, commas after, and an +.QW or +before the last option. +.SH "OLD CHANNEL TYPES" +The original (8.3.1 and below) \fBTcl_ChannelType\fR structure contains +the following fields: +.PP +.CS +typedef struct Tcl_ChannelType { + const char *\fItypeName\fR; + Tcl_DriverBlockModeProc *\fIblockModeProc\fR; + Tcl_DriverCloseProc *\fIcloseProc\fR; + Tcl_DriverInputProc *\fIinputProc\fR; + Tcl_DriverOutputProc *\fIoutputProc\fR; + Tcl_DriverSeekProc *\fIseekProc\fR; + Tcl_DriverSetOptionProc *\fIsetOptionProc\fR; + Tcl_DriverGetOptionProc *\fIgetOptionProc\fR; + Tcl_DriverWatchProc *\fIwatchProc\fR; + Tcl_DriverGetHandleProc *\fIgetHandleProc\fR; + Tcl_DriverClose2Proc *\fIclose2Proc\fR; +} \fBTcl_ChannelType\fR; +.CE +.PP +It is still possible to create channel with the above structure. The +internal channel code will determine the version. It is imperative to use +the new \fBTcl_ChannelType\fR structure if you are creating a stacked +channel driver, due to problems with the earlier stacked channel +implementation (in 8.2.0 to 8.3.1). +.PP +Prior to 8.4.0 (i.e. during the later releases of 8.3 and early part +of the 8.4 development cycle) the \fBTcl_ChannelType\fR structure +contained the following fields: +.PP +.CS +typedef struct Tcl_ChannelType { + const char *\fItypeName\fR; + Tcl_ChannelTypeVersion \fIversion\fR; + Tcl_DriverCloseProc *\fIcloseProc\fR; + Tcl_DriverInputProc *\fIinputProc\fR; + Tcl_DriverOutputProc *\fIoutputProc\fR; + Tcl_DriverSeekProc *\fIseekProc\fR; + Tcl_DriverSetOptionProc *\fIsetOptionProc\fR; + Tcl_DriverGetOptionProc *\fIgetOptionProc\fR; + Tcl_DriverWatchProc *\fIwatchProc\fR; + Tcl_DriverGetHandleProc *\fIgetHandleProc\fR; + Tcl_DriverClose2Proc *\fIclose2Proc\fR; + Tcl_DriverBlockModeProc *\fIblockModeProc\fR; + Tcl_DriverFlushProc *\fIflushProc\fR; + Tcl_DriverHandlerProc *\fIhandlerProc\fR; + Tcl_DriverTruncateProc *\fItruncateProc\fR; +} \fBTcl_ChannelType\fR; +.CE +.PP +When the above structure is registered as a channel type, the +\fIversion\fR field should always be \fBTCL_CHANNEL_VERSION_2\fR. +.SH "SEE ALSO" +Tcl_Close(3), Tcl_OpenFileChannel(3), Tcl_SetErrno(3), Tcl_QueueEvent(3), Tcl_StackChannel(3), Tcl_GetStdChannel(3) +.SH KEYWORDS +blocking, channel driver, channel registration, channel type, nonblocking diff --git a/tcl8.6/doc/CrtChnlHdlr.3 b/tcl8.6/doc/CrtChnlHdlr.3 new file mode 100644 index 0000000..0ecd3c9 --- /dev/null +++ b/tcl8.6/doc/CrtChnlHdlr.3 @@ -0,0 +1,89 @@ +'\" +'\" Copyright (c) 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. +'\" +.TH Tcl_CreateChannelHandler 3 7.5 Tcl "Tcl Library Procedures" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +Tcl_CreateChannelHandler, Tcl_DeleteChannelHandler \- call a procedure when a channel becomes readable or writable +.SH SYNOPSIS +.nf +.nf +\fB#include <tcl.h>\fR +.sp +void +\fBTcl_CreateChannelHandler\fR(\fIchannel, mask, proc, clientData\fR) +.sp +void +\fBTcl_DeleteChannelHandler\fR(\fIchannel, proc, clientData\fR) +.sp +.SH ARGUMENTS +.AS Tcl_ChannelProc clientData +.AP Tcl_Channel channel in +Tcl channel such as returned by \fBTcl_CreateChannel\fR. +.AP int mask in +Conditions under which \fIproc\fR should be called: OR-ed combination of +\fBTCL_READABLE\fR, \fBTCL_WRITABLE\fR and \fBTCL_EXCEPTION\fR. Specify +a zero value to temporarily disable an existing handler. +.AP Tcl_FileProc *proc in +Procedure to invoke whenever the channel indicated by \fIchannel\fR meets +the conditions specified by \fImask\fR. +.AP ClientData clientData in +Arbitrary one-word value to pass to \fIproc\fR. +.BE +.SH DESCRIPTION +.PP +\fBTcl_CreateChannelHandler\fR arranges for \fIproc\fR to be called in the +future whenever input or output becomes possible on the channel identified +by \fIchannel\fR, or whenever an exceptional condition exists for +\fIchannel\fR. The conditions of interest under which \fIproc\fR will be +invoked are specified by the \fImask\fR argument. +See the manual entry for \fBfileevent\fR for a precise description of +what it means for a channel to be readable or writable. +\fIProc\fR must conform to the following prototype: +.PP +.CS +typedef void \fBTcl_ChannelProc\fR( + ClientData \fIclientData\fR, + int \fImask\fR); +.CE +.PP +The \fIclientData\fR argument is the same as the value passed to +\fBTcl_CreateChannelHandler\fR when the handler was created. Typically, +\fIclientData\fR points to a data structure containing application-specific +information about the channel. \fIMask\fR is an integer mask indicating +which of the requested conditions actually exists for the channel; it will +contain a subset of the bits from the \fImask\fR argument to +\fBTcl_CreateChannelHandler\fR when the handler was created. +.PP +Each channel handler is identified by a unique combination of \fIchannel\fR, +\fIproc\fR and \fIclientData\fR. +There may be many handlers for a given channel as long as they do not +have the same \fIchannel\fR, \fIproc\fR, and \fIclientData\fR. +If \fBTcl_CreateChannelHandler\fR is invoked when there is already a handler +for \fIchannel\fR, \fIproc\fR, and \fIclientData\fR, then no new +handler is created; instead, the \fImask\fR is changed for the +existing handler. +.PP +\fBTcl_DeleteChannelHandler\fR deletes a channel handler identified by +\fIchannel\fR, \fIproc\fR and \fIclientData\fR; if no such handler exists, +the call has no effect. +.PP +Channel handlers are invoked via the Tcl event mechanism, so they +are only useful in applications that are event-driven. +Note also that the conditions specified in the \fImask\fR argument +to \fIproc\fR may no longer exist when \fIproc\fR is invoked: for +example, if there are two handlers for \fBTCL_READABLE\fR on the same +channel, the first handler could consume all of the available input +so that the channel is no longer readable when the second handler +is invoked. +For this reason it may be useful to use nonblocking I/O on channels +for which there are event handlers. +.SH "SEE ALSO" +Notifier(3), Tcl_CreateChannel(3), Tcl_OpenFileChannel(3), vwait(n). +.SH KEYWORDS +blocking, callback, channel, events, handler, nonblocking. diff --git a/tcl8.6/doc/CrtCloseHdlr.3 b/tcl8.6/doc/CrtCloseHdlr.3 new file mode 100644 index 0000000..bac2431 --- /dev/null +++ b/tcl8.6/doc/CrtCloseHdlr.3 @@ -0,0 +1,55 @@ +'\" +'\" 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. +'\" +.TH Tcl_CreateCloseHandler 3 7.5 Tcl "Tcl Library Procedures" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +Tcl_CreateCloseHandler, Tcl_DeleteCloseHandler \- arrange for callbacks when channels are closed +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +void +\fBTcl_CreateCloseHandler\fR(\fIchannel, proc, clientData\fR) +.sp +void +\fBTcl_DeleteCloseHandler\fR(\fIchannel, proc, clientData\fR) +.sp +.SH ARGUMENTS +.AS Tcl_CloseProc clientData +.AP Tcl_Channel channel in +The channel for which to create or delete a close callback. +.AP Tcl_CloseProc *proc in +The procedure to call as the callback. +.AP ClientData clientData in +Arbitrary one-word value to pass to \fIproc\fR. +.BE +.SH DESCRIPTION +.PP +\fBTcl_CreateCloseHandler\fR arranges for \fIproc\fR to be called when +\fIchannel\fR is closed with \fBTcl_Close\fR or +\fBTcl_UnregisterChannel\fR, or using the Tcl \fBclose\fR command. +\fIProc\fR should match the following prototype: +.PP +.CS +typedef void \fBTcl_CloseProc\fR( + ClientData \fIclientData\fR); +.CE +.PP +The \fIclientData\fR is the same as the value provided in the call to +\fBTcl_CreateCloseHandler\fR. +.PP +\fBTcl_DeleteCloseHandler\fR removes a close callback for \fIchannel\fR. +The \fIproc\fR and \fIclientData\fR identify which close callback to +remove; \fBTcl_DeleteCloseHandler\fR does nothing if its \fIproc\fR and +\fIclientData\fR arguments do not match the \fIproc\fR and \fIclientData\fR +for a close handler for \fIchannel\fR. +.SH "SEE ALSO" +close(n), Tcl_Close(3), Tcl_UnregisterChannel(3) +.SH KEYWORDS +callback, channel closing diff --git a/tcl8.6/doc/CrtCommand.3 b/tcl8.6/doc/CrtCommand.3 new file mode 100644 index 0000000..bf76d48 --- /dev/null +++ b/tcl8.6/doc/CrtCommand.3 @@ -0,0 +1,143 @@ +'\" +'\" Copyright (c) 1989-1993 The Regents of the University of California. +'\" Copyright (c) 1994-1997 Sun Microsystems, Inc. +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH Tcl_CreateCommand 3 "" Tcl "Tcl Library Procedures" +.so man.macros +.BS +.SH NAME +Tcl_CreateCommand \- implement new commands in C +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +Tcl_Command +\fBTcl_CreateCommand\fR(\fIinterp, cmdName, proc, clientData, deleteProc\fR) +.SH ARGUMENTS +.AS Tcl_CmdDeleteProc *deleteProc +.AP Tcl_Interp *interp in +Interpreter in which to create new command. +.AP "const char" *cmdName in +Name of command. +.AP Tcl_CmdProc *proc in +Implementation of new command: \fIproc\fR will be called whenever +\fIcmdName\fR is invoked as a command. +.AP ClientData clientData in +Arbitrary one-word value to pass to \fIproc\fR and \fIdeleteProc\fR. +.AP Tcl_CmdDeleteProc *deleteProc in +Procedure to call before \fIcmdName\fR is deleted from the interpreter; +allows for command-specific cleanup. If NULL, then no procedure is +called before the command is deleted. +.BE +.SH DESCRIPTION +.PP +\fBTcl_CreateCommand\fR defines a new command in \fIinterp\fR and associates +it with procedure \fIproc\fR such that whenever \fIcmdName\fR is +invoked as a Tcl command (via a call to \fBTcl_Eval\fR) the Tcl interpreter +will call \fIproc\fR to process the command. +It differs from \fBTcl_CreateObjCommand\fR in that a new string-based +command is defined; +that is, a command procedure is defined that takes an array of +argument strings instead of values. +The value-based command procedures registered by \fBTcl_CreateObjCommand\fR +can execute significantly faster than the string-based command procedures +defined by \fBTcl_CreateCommand\fR. +This is because they take Tcl values as arguments +and those values can retain an internal representation that +can be manipulated more efficiently. +Also, Tcl's interpreter now uses values internally. +In order to invoke a string-based command procedure +registered by \fBTcl_CreateCommand\fR, +it must generate and fetch a string representation +from each argument value before the call. +New commands should be defined using \fBTcl_CreateObjCommand\fR. +We support \fBTcl_CreateCommand\fR for backwards compatibility. +.PP +The procedures \fBTcl_DeleteCommand\fR, \fBTcl_GetCommandInfo\fR, +and \fBTcl_SetCommandInfo\fR are used in conjunction with +\fBTcl_CreateCommand\fR. +.PP +\fBTcl_CreateCommand\fR will delete an existing command \fIcmdName\fR, +if one is already associated with the interpreter. +It returns a token that may be used to refer +to the command in subsequent calls to \fBTcl_GetCommandName\fR. +If \fIcmdName\fR contains any \fB::\fR namespace qualifiers, +then the command is added to the specified namespace; +otherwise the command is added to the global namespace. +If \fBTcl_CreateCommand\fR is called for an interpreter that is in +the process of being deleted, then it does not create a new command +and it returns NULL. +\fIProc\fR should have arguments and result that match the type +\fBTcl_CmdProc\fR: +.PP +.CS +typedef int \fBTcl_CmdProc\fR( + ClientData \fIclientData\fR, + Tcl_Interp *\fIinterp\fR, + int \fIargc\fR, + const char *\fIargv\fR[]); +.CE +.PP +When \fIproc\fR is invoked the \fIclientData\fR and \fIinterp\fR +parameters will be copies of the \fIclientData\fR and \fIinterp\fR +arguments given to \fBTcl_CreateCommand\fR. +Typically, \fIclientData\fR points to an application-specific +data structure that describes what to do when the command procedure +is invoked. \fIArgc\fR and \fIargv\fR describe the arguments to +the command, \fIargc\fR giving the number of arguments (including +the command name) and \fIargv\fR giving the values of the arguments +as strings. The \fIargv\fR array will contain \fIargc\fR+1 values; +the first \fIargc\fR values point to the argument strings, and the +last value is NULL. +Note that the argument strings should not be modified as they may +point to constant strings or may be shared with other parts of the +interpreter. +.PP +Note that the argument strings are encoded in normalized UTF-8 since +version 8.1 of Tcl. +.PP +\fIProc\fR must return an integer code that is expected to be one of +\fBTCL_OK\fR, \fBTCL_ERROR\fR, \fBTCL_RETURN\fR, \fBTCL_BREAK\fR, or +\fBTCL_CONTINUE\fR. See the Tcl overview man page +for details on what these codes mean. Most normal commands will only +return \fBTCL_OK\fR or \fBTCL_ERROR\fR. In addition, \fIproc\fR must set +the interpreter result; +in the case of a \fBTCL_OK\fR return code this gives the result +of the command, and in the case of \fBTCL_ERROR\fR it gives an error message. +The \fBTcl_SetResult\fR procedure provides an easy interface for setting +the return value; for complete details on how the interpreter result +field is managed, see the \fBTcl_Interp\fR man page. +Before invoking a command procedure, +\fBTcl_Eval\fR sets the interpreter result to point to an empty string, +so simple commands can return an empty result by doing nothing at all. +.PP +The contents of the \fIargv\fR array belong to Tcl and are not +guaranteed to persist once \fIproc\fR returns: \fIproc\fR should +not modify them, nor should it set the interpreter result to point +anywhere within the \fIargv\fR values. +Call \fBTcl_SetResult\fR with status \fBTCL_VOLATILE\fR if you want +to return something from the \fIargv\fR array. +.PP +\fIDeleteProc\fR will be invoked when (if) \fIcmdName\fR is deleted. This can +occur through a call to \fBTcl_DeleteCommand\fR or \fBTcl_DeleteInterp\fR, +or by replacing \fIcmdName\fR in another call to \fBTcl_CreateCommand\fR. +\fIDeleteProc\fR is invoked before the command is deleted, and gives the +application an opportunity to release any structures associated +with the command. \fIDeleteProc\fR should have arguments and +result that match the type \fBTcl_CmdDeleteProc\fR: +.PP +.CS +typedef void \fBTcl_CmdDeleteProc\fR( + ClientData \fIclientData\fR); +.CE +.PP +The \fIclientData\fR argument will be the same as the \fIclientData\fR +argument passed to \fBTcl_CreateCommand\fR. +.SH "SEE ALSO" +Tcl_CreateObjCommand, Tcl_DeleteCommand, Tcl_GetCommandInfo, +Tcl_SetCommandInfo, Tcl_GetCommandName, Tcl_SetObjResult +.SH KEYWORDS +bind, command, create, delete, interpreter, namespace diff --git a/tcl8.6/doc/CrtFileHdlr.3 b/tcl8.6/doc/CrtFileHdlr.3 new file mode 100644 index 0000000..c1bc1fa --- /dev/null +++ b/tcl8.6/doc/CrtFileHdlr.3 @@ -0,0 +1,91 @@ +'\" +'\" Copyright (c) 1990-1994 The Regents of the University of California. +'\" Copyright (c) 1994-1997 Sun Microsystems, Inc. +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH Tcl_CreateFileHandler 3 8.0 Tcl "Tcl Library Procedures" +.so man.macros +.BS +.SH NAME +Tcl_CreateFileHandler, Tcl_DeleteFileHandler \- associate procedure callbacks with files or devices (Unix only) +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +\fBTcl_CreateFileHandler\fR(\fIfd, mask, proc, clientData\fR) +.sp +\fBTcl_DeleteFileHandler\fR(\fIfd\fR) +.SH ARGUMENTS +.AS Tcl_FileProc clientData +.AP int fd in +Unix file descriptor for an open file or device. +.AP int mask in +Conditions under which \fIproc\fR should be called: +OR-ed combination of \fBTCL_READABLE\fR, \fBTCL_WRITABLE\fR, +and \fBTCL_EXCEPTION\fR. May be set to 0 to temporarily disable +a handler. +.AP Tcl_FileProc *proc in +Procedure to invoke whenever the file or device indicated +by \fIfile\fR meets the conditions specified by \fImask\fR. +.AP ClientData clientData in +Arbitrary one-word value to pass to \fIproc\fR. +.BE +.SH DESCRIPTION +.PP +\fBTcl_CreateFileHandler\fR arranges for \fIproc\fR to be +invoked in the future whenever I/O becomes possible on a file +or an exceptional condition exists for the file. The file +is indicated by \fIfd\fR, and the conditions of interest +are indicated by \fImask\fR. For example, if \fImask\fR +is \fBTCL_READABLE\fR, \fIproc\fR will be called when +the file is readable. +The callback to \fIproc\fR is made by \fBTcl_DoOneEvent\fR, so +\fBTcl_CreateFileHandler\fR is only useful in programs that dispatch +events through \fBTcl_DoOneEvent\fR or through Tcl commands such +as \fBvwait\fR. +.PP +\fIProc\fR should have arguments and result that match the +type \fBTcl_FileProc\fR: +.PP +.CS +typedef void \fBTcl_FileProc\fR( + ClientData \fIclientData\fR, + int \fImask\fR); +.CE +.PP +The \fIclientData\fR parameter to \fIproc\fR is a copy +of the \fIclientData\fR +argument given to \fBTcl_CreateFileHandler\fR when the callback +was created. Typically, \fIclientData\fR points to a data +structure containing application-specific information about +the file. \fIMask\fR is an integer mask indicating which +of the requested conditions actually exists for the file; it +will contain a subset of the bits in the \fImask\fR argument +to \fBTcl_CreateFileHandler\fR. +.PP +There may exist only one handler for a given file at a given time. +If \fBTcl_CreateFileHandler\fR is called when a handler already +exists for \fIfd\fR, then the new callback replaces the information +that was previously recorded. +.PP +\fBTcl_DeleteFileHandler\fR may be called to delete the +file handler for \fIfd\fR; if no handler exists for the +file given by \fIfd\fR then the procedure has no effect. +.PP +The purpose of file handlers is to enable an application to respond to +events while waiting for files to become ready for I/O. For this to work +correctly, the application may need to use non-blocking I/O operations on +the files for which handlers are declared. Otherwise the application may +block if it reads or writes too much data; while waiting for the I/O to +complete the application will not be able to service other events. Use +\fBTcl_SetChannelOption\fR with \fB\-blocking\fR to set the channel into +blocking or nonblocking mode as required. +.PP +Note that these interfaces are only supported by the Unix +implementation of the Tcl notifier. +.SH "SEE ALSO" +fileevent(n), Tcl_CreateTimerHandler(3), Tcl_DoWhenIdle(3) +.SH KEYWORDS +callback, file, handler diff --git a/tcl8.6/doc/CrtInterp.3 b/tcl8.6/doc/CrtInterp.3 new file mode 100644 index 0000000..679795e --- /dev/null +++ b/tcl8.6/doc/CrtInterp.3 @@ -0,0 +1,150 @@ +'\" +'\" Copyright (c) 1989-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. +'\" +.TH Tcl_CreateInterp 3 7.5 Tcl "Tcl Library Procedures" +.so man.macros +.BS +.SH NAME +Tcl_CreateInterp, Tcl_DeleteInterp, Tcl_InterpActive, Tcl_InterpDeleted \- create and delete Tcl command interpreters +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +Tcl_Interp * +\fBTcl_CreateInterp\fR() +.sp +\fBTcl_DeleteInterp\fR(\fIinterp\fR) +.sp +int +\fBTcl_InterpDeleted\fR(\fIinterp\fR) +.sp +.VS 8.6 +int +\fBTcl_InterpActive\fR(\fIinterp\fR) +.VE 8.6 +.SH ARGUMENTS +.AS Tcl_Interp *interp +.AP Tcl_Interp *interp in +Token for interpreter to be destroyed or queried. +.BE +.SH DESCRIPTION +.PP +\fBTcl_CreateInterp\fR creates a new interpreter structure and returns +a token for it. The token is required in calls to most other Tcl +procedures, such as \fBTcl_CreateCommand\fR, \fBTcl_Eval\fR, and +\fBTcl_DeleteInterp\fR. The token returned by \fBTcl_CreateInterp\fR +may only be passed to Tcl routines called from the same thread as +the original \fBTcl_CreateInterp\fR call. It is not safe for multiple +threads to pass the same token to Tcl's routines. +The new interpreter is initialized with the built-in Tcl commands +and with standard variables like \fBtcl_platform\fR and \fBenv\fR. To +bind in additional commands, call \fBTcl_CreateCommand\fR, and to +create additional variables, call \fBTcl_SetVar\fR. +.PP +\fBTcl_DeleteInterp\fR marks an interpreter as deleted; the interpreter +will eventually be deleted when all calls to \fBTcl_Preserve\fR for it have +been matched by calls to \fBTcl_Release\fR. At that time, all of the +resources associated with it, including variables, procedures, and +application-specific command bindings, will be deleted. After +\fBTcl_DeleteInterp\fR returns any attempt to use \fBTcl_Eval\fR on the +interpreter will fail and return \fBTCL_ERROR\fR. After the call to +\fBTcl_DeleteInterp\fR it is safe to examine the interpreter's result, +query or set the values of variables, define, undefine or retrieve +procedures, and examine the runtime evaluation stack. See below, in the +section \fBINTERPRETERS AND MEMORY MANAGEMENT\fR for details. +.PP +\fBTcl_InterpDeleted\fR returns nonzero if \fBTcl_DeleteInterp\fR was +called with \fIinterp\fR as its argument; this indicates that the +interpreter will eventually be deleted, when the last call to +\fBTcl_Preserve\fR for it is matched by a call to \fBTcl_Release\fR. If +nonzero is returned, further calls to \fBTcl_Eval\fR in this interpreter +will return \fBTCL_ERROR\fR. +.PP +\fBTcl_InterpDeleted\fR is useful in deletion callbacks to distinguish +between when only the memory the callback is responsible for is being +deleted and when the whole interpreter is being deleted. In the former case +the callback may recreate the data being deleted, but this would lead to an +infinite loop if the interpreter were being deleted. +.PP +.VS 8.6 +\fBTcl_InterpActive\fR is useful for determining whether there is any +execution of scripts ongoing in an interpreter, which is a useful piece of +information when Tcl is embedded in a garbage-collected environment and it +becomes necessary to determine whether the interpreter is a candidate for +deletion. The function returns a true value if the interpreter has at least +one active execution running inside it, and a false value otherwise. +.VE 8.6 +.SH "INTERPRETERS AND MEMORY MANAGEMENT" +.PP +\fBTcl_DeleteInterp\fR can be called at any time on an interpreter that may +be used by nested evaluations and C code in various extensions. Tcl +implements a simple mechanism that allows callers to use interpreters +without worrying about the interpreter being deleted in a nested call, and +without requiring special code to protect the interpreter, in most cases. +This mechanism ensures that nested uses of an interpreter can safely +continue using it even after \fBTcl_DeleteInterp\fR is called. +.PP +The mechanism relies on matching up calls to \fBTcl_Preserve\fR with calls +to \fBTcl_Release\fR. If \fBTcl_DeleteInterp\fR has been called, only when +the last call to \fBTcl_Preserve\fR is matched by a call to +\fBTcl_Release\fR, will the interpreter be freed. See the manual entry for +\fBTcl_Preserve\fR for a description of these functions. +.PP +The rules for when the user of an interpreter must call \fBTcl_Preserve\fR +and \fBTcl_Release\fR are simple: +.TP +\fBInterpreters Passed As Arguments\fR +. +Functions that are passed an interpreter as an argument can safely use the +interpreter without any special protection. Thus, when you write an +extension consisting of new Tcl commands, no special code is needed to +protect interpreters received as arguments. This covers the majority of all +uses. +.TP +\fBInterpreter Creation And Deletion\fR +. +When a new interpreter is created and used in a call to \fBTcl_Eval\fR, +\fBTcl_VarEval\fR, \fBTcl_GlobalEval\fR, \fBTcl_SetVar\fR, or +\fBTcl_GetVar\fR, a pair of calls to \fBTcl_Preserve\fR and +\fBTcl_Release\fR should be wrapped around all uses of the interpreter. +Remember that it is unsafe to use the interpreter once \fBTcl_Release\fR +has been called. To ensure that the interpreter is properly deleted when +it is no longer needed, call \fBTcl_InterpDeleted\fR to test if some other +code already called \fBTcl_DeleteInterp\fR; if not, call +\fBTcl_DeleteInterp\fR before calling \fBTcl_Release\fR in your own code. +.TP +\fBRetrieving An Interpreter From A Data Structure\fR +. +When an interpreter is retrieved from a data structure (e.g. the client +data of a callback) for use in one of the evaluation functions +(\fBTcl_Eval\fR, \fBTcl_VarEval\fR, \fBTcl_GlobalEval\fR, \fBTcl_EvalObjv\fR, +etc.) or variable access functions (\fBTcl_SetVar\fR, \fBTcl_GetVar\fR, +\fBTcl_SetVar2Ex\fR, etc.), a pair of +calls to \fBTcl_Preserve\fR and \fBTcl_Release\fR should be wrapped around +all uses of the interpreter; it is unsafe to reuse the interpreter once +\fBTcl_Release\fR has been called. If an interpreter is stored inside a +callback data structure, an appropriate deletion cleanup mechanism should +be set up by the code that creates the data structure so that the +interpreter is removed from the data structure (e.g. by setting the field +to NULL) when the interpreter is deleted. Otherwise, you may be using an +interpreter that has been freed and whose memory may already have been +reused. +.PP +All uses of interpreters in Tcl and Tk have already been protected. +Extension writers should ensure that their code also properly protects any +additional interpreters used, as described above. +.PP +.VS 8.6 +Note that the protection mechanisms do not work well with conventional garbage +collection systems. When in such a managed environment, \fBTcl_InterpActive\fR +should be used to determine when an interpreter is a candidate for deletion +due to inactivity. +.VE 8.6 +.SH "SEE ALSO" +Tcl_Preserve(3), Tcl_Release(3) +.SH KEYWORDS +command, create, delete, interpreter diff --git a/tcl8.6/doc/CrtMathFnc.3 b/tcl8.6/doc/CrtMathFnc.3 new file mode 100644 index 0000000..acceb5b --- /dev/null +++ b/tcl8.6/doc/CrtMathFnc.3 @@ -0,0 +1,162 @@ +'\" +'\" Copyright (c) 1989-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. +'\" +.TH Tcl_CreateMathFunc 3 8.4 Tcl "Tcl Library Procedures" +.so man.macros +.BS +.SH NAME +Tcl_CreateMathFunc, Tcl_GetMathFuncInfo, Tcl_ListMathFuncs \- Define, query and enumerate math functions for expressions +.SH "NOTICE OF EVENTUAL DEPRECATION" +.PP +The \fBTcl_CreateMathFunc\fR and \fBTcl_GetMathFuncInfo\fR functions +are rendered somewhat obsolete by the ability to create functions for +expressions by placing commands in the \fBtcl::mathfunc\fR namespace, +as described in the \fBmathfunc\fR manual page; the API described on +this page is not expected to be maintained indefinitely. +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +void +\fBTcl_CreateMathFunc\fR(\fIinterp, name, numArgs, argTypes, proc, clientData\fR) +.sp +int +\fBTcl_GetMathFuncInfo\fR(\fIinterp, name, numArgsPtr, argTypesPtr, procPtr, + clientDataPtr\fR) +.sp +Tcl_Obj * +\fBTcl_ListMathFuncs\fR(\fIinterp, pattern\fR) +.SH ARGUMENTS +.AS Tcl_ValueType *clientDataPtr out +.AP Tcl_Interp *interp in +Interpreter in which new function will be defined. +.AP "const char" *name in +Name for new function. +.AP int numArgs in +Number of arguments to new function; also gives size of \fIargTypes\fR array. +.AP Tcl_ValueType *argTypes in +Points to an array giving the permissible types for each argument to +function. +.AP Tcl_MathProc *proc in +Procedure that implements the function. +.AP ClientData clientData in +Arbitrary one-word value to pass to \fIproc\fR when it is invoked. +.AP int *numArgsPtr out +Points to a variable that will be set to contain the number of +arguments to the function. +.AP Tcl_ValueType **argTypesPtr out +Points to a variable that will be set to contain a pointer to an array +giving the permissible types for each argument to the function which +will need to be freed up using \fITcl_Free\fR. +.AP Tcl_MathProc **procPtr out +Points to a variable that will be set to contain a pointer to the +implementation code for the function (or NULL if the function is +implemented directly in bytecode). +.AP ClientData *clientDataPtr out +Points to a variable that will be set to contain the clientData +argument passed to \fITcl_CreateMathFunc\fR when the function was +created if the function is not implemented directly in bytecode. +.AP "const char" *pattern in +Pattern to match against function names so as to filter them (by +passing to \fITcl_StringMatch\fR), or NULL to not apply any filter. +.BE +.SH DESCRIPTION +.PP +Tcl allows a number of mathematical functions to be used in +expressions, such as \fBsin\fR, \fBcos\fR, and \fBhypot\fR. +These functions are represented by commands in the namespace, +\fBtcl::mathfunc\fR. The \fBTcl_CreateMathFunc\fR function is +an obsolete way for applications to add additional functions +to those already provided by Tcl or to replace existing functions. +It should not be used by new applications, which should create +math functions using \fBTcl_CreateObjCommand\fR to create a command +in the \fBtcl::mathfunc\fR namespace. +.PP +In the \fBTcl_CreateMathFunc\fR interface, +\fIName\fR is the name of the function as it will appear in expressions. +If \fIname\fR does not already exist in the \fB::tcl::mathfunc\fR +namespace, then a new command is created in that namespace. +If \fIname\fR does exist, then the existing function is replaced. +\fINumArgs\fR and \fIargTypes\fR describe the arguments to the function. +Each entry in the \fIargTypes\fR array must be +one of \fBTCL_INT\fR, \fBTCL_DOUBLE\fR, \fBTCL_WIDE_INT\fR, +or \fBTCL_EITHER\fR to indicate whether the corresponding argument must be an +integer, a double-precision floating value, a wide (64-bit) integer, +or any, respectively. +.PP +Whenever the function is invoked in an expression Tcl will invoke +\fIproc\fR. \fIProc\fR should have arguments and result that match +the type \fBTcl_MathProc\fR: +.PP +.CS +typedef int \fBTcl_MathProc\fR( + ClientData \fIclientData\fR, + Tcl_Interp *\fIinterp\fR, + Tcl_Value *\fIargs\fR, + Tcl_Value *\fIresultPtr\fR); +.CE +.PP +When \fIproc\fR is invoked the \fIclientData\fR and \fIinterp\fR +arguments will be the same as those passed to \fBTcl_CreateMathFunc\fR. +\fIArgs\fR will point to an array of \fInumArgs\fR Tcl_Value structures, +which describe the actual arguments to the function: +.PP +.CS +typedef struct Tcl_Value { + Tcl_ValueType \fItype\fR; + long \fIintValue\fR; + double \fIdoubleValue\fR; + Tcl_WideInt \fIwideValue\fR; +} \fBTcl_Value\fR; +.CE +.PP +The \fItype\fR field indicates the type of the argument and is +one of \fBTCL_INT\fR, \fBTCL_DOUBLE\fR or \fBTCL_WIDE_INT\fR. +It will match the \fIargTypes\fR value specified for the function unless +the \fIargTypes\fR value was \fBTCL_EITHER\fR. Tcl converts +the argument supplied in the expression to the type requested in +\fIargTypes\fR, if that is necessary. +Depending on the value of the \fItype\fR field, the \fIintValue\fR, +\fIdoubleValue\fR or \fIwideValue\fR +field will contain the actual value of the argument. +.PP +\fIProc\fR should compute its result and store it either as an integer +in \fIresultPtr->intValue\fR or as a floating value in +\fIresultPtr->doubleValue\fR. +It should set also \fIresultPtr->type\fR to one of +\fBTCL_INT\fR, \fBTCL_DOUBLE\fR or \fBTCL_WIDE_INT\fR +to indicate which value was set. +Under normal circumstances \fIproc\fR should return \fBTCL_OK\fR. +If an error occurs while executing the function, \fIproc\fR should +return \fBTCL_ERROR\fR and leave an error message in the interpreter's result. +.PP +\fBTcl_GetMathFuncInfo\fR retrieves the values associated with +function \fIname\fR that were passed to a preceding +\fBTcl_CreateMathFunc\fR call. Normally, the return code is +\fBTCL_OK\fR but if the named function does not exist, \fBTCL_ERROR\fR +is returned and an error message is placed in the interpreter's +result. +.PP +If an error did not occur, the array reference placed in the variable +pointed to by \fIargTypesPtr\fR is newly allocated, and should be +released by passing it to \fBTcl_Free\fR. Some functions (the +standard set implemented in the core, and those defined by placing +commands in the \fBtcl::mathfunc\fR namespace) do not have +argument type information; attempting to retrieve values for +them causes a NULL to be stored in the variable pointed to by +\fIprocPtr\fR and the variable pointed to by \fIclientDataPtr\fR +will not be modified. The variable pointed to by \fInumArgsPointer\fR +will contain -1, and no argument types will be stored in the variable +pointed to by \fIargTypesPointer\fR. +.PP +\fBTcl_ListMathFuncs\fR returns a Tcl value containing a list of all +the math functions defined in the interpreter whose name matches +\fIpattern\fR. The returned value has a reference count of zero. +.SH "SEE ALSO" +expr(n), info(n), Tcl_CreateObjCommand(3), Tcl_Free(3), Tcl_NewListObj(3) +.SH KEYWORDS +expression, mathematical function diff --git a/tcl8.6/doc/CrtObjCmd.3 b/tcl8.6/doc/CrtObjCmd.3 new file mode 100644 index 0000000..6714bd7 --- /dev/null +++ b/tcl8.6/doc/CrtObjCmd.3 @@ -0,0 +1,302 @@ +'\" +'\" Copyright (c) 1996-1997 Sun Microsystems, Inc. +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH Tcl_CreateObjCommand 3 8.0 Tcl "Tcl Library Procedures" +.so man.macros +.BS +.SH NAME +Tcl_CreateObjCommand, Tcl_DeleteCommand, Tcl_DeleteCommandFromToken, Tcl_GetCommandInfo, Tcl_GetCommandInfoFromToken, Tcl_SetCommandInfo, Tcl_SetCommandInfoFromToken, Tcl_GetCommandName, Tcl_GetCommandFullName, Tcl_GetCommandFromObj \- implement new commands in C +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +Tcl_Command +\fBTcl_CreateObjCommand\fR(\fIinterp, cmdName, proc, clientData, deleteProc\fR) +.sp +int +\fBTcl_DeleteCommand\fR(\fIinterp, cmdName\fR) +.sp +int +\fBTcl_DeleteCommandFromToken\fR(\fIinterp, token\fR) +.sp +int +\fBTcl_GetCommandInfo\fR(\fIinterp, cmdName, infoPtr\fR) +.sp +int +\fBTcl_SetCommandInfo\fR(\fIinterp, cmdName, infoPtr\fR) +.sp +int +\fBTcl_GetCommandInfoFromToken\fR(\fItoken, infoPtr\fR) +.sp +int +\fBTcl_SetCommandInfoFromToken\fR(\fItoken, infoPtr\fR) +.sp +const char * +\fBTcl_GetCommandName\fR(\fIinterp, token\fR) +.sp +void +\fBTcl_GetCommandFullName\fR(\fIinterp, token, objPtr\fR) +.sp +Tcl_Command +\fBTcl_GetCommandFromObj\fR(\fIinterp, objPtr\fR) +.SH ARGUMENTS +.AS Tcl_CmdDeleteProc *deleteProc in/out +.AP Tcl_Interp *interp in +Interpreter in which to create a new command or that contains a command. +.AP char *cmdName in +Name of command. +.AP Tcl_ObjCmdProc *proc in +Implementation of the new command: \fIproc\fR will be called whenever +\fIcmdName\fR is invoked as a command. +.AP ClientData clientData in +Arbitrary one-word value to pass to \fIproc\fR and \fIdeleteProc\fR. +.AP Tcl_CmdDeleteProc *deleteProc in +Procedure to call before \fIcmdName\fR is deleted from the interpreter; +allows for command-specific cleanup. If NULL, then no procedure is +called before the command is deleted. +.AP Tcl_Command token in +Token for command, returned by previous call to \fBTcl_CreateObjCommand\fR. +The command must not have been deleted. +.AP Tcl_CmdInfo *infoPtr in/out +Pointer to structure containing various information about a +Tcl command. +.AP Tcl_Obj *objPtr in +Value containing the name of a Tcl command. +.BE +.SH DESCRIPTION +.PP +\fBTcl_CreateObjCommand\fR defines a new command in \fIinterp\fR +and associates it with procedure \fIproc\fR +such that whenever \fIname\fR is +invoked as a Tcl command (e.g., via a call to \fBTcl_EvalObjEx\fR) +the Tcl interpreter will call \fIproc\fR to process the command. +.PP +\fBTcl_CreateObjCommand\fR deletes any existing command +\fIname\fR already associated with the interpreter +(however see below for an exception where the existing command +is not deleted). +It returns a token that may be used to refer +to the command in subsequent calls to \fBTcl_GetCommandName\fR. +If \fIname\fR contains any \fB::\fR namespace qualifiers, +then the command is added to the specified namespace; +otherwise the command is added to the global namespace. +If \fBTcl_CreateObjCommand\fR is called for an interpreter that is in +the process of being deleted, then it does not create a new command +and it returns NULL. +\fIproc\fR should have arguments and result that match the type +\fBTcl_ObjCmdProc\fR: +.PP +.CS +typedef int \fBTcl_ObjCmdProc\fR( + ClientData \fIclientData\fR, + Tcl_Interp *\fIinterp\fR, + int \fIobjc\fR, + Tcl_Obj *const \fIobjv\fR[]); +.CE +.PP +When \fIproc\fR is invoked, the \fIclientData\fR and \fIinterp\fR parameters +will be copies of the \fIclientData\fR and \fIinterp\fR arguments given to +\fBTcl_CreateObjCommand\fR. Typically, \fIclientData\fR points to an +application-specific data structure that describes what to do when the +command procedure is invoked. \fIObjc\fR and \fIobjv\fR describe the +arguments to the command, \fIobjc\fR giving the number of argument values +(including the command name) and \fIobjv\fR giving the values of the +arguments. The \fIobjv\fR array will contain \fIobjc\fR values, pointing to +the argument values. Unlike \fIargv\fR[\fIargv\fR] used in a +string-based command procedure, \fIobjv\fR[\fIobjc\fR] will not contain NULL. +.PP +Additionally, when \fIproc\fR is invoked, it must not modify the contents +of the \fIobjv\fR array by assigning new pointer values to any element of the +array (for example, \fIobjv\fR[\fB2\fR] = \fBNULL\fR) because this will +cause memory to be lost and the runtime stack to be corrupted. The +\fBconst\fR in the declaration of \fIobjv\fR will cause ANSI-compliant +compilers to report any such attempted assignment as an error. However, +it is acceptable to modify the internal representation of any individual +value argument. For instance, the user may call +\fBTcl_GetIntFromObj\fR on \fIobjv\fR[\fB2\fR] to obtain the integer +representation of that value; that call may change the type of the value +that \fIobjv\fR[\fB2\fR] points at, but will not change where +\fIobjv\fR[\fB2\fR] points. +.PP +\fIproc\fR must return an integer code that is either \fBTCL_OK\fR, +\fBTCL_ERROR\fR, \fBTCL_RETURN\fR, \fBTCL_BREAK\fR, or \fBTCL_CONTINUE\fR. +See the Tcl overview man page +for details on what these codes mean. Most normal commands will only +return \fBTCL_OK\fR or \fBTCL_ERROR\fR. +In addition, if \fIproc\fR needs to return a non-empty result, +it can call \fBTcl_SetObjResult\fR to set the interpreter's result. +In the case of a \fBTCL_OK\fR return code this gives the result +of the command, +and in the case of \fBTCL_ERROR\fR this gives an error message. +Before invoking a command procedure, +\fBTcl_EvalObjEx\fR sets interpreter's result to +point to a value representing an empty string, so simple +commands can return an empty result by doing nothing at all. +.PP +The contents of the \fIobjv\fR array belong to Tcl and are not +guaranteed to persist once \fIproc\fR returns: \fIproc\fR should +not modify them. +Call \fBTcl_SetObjResult\fR if you want +to return something from the \fIobjv\fR array. +.PP +Ordinarily, \fBTcl_CreateObjCommand\fR deletes any existing command +\fIname\fR already associated with the interpreter. +However, if the existing command was created by a previous call to +\fBTcl_CreateCommand\fR, +\fBTcl_CreateObjCommand\fR does not delete the command +but instead arranges for the Tcl interpreter to call the +\fBTcl_ObjCmdProc\fR \fIproc\fR in the future. +The old string-based \fBTcl_CmdProc\fR associated with the command +is retained and its address can be obtained by subsequent +\fBTcl_GetCommandInfo\fR calls. This is done for backwards compatibility. +.PP +\fIDeleteProc\fR will be invoked when (if) \fIname\fR is deleted. +This can occur through a call to \fBTcl_DeleteCommand\fR, +\fBTcl_DeleteCommandFromToken\fR, or \fBTcl_DeleteInterp\fR, +or by replacing \fIname\fR in another call to \fBTcl_CreateObjCommand\fR. +\fIDeleteProc\fR is invoked before the command is deleted, and gives the +application an opportunity to release any structures associated +with the command. \fIDeleteProc\fR should have arguments and +result that match the type \fBTcl_CmdDeleteProc\fR: +.PP +.CS +typedef void \fBTcl_CmdDeleteProc\fR( + ClientData \fIclientData\fR); +.CE +.PP +The \fIclientData\fR argument will be the same as the \fIclientData\fR +argument passed to \fBTcl_CreateObjCommand\fR. +.PP +\fBTcl_DeleteCommand\fR deletes a command from a command interpreter. +Once the call completes, attempts to invoke \fIcmdName\fR in +\fIinterp\fR will result in errors. +If \fIcmdName\fR is not bound as a command in \fIinterp\fR then +\fBTcl_DeleteCommand\fR does nothing and returns -1; otherwise +it returns 0. +There are no restrictions on \fIcmdName\fR: it may refer to +a built-in command, an application-specific command, or a Tcl procedure. +If \fIname\fR contains any \fB::\fR namespace qualifiers, +the command is deleted from the specified namespace. +.PP +Given a token returned by \fBTcl_CreateObjCommand\fR, +\fBTcl_DeleteCommandFromToken\fR deletes the command +from a command interpreter. +It will delete a command even if that command has been renamed. +Once the call completes, attempts to invoke the command in +\fIinterp\fR will result in errors. +If the command corresponding to \fItoken\fR +has already been deleted from \fIinterp\fR then +\fBTcl_DeleteCommand\fR does nothing and returns -1; +otherwise it returns 0. +.PP +\fBTcl_GetCommandInfo\fR checks to see whether its \fIcmdName\fR argument +exists as a command in \fIinterp\fR. +\fIcmdName\fR may include \fB::\fR namespace qualifiers +to identify a command in a particular namespace. +If the command is not found, then it returns 0. +Otherwise it places information about the command +in the \fBTcl_CmdInfo\fR structure +pointed to by \fIinfoPtr\fR and returns 1. +A \fBTcl_CmdInfo\fR structure has the following fields: +.PP +.CS +typedef struct Tcl_CmdInfo { + int \fIisNativeObjectProc\fR; + Tcl_ObjCmdProc *\fIobjProc\fR; + ClientData \fIobjClientData\fR; + Tcl_CmdProc *\fIproc\fR; + ClientData \fIclientData\fR; + Tcl_CmdDeleteProc *\fIdeleteProc\fR; + ClientData \fIdeleteData\fR; + Tcl_Namespace *\fInamespacePtr\fR; +} \fBTcl_CmdInfo\fR; +.CE +.PP +The \fIisNativeObjectProc\fR field has the value 1 +if \fBTcl_CreateObjCommand\fR was called to register the command; +it is 0 if only \fBTcl_CreateCommand\fR was called. +It allows a program to determine whether it is faster to +call \fIobjProc\fR or \fIproc\fR: +\fIobjProc\fR is normally faster +if \fIisNativeObjectProc\fR has the value 1. +The fields \fIobjProc\fR and \fIobjClientData\fR +have the same meaning as the \fIproc\fR and \fIclientData\fR +arguments to \fBTcl_CreateObjCommand\fR; +they hold information about the value-based command procedure +that the Tcl interpreter calls to implement the command. +The fields \fIproc\fR and \fIclientData\fR +hold information about the string-based command procedure +that implements the command. +If \fBTcl_CreateCommand\fR was called for this command, +this is the procedure passed to it; +otherwise, this is a compatibility procedure +registered by \fBTcl_CreateObjCommand\fR +that simply calls the command's +value-based procedure after converting its string arguments to Tcl values. +The field \fIdeleteData\fR is the ClientData value +to pass to \fIdeleteProc\fR; it is normally the same as +\fIclientData\fR but may be set independently using the +\fBTcl_SetCommandInfo\fR procedure. +The field \fInamespacePtr\fR holds a pointer to the +Tcl_Namespace that contains the command. +.PP +\fBTcl_GetCommandInfoFromToken\fR is identical to +\fBTcl_GetCommandInfo\fR except that it uses a command token returned +from \fBTcl_CreateObjCommand\fR in place of the command name. If the +\fItoken\fR parameter is NULL, it returns 0; otherwise, it returns 1 +and fills in the structure designated by \fIinfoPtr\fR. +.PP +\fBTcl_SetCommandInfo\fR is used to modify the procedures and +ClientData values associated with a command. +Its \fIcmdName\fR argument is the name of a command in \fIinterp\fR. +\fIcmdName\fR may include \fB::\fR namespace qualifiers +to identify a command in a particular namespace. +If this command does not exist then \fBTcl_SetCommandInfo\fR returns 0. +Otherwise, it copies the information from \fI*infoPtr\fR to +Tcl's internal structure for the command and returns 1. +.PP +\fBTcl_SetCommandInfoFromToken\fR is identical to +\fBTcl_SetCommandInfo\fR except that it takes a command token as +returned by \fBTcl_CreateObjCommand\fR instead of the command name. +If the \fItoken\fR parameter is NULL, it returns 0. Otherwise, it +copies the information from \fI*infoPtr\fR to Tcl's internal structure +for the command and returns 1. +.PP +Note that \fBTcl_SetCommandInfo\fR and +\fBTcl_SetCommandInfoFromToken\fR both allow the ClientData for a +command's deletion procedure to be given a different value than the +ClientData for its command procedure. +.PP +Note that neither \fBTcl_SetCommandInfo\fR nor +\fBTcl_SetCommandInfoFromToken\fR will change a command's namespace. +Use \fBTcl_Eval\fR to call the \fBrename\fR command to do that. +.PP +\fBTcl_GetCommandName\fR provides a mechanism for tracking commands +that have been renamed. +Given a token returned by \fBTcl_CreateObjCommand\fR +when the command was created, \fBTcl_GetCommandName\fR returns the +string name of the command. If the command has been renamed since it +was created, then \fBTcl_GetCommandName\fR returns the current name. +This name does not include any \fB::\fR namespace qualifiers. +The command corresponding to \fItoken\fR must not have been deleted. +The string returned by \fBTcl_GetCommandName\fR is in dynamic memory +owned by Tcl and is only guaranteed to retain its value as long as the +command is not deleted or renamed; callers should copy the string if +they need to keep it for a long time. +.PP +\fBTcl_GetCommandFullName\fR produces the fully qualified name +of a command from a command token. +The name, including all namespace prefixes, +is appended to the value specified by \fIobjPtr\fR. +.PP +\fBTcl_GetCommandFromObj\fR returns a token for the command +specified by the name in a \fBTcl_Obj\fR. +The command name is resolved relative to the current namespace. +Returns NULL if the command is not found. +.SH "SEE ALSO" +Tcl_CreateCommand(3), Tcl_ResetResult(3), Tcl_SetObjResult(3) +.SH KEYWORDS +bind, command, create, delete, namespace, value diff --git a/tcl8.6/doc/CrtSlave.3 b/tcl8.6/doc/CrtSlave.3 new file mode 100644 index 0000000..ac681bc --- /dev/null +++ b/tcl8.6/doc/CrtSlave.3 @@ -0,0 +1,236 @@ +'\" +'\" Copyright (c) 1995-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. +'\" +.TH Tcl_CreateSlave 3 7.6 Tcl "Tcl Library Procedures" +.so man.macros +.BS +.SH NAME +Tcl_IsSafe, Tcl_MakeSafe, Tcl_CreateSlave, Tcl_GetSlave, Tcl_GetMaster, Tcl_GetInterpPath, Tcl_CreateAlias, Tcl_CreateAliasObj, Tcl_GetAlias, Tcl_GetAliasObj, Tcl_ExposeCommand, Tcl_HideCommand \- manage multiple Tcl interpreters, aliases and hidden commands +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +int +\fBTcl_IsSafe\fR(\fIinterp\fR) +.sp +int +\fBTcl_MakeSafe\fR(\fIinterp\fR) +.sp +Tcl_Interp * +\fBTcl_CreateSlave\fR(\fIinterp, slaveName, isSafe\fR) +.sp +Tcl_Interp * +\fBTcl_GetSlave\fR(\fIinterp, slaveName\fR) +.sp +Tcl_Interp * +\fBTcl_GetMaster\fR(\fIinterp\fR) +.sp +int +\fBTcl_GetInterpPath\fR(\fIaskingInterp, slaveInterp\fR) +.sp +int +\fBTcl_CreateAlias\fR(\fIslaveInterp, slaveCmd, targetInterp, targetCmd, + argc, argv\fR) +.sp +int +\fBTcl_CreateAliasObj\fR(\fIslaveInterp, slaveCmd, targetInterp, targetCmd, + objc, objv\fR) +.sp +int +\fBTcl_GetAlias\fR(\fIinterp, slaveCmd, targetInterpPtr, targetCmdPtr, + argcPtr, argvPtr\fR) +.sp +int +\fBTcl_GetAliasObj\fR(\fIinterp, slaveCmd, targetInterpPtr, targetCmdPtr, + objcPtr, objvPtr\fR) +.sp +int +\fBTcl_ExposeCommand\fR(\fIinterp, hiddenCmdName, cmdName\fR) +.sp +int +\fBTcl_HideCommand\fR(\fIinterp, cmdName, hiddenCmdName\fR) +.SH ARGUMENTS +.AS "const char *const" **targetInterpPtr out +.AP Tcl_Interp *interp in +Interpreter in which to execute the specified command. +.AP "const char" *slaveName in +Name of slave interpreter to create or manipulate. +.AP int isSafe in +If non-zero, a +.QW safe +slave that is suitable for running untrusted code +is created, otherwise a trusted slave is created. +.AP Tcl_Interp *slaveInterp in +Interpreter to use for creating the source command for an alias (see +below). +.AP "const char" *slaveCmd in +Name of source command for alias. +.AP Tcl_Interp *targetInterp in +Interpreter that contains the target command for an alias. +.AP "const char" *targetCmd in +Name of target command for alias in \fItargetInterp\fR. +.AP int argc in +Count of additional arguments to pass to the alias command. +.AP "const char *const" *argv in +Vector of strings, the additional arguments to pass to the alias command. +This storage is owned by the caller. +.AP int objc in +Count of additional value arguments to pass to the aliased command. +.AP Tcl_Obj **objv in +Vector of Tcl_Obj structures, the additional value arguments to pass to +the aliased command. +This storage is owned by the caller. +.AP Tcl_Interp **targetInterpPtr in +Pointer to location to store the address of the interpreter where a target +command is defined for an alias. +.AP "const char" **targetCmdPtr out +Pointer to location to store the address of the name of the target command +for an alias. +.AP int *argcPtr out +Pointer to location to store count of additional arguments to be passed to +the alias. The location is in storage owned by the caller. +.AP "const char" ***argvPtr out +Pointer to location to store a vector of strings, the additional arguments +to pass to an alias. The location is in storage owned by the caller, the +vector of strings is owned by the called function. +.AP int *objcPtr out +Pointer to location to store count of additional value arguments to be +passed to the alias. The location is in storage owned by the caller. +.AP Tcl_Obj ***objvPtr out +Pointer to location to store a vector of Tcl_Obj structures, the additional +arguments to pass to an alias command. The location is in storage +owned by the caller, the vector of Tcl_Obj structures is owned by the +called function. +.AP "const char" *cmdName in +Name of an exposed command to hide or create. +.AP "const char" *hiddenCmdName in +Name under which a hidden command is stored and with which it can be +exposed or invoked. +.BE + +.SH DESCRIPTION +.PP +These procedures are intended for access to the multiple interpreter +facility from inside C programs. They enable managing multiple interpreters +in a hierarchical relationship, and the management of aliases, commands +that when invoked in one interpreter execute a command in another +interpreter. The return value for those procedures that return an \fBint\fR +is either \fBTCL_OK\fR or \fBTCL_ERROR\fR. If \fBTCL_ERROR\fR is returned +then the \fBresult\fR field of the interpreter contains an error message. +.PP +\fBTcl_CreateSlave\fR creates a new interpreter as a slave of \fIinterp\fR. +It also creates a slave command named \fIslaveName\fR in \fIinterp\fR which +allows \fIinterp\fR to manipulate the new slave. +If \fIisSafe\fR is zero, the command creates a trusted slave in which Tcl +code has access to all the Tcl commands. +If it is \fB1\fR, the command creates a +.QW safe +slave in which Tcl code has access only to set of Tcl commands defined as +.QW "Safe Tcl" ; +see the manual entry for the Tcl \fBinterp\fR command for details. +If the creation of the new slave interpreter failed, \fBNULL\fR is returned. +.PP +\fBTcl_IsSafe\fR returns \fB1\fR if \fIinterp\fR is +.QW safe +(was created with the \fBTCL_SAFE_INTERPRETER\fR flag specified), +\fB0\fR otherwise. +.PP +\fBTcl_MakeSafe\fR marks \fIinterp\fR as +.QW safe , +so that future +calls to \fBTcl_IsSafe\fR will return 1. It also removes all known +potentially-unsafe core functionality (both commands and variables) +from \fIinterp\fR. However, it cannot know what parts of an extension +or application are safe and does not make any attempt to remove those +parts, so safety is not guaranteed after calling \fBTcl_MakeSafe\fR. +Callers will want to take care with their use of \fBTcl_MakeSafe\fR +to avoid false claims of safety. For many situations, \fBTcl_CreateSlave\fR +may be a better choice, since it creates interpreters in a known-safe state. +.PP +\fBTcl_GetSlave\fR returns a pointer to a slave interpreter of +\fIinterp\fR. The slave interpreter is identified by \fIslaveName\fR. +If no such slave interpreter exists, \fBNULL\fR is returned. +.PP +\fBTcl_GetMaster\fR returns a pointer to the master interpreter of +\fIinterp\fR. If \fIinterp\fR has no master (it is a +top-level interpreter) then \fBNULL\fR is returned. +.PP +\fBTcl_GetInterpPath\fR sets the \fIresult\fR field in \fIaskingInterp\fR +to the relative path between \fIaskingInterp\fR and \fIslaveInterp\fR; +\fIslaveInterp\fR must be a slave of \fIaskingInterp\fR. If the computation +of the relative path succeeds, \fBTCL_OK\fR is returned, else +\fBTCL_ERROR\fR is returned and the \fIresult\fR field in +\fIaskingInterp\fR contains the error message. +.PP +\fBTcl_CreateAlias\fR creates a command named \fIslaveCmd\fR in +\fIslaveInterp\fR that when invoked, will cause the command \fItargetCmd\fR +to be invoked in \fItargetInterp\fR. The arguments specified by the strings +contained in \fIargv\fR are always prepended to any arguments supplied in the +invocation of \fIslaveCmd\fR and passed to \fItargetCmd\fR. +This operation returns \fBTCL_OK\fR if it succeeds, or \fBTCL_ERROR\fR if +it fails; in that case, an error message is left in the value result +of \fIslaveInterp\fR. +Note that there are no restrictions on the ancestry relationship (as +created by \fBTcl_CreateSlave\fR) between \fIslaveInterp\fR and +\fItargetInterp\fR. Any two interpreters can be used, without any +restrictions on how they are related. +.PP +\fBTcl_CreateAliasObj\fR is similar to \fBTcl_CreateAlias\fR except +that it takes a vector of values to pass as additional arguments instead +of a vector of strings. +.PP +\fBTcl_GetAlias\fR returns information about an alias \fIaliasName\fR +in \fIinterp\fR. Any of the result fields can be \fBNULL\fR, in +which case the corresponding datum is not returned. If a result field is +non\-\fBNULL\fR, the address indicated is set to the corresponding datum. +For example, if \fItargetNamePtr\fR is non\-\fBNULL\fR it is set to a +pointer to the string containing the name of the target command. +.PP +\fBTcl_GetAliasObj\fR is similar to \fBTcl_GetAlias\fR except that it +returns a pointer to a vector of Tcl_Obj structures instead of a vector of +strings. +.PP +\fBTcl_ExposeCommand\fR moves the command named \fIhiddenCmdName\fR from +the set of hidden commands to the set of exposed commands, putting +it under the name +\fIcmdName\fR. +\fIHiddenCmdName\fR must be the name of an existing hidden +command, or the operation will return \fBTCL_ERROR\fR and leave an error +message in the \fIresult\fR field in \fIinterp\fR. +If an exposed command named \fIcmdName\fR already exists, +the operation returns \fBTCL_ERROR\fR and leaves an error message in the +value result of \fIinterp\fR. +If the operation succeeds, it returns \fBTCL_OK\fR. +After executing this command, attempts to use \fIcmdName\fR in a call to +\fBTcl_Eval\fR or with the Tcl \fBeval\fR command will again succeed. +.PP +\fBTcl_HideCommand\fR moves the command named \fIcmdName\fR from the set of +exposed commands to the set of hidden commands, under the name +\fIhiddenCmdName\fR. +\fICmdName\fR must be the name of an existing exposed +command, or the operation will return \fBTCL_ERROR\fR and leave an error +message in the value result of \fIinterp\fR. +Currently both \fIcmdName\fR and \fIhiddenCmdName\fR must not contain +namespace qualifiers, or the operation will return \fBTCL_ERROR\fR and +leave an error message in the value result of \fIinterp\fR. +The \fICmdName\fR will be looked up in the global namespace, and not +relative to the current namespace, even if the current namespace is not the +global one. +If a hidden command whose name is \fIhiddenCmdName\fR already +exists, the operation also returns \fBTCL_ERROR\fR and the \fIresult\fR +field in \fIinterp\fR contains an error message. +If the operation succeeds, it returns \fBTCL_OK\fR. +After executing this command, attempts to use \fIcmdName\fR in a call to +\fBTcl_Eval\fR or with the Tcl \fBeval\fR command will fail. +.PP +For a description of the Tcl interface to multiple interpreters, see +\fIinterp(n)\fR. +.SH "SEE ALSO" +interp + +.SH KEYWORDS +alias, command, exposed commands, hidden commands, interpreter, invoke, +master, slave diff --git a/tcl8.6/doc/CrtTimerHdlr.3 b/tcl8.6/doc/CrtTimerHdlr.3 new file mode 100644 index 0000000..f3957c7 --- /dev/null +++ b/tcl8.6/doc/CrtTimerHdlr.3 @@ -0,0 +1,76 @@ +'\" +'\" Copyright (c) 1990 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. +'\" +.TH Tcl_CreateTimerHandler 3 7.5 Tcl "Tcl Library Procedures" +.so man.macros +.BS +.SH NAME +Tcl_CreateTimerHandler, Tcl_DeleteTimerHandler \- call a procedure at a given time +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +Tcl_TimerToken +\fBTcl_CreateTimerHandler\fR(\fImilliseconds, proc, clientData\fR) +.sp +\fBTcl_DeleteTimerHandler\fR(\fItoken\fR) +.SH ARGUMENTS +.AS Tcl_TimerToken milliseconds +.AP int milliseconds in +How many milliseconds to wait before invoking \fIproc\fR. +.AP Tcl_TimerProc *proc in +Procedure to invoke after \fImilliseconds\fR have elapsed. +.AP ClientData clientData in +Arbitrary one-word value to pass to \fIproc\fR. +.AP Tcl_TimerToken token in +Token for previously created timer handler (the return value +from some previous call to \fBTcl_CreateTimerHandler\fR). +.BE +.SH DESCRIPTION +.PP +\fBTcl_CreateTimerHandler\fR arranges for \fIproc\fR to be +invoked at a time \fImilliseconds\fR milliseconds in the +future. +The callback to \fIproc\fR will be made by \fBTcl_DoOneEvent\fR, +so \fBTcl_CreateTimerHandler\fR is only useful in programs that +dispatch events through \fBTcl_DoOneEvent\fR or through Tcl commands +such as \fBvwait\fR. +The call to \fIproc\fR may not be made at the exact time given by +\fImilliseconds\fR: it will be made at the next opportunity +after that time. For example, if \fBTcl_DoOneEvent\fR is not +called until long after the time has elapsed, or if there +are other pending events to process before the call to +\fIproc\fR, then the call to \fIproc\fR will be delayed. +.PP +\fIProc\fR should have arguments and return value that match +the type \fBTcl_TimerProc\fR: +.PP +.CS +typedef void \fBTcl_TimerProc\fR( + ClientData \fIclientData\fR); +.CE +.PP +The \fIclientData\fR parameter to \fIproc\fR is a +copy of the \fIclientData\fR argument given to +\fBTcl_CreateTimerHandler\fR when the callback +was created. Typically, \fIclientData\fR points to a data +structure containing application-specific information about +what to do in \fIproc\fR. +.PP +\fBTcl_DeleteTimerHandler\fR may be called to delete a +previously created timer handler. It deletes the handler +indicated by \fItoken\fR so that no call to \fIproc\fR +will be made; if that handler no longer exists +(e.g. because the time period has already elapsed and \fIproc\fR +has been invoked then \fBTcl_DeleteTimerHandler\fR does nothing. +The tokens returned by \fBTcl_CreateTimerHandler\fR never have +a value of NULL, so if NULL is passed to \fBTcl_DeleteTimerHandler\fR +then the procedure does nothing. +.SH "SEE ALSO" +after(n), Tcl_CreateFileHandler(3), Tcl_DoWhenIdle(3) +.SH KEYWORDS +callback, clock, handler, timer diff --git a/tcl8.6/doc/CrtTrace.3 b/tcl8.6/doc/CrtTrace.3 new file mode 100644 index 0000000..d5353ac --- /dev/null +++ b/tcl8.6/doc/CrtTrace.3 @@ -0,0 +1,191 @@ +'\" +'\" Copyright (c) 1989-1993 The Regents of the University of California. +'\" Copyright (c) 1994-1996 Sun Microsystems, Inc. +'\" Copyright (c) 2002 by Kevin B. Kenny <kennykb@acm.org>. All rights reserved. +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH Tcl_CreateTrace 3 "" Tcl "Tcl Library Procedures" +.so man.macros +.BS +.SH NAME +Tcl_CreateTrace, Tcl_CreateObjTrace, Tcl_DeleteTrace \- arrange for command execution to be traced +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +Tcl_Trace +\fBTcl_CreateTrace\fR(\fIinterp, level, proc, clientData\fR) +.sp +Tcl_Trace +\fBTcl_CreateObjTrace\fR(\fIinterp, level, flags, objProc, clientData, deleteProc\fR) +.sp +\fBTcl_DeleteTrace\fR(\fIinterp, trace\fR) +.SH ARGUMENTS +.AS Tcl_CmdObjTraceDeleteProc *deleteProc +.AP Tcl_Interp *interp in +Interpreter containing command to be traced or untraced. +.AP int level in +Only commands at or below this nesting level will be traced unless +0 is specified. 1 means +top-level commands only, 2 means top-level commands or those that are +invoked as immediate consequences of executing top-level commands +(procedure bodies, bracketed commands, etc.) and so on. +A value of 0 means that commands at any level are traced. +.AP int flags in +Flags governing the trace execution. See below for details. +.AP Tcl_CmdObjTraceProc *objProc in +Procedure to call for each command that is executed. See below for +details of the calling sequence. +.AP Tcl_CmdTraceProc *proc in +Procedure to call for each command that is executed. See below for +details on the calling sequence. +.AP ClientData clientData in +Arbitrary one-word value to pass to \fIobjProc\fR or \fIproc\fR. +.AP Tcl_CmdObjTraceDeleteProc *deleteProc in +Procedure to call when the trace is deleted. See below for details of +the calling sequence. A NULL pointer is permissible and results in no +callback when the trace is deleted. +.AP Tcl_Trace trace in +Token for trace to be removed (return value from previous call +to \fBTcl_CreateTrace\fR). +.BE +.SH DESCRIPTION +.PP +\fBTcl_CreateObjTrace\fR arranges for command tracing. After it is +called, \fIobjProc\fR will be invoked before the Tcl interpreter calls +any command procedure when evaluating commands in \fIinterp\fR. +The return value from \fBTcl_CreateObjTrace\fR is a token for the trace, +which may be passed to \fBTcl_DeleteTrace\fR to remove the trace. +There may be many traces in effect simultaneously for the same +interpreter. +.PP +\fIobjProc\fR should have arguments and result that match the type, +\fBTcl_CmdObjTraceProc\fR: +.PP +.CS +typedef int \fBTcl_CmdObjTraceProc\fR( + \fBClientData\fR \fIclientData\fR, + \fBTcl_Interp\fR* \fIinterp\fR, + int \fIlevel\fR, + const char *\fIcommand\fR, + \fBTcl_Command\fR \fIcommandToken\fR, + int \fIobjc\fR, + \fBTcl_Obj\fR *const \fIobjv\fR[]); +.CE +.PP +The \fIclientData\fR and \fIinterp\fR parameters are copies of the +corresponding arguments given to \fBTcl_CreateTrace\fR. +\fIClientData\fR typically points to an application-specific data +structure that describes what to do when \fIobjProc\fR is invoked. The +\fIlevel\fR parameter gives the nesting level of the command (1 for +top-level commands passed to \fBTcl_Eval\fR by the application, 2 for +the next-level commands passed to \fBTcl_Eval\fR as part of parsing or +interpreting level-1 commands, and so on). The \fIcommand\fR parameter +points to a string containing the text of the command, before any +argument substitution. The \fIcommandToken\fR parameter is a Tcl +command token that identifies the command to be invoked. The token +may be passed to \fBTcl_GetCommandName\fR, +\fBTcl_GetCommandInfoFromToken\fR, or \fBTcl_SetCommandInfoFromToken\fR to +manipulate the definition of the command. The \fIobjc\fR and \fIobjv\fR +parameters designate the final parameter count and parameter vector +that will be passed to the command, and have had all substitutions +performed. +.PP +The \fIobjProc\fR callback is expected to return a standard Tcl status +return code. If this code is \fBTCL_OK\fR (the normal case), then +the Tcl interpreter will invoke the command. Any other return code +is treated as if the command returned that status, and the command is +\fInot\fR invoked. +.PP +The \fIobjProc\fR callback must not modify \fIobjv\fR in any way. It +is, however, permissible to change the command by calling +\fBTcl_SetCommandTokenInfo\fR prior to returning. Any such change +takes effect immediately, and the command is invoked with the new +information. +.PP +Tracing will only occur for commands at nesting level less than +or equal to the \fIlevel\fR parameter (i.e. the \fIlevel\fR +parameter to \fIobjProc\fR will always be less than or equal to the +\fIlevel\fR parameter to \fBTcl_CreateTrace\fR). +.PP +Tracing has a significant effect on runtime performance because it +causes the bytecode compiler to refrain from generating in-line code +for Tcl commands such as \fBif\fR and \fBwhile\fR in order that they +may be traced. If traces for the built-in commands are not required, +the \fIflags\fR parameter may be set to the constant value +\fBTCL_ALLOW_INLINE_COMPILATION\fR. In this case, traces on built-in +commands may or may not result in trace callbacks, depending on the +state of the interpreter, but run-time performance will be improved +significantly. (This functionality is desirable, for example, when +using \fBTcl_CreateObjTrace\fR to implement an execution time +profiler.) +.PP +Calls to \fIobjProc\fR will be made by the Tcl parser immediately before +it calls the command procedure for the command (\fIcmdProc\fR). This +occurs after argument parsing and substitution, so tracing for +substituted commands occurs before tracing of the commands +containing the substitutions. If there is a syntax error in a +command, or if there is no command procedure associated with a +command name, then no tracing will occur for that command. If a +string passed to Tcl_Eval contains multiple commands (bracketed, or +on different lines) then multiple calls to \fIobjProc\fR will occur, +one for each command. +.PP +\fBTcl_DeleteTrace\fR removes a trace, so that no future calls will be +made to the procedure associated with the trace. After \fBTcl_DeleteTrace\fR +returns, the caller should never again use the \fItrace\fR token. +.PP +When \fBTcl_DeleteTrace\fR is called, the interpreter invokes the +\fIdeleteProc\fR that was passed as a parameter to +\fBTcl_CreateObjTrace\fR. The \fIdeleteProc\fR must match the type, +\fBTcl_CmdObjTraceDeleteProc\fR: +.PP +.CS +typedef void \fBTcl_CmdObjTraceDeleteProc\fR( + \fBClientData\fR \fIclientData\fR); +.CE +.PP +The \fIclientData\fR parameter will be the same as the +\fIclientData\fR parameter that was originally passed to +\fBTcl_CreateObjTrace\fR. +.PP +\fBTcl_CreateTrace\fR is an alternative interface for command tracing, +\fInot recommended for new applications\fR. It is provided for backward +compatibility with code that was developed for older versions of the +Tcl interpreter. It is similar to \fBTcl_CreateObjTrace\fR, except +that its \fIproc\fR parameter should have arguments and result that +match the type \fBTcl_CmdTraceProc\fR: +.PP +.CS +typedef void \fBTcl_CmdTraceProc\fR( + ClientData \fIclientData\fR, + Tcl_Interp *\fIinterp\fR, + int \fIlevel\fR, + char *\fIcommand\fR, + Tcl_CmdProc *\fIcmdProc\fR, + ClientData \fIcmdClientData\fR, + int \fIargc\fR, + const char *\fIargv\fR[]); +.CE +.PP +The parameters to the \fIproc\fR callback are similar to those of the +\fIobjProc\fR callback above. The \fIcommandToken\fR is +replaced with \fIcmdProc\fR, a pointer to the (string-based) command +procedure that will be invoked; and \fIcmdClientData\fR, the client +data that will be passed to the procedure. The \fIobjc\fR parameter +is replaced with an \fIargv\fR parameter, that gives the arguments to +the command as character strings. +\fIProc\fR must not modify the \fIcommand\fR or \fIargv\fR strings. +.PP +If a trace created with \fBTcl_CreateTrace\fR is in effect, inline +compilation of Tcl commands such as \fBif\fR and \fBwhile\fR is always +disabled. There is no notification when a trace created with +\fBTcl_CreateTrace\fR is deleted. +There is no way to be notified when the trace created by +\fBTcl_CreateTrace\fR is deleted. There is no way for the \fIproc\fR +associated with a call to \fBTcl_CreateTrace\fR to abort execution of +\fIcommand\fR. +.SH KEYWORDS +command, create, delete, interpreter, trace diff --git a/tcl8.6/doc/DString.3 b/tcl8.6/doc/DString.3 new file mode 100644 index 0000000..00f1b8a --- /dev/null +++ b/tcl8.6/doc/DString.3 @@ -0,0 +1,153 @@ +'\" +'\" Copyright (c) 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. +'\" +.TH Tcl_DString 3 7.4 Tcl "Tcl Library Procedures" +.so man.macros +.BS +.SH NAME +Tcl_DStringInit, Tcl_DStringAppend, Tcl_DStringAppendElement, Tcl_DStringStartSublist, Tcl_DStringEndSublist, Tcl_DStringLength, Tcl_DStringValue, Tcl_DStringSetLength, Tcl_DStringTrunc, Tcl_DStringFree, Tcl_DStringResult, Tcl_DStringGetResult \- manipulate dynamic strings +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +\fBTcl_DStringInit\fR(\fIdsPtr\fR) +.sp +char * +\fBTcl_DStringAppend\fR(\fIdsPtr, bytes, length\fR) +.sp +char * +\fBTcl_DStringAppendElement\fR(\fIdsPtr, element\fR) +.sp +\fBTcl_DStringStartSublist\fR(\fIdsPtr\fR) +.sp +\fBTcl_DStringEndSublist\fR(\fIdsPtr\fR) +.sp +int +\fBTcl_DStringLength\fR(\fIdsPtr\fR) +.sp +char * +\fBTcl_DStringValue\fR(\fIdsPtr\fR) +.sp +\fBTcl_DStringSetLength\fR(\fIdsPtr, newLength\fR) +.sp +\fBTcl_DStringTrunc\fR(\fIdsPtr, newLength\fR) +.sp +\fBTcl_DStringFree\fR(\fIdsPtr\fR) +.sp +\fBTcl_DStringResult\fR(\fIinterp, dsPtr\fR) +.sp +\fBTcl_DStringGetResult\fR(\fIinterp, dsPtr\fR) +.SH ARGUMENTS +.AS Tcl_DString newLength in/out +.AP Tcl_DString *dsPtr in/out +Pointer to structure that is used to manage a dynamic string. +.AP "const char" *bytes in +Pointer to characters to append to dynamic string. +.AP "const char" *element in +Pointer to characters to append as list element to dynamic string. +.AP int length in +Number of bytes from \fIbytes\fR to add to dynamic string. If -1, +add all characters up to null terminating character. +.AP int newLength in +New length for dynamic string, not including null terminating +character. +.AP Tcl_Interp *interp in/out +Interpreter whose result is to be set from or moved to the +dynamic string. +.BE + +.SH DESCRIPTION +.PP +Dynamic strings provide a mechanism for building up arbitrarily long +strings by gradually appending information. If the dynamic string is +short then there will be no memory allocation overhead; as the string +gets larger, additional space will be allocated as needed. +.PP +\fBTcl_DStringInit\fR initializes a dynamic string to zero length. +The Tcl_DString structure must have been allocated by the caller. +No assumptions are made about the current state of the structure; +anything already in it is discarded. +If the structure has been used previously, \fBTcl_DStringFree\fR should +be called first to free up any memory allocated for the old +string. +.PP +\fBTcl_DStringAppend\fR adds new information to a dynamic string, +allocating more memory for the string if needed. +If \fIlength\fR is less than zero then everything in \fIbytes\fR +is appended to the dynamic string; otherwise \fIlength\fR +specifies the number of bytes to append. +\fBTcl_DStringAppend\fR returns a pointer to the characters of +the new string. The string can also be retrieved from the +\fIstring\fR field of the Tcl_DString structure. +.PP +\fBTcl_DStringAppendElement\fR is similar to \fBTcl_DStringAppend\fR +except that it does not take a \fIlength\fR argument (it appends +all of \fIelement\fR) and it converts the string to a proper list element +before appending. +\fBTcl_DStringAppendElement\fR adds a separator space before the +new list element unless the new list element is the first in a +list or sub-list (i.e. either the current string is empty, or it +contains the single character +.QW { , +or the last two characters of the current string are +.QW " {" ). +\fBTcl_DStringAppendElement\fR returns a pointer to the +characters of the new string. +.PP +\fBTcl_DStringStartSublist\fR and \fBTcl_DStringEndSublist\fR can be +used to create nested lists. +To append a list element that is itself a sublist, first +call \fBTcl_DStringStartSublist\fR, then call \fBTcl_DStringAppendElement\fR +for each of the elements in the sublist, then call +\fBTcl_DStringEndSublist\fR to end the sublist. +\fBTcl_DStringStartSublist\fR appends a space character if needed, +followed by an open brace; \fBTcl_DStringEndSublist\fR appends +a close brace. +Lists can be nested to any depth. +.PP +\fBTcl_DStringLength\fR is a macro that returns the current length +of a dynamic string (not including the terminating null character). +\fBTcl_DStringValue\fR is a macro that returns a pointer to the +current contents of a dynamic string. +.PP +.PP +\fBTcl_DStringSetLength\fR changes the length of a dynamic string. +If \fInewLength\fR is less than the string's current length, then +the string is truncated. +If \fInewLength\fR is greater than the string's current length, +then the string will become longer and new space will be allocated +for the string if needed. +However, \fBTcl_DStringSetLength\fR will not initialize the new +space except to provide a terminating null character; it is up to the +caller to fill in the new space. +\fBTcl_DStringSetLength\fR does not free up the string's storage space +even if the string is truncated to zero length, so \fBTcl_DStringFree\fR +will still need to be called. +.PP +\fBTcl_DStringTrunc\fR changes the length of a dynamic string. +This procedure is now deprecated. \fBTcl_DStringSetLength\fR should +be used instead. +.PP +\fBTcl_DStringFree\fR should be called when you are finished using +the string. It frees up any memory that was allocated for the string +and reinitializes the string's value to an empty string. +.PP +\fBTcl_DStringResult\fR sets the result of \fIinterp\fR to the value of +the dynamic string given by \fIdsPtr\fR. It does this by moving +a pointer from \fIdsPtr\fR to the interpreter's result. +This saves the cost of allocating new memory and copying the string. +\fBTcl_DStringResult\fR also reinitializes the dynamic string to +an empty string. +.PP +\fBTcl_DStringGetResult\fR does the opposite of \fBTcl_DStringResult\fR. +It sets the value of \fIdsPtr\fR to the result of \fIinterp\fR and +it clears \fIinterp\fR's result. +If possible it does this by moving a pointer rather than by copying +the string. + +.SH KEYWORDS +append, dynamic string, free, result diff --git a/tcl8.6/doc/DetachPids.3 b/tcl8.6/doc/DetachPids.3 new file mode 100644 index 0000000..39a51d3 --- /dev/null +++ b/tcl8.6/doc/DetachPids.3 @@ -0,0 +1,75 @@ +'\" +'\" Copyright (c) 1989-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. +'\" +.TH Tcl_DetachPids 3 "" Tcl "Tcl Library Procedures" +.so man.macros +.BS +.SH NAME +Tcl_DetachPids, Tcl_ReapDetachedProcs, Tcl_WaitPid \- manage child processes in background +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +\fBTcl_DetachPids\fR(\fInumPids, pidPtr\fR) +.sp +\fBTcl_ReapDetachedProcs\fR() +.sp +Tcl_Pid +\fBTcl_WaitPid\fR(\fIpid, statusPtr, options\fR) +.SH ARGUMENTS +.AS Tcl_Pid *statusPtr out +.AP int numPids in +Number of process ids contained in the array pointed to by \fIpidPtr\fR. +.AP int *pidPtr in +Address of array containing \fInumPids\fR process ids. +.AP Tcl_Pid pid in +The id of the process (pipe) to wait for. +.AP int *statusPtr out +The result of waiting on a process (pipe). Either 0 or ECHILD. +.AP int options in +The options controlling the wait. WNOHANG specifies not to wait when +checking the process. +.BE +.SH DESCRIPTION +.PP +\fBTcl_DetachPids\fR and \fBTcl_ReapDetachedProcs\fR provide a +mechanism for managing subprocesses that are running in background. +These procedures are needed because the parent of a process must +eventually invoke the \fBwaitpid\fR kernel call (or one of a few other +similar kernel calls) to wait for the child to exit. Until the +parent waits for the child, the child's state cannot be completely +reclaimed by the system. If a parent continually creates children +and doesn't wait on them, the system's process table will eventually +overflow, even if all the children have exited. +.PP +\fBTcl_DetachPids\fR may be called to ask Tcl to take responsibility +for one or more processes whose process ids are contained in the +\fIpidPtr\fR array passed as argument. The caller presumably +has started these processes running in background and does not +want to have to deal with them again. +.PP +\fBTcl_ReapDetachedProcs\fR invokes the \fBwaitpid\fR kernel call +on each of the background processes so that its state can be cleaned +up if it has exited. If the process has not exited yet, +\fBTcl_ReapDetachedProcs\fR does not wait for it to exit; it will check again +the next time it is invoked. +Tcl automatically calls \fBTcl_ReapDetachedProcs\fR each time the +\fBexec\fR command is executed, so in most cases it is not necessary +for any code outside of Tcl to invoke \fBTcl_ReapDetachedProcs\fR. +However, if you call \fBTcl_DetachPids\fR in situations where the +\fBexec\fR command may never get executed, you may wish to call +\fBTcl_ReapDetachedProcs\fR from time to time so that background +processes can be cleaned up. +.PP +\fBTcl_WaitPid\fR is a thin wrapper around the facilities provided by +the operating system to wait on the end of a spawned process and to +check a whether spawned process is still running. It is used by +\fBTcl_ReapDetachedProcs\fR and the channel system to portably access +the operating system. + +.SH KEYWORDS +background, child, detach, process, wait diff --git a/tcl8.6/doc/DictObj.3 b/tcl8.6/doc/DictObj.3 new file mode 100644 index 0000000..90ca9e3 --- /dev/null +++ b/tcl8.6/doc/DictObj.3 @@ -0,0 +1,234 @@ +'\" +'\" Copyright (c) 2003 Donal K. Fellows +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH Tcl_DictObj 3 8.5 Tcl "Tcl Library Procedures" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +Tcl_NewDictObj, Tcl_DictObjPut, Tcl_DictObjGet, Tcl_DictObjRemove, Tcl_DictObjSize, Tcl_DictObjFirst, Tcl_DictObjNext, Tcl_DictObjDone, Tcl_DictObjPutKeyList, Tcl_DictObjRemoveKeyList \- manipulate Tcl values as dictionaries +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +Tcl_Obj * +\fBTcl_NewDictObj\fR() +.sp +int +\fBTcl_DictObjGet\fR(\fIinterp, dictPtr, keyPtr, valuePtrPtr\fR) +.sp +int +\fBTcl_DictObjPut\fR(\fIinterp, dictPtr, keyPtr, valuePtr\fR) +.sp +int +\fBTcl_DictObjRemove\fR(\fIinterp, dictPtr, keyPtr\fR) +.sp +int +\fBTcl_DictObjSize\fR(\fIinterp, dictPtr, sizePtr\fR) +.sp +int +\fBTcl_DictObjFirst\fR(\fIinterp, dictPtr, searchPtr, + keyPtrPtr, valuePtrPtr, donePtr\fR) +.sp +void +\fBTcl_DictObjNext\fR(\fIsearchPtr, keyPtrPtr, valuePtrPtr, donePtr\fR) +.sp +void +\fBTcl_DictObjDone\fR(\fIsearchPtr\fR) +.sp +int +\fBTcl_DictObjPutKeyList\fR(\fIinterp, dictPtr, keyc, keyv, valuePtr\fR) +.sp +int +\fBTcl_DictObjRemoveKeyList\fR(\fIinterp, dictPtr, keyc, keyv\fR) +.SH ARGUMENTS +.AS Tcl_DictSearch "**valuePtrPtr" in/out +.AP Tcl_Interp *interp in +If an error occurs while converting a value to be a dictionary value, +an error message is left in the interpreter's result value +unless \fIinterp\fR is NULL. +.AP Tcl_Obj *dictPtr in/out +Points to the dictionary value to be manipulated. +If \fIdictPtr\fR does not already point to a dictionary value, +an attempt will be made to convert it to one. +.AP Tcl_Obj *keyPtr in +Points to the key for the key/value pair being manipulated within the +dictionary value. +.AP Tcl_Obj **keyPtrPtr out +Points to a variable that will have the key from a key/value pair +placed within it. May be NULL to indicate that the caller is not +interested in the key. +.AP Tcl_Obj *valuePtr in +Points to the value for the key/value pair being manipulated within the +dictionary value (or sub-value, in the case of +\fBTcl_DictObjPutKeyList\fR.) +.AP Tcl_Obj **valuePtrPtr out +Points to a variable that will have the value from a key/value pair +placed within it. For \fBTcl_DictObjFirst\fR and +\fBTcl_DictObjNext\fR, this may be NULL to indicate that the caller is +not interested in the value. +.AP int *sizePtr out +Points to a variable that will have the number of key/value pairs +contained within the dictionary placed within it. +.AP Tcl_DictSearch *searchPtr in/out +Pointer to record to use to keep track of progress in enumerating all +key/value pairs in a dictionary. The contents of the record will be +initialized by the call to \fBTcl_DictObjFirst\fR. If the enumerating +is to be terminated before all values in the dictionary have been +returned, the search record \fImust\fR be passed to +\fBTcl_DictObjDone\fR to enable the internal locks to be released. +.AP int *donePtr out +Points to a variable that will have a non-zero value written into it +when the enumeration of the key/value pairs in a dictionary has +completed, and a zero otherwise. +.AP int keyc in +Indicates the number of keys that will be supplied in the \fIkeyv\fR +array. +.AP "Tcl_Obj *const" *keyv in +Array of \fIkeyc\fR pointers to values that +\fBTcl_DictObjPutKeyList\fR and \fBTcl_DictObjRemoveKeyList\fR will +use to locate the key/value pair to manipulate within the +sub-dictionaries of the main dictionary value passed to them. +.BE + +.SH DESCRIPTION +.PP +Tcl dictionary values have an internal representation that supports +efficient mapping from keys to values and which guarantees that the +particular ordering of keys within the dictionary remains the same +modulo any keys being deleted (which removes them from the order) or +added (which adds them to the end of the order). If reinterpreted as a +list, the values at the even-valued indices in the list will be the +keys of the dictionary, and each will be followed (in the odd-valued +index) by the value associated with that key. +.PP +The procedures described in this man page are used to +create, modify, index, and iterate over dictionary values from C code. +.PP +\fBTcl_NewDictObj\fR creates a new, empty dictionary value. The +string representation of the value will be invalid, and the reference +count of the value will be zero. +.PP +\fBTcl_DictObjGet\fR looks up the given key within the given +dictionary and writes a pointer to the value associated with that key +into the variable pointed to by \fIvaluePtrPtr\fR, or a NULL if the +key has no mapping within the dictionary. The result of this +procedure is \fBTCL_OK\fR, or \fBTCL_ERROR\fR if the \fIdictPtr\fR cannot be +converted to a dictionary. +.PP +\fBTcl_DictObjPut\fR updates the given dictionary so that the given +key maps to the given value; any key may exist at most once in any +particular dictionary. The dictionary must not be shared, but the key +and value may be. This procedure may increase the reference count of +both key and value if it proves necessary to store them. Neither key +nor value should be NULL. The result of this procedure is \fBTCL_OK\fR, or +\fBTCL_ERROR\fR if the \fIdictPtr\fR cannot be converted to a dictionary. +.PP +\fBTcl_DictObjRemove\fR updates the given dictionary so that the given +key has no mapping to any value. The dictionary must not be shared, +but the key may be. The key actually stored in the dictionary will +have its reference count decremented if it was present. It is not an +error if the key did not previously exist. The result of this +procedure is \fBTCL_OK\fR, or \fBTCL_ERROR\fR if the \fIdictPtr\fR cannot be +converted to a dictionary. +.PP +\fBTcl_DictObjSize\fR updates the given variable with the number of +key/value pairs currently in the given dictionary. The result of this +procedure is \fBTCL_OK\fR, or \fBTCL_ERROR\fR if the \fIdictPtr\fR cannot be +converted to a dictionary. +.PP +\fBTcl_DictObjFirst\fR commences an iteration across all the key/value +pairs in the given dictionary, placing the key and value in the +variables pointed to by the \fIkeyPtrPtr\fR and \fIvaluePtrPtr\fR +arguments (which may be NULL to indicate that the caller is +uninterested in they key or variable respectively.) The next +key/value pair in the dictionary may be retrieved with +\fBTcl_DictObjNext\fR. Concurrent updates of the dictionary's +internal representation will not modify the iteration processing +unless the dictionary is unshared, when this will trigger premature +termination of the iteration instead (which Tcl scripts cannot trigger +via the \fBdict\fR command.) The \fIsearchPtr\fR argument points to a +piece of context that is used to identify which particular iteration +is being performed, and is initialized by the call to +\fBTcl_DictObjFirst\fR. The \fIdonePtr\fR argument points to a +variable that is updated to be zero of there are further key/value +pairs to be iterated over, or non-zero if the iteration is complete. +The order of iteration is implementation-defined. If the +\fIdictPtr\fR argument cannot be converted to a dictionary, +\fBTcl_DictObjFirst\fR returns \fBTCL_ERROR\fR and the iteration is not +commenced, and otherwise it returns \fBTCL_OK\fR. +.PP +When \fBTcl_DictObjFirst\fR is called upon a dictionary, a lock is placed on +the dictionary to enable that dictionary to be iterated over safely without +regard for whether the dictionary is modified during the iteration. Because of +this, once the iteration over a dictionary's keys has finished (whether +because all values have been iterated over as indicated by the variable +indicated by the \fIdonePtr\fR argument being set to one, or because no +further values are required) the \fBTcl_DictObjDone\fR function must be called +with the same \fIsearchPtr\fR as was passed to \fBTcl_DictObjFirst\fR so that +the internal locks can be released. Once a particular \fIsearchPtr\fR is +passed to \fBTcl_DictObjDone\fR, passing it to \fBTcl_DictObjNext\fR (without +first initializing it with \fBTcl_DictObjFirst\fR) will result in no values +being produced and the variable pointed to by \fIdonePtr\fR being set to one. +It is safe to call \fBTcl_DictObjDone\fR multiple times on the same +\fIsearchPtr\fR for each call to \fBTcl_DictObjFirst\fR. +.PP +The procedures \fBTcl_DictObjPutKeyList\fR and +\fBTcl_DictObjRemoveKeyList\fR are the close analogues of +\fBTcl_DictObjPut\fR and \fBTcl_DictObjRemove\fR respectively, except +that instead of working with a single dictionary, they are designed to +operate on a nested tree of dictionaries, with inner dictionaries +stored as values inside outer dictionaries. The \fIkeyc\fR and +\fIkeyv\fR arguments specify a list of keys (with outermost keys +first) that acts as a path to the key/value pair to be affected. Note +that there is no corresponding operation for reading a value for a +path as this is easy to construct from repeated use of +\fBTcl_DictObjGet\fR. With \fBTcl_DictObjPutKeyList\fR, nested +dictionaries are created for non-terminal keys where they do not +already exist. With \fBTcl_DictObjRemoveKeyList\fR, all non-terminal +keys must exist and have dictionaries as their values. +.SH EXAMPLE +Using the dictionary iteration interface to search determine if there +is a key that maps to itself: +.PP +.CS +Tcl_DictSearch search; +Tcl_Obj *key, *value; +int done; + +/* + * Assume interp and objPtr are parameters. This is the + * idiomatic way to start an iteration over the dictionary; it + * sets a lock on the internal representation that ensures that + * there are no concurrent modification issues when normal + * reference count management is also used. The lock is + * released automatically when the loop is finished, but must + * be released manually when an exceptional exit from the loop + * is performed. However it is safe to try to release the lock + * even if we've finished iterating over the loop. + */ +if (\fBTcl_DictObjFirst\fR(interp, objPtr, &search, + &key, &value, &done) != TCL_OK) { + return TCL_ERROR; +} +for (; !done ; \fBTcl_DictObjNext\fR(&search, &key, &value, &done)) { + /* + * Note that strcmp() is not a good way of comparing + * values and is just used here for demonstration + * purposes. + */ + if (!strcmp(Tcl_GetString(key), Tcl_GetString(value))) { + break; + } +} +\fBTcl_DictObjDone\fR(&search); +Tcl_SetObjResult(interp, Tcl_NewBooleanObj(!done)); +return TCL_OK; +.CE +.SH "SEE ALSO" +Tcl_NewObj, Tcl_DecrRefCount, Tcl_IncrRefCount, Tcl_InitObjHashTable +.SH KEYWORDS +dict, dict value, dictionary, dictionary value, hash table, iteration, value diff --git a/tcl8.6/doc/DoOneEvent.3 b/tcl8.6/doc/DoOneEvent.3 new file mode 100644 index 0000000..d48afd0 --- /dev/null +++ b/tcl8.6/doc/DoOneEvent.3 @@ -0,0 +1,106 @@ +'\" +'\" Copyright (c) 1990-1992 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. +'\" +.TH Tcl_DoOneEvent 3 7.5 Tcl "Tcl Library Procedures" +.so man.macros +.BS +.SH NAME +Tcl_DoOneEvent \- wait for events and invoke event handlers +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +int +\fBTcl_DoOneEvent\fR(\fIflags\fR) +.SH ARGUMENTS +.AS int flags +.AP int flags in +This parameter is normally zero. It may be an OR-ed combination +of any of the following flag bits: +\fBTCL_WINDOW_EVENTS\fR, \fBTCL_FILE_EVENTS\fR, +\fBTCL_TIMER_EVENTS\fR, \fBTCL_IDLE_EVENTS\fR, \fBTCL_ALL_EVENTS\fR, +or \fBTCL_DONT_WAIT\fR. +.BE + +.SH DESCRIPTION +.PP +This procedure is the entry point to Tcl's event loop; it is responsible for +waiting for events and dispatching event handlers created with +procedures such as \fBTk_CreateEventHandler\fR, \fBTcl_CreateFileHandler\fR, +\fBTcl_CreateTimerHandler\fR, and \fBTcl_DoWhenIdle\fR. +\fBTcl_DoOneEvent\fR checks to see if +events are already present on the Tcl event queue; if so, +it calls the handler(s) for the first (oldest) event, removes it from +the queue, and returns. +If there are no events ready to be handled, then \fBTcl_DoOneEvent\fR +checks for new events from all possible sources. +If any are found, it puts all of them on Tcl's event queue, calls +handlers for the first event on the queue, and returns. +If no events are found, \fBTcl_DoOneEvent\fR checks for \fBTcl_DoWhenIdle\fR +callbacks; if any are found, it invokes all of them and returns. +Finally, if no events or idle callbacks have been found, then +\fBTcl_DoOneEvent\fR sleeps until an event occurs; then it adds any +new events to the Tcl event queue, calls handlers for the first event, +and returns. +The normal return value is 1 to signify that some event +was processed (see below for other alternatives). +.PP +If the \fIflags\fR argument to \fBTcl_DoOneEvent\fR is non-zero, +it restricts the kinds of events that will be processed by +\fBTcl_DoOneEvent\fR. +\fIFlags\fR may be an OR-ed combination of any of the following bits: +.TP 27 +\fBTCL_WINDOW_EVENTS\fR \- +Process window system events. +.TP 27 +\fBTCL_FILE_EVENTS\fR \- +Process file events. +.TP 27 +\fBTCL_TIMER_EVENTS\fR \- +Process timer events. +.TP 27 +\fBTCL_IDLE_EVENTS\fR \- +Process idle callbacks. +.TP 27 +\fBTCL_ALL_EVENTS\fR \- +Process all kinds of events: equivalent to OR-ing together all of the +above flags or specifying none of them. +.TP 27 +\fBTCL_DONT_WAIT\fR \- +Do not sleep: process only events that are ready at the time of the +call. +.LP +If any of the flags \fBTCL_WINDOW_EVENTS\fR, \fBTCL_FILE_EVENTS\fR, +\fBTCL_TIMER_EVENTS\fR, or \fBTCL_IDLE_EVENTS\fR is set, then the only +events that will be considered are those for which flags are set. +Setting none of these flags is equivalent to the value +\fBTCL_ALL_EVENTS\fR, which causes all event types to be processed. +If an application has defined additional event sources with +\fBTcl_CreateEventSource\fR, then additional \fIflag\fR values +may also be valid, depending on those event sources. +.PP +The \fBTCL_DONT_WAIT\fR flag causes \fBTcl_DoOneEvent\fR not to put +the process to sleep: it will check for events but if none are found +then it returns immediately with a return value of 0 to indicate +that no work was done. +\fBTcl_DoOneEvent\fR will also return 0 without doing anything if +the only alternative is to block forever (this can happen, for example, +if \fIflags\fR is \fBTCL_IDLE_EVENTS\fR and there are no +\fBTcl_DoWhenIdle\fR callbacks pending, or if no event handlers or +timer handlers exist). +.PP +\fBTcl_DoOneEvent\fR may be invoked recursively. For example, +it is possible to invoke \fBTcl_DoOneEvent\fR recursively +from a handler called by \fBTcl_DoOneEvent\fR. This sort +of operation is useful in some modal situations, such +as when a +notification dialog has been popped up and an application wishes to +wait for the user to click a button in the dialog before +doing anything else. + +.SH KEYWORDS +callback, event, handler, idle, timer diff --git a/tcl8.6/doc/DoWhenIdle.3 b/tcl8.6/doc/DoWhenIdle.3 new file mode 100644 index 0000000..3e28b4d --- /dev/null +++ b/tcl8.6/doc/DoWhenIdle.3 @@ -0,0 +1,87 @@ +'\" +'\" Copyright (c) 1990 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. +'\" +.TH Tcl_DoWhenIdle 3 7.5 Tcl "Tcl Library Procedures" +.so man.macros +.BS +.SH NAME +Tcl_DoWhenIdle, Tcl_CancelIdleCall \- invoke a procedure when there are no pending events +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +\fBTcl_DoWhenIdle\fR(\fIproc, clientData\fR) +.sp +\fBTcl_CancelIdleCall\fR(\fIproc, clientData\fR) +.SH ARGUMENTS +.AS Tcl_IdleProc clientData +.AP Tcl_IdleProc *proc in +Procedure to invoke. +.AP ClientData clientData in +Arbitrary one-word value to pass to \fIproc\fR. +.BE +.SH DESCRIPTION +.PP +\fBTcl_DoWhenIdle\fR arranges for \fIproc\fR to be invoked +when the application becomes idle. The application is +considered to be idle when \fBTcl_DoOneEvent\fR has been +called, could not find any events to handle, and is about +to go to sleep waiting for an event to occur. At this +point all pending \fBTcl_DoWhenIdle\fR handlers are +invoked. For each call to \fBTcl_DoWhenIdle\fR there will +be a single call to \fIproc\fR; after \fIproc\fR is +invoked the handler is automatically removed. +\fBTcl_DoWhenIdle\fR is only usable in programs that +use \fBTcl_DoOneEvent\fR to dispatch events. +.PP +\fIProc\fR should have arguments and result that match the +type \fBTcl_IdleProc\fR: +.PP +.CS +typedef void \fBTcl_IdleProc\fR( + ClientData \fIclientData\fR); +.CE +.PP +The \fIclientData\fR parameter to \fIproc\fR is a copy of the \fIclientData\fR +argument given to \fBTcl_DoWhenIdle\fR. Typically, \fIclientData\fR +points to a data structure containing application-specific information about +what \fIproc\fR should do. +.PP +\fBTcl_CancelIdleCall\fR +may be used to cancel one or more previous +calls to \fBTcl_DoWhenIdle\fR: if there is a \fBTcl_DoWhenIdle\fR +handler registered for \fIproc\fR and \fIclientData\fR, then it +is removed without invoking it. If there is more than one +handler on the idle list that refers to \fIproc\fR and \fIclientData\fR, +all of the handlers are removed. If no existing handlers match +\fIproc\fR and \fIclientData\fR then nothing happens. +.PP +\fBTcl_DoWhenIdle\fR is most useful in situations where +(a) a piece of work will have to be done but (b) it is +possible that something will happen in the near future +that will change what has to be done or require something +different to be done. \fBTcl_DoWhenIdle\fR allows the +actual work to be deferred until all pending events have +been processed. At this point the exact work to be done +will presumably be known and it can be done exactly once. +.PP +For example, \fBTcl_DoWhenIdle\fR might be used by an editor +to defer display updates until all pending commands have +been processed. Without this feature, redundant redisplays +might occur in some situations, such as the processing of +a command file. +.SH BUGS +.PP +At present it is not safe for an idle callback to reschedule itself +continuously. This will interact badly with certain features of Tk +that attempt to wait for all idle callbacks to complete. If you would +like for an idle callback to reschedule itself continuously, it is +better to use a timer handler with a zero timeout period. +.SH "SEE ALSO" +after(n), Tcl_CreateFileHandler(3), Tcl_CreateTimerHandler(3) +.SH KEYWORDS +callback, defer, idle callback diff --git a/tcl8.6/doc/DoubleObj.3 b/tcl8.6/doc/DoubleObj.3 new file mode 100644 index 0000000..85e4de5 --- /dev/null +++ b/tcl8.6/doc/DoubleObj.3 @@ -0,0 +1,64 @@ +'\" +'\" Copyright (c) 1996-1997 Sun Microsystems, Inc. +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH Tcl_DoubleObj 3 8.0 Tcl "Tcl Library Procedures" +.so man.macros +.BS +.SH NAME +Tcl_NewDoubleObj, Tcl_SetDoubleObj, Tcl_GetDoubleFromObj \- manipulate Tcl values as floating-point values +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +Tcl_Obj * +\fBTcl_NewDoubleObj\fR(\fIdoubleValue\fR) +.sp +\fBTcl_SetDoubleObj\fR(\fIobjPtr, doubleValue\fR) +.sp +int +\fBTcl_GetDoubleFromObj\fR(\fIinterp, objPtr, doublePtr\fR) +.SH ARGUMENTS +.AS Tcl_Interp doubleValue in/out +.AP double doubleValue in +A double-precision floating-point value used to initialize or set a Tcl value. +.AP Tcl_Obj *objPtr in/out +For \fBTcl_SetDoubleObj\fR, this points to the value in which to store a +double value. +For \fBTcl_GetDoubleFromObj\fR, this refers to the value +from which to retrieve a double value. +.AP Tcl_Interp *interp in/out +When non-NULL, an error message is left here when double value retrieval fails. +.AP double *doublePtr out +Points to place to store the double value obtained from \fIobjPtr\fR. +.BE + +.SH DESCRIPTION +.PP +These procedures are used to create, modify, and read Tcl values that +hold double-precision floating-point values. +.PP +\fBTcl_NewDoubleObj\fR creates and returns a new Tcl value initialized to +the double value \fIdoubleValue\fR. The returned Tcl value is unshared. +.PP +\fBTcl_SetDoubleObj\fR sets the value of an existing Tcl value pointed to +by \fIobjPtr\fR to the double value \fIdoubleValue\fR. The \fIobjPtr\fR +argument must point to an unshared Tcl value. Any attempt to set the value +of a shared Tcl value violates Tcl's copy-on-write policy. Any existing +string representation or internal representation in the unshared Tcl value +will be freed as a consequence of setting the new value. +.PP +\fBTcl_GetDoubleFromObj\fR attempts to retrieve a double value from the +Tcl value \fIobjPtr\fR. If the attempt succeeds, then \fBTCL_OK\fR is +returned, and the double value is written to the storage pointed to by +\fIdoublePtr\fR. If the attempt fails, then \fBTCL_ERROR\fR is returned, +and if \fIinterp\fR is non-NULL, an error message is left in \fIinterp\fR. +The \fBTcl_ObjType\fR of \fIobjPtr\fR may be changed to make subsequent +calls to \fBTcl_GetDoubleFromObj\fR more efficient. +'\" TODO: add discussion of treatment of NaN value +.SH "SEE ALSO" +Tcl_NewObj, Tcl_DecrRefCount, Tcl_IncrRefCount, Tcl_GetObjResult +.SH KEYWORDS +double, double value, double type, internal representation, value, value type, string representation diff --git a/tcl8.6/doc/DumpActiveMemory.3 b/tcl8.6/doc/DumpActiveMemory.3 new file mode 100644 index 0000000..43333da --- /dev/null +++ b/tcl8.6/doc/DumpActiveMemory.3 @@ -0,0 +1,68 @@ +'\" +'\" Copyright (c) 1992-1999 Karl Lehenbauer and Mark Diekhans. +'\" Copyright (c) 2000 by Scriptics Corporation. +'\" All rights reserved. +'\" +.TH "Tcl_DumpActiveMemory" 3 8.1 Tcl "Tcl Library Procedures" +.so man.macros +.BS +.SH NAME +Tcl_DumpActiveMemory, Tcl_InitMemory, Tcl_ValidateAllMemory \- Validated memory allocation interface +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +int +\fBTcl_DumpActiveMemory\fR(\fIfileName\fR) +.sp +void +\fBTcl_InitMemory\fR(\fIinterp\fR) +.sp +void +\fBTcl_ValidateAllMemory\fR(\fIfileName, line\fR) + +.SH ARGUMENTS +.AS Tcl_Interp *fileName +.AP Tcl_Interp *interp in +Tcl interpreter in which to add commands. +.AP "const char" *fileName in +For \fBTcl_DumpActiveMemory\fR, name of the file to which memory +information will be written. For \fBTcl_ValidateAllMemory\fR, name of +the file from which the call is being made (normally \fB__FILE__\fR). +.AP int line in +Line number at which the call to \fBTcl_ValidateAllMemory\fR is made +(normally \fB__LINE__\fR). +.BE + +.SH DESCRIPTION +These functions provide access to Tcl memory debugging information. +They are only functional when Tcl has been compiled with +\fBTCL_MEM_DEBUG\fR defined at compile-time. When \fBTCL_MEM_DEBUG\fR +is not defined, these functions are all no-ops. +.PP +\fBTcl_DumpActiveMemory\fR will output a list of all currently +allocated memory to the specified file. The information output for +each allocated block of memory is: starting and ending addresses +(excluding guard zone), size, source file where \fBckalloc\fR was +called to allocate the block and line number in that file. It is +especially useful to call \fBTcl_DumpActiveMemory\fR after the Tcl +interpreter has been deleted. +.PP +\fBTcl_InitMemory\fR adds the Tcl \fBmemory\fR command to the +interpreter given by \fIinterp\fR. \fBTcl_InitMemory\fR is called +by \fBTcl_Main\fR. +.PP +\fBTcl_ValidateAllMemory\fR forces a validation of the guard zones of +all currently allocated blocks of memory. Normally validation of a +block occurs when its freed, unless full validation is enabled, in +which case validation of all blocks occurs when \fBckalloc\fR and +\fBckfree\fR are called. This function forces the validation to occur +at any point. + +.SH "SEE ALSO" +TCL_MEM_DEBUG, memory + +.SH KEYWORDS +memory, debug + + diff --git a/tcl8.6/doc/Encoding.3 b/tcl8.6/doc/Encoding.3 new file mode 100644 index 0000000..81ef508 --- /dev/null +++ b/tcl8.6/doc/Encoding.3 @@ -0,0 +1,558 @@ +'\" +'\" Copyright (c) 1997-1998 Sun Microsystems, Inc. +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH Tcl_GetEncoding 3 "8.1" Tcl "Tcl Library Procedures" +.so man.macros +.BS +.SH NAME +Tcl_GetEncoding, Tcl_FreeEncoding, Tcl_GetEncodingFromObj, Tcl_ExternalToUtfDString, Tcl_ExternalToUtf, Tcl_UtfToExternalDString, Tcl_UtfToExternal, Tcl_WinTCharToUtf, Tcl_WinUtfToTChar, Tcl_GetEncodingName, Tcl_SetSystemEncoding, Tcl_GetEncodingNameFromEnvironment, Tcl_GetEncodingNames, Tcl_CreateEncoding, Tcl_GetEncodingSearchPath, Tcl_SetEncodingSearchPath, Tcl_GetDefaultEncodingDir, Tcl_SetDefaultEncodingDir \- procedures for creating and using encodings +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +Tcl_Encoding +\fBTcl_GetEncoding\fR(\fIinterp, name\fR) +.sp +void +\fBTcl_FreeEncoding\fR(\fIencoding\fR) +.sp +int +\fBTcl_GetEncodingFromObj\fR(\fIinterp, objPtr, encodingPtr\fR) +.sp +char * +\fBTcl_ExternalToUtfDString\fR(\fIencoding, src, srcLen, dstPtr\fR) +.sp +char * +\fBTcl_UtfToExternalDString\fR(\fIencoding, src, srcLen, dstPtr\fR) +.sp +int +\fBTcl_ExternalToUtf\fR(\fIinterp, encoding, src, srcLen, flags, statePtr, + dst, dstLen, srcReadPtr, dstWrotePtr, dstCharsPtr\fR) +.sp +int +\fBTcl_UtfToExternal\fR(\fIinterp, encoding, src, srcLen, flags, statePtr, + dst, dstLen, srcReadPtr, dstWrotePtr, dstCharsPtr\fR) +.sp +char * +\fBTcl_WinTCharToUtf\fR(\fItsrc, srcLen, dstPtr\fR) +.sp +TCHAR * +\fBTcl_WinUtfToTChar\fR(\fIsrc, srcLen, dstPtr\fR) +.sp +const char * +\fBTcl_GetEncodingName\fR(\fIencoding\fR) +.sp +int +\fBTcl_SetSystemEncoding\fR(\fIinterp, name\fR) +.sp +const char * +\fBTcl_GetEncodingNameFromEnvironment\fR(\fIbufPtr\fR) +.sp +void +\fBTcl_GetEncodingNames\fR(\fIinterp\fR) +.sp +Tcl_Encoding +\fBTcl_CreateEncoding\fR(\fItypePtr\fR) +.sp +Tcl_Obj * +\fBTcl_GetEncodingSearchPath\fR() +.sp +int +\fBTcl_SetEncodingSearchPath\fR(\fIsearchPath\fR) +.sp +const char * +\fBTcl_GetDefaultEncodingDir\fR(\fIvoid\fR) +.sp +void +\fBTcl_SetDefaultEncodingDir\fR(\fIpath\fR) +.SH ARGUMENTS +.AS "const Tcl_EncodingType" *dstWrotePtr in/out +.AP Tcl_Interp *interp in +Interpreter to use for error reporting, or NULL if no error reporting is +desired. +.AP "const char" *name in +Name of encoding to load. +.AP Tcl_Encoding encoding in +The encoding to query, free, or use for converting text. If \fIencoding\fR is +NULL, the current system encoding is used. +.AP Tcl_Obj *objPtr in +Name of encoding to get token for. +.AP Tcl_Encoding *encodingPtr out +Points to storage where encoding token is to be written. +.AP "const char" *src in +For the \fBTcl_ExternalToUtf\fR functions, an array of bytes in the +specified encoding that are to be converted to UTF-8. For the +\fBTcl_UtfToExternal\fR and \fBTcl_WinUtfToTChar\fR functions, an array of +UTF-8 characters to be converted to the specified encoding. +.AP "const TCHAR" *tsrc in +An array of Windows TCHAR characters to convert to UTF-8. +.AP int srcLen in +Length of \fIsrc\fR or \fItsrc\fR in bytes. If the length is negative, the +encoding-specific length of the string is used. +.AP Tcl_DString *dstPtr out +Pointer to an uninitialized or free \fBTcl_DString\fR in which the converted +result will be stored. +.AP int flags in +Various flag bits OR-ed together. +\fBTCL_ENCODING_START\fR signifies that the +source buffer is the first block in a (potentially multi-block) input +stream, telling the conversion routine to reset to an initial state and +perform any initialization that needs to occur before the first byte is +converted. \fBTCL_ENCODING_END\fR signifies that the source buffer is the last +block in a (potentially multi-block) input stream, telling the conversion +routine to perform any finalization that needs to occur after the last +byte is converted and then to reset to an initial state. +\fBTCL_ENCODING_STOPONERROR\fR signifies that the conversion routine should +return immediately upon reading a source character that does not exist in +the target encoding; otherwise a default fallback character will +automatically be substituted. +.AP Tcl_EncodingState *statePtr in/out +Used when converting a (generally long or indefinite length) byte stream +in a piece-by-piece fashion. The conversion routine stores its current +state in \fI*statePtr\fR after \fIsrc\fR (the buffer containing the +current piece) has been converted; that state information must be passed +back when converting the next piece of the stream so the conversion +routine knows what state it was in when it left off at the end of the +last piece. May be NULL, in which case the value specified for \fIflags\fR +is ignored and the source buffer is assumed to contain the complete string to +convert. +.AP char *dst out +Buffer in which the converted result will be stored. No more than +\fIdstLen\fR bytes will be stored in \fIdst\fR. +.AP int dstLen in +The maximum length of the output buffer \fIdst\fR in bytes. +.AP int *srcReadPtr out +Filled with the number of bytes from \fIsrc\fR that were actually +converted. This may be less than the original source length if there was +a problem converting some source characters. May be NULL. +.AP int *dstWrotePtr out +Filled with the number of bytes that were actually stored in the output +buffer as a result of the conversion. May be NULL. +.AP int *dstCharsPtr out +Filled with the number of characters that correspond to the number of bytes +stored in the output buffer. May be NULL. +.AP Tcl_DString *bufPtr out +Storage for the prescribed system encoding name. +.AP "const Tcl_EncodingType" *typePtr in +Structure that defines a new type of encoding. +.AP Tcl_Obj *searchPath in +List of filesystem directories in which to search for encoding data files. +.AP "const char" *path in +A path to the location of the encoding file. +.BE +.SH INTRODUCTION +.PP +These routines convert between Tcl's internal character representation, +UTF-8, and character representations used by various operating systems or +file systems, such as Unicode, ASCII, or Shift-JIS. When operating on +strings, such as such as obtaining the names of files or displaying +characters using international fonts, the strings must be translated into +one or possibly multiple formats that the various system calls can use. For +instance, on a Japanese Unix workstation, a user might obtain a filename +represented in the EUC-JP file encoding and then translate the characters to +the jisx0208 font encoding in order to display the filename in a Tk widget. +The purpose of the encoding package is to help bridge the translation gap. +UTF-8 provides an intermediate staging ground for all the various +encodings. In the example above, text would be translated into UTF-8 from +whatever file encoding the operating system is using. Then it would be +translated from UTF-8 into whatever font encoding the display routines +require. +.PP +Some basic encodings are compiled into Tcl. Others can be defined by the +user or dynamically loaded from encoding files in a +platform-independent manner. +.SH DESCRIPTION +.PP +\fBTcl_GetEncoding\fR finds an encoding given its \fIname\fR. The name may +refer to a built-in Tcl encoding, a user-defined encoding registered by +calling \fBTcl_CreateEncoding\fR, or a dynamically-loadable encoding +file. The return value is a token that represents the encoding and can be +used in subsequent calls to procedures such as \fBTcl_GetEncodingName\fR, +\fBTcl_FreeEncoding\fR, and \fBTcl_UtfToExternal\fR. If the name did not +refer to any known or loadable encoding, NULL is returned and an error +message is returned in \fIinterp\fR. +.PP +The encoding package maintains a database of all encodings currently in use. +The first time \fIname\fR is seen, \fBTcl_GetEncoding\fR returns an +encoding with a reference count of 1. If the same \fIname\fR is requested +further times, then the reference count for that encoding is incremented +without the overhead of allocating a new encoding and all its associated +data structures. +.PP +When an \fIencoding\fR is no longer needed, \fBTcl_FreeEncoding\fR +should be called to release it. When an \fIencoding\fR is no longer in use +anywhere (i.e., it has been freed as many times as it has been gotten) +\fBTcl_FreeEncoding\fR will release all storage the encoding was using +and delete it from the database. +.PP +\fBTcl_GetEncodingFromObj\fR treats the string representation of +\fIobjPtr\fR as an encoding name, and finds an encoding with that +name, just as \fBTcl_GetEncoding\fR does. When an encoding is found, +it is cached within the \fBobjPtr\fR value for future reference, the +\fBTcl_Encoding\fR token is written to the storage pointed to by +\fIencodingPtr\fR, and the value \fBTCL_OK\fR is returned. If no such +encoding is found, the value \fBTCL_ERROR\fR is returned, and no +writing to \fB*\fR\fIencodingPtr\fR takes place. Just as with +\fBTcl_GetEncoding\fR, the caller should call \fBTcl_FreeEncoding\fR +on the resulting encoding token when that token will no longer be +used. +.PP +\fBTcl_ExternalToUtfDString\fR converts a source buffer \fIsrc\fR from the +specified \fIencoding\fR into UTF-8. The converted bytes are stored in +\fIdstPtr\fR, which is then null-terminated. The caller should eventually +call \fBTcl_DStringFree\fR to free any information stored in \fIdstPtr\fR. +When converting, if any of the characters in the source buffer cannot be +represented in the target encoding, a default fallback character will be +used. The return value is a pointer to the value stored in the DString. +.PP +\fBTcl_ExternalToUtf\fR converts a source buffer \fIsrc\fR from the specified +\fIencoding\fR into UTF-8. Up to \fIsrcLen\fR bytes are converted from the +source buffer and up to \fIdstLen\fR converted bytes are stored in \fIdst\fR. +In all cases, \fI*srcReadPtr\fR is filled with the number of bytes that were +successfully converted from \fIsrc\fR and \fI*dstWrotePtr\fR is filled with +the corresponding number of bytes that were stored in \fIdst\fR. The return +value is one of the following: +.RS +.IP \fBTCL_OK\fR 29 +All bytes of \fIsrc\fR were converted. +.IP \fBTCL_CONVERT_NOSPACE\fR 29 +The destination buffer was not large enough for all of the converted data; as +many characters as could fit were converted though. +.IP \fBTCL_CONVERT_MULTIBYTE\fR 29 +The last few bytes in the source buffer were the beginning of a multibyte +sequence, but more bytes were needed to complete this sequence. A +subsequent call to the conversion routine should pass a buffer containing +the unconverted bytes that remained in \fIsrc\fR plus some further bytes +from the source stream to properly convert the formerly split-up multibyte +sequence. +.IP \fBTCL_CONVERT_SYNTAX\fR 29 +The source buffer contained an invalid character sequence. This may occur +if the input stream has been damaged or if the input encoding method was +misidentified. +.IP \fBTCL_CONVERT_UNKNOWN\fR 29 +The source buffer contained a character that could not be represented in +the target encoding and \fBTCL_ENCODING_STOPONERROR\fR was specified. +.RE +.LP +\fBTcl_UtfToExternalDString\fR converts a source buffer \fIsrc\fR from UTF-8 +into the specified \fIencoding\fR. The converted bytes are stored in +\fIdstPtr\fR, which is then terminated with the appropriate encoding-specific +null. The caller should eventually call \fBTcl_DStringFree\fR to free any +information stored in \fIdstPtr\fR. When converting, if any of the +characters in the source buffer cannot be represented in the target +encoding, a default fallback character will be used. The return value is +a pointer to the value stored in the DString. +.PP +\fBTcl_UtfToExternal\fR converts a source buffer \fIsrc\fR from UTF-8 into +the specified \fIencoding\fR. Up to \fIsrcLen\fR bytes are converted from +the source buffer and up to \fIdstLen\fR converted bytes are stored in +\fIdst\fR. In all cases, \fI*srcReadPtr\fR is filled with the number of +bytes that were successfully converted from \fIsrc\fR and \fI*dstWrotePtr\fR +is filled with the corresponding number of bytes that were stored in +\fIdst\fR. The return values are the same as the return values for +\fBTcl_ExternalToUtf\fR. +.PP +\fBTcl_WinUtfToTChar\fR and \fBTcl_WinTCharToUtf\fR are +Windows-only convenience +functions for converting between UTF-8 and Windows strings +based on the TCHAR type which is by convention +a Unicode character on Windows NT. +These functions are essentially wrappers around +\fBTcl_UtfToExternalDString\fR and +\fBTcl_ExternalToUtfDString\fR that convert to and from the +Unicode encoding. +.PP +\fBTcl_GetEncodingName\fR is roughly the inverse of \fBTcl_GetEncoding\fR. +Given an \fIencoding\fR, the return value is the \fIname\fR argument that +was used to create the encoding. The string returned by +\fBTcl_GetEncodingName\fR is only guaranteed to persist until the +\fIencoding\fR is deleted. The caller must not modify this string. +.PP +\fBTcl_SetSystemEncoding\fR sets the default encoding that should be used +whenever the user passes a NULL value for the \fIencoding\fR argument to +any of the other encoding functions. If \fIname\fR is NULL, the system +encoding is reset to the default system encoding, \fBbinary\fR. If the +name did not refer to any known or loadable encoding, \fBTCL_ERROR\fR is +returned and an error message is left in \fIinterp\fR. Otherwise, this +procedure increments the reference count of the new system encoding, +decrements the reference count of the old system encoding, and returns +\fBTCL_OK\fR. +.PP +\fBTcl_GetEncodingNameFromEnvironment\fR provides a means for the Tcl +library to report the encoding name it believes to be the correct one +to use as the system encoding, based on system calls and examination of +the environment suitable for the platform. It accepts \fIbufPtr\fR, +a pointer to an uninitialized or freed \fBTcl_DString\fR and writes +the encoding name to it. The \fBTcl_DStringValue\fR is returned. +.PP +\fBTcl_GetEncodingNames\fR sets the \fIinterp\fR result to a list +consisting of the names of all the encodings that are currently defined +or can be dynamically loaded, searching the encoding path specified by +\fBTcl_SetDefaultEncodingDir\fR. This procedure does not ensure that the +dynamically-loadable encoding files contain valid data, but merely that they +exist. +.PP +\fBTcl_CreateEncoding\fR defines a new encoding and registers the C +procedures that are called back to convert between the encoding and +UTF-8. Encodings created by \fBTcl_CreateEncoding\fR are thereafter +visible in the database used by \fBTcl_GetEncoding\fR. Just as with the +\fBTcl_GetEncoding\fR procedure, the return value is a token that +represents the encoding and can be used in subsequent calls to other +encoding functions. \fBTcl_CreateEncoding\fR returns an encoding with a +reference count of 1. If an encoding with the specified \fIname\fR +already exists, then its entry in the database is replaced with the new +encoding; the token for the old encoding will remain valid and continue +to behave as before, but users of the new token will now call the new +encoding procedures. +.PP +The \fItypePtr\fR argument to \fBTcl_CreateEncoding\fR contains information +about the name of the encoding and the procedures that will be called to +convert between this encoding and UTF-8. It is defined as follows: +.PP +.CS +typedef struct Tcl_EncodingType { + const char *\fIencodingName\fR; + Tcl_EncodingConvertProc *\fItoUtfProc\fR; + Tcl_EncodingConvertProc *\fIfromUtfProc\fR; + Tcl_EncodingFreeProc *\fIfreeProc\fR; + ClientData \fIclientData\fR; + int \fInullSize\fR; +} \fBTcl_EncodingType\fR; +.CE +.PP +The \fIencodingName\fR provides a string name for the encoding, by +which it can be referred in other procedures such as +\fBTcl_GetEncoding\fR. The \fItoUtfProc\fR refers to a callback +procedure to invoke to convert text from this encoding into UTF-8. +The \fIfromUtfProc\fR refers to a callback procedure to invoke to +convert text from UTF-8 into this encoding. The \fIfreeProc\fR refers +to a callback procedure to invoke when this encoding is deleted. The +\fIfreeProc\fR field may be NULL. The \fIclientData\fR contains an +arbitrary one-word value passed to \fItoUtfProc\fR, \fIfromUtfProc\fR, +and \fIfreeProc\fR whenever they are called. Typically, this is a +pointer to a data structure containing encoding-specific information +that can be used by the callback procedures. For instance, two very +similar encodings such as \fBascii\fR and \fBmacRoman\fR may use the +same callback procedure, but use different values of \fIclientData\fR +to control its behavior. The \fInullSize\fR specifies the number of +zero bytes that signify end-of-string in this encoding. It must be +\fB1\fR (for single-byte or multi-byte encodings like ASCII or +Shift-JIS) or \fB2\fR (for double-byte encodings like Unicode). +Constant-sized encodings with 3 or more bytes per character (such as +CNS11643) are not accepted. +.PP +The callback procedures \fItoUtfProc\fR and \fIfromUtfProc\fR should match the +type \fBTcl_EncodingConvertProc\fR: +.PP +.CS +typedef int \fBTcl_EncodingConvertProc\fR( + ClientData \fIclientData\fR, + const char *\fIsrc\fR, + int \fIsrcLen\fR, + int \fIflags\fR, + Tcl_EncodingState *\fIstatePtr\fR, + char *\fIdst\fR, + int \fIdstLen\fR, + int *\fIsrcReadPtr\fR, + int *\fIdstWrotePtr\fR, + int *\fIdstCharsPtr\fR); +.CE +.PP +The \fItoUtfProc\fR and \fIfromUtfProc\fR procedures are called by the +\fBTcl_ExternalToUtf\fR or \fBTcl_UtfToExternal\fR family of functions to +perform the actual conversion. The \fIclientData\fR parameter to these +procedures is the same as the \fIclientData\fR field specified to +\fBTcl_CreateEncoding\fR when the encoding was created. The remaining +arguments to the callback procedures are the same as the arguments, +documented at the top, to \fBTcl_ExternalToUtf\fR or +\fBTcl_UtfToExternal\fR, with the following exceptions. If the +\fIsrcLen\fR argument to one of those high-level functions is negative, +the value passed to the callback procedure will be the appropriate +encoding-specific string length of \fIsrc\fR. If any of the \fIsrcReadPtr\fR, +\fIdstWrotePtr\fR, or \fIdstCharsPtr\fR arguments to one of the high-level +functions is NULL, the corresponding value passed to the callback +procedure will be a non-NULL location. +.PP +The callback procedure \fIfreeProc\fR, if non-NULL, should match the type +\fBTcl_EncodingFreeProc\fR: +.PP +.CS +typedef void \fBTcl_EncodingFreeProc\fR( + ClientData \fIclientData\fR); +.CE +.PP +This \fIfreeProc\fR function is called when the encoding is deleted. The +\fIclientData\fR parameter is the same as the \fIclientData\fR field +specified to \fBTcl_CreateEncoding\fR when the encoding was created. +.PP +\fBTcl_GetEncodingSearchPath\fR and \fBTcl_SetEncodingSearchPath\fR +are called to access and set the list of filesystem directories searched +for encoding data files. +.PP +The value returned by \fBTcl_GetEncodingSearchPath\fR +is the value stored by the last successful call to +\fBTcl_SetEncodingSearchPath\fR. If no calls to +\fBTcl_SetEncodingSearchPath\fR have occurred, Tcl will compute an initial +value based on the environment. There is one encoding search path for the +entire process, shared by all threads in the process. +.PP +\fBTcl_SetEncodingSearchPath\fR stores \fIsearchPath\fR and returns +\fBTCL_OK\fR, unless \fIsearchPath\fR is not a valid Tcl list, which +causes \fBTCL_ERROR\fR to be returned. The elements of \fIsearchPath\fR +are not verified as existing readable filesystem directories. When +searching for encoding data files takes place, and non-existent or +non-readable filesystem directories on the \fIsearchPath\fR are silently +ignored. +.PP +\fBTcl_GetDefaultEncodingDir\fR and \fBTcl_SetDefaultEncodingDir\fR +are obsolete interfaces best replaced with calls to +\fBTcl_GetEncodingSearchPath\fR and \fBTcl_SetEncodingSearchPath\fR. +They are called to access and set the first element of the \fIsearchPath\fR +list. Since Tcl searches \fIsearchPath\fR for encoding data files in +list order, these routines establish the +.QW default +directory in which to find encoding data files. +.SH "ENCODING FILES" +Space would prohibit precompiling into Tcl every possible encoding +algorithm, so many encodings are stored on disk as dynamically-loadable +encoding files. This behavior also allows the user to create additional +encoding files that can be loaded using the same mechanism. These +encoding files contain information about the tables and/or escape +sequences used to map between an external encoding and Unicode. The +external encoding may consist of single-byte, multi-byte, or double-byte +characters. +.PP +Each dynamically-loadable encoding is represented as a text file. The +initial line of the file, beginning with a +.QW # +symbol, is a comment +that provides a human-readable description of the file. The next line +identifies the type of encoding file. It can be one of the following +letters: +.IP "[1] \fBS\fR" +A single-byte encoding, where one character is always one byte long in the +encoding. An example is \fBiso8859-1\fR, used by many European languages. +.IP "[2] \fBD\fR" +A double-byte encoding, where one character is always two bytes long in the +encoding. An example is \fBbig5\fR, used for Chinese text. +.IP "[3] \fBM\fR" +A multi-byte encoding, where one character may be either one or two bytes long. +Certain bytes are lead bytes, indicating that another byte must follow +and that together the two bytes represent one character. Other bytes are not +lead bytes and represent themselves. An example is \fBshiftjis\fR, used by +many Japanese computers. +.IP "[4] \fBE\fR" +An escape-sequence encoding, specifying that certain sequences of bytes +do not represent characters, but commands that describe how following bytes +should be interpreted. +.PP +The rest of the lines in the file depend on the type. +.PP +Cases [1], [2], and [3] are collectively referred to as table-based encoding +files. The lines in a table-based encoding file are in the same +format as this example taken from the \fBshiftjis\fR encoding (this is not +the complete file): +.PP +.CS +# Encoding file: shiftjis, multi-byte +M +003F 0 40 +00 +0000000100020003000400050006000700080009000A000B000C000D000E000F +0010001100120013001400150016001700180019001A001B001C001D001E001F +0020002100220023002400250026002700280029002A002B002C002D002E002F +0030003100320033003400350036003700380039003A003B003C003D003E003F +0040004100420043004400450046004700480049004A004B004C004D004E004F +0050005100520053005400550056005700580059005A005B005C005D005E005F +0060006100620063006400650066006700680069006A006B006C006D006E006F +0070007100720073007400750076007700780079007A007B007C007D203E007F +0080000000000000000000000000000000000000000000000000000000000000 +0000000000000000000000000000000000000000000000000000000000000000 +0000FF61FF62FF63FF64FF65FF66FF67FF68FF69FF6AFF6BFF6CFF6DFF6EFF6F +FF70FF71FF72FF73FF74FF75FF76FF77FF78FF79FF7AFF7BFF7CFF7DFF7EFF7F +FF80FF81FF82FF83FF84FF85FF86FF87FF88FF89FF8AFF8BFF8CFF8DFF8EFF8F +FF90FF91FF92FF93FF94FF95FF96FF97FF98FF99FF9AFF9BFF9CFF9DFF9EFF9F +0000000000000000000000000000000000000000000000000000000000000000 +0000000000000000000000000000000000000000000000000000000000000000 +81 +0000000000000000000000000000000000000000000000000000000000000000 +0000000000000000000000000000000000000000000000000000000000000000 +0000000000000000000000000000000000000000000000000000000000000000 +0000000000000000000000000000000000000000000000000000000000000000 +300030013002FF0CFF0E30FBFF1AFF1BFF1FFF01309B309C00B4FF4000A8FF3E +FFE3FF3F30FD30FE309D309E30034EDD30053006300730FC20152010FF0F005C +301C2016FF5C2026202520182019201C201DFF08FF0930143015FF3BFF3DFF5B +FF5D30083009300A300B300C300D300E300F30103011FF0B221200B100D70000 +00F7FF1D2260FF1CFF1E22662267221E22342642264000B0203220332103FFE5 +FF0400A200A3FF05FF03FF06FF0AFF2000A72606260525CB25CF25CE25C725C6 +25A125A025B325B225BD25BC203B301221922190219121933013000000000000 +000000000000000000000000000000002208220B2286228722822283222A2229 +000000000000000000000000000000002227222800AC21D221D4220022030000 +0000000000000000000000000000000000000000222022A52312220222072261 +2252226A226B221A223D221D2235222B222C0000000000000000000000000000 +212B2030266F266D266A2020202100B6000000000000000025EF000000000000 +.CE +.PP +The third line of the file is three numbers. The first number is the +fallback character (in base 16) to use when converting from UTF-8 to this +encoding. The second number is a \fB1\fR if this file represents the +encoding for a symbol font, or \fB0\fR otherwise. The last number (in base +10) is how many pages of data follow. +.PP +Subsequent lines in the example above are pages that describe how to map +from the encoding into 2-byte Unicode. The first line in a page identifies +the page number. Following it are 256 double-byte numbers, arranged as 16 +rows of 16 numbers. Given a character in the encoding, the high byte of +that character is used to select which page, and the low byte of that +character is used as an index to select one of the double-byte numbers in +that page \- the value obtained being the corresponding Unicode character. +By examination of the example above, one can see that the characters 0x7E +and 0x8163 in \fBshiftjis\fR map to 203E and 2026 in Unicode, respectively. +.PP +Following the first page will be all the other pages, each in the same +format as the first: one number identifying the page followed by 256 +double-byte Unicode characters. If a character in the encoding maps to the +Unicode character 0000, it means that the character does not actually exist. +If all characters on a page would map to 0000, that page can be omitted. +.PP +Case [4] is the escape-sequence encoding file. The lines in an this type of +file are in the same format as this example taken from the \fBiso2022-jp\fR +encoding: +.PP +.CS +.ta 1.5i +# Encoding file: iso2022-jp, escape-driven +E +init {} +final {} +iso8859-1 \ex1b(B +jis0201 \ex1b(J +jis0208 \ex1b$@ +jis0208 \ex1b$B +jis0212 \ex1b$(D +gb2312 \ex1b$A +ksc5601 \ex1b$(C +.CE +.PP +In the file, the first column represents an option and the second column +is the associated value. \fBinit\fR is a string to emit or expect before +the first character is converted, while \fBfinal\fR is a string to emit +or expect after the last character. All other options are names of +table-based encodings; the associated value is the escape-sequence that +marks that encoding. Tcl syntax is used for the values; in the above +example, for instance, +.QW \fB{}\fR +represents the empty string and +.QW \fB\ex1b\fR +represents character 27. +.PP +When \fBTcl_GetEncoding\fR encounters an encoding \fIname\fR that has not +been loaded, it attempts to load an encoding file called \fIname\fB.enc\fR +from the \fBencoding\fR subdirectory of each directory that Tcl searches +for its script library. If the encoding file exists, but is +malformed, an error message will be left in \fIinterp\fR. +.SH KEYWORDS +utf, encoding, convert diff --git a/tcl8.6/doc/Ensemble.3 b/tcl8.6/doc/Ensemble.3 new file mode 100644 index 0000000..30c1d3b --- /dev/null +++ b/tcl8.6/doc/Ensemble.3 @@ -0,0 +1,219 @@ +'\" +'\" Copyright (c) 2005 Donal K. Fellows +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +'\" This documents the C API introduced in TIP#235 +'\" +.TH Tcl_Ensemble 3 8.5 Tcl "Tcl Library Procedures" +.so man.macros +.BS +.SH NAME +Tcl_CreateEnsemble, Tcl_FindEnsemble, Tcl_GetEnsembleFlags, Tcl_GetEnsembleMappingDict, Tcl_GetEnsembleNamespace, Tcl_GetEnsembleParameterList, Tcl_GetEnsembleUnknownHandler, Tcl_GetEnsembleSubcommandList, Tcl_IsEnsemble, Tcl_SetEnsembleFlags, Tcl_SetEnsembleMappingDict, Tcl_SetEnsembleParameterList, Tcl_SetEnsembleSubcommandList, Tcl_SetEnsembleUnknownHandler \- manipulate ensemble commands +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +Tcl_Command +\fBTcl_CreateEnsemble\fR(\fIinterp, name, namespacePtr, ensFlags\fR) +.sp +Tcl_Command +\fBTcl_FindEnsemble\fR(\fIinterp, cmdNameObj, flags\fR) +.sp +int +\fBTcl_IsEnsemble\fR(\fItoken\fR) +.sp +int +\fBTcl_GetEnsembleFlags\fR(\fIinterp, token, ensFlagsPtr\fR) +.sp +int +\fBTcl_SetEnsembleFlags\fR(\fIinterp, token, ensFlags\fR) +.sp +int +\fBTcl_GetEnsembleMappingDict\fR(\fIinterp, token, dictObjPtr\fR) +.sp +int +\fBTcl_SetEnsembleMappingDict\fR(\fIinterp, token, dictObj\fR) +.sp +.VS 8.6 +int +\fBTcl_GetEnsembleParameterList\fR(\fIinterp, token, listObjPtr\fR) +.sp +int +\fBTcl_SetEnsembleParameterList\fR(\fIinterp, token, listObj\fR) +.VE 8.6 +.sp +int +\fBTcl_GetEnsembleSubcommandList\fR(\fIinterp, token, listObjPtr\fR) +.sp +int +\fBTcl_SetEnsembleSubcommandList\fR(\fIinterp, token, listObj\fR) +.sp +int +\fBTcl_GetEnsembleUnknownHandler\fR(\fIinterp, token, listObjPtr\fR) +.sp +int +\fBTcl_SetEnsembleUnknownHandler\fR(\fIinterp, token, listObj\fR) +.sp +int +\fBTcl_GetEnsembleNamespace\fR(\fIinterp, token, namespacePtrPtr\fR) +.SH ARGUMENTS +.AS Tcl_Namespace **namespacePtrPtr in/out +.AP Tcl_Interp *interp in/out +The interpreter in which the ensemble is to be created or found. Also +where error result messages are written. The functions whose names +start with \fBTcl_GetEnsemble\fR may have a NULL for the \fIinterp\fR, +but all other functions must not. +.AP "const char" *name in +The name of the ensemble command to be created. +.AP Tcl_Namespace *namespacePtr in +The namespace to which the ensemble command is to be bound, or NULL +for the current namespace. +.AP int ensFlags in +An ORed set of flag bits describing the basic configuration of the +ensemble. Currently only one bit has meaning, \fBTCL_ENSEMBLE_PREFIX\fR, +which is present when the ensemble command should also match +unambiguous prefixes of subcommands. +.AP Tcl_Obj *cmdNameObj in +A value holding the name of the ensemble command to look up. +.AP int flags in +An ORed set of flag bits controlling the behavior of +\fBTcl_FindEnsemble\fR. Currently only \fBTCL_LEAVE_ERR_MSG\fR is supported. +.AP Tcl_Command token in +A normal command token that refers to an ensemble command, or which +you wish to use for testing as an ensemble command in \fBTcl_IsEnsemble\fR. +.AP int *ensFlagsPtr out +Pointer to a variable into which to write the current ensemble flag +bits; currently only the bit \fBTCL_ENSEMBLE_PREFIX\fR is defined. +.AP Tcl_Obj *dictObj in +A dictionary value to use for the subcommand to implementation command +prefix mapping dictionary in the ensemble. May be NULL if the mapping +dictionary is to be removed. +.AP Tcl_Obj **dictObjPtr out +Pointer to a variable into which to write the current ensemble mapping +dictionary. +.AP Tcl_Obj *listObj in +A list value to use for the list of formal pre-subcommand parameters, the +defined list of subcommands in the dictionary or the unknown subcommand +handler command prefix. May be NULL if the subcommand list or unknown handler +are to be removed. +.AP Tcl_Obj **listObjPtr out +Pointer to a variable into which to write the current list of formal +pre-subcommand parameters, the defined list of subcommands or the current +unknown handler prefix. +.AP Tcl_Namespace **namespacePtrPtr out +Pointer to a variable into which to write the handle of the namespace +to which the ensemble is bound. +.BE +.SH DESCRIPTION +An ensemble is a command, bound to some namespace, which consists of a +collection of subcommands implemented by other Tcl commands. The first +argument to the ensemble command is always interpreted as a selector +that states what subcommand to execute. +.PP +Ensembles are created using \fBTcl_CreateEnsemble\fR, which takes four +arguments: the interpreter to work within, the name of the ensemble to +create, the namespace within the interpreter to bind the ensemble to, +and the default set of ensemble flags. The result of the function is +the command token for the ensemble, which may be used to further +configure the ensemble using the API described below in +\fBENSEMBLE PROPERTIES\fR. +.PP +Given the name of an ensemble command, the token for that command may +be retrieved using \fBTcl_FindEnsemble\fR. If the given command name +(in \fIcmdNameObj\fR) does not refer to an ensemble command, the +result of the function is NULL and (if the \fBTCL_LEAVE_ERR_MSG\fR bit is +set in \fIflags\fR) an error message is left in the interpreter +result. +.PP +A command token may be checked to see if it refers to an ensemble +using \fBTcl_IsEnsemble\fR. This returns 1 if the token refers to an +ensemble, or 0 otherwise. +.SS "ENSEMBLE PROPERTIES" +Every ensemble has four read-write properties and a read-only +property. The properties are: +.TP +\fBflags\fR (read-write) +. +The set of flags for the ensemble, expressed as a +bit-field. Currently, the only public flag is \fBTCL_ENSEMBLE_PREFIX\fR +which is set when unambiguous prefixes of subcommands are permitted to +be resolved to implementations as well as exact matches. The flags may +be read and written using \fBTcl_GetEnsembleFlags\fR and +\fBTcl_SetEnsembleFlags\fR respectively. The result of both of those +functions is a Tcl result code (\fBTCL_OK\fR, or \fBTCL_ERROR\fR if +the token does not refer to an ensemble). +.TP +\fBmapping dictionary\fR (read-write) +. +A dictionary containing a mapping from subcommand names to lists of +words to use as a command prefix (replacing the first two words of the +command which are the ensemble command itself and the subcommand +name), or NULL if every subcommand is to be mapped to the command with +the same unqualified name in the ensemble's bound namespace. Defaults +to NULL. May be read and written using +\fBTcl_GetEnsembleMappingDict\fR and \fBTcl_SetEnsembleMappingDict\fR +respectively. The result of both of those functions is a Tcl result +code (\fBTCL_OK\fR, or \fBTCL_ERROR\fR if the token does not refer to an +ensemble) and the dictionary obtained from +\fBTcl_GetEnsembleMappingDict\fR should always be treated as immutable +even if it is unshared. +All command names in prefixes set via \fBTcl_SetEnsembleMappingDict\fR +must be fully qualified. +.TP +\fBformal pre-subcommand parameter list\fR (read-write) +.VS 8.6 +A list of formal parameter names (the names only being used when generating +error messages) that come at invocation of the ensemble between the name of +the ensemble and the subcommand argument. NULL (the default) is equivalent to +the empty list. May be read and written using +\fBTcl_GetEnsembleParameterList\fR and \fBTcl_SetEnsembleParameterList\fR +respectively. The result of both of those functions is a Tcl result code +(\fBTCL_OK\fR, or \fBTCL_ERROR\fR if the token does not refer to an +ensemble) and the +dictionary obtained from \fBTcl_GetEnsembleParameterList\fR should always be +treated as immutable even if it is unshared. +.VE 8.6 +.TP +\fBsubcommand list\fR (read-write) +. +A list of all the subcommand names for the ensemble, or NULL if this +is to be derived from either the keys of the mapping dictionary (see +above) or (if that is also NULL) from the set of commands exported by +the bound namespace. May be read and written using +\fBTcl_GetEnsembleSubcommandList\fR and +\fBTcl_SetEnsembleSubcommandList\fR respectively. The result of both +of those functions is a Tcl result code (\fBTCL_OK\fR, or +\fBTCL_ERROR\fR if the +token does not refer to an ensemble) and the list obtained from +\fBTcl_GetEnsembleSubcommandList\fR should always be treated as +immutable even if it is unshared. +.TP +\fBunknown subcommand handler command prefix\fR (read-write) +. +A list of words to prepend on the front of any subcommand when the +subcommand is unknown to the ensemble (according to the current prefix +handling rule); see the \fBnamespace ensemble\fR command for more +details. If NULL, the default behavior \- generate a suitable error +message \- will be used when an unknown subcommand is encountered. May +be read and written using \fBTcl_GetEnsembleUnknownHandler\fR and +\fBTcl_SetEnsembleUnknownHandler\fR respectively. The result of both +functions is a Tcl result code (\fBTCL_OK\fR, or \fBTCL_ERROR\fR if +the token does +not refer to an ensemble) and the list obtained from +\fBTcl_GetEnsembleUnknownHandler\fR should always be treated as +immutable even if it is unshared. +.TP +\fBbound namespace\fR (read-only) +. +The namespace to which the ensemble is bound; when the namespace is +deleted, so too will the ensemble, and this namespace is also the +namespace whose list of exported commands is used if both the mapping +dictionary and the subcommand list properties are NULL. May be read +using \fBTcl_GetEnsembleNamespace\fR which returns a Tcl result code +(\fBTCL_OK\fR, or \fBTCL_ERROR\fR if the token does not refer to an ensemble). +.SH "SEE ALSO" +namespace(n), Tcl_DeleteCommandFromToken(3) +.SH KEYWORDS +command, ensemble diff --git a/tcl8.6/doc/Environment.3 b/tcl8.6/doc/Environment.3 new file mode 100644 index 0000000..85880b4 --- /dev/null +++ b/tcl8.6/doc/Environment.3 @@ -0,0 +1,38 @@ +'\" +'\" Copyright (c) 1997-1998 Sun Microsystems, Inc. +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH Tcl_PutEnv 3 "7.5" Tcl "Tcl Library Procedures" +.so man.macros +.BS +.SH NAME +Tcl_PutEnv \- procedures to manipulate the environment +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +int +\fBTcl_PutEnv\fR(\fIassignment\fR) +.SH ARGUMENTS +.AS "const char" *assignment +.AP "const char" *assignment in +Info about environment variable in the format +.QW \fINAME\fB=\fIvalue\fR . +The \fIassignment\fR argument is in the system encoding. +.BE +.SH DESCRIPTION +.PP +\fBTcl_PutEnv\fR sets an environment variable. The information is +passed in a single string of the form +.QW \fINAME\fB=\fIvalue\fR . +This procedure is +intended to be a stand-in for the UNIX \fBputenv\fR system call. All +Tcl-based applications using \fBputenv\fR should redefine it to +\fBTcl_PutEnv\fR so that they will interface properly to the Tcl +runtime. +.SH "SEE ALSO" +env(n) +.SH KEYWORDS +environment, variable diff --git a/tcl8.6/doc/Eval.3 b/tcl8.6/doc/Eval.3 new file mode 100644 index 0000000..191bace --- /dev/null +++ b/tcl8.6/doc/Eval.3 @@ -0,0 +1,211 @@ +'\" +'\" Copyright (c) 1989-1993 The Regents of the University of California. +'\" Copyright (c) 1994-1997 Sun Microsystems, Inc. +'\" Copyright (c) 2000 Scriptics Corporation. +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH Tcl_Eval 3 8.1 Tcl "Tcl Library Procedures" +.so man.macros +.BS +.SH NAME +Tcl_EvalObjEx, Tcl_EvalFile, Tcl_EvalObjv, Tcl_Eval, Tcl_EvalEx, Tcl_GlobalEval, Tcl_GlobalEvalObj, Tcl_VarEval, Tcl_VarEvalVA \- execute Tcl scripts +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +int +\fBTcl_EvalObjEx\fR(\fIinterp, objPtr, flags\fR) +.sp +int +\fBTcl_EvalFile\fR(\fIinterp, fileName\fR) +.sp +int +\fBTcl_EvalObjv\fR(\fIinterp, objc, objv, flags\fR) +.sp +int +\fBTcl_Eval\fR(\fIinterp, script\fR) +.sp +int +\fBTcl_EvalEx\fR(\fIinterp, script, numBytes, flags\fR) +.sp +int +\fBTcl_GlobalEval\fR(\fIinterp, script\fR) +.sp +int +\fBTcl_GlobalEvalObj\fR(\fIinterp, objPtr\fR) +.sp +int +\fBTcl_VarEval\fR(\fIinterp, part, part, ... \fB(char *) NULL\fR) +.sp +int +\fBTcl_VarEvalVA\fR(\fIinterp, argList\fR) +.SH ARGUMENTS +.AS Tcl_Interp **termPtr +.AP Tcl_Interp *interp in +Interpreter in which to execute the script. The interpreter's result is +modified to hold the result or error message from the script. +.AP Tcl_Obj *objPtr in +A Tcl value containing the script to execute. +.AP int flags in +ORed combination of flag bits that specify additional options. +\fBTCL_EVAL_GLOBAL\fR and \fBTCL_EVAL_DIRECT\fR are currently supported. +.AP "const char" *fileName in +Name of a file containing a Tcl script. +.AP int objc in +The number of values in the array pointed to by \fIobjPtr\fR; +this is also the number of words in the command. +.AP Tcl_Obj **objv in +Points to an array of pointers to values; each value holds the +value of a single word in the command to execute. +.AP int numBytes in +The number of bytes in \fIscript\fR, not including any +null terminating character. If \-1, then all characters up to the +first null byte are used. +.AP "const char" *script in +Points to first byte of script to execute (null-terminated and UTF-8). +.AP char *part in +String forming part of a Tcl script. +.AP va_list argList in +An argument list which must have been initialized using +\fBva_start\fR, and cleared using \fBva_end\fR. +.BE + +.SH DESCRIPTION +.PP +The procedures described here are invoked to execute Tcl scripts in +various forms. +\fBTcl_EvalObjEx\fR is the core procedure and is used by many of the others. +It executes the commands in the script stored in \fIobjPtr\fR +until either an error occurs or the end of the script is reached. +If this is the first time \fIobjPtr\fR has been executed, +its commands are compiled into bytecode instructions +which are then executed. The +bytecodes are saved in \fIobjPtr\fR so that the compilation step +can be skipped if the value is evaluated again in the future. +.PP +The return value from \fBTcl_EvalObjEx\fR (and all the other procedures +described here) is a Tcl completion code with +one of the values \fBTCL_OK\fR, \fBTCL_ERROR\fR, \fBTCL_RETURN\fR, +\fBTCL_BREAK\fR, or \fBTCL_CONTINUE\fR, or possibly some other +integer value originating in an extension. +In addition, a result value or error message is left in \fIinterp\fR's +result; it can be retrieved using \fBTcl_GetObjResult\fR. +.PP +\fBTcl_EvalFile\fR reads the file given by \fIfileName\fR and evaluates +its contents as a Tcl script. It returns the same information as +\fBTcl_EvalObjEx\fR. +If the file could not be read then a Tcl error is returned to describe +why the file could not be read. +The eofchar for files is +.QW \e32 +(^Z) for all platforms. If you require a +.QW ^Z +in code for string comparison, you can use +.QW \e032 +or +.QW \eu001a , +which will be safely substituted by the Tcl interpreter into +.QW ^Z . +.PP +\fBTcl_EvalObjv\fR executes a single pre-parsed command instead of a +script. The \fIobjc\fR and \fIobjv\fR arguments contain the values +of the words for the Tcl command, one word in each value in +\fIobjv\fR. \fBTcl_EvalObjv\fR evaluates the command and returns +a completion code and result just like \fBTcl_EvalObjEx\fR. +The caller of \fBTcl_EvalObjv\fR has to manage the reference count of the +elements of \fIobjv\fR, insuring that the values are valid until +\fBTcl_EvalObjv\fR returns. +.PP +\fBTcl_Eval\fR is similar to \fBTcl_EvalObjEx\fR except that the script to +be executed is supplied as a string instead of a value and no compilation +occurs. The string should be a proper UTF-8 string as converted by +\fBTcl_ExternalToUtfDString\fR or \fBTcl_ExternalToUtf\fR when it is known +to possibly contain upper ASCII characters whose possible combinations +might be a UTF-8 special code. The string is parsed and executed directly +(using \fBTcl_EvalObjv\fR) instead of compiling it and executing the +bytecodes. In situations where it is known that the script will never be +executed again, \fBTcl_Eval\fR may be faster than \fBTcl_EvalObjEx\fR. + \fBTcl_Eval\fR returns a completion code and result just like +\fBTcl_EvalObjEx\fR. Note: for backward compatibility with versions before +Tcl 8.0, \fBTcl_Eval\fR copies the value result in \fIinterp\fR to +\fIinterp->result\fR (use is deprecated) where it can be accessed directly. + This makes \fBTcl_Eval\fR somewhat slower than \fBTcl_EvalEx\fR, which +does not do the copy. +.PP +\fBTcl_EvalEx\fR is an extended version of \fBTcl_Eval\fR that takes +additional arguments \fInumBytes\fR and \fIflags\fR. For the +efficiency reason given above, \fBTcl_EvalEx\fR is generally preferred +over \fBTcl_Eval\fR. +.PP +\fBTcl_GlobalEval\fR and \fBTcl_GlobalEvalObj\fR are older procedures +that are now deprecated. They are similar to \fBTcl_EvalEx\fR and +\fBTcl_EvalObjEx\fR except that the script is evaluated in the global +namespace and its variable context consists of global variables only +(it ignores any Tcl procedures that are active). These functions are +equivalent to using the \fBTCL_EVAL_GLOBAL\fR flag (see below). +.PP +\fBTcl_VarEval\fR takes any number of string arguments +of any length, concatenates them into a single string, +then calls \fBTcl_Eval\fR to execute that string as a Tcl command. +It returns the result of the command and also modifies +\fIinterp->result\fR in the same way as \fBTcl_Eval\fR. +The last argument to \fBTcl_VarEval\fR must be NULL to indicate the end +of arguments. \fBTcl_VarEval\fR is now deprecated. +.PP +\fBTcl_VarEvalVA\fR is the same as \fBTcl_VarEval\fR except that +instead of taking a variable number of arguments it takes an argument +list. Like \fBTcl_VarEval\fR, \fBTcl_VarEvalVA\fR is deprecated. + +.SH "FLAG BITS" +.PP +Any ORed combination of the following values may be used for the +\fIflags\fR argument to procedures such as \fBTcl_EvalObjEx\fR: +.TP 23 +\fBTCL_EVAL_DIRECT\fR +. +This flag is only used by \fBTcl_EvalObjEx\fR; it is ignored by +other procedures. If this flag bit is set, the script is not +compiled to bytecodes; instead it is executed directly +as is done by \fBTcl_EvalEx\fR. The +\fBTCL_EVAL_DIRECT\fR flag is useful in situations where the +contents of a value are going to change immediately, so the +bytecodes will not be reused in a future execution. In this case, +it is faster to execute the script directly. +.TP 23 +\fBTCL_EVAL_GLOBAL\fR +. +If this flag is set, the script is processed at global level. This +means that it is evaluated in the global namespace and its variable +context consists of global variables only (it ignores any Tcl +procedures that are active). + +.SH "MISCELLANEOUS DETAILS" +.PP +During the processing of a Tcl command it is legal to make nested +calls to evaluate other commands (this is how procedures and +some control structures are implemented). +If a code other than \fBTCL_OK\fR is returned +from a nested \fBTcl_EvalObjEx\fR invocation, +then the caller should normally return immediately, +passing that same return code back to its caller, +and so on until the top-level application is reached. +A few commands, like \fBfor\fR, will check for certain +return codes, like \fBTCL_BREAK\fR and \fBTCL_CONTINUE\fR, and process them +specially without returning. +.PP +\fBTcl_EvalObjEx\fR keeps track of how many nested \fBTcl_EvalObjEx\fR +invocations are in progress for \fIinterp\fR. +If a code of \fBTCL_RETURN\fR, \fBTCL_BREAK\fR, or \fBTCL_CONTINUE\fR is +about to be returned from the topmost \fBTcl_EvalObjEx\fR +invocation for \fIinterp\fR, +it converts the return code to \fBTCL_ERROR\fR +and sets \fIinterp\fR's result to an error message indicating that +the \fBreturn\fR, \fBbreak\fR, or \fBcontinue\fR command was +invoked in an inappropriate place. +This means that top-level applications should never see a return code +from \fBTcl_EvalObjEx\fR other than \fBTCL_OK\fR or \fBTCL_ERROR\fR. + +.SH KEYWORDS +execute, file, global, result, script, value diff --git a/tcl8.6/doc/Exit.3 b/tcl8.6/doc/Exit.3 new file mode 100644 index 0000000..9a04db3 --- /dev/null +++ b/tcl8.6/doc/Exit.3 @@ -0,0 +1,140 @@ +'\" +'\" Copyright (c) 1995-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. +'\" +.TH Tcl_Exit 3 8.5 Tcl "Tcl Library Procedures" +.so man.macros +.BS +.SH NAME +Tcl_Exit, Tcl_Finalize, Tcl_CreateExitHandler, Tcl_DeleteExitHandler, Tcl_ExitThread, Tcl_FinalizeThread, Tcl_CreateThreadExitHandler, Tcl_DeleteThreadExitHandler, Tcl_SetExitProc \- end the application or thread (and invoke exit handlers) +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +\fBTcl_Exit\fR(\fIstatus\fR) +.sp +\fBTcl_Finalize\fR() +.sp +\fBTcl_CreateExitHandler\fR(\fIproc, clientData\fR) +.sp +\fBTcl_DeleteExitHandler\fR(\fIproc, clientData\fR) +.sp +\fBTcl_ExitThread\fR(\fIstatus\fR) +.sp +\fBTcl_FinalizeThread\fR() +.sp +\fBTcl_CreateThreadExitHandler\fR(\fIproc, clientData\fR) +.sp +\fBTcl_DeleteThreadExitHandler\fR(\fIproc, clientData\fR) +.sp +Tcl_ExitProc * +\fBTcl_SetExitProc\fR(\fIproc\fR) +.SH ARGUMENTS +.AS Tcl_ExitProc clientData +.AP int status in +Provides information about why the application or thread exited. +Exact meaning may +be platform-specific. 0 usually means a normal exit, any nonzero value +usually means that an error occurred. +.AP Tcl_ExitProc *proc in +Procedure to invoke before exiting application, or (for +\fBTcl_SetExitProc\fR) NULL to uninstall the current application exit +procedure. +.AP ClientData clientData in +Arbitrary one-word value to pass to \fIproc\fR. +.BE + +.SH DESCRIPTION +.PP +The procedures described here provide a graceful mechanism to end the +execution of a \fBTcl\fR application. Exit handlers are invoked to cleanup the +application's state before ending the execution of \fBTcl\fR code. +.PP +Invoke \fBTcl_Exit\fR to end a \fBTcl\fR application and to exit from this +process. This procedure is invoked by the \fBexit\fR command, and can be +invoked anyplace else to terminate the application. +No-one should ever invoke the \fBexit\fR system procedure directly; always +invoke \fBTcl_Exit\fR instead, so that it can invoke exit handlers. +Note that if other code invokes \fBexit\fR system procedure directly, or +otherwise causes the application to terminate without calling +\fBTcl_Exit\fR, the exit handlers will not be run. +\fBTcl_Exit\fR internally invokes the \fBexit\fR system call, thus it never +returns control to its caller. +If an application exit handler has been installed (see +\fBTcl_SetExitProc\fR), that handler is invoked with an argument +consisting of the exit status (cast to ClientData); the application +exit handler should not return control to Tcl. +.PP +\fBTcl_Finalize\fR is similar to \fBTcl_Exit\fR except that it does not +exit from the current process. +It is useful for cleaning up when a process is finished using \fBTcl\fR but +wishes to continue executing, and when \fBTcl\fR is used in a dynamically +loaded extension that is about to be unloaded. +Your code should always invoke \fBTcl_Finalize\fR when \fBTcl\fR is being +unloaded, to ensure proper cleanup. \fBTcl_Finalize\fR can be safely called +more than once. +.PP +\fBTcl_ExitThread\fR is used to terminate the current thread and invoke +per-thread exit handlers. This finalization is done by +\fBTcl_FinalizeThread\fR, which you can call if you just want to clean +up per-thread state and invoke the thread exit handlers. +\fBTcl_Finalize\fR calls \fBTcl_FinalizeThread\fR for the current +thread automatically. +.PP +\fBTcl_CreateExitHandler\fR arranges for \fIproc\fR to be invoked +by \fBTcl_Finalize\fR and \fBTcl_Exit\fR. +\fBTcl_CreateThreadExitHandler\fR arranges for \fIproc\fR to be invoked +by \fBTcl_FinalizeThread\fR and \fBTcl_ExitThread\fR. +This provides a hook for cleanup operations such as flushing buffers +and freeing global memory. +\fIProc\fR should match the type \fBTcl_ExitProc\fR: +.PP +.CS +typedef void \fBTcl_ExitProc\fR( + ClientData \fIclientData\fR); +.CE +.PP +The \fIclientData\fR parameter to \fIproc\fR is a +copy of the \fIclientData\fR argument given to +\fBTcl_CreateExitHandler\fR or \fBTcl_CreateThreadExitHandler\fR when +the callback +was created. Typically, \fIclientData\fR points to a data +structure containing application-specific information about +what to do in \fIproc\fR. +.PP +\fBTcl_DeleteExitHandler\fR and \fBTcl_DeleteThreadExitHandler\fR may be +called to delete a +previously-created exit handler. It removes the handler +indicated by \fIproc\fR and \fIclientData\fR so that no call +to \fIproc\fR will be made. If no such handler exists then +\fBTcl_DeleteExitHandler\fR or \fBTcl_DeleteThreadExitHandler\fR does nothing. +.PP +\fBTcl_Finalize\fR and \fBTcl_Exit\fR execute all registered exit handlers, +in reverse order from the order in which they were registered. +This matches the natural order in which extensions are loaded and unloaded; +if extension \fBA\fR loads extension \fBB\fR, it usually +unloads \fBB\fR before it itself is unloaded. +If extension \fBA\fR registers its exit handlers before loading extension +\fBB\fR, this ensures that any exit handlers for \fBB\fR will be executed +before the exit handlers for \fBA\fR. +.PP +\fBTcl_Finalize\fR and \fBTcl_Exit\fR call \fBTcl_FinalizeThread\fR +and the thread exit handlers \fIafter\fR +the process-wide exit handlers. This is because thread finalization shuts +down the I/O channel system, so any attempt at I/O by the global exit +handlers will vanish into the bitbucket. +.PP +\fBTcl_SetExitProc\fR installs an application exit handler, returning +the previously-installed application exit handler or NULL if no +application handler was installed. If an application exit handler is +installed, that exit handler takes over complete responsibility for +finalization of Tcl's subsystems via \fBTcl_Finalize\fR at an +appropriate time. The argument passed to \fIproc\fR when it is +invoked will be the exit status code (as passed to \fBTcl_Exit\fR) +cast to a ClientData value. +.SH "SEE ALSO" +exit(n) +.SH KEYWORDS +abort, callback, cleanup, dynamic loading, end application, exit, unloading, thread diff --git a/tcl8.6/doc/ExprLong.3 b/tcl8.6/doc/ExprLong.3 new file mode 100644 index 0000000..0d369ce --- /dev/null +++ b/tcl8.6/doc/ExprLong.3 @@ -0,0 +1,106 @@ +'\" +'\" Copyright (c) 1989-1993 The Regents of the University of California. +'\" Copyright (c) 1994-1997 Sun Microsystems, Inc. +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH Tcl_ExprLong 3 7.0 Tcl "Tcl Library Procedures" +.so man.macros +.BS +.SH NAME +Tcl_ExprLong, Tcl_ExprDouble, Tcl_ExprBoolean, Tcl_ExprString \- evaluate an expression +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +int +\fBTcl_ExprLong\fR(\fIinterp, expr, longPtr\fR) +.sp +int +\fBTcl_ExprDouble\fR(\fIinterp, expr, doublePtr\fR) +.sp +int +\fBTcl_ExprBoolean\fR(\fIinterp, expr, booleanPtr\fR) +.sp +int +\fBTcl_ExprString\fR(\fIinterp, expr\fR) +.SH ARGUMENTS +.AS Tcl_Interp *booleanPtr out +.AP Tcl_Interp *interp in +Interpreter in whose context to evaluate \fIexpr\fR. +.AP "const char" *expr in +Expression to be evaluated. +.AP long *longPtr out +Pointer to location in which to store the integer value of the +expression. +.AP int *doublePtr out +Pointer to location in which to store the floating-point value of the +expression. +.AP int *booleanPtr out +Pointer to location in which to store the 0/1 boolean value of the +expression. +.BE + +.SH DESCRIPTION +.PP +These four procedures all evaluate the expression +given by the \fIexpr\fR argument +and return the result in one of four different forms. +The expression can have any of the forms accepted by the \fBexpr\fR command. +Note that these procedures have been largely replaced by the +value-based procedures \fBTcl_ExprLongObj\fR, \fBTcl_ExprDoubleObj\fR, +\fBTcl_ExprBooleanObj\fR, and \fBTcl_ExprObj\fR. +Those value-based procedures evaluate an expression held in a Tcl value +instead of a string. +The value argument can retain an internal representation +that is more efficient to execute. +.PP +The \fIinterp\fR argument refers to an interpreter used to +evaluate the expression (e.g. for variables and nested Tcl +commands) and to return error information. +.PP +For all of these procedures the return value is a standard +Tcl result: \fBTCL_OK\fR means the expression was successfully +evaluated, and \fBTCL_ERROR\fR means that an error occurred while +evaluating the expression. +If \fBTCL_ERROR\fR is returned then +the interpreter's result will hold a message describing the error. +If an error occurs while executing a Tcl command embedded in +the expression then that error will be returned. +.PP +If the expression is successfully evaluated, then its value is +returned in one of four forms, depending on which procedure +is invoked. +\fBTcl_ExprLong\fR stores an integer value at \fI*longPtr\fR. +If the expression's actual value is a floating-point number, +then it is truncated to an integer. +If the expression's actual value is a non-numeric string then +an error is returned. +.PP +\fBTcl_ExprDouble\fR stores a floating-point value at \fI*doublePtr\fR. +If the expression's actual value is an integer, it is converted to +floating-point. +If the expression's actual value is a non-numeric string then +an error is returned. +.PP +\fBTcl_ExprBoolean\fR stores a 0/1 integer value at \fI*booleanPtr\fR. +If the expression's actual value is an integer or floating-point +number, then they store 0 at \fI*booleanPtr\fR if +the value was zero and 1 otherwise. +If the expression's actual value is a non-numeric string then +it must be one of the values accepted by \fBTcl_GetBoolean\fR +such as +.QW yes +or +.QW no , +or else an error occurs. +.PP +\fBTcl_ExprString\fR returns the value of the expression as a +string stored in the interpreter's result. + +.SH "SEE ALSO" +Tcl_ExprLongObj, Tcl_ExprDoubleObj, Tcl_ExprBooleanObj, Tcl_ExprObj + +.SH KEYWORDS +boolean, double, evaluate, expression, integer, value, string diff --git a/tcl8.6/doc/ExprLongObj.3 b/tcl8.6/doc/ExprLongObj.3 new file mode 100644 index 0000000..35edb5f --- /dev/null +++ b/tcl8.6/doc/ExprLongObj.3 @@ -0,0 +1,106 @@ +'\" +'\" Copyright (c) 1996-1997 Sun Microsystems, Inc. +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH Tcl_ExprLongObj 3 8.0 Tcl "Tcl Library Procedures" +.so man.macros +.BS +.SH NAME +Tcl_ExprLongObj, Tcl_ExprDoubleObj, Tcl_ExprBooleanObj, Tcl_ExprObj \- evaluate an expression +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +int +\fBTcl_ExprLongObj\fR(\fIinterp, objPtr, longPtr\fR) +.sp +int +\fBTcl_ExprDoubleObj\fR(\fIinterp, objPtr, doublePtr\fR) +.sp +int +\fBTcl_ExprBooleanObj\fR(\fIinterp, objPtr, booleanPtr\fR) +.sp +int +\fBTcl_ExprObj\fR(\fIinterp, objPtr, resultPtrPtr\fR) +.SH ARGUMENTS +.AS Tcl_Interp **resultPtrPtr out +.AP Tcl_Interp *interp in +Interpreter in whose context to evaluate \fIobjPtr\fR. +.AP Tcl_Obj *objPtr in +Pointer to a value containing the expression to evaluate. +.AP long *longPtr out +Pointer to location in which to store the integer value of the +expression. +.AP int *doublePtr out +Pointer to location in which to store the floating-point value of the +expression. +.AP int *booleanPtr out +Pointer to location in which to store the 0/1 boolean value of the +expression. +.AP Tcl_Obj **resultPtrPtr out +Pointer to location in which to store a pointer to the value +that is the result of the expression. +.BE + +.SH DESCRIPTION +.PP +These four procedures all evaluate an expression, returning +the result in one of four different forms. +The expression is given by the \fIobjPtr\fR argument, and it +can have any of the forms accepted by the \fBexpr\fR command. +.PP +The \fIinterp\fR argument refers to an interpreter used to +evaluate the expression (e.g. for variables and nested Tcl +commands) and to return error information. +.PP +For all of these procedures the return value is a standard +Tcl result: \fBTCL_OK\fR means the expression was successfully +evaluated, and \fBTCL_ERROR\fR means that an error occurred while +evaluating the expression. +If \fBTCL_ERROR\fR is returned, +then a message describing the error +can be retrieved using \fBTcl_GetObjResult\fR. +If an error occurs while executing a Tcl command embedded in +the expression then that error will be returned. +.PP +If the expression is successfully evaluated, then its value is +returned in one of four forms, depending on which procedure +is invoked. +\fBTcl_ExprLongObj\fR stores an integer value at \fI*longPtr\fR. +If the expression's actual value is a floating-point number, +then it is truncated to an integer. +If the expression's actual value is a non-numeric string then +an error is returned. +.PP +\fBTcl_ExprDoubleObj\fR stores a floating-point value at \fI*doublePtr\fR. +If the expression's actual value is an integer, it is converted to +floating-point. +If the expression's actual value is a non-numeric string then +an error is returned. +.PP +\fBTcl_ExprBooleanObj\fR stores a 0/1 integer value at \fI*booleanPtr\fR. +If the expression's actual value is an integer or floating-point +number, then they store 0 at \fI*booleanPtr\fR if +the value was zero and 1 otherwise. +If the expression's actual value is a non-numeric string then +it must be one of the values accepted by \fBTcl_GetBoolean\fR +such as +.QW yes +or +.QW no , +or else an error occurs. +.PP +If \fBTcl_ExprObj\fR successfully evaluates the expression, +it stores a pointer to the Tcl value +containing the expression's value at \fI*resultPtrPtr\fR. +In this case, the caller is responsible for calling +\fBTcl_DecrRefCount\fR to decrement the value's reference count +when it is finished with the value. + +.SH "SEE ALSO" +Tcl_ExprLong, Tcl_ExprDouble, Tcl_ExprBoolean, Tcl_ExprString, Tcl_GetObjResult + +.SH KEYWORDS +boolean, double, evaluate, expression, integer, value, string diff --git a/tcl8.6/doc/FileSystem.3 b/tcl8.6/doc/FileSystem.3 new file mode 100644 index 0000000..28ee8f0 --- /dev/null +++ b/tcl8.6/doc/FileSystem.3 @@ -0,0 +1,1644 @@ +'\" +'\" Copyright (c) 2001 Vincent Darley +'\" Copyright (c) 2008-2010 Donal K. Fellows +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH Filesystem 3 8.4 Tcl "Tcl Library Procedures" +.so man.macros +.BS +.SH NAME +Tcl_FSRegister, Tcl_FSUnregister, Tcl_FSData, Tcl_FSMountsChanged, Tcl_FSGetFileSystemForPath, Tcl_FSGetPathType, Tcl_FSCopyFile, Tcl_FSCopyDirectory, Tcl_FSCreateDirectory, Tcl_FSDeleteFile, Tcl_FSRemoveDirectory, Tcl_FSRenameFile, Tcl_FSListVolumes, Tcl_FSEvalFile, Tcl_FSEvalFileEx, Tcl_FSLoadFile, Tcl_FSUnloadFile, Tcl_FSMatchInDirectory, Tcl_FSLink, Tcl_FSLstat, Tcl_FSUtime, Tcl_FSFileAttrsGet, Tcl_FSFileAttrsSet, Tcl_FSFileAttrStrings, Tcl_FSStat, Tcl_FSAccess, Tcl_FSOpenFileChannel, Tcl_FSGetCwd, Tcl_FSChdir, Tcl_FSPathSeparator, Tcl_FSJoinPath, Tcl_FSSplitPath, Tcl_FSEqualPaths, Tcl_FSGetNormalizedPath, Tcl_FSJoinToPath, Tcl_FSConvertToPathType, Tcl_FSGetInternalRep, Tcl_FSGetTranslatedPath, Tcl_FSGetTranslatedStringPath, Tcl_FSNewNativePath, Tcl_FSGetNativePath, Tcl_FSFileSystemInfo, Tcl_GetAccessTimeFromStat, Tcl_GetBlockSizeFromStat, Tcl_GetBlocksFromStat, Tcl_GetChangeTimeFromStat, Tcl_GetDeviceTypeFromStat, Tcl_GetFSDeviceFromStat, Tcl_GetFSInodeFromStat, Tcl_GetGroupIdFromStat, Tcl_GetLinkCountFromStat, Tcl_GetModeFromStat, Tcl_GetModificationTimeFromStat, Tcl_GetSizeFromStat, Tcl_GetUserIdFromStat, Tcl_AllocStatBuf \- procedures to interact with any filesystem +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +int +\fBTcl_FSRegister\fR(\fIclientData, fsPtr\fR) +.sp +int +\fBTcl_FSUnregister\fR(\fIfsPtr\fR) +.sp +ClientData +\fBTcl_FSData\fR(\fIfsPtr\fR) +.sp +void +\fBTcl_FSMountsChanged\fR(\fIfsPtr\fR) +.sp +const Tcl_Filesystem * +\fBTcl_FSGetFileSystemForPath\fR(\fIpathPtr\fR) +.sp +Tcl_PathType +\fBTcl_FSGetPathType\fR(\fIpathPtr\fR) +.sp +int +\fBTcl_FSCopyFile\fR(\fIsrcPathPtr, destPathPtr\fR) +.sp +int +\fBTcl_FSCopyDirectory\fR(\fIsrcPathPtr, destPathPtr, errorPtr\fR) +.sp +int +\fBTcl_FSCreateDirectory\fR(\fIpathPtr\fR) +.sp +int +\fBTcl_FSDeleteFile\fR(\fIpathPtr\fR) +.sp +int +\fBTcl_FSRemoveDirectory\fR(\fIpathPtr, int recursive, errorPtr\fR) +.sp +int +\fBTcl_FSRenameFile\fR(\fIsrcPathPtr, destPathPtr\fR) +.sp +Tcl_Obj * +\fBTcl_FSListVolumes\fR(\fIvoid\fR) +.sp +int +\fBTcl_FSEvalFileEx\fR(\fIinterp, pathPtr, encodingName\fR) +.sp +int +\fBTcl_FSEvalFile\fR(\fIinterp, pathPtr\fR) +.sp +int +\fBTcl_FSLoadFile\fR(\fIinterp, pathPtr, sym1, sym2, proc1Ptr, proc2Ptr, + loadHandlePtr, unloadProcPtr\fR) +.sp +.VS 8.6 +int +\fBTcl_FSUnloadFile\fR(\fIinterp, loadHandle\fR) +.VE 8.6 +.sp +int +\fBTcl_FSMatchInDirectory\fR(\fIinterp, resultPtr, pathPtr, pattern, types\fR) +.sp +Tcl_Obj * +\fBTcl_FSLink\fR(\fIlinkNamePtr, toPtr, linkAction\fR) +.sp +int +\fBTcl_FSLstat\fR(\fIpathPtr, statPtr\fR) +.sp +int +\fBTcl_FSUtime\fR(\fIpathPtr, tval\fR) +.sp +int +\fBTcl_FSFileAttrsGet\fR(\fIinterp, int index, pathPtr, objPtrRef\fR) +.sp +int +\fBTcl_FSFileAttrsSet\fR(\fIinterp, int index, pathPtr, Tcl_Obj *objPtr\fR) +.sp +const char *const * +\fBTcl_FSFileAttrStrings\fR(\fIpathPtr, objPtrRef\fR) +.sp +int +\fBTcl_FSStat\fR(\fIpathPtr, statPtr\fR) +.sp +int +\fBTcl_FSAccess\fR(\fIpathPtr, mode\fR) +.sp +Tcl_Channel +\fBTcl_FSOpenFileChannel\fR(\fIinterp, pathPtr, modeString, permissions\fR) +.sp +Tcl_Obj * +\fBTcl_FSGetCwd\fR(\fIinterp\fR) +.sp +int +\fBTcl_FSChdir\fR(\fIpathPtr\fR) +.sp +Tcl_Obj * +\fBTcl_FSPathSeparator\fR(\fIpathPtr\fR) +.sp +Tcl_Obj * +\fBTcl_FSJoinPath\fR(\fIlistObj, elements\fR) +.sp +Tcl_Obj * +\fBTcl_FSSplitPath\fR(\fIpathPtr, lenPtr\fR) +.sp +int +\fBTcl_FSEqualPaths\fR(\fIfirstPtr, secondPtr\fR) +.sp +Tcl_Obj * +\fBTcl_FSGetNormalizedPath\fR(\fIinterp, pathPtr\fR) +.sp +Tcl_Obj * +\fBTcl_FSJoinToPath\fR(\fIbasePtr, objc, objv\fR) +.sp +int +\fBTcl_FSConvertToPathType\fR(\fIinterp, pathPtr\fR) +.sp +ClientData +\fBTcl_FSGetInternalRep\fR(\fIpathPtr, fsPtr\fR) +.sp +Tcl_Obj * +\fBTcl_FSGetTranslatedPath\fR(\fIinterp, pathPtr\fR) +.sp +const char * +\fBTcl_FSGetTranslatedStringPath\fR(\fIinterp, pathPtr\fR) +.sp +Tcl_Obj * +\fBTcl_FSNewNativePath\fR(\fIfsPtr, clientData\fR) +.sp +const void * +\fBTcl_FSGetNativePath\fR(\fIpathPtr\fR) +.sp +Tcl_Obj * +\fBTcl_FSFileSystemInfo\fR(\fIpathPtr\fR) +.sp +Tcl_StatBuf * +\fBTcl_AllocStatBuf\fR() +.sp +.VS 8.6 +Tcl_WideInt +\fBTcl_GetAccessTimeFromStat\fR(\fIstatPtr\fR) +.sp +unsigned +\fBTcl_GetBlockSizeFromStat\fR(\fIstatPtr\fR) +.sp +Tcl_WideUInt +\fBTcl_GetBlocksFromStat\fR(\fIstatPtr\fR) +.sp +Tcl_WideInt +\fBTcl_GetChangeTimeFromStat\fR(\fIstatPtr\fR) +.sp +int +\fBTcl_GetDeviceTypeFromStat\fR(\fIstatPtr\fR) +.sp +unsigned +\fBTcl_GetFSDeviceFromStat\fR(\fIstatPtr\fR) +.sp +unsigned +\fBTcl_GetFSInodeFromStat\fR(\fIstatPtr\fR) +.sp +int +\fBTcl_GetGroupIdFromStat\fR(\fIstatPtr\fR) +.sp +int +\fBTcl_GetLinkCountFromStat\fR(\fIstatPtr\fR) +.sp +unsigned +\fBTcl_GetModeFromStat\fR(\fIstatPtr\fR) +.sp +Tcl_WideInt +\fBTcl_GetModificationTimeFromStat\fR(\fIstatPtr\fR) +.sp +Tcl_WideUInt +\fBTcl_GetSizeFromStat\fR(\fIstatPtr\fR) +.sp +int +\fBTcl_GetUserIdFromStat\fR(\fIstatPtr\fR) +.VE 8.6 +.SH ARGUMENTS +.AS Tcl_GlobTypeData **srcPathPtr out +.AP "const Tcl_Filesystem" *fsPtr in +Points to a structure containing the addresses of procedures that +can be called to perform the various filesystem operations. +.AP Tcl_Obj *pathPtr in +The path represented by this value is used for the operation in +question. If the value does not already have an internal \fBpath\fR +representation, it will be converted to have one. +.AP Tcl_Obj *srcPathPtr in +As for \fIpathPtr\fR, but used for the source file for a copy or +rename operation. +.AP Tcl_Obj *destPathPtr in +As for \fIpathPtr\fR, but used for the destination filename for a copy or +rename operation. +.AP "const char" *encodingName in +The encoding of the data stored in the +file identified by \fIpathPtr\fR and to be evaluated. +.AP "const char" *pattern in +Only files or directories matching this pattern will be returned. +.AP Tcl_GlobTypeData *types in +Only files or directories matching the type descriptions contained in +this structure will be returned. This parameter may be NULL. +.AP Tcl_Interp *interp in +Interpreter to use either for results, evaluation, or reporting error +messages. +.AP ClientData clientData in +The native description of the path value to create. +.AP Tcl_Obj *firstPtr in +The first of two path values to compare. The value may be converted +to \fBpath\fR type. +.AP Tcl_Obj *secondPtr in +The second of two path values to compare. The value may be converted +to \fBpath\fR type. +.AP Tcl_Obj *listObj in +The list of path elements to operate on with a \fBjoin\fR operation. +.AP int elements in +If non-negative, the number of elements in the \fIlistObj\fR which should +be joined together. If negative, then all elements are joined. +.AP Tcl_Obj **errorPtr out +In the case of an error, filled with a value containing the name of +the file which caused an error in the various copy/rename operations. +.AP Tcl_Obj **objPtrRef out +Filled with a value containing the result of the operation. +.AP Tcl_Obj *resultPtr out +Pre-allocated value in which to store (using +\fBTcl_ListObjAppendElement\fR) the list of +files or directories which are successfully matched. +.AP int mode in +Mask consisting of one or more of R_OK, W_OK, X_OK and F_OK. R_OK, +W_OK and X_OK request checking whether the file exists and has read, +write and execute permissions, respectively. F_OK just requests +checking for the existence of the file. +.AP Tcl_StatBuf *statPtr out +The structure that contains the result of a stat or lstat operation. +.AP "const char" *sym1 in +Name of a procedure to look up in the file's symbol table +.AP "const char" *sym2 in +Name of a procedure to look up in the file's symbol table +.AP Tcl_PackageInitProc **proc1Ptr out +Filled with the init function for this code. +.AP Tcl_PackageInitProc **proc2Ptr out +Filled with the safe-init function for this code. +.AP ClientData *clientDataPtr out +Filled with the clientData value to pass to this code's unload +function when it is called. +.AP Tcl_LoadHandle *loadHandlePtr out +Filled with an abstract token representing the loaded file. +.AP Tcl_FSUnloadFileProc **unloadProcPtr out +Filled with the function to use to unload this piece of code. +.AP Tcl_LoadHandle loadHandle in +Handle to the loaded library to be unloaded. +.AP utimbuf *tval in +The access and modification times in this structure are read and +used to set those values for a given file. +.AP "const char" *modeString in +Specifies how the file is to be accessed. May have any of the values +allowed for the \fImode\fR argument to the Tcl \fBopen\fR command. +.AP int permissions in +POSIX-style permission flags such as 0644. If a new file is created, these +permissions will be set on the created file. +.AP int *lenPtr out +If non-NULL, filled with the number of elements in the split path. +.AP Tcl_Obj *basePtr in +The base path on to which to join the given elements. May be NULL. +.AP int objc in +The number of elements in \fIobjv\fR. +.AP "Tcl_Obj *const" objv[] in +The elements to join to the given base path. +.AP Tcl_Obj *linkNamePtr in +The name of the link to be created or read. +.AP Tcl_Obj *toPtr in +What the link called \fIlinkNamePtr\fR should be linked to, or NULL if +the symbolic link specified by \fIlinkNamePtr\fR is to be read. +.AP int linkAction in +OR-ed combination of flags indicating what kind of link should be +created (will be ignored if \fItoPtr\fR is NULL). Valid bits to set +are \fBTCL_CREATE_SYMBOLIC_LINK\fR and \fBTCL_CREATE_HARD_LINK\fR. +When both flags are set and the underlying filesystem can do either, +symbolic links are preferred. +.BE +.SH DESCRIPTION +.PP +There are several reasons for calling the \fBTcl_FS\fR API functions +(e.g.\ \fBTcl_FSAccess\fR and \fBTcl_FSStat\fR) +rather than calling system level functions like \fBaccess\fR and +\fBstat\fR directly. First, they will work cross-platform, so an +extension which calls them should work unmodified on Unix and +Windows. Second, the Windows implementation of some of these functions +fixes some bugs in the system level calls. Third, these function calls +deal with any +.QW "Utf to platform-native" +path conversions which may be +required (and may cache the results of such conversions for greater +efficiency on subsequent calls). Fourth, and perhaps most importantly, +all of these functions are +.QW "virtual filesystem aware" . +Any virtual filesystem (VFS for short) which has been registered (through +\fBTcl_FSRegister\fR) may reroute file access to alternative +media or access methods. This means that all of these functions (and +therefore the corresponding \fBfile\fR, \fBglob\fR, \fBpwd\fR, \fBcd\fR, +\fBopen\fR, etc.\ Tcl commands) may be operate on +.QW files +which are not +native files in the native filesystem. This also means that any Tcl +extension which accesses the filesystem (FS for short) through this API is +automatically +.QW "virtual filesystem aware" . +Of course, if an extension +accesses the native filesystem directly (through platform-specific +APIs, for example), then Tcl cannot intercept such calls. +.PP +If appropriate VFSes have been registered, the +.QW files +may, to give two +examples, be remote (e.g.\ situated on a remote ftp server) or archived +(e.g.\ lying inside a .zip archive). Such registered filesystems provide +a lookup table of functions to implement all or some of the functionality +listed here. Finally, the \fBTcl_FSStat\fR and \fBTcl_FSLstat\fR calls +abstract away from what the +.QW "struct stat" +buffer is actually +declared to be, allowing the same code to be used both on systems with +and systems without support for files larger than 2GB in size. +.PP +The \fBTcl_FS\fR API is \fBTcl_Obj\fR-ified and may cache internal +representations and other path-related strings (e.g.\ the current working +directory). One side-effect of this is that one must not pass in values +with a reference count of zero to any of these functions. If such calls were +handled, they might result +in memory leaks (under some circumstances, the filesystem code may wish +to retain a reference to the passed in value, and so one must not assume +that after any of these calls return, the value still has a reference count of +zero - it may have been incremented) or in a direct segmentation fault +(or other memory access error) +due to the value being freed part way through the complex value +manipulation required to ensure that the path is fully normalized and +absolute for filesystem determination. The practical lesson to learn +from this is that +.PP +.CS +Tcl_Obj *path = Tcl_NewStringObj(...); +Tcl_FS\fIWhatever\fR(path); +Tcl_DecrRefCount(path); +.CE +.PP +is wrong, and may cause memory errors. The \fIpath\fR must have its +reference count incremented before passing it in, or +decrementing it. For this reason, values with a reference count of zero are +considered not to be valid filesystem paths and calling any Tcl_FS API +function with such a value will result in no action being taken. +.SS "FS API FUNCTIONS" +\fBTcl_FSCopyFile\fR attempts to copy the file given by \fIsrcPathPtr\fR to the +path name given by \fIdestPathPtr\fR. If the two paths given lie in the same +filesystem (according to \fBTcl_FSGetFileSystemForPath\fR) then that +filesystem's +.QW "copy file" +function is called (if it is non-NULL). +Otherwise the function returns -1 and sets the \fBerrno\fR global C +variable to the +.QW EXDEV +POSIX error code (which signifies a +.QW "cross-domain link" ). +.PP +\fBTcl_FSCopyDirectory\fR attempts to copy the directory given by \fIsrcPathPtr\fR to the +path name given by \fIdestPathPtr\fR. If the two paths given lie in the same +filesystem (according to \fBTcl_FSGetFileSystemForPath\fR) then that +filesystem's +.QW "copy file" +function is called (if it is non-NULL). +Otherwise the function returns -1 and sets the \fBerrno\fR global C +variable to the +.QW EXDEV +POSIX error code (which signifies a +.QW "cross-domain link" ). +.PP +\fBTcl_FSCreateDirectory\fR attempts to create the directory given by +\fIpathPtr\fR by calling the owning filesystem's +.QW "create directory" +function. +.PP +\fBTcl_FSDeleteFile\fR attempts to delete the file given by +\fIpathPtr\fR by calling the owning filesystem's +.QW "delete file" +function. +.PP +\fBTcl_FSRemoveDirectory\fR attempts to remove the directory given by +\fIpathPtr\fR by calling the owning filesystem's +.QW "remove directory" +function. +.PP +\fBTcl_FSRenameFile\fR attempts to rename the file or directory given by +\fIsrcPathPtr\fR to the path name given by \fIdestPathPtr\fR. If the two paths +given lie in the same filesystem (according to +\fBTcl_FSGetFileSystemForPath\fR) then that filesystem's +.QW "rename file" +function is called (if it is non-NULL). Otherwise the function returns -1 +and sets the \fBerrno\fR global C variable to the +.QW EXDEV +POSIX error code (which signifies a +.QW "cross-domain link" ). +.PP +\fBTcl_FSListVolumes\fR calls each filesystem which has a non-NULL +.QW "list volumes" +function and asks them to return their list of root volumes. It +accumulates the return values in a list which is returned to the +caller (with a reference count of 0). +.PP +\fBTcl_FSEvalFileEx\fR reads the file given by \fIpathPtr\fR using +the encoding identified by \fIencodingName\fR and evaluates +its contents as a Tcl script. It returns the same information as +\fBTcl_EvalObjEx\fR. +If \fIencodingName\fR is NULL, the system encoding is used for +reading the file contents. +If the file could not be read then a Tcl error is returned to describe +why the file could not be read. +The eofchar for files is +.QW \e32 +(^Z) for all platforms. +If you require a +.QW ^Z +in code for string comparison, you can use +.QW \e032 +or +.QW \eu001a , +which will be safely substituted by the Tcl interpreter into +.QW ^Z . +\fBTcl_FSEvalFile\fR is a simpler version of +\fBTcl_FSEvalFileEx\fR that always uses the system encoding +when reading the file. +.PP +\fBTcl_FSLoadFile\fR dynamically loads a binary code file into memory and +returns the addresses of two procedures within that file, if they are +defined. The appropriate function for the filesystem to which \fIpathPtr\fR +belongs will be called. If that filesystem does not implement this +function (most virtual filesystems will not, because of OS limitations +in dynamically loading binary code), Tcl will attempt to copy the file +to a temporary directory and load that temporary file. +.VS 8.6 +\fBTcl_FSUnloadFile\fR reverses the operation, asking for the library +indicated by the \fIloadHandle\fR to be removed from the process. Note that, +unlike with the \fBunload\fR command, this does not give the library any +opportunity to clean up. +.VE 8.6 +.PP +Both the above functions return a standard Tcl completion code. If an error +occurs, an error message is left in the \fIinterp\fR's result. +.PP +.VS 8.6 +The token provided via the variable indicated by \fIloadHandlePtr\fR may be +used with \fBTcl_FindSymbol\fR. +.VE 8.6 +.PP +\fBTcl_FSMatchInDirectory\fR is used by the globbing code to search a +directory for all files which match a given pattern. The appropriate +function for the filesystem to which \fIpathPtr\fR belongs will be called. +.PP +The return value is a standard Tcl result indicating whether an error +occurred in globbing. Error messages are placed in interp (unless +interp is NULL, which is allowed), but good results are placed in the +resultPtr given. +.PP +Note that the \fBglob\fR code implements recursive patterns internally, so +this function will only ever be passed simple patterns, which can be +matched using the logic of \fBstring match\fR. To handle recursion, Tcl +will call this function frequently asking only for directories to be +returned. A special case of being called with a NULL pattern indicates +that the path needs to be checked only for the correct type. +.PP +\fBTcl_FSLink\fR replaces the library version of \fBreadlink\fR, and +extends it to support the creation of links. The appropriate function +for the filesystem to which \fIlinkNamePtr\fR belongs will be called. +.PP +If the \fItoPtr\fR is NULL, a +.QW "read link" +action is performed. The result +is a Tcl_Obj specifying the contents of the symbolic link given by +\fIlinkNamePtr\fR, or NULL if the link could not be read. The result is owned +by the caller, which should call \fBTcl_DecrRefCount\fR when the result is no +longer needed. If the \fItoPtr\fR is not NULL, Tcl should create a link +of one of the types passed in in the \fIlinkAction\fR flag. This flag is +an ORed combination of \fBTCL_CREATE_SYMBOLIC_LINK\fR and \fBTCL_CREATE_HARD_LINK\fR. +Where a choice exists (i.e.\ more than one flag is passed in), the Tcl +convention is to prefer symbolic links. When a link is successfully +created, the return value should be \fItoPtr\fR (which is therefore +already owned by the caller). If unsuccessful, NULL is returned. +.PP +\fBTcl_FSLstat\fR fills the \fITcl_StatBuf\fR structure \fIstatPtr\fR with +information about the specified file. You do not need any access rights to the +file to get this information but you need search rights to all +directories named in the path leading to the file. The \fITcl_StatBuf\fR +structure includes info regarding device, inode (always 0 on Windows), +privilege mode, nlink (always 1 on Windows), user id (always 0 on +Windows), group id (always 0 on Windows), rdev (same as device on +Windows), size, last access time, last modification time, and +last metadata change time. +See \fBPORTABLE STAT RESULT API\fR for a description of how to write +portable code to allocate and access the \fITcl_StatBuf\fR structure. +.PP +If \fIpath\fR exists, \fBTcl_FSLstat\fR returns 0 and the stat structure +is filled with data. Otherwise, -1 is returned, and no stat info is +given. +.PP +\fBTcl_FSUtime\fR replaces the library version of utime. +.PP +This returns 0 on success and -1 on error (as per the \fButime\fR +documentation). If successful, the function +will update the +.QW atime +and +.QW mtime +values of the file given. +.PP +\fBTcl_FSFileAttrsGet\fR implements read access for the hookable \fBfile +attributes\fR subcommand. The appropriate function for the filesystem to +which \fIpathPtr\fR belongs will be called. +.PP +If the result is \fBTCL_OK\fR, then a value was placed in +\fIobjPtrRef\fR, which +will only be temporarily valid (unless \fBTcl_IncrRefCount\fR is called). +.PP +\fBTcl_FSFileAttrsSet\fR implements write access for the hookable \fBfile +attributes\fR subcommand. The appropriate function for the filesystem to +which \fIpathPtr\fR belongs will be called. +.PP +\fBTcl_FSFileAttrStrings\fR implements part of the hookable \fBfile +attributes\fR subcommand. The appropriate function for the filesystem +to which \fIpathPtr\fR belongs will be called. +.PP +The called procedure may either return an array of strings, or may +instead return NULL and place a Tcl list into the given \fIobjPtrRef\fR. Tcl +will take that list and first increment its reference count before using it. +On completion of that use, Tcl will decrement its reference count. Hence if +the list should be disposed of by Tcl when done, it should have a +reference count of zero, and if the list should not be disposed of, the +filesystem should ensure it retains a reference count to the value. +.PP +\fBTcl_FSAccess\fR checks whether the process would be allowed to read, +write or test for existence of the file (or other filesystem object) +whose name is \fIpathname\fR. If \fIpathname\fR is a symbolic link on Unix, +then permissions of the file referred by this symbolic link are +tested. +.PP +On success (all requested permissions granted), zero is returned. On +error (at least one bit in mode asked for a permission that is denied, +or some other error occurred), -1 is returned. +.PP +\fBTcl_FSStat\fR fills the \fITcl_StatBuf\fR structure \fIstatPtr\fR with +information about the specified file. You do not need any access rights to the +file to get this information but you need search rights to all +directories named in the path leading to the file. The \fITcl_StatBuf\fR +structure includes info regarding device, inode (always 0 on Windows), +privilege mode, nlink (always 1 on Windows), user id (always 0 on +Windows), group id (always 0 on Windows), rdev (same as device on +Windows), size, last access time, last modification time, and +last metadata change time. +See \fBPORTABLE STAT RESULT API\fR for a description of how to write +portable code to allocate and access the \fITcl_StatBuf\fR structure. +.PP +If \fIpath\fR exists, \fBTcl_FSStat\fR returns 0 and the stat structure +is filled with data. Otherwise, -1 is returned, and no stat info is +given. +.PP +\fBTcl_FSOpenFileChannel\fR opens a file specified by \fIpathPtr\fR and +returns a channel handle that can be used to perform input and output on +the file. This API is modeled after the \fBfopen\fR procedure of +the Unix standard I/O library. +The syntax and meaning of all arguments is similar to those +given in the Tcl \fBopen\fR command when opening a file. +If an error occurs while opening the channel, \fBTcl_FSOpenFileChannel\fR +returns NULL and records a POSIX error code that can be +retrieved with \fBTcl_GetErrno\fR. +In addition, if \fIinterp\fR is non-NULL, \fBTcl_FSOpenFileChannel\fR +leaves an error message in \fIinterp\fR's result after any error. +.PP +The newly created channel is not registered in the supplied interpreter; to +register it, use \fBTcl_RegisterChannel\fR. +If one of the standard channels, \fBstdin\fR, \fBstdout\fR or \fBstderr\fR was +previously closed, the act of creating the new channel also assigns it as a +replacement for the standard channel. +.PP +\fBTcl_FSGetCwd\fR replaces the library version of \fBgetcwd\fR. +.PP +It returns the Tcl library's current working directory. This may be +different to the native platform's working directory, which happens when +the current working directory is not in the native filesystem. +.PP +The result is a pointer to a Tcl_Obj specifying the current directory, +or NULL if the current directory could not be determined. If NULL is +returned, an error message is left in the \fIinterp\fR's result. +.PP +The result already has its reference count incremented for the caller. When +it is no longer needed, that reference count should be decremented. This is +needed for thread-safety purposes, to allow multiple threads to access +this and related functions, while ensuring the results are always +valid. +.PP +\fBTcl_FSChdir\fR replaces the library version of \fBchdir\fR. The path is +normalized and then passed to the filesystem which claims it. If that +filesystem does not implement this function, Tcl will fallback to a +combination of \fBstat\fR and \fBaccess\fR to check whether the directory +exists and has appropriate permissions. +.PP +For results, see \fBchdir\fR documentation. If successful, we keep a +record of the successful path in \fIcwdPathPtr\fR for subsequent calls to +\fBTcl_FSGetCwd\fR. +.PP +\fBTcl_FSPathSeparator\fR returns the separator character to be used for +most specific element of the path specified by \fIpathPtr\fR (i.e.\ the last +part of the path). +.PP +The separator is returned as a Tcl_Obj containing a string of length +1. If the path is invalid, NULL is returned. +.PP +\fBTcl_FSJoinPath\fR takes the given Tcl_Obj, which must be a valid +list (which is allowed to have a reference count of zero), and returns the path +value given by considering the first \fIelements\fR elements as valid path +segments (each path segment may be a complete path, a partial path or +just a single possible directory or file name). If any path segment is +actually an absolute path, then all prior path segments are discarded. +If \fIelements\fR is less than 0, we use the entire list. +.PP +It is possible that the returned value is actually an element +of the given list, so the caller should be careful to increment the +reference count of the result before freeing the list. +.PP +The returned value, typically with a reference count of zero (but it +could be shared +under some conditions), contains the joined path. The caller must +add a reference count to the value before using it. In particular, the +returned value could be an element of the given list, so freeing the +list might free the value prematurely if no reference count has been taken. +If the number of elements is zero, then the returned value will be +an empty-string Tcl_Obj. +.PP +\fBTcl_FSSplitPath\fR takes the given Tcl_Obj, which should be a valid path, +and returns a Tcl list value containing each segment of that path as +an element. +It returns a list value with a reference count of zero. If the +passed in \fIlenPtr\fR is non-NULL, the variable it points to will be +updated to contain the number of elements in the returned list. +.PP +\fBTcl_FSEqualPaths\fR tests whether the two paths given represent the same +filesystem object. +It returns 1 if the paths are equal, and 0 if they are different. If +either path is NULL, 0 is always returned. +.PP +\fBTcl_FSGetNormalizedPath\fR this important function attempts to extract +from the given Tcl_Obj a unique normalized path representation, whose +string value can be used as a unique identifier for the file. +.PP +It returns the normalized path value, owned by Tcl, or NULL if the path +was invalid or could otherwise not be successfully converted. +Extraction of absolute, normalized paths is very efficient (because the +filesystem operates on these representations internally), although the +result when the filesystem contains numerous symbolic links may not be +the most user-friendly version of a path. The return value is owned by +Tcl and has a lifetime equivalent to that of the \fIpathPtr\fR passed in +(unless that is a relative path, in which case the normalized path +value may be freed any time the cwd changes) - the caller can of +course increment the reference count if it wishes to maintain a copy for longer. +.PP +\fBTcl_FSJoinToPath\fR takes the given value, which should usually be a +valid path or NULL, and joins onto it the array of paths segments +given. +.PP +Returns a value, typically with reference count of zero (but it could be shared +under some conditions), containing the joined path. The caller must +add a reference count to the value before using it. If any of the values +passed into this function (\fIpathPtr\fR or \fIpath\fR elements) have +a reference count +of zero, they will be freed when this function returns. +.PP +\fBTcl_FSConvertToPathType\fR tries to convert the given Tcl_Obj to a valid +Tcl path type, taking account of the fact that the cwd may have changed +even if this value is already supposedly of the correct type. +The filename may begin with +.QW ~ +(to indicate current user's home directory) or +.QW ~<user> +(to indicate any user's home directory). +.PP +If the conversion succeeds (i.e.\ the value is a valid path in one of +the current filesystems), then \fBTCL_OK\fR is returned. Otherwise +\fBTCL_ERROR\fR is returned, and an error message may +be left in the interpreter. +.PP +\fBTcl_FSGetInternalRep\fR extracts the internal representation of a given +path value, in the given filesystem. If the path value belongs to a +different filesystem, we return NULL. If the internal representation is +currently NULL, we attempt to generate it, by calling the filesystem's +\fBTcl_FSCreateInternalRepProc\fR. +.PP +Returns NULL or a valid internal path representation. This internal +representation is cached, so that repeated calls to this function will +not require additional conversions. +.PP +\fBTcl_FSGetTranslatedPath\fR attempts to extract the translated path +from the given Tcl_Obj. +.PP +If the translation succeeds (i.e.\ the value is a valid path), then it is +returned. Otherwise NULL will be returned, and an error message may be +left in the interpreter. A +.QW translated +path is one which contains no +.QW ~ +or +.QW ~user +sequences (these have been expanded to their current +representation in the filesystem). The value returned is owned by the +caller, which must store it or call \fBTcl_DecrRefCount\fR to ensure memory is +freed. This function is of little practical use, and +\fBTcl_FSGetNormalizedPath\fR or \fBTcl_FSGetNativePath\fR are usually +better functions to use for most purposes. +.PP +\fBTcl_FSGetTranslatedStringPath\fR does the same as +\fBTcl_FSGetTranslatedPath\fR, but returns a character string or NULL. +The string returned is dynamically allocated and owned by the caller, +which must store it or call \fBckfree\fR to ensure it is freed. Again, +\fBTcl_FSGetNormalizedPath\fR or \fBTcl_FSGetNativePath\fR are usually +better functions to use for most purposes. +.PP +\fBTcl_FSNewNativePath\fR performs something like the reverse of the +usual obj->path->nativerep conversions. If some code retrieves a path +in native form (from, e.g.\ \fBreadlink\fR or a native dialog), and that path +is to be used at the Tcl level, then calling this function is an +efficient way of creating the appropriate path value type. +.PP +The resulting value is a pure +.QW path +value, which will only receive +a UTF-8 string representation if that is required by some Tcl code. +.PP +\fBTcl_FSGetNativePath\fR is for use by the Win/Unix native +filesystems, so that they can easily retrieve the native (char* or +TCHAR*) representation of a path. This function is a convenience +wrapper around \fBTcl_FSGetInternalRep\fR. It may be desirable in the +future to have non-string-based native representations (for example, +on MacOSX, a representation using a fileSpec of FSRef structure would +probably be more efficient). On Windows a full Unicode representation +would allow for paths of unlimited length. Currently the representation +is simply a character string which may contain either the relative path +or a complete, absolute normalized path in the native encoding (complex +conditions dictate which of these will be provided, so neither can be +relied upon, unless the path is known to be absolute). If you need a +native path which must be absolute, then you should ask for the native +version of a normalized path. If for some reason a non-absolute, +non-normalized version of the path is needed, that must be constructed +separately (e.g.\ using \fBTcl_FSGetTranslatedPath\fR). +.PP +The native representation is cached so that repeated calls to this +function will not require additional conversions. The return value is +owned by Tcl and has a lifetime equivalent to that of the \fIpathPtr\fR +passed in (unless that is a relative path, in which case the native +representation may be freed any time the cwd changes). +.PP +\fBTcl_FSFileSystemInfo\fR returns a list of two elements. The first +element is the name of the filesystem (e.g. +.QW native , +.QW vfs , +.QW zip , +or +.QW prowrap , +perhaps), and the second is the particular type of the +given path within that filesystem (which is filesystem dependent). The +second element may be empty if the filesystem does not provide a +further categorization of files. +.PP +A valid list value is returned, unless the path value is not +recognized, when NULL will be returned. +.PP +\fBTcl_FSGetFileSystemForPath\fR returns a pointer to the +\fBTcl_Filesystem\fR which accepts this path as valid. +.PP +If no filesystem will accept the path, NULL is returned. +.PP +\fBTcl_FSGetPathType\fR determines whether the given path is relative +to the current directory, relative to the current volume, or +absolute. +.PP +It returns one of \fBTCL_PATH_ABSOLUTE\fR, \fBTCL_PATH_RELATIVE\fR, or +\fBTCL_PATH_VOLUME_RELATIVE\fR +.SS "PORTABLE STAT RESULT API" +.PP +\fBTcl_AllocStatBuf\fR allocates a \fITcl_StatBuf\fR on the system heap (which +may be deallocated by being passed to \fBckfree\fR). This allows extensions to +invoke \fBTcl_FSStat\fR and \fBTcl_FSLstat\fR without being dependent on the +size of the buffer. That in turn depends on the flags used to build Tcl. +.PP +.VS 8.6 +The portable fields of a \fITcl_StatBuf\fR may be read using the following +functions, each of which returns the value of the corresponding field listed +in the table below. Note that on some platforms there may be other fields in +the \fITcl_StatBuf\fR as it is an alias for a suitable system structure, but +only the portable ones are made available here. See your system documentation +for a full description of these fields. +.DS +.ta \w'\fBTcl_GetModificationTimeFromStat\fR\0\0\0\0'u +\fIAccess Function\fR \fIField\fR + \fBTcl_GetFSDeviceFromStat\fR st_dev + \fBTcl_GetFSInodeFromStat\fR st_ino + \fBTcl_GetModeFromStat\fR st_mode + \fBTcl_GetLinkCountFromStat\fR st_nlink + \fBTcl_GetUserIdFromStat\fR st_uid + \fBTcl_GetGroupIdFromStat\fR st_gid + \fBTcl_GetDeviceTypeFromStat\fR st_rdev + \fBTcl_GetAccessTimeFromStat\fR st_atime + \fBTcl_GetModificationTimeFromStat\fR st_mtime + \fBTcl_GetChangeTimeFromStat\fR st_ctime + \fBTcl_GetSizeFromStat\fR st_size + \fBTcl_GetBlocksFromStat\fR st_blocks + \fBTcl_GetBlockSizeFromStat\fR st_blksize +.DE +.VE 8.6 +.SH "THE VIRTUAL FILESYSTEM API" +.PP +A filesystem provides a \fBTcl_Filesystem\fR structure that contains +pointers to functions that implement the various operations on a +filesystem; these operations are invoked as needed by the generic +layer, which generally occurs through the functions listed above. +.PP +The \fBTcl_Filesystem\fR structures are manipulated using the following +methods. +.PP +\fBTcl_FSRegister\fR takes a pointer to a filesystem structure and an +optional piece of data to associated with that filesystem. On calling +this function, Tcl will attach the filesystem to the list of known +filesystems, and it will become fully functional immediately. Tcl does +not check if the same filesystem is registered multiple times (and in +general that is not a good thing to do). \fBTCL_OK\fR will be returned. +.PP +\fBTcl_FSUnregister\fR removes the given filesystem structure from +the list of known filesystems, if it is known, and returns \fBTCL_OK\fR. If +the filesystem is not currently registered, \fBTCL_ERROR\fR is returned. +.PP +\fBTcl_FSData\fR will return the ClientData associated with the given +filesystem, if that filesystem is registered. Otherwise it will +return NULL. +.PP +\fBTcl_FSMountsChanged\fR is used to inform the Tcl's core that +the set of mount points for the given (already registered) filesystem +have changed, and that cached file representations may therefore no +longer be correct. +.SS "THE TCL_FILESYSTEM STRUCTURE" +.PP +The \fBTcl_Filesystem\fR structure contains the following fields: +.PP +.CS +typedef struct Tcl_Filesystem { + const char *\fItypeName\fR; + int \fIstructureLength\fR; + Tcl_FSVersion \fIversion\fR; + Tcl_FSPathInFilesystemProc *\fIpathInFilesystemProc\fR; + Tcl_FSDupInternalRepProc *\fIdupInternalRepProc\fR; + Tcl_FSFreeInternalRepProc *\fIfreeInternalRepProc\fR; + Tcl_FSInternalToNormalizedProc *\fIinternalToNormalizedProc\fR; + Tcl_FSCreateInternalRepProc *\fIcreateInternalRepProc\fR; + Tcl_FSNormalizePathProc *\fInormalizePathProc\fR; + Tcl_FSFilesystemPathTypeProc *\fIfilesystemPathTypeProc\fR; + Tcl_FSFilesystemSeparatorProc *\fIfilesystemSeparatorProc\fR; + Tcl_FSStatProc *\fIstatProc\fR; + Tcl_FSAccessProc *\fIaccessProc\fR; + Tcl_FSOpenFileChannelProc *\fIopenFileChannelProc\fR; + Tcl_FSMatchInDirectoryProc *\fImatchInDirectoryProc\fR; + Tcl_FSUtimeProc *\fIutimeProc\fR; + Tcl_FSLinkProc *\fIlinkProc\fR; + Tcl_FSListVolumesProc *\fIlistVolumesProc\fR; + Tcl_FSFileAttrStringsProc *\fIfileAttrStringsProc\fR; + Tcl_FSFileAttrsGetProc *\fIfileAttrsGetProc\fR; + Tcl_FSFileAttrsSetProc *\fIfileAttrsSetProc\fR; + Tcl_FSCreateDirectoryProc *\fIcreateDirectoryProc\fR; + Tcl_FSRemoveDirectoryProc *\fIremoveDirectoryProc\fR; + Tcl_FSDeleteFileProc *\fIdeleteFileProc\fR; + Tcl_FSCopyFileProc *\fIcopyFileProc\fR; + Tcl_FSRenameFileProc *\fIrenameFileProc\fR; + Tcl_FSCopyDirectoryProc *\fIcopyDirectoryProc\fR; + Tcl_FSLstatProc *\fIlstatProc\fR; + Tcl_FSLoadFileProc *\fIloadFileProc\fR; + Tcl_FSGetCwdProc *\fIgetCwdProc\fR; + Tcl_FSChdirProc *\fIchdirProc\fR; +} \fBTcl_Filesystem\fR; +.CE +.PP +Except for the first three fields in this structure which contain +simple data elements, all entries contain addresses of functions called +by the generic filesystem layer to perform the complete range of +filesystem related actions. +.PP +The many functions in this structure are broken down into three +categories: infrastructure functions (almost all of which must be +implemented), operational functions (which must be implemented if a +complete filesystem is provided), and efficiency functions (which need +only be implemented if they can be done so efficiently, or if they have +side-effects which are required by the filesystem; Tcl has less +efficient emulations it can fall back on). It is important to note +that, in the current version of Tcl, most of these fallbacks are only +used to handle commands initiated in Tcl, not in C. What this means is, +that if a \fBfile rename\fR command is issued in Tcl, and the relevant +filesystem(s) do not implement their \fITcl_FSRenameFileProc\fR, Tcl's +core will instead fallback on a combination of other filesystem +functions (it will use \fITcl_FSCopyFileProc\fR followed by +\fITcl_FSDeleteFileProc\fR, and if \fITcl_FSCopyFileProc\fR is not +implemented there is a further fallback). However, if a +\fITcl_FSRenameFileProc\fR command is issued at the C level, no such +fallbacks occur. This is true except for the last four entries in the +filesystem table (\fBlstat\fR, \fBload\fR, \fBgetcwd\fR and \fBchdir\fR) +for which fallbacks do in fact occur at the C level. +.PP +Any functions which take path names in Tcl_Obj form take +those names in UTF\-8 form. The filesystem infrastructure API is +designed to support efficient, cached conversion of these UTF\-8 paths +to other native representations. +.SS "EXAMPLE FILESYSTEM DEFINITION" +.PP +Here is the filesystem lookup table used by the +.QW vfs +extension which allows filesystem actions to be implemented in Tcl. +.PP +.CS +static Tcl_Filesystem vfsFilesystem = { + "tclvfs", + sizeof(Tcl_Filesystem), + TCL_FILESYSTEM_VERSION_1, + &VfsPathInFilesystem, + &VfsDupInternalRep, + &VfsFreeInternalRep, + /* No internal to normalized, since we don't create + * any pure 'internal' Tcl_Obj path representations */ + NULL, + /* No create native rep function, since we don't use + * it and don't choose to support uses of + * Tcl_FSNewNativePath */ + NULL, + /* Normalize path isn't needed - we assume paths only + * have one representation */ + NULL, + &VfsFilesystemPathType, + &VfsFilesystemSeparator, + &VfsStat, + &VfsAccess, + &VfsOpenFileChannel, + &VfsMatchInDirectory, + &VfsUtime, + /* We choose not to support symbolic links inside our + * VFS's */ + NULL, + &VfsListVolumes, + &VfsFileAttrStrings, + &VfsFileAttrsGet, + &VfsFileAttrsSet, + &VfsCreateDirectory, + &VfsRemoveDirectory, + &VfsDeleteFile, + /* No copy file; use the core fallback mechanism */ + NULL, + /* No rename file; use the core fallback mechanism */ + NULL, + /* No copy directory; use the core fallback mechanism */ + NULL, + /* Core will use stat for lstat */ + NULL, + /* No load; use the core fallback mechanism */ + NULL, + /* We don't need a getcwd or chdir; the core's own + * internal value is suitable */ + NULL, + NULL +}; +.CE +.SH "FILESYSTEM INFRASTRUCTURE" +.PP +These fields contain basic information about the filesystem structure +and addresses of functions which are used to associate +a particular filesystem with a file path, and deal with the internal +handling of path representations, for example copying and freeing such +representations. +.SS TYPENAME +.PP +The \fItypeName\fR field contains a null-terminated string that +identifies the type of the filesystem implemented, e.g. +.QW native , +.QW zip +or +.QW vfs . +.SS "STRUCTURE LENGTH" +.PP +The \fIstructureLength\fR field is generally implemented as +\fIsizeof(Tcl_Filesystem)\fR, and is there to allow easier +binary backwards compatibility if the size of the structure +changes in a future Tcl release. +.SS VERSION +.PP +The \fIversion\fR field should be set to \fBTCL_FILESYSTEM_VERSION_1\fR. +.SS PATHINFILESYSTEMPROC +.PP +The \fIpathInFilesystemProc\fR field contains the address of a function +which is called to determine whether a given path value belongs to this +filesystem or not. Tcl will only call the rest of the filesystem +functions with a path for which this function has returned \fBTCL_OK\fR. +If the path does not belong, -1 should be returned (the behavior of Tcl +for any other return value is not defined). If \fBTCL_OK\fR is returned, +then the optional \fIclientDataPtr\fR output parameter can be used to +return an internal (filesystem specific) representation of the path, +which will be cached inside the path value, and may be retrieved +efficiently by the other filesystem functions. Tcl will simultaneously +cache the fact that this path belongs to this filesystem. Such caches +are invalidated when filesystem structures are added or removed from +Tcl's internal list of known filesystems. +.PP +.CS +typedef int \fBTcl_FSPathInFilesystemProc\fR( + Tcl_Obj *\fIpathPtr\fR, + ClientData *\fIclientDataPtr\fR); +.CE +.SS DUPINTERNALREPPROC +.PP +This function makes a copy of a path's internal representation, and is +called when Tcl needs to duplicate a path value. If NULL, Tcl will +simply not copy the internal representation, which may then need to be +regenerated later. +.PP +.CS +typedef ClientData \fBTcl_FSDupInternalRepProc\fR( + ClientData \fIclientData\fR); +.CE +.SS FREEINTERNALREPPROC +Free the internal representation. This must be implemented if internal +representations need freeing (i.e.\ if some memory is allocated when an +internal representation is generated), but may otherwise be NULL. +.PP +.CS +typedef void \fBTcl_FSFreeInternalRepProc\fR( + ClientData \fIclientData\fR); +.CE +.SS INTERNALTONORMALIZEDPROC +.PP +Function to convert internal representation to a normalized path. Only +required if the filesystem creates pure path values with no string/path +representation. The return value is a Tcl value whose string +representation is the normalized path. +.PP +.CS +typedef Tcl_Obj *\fBTcl_FSInternalToNormalizedProc\fR( + ClientData \fIclientData\fR); +.CE +.SS CREATEINTERNALREPPROC +.PP +Function to take a path value, and calculate an internal +representation for it, and store that native representation in the +value. May be NULL if paths have no internal representation, or if +the \fITcl_FSPathInFilesystemProc\fR for this filesystem always +immediately creates an internal representation for paths it accepts. +.PP +.CS +typedef ClientData \fBTcl_FSCreateInternalRepProc\fR( + Tcl_Obj *\fIpathPtr\fR); +.CE +.SS NORMALIZEPATHPROC +.PP +Function to normalize a path. Should be implemented for all +filesystems which can have multiple string representations for the same +path value. In Tcl, every +.QW path +must have a single unique +.QW normalized +string representation. Depending on the filesystem, +there may be more than one unnormalized string representation which +refers to that path (e.g.\ a relative path, a path with different +character case if the filesystem is case insensitive, a path contain a +reference to a home directory such as +.QW ~ , +a path containing symbolic +links, etc). If the very last component in the path is a symbolic +link, it should not be converted into the value it points to (but +its case or other aspects should be made unique). All other path +components should be converted from symbolic links. This one +exception is required to agree with Tcl's semantics with \fBfile +delete\fR, \fBfile rename\fR, \fBfile copy\fR operating on symbolic links. +This function may be called with \fInextCheckpoint\fR either +at the beginning of the path (i.e.\ zero), at the end of the path, or +at any intermediate file separator in the path. It will never +point to any other arbitrary position in the path. In the last of +the three valid cases, the implementation can assume that the path +up to and including the file separator is known and normalized. +.PP +.CS +typedef int \fBTcl_FSNormalizePathProc\fR( + Tcl_Interp *\fIinterp\fR, + Tcl_Obj *\fIpathPtr\fR, + int \fInextCheckpoint\fR); +.CE +.SH "FILESYSTEM OPERATIONS" +.PP +The fields in this section of the structure contain addresses of +functions which are called to carry out the basic filesystem +operations. A filesystem which expects to be used with the complete +standard Tcl command set must implement all of these. If some of +them are not implemented, then certain Tcl commands may fail when +operating on paths within that filesystem. However, in some instances +this may be desirable (for example, a read-only filesystem should not +implement the last four functions, and a filesystem which does not +support symbolic links need not implement the \fBreadlink\fR function, +etc. The Tcl core expects filesystems to behave in this way). +.SS FILESYSTEMPATHTYPEPROC +.PP +Function to determine the type of a path in this filesystem. May be +NULL, in which case no type information will be available to users of +the filesystem. The +.QW type +is used only for informational purposes, +and should be returned as the string representation of the Tcl_Obj +which is returned. A typical return value might be +.QW networked , +.QW zip +or +.QW ftp . +The Tcl_Obj result is owned by the filesystem and so Tcl will +increment the reference count of that value if it wishes to retain a reference +to it. +.PP +.CS +typedef Tcl_Obj *\fBTcl_FSFilesystemPathTypeProc\fR( + Tcl_Obj *\fIpathPtr\fR); +.CE +.SS FILESYSTEMSEPARATORPROC +.PP +Function to return the separator character(s) for this filesystem. +This need only be implemented if the filesystem wishes to use a +different separator than the standard string +.QW / . +Amongst other +uses, it is returned by the \fBfile separator\fR command. The +return value should be a value with reference count of zero. +.PP +.CS +typedef Tcl_Obj *\fBTcl_FSFilesystemSeparatorProc\fR( + Tcl_Obj *\fIpathPtr\fR); +.CE +.SS STATPROC +.PP +Function to process a \fBTcl_FSStat\fR call. Must be implemented for any +reasonable filesystem, since many Tcl level commands depend crucially +upon it (e.g.\ \fBfile atime\fR, \fBfile isdirectory\fR, \fBfile size\fR, +\fBglob\fR). +.PP +.CS +typedef int \fBTcl_FSStatProc\fR( + Tcl_Obj *\fIpathPtr\fR, + Tcl_StatBuf *\fIstatPtr\fR); +.CE +.PP +The \fBTcl_FSStatProc\fR fills the stat structure \fIstatPtr\fR with +information about the specified file. You do not need any access +rights to the file to get this information but you need search rights +to all directories named in the path leading to the file. The stat +structure includes info regarding device, inode (always 0 on Windows), +privilege mode, nlink (always 1 on Windows), user id (always 0 on +Windows), group id (always 0 on Windows), rdev (same as device on +Windows), size, last access time, last modification time, and +last metadata change time. +.PP +If the file represented by \fIpathPtr\fR exists, the +\fBTcl_FSStatProc\fR returns 0 and the stat structure is filled with +data. Otherwise, -1 is returned, and no stat info is given. +.SS ACCESSPROC +.PP +Function to process a \fBTcl_FSAccess\fR call. Must be implemented for +any reasonable filesystem, since many Tcl level commands depend crucially +upon it (e.g.\ \fBfile exists\fR, \fBfile readable\fR). +.PP +.CS +typedef int \fBTcl_FSAccessProc\fR( + Tcl_Obj *\fIpathPtr\fR, + int \fImode\fR); +.CE +.PP +The \fBTcl_FSAccessProc\fR checks whether the process would be allowed +to read, write or test for existence of the file (or other filesystem +object) whose name is in \fIpathPtr\fR. If the pathname refers to a +symbolic link, then the +permissions of the file referred by this symbolic link should be tested. +.PP +On success (all requested permissions granted), zero is returned. On +error (at least one bit in mode asked for a permission that is denied, +or some other error occurred), -1 is returned. +.SS OPENFILECHANNELPROC +.PP +Function to process a \fBTcl_FSOpenFileChannel\fR call. Must be +implemented for any reasonable filesystem, since any operations +which require open or accessing a file's contents will use it +(e.g.\ \fBopen\fR, \fBencoding\fR, and many Tk commands). +.PP +.CS +typedef Tcl_Channel \fBTcl_FSOpenFileChannelProc\fR( + Tcl_Interp *\fIinterp\fR, + Tcl_Obj *\fIpathPtr\fR, + int \fImode\fR, + int \fIpermissions\fR); +.CE +.PP +The \fBTcl_FSOpenFileChannelProc\fR opens a file specified by +\fIpathPtr\fR and returns a channel handle that can be used to perform +input and output on the file. This API is modeled after the \fBfopen\fR +procedure of the Unix standard I/O library. The syntax and meaning of +all arguments is similar to those given in the Tcl \fBopen\fR command +when opening a file, where the \fImode\fR argument is a combination of +the POSIX flags O_RDONLY, O_WRONLY, etc. If an error occurs while +opening the channel, the \fBTcl_FSOpenFileChannelProc\fR returns NULL and +records a POSIX error code that can be retrieved with \fBTcl_GetErrno\fR. +In addition, if \fIinterp\fR is non-NULL, the +\fBTcl_FSOpenFileChannelProc\fR leaves an error message in \fIinterp\fR's +result after any error. +.PP +The newly created channel must not be registered in the supplied interpreter +by a \fBTcl_FSOpenFileChannelProc\fR; that task is up to the caller of +\fBTcl_FSOpenFileChannel\fR (if necessary). If one of +the standard channels, \fBstdin\fR, \fBstdout\fR or \fBstderr\fR was +previously closed, the act of creating the new channel also assigns it +as a replacement for the standard channel. +.SS MATCHINDIRECTORYPROC +.PP +Function to process a \fBTcl_FSMatchInDirectory\fR call. If not +implemented, then glob and recursive copy functionality will be lacking +in the filesystem (and this may impact commands like \fBencoding names\fR +which use glob functionality internally). +.PP +.CS +typedef int \fBTcl_FSMatchInDirectoryProc\fR( + Tcl_Interp *\fIinterp\fR, + Tcl_Obj *\fIresultPtr\fR, + Tcl_Obj *\fIpathPtr\fR, + const char *\fIpattern\fR, + Tcl_GlobTypeData *\fItypes\fR); +.CE +.PP +The function should return all files or directories (or other filesystem +objects) which match the given pattern and accord with the \fItypes\fR +specification given. There are two ways in which this function may be +called. If \fIpattern\fR is NULL, then \fIpathPtr\fR is a full path +specification of a single file or directory which should be checked for +existence and correct type. Otherwise, \fIpathPtr\fR is a directory, the +contents of which the function should search for files or directories +which have the correct type. In either case, \fIpathPtr\fR can be +assumed to be both non-NULL and non-empty. It is not currently +documented whether \fIpathPtr\fR will have a file separator at its end of +not, so code should be flexible to both possibilities. +.PP +The return value is a standard Tcl result indicating whether an error +occurred in the matching process. Error messages are placed in +\fIinterp\fR, unless \fIinterp\fR in NULL in which case no error +message need be generated; on a \fBTCL_OK\fR result, results should be +added to the \fIresultPtr\fR value given (which can be assumed to be a +valid unshared Tcl list). The matches added +to \fIresultPtr\fR should include any path prefix given in \fIpathPtr\fR +(this usually means they will be absolute path specifications). +Note that if no matches are found, that simply leads to an empty +result; errors are only signaled for actual file or filesystem +problems which may occur during the matching process. +.PP +The \fBTcl_GlobTypeData\fR structure passed in the \fItypes\fR +parameter contains the following fields: +.PP +.CS +typedef struct Tcl_GlobTypeData { + /* Corresponds to bcdpfls as in 'find -t' */ + int \fItype\fR; + /* Corresponds to file permissions */ + int \fIperm\fR; + /* Acceptable mac type */ + Tcl_Obj *\fImacType\fR; + /* Acceptable mac creator */ + Tcl_Obj *\fImacCreator\fR; +} \fBTcl_GlobTypeData\fR; +.CE +.PP +There are two specific cases which it is important to handle correctly, +both when \fItypes\fR is non-NULL. The two cases are when \fItypes->types +& TCL_GLOB_TYPE_DIR\fR or \fItypes->types & TCL_GLOB_TYPE_MOUNT\fR are +true (and in particular when the other flags are false). In the first of +these cases, the function must list the contained directories. Tcl uses +this to implement recursive globbing, so it is critical that filesystems +implement directory matching correctly. In the second of these cases, +with \fBTCL_GLOB_TYPE_MOUNT\fR, the filesystem must list the mount points +which lie within the given \fIpathPtr\fR (and in this case, \fIpathPtr\fR +need not lie within the same filesystem - different to all other cases in +which this function is called). Support for this is critical if Tcl is +to have seamless transitions between from one filesystem to another. +.SS UTIMEPROC +.PP +Function to process a \fBTcl_FSUtime\fR call. Required to allow setting +(not reading) of times with \fBfile mtime\fR, \fBfile atime\fR and the +open-r/open-w/fcopy implementation of \fBfile copy\fR. +.PP +.CS +typedef int \fBTcl_FSUtimeProc\fR( + Tcl_Obj *\fIpathPtr\fR, + struct utimbuf *\fItval\fR); +.CE +.PP +The access and modification times of the file specified by \fIpathPtr\fR +should be changed to the values given in the \fItval\fR structure. +.PP +The return value should be 0 on success and -1 on an error, as +with the system \fButime\fR. +.SS LINKPROC +.PP +Function to process a \fBTcl_FSLink\fR call. Should be implemented +only if the filesystem supports links, and may otherwise be NULL. +.PP +.CS +typedef Tcl_Obj *\fBTcl_FSLinkProc\fR( + Tcl_Obj *\fIlinkNamePtr\fR, + Tcl_Obj *\fItoPtr\fR, + int \fIlinkAction\fR); +.CE +.PP +If \fItoPtr\fR is NULL, the function is being asked to read the +contents of a link. The result is a Tcl_Obj specifying the contents of +the link given by \fIlinkNamePtr\fR, or NULL if the link could +not be read. The result is owned by the caller (and should therefore +have its ref count incremented before being returned). Any callers +should call \fBTcl_DecrRefCount\fR on this result when it is no longer needed. +If \fItoPtr\fR is not NULL, the function should attempt to create a link. +The result in this case should be \fItoPtr\fR if the link was successful +and NULL otherwise. In this case the result is not owned by the caller +(i.e.\ no reference count manipulations on either end are needed). See +the documentation for \fBTcl_FSLink\fR for the correct interpretation +of the \fIlinkAction\fR flags. +.SS LISTVOLUMESPROC +.PP +Function to list any filesystem volumes added by this filesystem. +Should be implemented only if the filesystem adds volumes at the head +of the filesystem, so that they can be returned by \fBfile volumes\fR. +.PP +.CS +typedef Tcl_Obj *\fBTcl_FSListVolumesProc\fR(void); +.CE +.PP +The result should be a list of volumes added by this filesystem, or +NULL (or an empty list) if no volumes are provided. The result value +is considered to be owned by the filesystem (not by Tcl's core), but +should be given a reference count for Tcl. Tcl will use the contents of the +list and then decrement that reference count. This allows filesystems to +choose whether they actually want to retain a +.QW "master list" +of volumes +or not (if not, they generate the list on the fly and pass it to Tcl +with a reference count of 1 and then forget about the list, if yes, then +they simply increment the reference count of their master list and pass it +to Tcl which will copy the contents and then decrement the count back +to where it was). +.PP +Therefore, Tcl considers return values from this proc to be read-only. +.SS FILEATTRSTRINGSPROC +.PP +Function to list all attribute strings which are valid for this +filesystem. If not implemented the filesystem will not support +the \fBfile attributes\fR command. This allows arbitrary additional +information to be attached to files in the filesystem. If it is +not implemented, there is no need to implement the \fBget\fR and \fBset\fR +methods. +.PP +.CS +typedef const char *const *\fBTcl_FSFileAttrStringsProc\fR( + Tcl_Obj *\fIpathPtr\fR, + Tcl_Obj **\fIobjPtrRef\fR); +.CE +.PP +The called function may either return an array of strings, or may +instead return NULL and place a Tcl list into the given \fIobjPtrRef\fR. Tcl +will take that list and first increment its reference count before using it. +On completion of that use, Tcl will decrement its reference count. Hence if +the list should be disposed of by Tcl when done, it should have a +reference count of zero, and if the list should not be disposed of, the +filesystem should ensure it returns a value with a reference count +of at least one. +.SS FILEATTRSGETPROC +.PP +Function to process a \fBTcl_FSFileAttrsGet\fR call, used by \fBfile +attributes\fR. +.PP +.CS +typedef int \fBTcl_FSFileAttrsGetProc\fR( + Tcl_Interp *\fIinterp\fR, + int \fIindex\fR, + Tcl_Obj *\fIpathPtr\fR, + Tcl_Obj **\fIobjPtrRef\fR); +.CE +.PP +Returns a standard Tcl return code. The attribute value retrieved, +which corresponds to the \fIindex\fR'th element in the list returned by +the \fBTcl_FSFileAttrStringsProc\fR, is a Tcl_Obj placed in \fIobjPtrRef\fR (if +\fBTCL_OK\fR was returned) and is likely to have a reference count of zero. Either +way we must either store it somewhere (e.g.\ the Tcl result), or +Incr/Decr its reference count to ensure it is properly freed. +.SS FILEATTRSSETPROC +.PP +Function to process a \fBTcl_FSFileAttrsSet\fR call, used by \fBfile +attributes\fR. If the filesystem is read-only, there is no need +to implement this. +.PP +.CS +typedef int \fBTcl_FSFileAttrsSetProc\fR( + Tcl_Interp *\fIinterp\fR, + int \fIindex\fR, + Tcl_Obj *\fIpathPtr\fR, + Tcl_Obj *\fIobjPtr\fR); +.CE +.PP +The attribute value of the \fIindex\fR'th element in the list returned by +the Tcl_FSFileAttrStringsProc should be set to the \fIobjPtr\fR given. +.SS CREATEDIRECTORYPROC +.PP +Function to process a \fBTcl_FSCreateDirectory\fR call. Should be +implemented unless the FS is read-only. +.PP +.CS +typedef int \fBTcl_FSCreateDirectoryProc\fR( + Tcl_Obj *\fIpathPtr\fR); +.CE +.PP +The return value is a standard Tcl result indicating whether an error +occurred in the process. If successful, a new directory should have +been added to the filesystem in the location specified by +\fIpathPtr\fR. +.SS REMOVEDIRECTORYPROC +.PP +Function to process a \fBTcl_FSRemoveDirectory\fR call. Should be +implemented unless the FS is read-only. +.PP +.CS +typedef int \fBTcl_FSRemoveDirectoryProc\fR( + Tcl_Obj *\fIpathPtr\fR, + int \fIrecursive\fR, + Tcl_Obj **\fIerrorPtr\fR); +.CE +.PP +The return value is a standard Tcl result indicating whether an error +occurred in the process. If successful, the directory specified by +\fIpathPtr\fR should have been removed from the filesystem. If the +\fIrecursive\fR flag is given, then a non-empty directory should be +deleted without error. If this flag is not given, then and the +directory is non-empty a POSIX +.QW EEXIST +error should be signaled. If an +error does occur, the name of the file or directory which caused the +error should be placed in \fIerrorPtr\fR. +.SS DELETEFILEPROC +.PP +Function to process a \fBTcl_FSDeleteFile\fR call. Should be implemented +unless the FS is read-only. +.PP +.CS +typedef int \fBTcl_FSDeleteFileProc\fR( + Tcl_Obj *\fIpathPtr\fR); +.CE +.PP +The return value is a standard Tcl result indicating whether an error +occurred in the process. If successful, the file specified by +\fIpathPtr\fR should have been removed from the filesystem. Note that, +if the filesystem supports symbolic links, Tcl will always call this +function and not Tcl_FSRemoveDirectoryProc when needed to delete them +(even if they are symbolic links to directories). +.SH "FILESYSTEM EFFICIENCY" +.PP +These functions need not be implemented for a particular filesystem +because the core has a fallback implementation available. See each +individual description for the consequences of leaving the field NULL. +.SS LSTATPROC +.PP +Function to process a \fBTcl_FSLstat\fR call. If not implemented, Tcl +will attempt to use the \fIstatProc\fR defined above instead. Therefore +it need only be implemented if a filesystem can differentiate between +\fBstat\fR and \fBlstat\fR calls. +.PP +.CS +typedef int \fBTcl_FSLstatProc\fR( + Tcl_Obj *\fIpathPtr\fR, + Tcl_StatBuf *\fIstatPtr\fR); +.CE +.PP +The behavior of this function is very similar to that of the +\fBTcl_FSStatProc\fR defined above, except that if it is applied +to a symbolic link, it returns information about the link, not +about the target file. +.SS COPYFILEPROC +.PP +Function to process a \fBTcl_FSCopyFile\fR call. If not implemented Tcl +will fall back on \fBopen\fR-r, \fBopen\fR-w and \fBfcopy\fR as a +copying mechanism. +Therefore it need only be implemented if the filesystem can perform +that action more efficiently. +.PP +.CS +typedef int \fBTcl_FSCopyFileProc\fR( + Tcl_Obj *\fIsrcPathPtr\fR, + Tcl_Obj *\fIdestPathPtr\fR); +.CE +.PP +The return value is a standard Tcl result indicating whether an error +occurred in the copying process. Note that, \fIdestPathPtr\fR is the +name of the file which should become the copy of \fIsrcPathPtr\fR. It +is never the name of a directory into which \fIsrcPathPtr\fR could be +copied (i.e.\ the function is much simpler than the Tcl level \fBfile +copy\fR subcommand). Note that, +if the filesystem supports symbolic links, Tcl will always call this +function and not \fIcopyDirectoryProc\fR when needed to copy them +(even if they are symbolic links to directories). Finally, if the +filesystem determines it cannot support the \fBfile copy\fR action, +calling \fBTcl_SetErrno(EXDEV)\fR and returning a non-\fBTCL_OK\fR +result will tell Tcl to use its standard fallback mechanisms. +.SS RENAMEFILEPROC +.PP +Function to process a \fBTcl_FSRenameFile\fR call. If not implemented, +Tcl will fall back on a copy and delete mechanism. Therefore it need +only be implemented if the filesystem can perform that action more +efficiently. +.PP +.CS +typedef int \fBTcl_FSRenameFileProc\fR( + Tcl_Obj *\fIsrcPathPtr\fR, + Tcl_Obj *\fIdestPathPtr\fR); +.CE +.PP +The return value is a standard Tcl result indicating whether an error +occurred in the renaming process. If the +filesystem determines it cannot support the \fBfile rename\fR action, +calling \fBTcl_SetErrno(EXDEV)\fR and returning a non-\fBTCL_OK\fR +result will tell Tcl to use its standard fallback mechanisms. +.SS COPYDIRECTORYPROC +.PP +Function to process a \fBTcl_FSCopyDirectory\fR call. If not +implemented, Tcl will fall back on a recursive \fBfile mkdir\fR, \fBfile copy\fR +mechanism. Therefore it need only be implemented if the filesystem can +perform that action more efficiently. +.PP +.CS +typedef int \fBTcl_FSCopyDirectoryProc\fR( + Tcl_Obj *\fIsrcPathPtr\fR, + Tcl_Obj *\fIdestPathPtr\fR, + Tcl_Obj **\fIerrorPtr\fR); +.CE +.PP +The return value is a standard Tcl result indicating whether an error +occurred in the copying process. If an error does occur, the name of +the file or directory which caused the error should be placed in +\fIerrorPtr\fR. Note that, \fIdestPathPtr\fR is the name of the +directory-name which should become the mirror-image of +\fIsrcPathPtr\fR. It is not the name of a directory into which +\fIsrcPathPtr\fR should be copied (i.e.\ the function is much simpler +than the Tcl level \fBfile copy\fR subcommand). Finally, if the +filesystem determines it cannot support the directory copy action, +calling \fBTcl_SetErrno(EXDEV)\fR and returning a non-\fBTCL_OK\fR +result will tell Tcl to use its standard fallback mechanisms. +.SS LOADFILEPROC +.PP +Function to process a \fBTcl_FSLoadFile\fR call. If not implemented, Tcl +will fall back on a copy to native-temp followed by a \fBTcl_FSLoadFile\fR on +that temporary copy. Therefore it need only be implemented if the +filesystem can load code directly, or it can be implemented simply to +return \fBTCL_ERROR\fR to disable load functionality in this filesystem +entirely. +.PP +.CS +typedef int \fBTcl_FSLoadFileProc\fR( + Tcl_Interp *\fIinterp\fR, + Tcl_Obj *\fIpathPtr\fR, + Tcl_LoadHandle *\fIhandlePtr\fR, + Tcl_FSUnloadFileProc *\fIunloadProcPtr\fR); +.CE +.PP +Returns a standard Tcl completion code. If an error occurs, an error +message is left in the \fIinterp\fR's result. The function dynamically loads a +binary code file into memory. On a successful load, the \fIhandlePtr\fR +should be filled with a token for the dynamically loaded file, and the +\fIunloadProcPtr\fR should be filled in with the address of a procedure. +The unload procedure will be called with the given \fBTcl_LoadHandle\fR as its +only parameter when Tcl needs to unload the file. For example, for the +native filesystem, the \fBTcl_LoadHandle\fR returned is currently a token +which can be used in the private \fBTclpFindSymbol\fR to access functions +in the new code. Each filesystem is free to define the +\fBTcl_LoadHandle\fR as it requires. Finally, if the +filesystem determines it cannot support the file load action, +calling \fBTcl_SetErrno(EXDEV)\fR and returning a non-\fBTCL_OK\fR +result will tell Tcl to use its standard fallback mechanisms. +.SS UNLOADFILEPROC +.PP +Function to unload a previously successfully loaded file. If load was +implemented, then this should also be implemented, if there is any +cleanup action required. +.PP +.CS +typedef void \fBTcl_FSUnloadFileProc\fR( + Tcl_LoadHandle \fIloadHandle\fR); +.CE +.SS GETCWDPROC +.PP +Function to process a \fBTcl_FSGetCwd\fR call. Most filesystems need not +implement this. It will usually only be called once, if \fBgetcwd\fR is +called before \fBchdir\fR. May be NULL. +.PP +.CS +typedef Tcl_Obj *\fBTcl_FSGetCwdProc\fR( + Tcl_Interp *\fIinterp\fR); +.CE +.PP +If the filesystem supports a native notion of a current working +directory (which might perhaps change independent of Tcl), this +function should return that cwd as the result, or NULL if the current +directory could not be determined (e.g.\ the user does not have +appropriate permissions on the cwd directory). If NULL is returned, an +error message is left in the \fIinterp\fR's result. +.SS CHDIRPROC +.PP +Function to process a \fBTcl_FSChdir\fR call. If filesystems do not +implement this, it will be emulated by a series of directory access +checks. Otherwise, virtual filesystems which do implement it need only +respond with a positive return result if the \fIpathPtr\fR is a valid, +accessible directory in their filesystem. They need not remember the +result, since that will be automatically remembered for use by +\fBTcl_FSGetCwd\fR. +Real filesystems should carry out the correct action (i.e.\ call the +correct system \fBchdir\fR API). +.PP +.CS +typedef int \fBTcl_FSChdirProc\fR( + Tcl_Obj *\fIpathPtr\fR); +.CE +.PP +The \fBTcl_FSChdirProc\fR changes the applications current working +directory to the value specified in \fIpathPtr\fR. The function returns +-1 on error or 0 on success. +.SH "SEE ALSO" +cd(n), file(n), filename(n), load(n), open(n), pwd(n), source(n), unload(n) +.SH KEYWORDS +stat, access, filesystem, vfs, virtual filesystem diff --git a/tcl8.6/doc/FindExec.3 b/tcl8.6/doc/FindExec.3 new file mode 100644 index 0000000..b01315c --- /dev/null +++ b/tcl8.6/doc/FindExec.3 @@ -0,0 +1,63 @@ +'\" +'\" Copyright (c) 1995-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. +'\" +.TH Tcl_FindExecutable 3 8.1 Tcl "Tcl Library Procedures" +.so man.macros +.BS +.SH NAME +Tcl_FindExecutable, Tcl_GetNameOfExecutable \- identify or return the name of the binary file containing the application +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +void +\fBTcl_FindExecutable\fR(\fIargv0\fR) +.sp +const char * +\fBTcl_GetNameOfExecutable\fR() +.SH ARGUMENTS +.AS char *argv0 +.AP char *argv0 in +The first command-line argument to the program, which gives the +application's name. +.BE + +.SH DESCRIPTION +.PP +The \fBTcl_FindExecutable\fR procedure computes the full path name of +the executable file from which the application was invoked and saves +it for Tcl's internal use. +The executable's path name is needed for several purposes in +Tcl. For example, it is needed on some platforms in the +implementation of the \fBload\fR command. +It is also returned by the \fBinfo nameofexecutable\fR command. +.PP +On UNIX platforms this procedure is typically invoked as the very +first thing in the application's main program; it must be passed +\fIargv[0]\fR as its argument. It is important not to change the +working directory before the invocation. +\fBTcl_FindExecutable\fR uses \fIargv0\fR +along with the \fBPATH\fR environment variable to find the +application's executable, if possible. If it fails to find +the binary, then future calls to \fBinfo nameofexecutable\fR +will return an empty string. +.PP +On Windows platforms this procedure is typically invoked as the very +first thing in the application's main program as well; Its \fIargv[0]\fR +argument is only used to indicate whether the executable has a stderr +channel (any non-null value) or not (the value null). If \fBTcl_SetPanicProc\fR +is never called and no debugger is running, this determines whether +the panic message is sent to stderr or to a standard system dialog. +.PP +\fBTcl_GetNameOfExecutable\fR simply returns a pointer to the +internal full path name of the executable file as computed by +\fBTcl_FindExecutable\fR. This procedure call is the C API +equivalent to the \fBinfo nameofexecutable\fR command. NULL +is returned if the internal full path name has not been +computed or unknown. + +.SH KEYWORDS +binary, executable file diff --git a/tcl8.6/doc/GetCwd.3 b/tcl8.6/doc/GetCwd.3 new file mode 100644 index 0000000..58abcde --- /dev/null +++ b/tcl8.6/doc/GetCwd.3 @@ -0,0 +1,52 @@ +'\" +'\" Copyright (c) 1998-1999 Scriptics Corporation +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH Tcl_GetCwd 3 8.1 Tcl "Tcl Library Procedures" +.so man.macros +.BS +.SH NAME +Tcl_GetCwd, Tcl_Chdir \- manipulate the current working directory +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +char * +\fBTcl_GetCwd\fR(\fIinterp\fR, \fIbufferPtr\fR) +.sp +int +\fBTcl_Chdir\fR(\fIpath\fR) +.SH ARGUMENTS +.AS Tcl_DString *bufferPtr in/out +.AP Tcl_Interp *interp in +Interpreter in which to report an error, if any. +.AP Tcl_DString *bufferPtr in/out +This dynamic string is used to store the current working directory. +At the time of the call it should be uninitialized or free. The +caller must eventually call \fBTcl_DStringFree\fR to free up +anything stored here. +.AP char *path in +File path in UTF\-8 format. +.BE + +.SH DESCRIPTION +.PP +These procedures may be used to manipulate the current working +directory for the application. They provide C\-level access to +the same functionality as the Tcl \fBpwd\fR command. +.PP +\fBTcl_GetCwd\fR returns a pointer to a string specifying the current +directory, or NULL if the current directory could not be determined. +If NULL is returned, an error message is left in the \fIinterp\fR's result. +Storage for the result string is allocated in bufferPtr; the caller +must call \fBTcl_DStringFree()\fR when the result is no longer needed. +The format of the path is UTF\-8. +.PP +\fBTcl_Chdir\fR changes the applications current working directory to +the value specified in \fIpath\fR. The format of the passed in string +must be UTF\-8. The function returns -1 on error or 0 on success. + +.SH KEYWORDS +pwd diff --git a/tcl8.6/doc/GetHostName.3 b/tcl8.6/doc/GetHostName.3 new file mode 100644 index 0000000..73432d3 --- /dev/null +++ b/tcl8.6/doc/GetHostName.3 @@ -0,0 +1,27 @@ +'\" +'\" Copyright (c) 1998-2000 by Scriptics Corporation. +'\" All rights reserved. +'\" +.TH Tcl_GetHostName 3 8.3 Tcl "Tcl Library Procedures" +.so man.macros +.BS +.SH NAME +Tcl_GetHostName \- get the name of the local host +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +const char * +\fBTcl_GetHostName\fR() +.BE + +.SH DESCRIPTION +.PP +\fBTcl_GetHostName\fR is a utility procedure used by some of the +Tcl commands. It returns a pointer to a string containing the name +for the current machine, or an empty string if the name cannot be +determined. The string is statically allocated, and the caller must +not modify of free it. +.PP +.SH KEYWORDS +hostname diff --git a/tcl8.6/doc/GetIndex.3 b/tcl8.6/doc/GetIndex.3 new file mode 100644 index 0000000..fc6f40b --- /dev/null +++ b/tcl8.6/doc/GetIndex.3 @@ -0,0 +1,104 @@ +'\" +'\" Copyright (c) 1997 Sun Microsystems, Inc. +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH Tcl_GetIndexFromObj 3 8.1 Tcl "Tcl Library Procedures" +.so man.macros +.BS +.SH NAME +Tcl_GetIndexFromObj, Tcl_GetIndexFromObjStruct \- lookup string in table of keywords +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +int +\fBTcl_GetIndexFromObj\fR(\fIinterp, objPtr, tablePtr, msg, flags, +indexPtr\fR) +.sp +int +\fBTcl_GetIndexFromObjStruct\fR(\fIinterp, objPtr, structTablePtr, offset, + msg, flags, indexPtr\fR) +.SH ARGUMENTS +.AS "const char" *structTablePtr in/out +.AP Tcl_Interp *interp in +Interpreter to use for error reporting; if NULL, then no message is +provided on errors. +.AP Tcl_Obj *objPtr in/out +The string value of this value is used to search through \fItablePtr\fR. +The internal representation is modified to hold the index of the matching +table entry. +.AP "const char *const" *tablePtr in +An array of null-terminated strings. The end of the array is marked +by a NULL string pointer. +Note that references to the \fItablePtr\fR may be retained in the +internal representation of \fIobjPtr\fR, so this should represent the +address of a statically-allocated array. +.AP "const void" *structTablePtr in +An array of arbitrary type, typically some \fBstruct\fR type. +The first member of the structure must be a null-terminated string. +The size of the structure is given by \fIoffset\fR. +Note that references to the \fIstructTablePtr\fR may be retained in the +internal representation of \fIobjPtr\fR, so this should represent the +address of a statically-allocated array of structures. +.AP int offset in +The offset to add to structTablePtr to get to the next entry. +The end of the array is marked by a NULL string pointer. +.AP "const char" *msg in +Null-terminated string describing what is being looked up, such as +\fBoption\fR. This string is included in error messages. +.AP int flags in +OR-ed combination of bits providing additional information for +operation. The only bit that is currently defined is \fBTCL_EXACT\fR. +.AP int *indexPtr out +The index of the string in \fItablePtr\fR that matches the value of +\fIobjPtr\fR is returned here. +.BE +.SH DESCRIPTION +.PP +These procedures provide an efficient way for looking up keywords, +switch names, option names, and similar things where the literal value of +a Tcl value must be chosen from a predefined set. +\fBTcl_GetIndexFromObj\fR compares \fIobjPtr\fR against each of +the strings in \fItablePtr\fR to find a match. A match occurs if +\fIobjPtr\fR's string value is identical to one of the strings in +\fItablePtr\fR, or if it is a non-empty unique abbreviation +for exactly one of the strings in \fItablePtr\fR and the +\fBTCL_EXACT\fR flag was not specified; in either case +the index of the matching entry is stored at \fI*indexPtr\fR +and \fBTCL_OK\fR is returned. +.PP +If there is no matching entry, +\fBTCL_ERROR\fR is returned and an error message is left in \fIinterp\fR's +result if \fIinterp\fR is not NULL. \fIMsg\fR is included in the +error message to indicate what was being looked up. For example, +if \fImsg\fR is \fBoption\fR the error message will have a form like +.QW "\fBbad option \N'34'firt\N'34': must be first, second, or third\fR" . +.PP +If \fBTcl_GetIndexFromObj\fR completes successfully it modifies the +internal representation of \fIobjPtr\fR to hold the address of +the table and the index of the matching entry. If \fBTcl_GetIndexFromObj\fR +is invoked again with the same \fIobjPtr\fR and \fItablePtr\fR +arguments (e.g. during a reinvocation of a Tcl command), it returns +the matching index immediately without having to redo the lookup +operation. Note: \fBTcl_GetIndexFromObj\fR assumes that the entries +in \fItablePtr\fR are static: they must not change between +invocations. If the value of \fIobjPtr\fR is the empty string, +\fBTcl_GetIndexFromObj\fR will treat it as a non-matching value +and return \fBTCL_ERROR\fR. +.PP +\fBTcl_GetIndexFromObjStruct\fR works just like +\fBTcl_GetIndexFromObj\fR, except that instead of treating +\fItablePtr\fR as an array of string pointers, it treats it as a +pointer to the first string in a series of strings that have +\fIoffset\fR bytes between them (i.e. that there is a pointer to the +first array of characters at \fItablePtr\fR, a pointer to the second +array of characters at \fItablePtr\fR+\fIoffset\fR bytes, etc.) +This is particularly useful when processing things like +\fBTk_ConfigurationSpec\fR, whose string keys are in the same place in +each of several array elements. +.SH "SEE ALSO" +prefix(n), Tcl_WrongNumArgs(3) +.SH KEYWORDS +index, option, value, table lookup diff --git a/tcl8.6/doc/GetInt.3 b/tcl8.6/doc/GetInt.3 new file mode 100644 index 0000000..5a3304a --- /dev/null +++ b/tcl8.6/doc/GetInt.3 @@ -0,0 +1,101 @@ +'\" +'\" Copyright (c) 1989-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. +'\" +.TH Tcl_GetInt 3 "" Tcl "Tcl Library Procedures" +.so man.macros +.BS +.SH NAME +Tcl_GetInt, Tcl_GetDouble, Tcl_GetBoolean \- convert from string to integer, double, or boolean +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +int +\fBTcl_GetInt\fR(\fIinterp, src, intPtr\fR) +.sp +int +\fBTcl_GetDouble\fR(\fIinterp, src, doublePtr\fR) +.sp +int +\fBTcl_GetBoolean\fR(\fIinterp, src, boolPtr\fR) +.SH ARGUMENTS +.AS Tcl_Interp *doublePtr out +.AP Tcl_Interp *interp in +Interpreter to use for error reporting. +.AP "const char" *src in +Textual value to be converted. +.AP int *intPtr out +Points to place to store integer value converted from \fIsrc\fR. +.AP double *doublePtr out +Points to place to store double-precision floating-point +value converted from \fIsrc\fR. +.AP int *boolPtr out +Points to place to store boolean value (0 or 1) converted from \fIsrc\fR. +.BE + +.SH DESCRIPTION +.PP +These procedures convert from strings to integers or double-precision +floating-point values or booleans (represented as 0- or 1-valued +integers). Each of the procedures takes a \fIsrc\fR argument, +converts it to an internal form of a particular type, and stores +the converted value at the location indicated by the procedure's +third argument. If all goes well, each of the procedures returns +\fBTCL_OK\fR. If \fIsrc\fR does not have the proper syntax for the +desired type then \fBTCL_ERROR\fR is returned, an error message is left +in the interpreter's result, and nothing is stored at *\fIintPtr\fR +or *\fIdoublePtr\fR or *\fIboolPtr\fR. +.PP +\fBTcl_GetInt\fR expects \fIsrc\fR to consist of a collection +of integer digits, optionally signed and optionally preceded and +followed by white space. If the first two characters of \fIsrc\fR +after the optional white space and sign are +.QW \fB0x\fR +then \fIsrc\fR is expected to be in hexadecimal form; otherwise, +if the first such characters are +.QW \fB0o\fR +then \fIsrc\fR is expected to be in octal form; otherwise, +if the first such characters are +.QW \fB0b\fR +then \fIsrc\fR is expected to be in binary form; otherwise, +if the first such character is +.QW \fB0\fR +then \fIsrc\fR +is expected to be in octal form; otherwise, \fIsrc\fR is +expected to be in decimal form. +.PP +\fBTcl_GetDouble\fR expects \fIsrc\fR to consist of a floating-point +number, which is: white space; a sign; a sequence of digits; a +decimal point +.QW \fB.\fR ; +a sequence of digits; the letter +.QW \fBe\fR ; +a signed decimal exponent; and more white space. +Any of the fields may be omitted, except that +the digits either before or after the decimal point must be present +and if the +.QW \fBe\fR +is present then it must be followed by the exponent number. If there +are no fields apart from the sign and initial sequence of digits +(i.e., no decimal point or exponent indicator), that +initial sequence of digits should take one of the forms that +\fBTcl_GetInt\fR supports, described above. The use of +.QW \fB,\fR +as a decimal point is not supported nor should any other sort of +inter-digit separator be present. +.PP +\fBTcl_GetBoolean\fR expects \fIsrc\fR to specify a boolean +value. If \fIsrc\fR is any of \fB0\fR, \fBfalse\fR, +\fBno\fR, or \fBoff\fR, then \fBTcl_GetBoolean\fR stores a zero +value at \fI*boolPtr\fR. +If \fIsrc\fR is any of \fB1\fR, \fBtrue\fR, \fByes\fR, or \fBon\fR, +then 1 is stored at \fI*boolPtr\fR. +Any of these values may be abbreviated, and upper-case spellings +are also acceptable. + +.SH KEYWORDS +boolean, conversion, double, floating-point, integer diff --git a/tcl8.6/doc/GetOpnFl.3 b/tcl8.6/doc/GetOpnFl.3 new file mode 100644 index 0000000..86d1b94 --- /dev/null +++ b/tcl8.6/doc/GetOpnFl.3 @@ -0,0 +1,58 @@ +'\" +'\" Copyright (c) 1996-1997 Sun Microsystems, Inc. +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH Tcl_GetOpenFile 3 8.0 Tcl "Tcl Library Procedures" +.so man.macros +.BS +.SH NAME +Tcl_GetOpenFile \- Return a FILE* for a channel registered in the given interpreter (Unix only) +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +int +\fBTcl_GetOpenFile\fR(\fIinterp, chanID, write, checkUsage, filePtr\fR) +.sp +.SH ARGUMENTS +.AS Tcl_Interp checkUsage out +.AP Tcl_Interp *interp in +Tcl interpreter from which file handle is to be obtained. +.AP "const char" *chanID in +String identifying channel, such as \fBstdin\fR or \fBfile4\fR. +.AP int write in +Non-zero means the file will be used for writing, zero means it will +be used for reading. +.AP int checkUsage in +If non-zero, then an error will be generated if the file was not opened +for the access indicated by \fIwrite\fR. +.AP ClientData *filePtr out +Points to word in which to store pointer to FILE structure for +the file given by \fIchanID\fR. +.BE + +.SH DESCRIPTION +.PP +\fBTcl_GetOpenFile\fR takes as argument a file identifier of the form +returned by the \fBopen\fR command and +returns at \fI*filePtr\fR a pointer to the FILE structure for +the file. +The \fIwrite\fR argument indicates whether the FILE pointer will +be used for reading or writing. +In some cases, such as a channel that connects to a pipeline of +subprocesses, different FILE pointers will be returned for reading +and writing. +\fBTcl_GetOpenFile\fR normally returns \fBTCL_OK\fR. +If an error occurs in \fBTcl_GetOpenFile\fR (e.g. \fIchanID\fR did not +make any sense or \fIcheckUsage\fR was set and the file was not opened +for the access specified by \fIwrite\fR) then \fBTCL_ERROR\fR is returned +and the interpreter's result will contain an error message. +In the current implementation \fIcheckUsage\fR is ignored and consistency +checks are always performed. +.PP +Note that this interface is only supported on the Unix platform. + +.SH KEYWORDS +channel, file handle, permissions, pipeline, read, write diff --git a/tcl8.6/doc/GetStdChan.3 b/tcl8.6/doc/GetStdChan.3 new file mode 100644 index 0000000..be0e79f --- /dev/null +++ b/tcl8.6/doc/GetStdChan.3 @@ -0,0 +1,86 @@ +'\" +'\" Copyright (c) 1996 by Sun Microsystems, Inc. +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH Tcl_GetStdChannel 3 7.5 Tcl "Tcl Library Procedures" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +Tcl_GetStdChannel, Tcl_SetStdChannel \- procedures for retrieving and replacing the standard channels +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +Tcl_Channel +\fBTcl_GetStdChannel\fR(\fItype\fR) +.sp +\fBTcl_SetStdChannel\fR(\fIchannel, type\fR) +.sp +.SH ARGUMENTS +.AS Tcl_Channel channel +.AP int type in +The identifier for the standard channel to retrieve or modify. Must be one of +\fBTCL_STDIN\fR, \fBTCL_STDOUT\fR, or \fBTCL_STDERR\fR. +.AP Tcl_Channel channel in +The channel to use as the new value for the specified standard channel. +.BE + +.SH DESCRIPTION +.PP +Tcl defines three special channels that are used by various I/O related +commands if no other channels are specified. The standard input channel +has a channel name of \fBstdin\fR and is used by \fBread\fR and \fBgets\fR. +The standard output channel is named \fBstdout\fR and is used by +\fBputs\fR. The standard error channel is named \fBstderr\fR and is used for +reporting errors. In addition, the standard channels are inherited by any +child processes created using \fBexec\fR or \fBopen\fR in the absence of any +other redirections. +.PP +The standard channels are actually aliases for other normal channels. The +current channel associated with a standard channel can be retrieved by calling +\fBTcl_GetStdChannel\fR with one of +\fBTCL_STDIN\fR, \fBTCL_STDOUT\fR, or \fBTCL_STDERR\fR as the \fItype\fR. The +return value will be a valid channel, or NULL. +.PP +A new channel can be set for the standard channel specified by \fItype\fR +by calling \fBTcl_SetStdChannel\fR with a new channel or NULL in the +\fIchannel\fR argument. If the specified channel is closed by a later call to +\fBTcl_Close\fR, then the corresponding standard channel will automatically be +set to NULL. +.PP +If a non-NULL value for \fIchannel\fR is passed to \fBTcl_SetStdChannel\fR, +then that same value should be passed to \fBTcl_RegisterChannel\fR, like so: +.PP +.CS +Tcl_RegisterChannel(NULL, channel); +.CE +.PP +This is a workaround for a misfeature in \fBTcl_SetStdChannel\fR that it +fails to do some reference counting housekeeping. This misfeature cannot +be corrected without contradicting the assumptions of some existing +code that calls \fBTcl_SetStdChannel\fR. +.PP +If \fBTcl_GetStdChannel\fR is called before \fBTcl_SetStdChannel\fR, Tcl will +construct a new channel to wrap the appropriate platform-specific standard +file handle. If \fBTcl_SetStdChannel\fR is called before +\fBTcl_GetStdChannel\fR, then the default channel will not be created. +.PP +If one of the standard channels is set to NULL, either by calling +\fBTcl_SetStdChannel\fR with a NULL \fIchannel\fR argument, or by calling +\fBTcl_Close\fR on the channel, then the next call to \fBTcl_CreateChannel\fR +will automatically set the standard channel with the newly created channel. If +more than one standard channel is NULL, then the standard channels will be +assigned starting with standard input, followed by standard output, with +standard error being last. +.PP +See \fBTcl_StandardChannels\fR for a general treatise about standard +channels and the behavior of the Tcl library with regard to them. + +.SH "SEE ALSO" +Tcl_Close(3), Tcl_CreateChannel(3), Tcl_Main(3), tclsh(1) + +.SH KEYWORDS +standard channel, standard input, standard output, standard error diff --git a/tcl8.6/doc/GetTime.3 b/tcl8.6/doc/GetTime.3 new file mode 100644 index 0000000..6b885ee --- /dev/null +++ b/tcl8.6/doc/GetTime.3 @@ -0,0 +1,109 @@ +'\" +'\" Copyright (c) 2001 by Kevin B. Kenny <kennykb@acm.org>. +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH Tcl_GetTime 3 8.4 Tcl "Tcl Library Procedures" +.so man.macros +.BS +.SH NAME +Tcl_GetTime, Tcl_SetTimeProc, Tcl_QueryTimeProc \- get date and time +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +\fBTcl_GetTime\fR(\fItimePtr\fR) +.sp +\fBTcl_SetTimeProc\fR(\fIgetProc, scaleProc, clientData\fR) +.sp +\fBTcl_QueryTimeProc\fR(\fIgetProcPtr, scaleProcPtr, clientDataPtr\fR) +.SH ARGUMENTS +.AS Tcl_GetTimeProc *getProc in +.AP Tcl_Time *timePtr out +Points to memory in which to store the date and time information. +.AP Tcl_GetTimeProc getProc in +Pointer to handler function replacing \fBTcl_GetTime\fR's access to the OS. +.AP Tcl_ScaleTimeProc scaleProc in +Pointer to handler function for the conversion of time delays in the +virtual domain to real-time. +.AP ClientData clientData in +Value passed through to the two handler functions. +.AP Tcl_GetTimeProc *getProcPtr out +Pointer to place the currently registered get handler function into. +.AP Tcl_ScaleTimeProc *scaleProcPtr out +Pointer to place the currently registered scale handler function into. +.AP ClientData *clientDataPtr out +Pointer to place the currently registered pass-through value into. +.BE +.SH DESCRIPTION +.PP +The \fBTcl_GetTime\fR function retrieves the current time as a +\fITcl_Time\fR structure in memory the caller provides. This +structure has the following definition: +.PP +.CS +typedef struct Tcl_Time { + long \fIsec\fR; + long \fIusec\fR; +} \fBTcl_Time\fR; +.CE +.PP +On return, the \fIsec\fR member of the structure is filled in with the +number of seconds that have elapsed since the \fIepoch:\fR the epoch +is the point in time of 00:00 UTC, 1 January 1970. This number does +\fInot\fR count leap seconds \- an interval of one day advances it by +86400 seconds regardless of whether a leap second has been inserted. +.PP +The \fIusec\fR member of the structure is filled in with the number of +microseconds that have elapsed since the start of the second +designated by \fIsec\fR. The Tcl library makes every effort to keep +this number as precise as possible, subject to the limitations of the +computer system. On multiprocessor variants of Windows, this number +may be limited to the 10- or 20-ms granularity of the system clock. +(On single-processor Windows systems, the \fIusec\fR field is derived +from a performance counter and is highly precise.) +.SS "VIRTUALIZED TIME" +.PP +The \fBTcl_SetTimeProc\fR function registers two related handler functions +with the core. The first handler function is a replacement for +\fBTcl_GetTime\fR, or rather the OS access made by +\fBTcl_GetTime\fR. The other handler function is used by the Tcl +notifier to convert wait/block times from the virtual domain into real +time. +.PP +The \fBTcl_QueryTimeProc\fR function returns the currently registered +handler functions. If no external handlers were set then this will +return the standard handlers accessing and processing the native time +of the OS. The arguments to the function are allowed to be NULL; and +any argument which is NULL is ignored and not set. +.PP +The signatures of the handler functions are as follows: +.PP +.CS +typedef void \fBTcl_GetTimeProc\fR( + Tcl_Time *\fItimebuf\fR, + ClientData \fIclientData\fR); +typedef void \fBTcl_ScaleTimeProc\fR( + Tcl_Time *\fItimebuf\fR, + ClientData \fIclientData\fR); +.CE +.PP +The \fItimebuf\fR fields contain the time to manipulate, and the +\fIclientData\fR fields contain a pointer supplied at the time the handler +functions were registered. +.PP +Any handler pair specified has to return data which is consistent between +them. In other words, setting one handler of the pair to something assuming a +10-times slowdown, and the other handler of the pair to something assuming a +two-times slowdown is wrong and not allowed. +.PP +The set handler functions are allowed to run the delivered time backwards, +however this should be avoided. We have to allow it as the native time can run +backwards as the user can fiddle with the system time one way or other. Note +that the insertion of the hooks will not change the behavior of the Tcl core +with regard to this situation, i.e. the existing behavior is retained. +.SH "SEE ALSO" +clock(n) +.SH KEYWORDS +date, time diff --git a/tcl8.6/doc/GetVersion.3 b/tcl8.6/doc/GetVersion.3 new file mode 100644 index 0000000..3672382 --- /dev/null +++ b/tcl8.6/doc/GetVersion.3 @@ -0,0 +1,48 @@ +'\" +'\" Copyright (c) 1999 Scriptics Corporation +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH Tcl_GetVersion 3 7.5 Tcl "Tcl Library Procedures" +.so man.macros +.BS +.SH NAME +Tcl_GetVersion \- get the version of the library at runtime +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +\fBTcl_GetVersion\fR(\fImajor, minor, patchLevel, type\fR) +.SH ARGUMENTS +.AS Tcl_ReleaseType *patchLevel out +.AP int *major out +Major version number of the Tcl library. +.AP int *minor out +Minor version number of the Tcl library. +.AP int *patchLevel out +The patch level of the Tcl library (or alpha or beta number). +.AP Tcl_ReleaseType *type out +The type of release, also indicates the type of patch level. Can be +one of \fBTCL_ALPHA_RELEASE\fR, \fBTCL_BETA_RELEASE\fR, or +\fBTCL_FINAL_RELEASE\fR. +.BE + +.SH DESCRIPTION +.PP +\fBTcl_GetVersion\fR should be used to query the version number +of the Tcl library at runtime. This is useful when using a +dynamically loaded Tcl library or when writing a stubs-aware +extension. For instance, if you write an extension that is +linked against the Tcl stubs library, it could be loaded into +a program linked to an older version of Tcl than you expected. +Use \fBTcl_GetVersion\fR to verify that fact, and possibly to +change the behavior of your extension. +.PP +\fBTcl_GetVersion\fR accepts NULL for any of the arguments. For instance if +you do not care about the \fIpatchLevel\fR of the library, pass +a NULL for the \fIpatchLevel\fR argument. + +.SH KEYWORDS +version, patchlevel, major, minor, alpha, beta, release + diff --git a/tcl8.6/doc/Hash.3 b/tcl8.6/doc/Hash.3 new file mode 100644 index 0000000..4dc3623 --- /dev/null +++ b/tcl8.6/doc/Hash.3 @@ -0,0 +1,334 @@ +'\" +'\" Copyright (c) 1989-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. +'\" +.TH Tcl_Hash 3 "" Tcl "Tcl Library Procedures" +.so man.macros +.BS +.SH NAME +Tcl_InitHashTable, Tcl_InitCustomHashTable, Tcl_InitObjHashTable, Tcl_DeleteHashTable, Tcl_CreateHashEntry, Tcl_DeleteHashEntry, Tcl_FindHashEntry, Tcl_GetHashValue, Tcl_SetHashValue, Tcl_GetHashKey, Tcl_FirstHashEntry, Tcl_NextHashEntry, Tcl_HashStats \- procedures to manage hash tables +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +\fBTcl_InitHashTable\fR(\fItablePtr, keyType\fR) +.sp +\fBTcl_InitCustomHashTable\fR(\fItablePtr, keyType, typePtr\fR) +.sp +\fBTcl_InitObjHashTable\fR(\fItablePtr\fR) +.sp +\fBTcl_DeleteHashTable\fR(\fItablePtr\fR) +.sp +Tcl_HashEntry * +\fBTcl_CreateHashEntry\fR(\fItablePtr, key, newPtr\fR) +.sp +\fBTcl_DeleteHashEntry\fR(\fIentryPtr\fR) +.sp +Tcl_HashEntry * +\fBTcl_FindHashEntry\fR(\fItablePtr, key\fR) +.sp +ClientData +\fBTcl_GetHashValue\fR(\fIentryPtr\fR) +.sp +\fBTcl_SetHashValue\fR(\fIentryPtr, value\fR) +.sp +void * +\fBTcl_GetHashKey\fR(\fItablePtr, entryPtr\fR) +.sp +Tcl_HashEntry * +\fBTcl_FirstHashEntry\fR(\fItablePtr, searchPtr\fR) +.sp +Tcl_HashEntry * +\fBTcl_NextHashEntry\fR(\fIsearchPtr\fR) +.sp +char * +\fBTcl_HashStats\fR(\fItablePtr\fR) +.SH ARGUMENTS +.AS "const Tcl_HashKeyType" *searchPtr out +.AP Tcl_HashTable *tablePtr in +Address of hash table structure (for all procedures but +\fBTcl_InitHashTable\fR, this must have been initialized by +previous call to \fBTcl_InitHashTable\fR). +.AP int keyType in +Kind of keys to use for new hash table. Must be either +\fBTCL_STRING_KEYS\fR, \fBTCL_ONE_WORD_KEYS\fR, \fBTCL_CUSTOM_TYPE_KEYS\fR, +\fBTCL_CUSTOM_PTR_KEYS\fR, or an integer value greater than 1. +.AP Tcl_HashKeyType *typePtr in +Address of structure which defines the behavior of the hash table. +.AP "const void" *key in +Key to use for probe into table. Exact form depends on +\fIkeyType\fR used to create table. +.AP int *newPtr out +The word at \fI*newPtr\fR is set to 1 if a new entry was created +and 0 if there was already an entry for \fIkey\fR. +.AP Tcl_HashEntry *entryPtr in +Pointer to hash table entry. +.AP ClientData value in +New value to assign to hash table entry. Need not have type +ClientData, but must fit in same space as ClientData. +.AP Tcl_HashSearch *searchPtr in +Pointer to record to use to keep track of progress in enumerating +all the entries in a hash table. +.BE +.SH DESCRIPTION +.PP +A hash table consists of zero or more entries, each consisting of a +key and a value. Given the key for an entry, the hashing routines can +very quickly locate the entry, and hence its value. There may be at +most one entry in a hash table with a particular key, but many entries +may have the same value. Keys can take one of four forms: strings, +one-word values, integer arrays, or custom keys defined by a +Tcl_HashKeyType structure (See section \fBTHE TCL_HASHKEYTYPE STRUCTURE\fR +below). All of the keys in a given table have the same +form, which is specified when the table is initialized. +.PP +The value of a hash table entry can be anything that fits in the same +space as a +.QW "char *" +pointer. Values for hash table entries are +managed entirely by clients, not by the hash module itself. Typically +each entry's value is a pointer to a data structure managed by client +code. +.PP +Hash tables grow gracefully as the number of entries increases, so +that there are always less than three entries per hash bucket, on +average. This allows for fast lookups regardless of the number of +entries in a table. +.PP +The core provides three functions for the initialization of hash +tables, Tcl_InitHashTable, Tcl_InitObjHashTable and +Tcl_InitCustomHashTable. +.PP +\fBTcl_InitHashTable\fR initializes a structure that describes a new +hash table. The space for the structure is provided by the caller, +not by the hash module. The value of \fIkeyType\fR indicates what +kinds of keys will be used for all entries in the table. All of the +key types described later are allowed, with the exception of +\fBTCL_CUSTOM_TYPE_KEYS\fR and \fBTCL_CUSTOM_PTR_KEYS\fR. +.PP +\fBTcl_InitObjHashTable\fR is a wrapper around +\fBTcl_InitCustomHashTable\fR and initializes a hash table whose keys +are Tcl_Obj *. +.PP +\fBTcl_InitCustomHashTable\fR initializes a structure that describes a +new hash table. The space for the structure is provided by the +caller, not by the hash module. The value of \fIkeyType\fR indicates +what kinds of keys will be used for all entries in the table. +\fIKeyType\fR must have one of the following values: +.IP \fBTCL_STRING_KEYS\fR 25 +Keys are null-terminated strings. +They are passed to hashing routines using the address of the +first character of the string. +.IP \fBTCL_ONE_WORD_KEYS\fR 25 +Keys are single-word values; they are passed to hashing routines +and stored in hash table entries as +.QW "char *" +values. +The pointer value is the key; it need not (and usually does not) +actually point to a string. +.IP \fBTCL_CUSTOM_TYPE_KEYS\fR 25 +Keys are of arbitrary type, and are stored in the entry. Hashing +and comparison is determined by \fItypePtr\fR. The Tcl_HashKeyType +structure is described in the section +\fBTHE TCL_HASHKEYTYPE STRUCTURE\fR below. +.IP \fBTCL_CUSTOM_PTR_KEYS\fR 25 +Keys are pointers to an arbitrary type, and are stored in the entry. Hashing +and comparison is determined by \fItypePtr\fR. The Tcl_HashKeyType +structure is described in the section +\fBTHE TCL_HASHKEYTYPE STRUCTURE\fR below. +.IP \fIother\fR 25 +If \fIkeyType\fR is not one of the above, +then it must be an integer value greater than 1. +In this case the keys will be arrays of +.QW int +values, where +\fIkeyType\fR gives the number of ints in each key. +This allows structures to be used as keys. +All keys must have the same size. +Array keys are passed into hashing functions using the address +of the first int in the array. +.PP +\fBTcl_DeleteHashTable\fR deletes all of the entries in a hash +table and frees up the memory associated with the table's +bucket array and entries. +It does not free the actual table structure (pointed to +by \fItablePtr\fR), since that memory is assumed to be managed +by the client. +\fBTcl_DeleteHashTable\fR also does not free or otherwise +manipulate the values of the hash table entries. +If the entry values point to dynamically-allocated memory, then +it is the client's responsibility to free these structures +before deleting the table. +.PP +\fBTcl_CreateHashEntry\fR locates the entry corresponding to a +particular key, creating a new entry in the table if there +was not already one with the given key. +If an entry already existed with the given key then \fI*newPtr\fR +is set to zero. +If a new entry was created, then \fI*newPtr\fR is set to a non-zero +value and the value of the new entry will be set to zero. +The return value from \fBTcl_CreateHashEntry\fR is a pointer to +the entry, which may be used to retrieve and modify the entry's +value or to delete the entry from the table. +.PP +\fBTcl_DeleteHashEntry\fR will remove an existing entry from a +table. +The memory associated with the entry itself will be freed, but +the client is responsible for any cleanup associated with the +entry's value, such as freeing a structure that it points to. +.PP +\fBTcl_FindHashEntry\fR is similar to \fBTcl_CreateHashEntry\fR +except that it does not create a new entry if the key doesn't exist; +instead, it returns NULL as result. +.PP +\fBTcl_GetHashValue\fR and \fBTcl_SetHashValue\fR are used to +read and write an entry's value, respectively. +Values are stored and retrieved as type +.QW ClientData , +which is +large enough to hold a pointer value. On almost all machines this is +large enough to hold an integer value too. +.PP +\fBTcl_GetHashKey\fR returns the key for a given hash table entry, +either as a pointer to a string, a one-word +.PQ "char *" +key, or +as a pointer to the first word of an array of integers, depending +on the \fIkeyType\fR used to create a hash table. +In all cases \fBTcl_GetHashKey\fR returns a result with type +.QW "char *" . +When the key is a string or array, the result of \fBTcl_GetHashKey\fR +points to information in the table entry; this information will +remain valid until the entry is deleted or its table is deleted. +.PP +\fBTcl_FirstHashEntry\fR and \fBTcl_NextHashEntry\fR may be used +to scan all of the entries in a hash table. +A structure of type +.QW Tcl_HashSearch , +provided by the client, +is used to keep track of progress through the table. +\fBTcl_FirstHashEntry\fR initializes the search record and +returns the first entry in the table (or NULL if the table is +empty). +Each subsequent call to \fBTcl_NextHashEntry\fR returns the +next entry in the table or +NULL if the end of the table has been reached. +A call to \fBTcl_FirstHashEntry\fR followed by calls to +\fBTcl_NextHashEntry\fR will return each of the entries in +the table exactly once, in an arbitrary order. +It is inadvisable to modify the structure of the table, e.g. +by creating or deleting entries, while the search is in progress, +with the exception of deleting the entry returned by +\fBTcl_FirstHashEntry\fR or \fBTcl_NextHashEntry\fR. +.PP +\fBTcl_HashStats\fR returns a dynamically-allocated string with +overall information about a hash table, such as the number of +entries it contains, the number of buckets in its hash array, +and the utilization of the buckets. +It is the caller's responsibility to free the result string +by passing it to \fBckfree\fR. +.PP +The header file \fBtcl.h\fR defines the actual data structures +used to implement hash tables. +This is necessary so that clients can allocate Tcl_HashTable +structures and so that macros can be used to read and write +the values of entries. +However, users of the hashing routines should never refer directly +to any of the fields of any of the hash-related data structures; +use the procedures and macros defined here. +.SH "THE TCL_HASHKEYTYPE STRUCTURE" +.PP +Extension writers can define new hash key types by defining four procedures, +initializing a \fBTcl_HashKeyType\fR structure to describe the type, and +calling \fBTcl_InitCustomHashTable\fR. The \fBTcl_HashKeyType\fR structure is +defined as follows: +.PP +.CS +typedef struct Tcl_HashKeyType { + int \fIversion\fR; + int \fIflags\fR; + Tcl_HashKeyProc *\fIhashKeyProc\fR; + Tcl_CompareHashKeysProc *\fIcompareKeysProc\fR; + Tcl_AllocHashEntryProc *\fIallocEntryProc\fR; + Tcl_FreeHashEntryProc *\fIfreeEntryProc\fR; +} \fBTcl_HashKeyType\fR; +.CE +.PP +The \fIversion\fR member is the version of the table. If this structure is +extended in future then the version can be used to distinguish between +different structures. It should be set to \fBTCL_HASH_KEY_TYPE_VERSION\fR. +.PP +The \fIflags\fR member is 0 or one or more of the following values OR'ed +together: +.IP \fBTCL_HASH_KEY_RANDOMIZE_HASH\fR 25 +There are some things, pointers for example which do not hash well because +they do not use the lower bits. If this flag is set then the hash table will +attempt to rectify this by randomizing the bits and then using the upper N +bits as the index into the table. +.IP \fBTCL_HASH_KEY_SYSTEM_HASH\fR 25 +This flag forces Tcl to use the memory allocation procedures provided by the +operating system when allocating and freeing memory used to store the hash +table data structures, and not any of Tcl's own customized memory allocation +routines. This is important if the hash table is to be used in the +implementation of a custom set of allocation routines, or something that a +custom set of allocation routines might depend on, in order to avoid any +circular dependency. +.PP +The \fIhashKeyProc\fR member contains the address of a function called to +calculate a hash value for the key. +.PP +.CS +typedef unsigned int \fBTcl_HashKeyProc\fR( + Tcl_HashTable *\fItablePtr\fR, + void *\fIkeyPtr\fR); +.CE +.PP +If this is NULL then \fIkeyPtr\fR is used and +\fBTCL_HASH_KEY_RANDOMIZE_HASH\fR is assumed. +.PP +The \fIcompareKeysProc\fR member contains the address of a function called to +compare two keys. +.PP +.CS +typedef int \fBTcl_CompareHashKeysProc\fR( + void *\fIkeyPtr\fR, + Tcl_HashEntry *\fIhPtr\fR); +.CE +.PP +If this is NULL then the \fIkeyPtr\fR pointers are compared. If the keys do +not match then the function returns 0, otherwise it returns 1. +.PP +The \fIallocEntryProc\fR member contains the address of a function called to +allocate space for an entry and initialize the key and clientData. +.PP +.CS +typedef Tcl_HashEntry *\fBTcl_AllocHashEntryProc\fR( + Tcl_HashTable *\fItablePtr\fR, + void *\fIkeyPtr\fR); +.CE +.PP +If this is NULL then \fBTcl_Alloc\fR is used to allocate enough space for a +Tcl_HashEntry, the key pointer is assigned to key.oneWordValue and the +clientData is set to NULL. String keys and array keys use this function to +allocate enough space for the entry and the key in one block, rather than +doing it in two blocks. This saves space for a pointer to the key from the +entry and another memory allocation. Tcl_Obj* keys use this function to +allocate enough space for an entry and increment the reference count on the +value. +.PP +The \fIfreeEntryProc\fR member contains the address of a function called to +free space for an entry. +.PP +.CS +typedef void \fBTcl_FreeHashEntryProc\fR( + Tcl_HashEntry *\fIhPtr\fR); +.CE +.PP +If this is NULL then \fBTcl_Free\fR is used to free the space for the entry. +Tcl_Obj* keys use this function to decrement the reference count on the +value. +.SH KEYWORDS +hash table, key, lookup, search, value diff --git a/tcl8.6/doc/Init.3 b/tcl8.6/doc/Init.3 new file mode 100644 index 0000000..33c27a3 --- /dev/null +++ b/tcl8.6/doc/Init.3 @@ -0,0 +1,34 @@ +'\" +'\" Copyright (c) 1998-2000 by Scriptics Corporation. +'\" All rights reserved. +'\" +.TH Tcl_Init 3 8.0 Tcl "Tcl Library Procedures" +.so man.macros +.BS +.SH NAME +Tcl_Init \- find and source initialization script +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +int +\fBTcl_Init\fR(\fIinterp\fR) +.SH ARGUMENTS +.AS Tcl_Interp *interp +.AP Tcl_Interp *interp in +Interpreter to initialize. +.BE + +.SH DESCRIPTION +.PP +\fBTcl_Init\fR is a helper procedure that finds and \fBsource\fRs the +\fBinit.tcl\fR script, which should exist somewhere on the Tcl library +path. +.PP +\fBTcl_Init\fR is typically called from \fBTcl_AppInit\fR procedures. + +.SH "SEE ALSO" +Tcl_AppInit, Tcl_Main + +.SH KEYWORDS +application, initialization, interpreter diff --git a/tcl8.6/doc/InitStubs.3 b/tcl8.6/doc/InitStubs.3 new file mode 100644 index 0000000..73c3437 --- /dev/null +++ b/tcl8.6/doc/InitStubs.3 @@ -0,0 +1,89 @@ +'\" +'\" Copyright (c) 1998-1999 Scriptics Corporation +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH Tcl_InitStubs 3 8.1 Tcl "Tcl Library Procedures" +.so man.macros +.BS +.SH NAME +Tcl_InitStubs \- initialize the Tcl stubs mechanism +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +const char * +\fBTcl_InitStubs\fR(\fIinterp, version, exact\fR) +.SH ARGUMENTS +.AS Tcl_Interp *interp +.AP Tcl_Interp *interp in +Tcl interpreter handle. +.AP "const char" *version in +A version string consisting of one or more decimal numbers +separated by dots. +.AP int exact in +Non-zero means that only the particular version specified by +\fIversion\fR is acceptable. +Zero means that versions newer than \fIversion\fR are also +acceptable as long as they have the same major version number +as \fIversion\fR. +.BE +.SH INTRODUCTION +.PP +The Tcl stubs mechanism defines a way to dynamically bind +extensions to a particular Tcl implementation at run time. +This provides two significant benefits to Tcl users: +.IP 1) 5 +Extensions that use the stubs mechanism can be loaded into +multiple versions of Tcl without being recompiled or +relinked. +.IP 2) 5 +Extensions that use the stubs mechanism can be dynamically +loaded into statically-linked Tcl applications. +.PP +The stubs mechanism accomplishes this by exporting function tables +that define an interface to the Tcl API. The extension then accesses +the Tcl API through offsets into the function table, so there are no +direct references to any of the Tcl library's symbols. This +redirection is transparent to the extension, so an extension writer +can continue to use all public Tcl functions as documented. +.PP +The stubs mechanism requires no changes to applications incorporating +Tcl interpreters. Only developers creating C-based Tcl extensions +need to take steps to use the stubs mechanism with their extensions. +.PP +Enabling the stubs mechanism for an extension requires the following +steps: +.IP 1) 5 +Call \fBTcl_InitStubs\fR in the extension before calling any other +Tcl functions. +.IP 2) 5 +Define the \fBUSE_TCL_STUBS\fR symbol. Typically, you would include the +\fB\-DUSE_TCL_STUBS\fR flag when compiling the extension. +.IP 3) 5 +Link the extension with the Tcl stubs library instead of the standard +Tcl library. For example, to use the Tcl 8.6 ABI on Unix platforms, +the library name is \fIlibtclstub8.6.a\fR; on Windows platforms, the +library name is \fItclstub86.lib\fR. +.PP +If the extension also requires the Tk API, it must also call +\fBTk_InitStubs\fR to initialize the Tk stubs interface and link +with the Tk stubs libraries. See the \fBTk_InitStubs\fR page for +more information. +.SH DESCRIPTION +\fBTcl_InitStubs\fR attempts to initialize the stub table pointers +and ensure that the correct version of Tcl is loaded. In addition +to an interpreter handle, it accepts as arguments a version number +and a Boolean flag indicating whether the extension requires +an exact version match or not. If \fIexact\fR is 0, then the +extension is indicating that newer versions of Tcl are acceptable +as long as they have the same major version number as \fIversion\fR; +non-zero means that only the specified \fIversion\fR is acceptable. +\fBTcl_InitStubs\fR returns a string containing the actual version +of Tcl satisfying the request, or NULL if the Tcl version is not +acceptable, does not support stubs, or any other error condition occurred. +.SH "SEE ALSO" +Tk_InitStubs +.SH KEYWORDS +stubs diff --git a/tcl8.6/doc/IntObj.3 b/tcl8.6/doc/IntObj.3 new file mode 100644 index 0000000..2acb446 --- /dev/null +++ b/tcl8.6/doc/IntObj.3 @@ -0,0 +1,152 @@ +'\" +'\" Copyright (c) 1996-1997 Sun Microsystems, Inc. +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH Tcl_IntObj 3 8.5 Tcl "Tcl Library Procedures" +.so man.macros +.BS +.SH NAME +Tcl_NewIntObj, Tcl_NewLongObj, Tcl_NewWideIntObj, Tcl_SetIntObj, Tcl_SetLongObj, Tcl_SetWideIntObj, Tcl_GetIntFromObj, Tcl_GetLongFromObj, Tcl_GetWideIntFromObj, Tcl_NewBignumObj, Tcl_SetBignumObj, Tcl_GetBignumFromObj, Tcl_TakeBignumFromObj \- manipulate Tcl values as integers +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +Tcl_Obj * +\fBTcl_NewIntObj\fR(\fIintValue\fR) +.sp +Tcl_Obj * +\fBTcl_NewLongObj\fR(\fIlongValue\fR) +.sp +Tcl_Obj * +\fBTcl_NewWideIntObj\fR(\fIwideValue\fR) +.sp +\fBTcl_SetIntObj\fR(\fIobjPtr, intValue\fR) +.sp +\fBTcl_SetLongObj\fR(\fIobjPtr, longValue\fR) +.sp +\fBTcl_SetWideIntObj\fR(\fIobjPtr, wideValue\fR) +.sp +int +\fBTcl_GetIntFromObj\fR(\fIinterp, objPtr, intPtr\fR) +.sp +int +\fBTcl_GetLongFromObj\fR(\fIinterp, objPtr, longPtr\fR) +.sp +int +\fBTcl_GetWideIntFromObj\fR(\fIinterp, objPtr, widePtr\fR) +.sp +.sp +\fB#include <tclTomMath.h>\fR +.sp +Tcl_Obj * +\fBTcl_NewBignumObj\fR(\fIbigValue\fR) +.sp +\fBTcl_SetBignumObj\fR(\fIobjPtr, bigValue\fR) +.sp +int +\fBTcl_GetBignumFromObj\fR(\fIinterp, objPtr, bigValue\fR) +.sp +int +\fBTcl_TakeBignumFromObj\fR(\fIinterp, objPtr, bigValue\fR) +.sp +int +\fBTcl_InitBignumFromDouble\fR(\fIinterp, doubleValue, bigValue\fR) +.SH ARGUMENTS +.AS Tcl_WideInt doubleValue in/out +.AP int intValue in +Integer value used to initialize or set a Tcl value. +.AP long longValue in +Long integer value used to initialize or set a Tcl value. +.AP Tcl_WideInt wideValue in +Wide integer value used to initialize or set a Tcl value. +.AP Tcl_Obj *objPtr in/out +For \fBTcl_SetIntObj\fR, \fBTcl_SetLongObj\fR, \fBTcl_SetWideIntObj\fR, +and \fBTcl_SetBignumObj\fR, this points to the value in which to store an +integral value. For \fBTcl_GetIntFromObj\fR, \fBTcl_GetLongFromObj\fR, +\fBTcl_GetWideIntFromObj\fR, \fBTcl_GetBignumFromObj\fR, and +\fBTcl_TakeBignumFromObj\fR, this refers to the value from which +to retrieve an integral value. +.AP Tcl_Interp *interp in/out +When non-NULL, an error message is left here when integral value +retrieval fails. +.AP int *intPtr out +Points to place to store the integer value retrieved from \fIobjPtr\fR. +.AP long *longPtr out +Points to place to store the long integer value retrieved from \fIobjPtr\fR. +.AP Tcl_WideInt *widePtr out +Points to place to store the wide integer value retrieved from \fIobjPtr\fR. +.AP mp_int *bigValue in/out +Points to a multi-precision integer structure declared by the LibTomMath +library. +.AP double doubleValue in +Double value from which the integer part is determined and +used to initialize a multi-precision integer value. +.BE +.SH DESCRIPTION +.PP +These procedures are used to create, modify, and read Tcl values +that hold integral values. +.PP +The different routines exist to accommodate different integral types in C +with which values might be exchanged. The C integral types for which Tcl +provides value exchange routines are \fBint\fR, \fBlong int\fR, +\fBTcl_WideInt\fR, and \fBmp_int\fR. The \fBint\fR and \fBlong int\fR types +are provided by the C language standard. The \fBTcl_WideInt\fR type is a +typedef defined to be whatever signed integral type covers at least the +64-bit integer range (-9223372036854775808 to 9223372036854775807). Depending +on the platform and the C compiler, the actual type might be +\fBlong int\fR, \fBlong long int\fR, \fB__int64\fR, or something else. +The \fBmp_int\fR type is a multiple-precision integer type defined +by the LibTomMath multiple-precision integer library. +.PP +The \fBTcl_NewIntObj\fR, \fBTcl_NewLongObj\fR, \fBTcl_NewWideIntObj\fR, +and \fBTcl_NewBignumObj\fR routines each create and return a new +Tcl value initialized to the integral value of the argument. The +returned Tcl value is unshared. +.PP +The \fBTcl_SetIntObj\fR, \fBTcl_SetLongObj\fR, \fBTcl_SetWideIntObj\fR, +and \fBTcl_SetBignumObj\fR routines each set the value of an existing +Tcl value pointed to by \fIobjPtr\fR to the integral value provided +by the other argument. The \fIobjPtr\fR argument must point to an +unshared Tcl value. Any attempt to set the value of a shared Tcl value +violates Tcl's copy-on-write policy. Any existing string representation +or internal representation in the unshared Tcl value will be freed +as a consequence of setting the new value. +.PP +The \fBTcl_GetIntFromObj\fR, \fBTcl_GetLongFromObj\fR, +\fBTcl_GetWideIntFromObj\fR, \fBTcl_GetBignumFromObj\fR, and +\fBTcl_TakeBignumFromObj\fR routines attempt to retrieve an integral +value of the appropriate type from the Tcl value \fIobjPtr\fR. If the +attempt succeeds, then \fBTCL_OK\fR is returned, and the value is +written to the storage provided by the caller. The attempt might +fail if \fIobjPtr\fR does not hold an integral value, or if the +value exceeds the range of the target type. If the attempt fails, +then \fBTCL_ERROR\fR is returned, and if \fIinterp\fR is non-NULL, +an error message is left in \fIinterp\fR. The \fBTcl_ObjType\fR +of \fIobjPtr\fR may be changed to make subsequent calls to the +same routine more efficient. Unlike the other functions, +\fBTcl_TakeBignumFromObj\fR may set the content of the Tcl value +\fIobjPtr\fR to an empty string in the process of retrieving the +multiple-precision integer value. +.PP +The choice between \fBTcl_GetBignumFromObj\fR and +\fBTcl_TakeBignumFromObj\fR is governed by how the caller will +continue to use \fIobjPtr\fR. If after the \fBmp_int\fR value +is retrieved from \fIobjPtr\fR, the caller will make no more +use of \fIobjPtr\fR, then using \fBTcl_TakeBignumFromObj\fR +permits Tcl to detect when an unshared \fIobjPtr\fR permits the +value to be moved instead of copied, which should be more efficient. +If anything later in the caller requires +\fIobjPtr\fR to continue to hold the same value, then +\fBTcl_GetBignumFromObj\fR must be chosen. +.PP +The \fBTcl_InitBignumFromDouble\fR routine is a utility procedure +that extracts the integer part of \fIdoubleValue\fR and stores that +integer value in the \fBmp_int\fR value \fIbigValue\fR. +.SH "SEE ALSO" +Tcl_NewObj, Tcl_DecrRefCount, Tcl_IncrRefCount, Tcl_GetObjResult +.SH KEYWORDS +integer, integer value, integer type, internal representation, value, +value type, string representation diff --git a/tcl8.6/doc/Interp.3 b/tcl8.6/doc/Interp.3 new file mode 100644 index 0000000..731007b --- /dev/null +++ b/tcl8.6/doc/Interp.3 @@ -0,0 +1,134 @@ +'\" +'\" Copyright (c) 1989-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. +'\" +.TH Tcl_Interp 3 7.5 Tcl "Tcl Library Procedures" +.so man.macros +.BS +.SH NAME +Tcl_Interp \- client-visible fields of interpreter structures +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +typedef struct { + char *\fIresult\fR; + Tcl_FreeProc *\fIfreeProc\fR; + int \fIerrorLine\fR; +} \fBTcl_Interp\fR; + +typedef void \fBTcl_FreeProc\fR( + char *\fIblockPtr\fR); +.BE +.SH DESCRIPTION +.PP +The \fBTcl_CreateInterp\fR procedure returns a pointer to a Tcl_Interp +structure. Callers of \fBTcl_CreateInterp\fR should use this pointer +as an opaque token, suitable for nothing other than passing back to +other routines in the Tcl interface. Accessing fields directly through +the pointer as described below is no longer supported. The supported +public routines \fBTcl_SetResult\fR, \fBTcl_GetResult\fR, +\fBTcl_SetErrorLine\fR, \fBTcl_GetErrorLine\fR must be used instead. +.PP +For legacy programs and extensions no longer being maintained, compiles +against the Tcl 8.6 header files are only possible with the compiler +directives +.CS +#define USE_INTERP_RESULT +.CE +and/or +.CS +#define USE_INTERP_ERRORLINE +.CE +depending on which fields of the \fBTcl_Interp\fR struct are accessed. +These directives may be embedded in code or supplied via compiler options. +.PP +The \fIresult\fR and \fIfreeProc\fR fields are used to return +results or error messages from commands. +This information is returned by command procedures back to \fBTcl_Eval\fR, +and by \fBTcl_Eval\fR back to its callers. +The \fIresult\fR field points to the string that represents the +result or error message, and the \fIfreeProc\fR field tells how +to dispose of the storage for the string when it is not needed anymore. +The easiest way for command procedures to manipulate these +fields is to call procedures like \fBTcl_SetResult\fR +or \fBTcl_AppendResult\fR; they +will hide all the details of managing the fields. +The description below is for those procedures that manipulate the +fields directly. +.PP +Whenever a command procedure returns, it must ensure +that the \fIresult\fR field of its interpreter points to the string +being returned by the command. +The \fIresult\fR field must always point to a valid string. +If a command wishes to return no result then \fIinterp->result\fR +should point to an empty string. +Normally, results are assumed to be statically allocated, +which means that the contents will not change before the next time +\fBTcl_Eval\fR is called or some other command procedure is invoked. +In this case, the \fIfreeProc\fR field must be zero. +Alternatively, a command procedure may dynamically +allocate its return value (e.g. using \fBTcl_Alloc\fR) +and store a pointer to it in \fIinterp->result\fR. +In this case, the command procedure must also set \fIinterp->freeProc\fR +to the address of a procedure that can free the value, or \fBTCL_DYNAMIC\fR +if the storage was allocated directly by Tcl or by a call to +\fBTcl_Alloc\fR. +If \fIinterp->freeProc\fR is non-zero, then Tcl will call \fIfreeProc\fR +to free the space pointed to by \fIinterp->result\fR before it +invokes the next command. +If a client procedure overwrites \fIinterp->result\fR when +\fIinterp->freeProc\fR is non-zero, then it is responsible for calling +\fIfreeProc\fR to free the old \fIinterp->result\fR (the \fBTcl_FreeResult\fR +macro should be used for this purpose). +.PP +\fIFreeProc\fR should have arguments and result that match the +\fBTcl_FreeProc\fR declaration above: it receives a single +argument which is a pointer to the result value to free. +In most applications \fBTCL_DYNAMIC\fR is the only non-zero value ever +used for \fIfreeProc\fR. +However, an application may store a different procedure address +in \fIfreeProc\fR in order to use an alternate memory allocator +or in order to do other cleanup when the result memory is freed. +.PP +As part of processing each command, \fBTcl_Eval\fR initializes +\fIinterp->result\fR +and \fIinterp->freeProc\fR just before calling the command procedure for +the command. The \fIfreeProc\fR field will be initialized to zero, +and \fIinterp->result\fR will point to an empty string. Commands that +do not return any value can simply leave the fields alone. +Furthermore, the empty string pointed to by \fIresult\fR is actually +part of an array of \fBTCL_RESULT_SIZE\fR characters (approximately 200). +If a command wishes to return a short string, it can simply copy +it to the area pointed to by \fIinterp->result\fR. Or, it can use +the sprintf procedure to generate a short result string at the location +pointed to by \fIinterp->result\fR. +.PP +It is a general convention in Tcl-based applications that the result +of an interpreter is normally in the initialized state described +in the previous paragraph. +Procedures that manipulate an interpreter's result (e.g. by +returning an error) will generally assume that the result +has been initialized when the procedure is called. +If such a procedure is to be called after the result has been +changed, then \fBTcl_ResetResult\fR should be called first to +reset the result to its initialized state. The direct use of +\fIinterp->result\fR is strongly deprecated (see \fBTcl_SetResult\fR). +.PP +The \fIerrorLine\fR +field is valid only after \fBTcl_Eval\fR returns +a \fBTCL_ERROR\fR return code. In this situation the \fIerrorLine\fR +field identifies the line number of the command being executed when +the error occurred. The line numbers are relative to the command +being executed: 1 means the first line of the command passed to +\fBTcl_Eval\fR, 2 means the second line, and so on. +The \fIerrorLine\fR field is typically used in conjunction with +\fBTcl_AddErrorInfo\fR to report information about where an error +occurred. +\fIErrorLine\fR should not normally be modified except by \fBTcl_Eval\fR. + +.SH KEYWORDS +free, initialized, interpreter, malloc, result diff --git a/tcl8.6/doc/Limit.3 b/tcl8.6/doc/Limit.3 new file mode 100644 index 0000000..20a2e02 --- /dev/null +++ b/tcl8.6/doc/Limit.3 @@ -0,0 +1,192 @@ +'\" +'\" Copyright (c) 2004 Donal K. Fellows +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH Tcl_LimitCheck 3 8.5 Tcl "Tcl Library Procedures" +.so man.macros +.BS +.SH NAME +Tcl_LimitAddHandler, Tcl_LimitCheck, Tcl_LimitExceeded, Tcl_LimitGetCommands, Tcl_LimitGetGranularity, Tcl_LimitGetTime, Tcl_LimitReady, Tcl_LimitRemoveHandler, Tcl_LimitSetCommands, Tcl_LimitSetGranularity, Tcl_LimitSetTime, Tcl_LimitTypeEnabled, Tcl_LimitTypeExceeded, Tcl_LimitTypeReset, Tcl_LimitTypeSet \- manage and check resource limits on interpreters +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +int +\fBTcl_LimitCheck\fR(\fIinterp\fR) +.sp +int +\fBTcl_LimitReady\fR(\fIinterp\fR) +.sp +int +\fBTcl_LimitExceeded\fR(\fIinterp\fR) +.sp +int +\fBTcl_LimitTypeExceeded\fR(\fIinterp, type\fR) +.sp +int +\fBTcl_LimitTypeEnabled\fR(\fIinterp, type\fR) +.sp +void +\fBTcl_LimitTypeSet\fR(\fIinterp, type\fR) +.sp +void +\fBTcl_LimitTypeReset\fR(\fIinterp, type\fR) +.sp +int +\fBTcl_LimitGetCommands\fR(\fIinterp\fR) +.sp +void +\fBTcl_LimitSetCommands\fR(\fIinterp, commandLimit\fR) +.sp +void +\fBTcl_LimitGetTime\fR(\fIinterp, timeLimitPtr\fR) +.sp +void +\fBTcl_LimitSetTime\fR(\fIinterp, timeLimitPtr\fR) +.sp +int +\fBTcl_LimitGetGranularity\fR(\fIinterp, type\fR) +.sp +void +\fBTcl_LimitSetGranularity\fR(\fIinterp, type, granularity\fR) +.sp +void +\fBTcl_LimitAddHandler\fR(\fIinterp, type, handlerProc, clientData, deleteProc\fR) +.sp +void +\fBTcl_LimitRemoveHandler\fR(\fIinterp, type, handlerProc, clientData\fR) +.SH ARGUMENTS +.AS Tcl_LimitHandlerDeleteProc commandLimit in/out +.AP Tcl_Interp *interp in +Interpreter that the limit being managed applies to or that will have +its limits checked. +.AP int type in +The type of limit that the operation refers to. This must be either +\fBTCL_LIMIT_COMMANDS\fR or \fBTCL_LIMIT_TIME\fR. +.AP int commandLimit in +The maximum number of commands (as reported by \fBinfo cmdcount\fR) +that may be executed in the interpreter. +.AP Tcl_Time *timeLimitPtr in/out +A pointer to a structure that will either have the new time limit read +from (\fBTcl_LimitSetTime\fR) or the current time limit written to +(\fBTcl_LimitGetTime\fR). +.AP int granularity in +Divisor that indicates how often a particular limit should really be +checked. Must be at least 1. +.AP Tcl_LimitHandlerProc *handlerProc in +Function to call when a particular limit is exceeded. If the +\fIhandlerProc\fR removes or raises the limit during its processing, +the limited interpreter will be permitted to continue to process after +the handler returns. Many handlers may be attached to the same +interpreter limit; their order of execution is not defined, and they +must be identified by \fIhandlerProc\fR and \fIclientData\fR when they +are deleted. +.AP ClientData clientData in +Arbitrary pointer-sized word used to pass some context to the +\fIhandlerProc\fR function. +.AP Tcl_LimitHandlerDeleteProc *deleteProc in +Function to call whenever a handler is deleted. May be NULL if the +\fIclientData\fR requires no deletion. +.BE +.SH DESCRIPTION +.PP +Tcl's interpreter resource limit subsystem allows for close control +over how much computation time a script may use, and is useful for +cases where a program is divided into multiple pieces where some parts +are more trusted than others (e.g. web application servers). +.PP +Every interpreter may have a limit on the wall-time for execution, and +a limit on the number of commands that the interpreter may execute. +Since checking of these limits is potentially expensive (especially +the time limit), each limit also has a checking granularity, which is +a divisor for an internal count of the number of points in the core +where a check may be performed (which is immediately before executing +a command and at an unspecified frequency between running commands, +which can happen in empty-bodied \fBwhile\fR loops). +.PP +The final component of the limit engine is a callback scheme which +allows for notifications of when a limit has been exceeded. These +callbacks can just provide logging, or may allocate more resources to +the interpreter to permit it to continue processing longer. +.PP +When a limit is exceeded (and the callbacks have run; the order of +execution of the callbacks is unspecified) execution in the limited +interpreter is stopped by raising an error and setting a flag that +prevents the \fBcatch\fR command in that interpreter from trapping +that error. It is up to the context that started execution in that +interpreter (typically a master interpreter) to handle the error. +.SH "LIMIT CHECKING API" +.PP +To check the resource limits for an interpreter, call +\fBTcl_LimitCheck\fR, which returns \fBTCL_OK\fR if the limit was not +exceeded (after processing callbacks) and \fBTCL_ERROR\fR if the limit was +exceeded (in which case an error message is also placed in the +interpreter result). That function should only be called when +\fBTcl_LimitReady\fR returns non-zero so that granularity policy is +enforced. This API is designed to be similar in usage to +\fBTcl_AsyncReady\fR and \fBTcl_AsyncInvoke\fR. +.PP +When writing code that may behave like \fBcatch\fR in respect of +errors, you should only trap an error if \fBTcl_LimitExceeded\fR +returns zero. If it returns non-zero, the interpreter is in a +limit-exceeded state and errors should be allowed to propagate to the +calling context. You can also check whether a particular type of +limit has been exceeded using \fBTcl_LimitTypeExceeded\fR. +.SH "LIMIT CONFIGURATION" +.PP +To check whether a limit has been set (but not whether it has actually +been exceeded) on an interpreter, call \fBTcl_LimitTypeEnabled\fR with +the type of limit you want to check. To enable a particular limit +call \fBTcl_LimitTypeSet\fR, and to disable a limit call +\fBTcl_LimitTypeReset\fR. +.PP +The level of a command limit may be set using +\fBTcl_LimitSetCommands\fR, and retrieved using +\fBTcl_LimitGetCommands\fR. Similarly for a time limit with +\fBTcl_LimitSetTime\fR and \fBTcl_LimitGetTime\fR respectively, but +with that API the time limit is copied from and to the Tcl_Time +structure that the \fItimeLimitPtr\fR argument points to. +.PP +The checking granularity for a particular limit may be set using +\fBTcl_LimitSetGranularity\fR and retrieved using +\fBTcl_LimitGetGranularity\fR. Note that granularities must always be +positive. +.SS "LIMIT CALLBACKS" +.PP +To add a handler callback to be invoked when a limit is exceeded, call +\fBTcl_LimitAddHandler\fR. The \fIhandlerProc\fR argument describes +the function that will actually be called; it should have the +following prototype: +.PP +.CS +typedef void \fBTcl_LimitHandlerProc\fR( + ClientData \fIclientData\fR, + Tcl_Interp *\fIinterp\fR); +.CE +.PP +The \fIclientData\fR argument to the handler will be whatever is +passed to the \fIclientData\fR argument to \fBTcl_LimitAddHandler\fR, +and the \fIinterp\fR is the interpreter that had its limit exceeded. +.PP +The \fIdeleteProc\fR argument to \fBTcl_LimitAddHandler\fR is a +function to call to delete the \fIclientData\fR value. It may be +\fBTCL_STATIC\fR or NULL if no deletion action is necessary, or +\fBTCL_DYNAMIC\fR if all that is necessary is to free the structure with +\fBTcl_Free\fR. Otherwise, it should refer to a function with the +following prototype: +.PP +.CS +typedef void \fBTcl_LimitHandlerDeleteProc\fR( + ClientData \fIclientData\fR); +.CE +.PP +A limit handler may be deleted using \fBTcl_LimitRemoveHandler\fR; the +handler removed will be the first one found (out of the handlers added +with \fBTcl_LimitAddHandler\fR) with exactly matching \fItype\fR, +\fIhandlerProc\fR and \fIclientData\fR arguments. This function +always invokes the \fIdeleteProc\fR on the \fIclientData\fR (unless +the \fIdeleteProc\fR was NULL or \fBTCL_STATIC\fR). +.SH KEYWORDS +interpreter, resource, limit, commands, time, callback diff --git a/tcl8.6/doc/LinkVar.3 b/tcl8.6/doc/LinkVar.3 new file mode 100644 index 0000000..c80d30d --- /dev/null +++ b/tcl8.6/doc/LinkVar.3 @@ -0,0 +1,231 @@ +'\" +'\" Copyright (c) 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. +'\" +.TH Tcl_LinkVar 3 7.5 Tcl "Tcl Library Procedures" +.so man.macros +.BS +.SH NAME +Tcl_LinkVar, Tcl_UnlinkVar, Tcl_UpdateLinkedVar \- link Tcl variable to C variable +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +int +\fBTcl_LinkVar\fR(\fIinterp, varName, addr, type\fR) +.sp +\fBTcl_UnlinkVar\fR(\fIinterp, varName\fR) +.sp +\fBTcl_UpdateLinkedVar\fR(\fIinterp, varName\fR) +.SH ARGUMENTS +.AS Tcl_Interp writable +.AP Tcl_Interp *interp in +Interpreter that contains \fIvarName\fR. +Also used by \fBTcl_LinkVar\fR to return error messages. +.AP "const char" *varName in +Name of global variable. +.AP char *addr in +Address of C variable that is to be linked to \fIvarName\fR. +.AP int type in +Type of C variable. Must be one of \fBTCL_LINK_INT\fR, +\fBTCL_LINK_UINT\fR, \fBTCL_LINK_CHAR\fR, \fBTCL_LINK_UCHAR\fR, +\fBTCL_LINK_SHORT\fR, \fBTCL_LINK_USHORT\fR, \fBTCL_LINK_LONG\fR, +\fBTCL_LINK_ULONG\fR, \fBTCL_LINK_WIDE_INT\fR, +\fBTCL_LINK_WIDE_UINT\fR, \fBTCL_LINK_FLOAT\fR, +\fBTCL_LINK_DOUBLE\fR, \fBTCL_LINK_BOOLEAN\fR, or +\fBTCL_LINK_STRING\fR, optionally OR'ed with \fBTCL_LINK_READ_ONLY\fR +to make Tcl variable read-only. +.BE +.SH DESCRIPTION +.PP +\fBTcl_LinkVar\fR uses variable traces to keep the Tcl variable +named by \fIvarName\fR in sync with the C variable at the address +given by \fIaddr\fR. +Whenever the Tcl variable is read the value of the C variable will +be returned, and whenever the Tcl variable is written the C +variable will be updated to have the same value. +\fBTcl_LinkVar\fR normally returns \fBTCL_OK\fR; if an error occurs +while setting up the link (e.g. because \fIvarName\fR is the +name of array) then \fBTCL_ERROR\fR is returned and the interpreter's result +contains an error message. +.PP +The \fItype\fR argument specifies the type of the C variable, +and must have one of the following values, optionally OR'ed with +\fBTCL_LINK_READ_ONLY\fR: +.TP +\fBTCL_LINK_INT\fR +The C variable is of type \fBint\fR. +Any value written into the Tcl variable must have a proper integer +form acceptable to \fBTcl_GetIntFromObj\fR; attempts to write +non-integer values into \fIvarName\fR will be rejected with +Tcl errors. Incomplete integer representations (like the empty +string, '+', '-' or the hex/octal/binary prefix) are accepted +as if they are valid too. +.TP +\fBTCL_LINK_UINT\fR +The C variable is of type \fBunsigned int\fR. +Any value written into the Tcl variable must have a proper unsigned +integer form acceptable to \fBTcl_GetWideIntFromObj\fR and in the +platform's defined range for the \fBunsigned int\fR type; attempts to +write non-integer values (or values outside the range) into +\fIvarName\fR will be rejected with Tcl errors. Incomplete integer +representations (like the empty string, '+', '-' or the hex/octal/binary +prefix) are accepted as if they are valid too. +.TP +\fBTCL_LINK_CHAR\fR +The C variable is of type \fBchar\fR. +Any value written into the Tcl variable must have a proper integer +form acceptable to \fBTcl_GetIntFromObj\fR and be in the range of the +\fBchar\fR datatype; attempts to write non-integer or out-of-range +values into \fIvarName\fR will be rejected with Tcl errors. Incomplete +integer representations (like the empty string, '+', '-' or the +hex/octal/binary prefix) are accepted as if they are valid too. +.TP +\fBTCL_LINK_UCHAR\fR +The C variable is of type \fBunsigned char\fR. +Any value written into the Tcl variable must have a proper unsigned +integer form acceptable to \fBTcl_GetIntFromObj\fR and in the +platform's defined range for the \fBunsigned char\fR type; attempts to +write non-integer values (or values outside the range) into +\fIvarName\fR will be rejected with Tcl errors. Incomplete integer +representations (like the empty string, '+', '-' or the hex/octal/binary +prefix) are accepted as if they are valid too. +.TP +\fBTCL_LINK_SHORT\fR +The C variable is of type \fBshort\fR. +Any value written into the Tcl variable must have a proper integer +form acceptable to \fBTcl_GetIntFromObj\fR and be in the range of the +\fBshort\fR datatype; attempts to write non-integer or out-of-range +values into \fIvarName\fR will be rejected with Tcl errors. Incomplete +integer representations (like the empty string, '+', '-' or the +hex/octal/binary prefix) are accepted as if they are valid too. +.TP +\fBTCL_LINK_USHORT\fR +The C variable is of type \fBunsigned short\fR. +Any value written into the Tcl variable must have a proper unsigned +integer form acceptable to \fBTcl_GetIntFromObj\fR and in the +platform's defined range for the \fBunsigned short\fR type; attempts to +write non-integer values (or values outside the range) into +\fIvarName\fR will be rejected with Tcl errors. Incomplete integer +representations (like the empty string, '+', '-' or the hex/octal/binary +prefix) are accepted as if they are valid too. +.TP +\fBTCL_LINK_LONG\fR +The C variable is of type \fBlong\fR. +Any value written into the Tcl variable must have a proper integer +form acceptable to \fBTcl_GetLongFromObj\fR; attempts to write +non-integer or out-of-range +values into \fIvarName\fR will be rejected with Tcl errors. Incomplete +integer representations (like the empty string, '+', '-' or the +hex/octal/binary prefix) are accepted as if they are valid too. +.TP +\fBTCL_LINK_ULONG\fR +The C variable is of type \fBunsigned long\fR. +Any value written into the Tcl variable must have a proper unsigned +integer form acceptable to \fBTcl_GetWideIntFromObj\fR and in the +platform's defined range for the \fBunsigned long\fR type; attempts to +write non-integer values (or values outside the range) into +\fIvarName\fR will be rejected with Tcl errors. Incomplete integer +representations (like the empty string, '+', '-' or the hex/octal/binary +prefix) are accepted as if they are valid too. +.TP +\fBTCL_LINK_DOUBLE\fR +The C variable is of type \fBdouble\fR. +Any value written into the Tcl variable must have a proper real +form acceptable to \fBTcl_GetDoubleFromObj\fR; attempts to write +non-real values into \fIvarName\fR will be rejected with +Tcl errors. Incomplete integer or real representations (like the +empty string, '.', '+', '-' or the hex/octal/binary prefix) are +accepted as if they are valid too. +.TP +\fBTCL_LINK_FLOAT\fR +The C variable is of type \fBfloat\fR. +Any value written into the Tcl variable must have a proper real +form acceptable to \fBTcl_GetDoubleFromObj\fR and must be within the +range acceptable for a \fBfloat\fR; attempts to +write non-real values (or values outside the range) into +\fIvarName\fR will be rejected with Tcl errors. Incomplete integer +or real representations (like the empty string, '.', '+', '-' or +the hex/octal/binary prefix) are accepted as if they are valid too. +.TP +\fBTCL_LINK_WIDE_INT\fR +The C variable is of type \fBTcl_WideInt\fR (which is an integer type +at least 64-bits wide on all platforms that can support it.) +Any value written into the Tcl variable must have a proper integer +form acceptable to \fBTcl_GetWideIntFromObj\fR; attempts to write +non-integer values into \fIvarName\fR will be rejected with +Tcl errors. Incomplete integer representations (like the empty +string, '+', '-' or the hex/octal/binary prefix) are accepted +as if they are valid too. +.TP +\fBTCL_LINK_WIDE_UINT\fR +The C variable is of type \fBTcl_WideUInt\fR (which is an unsigned +integer type at least 64-bits wide on all platforms that can support +it.) +Any value written into the Tcl variable must have a proper unsigned +integer form acceptable to \fBTcl_GetWideIntFromObj\fR (it will be +cast to unsigned); +.\" FIXME! Use bignums instead. +attempts to write non-integer values into \fIvarName\fR will be +rejected with Tcl errors. Incomplete integer representations (like +the empty string, '+', '-' or the hex/octal/binary prefix) are accepted +as if they are valid too. +.TP +\fBTCL_LINK_BOOLEAN\fR +The C variable is of type \fBint\fR. +If its value is zero then it will read from Tcl as +.QW 0 ; +otherwise it will read from Tcl as +.QW 1 . +Whenever \fIvarName\fR is +modified, the C variable will be set to a 0 or 1 value. +Any value written into the Tcl variable must have a proper boolean +form acceptable to \fBTcl_GetBooleanFromObj\fR; attempts to write +non-boolean values into \fIvarName\fR will be rejected with +Tcl errors. +.TP +\fBTCL_LINK_STRING\fR +The C variable is of type \fBchar *\fR. +If its value is not NULL then it must be a pointer to a string +allocated with \fBTcl_Alloc\fR or \fBckalloc\fR. +Whenever the Tcl variable is modified the current C string will be +freed and new memory will be allocated to hold a copy of the variable's +new value. +If the C variable contains a NULL pointer then the Tcl variable +will read as +.QW NULL . +.PP +If the \fBTCL_LINK_READ_ONLY\fR flag is present in \fItype\fR then the +variable will be read-only from Tcl, so that its value can only be +changed by modifying the C variable. +Attempts to write the variable from Tcl will be rejected with errors. +.PP +\fBTcl_UnlinkVar\fR removes the link previously set up for the +variable given by \fIvarName\fR. If there does not exist a link +for \fIvarName\fR then the procedure has no effect. +.PP +\fBTcl_UpdateLinkedVar\fR may be invoked after the C variable has +changed to force the Tcl variable to be updated immediately. +In many cases this procedure is not needed, since any attempt to +read the Tcl variable will return the latest value of the C variable. +However, if a trace has been set on the Tcl variable (such as a +Tk widget that wishes to display the value of the variable), the +trace will not trigger when the C variable has changed. +\fBTcl_UpdateLinkedVar\fR ensures that any traces on the Tcl +variable are invoked. +.PP +Note that, as with any call to a Tcl interpreter, \fBTcl_UpdateLinkedVar\fR +must be called from the same thread that created the interpreter. The safest +mechanism is to ensure that the C variable is only ever updated from the same +thread that created the interpreter (possibly in response to an event posted +with \fBTcl_ThreadQueueEvent\fR), but when it is necessary to update the +variable in a separate thread, it is advised that \fBTcl_AsyncMark\fR be used +to indicate to the thread hosting the interpreter that it is ready to run +\fBTcl_UpdateLinkedVar\fR. +.SH "SEE ALSO" +Tcl_TraceVar(3) +.SH KEYWORDS +boolean, integer, link, read-only, real, string, trace, variable diff --git a/tcl8.6/doc/ListObj.3 b/tcl8.6/doc/ListObj.3 new file mode 100644 index 0000000..dc1ba53 --- /dev/null +++ b/tcl8.6/doc/ListObj.3 @@ -0,0 +1,251 @@ +'\" +'\" Copyright (c) 1996-1997 Sun Microsystems, Inc. +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH Tcl_ListObj 3 8.0 Tcl "Tcl Library Procedures" +.so man.macros +.BS +.SH NAME +Tcl_ListObjAppendList, Tcl_ListObjAppendElement, Tcl_NewListObj, Tcl_SetListObj, Tcl_ListObjGetElements, Tcl_ListObjLength, Tcl_ListObjIndex, Tcl_ListObjReplace \- manipulate Tcl values as lists +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +int +\fBTcl_ListObjAppendList\fR(\fIinterp, listPtr, elemListPtr\fR) +.sp +int +\fBTcl_ListObjAppendElement\fR(\fIinterp, listPtr, objPtr\fR) +.sp +Tcl_Obj * +\fBTcl_NewListObj\fR(\fIobjc, objv\fR) +.sp +\fBTcl_SetListObj\fR(\fIobjPtr, objc, objv\fR) +.sp +int +\fBTcl_ListObjGetElements\fR(\fIinterp, listPtr, objcPtr, objvPtr\fR) +.sp +int +\fBTcl_ListObjLength\fR(\fIinterp, listPtr, intPtr\fR) +.sp +int +\fBTcl_ListObjIndex\fR(\fIinterp, listPtr, index, objPtrPtr\fR) +.sp +int +\fBTcl_ListObjReplace\fR(\fIinterp, listPtr, first, count, objc, objv\fR) +.SH ARGUMENTS +.AS "Tcl_Obj *const" *elemListPtr in/out +.AP Tcl_Interp *interp in +If an error occurs while converting a value to be a list value, +an error message is left in the interpreter's result value +unless \fIinterp\fR is NULL. +.AP Tcl_Obj *listPtr in/out +Points to the list value to be manipulated. +If \fIlistPtr\fR does not already point to a list value, +an attempt will be made to convert it to one. +.AP Tcl_Obj *elemListPtr in/out +For \fBTcl_ListObjAppendList\fR, this points to a list value +containing elements to be appended onto \fIlistPtr\fR. +Each element of *\fIelemListPtr\fR will +become a new element of \fIlistPtr\fR. +If *\fIelemListPtr\fR is not NULL and +does not already point to a list value, +an attempt will be made to convert it to one. +.AP Tcl_Obj *objPtr in +For \fBTcl_ListObjAppendElement\fR, +points to the Tcl value that will be appended to \fIlistPtr\fR. +For \fBTcl_SetListObj\fR, +this points to the Tcl value that will be converted to a list value +containing the \fIobjc\fR elements of the array referenced by \fIobjv\fR. +.AP int *objcPtr in +Points to location where \fBTcl_ListObjGetElements\fR +stores the number of element values in \fIlistPtr\fR. +.AP Tcl_Obj ***objvPtr out +A location where \fBTcl_ListObjGetElements\fR stores a pointer to an array +of pointers to the element values of \fIlistPtr\fR. +.AP int objc in +The number of Tcl values that \fBTcl_NewListObj\fR +will insert into a new list value, +and \fBTcl_ListObjReplace\fR will insert into \fIlistPtr\fR. +For \fBTcl_SetListObj\fR, +the number of Tcl values to insert into \fIobjPtr\fR. +.AP "Tcl_Obj *const" objv[] in +An array of pointers to values. +\fBTcl_NewListObj\fR will insert these values into a new list value +and \fBTcl_ListObjReplace\fR will insert them into an existing \fIlistPtr\fR. +Each value will become a separate list element. +.AP int *intPtr out +Points to location where \fBTcl_ListObjLength\fR +stores the length of the list. +.AP int index in +Index of the list element that \fBTcl_ListObjIndex\fR +is to return. +The first element has index 0. +.AP Tcl_Obj **objPtrPtr out +Points to place where \fBTcl_ListObjIndex\fR is to store +a pointer to the resulting list element value. +.AP int first in +Index of the starting list element that \fBTcl_ListObjReplace\fR +is to replace. +The list's first element has index 0. +.AP int count in +The number of elements that \fBTcl_ListObjReplace\fR +is to replace. +.BE + +.SH DESCRIPTION +.PP +Tcl list values have an internal representation that supports +the efficient indexing and appending. +The procedures described in this man page are used to +create, modify, index, and append to Tcl list values from C code. +.PP +\fBTcl_ListObjAppendList\fR and \fBTcl_ListObjAppendElement\fR +both add one or more values +to the end of the list value referenced by \fIlistPtr\fR. +\fBTcl_ListObjAppendList\fR appends each element of the list value +referenced by \fIelemListPtr\fR while +\fBTcl_ListObjAppendElement\fR appends the single value +referenced by \fIobjPtr\fR. +Both procedures will convert the value referenced by \fIlistPtr\fR +to a list value if necessary. +If an error occurs during conversion, +both procedures return \fBTCL_ERROR\fR and leave an error message +in the interpreter's result value if \fIinterp\fR is not NULL. +Similarly, if \fIelemListPtr\fR does not already refer to a list value, +\fBTcl_ListObjAppendList\fR will attempt to convert it to one +and if an error occurs during conversion, +will return \fBTCL_ERROR\fR +and leave an error message in the interpreter's result value +if interp is not NULL. +Both procedures invalidate any old string representation of \fIlistPtr\fR +and, if it was converted to a list value, +free any old internal representation. +Similarly, \fBTcl_ListObjAppendList\fR frees any old internal representation +of \fIelemListPtr\fR if it converts it to a list value. +After appending each element in \fIelemListPtr\fR, +\fBTcl_ListObjAppendList\fR increments the element's reference count +since \fIlistPtr\fR now also refers to it. +For the same reason, \fBTcl_ListObjAppendElement\fR +increments \fIobjPtr\fR's reference count. +If no error occurs, +the two procedures return \fBTCL_OK\fR after appending the values. +.PP +\fBTcl_NewListObj\fR and \fBTcl_SetListObj\fR +create a new value or modify an existing value to hold +the \fIobjc\fR elements of the array referenced by \fIobjv\fR +where each element is a pointer to a Tcl value. +If \fIobjc\fR is less than or equal to zero, +they return an empty value. +The new value's string representation is left invalid. +The two procedures increment the reference counts +of the elements in \fIobjc\fR since the list value now refers to them. +The new list value returned by \fBTcl_NewListObj\fR +has reference count zero. +.PP +\fBTcl_ListObjGetElements\fR returns a count and a pointer to an array of +the elements in a list value. It returns the count by storing it in the +address \fIobjcPtr\fR. Similarly, it returns the array pointer by storing +it in the address \fIobjvPtr\fR. +The memory pointed to is managed by Tcl and should not be freed or written +to by the caller. If the list is empty, 0 is stored at \fIobjcPtr\fR +and NULL at \fIobjvPtr\fR. +If \fIlistPtr\fR is not already a list value, \fBTcl_ListObjGetElements\fR +will attempt to convert it to one; if the conversion fails, it returns +\fBTCL_ERROR\fR and leaves an error message in the interpreter's result +value if \fIinterp\fR is not NULL. +Otherwise it returns \fBTCL_OK\fR after storing the count and array pointer. +.PP +\fBTcl_ListObjLength\fR returns the number of elements in the list value +referenced by \fIlistPtr\fR. +It returns this count by storing an integer in the address \fIintPtr\fR. +If the value is not already a list value, +\fBTcl_ListObjLength\fR will attempt to convert it to one; +if the conversion fails, it returns \fBTCL_ERROR\fR +and leaves an error message in the interpreter's result value +if \fIinterp\fR is not NULL. +Otherwise it returns \fBTCL_OK\fR after storing the list's length. +.PP +The procedure \fBTcl_ListObjIndex\fR returns a pointer to the value +at element \fIindex\fR in the list referenced by \fIlistPtr\fR. +It returns this value by storing a pointer to it +in the address \fIobjPtrPtr\fR. +If \fIlistPtr\fR does not already refer to a list value, +\fBTcl_ListObjIndex\fR will attempt to convert it to one; +if the conversion fails, it returns \fBTCL_ERROR\fR +and leaves an error message in the interpreter's result value +if \fIinterp\fR is not NULL. +If the index is out of range, +that is, \fIindex\fR is negative or +greater than or equal to the number of elements in the list, +\fBTcl_ListObjIndex\fR stores a NULL in \fIobjPtrPtr\fR +and returns \fBTCL_OK\fR. +Otherwise it returns \fBTCL_OK\fR after storing the element's +value pointer. +The reference count for the list element is not incremented; +the caller must do that if it needs to retain a pointer to the element. +.PP +\fBTcl_ListObjReplace\fR replaces zero or more elements +of the list referenced by \fIlistPtr\fR +with the \fIobjc\fR values in the array referenced by \fIobjv\fR. +If \fIlistPtr\fR does not point to a list value, +\fBTcl_ListObjReplace\fR will attempt to convert it to one; +if the conversion fails, it returns \fBTCL_ERROR\fR +and leaves an error message in the interpreter's result value +if \fIinterp\fR is not NULL. +Otherwise, it returns \fBTCL_OK\fR after replacing the values. +If \fIobjv\fR is NULL, no new elements are added. +If the argument \fIfirst\fR is zero or negative, +it refers to the first element. +If \fIfirst\fR is greater than or equal to the +number of elements in the list, then no elements are deleted; +the new elements are appended to the list. +\fIcount\fR gives the number of elements to replace. +If \fIcount\fR is zero or negative then no elements are deleted; +the new elements are simply inserted before the one +designated by \fIfirst\fR. +\fBTcl_ListObjReplace\fR invalidates \fIlistPtr\fR's +old string representation. +The reference counts of any elements inserted from \fIobjv\fR +are incremented since the resulting list now refers to them. +Similarly, the reference counts for any replaced values are decremented. +.PP +Because \fBTcl_ListObjReplace\fR combines +both element insertion and deletion, +it can be used to implement a number of list operations. +For example, the following code inserts the \fIobjc\fR values +referenced by the array of value pointers \fIobjv\fR +just before the element \fIindex\fR of the list referenced by \fIlistPtr\fR: +.PP +.CS +result = \fBTcl_ListObjReplace\fR(interp, listPtr, index, 0, + objc, objv); +.CE +.PP +Similarly, the following code appends the \fIobjc\fR values +referenced by the array \fIobjv\fR +to the end of the list \fIlistPtr\fR: +.PP +.CS +result = \fBTcl_ListObjLength\fR(interp, listPtr, &length); +if (result == TCL_OK) { + result = \fBTcl_ListObjReplace\fR(interp, listPtr, length, 0, + objc, objv); +} +.CE +.PP +The \fIcount\fR list elements starting at \fIfirst\fR can be deleted +by simply calling \fBTcl_ListObjReplace\fR +with a NULL \fIobjvPtr\fR: +.PP +.CS +result = \fBTcl_ListObjReplace\fR(interp, listPtr, first, count, + 0, NULL); +.CE +.SH "SEE ALSO" +Tcl_NewObj(3), Tcl_DecrRefCount(3), Tcl_IncrRefCount(3), Tcl_GetObjResult(3) +.SH KEYWORDS +append, index, insert, internal representation, length, list, list value, +list type, value, value type, replace, string representation diff --git a/tcl8.6/doc/Load.3 b/tcl8.6/doc/Load.3 new file mode 100644 index 0000000..0ffaf57 --- /dev/null +++ b/tcl8.6/doc/Load.3 @@ -0,0 +1,70 @@ +'\" +'\" Copyright (c) 2009-2010 Kevin B. Kenny +'\" Copyright (c) 2010 Donal K. Fellows +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH Load 3 8.6 Tcl "Tcl Library Procedures" +.so man.macros +.BS +.SH NAME +Tcl_LoadFile, Tcl_FindSymbol \- platform-independent dynamic library loading +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +int +\fBTcl_LoadFile\fR(\fIinterp, pathPtr, symbols, flags, procPtrs, loadHandlePtr\fR) +.sp +void * +\fBTcl_FindSymbol\fR(\fIinterp, loadHandle, symbol\fR) +.SH ARGUMENTS +.AS Tcl_LoadHandle loadHandle in +.AP Tcl_Interp *interp in +Interpreter to use for reporting error messages. +.AP Tcl_Obj *pathPtr in +The name of the file to load. If it is a single name, the library search path +of the current environment will be used to resolve it. +.AP "const char *const" symbols[] in +Array of names of symbols to be resolved during the load of the library, or +NULL if no symbols are to be resolved. If an array is given, the last entry in +the array must be NULL. +.AP int flags in +The value should normally be 0, but \fITCL_LOAD_GLOBAL\fR or \fITCL_LOAD_LAZY\fR +or a combination of those two is allowed as well. +.AP void *procPtrs out +Points to an array that will hold the addresses of the functions described in +the \fIsymbols\fR argument. Should be NULL if no symbols are to be resolved. +.AP Tcl_LoadHandle *loadHandlePtr out +Points to a variable that will hold the handle to the abstract token +describing the library that has been loaded. +.AP Tcl_LoadHandle loadHandle in +Abstract token describing the library to look up a symbol in. +.AP "const char" *symbol in +The name of the symbol to look up. +.BE +.SH DESCRIPTION +.PP +\fBTcl_LoadFile\fR loads a file from the filesystem (including potentially any +virtual filesystem that has been installed) and provides a handle to it that +may be used in further operations. The \fIsymbols\fR array, if non-NULL, +supplies a set of names of symbols (typically functions) that must be resolved +from the library and which will be stored in the array indicated by +\fIprocPtrs\fR. If any of the symbols is not resolved, the loading of the file +will fail with an error message left in the interpreter (if that is non-NULL). +The result of \fBTcl_LoadFile\fR is a standard Tcl error code. The library may +be unloaded with \fBTcl_FSUnloadFile\fR. +.PP +\fBTcl_FindSymbol\fR locates a symbol in a loaded library and returns it. If +the symbol cannot be found, it returns NULL and sets an error message in the +given \fIinterp\fR (if that is non-NULL). Note that it is unsafe to use this +operation on a handle that has been passed to \fBTcl_FSUnloadFile\fR. +.SH "SEE ALSO" +Tcl_FSLoadFile(3), Tcl_FSUnloadFile(3), load(n), unload(n) +.SH KEYWORDS +binary code, loading, shared library +'\" Local Variables: +'\" mode: nroff +'\" fill-column: 78 +'\" End: diff --git a/tcl8.6/doc/Method.3 b/tcl8.6/doc/Method.3 new file mode 100644 index 0000000..225da00 --- /dev/null +++ b/tcl8.6/doc/Method.3 @@ -0,0 +1,251 @@ +'\" +'\" Copyright (c) 2007 Donal K. Fellows +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH Tcl_Method 3 0.1 TclOO "TclOO Library Functions" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +Tcl_ClassSetConstructor, Tcl_ClassSetDestructor, Tcl_MethodDeclarerClass, Tcl_MethodDeclarerObject, Tcl_MethodIsPublic, Tcl_MethodIsType, Tcl_MethodName, Tcl_NewInstanceMethod, Tcl_NewMethod, Tcl_ObjectContextInvokeNext, Tcl_ObjectContextIsFiltering, Tcl_ObjectContextMethod, Tcl_ObjectContextObject, Tcl_ObjectContextSkippedArgs \- manipulate methods and method-call contexts +.SH SYNOPSIS +.nf +\fB#include <tclOO.h>\fR +.sp +Tcl_Method +\fBTcl_NewMethod\fR(\fIinterp, class, nameObj, isPublic, + methodTypePtr, clientData\fR) +.sp +Tcl_Method +\fBTcl_NewInstanceMethod\fR(\fIinterp, object, nameObj, isPublic, + methodTypePtr, clientData\fR) +.sp +\fBTcl_ClassSetConstructor\fR(\fIinterp, class, method\fR) +.sp +\fBTcl_ClassSetDestructor\fR(\fIinterp, class, method\fR) +.sp +Tcl_Class +\fBTcl_MethodDeclarerClass\fR(\fImethod\fR) +.sp +Tcl_Object +\fBTcl_MethodDeclarerObject\fR(\fImethod\fR) +.sp +Tcl_Obj * +\fBTcl_MethodName\fR(\fImethod\fR) +.sp +int +\fBTcl_MethodIsPublic\fR(\fImethod\fR) +.sp +int +\fBTcl_MethodIsType\fR(\fImethod, methodTypePtr, clientDataPtr\fR) +.sp +int +\fBTcl_ObjectContextInvokeNext\fR(\fIinterp, context, objc, objv, skip\fR) +.sp +int +\fBTcl_ObjectContextIsFiltering\fR(\fIcontext\fR) +.sp +Tcl_Method +\fBTcl_ObjectContextMethod\fR(\fIcontext\fR) +.sp +Tcl_Object +\fBTcl_ObjectContextObject\fR(\fIcontext\fR) +.sp +int +\fBTcl_ObjectContextSkippedArgs\fR(\fIcontext\fR) +.SH ARGUMENTS +.AS ClientData clientData in +.AP Tcl_Interp *interp in/out +The interpreter holding the object or class to create or update a method in. +.AP Tcl_Object object in +The object to create the method in. +.AP Tcl_Class class in +The class to create the method in. +.AP Tcl_Obj *nameObj in +The name of the method to create. Should not be NULL unless creating +constructors or destructors. +.AP int isPublic in +A flag saying what the visibility of the method is. The only supported public +values of this flag are 0 for a non-exported method, and 1 for an exported +method. +.AP Tcl_MethodType *methodTypePtr in +A description of the type of the method to create, or the type of method to +compare against. +.AP ClientData clientData in +A piece of data that is passed to the implementation of the method without +interpretation. +.AP ClientData *clientDataPtr out +A pointer to a variable in which to write the \fIclientData\fR value supplied +when the method was created. If NULL, the \fIclientData\fR value will not be +retrieved. +.AP Tcl_Method method in +A reference to a method to query. +.AP Tcl_ObjectContext context in +A reference to a method-call context. Note that client code \fImust not\fR +retain a reference to a context. +.AP int objc in +The number of arguments to pass to the method implementation. +.AP "Tcl_Obj *const" *objv in +An array of arguments to pass to the method implementation. +.AP int skip in +The number of arguments passed to the method implementation that do not +represent "real" arguments. +.BE +.SH DESCRIPTION +.PP +A method is an operation carried out on an object that is associated with the +object. Every method must be attached to either an object or a class; methods +attached to a class are associated with all instances (direct and indirect) of +that class. +.PP +Given a method, the entity that declared it can be found using +\fBTcl_MethodDeclarerClass\fR which returns the class that the method is +attached to (or NULL if the method is not attached to any class) and +\fBTcl_MethodDeclarerObject\fR which returns the object that the method is +attached to (or NULL if the method is not attached to an object). The name of +the method can be retrieved with \fBTcl_MethodName\fR and whether the method +is exported is retrieved with \fBTcl_MethodIsPublic\fR. The type of the method +can also be introspected upon to a limited degree; the function +\fBTcl_MethodIsType\fR returns whether a method is of a particular type, +assigning the per-method \fIclientData\fR to the variable pointed to by +\fIclientDataPtr\fR if (that is non-NULL) if the type is matched. +.SS "METHOD CREATION" +.PP +Methods are created by \fBTcl_NewMethod\fR and \fBTcl_NewInstanceMethod\fR, +which +create a method attached to a class or an object respectively. In both cases, +the \fInameObj\fR argument gives the name of the method to create, the +\fIisPublic\fR argument states whether the method should be exported +initially, the \fImethodTypePtr\fR argument describes the implementation of +the method (see the \fBMETHOD TYPES\fR section below) and the \fIclientData\fR +argument gives some implementation-specific data that is passed on to the +implementation of the method when it is called. +.PP +When the \fInameObj\fR argument to \fBTcl_NewMethod\fR is NULL, an +unnamed method is created, which is used for constructors and destructors. +Constructors should be installed into their class using the +\fBTcl_ClassSetConstructor\fR function, and destructors (which must not +require any arguments) should be installed into their class using the +\fBTcl_ClassSetDestructor\fR function. Unnamed methods should not be used for +any other purpose, and named methods should not be used as either constructors +or destructors. Also note that a NULL \fImethodTypePtr\fR is used to provide +internal signaling, and should not be used in client code. +.SS "METHOD CALL CONTEXTS" +.PP +When a method is called, a method-call context reference is passed in as one +of the arguments to the implementation function. This context can be inspected +to provide information about the caller, but should not be retained beyond the +moment when the method call terminates. +.PP +The method that is being called can be retrieved from the context by using +\fBTcl_ObjectContextMethod\fR, and the object that caused the method to be +invoked can be retrieved with \fBTcl_ObjectContextObject\fR. The number of +arguments that are to be skipped (e.g. the object name and method name in a +normal method call) is read with \fBTcl_ObjectContextSkippedArgs\fR, and the +context can also report whether it is working as a filter for another method +through \fBTcl_ObjectContextIsFiltering\fR. +.PP +During the execution of a method, the method implementation may choose to +invoke the stages of the method call chain that come after the current method +implementation. This (the core of the \fBnext\fR command) is done using +\fBTcl_ObjectContextInvokeNext\fR. Note that this function does not manipulate +the call-frame stack, unlike the \fBnext\fR command; if the method +implementation has pushed one or more extra frames on the stack as part of its +implementation, it is also responsible for temporarily popping those frames +from the stack while the \fBTcl_ObjectContextInvokeNext\fR function is +executing. Note also that the method-call context is \fInever\fR deleted +during the execution of this function. +.SH "METHOD TYPES" +.PP +The types of methods are described by a pointer to a Tcl_MethodType structure, +which is defined as: +.PP +.CS +typedef struct { + int \fIversion\fR; + const char *\fIname\fR; + Tcl_MethodCallProc *\fIcallProc\fR; + Tcl_MethodDeleteProc *\fIdeleteProc\fR; + Tcl_CloneProc *\fIcloneProc\fR; +} \fBTcl_MethodType\fR; +.CE +.PP +The \fIversion\fR field allows for future expansion of the structure, and +should always be declared equal to TCL_OO_METHOD_VERSION_CURRENT. The +\fIname\fR field provides a human-readable name for the type, and is the value +that is exposed via the \fBinfo class methodtype\fR and +\fBinfo object methodtype\fR Tcl commands. +.PP +The \fIcallProc\fR field gives a function that is called when the method is +invoked; it must never be NULL. +.PP +The \fIdeleteProc\fR field gives a function that is used to delete a +particular method, and is called when the method is replaced or removed; if +the field is NULL, it is assumed that the method's \fIclientData\fR needs no +special action to delete. +.PP +The \fIcloneProc\fR field is either a function that is used to copy a method's +\fIclientData\fR (as part of \fBTcl_CopyObjectInstance\fR) or NULL to indicate +that the \fIclientData\fR can just be copied directly. +.SS "TCL_METHODCALLPROC FUNCTION SIGNATURE" +.PP +Functions matching this signature are called when the method is invoked. +.PP +.CS +typedef int \fBTcl_MethodCallProc\fR( + ClientData \fIclientData\fR, + Tcl_Interp *\fIinterp\fR, + Tcl_ObjectContext \fIobjectContext\fR, + int \fIobjc\fR, + Tcl_Obj *const *\fIobjv\fR); +.CE +.PP +The \fIclientData\fR argument to a Tcl_MethodCallProc is the value that was +given when the method was created, the \fIinterp\fR is a place in which to +execute scripts and access variables as well as being where to put the result +of the method, and the \fIobjc\fR and \fIobjv\fR fields give the parameter +objects to the method. The calling context of the method can be discovered +through the \fIobjectContext\fR argument, and the return value from a +Tcl_MethodCallProc is any Tcl return code (e.g. TCL_OK, TCL_ERROR). +.SS "TCL_METHODDELETEPROC FUNCTION SIGNATURE" +.PP +Functions matching this signature are used when a method is deleted, whether +through a new method being created or because the object or class is deleted. +.PP +.CS +typedef void \fBTcl_MethodDeleteProc\fR( + ClientData \fIclientData\fR); +.CE +.PP +The \fIclientData\fR argument to a Tcl_MethodDeleteProc will be the same as +the value passed to the \fIclientData\fR argument to \fBTcl_NewMethod\fR or +\fBTcl_NewInstanceMethod\fR when the method was created. +.SS "TCL_CLONEPROC FUNCTION SIGNATURE" +.PP +Functions matching this signature are used to copy a method when the object or +class is copied using \fBTcl_CopyObjectInstance\fR (or \fBoo::copy\fR). +.PP +.CS +typedef int \fBTcl_CloneProc\fR( + Tcl_Interp *\fIinterp\fR, + ClientData \fIoldClientData\fR, + ClientData *\fInewClientDataPtr\fR); +.CE +.PP +The \fIinterp\fR argument gives a place to write an error message when the +attempt to clone the object is to fail, in which case the clone procedure must +also return TCL_ERROR; it should return TCL_OK otherwise. +The \fIoldClientData\fR field to a Tcl_CloneProc gives the value from the +method being copied from, and the \fInewClientDataPtr\fR field will point to +a variable in which to write the value for the method being copied to. +.SH "SEE ALSO" +Class(3), oo::class(n), oo::define(n), oo::object(n) +.SH KEYWORDS +constructor, method, object + +.\" Local variables: +.\" mode: nroff +.\" fill-column: 78 +.\" End: diff --git a/tcl8.6/doc/NRE.3 b/tcl8.6/doc/NRE.3 new file mode 100644 index 0000000..ff0d108 --- /dev/null +++ b/tcl8.6/doc/NRE.3 @@ -0,0 +1,328 @@ +.\" +.\" Copyright (c) 2008 by Kevin B. Kenny. +.\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH NRE 3 8.6 Tcl "Tcl Library Procedures" +.so man.macros +.BS +.SH NAME +Tcl_NRCreateCommand, Tcl_NRCallObjProc, Tcl_NREvalObj, Tcl_NREvalObjv, Tcl_NRCmdSwap, Tcl_NRExprObj, Tcl_NRAddCallback \- Non-Recursive (stackless) evaluation of Tcl scripts. +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +Tcl_Command +\fBTcl_NRCreateCommand\fR(\fIinterp, cmdName, proc, nreProc, clientData, + deleteProc\fR) +.sp +int +\fBTcl_NRCallObjProc\fR(\fIinterp, nreProc, clientData, objc, objv\fR) +.sp +int +\fBTcl_NREvalObj\fR(\fIinterp, objPtr, flags\fR) +.sp +int +\fBTcl_NREvalObjv\fR(\fIinterp, objc, objv, flags\fR) +.sp +int +\fBTcl_NRCmdSwap\fR(\fIinterp, cmd, objc, objv, flags\fR) +.sp +int +\fBTcl_NRExprObj\fR(\fIinterp, objPtr, resultPtr\fR) +.sp +void +\fBTcl_NRAddCallback\fR(\fIinterp, postProcPtr, data0, data1, data2, data3\fR) +.fi +.SH ARGUMENTS +.AS Tcl_CmdDeleteProc *interp in +.AP Tcl_Interp *interp in +Interpreter in which to create or evaluate a command. +.AP char *cmdName in +Name of a new command to create. +.AP Tcl_ObjCmdProc *proc in +Implementation of a command that will be called whenever \fIcmdName\fR +is invoked as a command in the unoptimized way. +.AP Tcl_ObjCmdProc *nreProc in +Implementation of a command that will be called whenever \fIcmdName\fR +is invoked and requested to conserve the C stack. +.AP ClientData clientData in +Arbitrary one-word value that will be passed to \fIproc\fR, \fInreProc\fR, +\fIdeleteProc\fR and \fIobjProc\fR. +.AP Tcl_CmdDeleteProc *deleteProc in/out +Procedure to call before \fIcmdName\fR is deleted from the interpreter. +This procedure allows for command-specific cleanup. If \fIdeleteProc\fR +is \fBNULL\fR, then no procedure is called before the command is deleted. +.AP int objc in +Count of parameters provided to the implementation of a command. +.AP Tcl_Obj **objv in +Pointer to an array of Tcl values. Each value holds the value of a +single word in the command to execute. +.AP Tcl_Obj *objPtr in +Pointer to a Tcl_Obj whose value is a script or expression to execute. +.AP int flags in +ORed combination of flag bits that specify additional options. +\fBTCL_EVAL_GLOBAL\fR is the only flag that is currently supported. +.\" TODO: This is a lie. But kbk didn't grasp TCL_EVAL_INVOKE and +.\" TCL_EVAL_NOERR well enough to document them. +.AP Tcl_Command cmd in +Token for a command that is to be used instead of the currently +executing command. +.AP Tcl_Obj *resultPtr out +Pointer to an unshared Tcl_Obj where the result of expression +evaluation is written. +.AP Tcl_NRPostProc *postProcPtr in +Pointer to a function that will be invoked when the command currently +executing in the interpreter designated by \fIinterp\fR completes. +.AP ClientData data0 in +.AP ClientData data1 in +.AP ClientData data2 in +.AP ClientData data3 in +\fIdata0\fR through \fIdata3\fR are four one-word values that will be passed +to the function designated by \fIpostProcPtr\fR when it is invoked. +.BE +.SH DESCRIPTION +.PP +This series of C functions provides an interface whereby commands that +are implemented in C can be evaluated, and invoke Tcl commands scripts +and scripts, without consuming space on the C stack. The non-recursive +evaluation is done by installing a \fItrampoline\fR, a small piece of +code that invokes a command or script, and then executes a series of +callbacks when the command or script returns. +.PP +The \fBTcl_NRCreateCommand\fR function creates a Tcl command in the +interpreter designated by \fIinterp\fR that is prepared to handle +nonrecursive evaluation with a trampoline. The \fIcmdName\fR argument +gives the name of the new command. If \fIcmdName\fR contains any +namespace qualifiers, then the new command is added to the specified +namespace; otherwise, it is added to the global namespace. \fIproc\fR +gives the procedure that will be called when the interpreter wishes to +evaluate the command in an unoptimized manner, and \fInreProc\fR is +the procedure that will be called when the interpreter wishes to +evaluate the command using a trampoline. \fIdeleteProc\fR is a +function that will be called before the command is deleted from the +interpreter. When any of the three functions is invoked, it is passed +the \fIclientData\fR parameter. +.PP +\fBTcl_NRCreateCommand\fR deletes any existing command +\fIname\fR already associated with the interpreter +(however see below for an exception where the existing command +is not deleted). +It returns a token that may be used to refer +to the command in subsequent calls to \fBTcl_GetCommandName\fR. +If \fBTcl_NRCreateCommand\fR is called for an interpreter that is in +the process of being deleted, then it does not create a new command, +does not delete any existing command of the same name, and returns NULL. +.PP +The \fIproc\fR and \fInreProc\fR function are expected to conform to +all the rules set forth for the \fIproc\fR argument to +\fBTcl_CreateObjCommand\fR(3) (\fIq.v.\fR). +.PP +When a command that is written to cope with evaluation via trampoline +is invoked without a trampoline on the stack, it will usually respond +to the invocation by creating a trampoline and calling the +trampoline-enabled implementation of the same command. This call is done by +means of \fBTcl_NRCallObjProc\fR. In the call to +\fBTcl_NRCallObjProc\fR, the \fIinterp\fR, \fIclientData\fR, +\fIobjc\fR and \fIobjv\fR parameters should be the same ones that were +passed to \fIproc\fR. The \fInreProc\fR parameter should designate the +trampoline-enabled implementation of the command. +.PP +\fBTcl_NREvalObj\fR arranges for the script contained in \fIobjPtr\fR +to be evaluated in the interpreter designated by \fIinterp\fR after +the current command (which must be trampoline-enabled) returns. It is +the method by which a command may invoke a script without consuming +space on the C stack. Similarly, \fBTcl_NREvalObjv\fR arranges to +invoke a single Tcl command whose words have already been separated +and substituted. The \fIobjc\fR and \fIobjv\fR parameters give the +words of the command to be evaluated when execution reaches the +trampoline. +.PP +\fBTcl_NRCmdSwap\fR allows for trampoline evaluation of a command whose +resolution is already known. The \fIcmd\fR parameter gives a +\fBTcl_Command\fR token (returned from \fBTcl_CreateObjCommand\fR or +\fBTcl_GetCommandFromObj\fR) identifying the command to be invoked in +the trampoline; this command must match the word in \fIobjv[0]\fR. +The remaining arguments are as for \fBTcl_NREvalObjv\fR. +.PP +\fBTcl_NREvalObj\fR, \fBTcl_NREvalObjv\fR and \fBTcl_NRCmdSwap\fR +all accept a \fIflags\fR parameter, which is an OR-ed-together set of +bits to control evaluation. At the present time, the only supported flag +available to callers is \fBTCL_EVAL_GLOBAL\fR. +.\" TODO: Again, this is a lie. Do we want to explain TCL_EVAL_INVOKE +.\" and TCL_EVAL_NOERR? +If the \fBTCL_EVAL_GLOBAL\fR flag is set, the script or command is +evaluated in the global namespace. If it is not set, it is evaluated +in the current namespace. +.PP +\fBTcl_NRExprObj\fR arranges for the expression contained in \fIobjPtr\fR +to be evaluated in the interpreter designated by \fIinterp\fR after +the current command (which must be trampoline-enabled) returns. It is +the method by which a command may evaluate a Tcl expression without consuming +space on the C stack. The argument \fIresultPtr\fR is a pointer to an +unshared Tcl_Obj where the result of expression evaluation is to be written. +If expression evaluation returns any code other than TCL_OK, the +\fIresultPtr\fR value is left untouched. +.PP +All of the routines return \fBTCL_OK\fR if command or expression invocation +has been scheduled successfully. If for any reason the scheduling cannot +be completed (for example, if the interpreter is unable to find +the requested command), they return \fBTCL_ERROR\fR with an +appropriate message left in the interpreter's result. +.PP +\fBTcl_NRAddCallback\fR arranges to have a C function called when the +current trampoline-enabled command in the Tcl interpreter designated +by \fIinterp\fR returns. The \fIpostProcPtr\fR argument is a pointer +to the callback function, which must have arguments and return value +consistent with the \fBTcl_NRPostProc\fR data type: +.PP +.CS +typedef int +\fBTcl_NRPostProc\fR( + \fBClientData\fR \fIdata\fR[], + \fBTcl_Interp\fR *\fIinterp\fR, + int \fIresult\fR); +.CE +.PP +When the trampoline invokes the callback function, the \fIdata\fR +parameter will point to an array containing the four one-word +quantities that were passed to \fBTcl_NRAddCallback\fR in the +\fIdata0\fR through \fIdata3\fR parameters. The Tcl interpreter will +be designated by the \fIinterp\fR parameter, and the \fIresult\fR +parameter will contain the result (\fBTCL_OK\fR, \fBTCL_ERROR\fR, +\fBTCL_RETURN\fR, \fBTCL_BREAK\fR or \fBTCL_CONTINUE\fR) that was +returned by the command evaluation. The callback function is expected, +in turn, either to return a \fIresult\fR to control further evaluation. +.PP +Multiple \fBTcl_NRAddCallback\fR invocations may request multiple +callbacks, which may be to the same or different callback +functions. If multiple callbacks are requested, they are executed in +last-in, first-out order, that is, the most recently requested +callback is executed first. +.SH EXAMPLE +.PP +The usual pattern for Tcl commands that invoke other Tcl commands +is something like: +.PP +.CS +int +\fITheCmdOldObjProc\fR( + ClientData clientData, + Tcl_Interp *interp, + int objc, + Tcl_Obj *const objv[]) +{ + int result; + Tcl_Obj *objPtr; + + \fI... preparation ...\fR + + result = \fBTcl_EvalObjEx\fR(interp, objPtr, 0); + + \fI... postprocessing ...\fR + + return result; +} +\fBTcl_CreateObjCommand\fR(interp, "theCommand", + \fITheCmdOldObjProc\fR, clientData, TheCmdDeleteProc); +.CE +.PP +To enable a command like this one for trampoline-based evaluation, +it must be split into three pieces: +.IP \(bu +A non-trampoline implementation, \fITheCmdNewObjProc\fR, +which will simply create a trampoline +and invoke the trampoline-based implementation. +.IP \(bu +A trampoline-enabled implementation, \fITheCmdNRObjProc\fR. This +function will perform the initialization, request that the trampoline +call the postprocessing routine after command evaluation, and finally, +request that the trampoline call the inner command. +.IP \(bu +A postprocessing routine, \fITheCmdPostProc\fR. This function will +perform the postprocessing formerly done after the return from the +inner command in \fITheCmdObjProc\fR. +.PP +The non-trampoline implementation is simple and stylized, containing +a single statement: +.PP +.CS +int +\fITheCmdNewObjProc\fR( + ClientData clientData, + Tcl_Interp *interp, + int objc, + Tcl_Obj *const objv[]) +{ + return \fBTcl_NRCallObjProc\fR(interp, \fITheCmdNRObjProc\fR, + clientData, objc, objv); +} +.CE +.PP +The trampoline-enabled implementation requests postprocessing, +and returns to the trampoline requesting command evaluation. +.PP +.CS +int +\fITheCmdNRObjProc\fR + ClientData clientData, + Tcl_Interp *interp, + int objc, + Tcl_Obj *const objv[]) +{ + Tcl_Obj *objPtr; + + \fI... preparation ...\fR + + \fBTcl_NRAddCallback\fR(interp, \fITheCmdPostProc\fR, + data0, data1, data2, data3); + /* \fIdata0 .. data3\fR are up to four one-word items to + * pass to the postprocessing procedure */ + + return \fBTcl_NREvalObj\fR(interp, objPtr, 0); +} +.CE +.PP +The postprocessing procedure does whatever the original command did +upon return from the inner evaluation. +.PP +.CS +int +\fITheCmdNRPostProc\fR( + ClientData data[], + Tcl_Interp *interp, + int result) +{ + /* \fIdata[0] .. data[3]\fR are the four words of data + * passed to \fBTcl_NRAddCallback\fR */ + + \fI... postprocessing ...\fR + + return result; +} +.CE +.PP +If \fItheCommand\fR is a command that results in multiple commands or +scripts being evaluated, its postprocessing routine may schedule +additional postprocessing and then request another command evaluation +by means of \fBTcl_NREvalObj\fR or one of the other evaluation +routines. Looping and sequencing constructs may be implemented in this way. +.PP +Finally, to install a trampoline-enabled command in the interpreter, +\fBTcl_NRCreateCommand\fR is used in place of +\fBTcl_CreateObjCommand\fR. It accepts two command procedures instead +of one. The first is for use when no trampoline is yet on the stack, +and the second is for use when there is already a trampoline in place. +.PP +.CS +\fBTcl_NRCreateCommand\fR(interp, "theCommand", + \fITheCmdNewObjProc\fR, \fITheCmdNRObjProc\fR, clientData, + TheCmdDeleteProc); +.CE +.SH "SEE ALSO" +Tcl_CreateCommand(3), Tcl_CreateObjCommand(3), Tcl_EvalObjEx(3), Tcl_GetCommandFromObj(3), Tcl_ExprObj(3) +.SH KEYWORDS +stackless, nonrecursive, execute, command, global, value, result, script +.SH COPYRIGHT +Copyright (c) 2008 by Kevin B. Kenny diff --git a/tcl8.6/doc/Namespace.3 b/tcl8.6/doc/Namespace.3 new file mode 100644 index 0000000..be89597 --- /dev/null +++ b/tcl8.6/doc/Namespace.3 @@ -0,0 +1,165 @@ +'\" +'\" Copyright (c) 2003 Donal K. Fellows +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +'\" Note that some of these functions do not seem to belong, but they +'\" were all introduced with the same TIP (#139) +'\" +.TH Tcl_Namespace 3 8.5 Tcl "Tcl Library Procedures" +.so man.macros +.BS +.SH NAME +Tcl_AppendExportList, Tcl_CreateNamespace, Tcl_DeleteNamespace, Tcl_Export, Tcl_FindCommand, Tcl_FindNamespace, Tcl_ForgetImport, Tcl_GetCurrentNamespace, Tcl_GetGlobalNamespace, Tcl_GetNamespaceUnknownHandler, Tcl_Import, Tcl_SetNamespaceUnknownHandler \- manipulate namespaces +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +Tcl_Namespace * +\fBTcl_CreateNamespace\fR(\fIinterp, name, clientData, deleteProc\fR) +.sp +\fBTcl_DeleteNamespace\fR(\fInsPtr\fR) +.sp +int +\fBTcl_AppendExportList\fR(\fIinterp, nsPtr, objPtr\fR) +.sp +int +\fBTcl_Export\fR(\fIinterp, nsPtr, pattern, resetListFirst\fR) +.sp +int +\fBTcl_Import\fR(\fIinterp, nsPtr, pattern, allowOverwrite\fR) +.sp +int +\fBTcl_ForgetImport\fR(\fIinterp, nsPtr, pattern\fR) +.sp +Tcl_Namespace * +\fBTcl_GetCurrentNamespace\fR(\fIinterp\fR) +.sp +Tcl_Namespace * +\fBTcl_GetGlobalNamespace\fR(\fIinterp\fR) +.sp +Tcl_Namespace * +\fBTcl_FindNamespace\fR(\fIinterp, name, contextNsPtr, flags\fR) +.sp +Tcl_Command +\fBTcl_FindCommand\fR(\fIinterp, name, contextNsPtr, flags\fR) +.sp +Tcl_Obj * +\fBTcl_GetNamespaceUnknownHandler(\fIinterp, nsPtr\fR) +.sp +int +\fBTcl_SetNamespaceUnknownHandler(\fIinterp, nsPtr, handlerPtr\fR) +.SH ARGUMENTS +.AS Tcl_NamespaceDeleteProc allowOverwrite in/out +.AP Tcl_Interp *interp in/out +The interpreter in which the namespace exists and where name lookups +are performed. Also where error result messages are written. +.AP "const char" *name in +The name of the namespace or command to be created or accessed. +.AP ClientData clientData in +A context pointer by the creator of the namespace. Not interpreted by +Tcl at all. +.AP Tcl_NamespaceDeleteProc *deleteProc in +A pointer to function to call when the namespace is deleted, or NULL +if no such callback is to be performed. +.AP Tcl_Namespace *nsPtr in +The namespace to be manipulated, or NULL (for other than +\fBTcl_DeleteNamespace\fR) to manipulate the current namespace. +.AP Tcl_Obj *objPtr out +A reference to an unshared value to which the function output will be +written. +.AP "const char" *pattern in +The glob-style pattern (see \fBTcl_StringMatch\fR) that describes the +commands to be imported or exported. +.AP int resetListFirst in +Whether the list of export patterns should be reset before adding the +current pattern to it. +.AP int allowOverwrite in +Whether new commands created by this import action can overwrite +existing commands. +.AP Tcl_Namespace *contextNsPtr in +The location in the namespace hierarchy where the search for a +namespace or command should be conducted relative to when the search +term is not rooted at the global namespace. NULL indicates the +current namespace. +.AP int flags in +OR-ed combination of bits controlling how the search is to be +performed. The following flags are supported: \fBTCL_GLOBAL_ONLY\fR +(indicates that the search is always to be conducted relative to the +global namespace), \fBTCL_NAMESPACE_ONLY\fR (just for \fBTcl_FindCommand\fR; +indicates that the search is always to be conducted relative to the +context namespace), and \fBTCL_LEAVE_ERR_MSG\fR (indicates that an error +message should be left in the interpreter if the search fails.) +.AP Tcl_Obj *handlerPtr in +A script fragment to be installed as the unknown command handler for the +namespace, or NULL to reset the handler to its default. +.BE +.SH DESCRIPTION +.PP +Namespaces are hierarchic naming contexts that can contain commands +and variables. They also maintain a list of patterns that describes +what commands are exported, and can import commands that have been +exported by other namespaces. Namespaces can also be manipulated +through the Tcl command \fBnamespace\fR. +.PP +The \fITcl_Namespace\fR structure encapsulates a namespace, and is +guaranteed to have the following fields in it: \fIname\fR (the local +name of the namespace, with no namespace separator characters in it, +with empty denoting the global namespace), \fIfullName\fR (the fully +specified name of the namespace), \fIclientData\fR, \fIdeleteProc\fR +(the values specified in the call to \fBTcl_CreateNamespace\fR), and +\fIparentPtr\fR (a pointer to the containing namespace, or NULL for +the global namespace.) +.PP +\fBTcl_CreateNamespace\fR creates a new namespace. The +\fIdeleteProc\fR will have the following type signature: +.PP +.CS +typedef void \fBTcl_NamespaceDeleteProc\fR( + ClientData \fIclientData\fR); +.CE +.PP +\fBTcl_DeleteNamespace\fR deletes a namespace, calling the +\fIdeleteProc\fR defined for the namespace (if any). +.PP +\fBTcl_AppendExportList\fR retrieves the export patterns for a +namespace given namespace and appends them (as list items) to +\fIobjPtr\fR. +.PP +\fBTcl_Export\fR sets and appends to the export patterns for a +namespace. Patterns are appended unless the \fIresetListFirst\fR flag +is true. +.PP +\fBTcl_Import\fR imports commands matching a pattern into a +namespace. Note that the pattern must include the name of the +namespace to import from. This function returns an error if +an attempt to import a command over an existing command is made, +unless the \fIallowOverwrite\fR flag has been set. +.PP +\fBTcl_ForgetImport\fR removes imports matching a pattern. +.PP +\fBTcl_GetCurrentNamespace\fR returns the current namespace for an +interpreter. +.PP +\fBTcl_GetGlobalNamespace\fR returns the global namespace for an +interpreter. +.PP +\fBTcl_FindNamespace\fR searches for a namespace named \fIname\fR +within the context of the namespace \fIcontextNsPtr\fR. If the +namespace cannot be found, NULL is returned. +.PP +\fBTcl_FindCommand\fR searches for a command named \fIname\fR within +the context of the namespace \fIcontextNsPtr\fR. If the command +cannot be found, NULL is returned. +.PP +\fBTcl_GetNamespaceUnknownHandler\fR returns the unknown command handler +for the namespace, or NULL if none is set. +.PP +\fBTcl_SetNamespaceUnknownHandler\fR sets the unknown command handler for +the namespace. If \fIhandlerPtr\fR is NULL, then the handler is reset to +its default. +.SH "SEE ALSO" +Tcl_CreateCommand(3), Tcl_ListObjAppendList(3), Tcl_SetVar(3) +.SH KEYWORDS +namespace, command diff --git a/tcl8.6/doc/Notifier.3 b/tcl8.6/doc/Notifier.3 new file mode 100644 index 0000000..16f9f8d --- /dev/null +++ b/tcl8.6/doc/Notifier.3 @@ -0,0 +1,635 @@ +'\" +'\" Copyright (c) 1998-1999 Scriptics Corporation +'\" Copyright (c) 1995-1997 Sun Microsystems, Inc. +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH Notifier 3 8.1 Tcl "Tcl Library Procedures" +.so man.macros +.BS +.SH NAME +Tcl_CreateEventSource, Tcl_DeleteEventSource, Tcl_SetMaxBlockTime, Tcl_QueueEvent, Tcl_ThreadQueueEvent, Tcl_ThreadAlert, Tcl_GetCurrentThread, Tcl_DeleteEvents, Tcl_InitNotifier, Tcl_FinalizeNotifier, Tcl_WaitForEvent, Tcl_AlertNotifier, Tcl_SetTimer, Tcl_ServiceAll, Tcl_ServiceEvent, Tcl_GetServiceMode, Tcl_SetServiceMode, Tcl_ServiceModeHook, Tcl_SetNotifier \- the event queue and notifier interfaces +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +void +\fBTcl_CreateEventSource\fR(\fIsetupProc, checkProc, clientData\fR) +.sp +void +\fBTcl_DeleteEventSource\fR(\fIsetupProc, checkProc, clientData\fR) +.sp +void +\fBTcl_SetMaxBlockTime\fR(\fItimePtr\fR) +.sp +void +\fBTcl_QueueEvent\fR(\fIevPtr, position\fR) +.sp +void +\fBTcl_ThreadQueueEvent\fR(\fIthreadId, evPtr, position\fR) +.sp +void +\fBTcl_ThreadAlert\fR(\fIthreadId\fR) +.sp +Tcl_ThreadId +\fBTcl_GetCurrentThread\fR() +.sp +void +\fBTcl_DeleteEvents\fR(\fIdeleteProc, clientData\fR) +.sp +ClientData +\fBTcl_InitNotifier\fR() +.sp +void +\fBTcl_FinalizeNotifier\fR(\fIclientData\fR) +.sp +int +\fBTcl_WaitForEvent\fR(\fItimePtr\fR) +.sp +void +\fBTcl_AlertNotifier\fR(\fIclientData\fR) +.sp +void +\fBTcl_SetTimer\fR(\fItimePtr\fR) +.sp +int +\fBTcl_ServiceAll\fR() +.sp +int +\fBTcl_ServiceEvent\fR(\fIflags\fR) +.sp +int +\fBTcl_GetServiceMode\fR() +.sp +int +\fBTcl_SetServiceMode\fR(\fImode\fR) +.sp +void +\fBTcl_ServiceModeHook\fR(\fImode\fR) +.sp +void +\fBTcl_SetNotifier\fR(\fInotifierProcPtr\fR) +.SH ARGUMENTS +.AS Tcl_EventDeleteProc *notifierProcPtr +.AP Tcl_EventSetupProc *setupProc in +Procedure to invoke to prepare for event wait in \fBTcl_DoOneEvent\fR. +.AP Tcl_EventCheckProc *checkProc in +Procedure for \fBTcl_DoOneEvent\fR to invoke after waiting for +events. Checks to see if any events have occurred and, if so, +queues them. +.AP ClientData clientData in +Arbitrary one-word value to pass to \fIsetupProc\fR, \fIcheckProc\fR, or +\fIdeleteProc\fR. +.AP "const Tcl_Time" *timePtr in +Indicates the maximum amount of time to wait for an event. This +is specified as an interval (how long to wait), not an absolute +time (when to wakeup). If the pointer passed to \fBTcl_WaitForEvent\fR +is NULL, it means there is no maximum wait time: wait forever if +necessary. +.AP Tcl_Event *evPtr in +An event to add to the event queue. The storage for the event must +have been allocated by the caller using \fBTcl_Alloc\fR or \fBckalloc\fR. +.AP Tcl_QueuePosition position in +Where to add the new event in the queue: \fBTCL_QUEUE_TAIL\fR, +\fBTCL_QUEUE_HEAD\fR, or \fBTCL_QUEUE_MARK\fR. +.AP Tcl_ThreadId threadId in +A unique identifier for a thread. +.AP Tcl_EventDeleteProc *deleteProc in +Procedure to invoke for each queued event in \fBTcl_DeleteEvents\fR. +.AP int flags in +What types of events to service. These flags are the same as those +passed to \fBTcl_DoOneEvent\fR. +.AP int mode in +Indicates whether events should be serviced by \fBTcl_ServiceAll\fR. +Must be one of \fBTCL_SERVICE_NONE\fR or \fBTCL_SERVICE_ALL\fR. +.AP Tcl_NotifierProcs* notifierProcPtr in +Structure of function pointers describing notifier procedures that are +to replace the ones installed in the executable. See +\fBREPLACING THE NOTIFIER\fR for details. +.BE +.SH INTRODUCTION +.PP +The interfaces described here are used to customize the Tcl event +loop. The two most common customizations are to add new sources of +events and to merge Tcl's event loop with some other event loop, such +as one provided by an application in which Tcl is embedded. Each of +these tasks is described in a separate section below. +.PP +The procedures in this manual entry are the building blocks out of which +the Tcl event notifier is constructed. The event notifier is the lowest +layer in the Tcl event mechanism. It consists of three things: +.IP [1] +Event sources: these represent the ways in which events can be +generated. For example, there is a timer event source that implements +the \fBTcl_CreateTimerHandler\fR procedure and the \fBafter\fR +command, and there is a file event source that implements the +\fBTcl_CreateFileHandler\fR procedure on Unix systems. An event +source must work with the notifier to detect events at the right +times, record them on the event queue, and eventually notify +higher-level software that they have occurred. The procedures +\fBTcl_CreateEventSource\fR, \fBTcl_DeleteEventSource\fR, +and \fBTcl_SetMaxBlockTime\fR, \fBTcl_QueueEvent\fR, and +\fBTcl_DeleteEvents\fR are used primarily by event sources. +.IP [2] +The event queue: for non-threaded applications, +there is a single queue for the whole application, +containing events that have been detected but not yet serviced. Event +sources place events onto the queue so that they may be processed in +order at appropriate times during the event loop. The event queue +guarantees a fair discipline of event handling, so that no event +source can starve the others. It also allows events to be saved for +servicing at a future time. Threaded applications work in a +similar manner, except that there is a separate event queue for +each thread containing a Tcl interpreter. +\fBTcl_QueueEvent\fR is used (primarily +by event sources) to add events to the event queue and +\fBTcl_DeleteEvents\fR is used to remove events from the queue without +processing them. In a threaded application, \fBTcl_QueueEvent\fR adds +an event to the current thread's queue, and \fBTcl_ThreadQueueEvent\fR +adds an event to a queue in a specific thread. +.IP [3] +The event loop: in order to detect and process events, the application +enters a loop that waits for events to occur, places them on the event +queue, and then processes them. Most applications will do this by +calling the procedure \fBTcl_DoOneEvent\fR, which is described in a +separate manual entry. +.PP +Most Tcl applications need not worry about any of the internals of +the Tcl notifier. However, the notifier now has enough flexibility +to be retargeted either for a new platform or to use an external event +loop (such as the Motif event loop, when Tcl is embedded in a Motif +application). The procedures \fBTcl_WaitForEvent\fR and +\fBTcl_SetTimer\fR are normally implemented by Tcl, but may be +replaced with new versions to retarget the notifier (the +\fBTcl_InitNotifier\fR, \fBTcl_AlertNotifier\fR, +\fBTcl_FinalizeNotifier\fR, \fBTcl_Sleep\fR, +\fBTcl_CreateFileHandler\fR, and \fBTcl_DeleteFileHandler\fR must +also be replaced; see CREATING A NEW NOTIFIER below for details). +The procedures \fBTcl_ServiceAll\fR, \fBTcl_ServiceEvent\fR, +\fBTcl_GetServiceMode\fR, and \fBTcl_SetServiceMode\fR are provided +to help connect Tcl's event loop to an external event loop such as +Motif's. +.SH "NOTIFIER BASICS" +.PP +The easiest way to understand how the notifier works is to consider +what happens when \fBTcl_DoOneEvent\fR is called. +\fBTcl_DoOneEvent\fR is passed a \fIflags\fR argument that indicates +what sort of events it is OK to process and also whether or not to +block if no events are ready. \fBTcl_DoOneEvent\fR does the following +things: +.IP [1] +Check the event queue to see if it contains any events that can +be serviced. If so, service the first possible event, remove it +from the queue, and return. It does this by calling +\fBTcl_ServiceEvent\fR and passing in the \fIflags\fR argument. +.IP [2] +Prepare to block for an event. To do this, \fBTcl_DoOneEvent\fR +invokes a \fIsetup procedure\fR in each event source. +The event source will perform event-source specific initialization and +possibly call \fBTcl_SetMaxBlockTime\fR to limit how long +\fBTcl_WaitForEvent\fR will block if no new events occur. +.IP [3] +Call \fBTcl_WaitForEvent\fR. This procedure is implemented differently +on different platforms; it waits for an event to occur, based on the +information provided by the event sources. +It may cause the application to block if \fItimePtr\fR specifies +an interval other than 0. +\fBTcl_WaitForEvent\fR returns when something has happened, +such as a file becoming readable or the interval given by \fItimePtr\fR +expiring. If there are no events for \fBTcl_WaitForEvent\fR to +wait for, so that it would block forever, then it returns immediately +and \fBTcl_DoOneEvent\fR returns 0. +.IP [4] +Call a \fIcheck procedure\fR in each event source. The check +procedure determines whether any events of interest to this source +occurred. If so, the events are added to the event queue. +.IP [5] +Check the event queue to see if it contains any events that can +be serviced. If so, service the first possible event, remove it +from the queue, and return. +.IP [6] +See if there are idle callbacks pending. If so, invoke all of them and +return. +.IP [7] +Either return 0 to indicate that no events were ready, or go back to +step [2] if blocking was requested by the caller. +.SH "CREATING A NEW EVENT SOURCE" +.PP +An event source consists of three procedures invoked by the notifier, +plus additional C procedures that are invoked by higher-level code +to arrange for event-driven callbacks. The three procedures called +by the notifier consist of the setup and check procedures described +above, plus an additional procedure that is invoked when an event +is removed from the event queue for servicing. +.PP +The procedure \fBTcl_CreateEventSource\fR creates a new event source. +Its arguments specify the setup procedure and check procedure for +the event source. +\fISetupProc\fR should match the following prototype: +.PP +.CS +typedef void \fBTcl_EventSetupProc\fR( + ClientData \fIclientData\fR, + int \fIflags\fR); +.CE +.PP +The \fIclientData\fR argument will be the same as the \fIclientData\fR +argument to \fBTcl_CreateEventSource\fR; it is typically used to +point to private information managed by the event source. +The \fIflags\fR argument will be the same as the \fIflags\fR +argument passed to \fBTcl_DoOneEvent\fR except that it will never +be 0 (\fBTcl_DoOneEvent\fR replaces 0 with \fBTCL_ALL_EVENTS\fR). +\fIFlags\fR indicates what kinds of events should be considered; +if the bit corresponding to this event source is not set, the event +source should return immediately without doing anything. For +example, the file event source checks for the \fBTCL_FILE_EVENTS\fR +bit. +.PP +\fISetupProc\fR's job is to make sure that the application wakes up +when events of the desired type occur. This is typically done in a +platform-dependent fashion. For example, under Unix an event source +might call \fBTcl_CreateFileHandler\fR; under Windows it might +request notification with a Windows event. For timer-driven event +sources such as timer events or any polled event, the event source +can call \fBTcl_SetMaxBlockTime\fR to force the application to wake +up after a specified time even if no events have occurred. +If no event source calls \fBTcl_SetMaxBlockTime\fR +then \fBTcl_WaitForEvent\fR will wait as long as necessary for an +event to occur; otherwise, it will only wait as long as the shortest +interval passed to \fBTcl_SetMaxBlockTime\fR by one of the event +sources. If an event source knows that it already has events ready to +report, it can request a zero maximum block time. For example, the +setup procedure for the X event source looks to see if there are +events already queued. If there are, it calls +\fBTcl_SetMaxBlockTime\fR with a 0 block time so that +\fBTcl_WaitForEvent\fR does not block if there is no new data on the X +connection. +The \fItimePtr\fR argument to \fBTcl_WaitForEvent\fR points to +a structure that describes a time interval in seconds and +microseconds: +.PP +.CS +typedef struct Tcl_Time { + long \fIsec\fR; + long \fIusec\fR; +} \fBTcl_Time\fR; +.CE +.PP +The \fIusec\fR field should be less than 1000000. +.PP +Information provided to \fBTcl_SetMaxBlockTime\fR +is only used for the next call to \fBTcl_WaitForEvent\fR; it is +discarded after \fBTcl_WaitForEvent\fR returns. +The next time an event wait is done each of the event sources' +setup procedures will be called again, and they can specify new +information for that event wait. +.PP +If the application uses an external event loop rather than +\fBTcl_DoOneEvent\fR, the event sources may need to call +\fBTcl_SetMaxBlockTime\fR at other times. For example, if a new event +handler is registered that needs to poll for events, the event source +may call \fBTcl_SetMaxBlockTime\fR to set the block time to zero to +force the external event loop to call Tcl. In this case, +\fBTcl_SetMaxBlockTime\fR invokes \fBTcl_SetTimer\fR with the shortest +interval seen since the last call to \fBTcl_DoOneEvent\fR or +\fBTcl_ServiceAll\fR. +.PP +In addition to the generic procedure \fBTcl_SetMaxBlockTime\fR, other +platform-specific procedures may also be available for +\fIsetupProc\fR, if there is additional information needed by +\fBTcl_WaitForEvent\fR on that platform. For example, on Unix systems +the \fBTcl_CreateFileHandler\fR interface can be used to wait for file events. +.PP +The second procedure provided by each event source is its check +procedure, indicated by the \fIcheckProc\fR argument to +\fBTcl_CreateEventSource\fR. \fICheckProc\fR must match the +following prototype: +.PP +.CS +typedef void \fBTcl_EventCheckProc\fR( + ClientData \fIclientData\fR, + int \fIflags\fR); +.CE +.PP +The arguments to this procedure are the same as those for \fIsetupProc\fR. +\fBCheckProc\fR is invoked by \fBTcl_DoOneEvent\fR after it has waited +for events. Presumably at least one event source is now prepared to +queue an event. \fBTcl_DoOneEvent\fR calls each of the event sources +in turn, so they all have a chance to queue any events that are ready. +The check procedure does two things. First, it must see if any events +have triggered. Different event sources do this in different ways. +.PP +If an event source's check procedure detects an interesting event, it +must add the event to Tcl's event queue. To do this, the event source +calls \fBTcl_QueueEvent\fR. The \fIevPtr\fR argument is a pointer to +a dynamically allocated structure containing the event (see below for +more information on memory management issues). Each event source can +define its own event structure with whatever information is relevant +to that event source. However, the first element of the structure +must be a structure of type \fBTcl_Event\fR, and the address of this +structure is used when communicating between the event source and the +rest of the notifier. A \fBTcl_Event\fR has the following definition: +.PP +.CS +typedef struct { + Tcl_EventProc *\fIproc\fR; + struct Tcl_Event *\fInextPtr\fR; +} \fBTcl_Event\fR; +.CE +.PP +The event source must fill in the \fIproc\fR field of +the event before calling \fBTcl_QueueEvent\fR. +The \fInextPtr\fR is used to link together the events in the queue +and should not be modified by the event source. +.PP +An event may be added to the queue at any of three positions, depending +on the \fIposition\fR argument to \fBTcl_QueueEvent\fR: +.IP \fBTCL_QUEUE_TAIL\fR 24 +Add the event at the back of the queue, so that all other pending +events will be serviced first. This is almost always the right +place for new events. +.IP \fBTCL_QUEUE_HEAD\fR 24 +Add the event at the front of the queue, so that it will be serviced +before all other queued events. +.IP \fBTCL_QUEUE_MARK\fR 24 +Add the event at the front of the queue, unless there are other +events at the front whose position is \fBTCL_QUEUE_MARK\fR; if so, +add the new event just after all other \fBTCL_QUEUE_MARK\fR events. +This value of \fIposition\fR is used to insert an ordered sequence of +events at the front of the queue, such as a series of +Enter and Leave events synthesized during a grab or ungrab operation +in Tk. +.PP +When it is time to handle an event from the queue (steps 1 and 4 +above) \fBTcl_ServiceEvent\fR will invoke the \fIproc\fR specified +in the first queued \fBTcl_Event\fR structure. +\fIProc\fR must match the following prototype: +.PP +.CS +typedef int \fBTcl_EventProc\fR( + Tcl_Event *\fIevPtr\fR, + int \fIflags\fR); +.CE +.PP +The first argument to \fIproc\fR is a pointer to the event, which will +be the same as the first argument to the \fBTcl_QueueEvent\fR call that +added the event to the queue. +The second argument to \fIproc\fR is the \fIflags\fR argument for the +current call to \fBTcl_ServiceEvent\fR; this is used by the event source +to return immediately if its events are not relevant. +.PP +It is up to \fIproc\fR to handle the event, typically by invoking +one or more Tcl commands or C-level callbacks. +Once the event source has finished handling the event it returns 1 +to indicate that the event can be removed from the queue. +If for some reason the event source decides that the event cannot +be handled at this time, it may return 0 to indicate that the event +should be deferred for processing later; in this case \fBTcl_ServiceEvent\fR +will go on to the next event in the queue and attempt to service it. +There are several reasons why an event source might defer an event. +One possibility is that events of this type are excluded by the +\fIflags\fR argument. +For example, the file event source will always return 0 if the +\fBTCL_FILE_EVENTS\fR bit is not set in \fIflags\fR. +Another example of deferring events happens in Tk if +\fBTk_RestrictEvents\fR has been invoked to defer certain kinds +of window events. +.PP +When \fIproc\fR returns 1, \fBTcl_ServiceEvent\fR will remove the +event from the event queue and free its storage. +Note that the storage for an event must be allocated by +the event source (using \fBTcl_Alloc\fR or the Tcl macro \fBckalloc\fR) +before calling \fBTcl_QueueEvent\fR, but it +will be freed by \fBTcl_ServiceEvent\fR, not by the event source. +.PP +Threaded applications work in a +similar manner, except that there is a separate event queue for +each thread containing a Tcl interpreter. +Calling \fBTcl_QueueEvent\fR in a multithreaded application adds +an event to the current thread's queue. +To add an event to another thread's queue, use \fBTcl_ThreadQueueEvent\fR. +\fBTcl_ThreadQueueEvent\fR accepts as an argument a Tcl_ThreadId argument, +which uniquely identifies a thread in a Tcl application. To obtain the +Tcl_ThreadId for the current thread, use the \fBTcl_GetCurrentThread\fR +procedure. (A thread would then need to pass this identifier to other +threads for those threads to be able to add events to its queue.) +After adding an event to another thread's queue, you then typically +need to call \fBTcl_ThreadAlert\fR to +.QW "wake up" +that thread's notifier to alert it to the new event. +.PP +\fBTcl_DeleteEvents\fR can be used to explicitly remove one or more +events from the event queue. \fBTcl_DeleteEvents\fR calls \fIproc\fR +for each event in the queue, deleting those for with the procedure +returns 1. Events for which the procedure returns 0 are left in the +queue. \fIProc\fR should match the following prototype: +.PP +.CS +typedef int \fBTcl_EventDeleteProc\fR( + Tcl_Event *\fIevPtr\fR, + ClientData \fIclientData\fR); +.CE +.PP +The \fIclientData\fR argument will be the same as the \fIclientData\fR +argument to \fBTcl_DeleteEvents\fR; it is typically used to point to +private information managed by the event source. The \fIevPtr\fR will +point to the next event in the queue. +.PP +\fBTcl_DeleteEventSource\fR deletes an event source. The \fIsetupProc\fR, +\fIcheckProc\fR, and \fIclientData\fR arguments must exactly match those +provided to the \fBTcl_CreateEventSource\fR for the event source to be deleted. +If no such source exists, \fBTcl_DeleteEventSource\fR has no effect. +.SH "CREATING A NEW NOTIFIER" +.PP +The notifier consists of all the procedures described in this manual +entry, plus \fBTcl_DoOneEvent\fR and \fBTcl_Sleep\fR, which are +available on all platforms, and \fBTcl_CreateFileHandler\fR and +\fBTcl_DeleteFileHandler\fR, which are Unix-specific. Most of these +procedures are generic, in that they are the same for all notifiers. +However, none of the procedures are notifier-dependent: +\fBTcl_InitNotifier\fR, \fBTcl_AlertNotifier\fR, +\fBTcl_FinalizeNotifier\fR, \fBTcl_SetTimer\fR, \fBTcl_Sleep\fR, +\fBTcl_WaitForEvent\fR, \fBTcl_CreateFileHandler\fR, +\fBTcl_DeleteFileHandler\fR and \fBTcl_ServiceModeHook\fR. To support a +new platform or to integrate Tcl with an application-specific event loop, +you must write new versions of these procedures. +.PP +\fBTcl_InitNotifier\fR initializes the notifier state and returns +a handle to the notifier state. Tcl calls this +procedure when initializing a Tcl interpreter. Similarly, +\fBTcl_FinalizeNotifier\fR shuts down the notifier, and is +called by \fBTcl_Finalize\fR when shutting down a Tcl interpreter. +.PP +\fBTcl_WaitForEvent\fR is the lowest-level procedure in the notifier; +it is responsible for waiting for an +.QW interesting +event to occur or +for a given time to elapse. Before \fBTcl_WaitForEvent\fR is invoked, +each of the event sources' setup procedure will have been invoked. +The \fItimePtr\fR argument to +\fBTcl_WaitForEvent\fR gives the maximum time to block for an event, +based on calls to \fBTcl_SetMaxBlockTime\fR made by setup procedures +and on other information (such as the \fBTCL_DONT_WAIT\fR bit in +\fIflags\fR). +.PP +Ideally, \fBTcl_WaitForEvent\fR should only wait for an event +to occur; it should not actually process the event in any way. +Later on, the +event sources will process the raw events and create Tcl_Events on +the event queue in their \fIcheckProc\fR procedures. +However, on some platforms (such as Windows) this is not possible; +events may be processed in \fBTcl_WaitForEvent\fR, including queuing +Tcl_Events and more (for example, callbacks for native widgets may be +invoked). The return value from \fBTcl_WaitForEvent\fR must be either +0, 1, or \-1. On platforms such as Windows where events get processed in +\fBTcl_WaitForEvent\fR, a return value of 1 means that there may be more +events still pending that have not been processed. This is a sign to the +caller that it must call \fBTcl_WaitForEvent\fR again if it wants all +pending events to be processed. A 0 return value means that calling +\fBTcl_WaitForEvent\fR again will not have any effect: either this is a +platform where \fBTcl_WaitForEvent\fR only waits without doing any event +processing, or \fBTcl_WaitForEvent\fR knows for sure that there are no +additional events to process (e.g. it returned because the time +elapsed). Finally, a return value of \-1 means that the event loop is +no longer operational and the application should probably unwind and +terminate. Under Windows this happens when a WM_QUIT message is received; +under Unix it happens when \fBTcl_WaitForEvent\fR would have waited +forever because there were no active event sources and the timeout was +infinite. +.PP +\fBTcl_AlertNotifier\fR is used in multithreaded applications to allow +any thread to +.QW "wake up" +the notifier to alert it to new events on its +queue. \fBTcl_AlertNotifier\fR requires as an argument the notifier +handle returned by \fBTcl_InitNotifier\fR. +.PP +If the notifier will be used with an external event loop, then it must +also support the \fBTcl_SetTimer\fR interface. \fBTcl_SetTimer\fR is +invoked by \fBTcl_SetMaxBlockTime\fR whenever the maximum blocking +time has been reduced. \fBTcl_SetTimer\fR should arrange for the +external event loop to invoke \fBTcl_ServiceAll\fR after the specified +interval even if no events have occurred. This interface is needed +because \fBTcl_WaitForEvent\fR is not invoked when there is an external +event loop. If the +notifier will only be used from \fBTcl_DoOneEvent\fR, then +\fBTcl_SetTimer\fR need not do anything. +.PP +\fBTcl_ServiceModeHook\fR is called by the platform-independent portion +of the notifier when client code makes a call to +\fBTcl_SetServiceMode\fR. This hook is provided to support operating +systems that require special event handling when the application is in +a modal loop (the Windows notifier, for instance, uses this hook to +create a communication window). +.PP +On Unix systems, the file event source also needs support from the +notifier. The file event source consists of the +\fBTcl_CreateFileHandler\fR and \fBTcl_DeleteFileHandler\fR +procedures, which are described in the \fBTcl_CreateFileHandler\fR +manual page. +.PP +The \fBTcl_Sleep\fR and \fBTcl_DoOneEvent\fR interfaces are described +in their respective manual pages. +.PP +The easiest way to create a new notifier is to look at the code +for an existing notifier, such as the files \fBunix/tclUnixNotfy.c\fR +or \fBwin/tclWinNotify.c\fR in the Tcl source distribution. +.SH "REPLACING THE NOTIFIER" +.PP +A notifier that has been written according to the conventions above +can also be installed in a running process in place of the standard +notifier. This mechanism is used so that a single executable can be +used (with the standard notifier) as a stand-alone program and reused +(with a replacement notifier in a loadable extension) as an extension +to another program, such as a Web browser plugin. +.PP +To do this, the extension makes a call to \fBTcl_SetNotifier\fR +passing a pointer to a \fBTcl_NotifierProcs\fR data structure. The +structure has the following layout: +.PP +.CS +typedef struct Tcl_NotifierProcs { + Tcl_SetTimerProc *\fIsetTimerProc\fR; + Tcl_WaitForEventProc *\fIwaitForEventProc\fR; + Tcl_CreateFileHandlerProc *\fIcreateFileHandlerProc\fR; + Tcl_DeleteFileHandlerProc *\fIdeleteFileHandlerProc\fR; + Tcl_InitNotifierProc *\fIinitNotifierProc\fR; + Tcl_FinalizeNotifierProc *\fIfinalizeNotifierProc\fR; + Tcl_AlertNotifierProc *\fIalertNotifierProc\fR; + Tcl_ServiceModeHookProc *\fIserviceModeHookProc\fR; +} \fBTcl_NotifierProcs\fR; +.CE +.PP +Following the call to \fBTcl_SetNotifier\fR, the pointers given in +the \fBTcl_NotifierProcs\fR structure replace whatever notifier had +been installed in the process. +.PP +It is extraordinarily unwise to replace a running notifier. Normally, +\fBTcl_SetNotifier\fR should be called at process initialization time +before the first call to \fBTcl_InitNotifier\fR. +.SH "EXTERNAL EVENT LOOPS" +.PP +The notifier interfaces are designed so that Tcl can be embedded into +applications that have their own private event loops. In this case, +the application does not call \fBTcl_DoOneEvent\fR except in the case +of recursive event loops such as calls to the Tcl commands \fBupdate\fR +or \fBvwait\fR. Most of the time is spent in the external event loop +of the application. In this case the notifier must arrange for the +external event loop to call back into Tcl when something +happens on the various Tcl event sources. These callbacks should +arrange for appropriate Tcl events to be placed on the Tcl event queue. +.PP +Because the external event loop is not calling \fBTcl_DoOneEvent\fR on +a regular basis, it is up to the notifier to arrange for +\fBTcl_ServiceEvent\fR to be called whenever events are pending on the +Tcl event queue. The easiest way to do this is to invoke +\fBTcl_ServiceAll\fR at the end of each callback from the external +event loop. This will ensure that all of the event sources are +polled, any queued events are serviced, and any pending idle handlers +are processed before returning control to the application. In +addition, event sources that need to poll for events can call +\fBTcl_SetMaxBlockTime\fR to force the external event loop to call +Tcl even if no events are available on the system event queue. +.PP +As a side effect of processing events detected in the main external +event loop, Tcl may invoke \fBTcl_DoOneEvent\fR to start a recursive event +loop in commands like \fBvwait\fR. \fBTcl_DoOneEvent\fR will invoke +the external event loop, which will result in callbacks as described +in the preceding paragraph, which will result in calls to +\fBTcl_ServiceAll\fR. However, in these cases it is undesirable to +service events in \fBTcl_ServiceAll\fR. Servicing events there is +unnecessary because control will immediately return to the +external event loop and hence to \fBTcl_DoOneEvent\fR, which can +service the events itself. Furthermore, \fBTcl_DoOneEvent\fR is +supposed to service only a single event, whereas \fBTcl_ServiceAll\fR +normally services all pending events. To handle this situation, +\fBTcl_DoOneEvent\fR sets a flag for \fBTcl_ServiceAll\fR +that causes it to return without servicing any events. +This flag is called the \fIservice mode\fR; +\fBTcl_DoOneEvent\fR restores it to its previous value before it returns. +.PP +In some cases, however, it may be necessary for \fBTcl_ServiceAll\fR +to service events +even when it has been invoked from \fBTcl_DoOneEvent\fR. This happens +when there is yet another recursive event loop invoked via an +event handler called by \fBTcl_DoOneEvent\fR (such as one that is +part of a native widget). In this case, \fBTcl_DoOneEvent\fR may not +have a chance to service events so \fBTcl_ServiceAll\fR must service +them all. Any recursive event loop that calls an external event +loop rather than \fBTcl_DoOneEvent\fR must reset the service mode so +that all events get processed in \fBTcl_ServiceAll\fR. This is done +by invoking the \fBTcl_SetServiceMode\fR procedure. If +\fBTcl_SetServiceMode\fR is passed \fBTCL_SERVICE_NONE\fR, then calls +to \fBTcl_ServiceAll\fR will return immediately without processing any +events. If \fBTcl_SetServiceMode\fR is passed \fBTCL_SERVICE_ALL\fR, +then calls to \fBTcl_ServiceAll\fR will behave normally. +\fBTcl_SetServiceMode\fR returns the previous value of the service +mode, which should be restored when the recursive loop exits. +\fBTcl_GetServiceMode\fR returns the current value of the service +mode. +.SH "SEE ALSO" +Tcl_CreateFileHandler(3), Tcl_DeleteFileHandler(3), Tcl_Sleep(3), +Tcl_DoOneEvent(3), Thread(3) +.SH KEYWORDS +event, notifier, event queue, event sources, file events, timer, idle, service mode, threads diff --git a/tcl8.6/doc/OOInitStubs.3 b/tcl8.6/doc/OOInitStubs.3 new file mode 100644 index 0000000..bc42453 --- /dev/null +++ b/tcl8.6/doc/OOInitStubs.3 @@ -0,0 +1,54 @@ +'\" +'\" Copyright (c) 2012 Donal K. Fellows +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH Tcl_OOInitStubs 3 1.0 TclOO "TclOO Library Functions" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +Tcl_OOInitStubs \- initialize library access to TclOO functionality +.SH SYNOPSIS +.nf +\fB#include <tclOO.h>\fR +.sp +const char * +\fBTcl_OOInitStubs\fR(\fIinterp\fR) +.fi +.SH ARGUMENTS +.AS Tcl_Interp *interp in +.AP Tcl_Interp *interp in +The Tcl interpreter that the TclOO API is integrated with and whose C +interface is going to be used. +.BE +.SH DESCRIPTION +.PP +When an extension library is going to use the C interface exposed by TclOO, it +should use \fBTcl_OOInitStubs\fR to initialize its access to that interface +from within its \fI*\fB_Init\fR (or \fI*\fB_SafeInit\fR) function, passing in +the \fIinterp\fR that was passed into that routine as context. If the result +of calling \fBTcl_OOInitStubs\fR is NULL, the initialization failed and an +error message will have been left in the interpreter's result. Otherwise, the +initialization succeeded and the TclOO API may thereafter be used; the +version of the TclOO API is returned. +.PP +When using this function, either the C #define symbol \fBUSE_TCLOO_STUBS\fR +should be defined and your library code linked against the Tcl stub library, +or that #define symbol should \fInot\fR be defined and your library code +linked against the Tcl main library directly. +.SH "BACKWARD COMPATIBILITY NOTE" +.PP +If you are linking against the Tcl 8.5 forward compatibility package for +TclOO, \fIonly\fR the stub-enabled configuration is supported and you should +also link against the TclOO independent stub library; that library is an +integrated part of the main Tcl stub library in Tcl 8.6. +.SH KEYWORDS +stubs +.SH "SEE ALSO" +Tcl_InitStubs(3) +.\" Local variables: +.\" mode: nroff +.\" fill-column: 78 +.\" End: diff --git a/tcl8.6/doc/Object.3 b/tcl8.6/doc/Object.3 new file mode 100644 index 0000000..eadd041 --- /dev/null +++ b/tcl8.6/doc/Object.3 @@ -0,0 +1,352 @@ +'\" +'\" Copyright (c) 1996-1997 Sun Microsystems, Inc. +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH Tcl_Obj 3 8.5 Tcl "Tcl Library Procedures" +.so man.macros +.BS +.SH NAME +Tcl_NewObj, Tcl_DuplicateObj, Tcl_IncrRefCount, Tcl_DecrRefCount, Tcl_IsShared, Tcl_InvalidateStringRep \- manipulate Tcl values +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +Tcl_Obj * +\fBTcl_NewObj\fR() +.sp +Tcl_Obj * +\fBTcl_DuplicateObj\fR(\fIobjPtr\fR) +.sp +\fBTcl_IncrRefCount\fR(\fIobjPtr\fR) +.sp +\fBTcl_DecrRefCount\fR(\fIobjPtr\fR) +.sp +int +\fBTcl_IsShared\fR(\fIobjPtr\fR) +.sp +\fBTcl_InvalidateStringRep\fR(\fIobjPtr\fR) +.SH ARGUMENTS +.AS Tcl_Obj *objPtr +.AP Tcl_Obj *objPtr in +Points to a value; +must have been the result of a previous call to \fBTcl_NewObj\fR. +.BE +.SH INTRODUCTION +.PP +This man page presents an overview of Tcl values (called \fBTcl_Obj\fRs for +historical reasons) and how they are used. +It also describes generic procedures for managing Tcl values. +These procedures are used to create and copy values, +and increment and decrement the count of references (pointers) to values. +The procedures are used in conjunction with ones +that operate on specific types of values such as +\fBTcl_GetIntFromObj\fR and \fBTcl_ListObjAppendElement\fR. +The individual procedures are described along with the data structures +they manipulate. +.PP +Tcl's \fIdual-ported\fR values provide a general-purpose mechanism +for storing and exchanging Tcl values. +They largely replace the use of strings in Tcl. +For example, they are used to store variable values, +command arguments, command results, and scripts. +Tcl values behave like strings but also hold an internal representation +that can be manipulated more efficiently. +For example, a Tcl list is now represented as a value +that holds the list's string representation +as well as an array of pointers to the values for each list element. +Dual-ported values avoid most runtime type conversions. +They also improve the speed of many operations +since an appropriate representation is immediately available. +The compiler itself uses Tcl values to +cache the instruction bytecodes resulting from compiling scripts. +.PP +The two representations are a cache of each other and are computed lazily. +That is, each representation is only computed when necessary, +it is computed from the other representation, +and, once computed, it is saved. +In addition, a change in one representation invalidates the other one. +As an example, a Tcl program doing integer calculations can +operate directly on a variable's internal machine integer +representation without having to constantly convert +between integers and strings. +Only when it needs a string representing the variable's value, +say to print it, +will the program regenerate the string representation from the integer. +Although values contain an internal representation, +their semantics are defined in terms of strings: +an up-to-date string can always be obtained, +and any change to the value will be reflected in that string +when the value's string representation is fetched. +Because of this representation invalidation and regeneration, +it is dangerous for extension writers to access +\fBTcl_Obj\fR fields directly. +It is better to access Tcl_Obj information using +procedures like \fBTcl_GetStringFromObj\fR and \fBTcl_GetString\fR. +.PP +Values are allocated on the heap +and are referenced using a pointer to their \fBTcl_Obj\fR structure. +Values are shared as much as possible. +This significantly reduces storage requirements +because some values such as long lists are very large. +Also, most Tcl values are only read and never modified. +This is especially true for procedure arguments, +which can be shared between the caller and the called procedure. +Assignment and argument binding is done by +simply assigning a pointer to the value. +Reference counting is used to determine when it is safe to +reclaim a value's storage. +.PP +Tcl values are typed. +A value's internal representation is controlled by its type. +Several types are predefined in the Tcl core +including integer, double, list, and bytecode. +Extension writers can extend the set of types +by defining their own \fBTcl_ObjType\fR structs. +.SH "THE TCL_OBJ STRUCTURE" +.PP +Each Tcl value is represented by a \fBTcl_Obj\fR structure +which is defined as follows. +.PP +.CS +typedef struct Tcl_Obj { + int \fIrefCount\fR; + char *\fIbytes\fR; + int \fIlength\fR; + const Tcl_ObjType *\fItypePtr\fR; + union { + long \fIlongValue\fR; + double \fIdoubleValue\fR; + void *\fIotherValuePtr\fR; + Tcl_WideInt \fIwideValue\fR; + struct { + void *\fIptr1\fR; + void *\fIptr2\fR; + } \fItwoPtrValue\fR; + struct { + void *\fIptr\fR; + unsigned long \fIvalue\fR; + } \fIptrAndLongRep\fR; + } \fIinternalRep\fR; +} \fBTcl_Obj\fR; +.CE +.PP +The \fIbytes\fR and the \fIlength\fR members together hold +a value's UTF-8 string representation, +which is a \fIcounted string\fR not containing null bytes (UTF-8 null +characters should be encoded as a two byte sequence: 192, 128.) +\fIbytes\fR points to the first byte of the string representation. +The \fIlength\fR member gives the number of bytes. +The byte array must always have a null byte after the last data byte, +at offset \fIlength\fR; +this allows string representations +to be treated as conventional null-terminated C strings. +C programs use \fBTcl_GetStringFromObj\fR and \fBTcl_GetString\fR to get +a value's string representation. +If \fIbytes\fR is NULL, +the string representation is invalid. +.PP +A value's type manages its internal representation. +The member \fItypePtr\fR points to the Tcl_ObjType structure +that describes the type. +If \fItypePtr\fR is NULL, +the internal representation is invalid. +.PP +The \fIinternalRep\fR union member holds +a value's internal representation. +This is either a (long) integer, a double-precision floating-point number, +a pointer to a value containing additional information +needed by the value's type to represent the value, a Tcl_WideInt +integer, two arbitrary pointers, or a pair made up of an unsigned long +integer and a pointer. +.PP +The \fIrefCount\fR member is used to tell when it is safe to free +a value's storage. +It holds the count of active references to the value. +Maintaining the correct reference count is a key responsibility +of extension writers. +Reference counting is discussed below +in the section \fBSTORAGE MANAGEMENT OF VALUES\fR. +.PP +Although extension writers can directly access +the members of a Tcl_Obj structure, +it is much better to use the appropriate procedures and macros. +For example, extension writers should never +read or update \fIrefCount\fR directly; +they should use macros such as +\fBTcl_IncrRefCount\fR and \fBTcl_IsShared\fR instead. +.PP +A key property of Tcl values is that they hold two representations. +A value typically starts out containing only a string representation: +it is untyped and has a NULL \fItypePtr\fR. +A value containing an empty string or a copy of a specified string +is created using \fBTcl_NewObj\fR or \fBTcl_NewStringObj\fR respectively. +A value's string value is gotten with +\fBTcl_GetStringFromObj\fR or \fBTcl_GetString\fR +and changed with \fBTcl_SetStringObj\fR. +If the value is later passed to a procedure like \fBTcl_GetIntFromObj\fR +that requires a specific internal representation, +the procedure will create one and set the value's \fItypePtr\fR. +The internal representation is computed from the string representation. +A value's two representations are duals of each other: +changes made to one are reflected in the other. +For example, \fBTcl_ListObjReplace\fR will modify a value's +internal representation and the next call to \fBTcl_GetStringFromObj\fR +or \fBTcl_GetString\fR will reflect that change. +.PP +Representations are recomputed lazily for efficiency. +A change to one representation made by a procedure +such as \fBTcl_ListObjReplace\fR is not reflected immediately +in the other representation. +Instead, the other representation is marked invalid +so that it is only regenerated if it is needed later. +Most C programmers never have to be concerned with how this is done +and simply use procedures such as \fBTcl_GetBooleanFromObj\fR or +\fBTcl_ListObjIndex\fR. +Programmers that implement their own value types +must check for invalid representations +and mark representations invalid when necessary. +The procedure \fBTcl_InvalidateStringRep\fR is used +to mark a value's string representation invalid and to +free any storage associated with the old string representation. +.PP +Values usually remain one type over their life, +but occasionally a value must be converted from one type to another. +For example, a C program might build up a string in a value +with repeated calls to \fBTcl_AppendToObj\fR, +and then call \fBTcl_ListObjIndex\fR to extract a list element from +the value. +The same value holding the same string value +can have several different internal representations +at different times. +Extension writers can also force a value to be converted from one type +to another using the \fBTcl_ConvertToType\fR procedure. +Only programmers that create new value types need to be concerned +about how this is done. +A procedure defined as part of the value type's implementation +creates a new internal representation for a value +and changes its \fItypePtr\fR. +See the man page for \fBTcl_RegisterObjType\fR +to see how to create a new value type. +.SH "EXAMPLE OF THE LIFETIME OF A VALUE" +.PP +As an example of the lifetime of a value, +consider the following sequence of commands: +.PP +.CS +\fBset x 123\fR +.CE +.PP +This assigns to \fIx\fR an untyped value whose +\fIbytes\fR member points to \fB123\fR and \fIlength\fR member contains 3. +The value's \fItypePtr\fR member is NULL. +.PP +.CS +\fBputs "x is $x"\fR +.CE +.PP +\fIx\fR's string representation is valid (since \fIbytes\fR is non-NULL) +and is fetched for the command. +.PP +.CS +\fBincr x\fR +.CE +.PP +The \fBincr\fR command first gets an integer from \fIx\fR's value +by calling \fBTcl_GetIntFromObj\fR. +This procedure checks whether the value is already an integer value. +Since it is not, it converts the value +by setting the value's internal representation +to the integer \fB123\fR +and setting the value's \fItypePtr\fR +to point to the integer Tcl_ObjType structure. +Both representations are now valid. +\fBincr\fR increments the value's integer internal representation +then invalidates its string representation +(by calling \fBTcl_InvalidateStringRep\fR) +since the string representation +no longer corresponds to the internal representation. +.PP +.CS +\fBputs "x is now $x"\fR +.CE +.PP +The string representation of \fIx\fR's value is needed +and is recomputed. +The string representation is now \fB124\fR +and both representations are again valid. +.SH "STORAGE MANAGEMENT OF VALUES" +.PP +Tcl values are allocated on the heap and are shared as much as possible +to reduce storage requirements. +Reference counting is used to determine when a value is +no longer needed and can safely be freed. +A value just created by \fBTcl_NewObj\fR or \fBTcl_NewStringObj\fR +has \fIrefCount\fR 0. +The macro \fBTcl_IncrRefCount\fR increments the reference count +when a new reference to the value is created. +The macro \fBTcl_DecrRefCount\fR decrements the count +when a reference is no longer needed and, +if the value's reference count drops to zero, frees its storage. +A value shared by different code or data structures has +\fIrefCount\fR greater than 1. +Incrementing a value's reference count ensures that +it will not be freed too early or have its value change accidentally. +.PP +As an example, the bytecode interpreter shares argument values +between calling and called Tcl procedures to avoid having to copy values. +It assigns the call's argument values to the procedure's +formal parameter variables. +In doing so, it calls \fBTcl_IncrRefCount\fR to increment +the reference count of each argument since there is now a new +reference to it from the formal parameter. +When the called procedure returns, +the interpreter calls \fBTcl_DecrRefCount\fR to decrement +each argument's reference count. +When a value's reference count drops less than or equal to zero, +\fBTcl_DecrRefCount\fR reclaims its storage. +Most command procedures do not have to be concerned about +reference counting since they use a value's value immediately +and do not retain a pointer to the value after they return. +However, if they do retain a pointer to a value in a data structure, +they must be careful to increment its reference count +since the retained pointer is a new reference. +.PP +Command procedures that directly modify values +such as those for \fBlappend\fR and \fBlinsert\fR must be careful to +copy a shared value before changing it. +They must first check whether the value is shared +by calling \fBTcl_IsShared\fR. +If the value is shared they must copy the value +by using \fBTcl_DuplicateObj\fR; +this returns a new duplicate of the original value +that has \fIrefCount\fR 0. +If the value is not shared, +the command procedure +.QW "owns" +the value and can safely modify it directly. +For example, the following code appears in the command procedure +that implements \fBlinsert\fR. +This procedure modifies the list value passed to it in \fIobjv[1]\fR +by inserting \fIobjc-3\fR new elements before \fIindex\fR. +.PP +.CS +listPtr = objv[1]; +if (\fBTcl_IsShared\fR(listPtr)) { + listPtr = \fBTcl_DuplicateObj\fR(listPtr); +} +result = Tcl_ListObjReplace(interp, listPtr, index, 0, + (objc-3), &(objv[3])); +.CE +.PP +As another example, \fBincr\fR's command procedure +must check whether the variable's value is shared before +incrementing the integer in its internal representation. +If it is shared, it needs to duplicate the value +in order to avoid accidentally changing values in other data structures. +.SH "SEE ALSO" +Tcl_ConvertToType(3), Tcl_GetIntFromObj(3), Tcl_ListObjAppendElement(3), Tcl_ListObjIndex(3), Tcl_ListObjReplace(3), Tcl_RegisterObjType(3) +.SH KEYWORDS +internal representation, value, value creation, value type, +reference counting, string representation, type conversion diff --git a/tcl8.6/doc/ObjectType.3 b/tcl8.6/doc/ObjectType.3 new file mode 100644 index 0000000..bf414ac --- /dev/null +++ b/tcl8.6/doc/ObjectType.3 @@ -0,0 +1,256 @@ +'\" +'\" Copyright (c) 1996-1997 Sun Microsystems, Inc. +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH Tcl_ObjType 3 8.0 Tcl "Tcl Library Procedures" +.so man.macros +.BS +.SH NAME +Tcl_RegisterObjType, Tcl_GetObjType, Tcl_AppendAllObjTypes, Tcl_ConvertToType \- manipulate Tcl value types +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +\fBTcl_RegisterObjType\fR(\fItypePtr\fR) +.sp +const Tcl_ObjType * +\fBTcl_GetObjType\fR(\fItypeName\fR) +.sp +int +\fBTcl_AppendAllObjTypes\fR(\fIinterp, objPtr\fR) +.sp +int +\fBTcl_ConvertToType\fR(\fIinterp, objPtr, typePtr\fR) +.SH ARGUMENTS +.AS "const char" *typeName +.AP "const Tcl_ObjType" *typePtr in +Points to the structure containing information about the Tcl value type. +This storage must live forever, +typically by being statically allocated. +.AP "const char" *typeName in +The name of a Tcl value type that \fBTcl_GetObjType\fR should look up. +.AP Tcl_Interp *interp in +Interpreter to use for error reporting. +.AP Tcl_Obj *objPtr in +For \fBTcl_AppendAllObjTypes\fR, this points to the value onto which +it appends the name of each value type as a list element. +For \fBTcl_ConvertToType\fR, this points to a value that +must have been the result of a previous call to \fBTcl_NewObj\fR. +.BE + +.SH DESCRIPTION +.PP +The procedures in this man page manage Tcl value types (sometimes +referred to as object types or \fBTcl_ObjType\fRs for historical reasons). +They are used to register new value types, look up types, +and force conversions from one type to another. +.PP +\fBTcl_RegisterObjType\fR registers a new Tcl value type +in the table of all value types that \fBTcl_GetObjType\fR +can look up by name. There are other value types supported by Tcl +as well, which Tcl chooses not to register. Extensions can likewise +choose to register the value types they create or not. +The argument \fItypePtr\fR points to a Tcl_ObjType structure that +describes the new type by giving its name +and by supplying pointers to four procedures +that implement the type. +If the type table already contains a type +with the same name as in \fItypePtr\fR, +it is replaced with the new type. +The Tcl_ObjType structure is described +in the section \fBTHE TCL_OBJTYPE STRUCTURE\fR below. +.PP +\fBTcl_GetObjType\fR returns a pointer to the registered Tcl_ObjType +with name \fItypeName\fR. +It returns NULL if no type with that name is registered. +.PP +\fBTcl_AppendAllObjTypes\fR appends the name of each registered value type +as a list element onto the Tcl value referenced by \fIobjPtr\fR. +The return value is \fBTCL_OK\fR unless there was an error +converting \fIobjPtr\fR to a list value; +in that case \fBTCL_ERROR\fR is returned. +.PP +\fBTcl_ConvertToType\fR converts a value from one type to another +if possible. +It creates a new internal representation for \fIobjPtr\fR +appropriate for the target type \fItypePtr\fR +and sets its \fItypePtr\fR member as determined by calling the +\fItypePtr->setFromAnyProc\fR routine. +Any internal representation for \fIobjPtr\fR's old type is freed. +If an error occurs during conversion, it returns \fBTCL_ERROR\fR +and leaves an error message in the result value for \fIinterp\fR +unless \fIinterp\fR is NULL. +Otherwise, it returns \fBTCL_OK\fR. +Passing a NULL \fIinterp\fR allows this procedure to be used +as a test whether the conversion can be done (and in fact was done). +.VS 8.5 +.PP +In many cases, the \fItypePtr->setFromAnyProc\fR routine will +set \fIobjPtr->typePtr\fR to the argument value \fItypePtr\fR, +but that is no longer guaranteed. The \fIsetFromAnyProc\fR is +free to set the internal representation for \fIobjPtr\fR to make +use of another related Tcl_ObjType, if it sees fit. +.VE 8.5 +.SH "THE TCL_OBJTYPE STRUCTURE" +.PP +Extension writers can define new value types by defining four +procedures and +initializing a Tcl_ObjType structure to describe the type. +Extension writers may also pass a pointer to their Tcl_ObjType +structure to \fBTcl_RegisterObjType\fR if they wish to permit +other extensions to look up their Tcl_ObjType by name with +the \fBTcl_GetObjType\fR routine. +The \fBTcl_ObjType\fR structure is defined as follows: +.PP +.CS +typedef struct Tcl_ObjType { + const char *\fIname\fR; + Tcl_FreeInternalRepProc *\fIfreeIntRepProc\fR; + Tcl_DupInternalRepProc *\fIdupIntRepProc\fR; + Tcl_UpdateStringProc *\fIupdateStringProc\fR; + Tcl_SetFromAnyProc *\fIsetFromAnyProc\fR; +} \fBTcl_ObjType\fR; +.CE +.SS "THE NAME FIELD" +.PP +The \fIname\fR member describes the name of the type, e.g. \fBint\fR. +When a type is registered, this is the name used by callers +of \fBTcl_GetObjType\fR to lookup the type. For unregistered +types, the \fIname\fR field is primarily of value for debugging. +The remaining four members are pointers to procedures +called by the generic Tcl value code: +.SS "THE SETFROMANYPROC FIELD" +.PP +The \fIsetFromAnyProc\fR member contains the address of a function +called to create a valid internal representation +from a value's string representation. +.PP +.CS +typedef int \fBTcl_SetFromAnyProc\fR( + Tcl_Interp *\fIinterp\fR, + Tcl_Obj *\fIobjPtr\fR); +.CE +.PP +If an internal representation cannot be created from the string, +it returns \fBTCL_ERROR\fR and puts a message +describing the error in the result value for \fIinterp\fR +unless \fIinterp\fR is NULL. +If \fIsetFromAnyProc\fR is successful, +it stores the new internal representation, +sets \fIobjPtr\fR's \fItypePtr\fR member to point to +the \fBTcl_ObjType\fR struct corresponding to the new +internal representation, and returns \fBTCL_OK\fR. +Before setting the new internal representation, +the \fIsetFromAnyProc\fR must free any internal representation +of \fIobjPtr\fR's old type; +it does this by calling the old type's \fIfreeIntRepProc\fR +if it is not NULL. +.PP +As an example, the \fIsetFromAnyProc\fR for the built-in Tcl list type +gets an up-to-date string representation for \fIobjPtr\fR +by calling \fBTcl_GetStringFromObj\fR. +It parses the string to verify it is in a valid list format and +to obtain each element value in the list, and, if this succeeds, +stores the list elements in \fIobjPtr\fR's internal representation +and sets \fIobjPtr\fR's \fItypePtr\fR member to point to the list type's +Tcl_ObjType structure. +.PP +Do not release \fIobjPtr\fR's old internal representation unless you +replace it with a new one or reset the \fItypePtr\fR member to NULL. +.PP +The \fIsetFromAnyProc\fR member may be set to NULL, if the routines +making use of the internal representation have no need to derive that +internal representation from an arbitrary string value. However, in +this case, passing a pointer to the type to \fBTcl_ConvertToType\fR will +lead to a panic, so to avoid this possibility, the type +should \fInot\fR be registered. +.SS "THE UPDATESTRINGPROC FIELD" +.PP +The \fIupdateStringProc\fR member contains the address of a function +called to create a valid string representation +from a value's internal representation. +.PP +.CS +typedef void \fBTcl_UpdateStringProc\fR( + Tcl_Obj *\fIobjPtr\fR); +.CE +.PP +\fIobjPtr\fR's \fIbytes\fR member is always NULL when it is called. +It must always set \fIbytes\fR non-NULL before returning. +We require the string representation's byte array +to have a null after the last byte, at offset \fIlength\fR, +and to have no null bytes before that; this allows string representations +to be treated as conventional null character-terminated C strings. +These restrictions are easily met by using Tcl's internal UTF encoding +for the string representation, same as one would do for other +Tcl routines accepting string values as arguments. +Storage for the byte array must be allocated in the heap by \fBTcl_Alloc\fR +or \fBckalloc\fR. Note that \fIupdateStringProc\fRs must allocate +enough storage for the string's bytes and the terminating null byte. +.PP +The \fIupdateStringProc\fR for Tcl's built-in double type, for example, +calls Tcl_PrintDouble to write to a buffer of size TCL_DOUBLE_SPACE, +then allocates and copies the string representation to just enough +space to hold it. A pointer to the allocated space is stored in +the \fIbytes\fR member. +.PP +The \fIupdateStringProc\fR member may be set to NULL, if the routines +making use of the internal representation are written so that the +string representation is never invalidated. Failure to meet this +obligation will lead to panics or crashes when \fBTcl_GetStringFromObj\fR +or other similar routines ask for the string representation. +.SS "THE DUPINTREPPROC FIELD" +.PP +The \fIdupIntRepProc\fR member contains the address of a function +called to copy an internal representation from one value to another. +.PP +.CS +typedef void \fBTcl_DupInternalRepProc\fR( + Tcl_Obj *\fIsrcPtr\fR, + Tcl_Obj *\fIdupPtr\fR); +.CE +.PP +\fIdupPtr\fR's internal representation is made a copy of \fIsrcPtr\fR's +internal representation. +Before the call, +\fIsrcPtr\fR's internal representation is valid and \fIdupPtr\fR's is not. +\fIsrcPtr\fR's value type determines what +copying its internal representation means. +.PP +For example, the \fIdupIntRepProc\fR for the Tcl integer type +simply copies an integer. +The built-in list type's \fIdupIntRepProc\fR uses a far more +sophisticated scheme to continue sharing storage as much as it +reasonably can. +.SS "THE FREEINTREPPROC FIELD" +.PP +The \fIfreeIntRepProc\fR member contains the address of a function +that is called when a value is freed. +.PP +.CS +typedef void \fBTcl_FreeInternalRepProc\fR( + Tcl_Obj *\fIobjPtr\fR); +.CE +.PP +The \fIfreeIntRepProc\fR function can deallocate the storage +for the value's internal representation +and do other type-specific processing necessary when a value is freed. +.PP +For example, the list type's \fIfreeIntRepProc\fR respects +the storage sharing scheme established by the \fIdupIntRepProc\fR +so that it only frees storage when the last value sharing it +is being freed. +.PP +The \fIfreeIntRepProc\fR member can be set to NULL +to indicate that the internal representation does not require freeing. +The \fIfreeIntRepProc\fR implementation must not access the +\fIbytes\fR member of the value, since Tcl makes its own internal +uses of that field during value deletion. The defined tasks for +the \fIfreeIntRepProc\fR have no need to consult the \fIbytes\fR +member. +.SH "SEE ALSO" +Tcl_NewObj(3), Tcl_DecrRefCount(3), Tcl_IncrRefCount(3) +.SH KEYWORDS +internal representation, value, value type, string representation, type conversion diff --git a/tcl8.6/doc/OpenFileChnl.3 b/tcl8.6/doc/OpenFileChnl.3 new file mode 100644 index 0000000..582ff4b --- /dev/null +++ b/tcl8.6/doc/OpenFileChnl.3 @@ -0,0 +1,648 @@ +'\" +'\" Copyright (c) 1996-1997 Sun Microsystems, Inc. +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH Tcl_OpenFileChannel 3 8.3 Tcl "Tcl Library Procedures" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +Tcl_OpenFileChannel, Tcl_OpenCommandChannel, Tcl_MakeFileChannel, Tcl_GetChannel, Tcl_GetChannelNames, Tcl_GetChannelNamesEx, Tcl_RegisterChannel, Tcl_UnregisterChannel, Tcl_DetachChannel, Tcl_IsStandardChannel, Tcl_Close, Tcl_ReadChars, Tcl_Read, Tcl_GetsObj, Tcl_Gets, Tcl_WriteObj, Tcl_WriteChars, Tcl_Write, Tcl_Flush, Tcl_Seek, Tcl_Tell, Tcl_TruncateChannel, Tcl_GetChannelOption, Tcl_SetChannelOption, Tcl_Eof, Tcl_InputBlocked, Tcl_InputBuffered, Tcl_OutputBuffered, Tcl_Ungets, Tcl_ReadRaw, Tcl_WriteRaw \- buffered I/O facilities using channels +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +Tcl_Channel +\fBTcl_OpenFileChannel\fR(\fIinterp, fileName, mode, permissions\fR) +.sp +Tcl_Channel +\fBTcl_OpenCommandChannel\fR(\fIinterp, argc, argv, flags\fR) +.sp +Tcl_Channel +\fBTcl_MakeFileChannel\fR(\fIhandle, readOrWrite\fR) +.sp +Tcl_Channel +\fBTcl_GetChannel\fR(\fIinterp, channelName, modePtr\fR) +.sp +int +\fBTcl_GetChannelNames\fR(\fIinterp\fR) +.sp +int +\fBTcl_GetChannelNamesEx\fR(\fIinterp, pattern\fR) +.sp +void +\fBTcl_RegisterChannel\fR(\fIinterp, channel\fR) +.sp +int +\fBTcl_UnregisterChannel\fR(\fIinterp, channel\fR) +.sp +int +\fBTcl_DetachChannel\fR(\fIinterp, channel\fR) +.sp +int +\fBTcl_IsStandardChannel\fR(\fIchannel\fR) +.sp +int +\fBTcl_Close\fR(\fIinterp, channel\fR) +.sp +int +\fBTcl_ReadChars\fR(\fIchannel, readObjPtr, charsToRead, appendFlag\fR) +.sp +int +\fBTcl_Read\fR(\fIchannel, readBuf, bytesToRead\fR) +.sp +int +\fBTcl_GetsObj\fR(\fIchannel, lineObjPtr\fR) +.sp +int +\fBTcl_Gets\fR(\fIchannel, lineRead\fR) +.sp +int +\fBTcl_Ungets\fR(\fIchannel, input, inputLen, addAtEnd\fR) +.sp +int +\fBTcl_WriteObj\fR(\fIchannel, writeObjPtr\fR) +.sp +int +\fBTcl_WriteChars\fR(\fIchannel, charBuf, bytesToWrite\fR) +.sp +int +\fBTcl_Write\fR(\fIchannel, byteBuf, bytesToWrite\fR) +.sp +int +\fBTcl_ReadRaw\fR(\fIchannel, readBuf, bytesToRead\fR) +.sp +int +\fBTcl_WriteRaw\fR(\fIchannel, byteBuf, bytesToWrite\fR) +.sp +int +\fBTcl_Eof\fR(\fIchannel\fR) +.sp +int +\fBTcl_Flush\fR(\fIchannel\fR) +.sp +int +\fBTcl_InputBlocked\fR(\fIchannel\fR) +.sp +int +\fBTcl_InputBuffered\fR(\fIchannel\fR) +.sp +int +\fBTcl_OutputBuffered\fR(\fIchannel\fR) +.sp +Tcl_WideInt +\fBTcl_Seek\fR(\fIchannel, offset, seekMode\fR) +.sp +Tcl_WideInt +\fBTcl_Tell\fR(\fIchannel\fR) +.sp +int +\fBTcl_TruncateChannel\fR(\fIchannel, length\fR) +.sp +int +\fBTcl_GetChannelOption\fR(\fIinterp, channel, optionName, optionValue\fR) +.sp +int +\fBTcl_SetChannelOption\fR(\fIinterp, channel, optionName, newValue\fR) +.sp +.SH ARGUMENTS +.AS Tcl_DString *channelName in/out +.AP Tcl_Interp *interp in +Used for error reporting and to look up a channel registered in it. +.AP "const char" *fileName in +The name of a local or network file. +.AP "const char" *mode in +Specifies how the file is to be accessed. May have any of the values +allowed for the \fImode\fR argument to the Tcl \fBopen\fR command. +.AP int permissions in +POSIX-style permission flags such as 0644. If a new file is created, these +permissions will be set on the created file. +.AP int argc in +The number of elements in \fIargv\fR. +.AP "const char" **argv in +Arguments for constructing a command pipeline. These values have the same +meaning as the non-switch arguments to the Tcl \fBexec\fR command. +.AP int flags in +Specifies the disposition of the stdio handles in pipeline: OR-ed +combination of \fBTCL_STDIN\fR, \fBTCL_STDOUT\fR, \fBTCL_STDERR\fR, and +\fBTCL_ENFORCE_MODE\fR. If \fBTCL_STDIN\fR is set, stdin for the first child +in the pipe is the pipe channel, otherwise it is the same as the standard +input of the invoking process; likewise for \fBTCL_STDOUT\fR and +\fBTCL_STDERR\fR. If \fBTCL_ENFORCE_MODE\fR is not set, then the pipe can +redirect stdio handles to override the stdio handles for which +\fBTCL_STDIN\fR, \fBTCL_STDOUT\fR and \fBTCL_STDERR\fR have been set. If it +is set, then such redirections cause an error. +.AP ClientData handle in +Operating system specific handle for I/O to a file. For Unix this is a +file descriptor, for Windows it is a HANDLE. +.AP int readOrWrite in +OR-ed combination of \fBTCL_READABLE\fR and \fBTCL_WRITABLE\fR to indicate +what operations are valid on \fIhandle\fR. +.AP "const char" *channelName in +The name of the channel. +.AP int *modePtr out +Points at an integer variable that will receive an OR-ed combination of +\fBTCL_READABLE\fR and \fBTCL_WRITABLE\fR denoting whether the channel is +open for reading and writing. +.AP "const char" *pattern in +The pattern to match on, passed to Tcl_StringMatch, or NULL. +.AP Tcl_Channel channel in +A Tcl channel for input or output. Must have been the return value +from a procedure such as \fBTcl_OpenFileChannel\fR. +.AP Tcl_Obj *readObjPtr in/out +A pointer to a Tcl value in which to store the characters read from the +channel. +.AP int charsToRead in +The number of characters to read from the channel. If the channel's encoding +is \fBbinary\fR, this is equivalent to the number of bytes to read from the +channel. +.AP int appendFlag in +If non-zero, data read from the channel will be appended to the value. +Otherwise, the data will replace the existing contents of the value. +.AP char *readBuf out +A buffer in which to store the bytes read from the channel. +.AP int bytesToRead in +The number of bytes to read from the channel. The buffer \fIreadBuf\fR must +be large enough to hold this many bytes. +.AP Tcl_Obj *lineObjPtr in/out +A pointer to a Tcl value in which to store the line read from the +channel. The line read will be appended to the current value of the +value. +.AP Tcl_DString *lineRead in/out +A pointer to a Tcl dynamic string in which to store the line read from the +channel. Must have been initialized by the caller. The line read will be +appended to any data already in the dynamic string. +.AP "const char" *input in +The input to add to a channel buffer. +.AP int inputLen in +Length of the input +.AP int addAtEnd in +Flag indicating whether the input should be added to the end or +beginning of the channel buffer. +.AP Tcl_Obj *writeObjPtr in +A pointer to a Tcl value whose contents will be output to the channel. +.AP "const char" *charBuf in +A buffer containing the characters to output to the channel. +.AP "const char" *byteBuf in +A buffer containing the bytes to output to the channel. +.AP int bytesToWrite in +The number of bytes to consume from \fIcharBuf\fR or \fIbyteBuf\fR and +output to the channel. +.AP Tcl_WideInt offset in +How far to move the access point in the channel at which the next input or +output operation will be applied, measured in bytes from the position +given by \fIseekMode\fR. May be either positive or negative. +.AP int seekMode in +Relative to which point to seek; used with \fIoffset\fR to calculate the new +access point for the channel. Legal values are \fBSEEK_SET\fR, +\fBSEEK_CUR\fR, and \fBSEEK_END\fR. +.AP Tcl_WideInt length in +The (non-negative) length to truncate the channel the channel to. +.AP "const char" *optionName in +The name of an option applicable to this channel, such as \fB\-blocking\fR. +May have any of the values accepted by the \fBfconfigure\fR command. +.AP Tcl_DString *optionValue in +Where to store the value of an option or a list of all options and their +values. Must have been initialized by the caller. +.AP "const char" *newValue in +New value for the option given by \fIoptionName\fR. +.BE +.SH DESCRIPTION +.PP +The Tcl channel mechanism provides a device-independent and +platform-independent mechanism for performing buffered input +and output operations on a variety of file, socket, and device +types. +The channel mechanism is extensible to new channel types, by +providing a low-level channel driver for the new type; the channel driver +interface is described in the manual entry for \fBTcl_CreateChannel\fR. The +channel mechanism provides a buffering scheme modeled after +Unix's standard I/O, and it also allows for nonblocking I/O on +channels. +.PP +The procedures described in this manual entry comprise the C APIs of the +generic layer of the channel architecture. For a description of the channel +driver architecture and how to implement channel drivers for new types of +channels, see the manual entry for \fBTcl_CreateChannel\fR. +.SH TCL_OPENFILECHANNEL +.PP +\fBTcl_OpenFileChannel\fR opens a file specified by \fIfileName\fR and +returns a channel handle that can be used to perform input and output on +the file. This API is modeled after the \fBfopen\fR procedure of +the Unix standard I/O library. +The syntax and meaning of all arguments is similar to those +given in the Tcl \fBopen\fR command when opening a file. +If an error occurs while opening the channel, \fBTcl_OpenFileChannel\fR +returns NULL and records a POSIX error code that can be +retrieved with \fBTcl_GetErrno\fR. +In addition, if \fIinterp\fR is non-NULL, \fBTcl_OpenFileChannel\fR +leaves an error message in \fIinterp\fR's result after any error. +As of Tcl 8.4, the value-based API \fBTcl_FSOpenFileChannel\fR should +be used in preference to \fBTcl_OpenFileChannel\fR wherever possible. +.PP +The newly created channel is not registered in the supplied interpreter; to +register it, use \fBTcl_RegisterChannel\fR, described below. +If one of the standard channels, \fBstdin\fR, \fBstdout\fR or \fBstderr\fR was +previously closed, the act of creating the new channel also assigns it as a +replacement for the standard channel. +.SH TCL_OPENCOMMANDCHANNEL +.PP +\fBTcl_OpenCommandChannel\fR provides a C-level interface to the +functions of the \fBexec\fR and \fBopen\fR commands. +It creates a sequence of subprocesses specified +by the \fIargv\fR and \fIargc\fR arguments and returns a channel that can +be used to communicate with these subprocesses. +The \fIflags\fR argument indicates what sort of communication will +exist with the command pipeline. +.PP +If the \fBTCL_STDIN\fR flag is set then the standard input for the +first subprocess will be tied to the channel: writing to the channel +will provide input to the subprocess. If \fBTCL_STDIN\fR is not set, +then standard input for the first subprocess will be the same as this +application's standard input. If \fBTCL_STDOUT\fR is set then +standard output from the last subprocess can be read from the channel; +otherwise it goes to this application's standard output. If +\fBTCL_STDERR\fR is set, standard error output for all subprocesses is +returned to the channel and results in an error when the channel is +closed; otherwise it goes to this application's standard error. If +\fBTCL_ENFORCE_MODE\fR is not set, then \fIargc\fR and \fIargv\fR can +redirect the stdio handles to override \fBTCL_STDIN\fR, +\fBTCL_STDOUT\fR, and \fBTCL_STDERR\fR; if it is set, then it is an +error for argc and argv to override stdio channels for which +\fBTCL_STDIN\fR, \fBTCL_STDOUT\fR, and \fBTCL_STDERR\fR have been set. +.PP +If an error occurs while opening the channel, \fBTcl_OpenCommandChannel\fR +returns NULL and records a POSIX error code that can be retrieved with +\fBTcl_GetErrno\fR. +In addition, \fBTcl_OpenCommandChannel\fR leaves an error message in +the interpreter's result if \fIinterp\fR is not NULL. +.PP +The newly created channel is not registered in the supplied interpreter; to +register it, use \fBTcl_RegisterChannel\fR, described below. +If one of the standard channels, \fBstdin\fR, \fBstdout\fR or \fBstderr\fR was +previously closed, the act of creating the new channel also assigns it as a +replacement for the standard channel. +.SH TCL_MAKEFILECHANNEL +.PP +\fBTcl_MakeFileChannel\fR makes a \fBTcl_Channel\fR from an existing, +platform-specific, file handle. +The newly created channel is not registered in the supplied interpreter; to +register it, use \fBTcl_RegisterChannel\fR, described below. +If one of the standard channels, \fBstdin\fR, \fBstdout\fR or \fBstderr\fR was +previously closed, the act of creating the new channel also assigns it as a +replacement for the standard channel. +.SH TCL_GETCHANNEL +.PP +\fBTcl_GetChannel\fR returns a channel given the \fIchannelName\fR used to +create it with \fBTcl_CreateChannel\fR and a pointer to a Tcl interpreter in +\fIinterp\fR. If a channel by that name is not registered in that interpreter, +the procedure returns NULL. If the \fImodePtr\fR argument is not NULL, it +points at an integer variable that will receive an OR-ed combination of +\fBTCL_READABLE\fR and \fBTCL_WRITABLE\fR describing whether the channel is +open for reading and writing. +.PP +\fBTcl_GetChannelNames\fR and \fBTcl_GetChannelNamesEx\fR write the +names of the registered channels to the interpreter's result as a +list value. \fBTcl_GetChannelNamesEx\fR will filter these names +according to the \fIpattern\fR. If \fIpattern\fR is NULL, then it +will not do any filtering. The return value is \fBTCL_OK\fR if no +errors occurred writing to the result, otherwise it is \fBTCL_ERROR\fR, +and the error message is left in the interpreter's result. +.SH TCL_REGISTERCHANNEL +.PP +\fBTcl_RegisterChannel\fR adds a channel to the set of channels accessible +in \fIinterp\fR. After this call, Tcl programs executing in that +interpreter can refer to the channel in input or output operations using +the name given in the call to \fBTcl_CreateChannel\fR. After this call, +the channel becomes the property of the interpreter, and the caller should +not call \fBTcl_Close\fR for the channel; the channel will be closed +automatically when it is unregistered from the interpreter. +.PP +Code executing outside of any Tcl interpreter can call +\fBTcl_RegisterChannel\fR with \fIinterp\fR as NULL, to indicate that it +wishes to hold a reference to this channel. Subsequently, the channel can +be registered in a Tcl interpreter and it will only be closed when the +matching number of calls to \fBTcl_UnregisterChannel\fR have been made. +This allows code executing outside of any interpreter to safely hold a +reference to a channel that is also registered in a Tcl interpreter. +.PP +This procedure interacts with the code managing the standard +channels. If no standard channels were initialized before the first +call to \fBTcl_RegisterChannel\fR, they will get initialized by that +call. See \fBTcl_StandardChannels\fR for a general treatise about +standard channels and the behavior of the Tcl library with regard to +them. +.SH TCL_UNREGISTERCHANNEL +.PP +\fBTcl_UnregisterChannel\fR removes a channel from the set of channels +accessible in \fIinterp\fR. After this call, Tcl programs will no longer be +able to use the channel's name to refer to the channel in that interpreter. +If this operation removed the last registration of the channel in any +interpreter, the channel is also closed and destroyed. +.PP +Code not associated with a Tcl interpreter can call +\fBTcl_UnregisterChannel\fR with \fIinterp\fR as NULL, to indicate to Tcl +that it no longer holds a reference to that channel. If this is the last +reference to the channel, it will now be closed. \fBTcl_UnregisterChannel\fR +is very similar to \fBTcl_DetachChannel\fR except that it will also +close the channel if no further references to it exist. +.SH TCL_DETACHCHANNEL +.PP +\fBTcl_DetachChannel\fR removes a channel from the set of channels +accessible in \fIinterp\fR. After this call, Tcl programs will no longer be +able to use the channel's name to refer to the channel in that interpreter. +Beyond that, this command has no further effect. It cannot be used on +the standard channels (\fBstdout\fR, \fBstderr\fR, \fBstdin\fR), and will return +\fBTCL_ERROR\fR if passed one of those channels. +.PP +Code not associated with a Tcl interpreter can call +\fBTcl_DetachChannel\fR with \fIinterp\fR as NULL, to indicate to Tcl +that it no longer holds a reference to that channel. If this is the last +reference to the channel, unlike \fBTcl_UnregisterChannel\fR, +it will not be closed. +.SH TCL_ISSTANDARDCHANNEL +.PP +\fBTcl_IsStandardChannel\fR tests whether a channel is one of the +three standard channels, \fBstdin\fR, \fBstdout\fR or \fBstderr\fR. +If so, it returns 1, otherwise 0. +.PP +No attempt is made to check whether the given channel or the standard +channels are initialized or otherwise valid. +.SH TCL_CLOSE +.PP +\fBTcl_Close\fR destroys the channel \fIchannel\fR, which must denote a +currently open channel. The channel should not be registered in any +interpreter when \fBTcl_Close\fR is called. Buffered output is flushed to +the channel's output device prior to destroying the channel, and any +buffered input is discarded. If this is a blocking channel, the call does +not return until all buffered data is successfully sent to the channel's +output device. If this is a nonblocking channel and there is buffered +output that cannot be written without blocking, the call returns +immediately; output is flushed in the background and the channel will be +closed once all of the buffered data has been output. In this case errors +during flushing are not reported. +.PP +If the channel was closed successfully, \fBTcl_Close\fR returns \fBTCL_OK\fR. +If an error occurs, \fBTcl_Close\fR returns \fBTCL_ERROR\fR and records a +POSIX error code that can be retrieved with \fBTcl_GetErrno\fR. +If the channel is being closed synchronously and an error occurs during +closing of the channel and \fIinterp\fR is not NULL, an error message is +left in the interpreter's result. +.PP +Note: it is not safe to call \fBTcl_Close\fR on a channel that has been +registered using \fBTcl_RegisterChannel\fR; see the documentation for +\fBTcl_RegisterChannel\fR, above, for details. If the channel has ever +been given as the \fBchan\fR argument in a call to +\fBTcl_RegisterChannel\fR, you should instead use +\fBTcl_UnregisterChannel\fR, which will internally call \fBTcl_Close\fR +when all calls to \fBTcl_RegisterChannel\fR have been matched by +corresponding calls to \fBTcl_UnregisterChannel\fR. +.SH "TCL_READCHARS AND TCL_READ" +.PP +\fBTcl_ReadChars\fR consumes bytes from \fIchannel\fR, converting the bytes +to UTF-8 based on the channel's encoding and storing the produced data in +\fIreadObjPtr\fR's string representation. The return value of +\fBTcl_ReadChars\fR is the number of characters, up to \fIcharsToRead\fR, +that were stored in \fIreadObjPtr\fR. If an error occurs while reading, the +return value is \-1 and \fBTcl_ReadChars\fR records a POSIX error code that +can be retrieved with \fBTcl_GetErrno\fR. +.PP +Setting \fIcharsToRead\fR to \fB\-1\fR will cause the command to read +all characters currently available (non-blocking) or everything until +eof (blocking mode). +.PP +The return value may be smaller than the value to read, indicating that less +data than requested was available. This is called a \fIshort read\fR. In +blocking mode, this can only happen on an end-of-file. In nonblocking mode, +a short read can also occur if there is not enough input currently +available: \fBTcl_ReadChars\fR returns a short count rather than waiting +for more data. +.PP +If the channel is in blocking mode, a return value of zero indicates an +end-of-file condition. If the channel is in nonblocking mode, a return +value of zero indicates either that no input is currently available or an +end-of-file condition. Use \fBTcl_Eof\fR and \fBTcl_InputBlocked\fR to tell +which of these conditions actually occurred. +.PP +\fBTcl_ReadChars\fR translates the various end-of-line representations into +the canonical \fB\en\fR internal representation according to the current +end-of-line recognition mode. End-of-line recognition and the various +platform-specific modes are described in the manual entry for the Tcl +\fBfconfigure\fR command. +.PP +As a performance optimization, when reading from a channel with the encoding +\fBbinary\fR, the bytes are not converted to UTF-8 as they are read. +Instead, they are stored in \fIreadObjPtr\fR's internal representation as a +byte-array value. The string representation of this value will only be +constructed if it is needed (e.g., because of a call to +\fBTcl_GetStringFromObj\fR). In this way, byte-oriented data can be read +from a channel, manipulated by calling \fBTcl_GetByteArrayFromObj\fR and +related functions, and then written to a channel without the expense of ever +converting to or from UTF-8. +.PP +\fBTcl_Read\fR is similar to \fBTcl_ReadChars\fR, except that it does not do +encoding conversions, regardless of the channel's encoding. It is deprecated +and exists for backwards compatibility with non-internationalized Tcl +extensions. It consumes bytes from \fIchannel\fR and stores them in +\fIreadBuf\fR, performing end-of-line translations on the way. The return value +of \fBTcl_Read\fR is the number of bytes, up to \fIbytesToRead\fR, written in +\fIreadBuf\fR. The buffer produced by \fBTcl_Read\fR is not null-terminated. +Its contents are valid from the zeroth position up to and excluding the +position indicated by the return value. +.PP +\fBTcl_ReadRaw\fR is the same as \fBTcl_Read\fR but does not +compensate for stacking. While \fBTcl_Read\fR (and the other functions +in the API) always get their data from the topmost channel in the +stack the supplied channel is part of, \fBTcl_ReadRaw\fR does +not. Thus this function is \fBonly\fR usable for transformational +channel drivers, i.e. drivers used in the middle of a stack of +channels, to move data from the channel below into the transformation. +.SH "TCL_GETSOBJ AND TCL_GETS" +.PP +\fBTcl_GetsObj\fR consumes bytes from \fIchannel\fR, converting the bytes to +UTF-8 based on the channel's encoding, until a full line of input has been +seen. If the channel's encoding is \fBbinary\fR, each byte read from the +channel is treated as an individual Unicode character. All of the +characters of the line except for the terminating end-of-line character(s) +are appended to \fIlineObjPtr\fR's string representation. The end-of-line +character(s) are read and discarded. +.PP +If a line was successfully read, the return value is greater than or equal +to zero and indicates the number of bytes stored in \fIlineObjPtr\fR. If an +error occurs, \fBTcl_GetsObj\fR returns \-1 and records a POSIX error code +that can be retrieved with \fBTcl_GetErrno\fR. \fBTcl_GetsObj\fR also +returns \-1 if the end of the file is reached; the \fBTcl_Eof\fR procedure +can be used to distinguish an error from an end-of-file condition. +.PP +If the channel is in nonblocking mode, the return value can also be \-1 if +no data was available or the data that was available did not contain an +end-of-line character. When \-1 is returned, the \fBTcl_InputBlocked\fR +procedure may be invoked to determine if the channel is blocked because +of input unavailability. +.PP +\fBTcl_Gets\fR is the same as \fBTcl_GetsObj\fR except the resulting +characters are appended to the dynamic string given by +\fIlineRead\fR rather than a Tcl value. +.SH "TCL_UNGETS" +.PP +\fBTcl_Ungets\fR is used to add data to the input queue of a channel, +at either the head or tail of the queue. The pointer \fIinput\fR points +to the data that is to be added. The length of the input to add is given +by \fIinputLen\fR. A non-zero value of \fIaddAtEnd\fR indicates that the +data is to be added at the end of queue; otherwise it will be added at the +head of the queue. If \fIchannel\fR has a +.QW sticky +EOF set, no data will be +added to the input queue. \fBTcl_Ungets\fR returns \fIinputLen\fR or +\-1 if an error occurs. +.SH "TCL_WRITECHARS, TCL_WRITEOBJ, AND TCL_WRITE" +.PP +\fBTcl_WriteChars\fR accepts \fIbytesToWrite\fR bytes of character data at +\fIcharBuf\fR. The UTF-8 characters in the buffer are converted to the +channel's encoding and queued for output to \fIchannel\fR. If +\fIbytesToWrite\fR is negative, \fBTcl_WriteChars\fR expects \fIcharBuf\fR +to be null-terminated and it outputs everything up to the null. +.PP +Data queued for output may not appear on the output device immediately, due +to internal buffering. If the data should appear immediately, call +\fBTcl_Flush\fR after the call to \fBTcl_WriteChars\fR, or set the +\fB\-buffering\fR option on the channel to \fBnone\fR. If you wish the data +to appear as soon as a complete line is accepted for output, set the +\fB\-buffering\fR option on the channel to \fBline\fR mode. +.PP +The return value of \fBTcl_WriteChars\fR is a count of how many bytes were +accepted for output to the channel. This is either greater than zero to +indicate success or \-1 to indicate that an error occurred. If an error +occurs, \fBTcl_WriteChars\fR records a POSIX error code that may be +retrieved with \fBTcl_GetErrno\fR. +.PP +Newline characters in the output data are translated to platform-specific +end-of-line sequences according to the \fB\-translation\fR option for the +channel. This is done even if the channel has no encoding. +.PP +\fBTcl_WriteObj\fR is similar to \fBTcl_WriteChars\fR except it +accepts a Tcl value whose contents will be output to the channel. The +UTF-8 characters in \fIwriteObjPtr\fR's string representation are converted +to the channel's encoding and queued for output to \fIchannel\fR. +As a performance optimization, when writing to a channel with the encoding +\fBbinary\fR, UTF-8 characters are not converted as they are written. +Instead, the bytes in \fIwriteObjPtr\fR's internal representation as a +byte-array value are written to the channel. The byte-array representation +of the value will be constructed if it is needed. In this way, +byte-oriented data can be read from a channel, manipulated by calling +\fBTcl_GetByteArrayFromObj\fR and related functions, and then written to a +channel without the expense of ever converting to or from UTF-8. +.PP +\fBTcl_Write\fR is similar to \fBTcl_WriteChars\fR except that it does not do +encoding conversions, regardless of the channel's encoding. It is +deprecated and exists for backwards compatibility with non-internationalized +Tcl extensions. It accepts \fIbytesToWrite\fR bytes of data at +\fIbyteBuf\fR and queues them for output to \fIchannel\fR. If +\fIbytesToWrite\fR is negative, \fBTcl_Write\fR expects \fIbyteBuf\fR to be +null-terminated and it outputs everything up to the null. +.PP +\fBTcl_WriteRaw\fR is the same as \fBTcl_Write\fR but does not +compensate for stacking. While \fBTcl_Write\fR (and the other +functions in the API) always feed their input to the topmost channel +in the stack the supplied channel is part of, \fBTcl_WriteRaw\fR does +not. Thus this function is \fBonly\fR usable for transformational +channel drivers, i.e. drivers used in the middle of a stack of +channels, to move data from the transformation into the channel below +it. +.SH TCL_FLUSH +.PP +\fBTcl_Flush\fR causes all of the buffered output data for \fIchannel\fR +to be written to its underlying file or device as soon as possible. +If the channel is in blocking mode, the call does not return until +all the buffered data has been sent to the channel or some error occurred. +The call returns immediately if the channel is nonblocking; it starts +a background flush that will write the buffered data to the channel +eventually, as fast as the channel is able to absorb it. +.PP +The return value is normally \fBTCL_OK\fR. +If an error occurs, \fBTcl_Flush\fR returns \fBTCL_ERROR\fR and +records a POSIX error code that can be retrieved with \fBTcl_GetErrno\fR. +.SH TCL_SEEK +.PP +\fBTcl_Seek\fR moves the access point in \fIchannel\fR where subsequent +data will be read or written. Buffered output is flushed to the channel and +buffered input is discarded, prior to the seek operation. +.PP +\fBTcl_Seek\fR normally returns the new access point. +If an error occurs, \fBTcl_Seek\fR returns \-1 and records a POSIX error +code that can be retrieved with \fBTcl_GetErrno\fR. +After an error, the access point may or may not have been moved. +.SH TCL_TELL +.PP +\fBTcl_Tell\fR returns the current access point for a channel. The returned +value is \-1 if the channel does not support seeking. +.SH TCL_TRUNCATECHANNEL +.PP +\fBTcl_TruncateChannel\fR truncates the file underlying \fIchannel\fR +to a given \fIlength\fR of bytes. It returns \fBTCL_OK\fR if the +operation succeeded, and \fBTCL_ERROR\fR otherwise. +.SH TCL_GETCHANNELOPTION +.PP +\fBTcl_GetChannelOption\fR retrieves, in \fIoptionValue\fR, the value of one of +the options currently in effect for a channel, or a list of all options and +their values. The \fIchannel\fR argument identifies the channel for which +to query an option or retrieve all options and their values. +If \fIoptionName\fR is not NULL, it is the name of the +option to query; the option's value is copied to the Tcl dynamic string +denoted by \fIoptionValue\fR. If +\fIoptionName\fR is NULL, the function stores an alternating list of option +names and their values in \fIoptionValue\fR, using a series of calls to +\fBTcl_DStringAppendElement\fR. The various preexisting options and +their possible values are described in the manual entry for the Tcl +\fBfconfigure\fR command. Other options can be added by each channel type. +These channel type specific options are described in the manual entry for +the Tcl command that creates a channel of that type; for example, the +additional options for TCP based channels are described in the manual entry +for the Tcl \fBsocket\fR command. +The procedure normally returns \fBTCL_OK\fR. If an error occurs, it returns +\fBTCL_ERROR\fR and calls \fBTcl_SetErrno\fR to store an appropriate POSIX +error code. +.SH TCL_SETCHANNELOPTION +.PP +\fBTcl_SetChannelOption\fR sets a new value \fInewValue\fR +for an option \fIoptionName\fR on \fIchannel\fR. +The procedure normally returns \fBTCL_OK\fR. If an error occurs, +it returns \fBTCL_ERROR\fR; in addition, if \fIinterp\fR is non-NULL, +\fBTcl_SetChannelOption\fR leaves an error message in the interpreter's result. +.SH TCL_EOF +.PP +\fBTcl_Eof\fR returns a nonzero value if \fIchannel\fR encountered +an end of file during the last input operation. +.SH TCL_INPUTBLOCKED +.PP +\fBTcl_InputBlocked\fR returns a nonzero value if \fIchannel\fR is in +nonblocking mode and the last input operation returned less data than +requested because there was insufficient data available. +The call always returns zero if the channel is in blocking mode. +.SH TCL_INPUTBUFFERED +.PP +\fBTcl_InputBuffered\fR returns the number of bytes of input currently +buffered in the internal buffers for a channel. If the channel is not open +for reading, this function always returns zero. +.SH TCL_OUTPUTBUFFERED +.PP +\fBTcl_OutputBuffered\fR returns the number of bytes of output +currently buffered in the internal buffers for a channel. If the +channel is not open for writing, this function always returns zero. +.SH "PLATFORM ISSUES" +.PP +The handles returned from \fBTcl_GetChannelHandle\fR depend on the +platform and the channel type. On Unix platforms, the handle is +always a Unix file descriptor as returned from the \fBopen\fR system +call. On Windows platforms, the handle is a file \fBHANDLE\fR when +the channel was created with \fBTcl_OpenFileChannel\fR, +\fBTcl_OpenCommandChannel\fR, or \fBTcl_MakeFileChannel\fR. Other +channel types may return a different type of handle on Windows +platforms. +.SH "SEE ALSO" +DString(3), fconfigure(n), filename(n), fopen(3), Tcl_CreateChannel(3) +.SH KEYWORDS +access point, blocking, buffered I/O, channel, channel driver, end of file, +flush, input, nonblocking, output, read, seek, write diff --git a/tcl8.6/doc/OpenTcp.3 b/tcl8.6/doc/OpenTcp.3 new file mode 100644 index 0000000..9fe2615 --- /dev/null +++ b/tcl8.6/doc/OpenTcp.3 @@ -0,0 +1,169 @@ +'\" +'\" Copyright (c) 1996-7 Sun Microsystems, Inc. +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH Tcl_OpenTcpClient 3 8.0 Tcl "Tcl Library Procedures" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +Tcl_OpenTcpClient, Tcl_MakeTcpClientChannel, Tcl_OpenTcpServer \- procedures to open channels using TCP sockets +.SH SYNOPSIS +.nf +\fB#include <tcl.h> \fR +.sp +Tcl_Channel +\fBTcl_OpenTcpClient\fR(\fIinterp, port, host, myaddr, myport, async\fR) +.sp +Tcl_Channel +\fBTcl_MakeTcpClientChannel\fR(\fIsock\fR) +.sp +Tcl_Channel +\fBTcl_OpenTcpServer\fR(\fIinterp, port, myaddr, proc, clientData\fR) +.sp +.SH ARGUMENTS +.AS Tcl_TcpAcceptProc clientData +.AP Tcl_Interp *interp in +Tcl interpreter to use for error reporting. If non-NULL and an +error occurs, an error message is left in the interpreter's result. +.AP int port in +A port number to connect to as a client or to listen on as a server. +.AP "const char" *host in +A string specifying a host name or address for the remote end of the connection. +.AP int myport in +A port number for the client's end of the socket. If 0, a port number +is allocated at random. +.AP "const char" *myaddr in +A string specifying the host name or address for network interface to use +for the local end of the connection. If NULL, a default interface is +chosen. +.AP int async in +If nonzero, the client socket is connected asynchronously to the server. +.AP ClientData sock in +Platform-specific handle for client TCP socket. +.AP Tcl_TcpAcceptProc *proc in +Pointer to a procedure to invoke each time a new connection is +accepted via the socket. +.AP ClientData clientData in +Arbitrary one-word value to pass to \fIproc\fR. +.BE +.SH DESCRIPTION +.PP +These functions are convenience procedures for creating +channels that communicate over TCP sockets. +The operations on a channel +are described in the manual entry for \fBTcl_OpenFileChannel\fR. +.SS TCL_OPENTCPCLIENT +.PP +\fBTcl_OpenTcpClient\fR opens a client TCP socket connected to a \fIport\fR +on a specific \fIhost\fR, and returns a channel that can be used to +communicate with the server. The host to connect to can be specified either +as a domain name style name (e.g. \fBwww.sunlabs.com\fR), or as a string +containing the alphanumeric representation of its four-byte address (e.g. +\fB127.0.0.1\fR). Use the string \fBlocalhost\fR to connect to a TCP socket on +the host on which the function is invoked. +.PP +The \fImyaddr\fR and \fImyport\fR arguments allow a client to specify an +address for the local end of the connection. If \fImyaddr\fR is NULL, then +an interface is chosen automatically by the operating system. +If \fImyport\fR is 0, then a port number is chosen at random by +the operating system. +.PP +If \fIasync\fR is zero, the call to \fBTcl_OpenTcpClient\fR returns only +after the client socket has either successfully connected to the server, or +the attempted connection has failed. +If \fIasync\fR is nonzero the socket is connected asynchronously and the +returned channel may not yet be connected to the server when the call to +\fBTcl_OpenTcpClient\fR returns. If the channel is in blocking mode and an +input or output operation is done on the channel before the connection is +completed or fails, that operation will wait until the connection either +completes successfully or fails. If the channel is in nonblocking mode, the +input or output operation will return immediately and a subsequent call to +\fBTcl_InputBlocked\fR on the channel will return nonzero. +.PP +The returned channel is opened for reading and writing. +If an error occurs in opening the socket, \fBTcl_OpenTcpClient\fR returns +NULL and records a POSIX error code that can be retrieved +with \fBTcl_GetErrno\fR. +In addition, if \fIinterp\fR is non-NULL, an error message +is left in the interpreter's result. +.PP +The newly created channel is not registered in the supplied interpreter; to +register it, use \fBTcl_RegisterChannel\fR. +If one of the standard channels, \fBstdin\fR, \fBstdout\fR or \fBstderr\fR was +previously closed, the act of creating the new channel also assigns it as a +replacement for the standard channel. +.SS TCL_MAKETCPCLIENTCHANNEL +.PP +\fBTcl_MakeTcpClientChannel\fR creates a \fBTcl_Channel\fR around an +existing, platform specific, handle for a client TCP socket. +.PP +The newly created channel is not registered in the supplied interpreter; to +register it, use \fBTcl_RegisterChannel\fR. +If one of the standard channels, \fBstdin\fR, \fBstdout\fR or \fBstderr\fR was +previously closed, the act of creating the new channel also assigns it as a +replacement for the standard channel. +.SS TCL_OPENTCPSERVER +.PP +\fBTcl_OpenTcpServer\fR opens a TCP socket on the local host on a specified +\fIport\fR and uses the Tcl event mechanism to accept requests from clients +to connect to it. The \fImyaddr\fR argument specifies the network interface. +If \fImyaddr\fR is NULL the special address INADDR_ANY should be used to +allow connections from any network interface. +Each time a client connects to this socket, Tcl creates a channel +for the new connection and invokes \fIproc\fR with information about +the channel. \fIProc\fR must match the following prototype: +.PP +.CS +typedef void \fBTcl_TcpAcceptProc\fR( + ClientData \fIclientData\fR, + Tcl_Channel \fIchannel\fR, + char *\fIhostName\fR, + int \fIport\fR); +.CE +.PP +The \fIclientData\fR argument will be the same as the \fIclientData\fR +argument to \fBTcl_OpenTcpServer\fR, \fIchannel\fR will be the handle +for the new channel, \fIhostName\fR points to a string containing +the name of the client host making the connection, and \fIport\fR +will contain the client's port number. +The new channel +is opened for both input and output. +If \fIproc\fR raises an error, the connection is closed automatically. +\fIProc\fR has no return value, but if it wishes to reject the +connection it can close \fIchannel\fR. +.PP +\fBTcl_OpenTcpServer\fR normally returns a pointer to a channel +representing the server socket. +If an error occurs, \fBTcl_OpenTcpServer\fR returns NULL and +records a POSIX error code that can be retrieved with \fBTcl_GetErrno\fR. +In addition, if the interpreter is non-NULL, an error message +is left in the interpreter's result. +.PP +The channel returned by \fBTcl_OpenTcpServer\fR cannot be used for +either input or output. +It is simply a handle for the socket used to accept connections. +The caller can close the channel to shut down the server and disallow +further connections from new clients. +.PP +TCP server channels operate correctly only in applications that dispatch +events through \fBTcl_DoOneEvent\fR or through Tcl commands such as +\fBvwait\fR; otherwise Tcl will never notice that a connection request from +a remote client is pending. +.PP +The newly created channel is not registered in the supplied interpreter; to +register it, use \fBTcl_RegisterChannel\fR. +If one of the standard channels, \fBstdin\fR, \fBstdout\fR or \fBstderr\fR was +previously closed, the act of creating the new channel also assigns it as a +replacement for the standard channel. +.SH "PLATFORM ISSUES" +.PP +On Unix platforms, the socket handle is a Unix file descriptor as +returned by the \fBsocket\fR system call. On the Windows platform, the +socket handle is a \fBSOCKET\fR as defined in the WinSock API. +.SH "SEE ALSO" +Tcl_OpenFileChannel(3), Tcl_RegisterChannel(3), vwait(n) +.SH KEYWORDS +channel, client, server, socket, TCP diff --git a/tcl8.6/doc/Panic.3 b/tcl8.6/doc/Panic.3 new file mode 100644 index 0000000..af86665 --- /dev/null +++ b/tcl8.6/doc/Panic.3 @@ -0,0 +1,89 @@ +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH Tcl_Panic 3 8.4 Tcl "Tcl Library Procedures" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +Tcl_Panic, Tcl_PanicVA, Tcl_SetPanicProc \- report fatal error and abort +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +void +\fBTcl_Panic\fR(\fIformat\fR, \fIarg\fR, \fIarg\fR, \fI...\fR) +.sp +void +\fBTcl_PanicVA\fR(\fIformat\fR, \fIargList\fR) +.sp +void +\fBTcl_SetPanicProc\fR(\fIpanicProc\fR) +.sp +.SH ARGUMENTS +.AS Tcl_PanicProc *panicProc +.AP "const char*" format in +A printf-style format string. +.AP "" arg in +Arguments matching the format string. +.AP va_list argList in +An argument list of arguments matching the format string. +Must have been initialized using \fBva_start\fR, +and cleared using \fBva_end\fR. +.AP Tcl_PanicProc *panicProc in +Procedure to report fatal error message and abort. +.BE +.SH DESCRIPTION +.PP +When the Tcl library detects that its internal data structures are in an +inconsistent state, or that its C procedures have been called in a +manner inconsistent with their documentation, it calls \fBTcl_Panic\fR +to display a message describing the error and abort the process. The +\fIformat\fR argument is a format string describing how to format the +remaining arguments \fIarg\fR into an error message, according to the +same formatting rules used by the \fBprintf\fR family of functions. The +same formatting rules are also used by the built-in Tcl command +\fBformat\fR. +.PP +In a freshly loaded Tcl library, \fBTcl_Panic\fR prints the formatted +error message to the standard error file of the process, and then +calls \fBabort\fR to terminate the process. \fBTcl_Panic\fR does not +return. On Windows, when a debugger is running, the formatted error +message is sent to the debugger in stead. If the windows executable +does not have a stderr channel (e.g. \fBwish.exe\fR), then a +system dialog box is used to display the panic message. +.PP +\fBTcl_SetPanicProc\fR may be used to modify the behavior of +\fBTcl_Panic\fR. The \fIpanicProc\fR argument should match the +type \fBTcl_PanicProc\fR: +.PP +.CS +typedef void \fBTcl_PanicProc\fR( + const char *\fBformat\fR, + \fBarg\fR, \fBarg\fR,...); +.CE +.PP +After \fBTcl_SetPanicProc\fR returns, any future calls to +\fBTcl_Panic\fR will call \fIpanicProc\fR, passing along the +\fIformat\fR and \fIarg\fR arguments. \fIpanicProc\fR should avoid +making calls into the Tcl library, or into other libraries that may +call the Tcl library, since the original call to \fBTcl_Panic\fR +indicates the Tcl library is not in a state of reliable operation. +.PP +The typical use of \fBTcl_SetPanicProc\fR arranges for the error message +to be displayed or reported in a manner more suitable for the +application or the platform. +.PP +Although the primary callers of \fBTcl_Panic\fR are the procedures of +the Tcl library, \fBTcl_Panic\fR is a public function and may be called +by any extension or application that wishes to abort the process and +have a panic message displayed the same way that panic messages from Tcl +will be displayed. +.PP +\fBTcl_PanicVA\fR is the same as \fBTcl_Panic\fR except that instead of +taking a variable number of arguments it takes an argument list. +.SH "SEE ALSO" +abort(3), printf(3), exec(n), format(n) +.SH KEYWORDS +abort, fatal, error diff --git a/tcl8.6/doc/ParseArgs.3 b/tcl8.6/doc/ParseArgs.3 new file mode 100644 index 0000000..df0ad33 --- /dev/null +++ b/tcl8.6/doc/ParseArgs.3 @@ -0,0 +1,198 @@ +'\" +'\" Copyright (c) 2008 Donal K. Fellows +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH Tcl_ParseArgsObjv 3 8.6 Tcl "Tcl Library Procedures" +.so man.macros +.BS +.SH NAME +Tcl_ParseArgsObjv \- parse arguments according to a tabular description +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +int +\fBTcl_ParseArgsObjv\fR(\fIinterp, argTable, objcPtr, objv, remObjv\fR) +.SH ARGUMENTS +.AS "const Tcl_ArgvInfo" ***remObjv in/out +.AP Tcl_Interp *interp out +Where to store error messages. +.AP "const Tcl_ArgvInfo" *argTable in +Pointer to array of option descriptors. +.AP int *objcPtr in/out +A pointer to variable holding number of arguments in \fIobjv\fR. Will be +modified to hold number of arguments left in the unprocessed argument list +stored in \fIremObjv\fR. +.AP "Tcl_Obj *const" *objv in +The array of arguments to be parsed. +.AP Tcl_Obj ***remObjv out +Pointer to a variable that will hold the array of unprocessed arguments. +Should be NULL if no return of unprocessed arguments is required. If +\fIobjcPtr\fR is updated to a non-zero value, the array returned through this +must be deallocated using \fBckfree\fR. +.BE +.SH DESCRIPTION +.PP +The \fBTcl_ParseArgsObjv\fR function provides a system for parsing argument +lists of the form +.QW "\fB\-someName \fIsomeValue\fR ..." . +Such argument lists are commonly found both in the arguments to a program and +in the arguments to an individual Tcl command. This parser assumes that the +order of the arguments does not matter, other than in so far as later copies +of a duplicated option overriding earlier ones. +.PP +The argument array is described by the \fIobjcPtr\fR and \fIobjv\fR +parameters, and an array of unprocessed arguments is returned through the +\fIobjcPtr\fR and \fIremObjv\fR parameters; if no return of unprocessed +arguments is desired, the \fIremObjv\fR parameter should be NULL. If any +problems happen, including if the +.QW "generate help" +option is selected, an error message is left in the interpreter result and +TCL_ERROR is returned. Otherwise, the interpreter result is left unchanged and +TCL_OK is returned. +.PP +The collection of arguments to be parsed is described by the \fIargTable\fR +parameter. This points to a table of descriptor structures that is terminated +by an entry with the \fItype\fR field set to TCL_ARGV_END. As convenience, the +following prototypical entries are provided: +.TP +\fBTCL_ARGV_AUTO_HELP\fR +. +Enables the argument processor to provide help when passed the argument +.QW \fB\-help\fR . +.TP +\fBTCL_ARGV_AUTO_REST\fR +. +Instructs the argument processor that arguments after +.QW \fB\-\-\fR +are to be unprocessed. +.TP +\fBTCL_ARGV_TABLE_END\fR +. +Marks the end of the table of argument descriptors. +.SS "ARGUMENT DESCRIPTOR ENTRIES" +.PP +Each entry of the argument descriptor table must be a structure of type +\fBTcl_ArgvInfo\fR. The structure is defined as this: +.PP +.CS +typedef struct { + int \fItype\fR; + const char *\fIkeyStr\fR; + void *\fIsrcPtr\fR; + void *\fIdstPtr\fR; + const char *\fIhelpStr\fR; + ClientData \fIclientData\fR; +} \fBTcl_ArgvInfo\fR; +.CE +.PP +The \fIkeyStr\fR field contains the name of the option; by convention, this +will normally begin with a +.QW \fB\-\fR +character. The \fItype\fR, \fIsrcPtr\fR, \fIdstPtr\fR and \fIclientData\fR +fields describe the interpretation of the value of the argument, as described +below. The \fIhelpStr\fR field gives some text that is used to provide help to +users when they request it. +.PP +As noted above, the \fItype\fR field is used to describe the interpretation of +the argument's value. The following values are acceptable values for +\fItype\fR: +.TP +\fBTCL_ARGV_CONSTANT\fR +. +The argument does not take any following value argument. If this argument is +present, the int pointed to by the \fIsrcPtr\fR field is copied to the +\fIdstPtr\fR field. The \fIclientData\fR field is ignored. +.TP +\fBTCL_ARGV_END\fR +. +This value marks the end of all option descriptors in the table. All other +fields are ignored. +.TP +\fBTCL_ARGV_FLOAT\fR +. +This argument takes a following floating point value argument. The value (once +parsed by \fBTcl_GetDoubleFromObj\fR) will be stored as a double-precision +value in the variable pointed to by the \fIdstPtr\fR field. The \fIsrcPtr\fR +and \fIclientData\fR fields are ignored. +.TP +\fBTCL_ARGV_FUNC\fR +. +This argument optionally takes a following value argument; it is up to the +handler callback function passed in \fIsrcPtr\fR to decide. That function will +have the following signature: +.RS +.PP +.CS +typedef int (\fBTcl_ArgvFuncProc\fR)( + ClientData \fIclientData\fR, + Tcl_Obj *\fIobjPtr\fR, + void *\fIdstPtr\fR); +.CE +.PP +The result is a boolean value indicating whether to consume the following +argument. The \fIclientData\fR is the value from the table entry, the +\fIobjPtr\fR is the value that represents the following argument or NULL if +there are no following arguments at all, and the \fIdstPtr\fR argument to the +\fBTcl_ArgvFuncProc\fR is the location to write the parsed value to. +.RE +.TP +\fBTCL_ARGV_GENFUNC\fR +. +This argument takes zero or more following arguments; the handler callback +function passed in \fIsrcPtr\fR returns how many (or a negative number to +signal an error, in which case it should also set the interpreter result). The +function will have the following signature: +.RS +.PP +.CS +typedef int (\fBTcl_ArgvGenFuncProc\fR)( + ClientData \fIclientData\fR, + Tcl_Interp *\fIinterp\fR, + int \fIobjc\fR, + Tcl_Obj *const *\fIobjv\fR, + void *\fIdstPtr\fR); +.CE +.PP +The \fIclientData\fR is the value from the table entry, the \fIinterp\fR is +where to store any error messages, the \fIkeyStr\fR is the name of the +argument, \fIobjc\fR and \fIobjv\fR describe an array of all the remaining +arguments, and \fIdstPtr\fR argument to the \fBTcl_ArgvGenFuncProc\fR is the +location to write the parsed value (or values) to. +.RE +.TP +\fBTCL_ARGV_HELP\fR +. +This special argument does not take any following value argument, but instead +causes \fBTcl_ParseArgsObjv\fR to generate an error message describing the +arguments supported. All other fields except the \fIhelpStr\fR field are +ignored. +.TP +\fBTCL_ARGV_INT\fR +. +This argument takes a following integer value argument. The value (once parsed +by \fBTcl_GetIntFromObj\fR) will be stored as an int in the variable pointed +to by the \fIdstPtr\fR field. The \fIsrcPtr\fR field is ignored. +.TP +\fBTCL_ARGV_REST\fR +. +This special argument does not take any following value argument, but instead +marks all following arguments to be left unprocessed. The \fIsrcPtr\fR, +\fIdstPtr\fR and \fIclientData\fR fields are ignored. +.TP +\fBTCL_ARGV_STRING\fR +. +This argument takes a following string value argument. A pointer to the string +will be stored at \fIdstPtr\fR; the string inside will have a lifetime linked +to the lifetime of the string representation of the argument value that it +came from, and so should be copied if it needs to be retained. The +\fIsrcPtr\fR and \fIclientData\fR fields are ignored. +.SH "SEE ALSO" +Tcl_GetIndexFromObj(3), Tcl_Main(3), Tcl_CreateObjCommand(3) +.SH KEYWORDS +argument, parse +'\" Local Variables: +'\" fill-column: 78 +'\" End: diff --git a/tcl8.6/doc/ParseCmd.3 b/tcl8.6/doc/ParseCmd.3 new file mode 100644 index 0000000..667d697 --- /dev/null +++ b/tcl8.6/doc/ParseCmd.3 @@ -0,0 +1,467 @@ +'\" +'\" Copyright (c) 1997 Sun Microsystems, Inc. +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH Tcl_ParseCommand 3 8.3 Tcl "Tcl Library Procedures" +.so man.macros +.BS +.SH NAME +Tcl_ParseCommand, Tcl_ParseExpr, Tcl_ParseBraces, Tcl_ParseQuotedString, Tcl_ParseVarName, Tcl_ParseVar, Tcl_FreeParse, Tcl_EvalTokens, Tcl_EvalTokensStandard \- parse Tcl scripts and expressions +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +int +\fBTcl_ParseCommand\fR(\fIinterp, start, numBytes, nested, parsePtr\fR) +.sp +int +\fBTcl_ParseExpr\fR(\fIinterp, start, numBytes, parsePtr\fR) +.sp +int +\fBTcl_ParseBraces\fR(\fIinterp, start, numBytes, parsePtr, append, termPtr\fR) +.sp +int +\fBTcl_ParseQuotedString\fR(\fIinterp, start, numBytes, parsePtr, append, termPtr\fR) +.sp +int +\fBTcl_ParseVarName\fR(\fIinterp, start, numBytes, parsePtr, append\fR) +.sp +const char * +\fBTcl_ParseVar\fR(\fIinterp, start, termPtr\fR) +.sp +\fBTcl_FreeParse\fR(\fIusedParsePtr\fR) +.sp +Tcl_Obj * +\fBTcl_EvalTokens\fR(\fIinterp, tokenPtr, numTokens\fR) +.sp +int +\fBTcl_EvalTokensStandard\fR(\fIinterp, tokenPtr, numTokens\fR) +.SH ARGUMENTS +.AS Tcl_Interp *usedParsePtr out +.AP Tcl_Interp *interp out +For procedures other than \fBTcl_FreeParse\fR, \fBTcl_EvalTokens\fR +and \fBTcl_EvalTokensStandard\fR, used only for error reporting; +if NULL, then no error messages are left after errors. +For \fBTcl_EvalTokens\fR and \fBTcl_EvalTokensStandard\fR, +determines the context for evaluating the +script and also is used for error reporting; must not be NULL. +.AP "const char" *start in +Pointer to first character in string to parse. +.AP int numBytes in +Number of bytes in string to parse, not including any terminating null +character. If less than 0 then the script consists of all characters +following \fIstart\fR up to the first null character. +.AP int nested in +Non-zero means that the script is part of a command substitution so an +unquoted close bracket should be treated as a command terminator. If zero, +close brackets have no special meaning. +.AP int append in +Non-zero means that \fI*parsePtr\fR already contains valid tokens; the new +tokens should be appended to those already present. Zero means that +\fI*parsePtr\fR is uninitialized; any information in it is ignored. +This argument is normally 0. +.AP Tcl_Parse *parsePtr out +Points to structure to fill in with information about the parsed +command, expression, variable name, etc. +Any previous information in this structure +is ignored, unless \fIappend\fR is non-zero in a call to +\fBTcl_ParseBraces\fR, \fBTcl_ParseQuotedString\fR, +or \fBTcl_ParseVarName\fR. +.AP "const char" **termPtr out +If not NULL, points to a location where +\fBTcl_ParseBraces\fR, \fBTcl_ParseQuotedString\fR, and +\fBTcl_ParseVar\fR will store a pointer to the character +just after the terminating character (the close-brace, the last +character of the variable name, or the close-quote (respectively)) +if the parse was successful. +.AP Tcl_Parse *usedParsePtr in +Points to structure that was filled in by a previous call to +\fBTcl_ParseCommand\fR, \fBTcl_ParseExpr\fR, \fBTcl_ParseVarName\fR, etc. +.BE +.SH DESCRIPTION +.PP +These procedures parse Tcl commands or portions of Tcl commands such as +expressions or references to variables. +Each procedure takes a pointer to a script (or portion thereof) +and fills in the structure pointed to by \fIparsePtr\fR +with a collection of tokens describing the information that was parsed. +The procedures normally return \fBTCL_OK\fR. +However, if an error occurs then they return \fBTCL_ERROR\fR, +leave an error message in \fIinterp\fR's result +(if \fIinterp\fR is not NULL), +and leave nothing in \fIparsePtr\fR. +.PP +\fBTcl_ParseCommand\fR is a procedure that parses Tcl +scripts. Given a pointer to a script, it +parses the first command from the script. If the command was parsed +successfully, \fBTcl_ParseCommand\fR returns \fBTCL_OK\fR and fills in the +structure pointed to by \fIparsePtr\fR with information about the +structure of the command (see below for details). +If an error occurred in parsing the command then +\fBTCL_ERROR\fR is returned, an error message is left in \fIinterp\fR's +result, and no information is left at \fI*parsePtr\fR. +.PP +\fBTcl_ParseExpr\fR parses Tcl expressions. +Given a pointer to a script containing an expression, +\fBTcl_ParseExpr\fR parses the expression. +If the expression was parsed successfully, +\fBTcl_ParseExpr\fR returns \fBTCL_OK\fR and fills in the +structure pointed to by \fIparsePtr\fR with information about the +structure of the expression (see below for details). +If an error occurred in parsing the command then +\fBTCL_ERROR\fR is returned, an error message is left in \fIinterp\fR's +result, and no information is left at \fI*parsePtr\fR. +.PP +\fBTcl_ParseBraces\fR parses a string or command argument +enclosed in braces such as +\fB{hello}\fR or \fB{string \et with \et tabs}\fR +from the beginning of its argument \fIstart\fR. +The first character of \fIstart\fR must be \fB{\fR. +If the braced string was parsed successfully, +\fBTcl_ParseBraces\fR returns \fBTCL_OK\fR, +fills in the structure pointed to by \fIparsePtr\fR +with information about the structure of the string +(see below for details), +and stores a pointer to the character just after the terminating \fB}\fR +in the location given by \fI*termPtr\fR. +If an error occurs while parsing the string +then \fBTCL_ERROR\fR is returned, +an error message is left in \fIinterp\fR's result, +and no information is left at \fI*parsePtr\fR or \fI*termPtr\fR. +.PP +\fBTcl_ParseQuotedString\fR parses a double-quoted string such as +\fB"sum is [expr {$a+$b}]"\fR +from the beginning of the argument \fIstart\fR. +The first character of \fIstart\fR must be \fB\N'34'\fR. +If the double-quoted string was parsed successfully, +\fBTcl_ParseQuotedString\fR returns \fBTCL_OK\fR, +fills in the structure pointed to by \fIparsePtr\fR +with information about the structure of the string +(see below for details), +and stores a pointer to the character just after the terminating \fB\N'34'\fR +in the location given by \fI*termPtr\fR. +If an error occurs while parsing the string +then \fBTCL_ERROR\fR is returned, +an error message is left in \fIinterp\fR's result, +and no information is left at \fI*parsePtr\fR or \fI*termPtr\fR. +.PP +\fBTcl_ParseVarName\fR parses a Tcl variable reference such as +\fB$abc\fR or \fB$x([expr {$index + 1}])\fR from the beginning of its +\fIstart\fR argument. +The first character of \fIstart\fR must be \fB$\fR. +If a variable name was parsed successfully, \fBTcl_ParseVarName\fR +returns \fBTCL_OK\fR and fills in the structure pointed to by +\fIparsePtr\fR with information about the structure of the variable name +(see below for details). If an error +occurs while parsing the command then \fBTCL_ERROR\fR is returned, an +error message is left in \fIinterp\fR's result (if \fIinterp\fR is not +NULL), and no information is left at \fI*parsePtr\fR. +.PP +\fBTcl_ParseVar\fR parse a Tcl variable reference such as \fB$abc\fR +or \fB$x([expr {$index + 1}])\fR from the beginning of its \fIstart\fR +argument. The first character of \fIstart\fR must be \fB$\fR. If +the variable name is parsed successfully, \fBTcl_ParseVar\fR returns a +pointer to the string value of the variable. If an error occurs while +parsing, then NULL is returned and an error message is left in +\fIinterp\fR's result. +.PP +The information left at \fI*parsePtr\fR +by \fBTcl_ParseCommand\fR, \fBTcl_ParseExpr\fR, \fBTcl_ParseBraces\fR, +\fBTcl_ParseQuotedString\fR, and \fBTcl_ParseVarName\fR +may include dynamically allocated memory. +If these five parsing procedures return \fBTCL_OK\fR +then the caller must invoke \fBTcl_FreeParse\fR to release +the storage at \fI*parsePtr\fR. +These procedures ignore any existing information in +\fI*parsePtr\fR (unless \fIappend\fR is non-zero), +so if repeated calls are being made to any of them +then \fBTcl_FreeParse\fR must be invoked once after each call. +.PP +\fBTcl_EvalTokensStandard\fR evaluates a sequence of parse tokens from +a Tcl_Parse structure. The tokens typically consist +of all the tokens in a word or all the tokens that make up the index for +a reference to an array variable. \fBTcl_EvalTokensStandard\fR performs the +substitutions requested by the tokens and concatenates the +resulting values. +The return value from \fBTcl_EvalTokensStandard\fR is a Tcl completion +code with one of the values \fBTCL_OK\fR, \fBTCL_ERROR\fR, +\fBTCL_RETURN\fR, \fBTCL_BREAK\fR, or \fBTCL_CONTINUE\fR, or possibly +some other integer value originating in an extension. +In addition, a result value or error message is left in \fIinterp\fR's +result; it can be retrieved using \fBTcl_GetObjResult\fR. +.PP +\fBTcl_EvalTokens\fR differs from \fBTcl_EvalTokensStandard\fR only in +the return convention used: it returns the result in a new Tcl_Obj. +The reference count of the value returned as result has been +incremented, so the caller must +invoke \fBTcl_DecrRefCount\fR when it is finished with the value. +If an error or other exception occurs while evaluating the tokens +(such as a reference to a non-existent variable) then the return value +is NULL and an error message is left in \fIinterp\fR's result. The use +of \fBTcl_EvalTokens\fR is deprecated. +.SH "TCL_PARSE STRUCTURE" +.PP +\fBTcl_ParseCommand\fR, \fBTcl_ParseExpr\fR, \fBTcl_ParseBraces\fR, +\fBTcl_ParseQuotedString\fR, and \fBTcl_ParseVarName\fR +return parse information in two data structures, Tcl_Parse and Tcl_Token: +.PP +.CS +typedef struct Tcl_Parse { + const char *\fIcommentStart\fR; + int \fIcommentSize\fR; + const char *\fIcommandStart\fR; + int \fIcommandSize\fR; + int \fInumWords\fR; + Tcl_Token *\fItokenPtr\fR; + int \fInumTokens\fR; + ... +} \fBTcl_Parse\fR; + +typedef struct Tcl_Token { + int \fItype\fR; + const char *\fIstart\fR; + int \fIsize\fR; + int \fInumComponents\fR; +} \fBTcl_Token\fR; +.CE +.PP +The first five fields of a Tcl_Parse structure +are filled in only by \fBTcl_ParseCommand\fR. +These fields are not used by the other parsing procedures. +.PP +\fBTcl_ParseCommand\fR fills in a Tcl_Parse structure +with information that describes one Tcl command and any comments that +precede the command. +If there are comments, +the \fIcommentStart\fR field points to the \fB#\fR character that begins +the first comment and \fIcommentSize\fR indicates the number of bytes +in all of the comments preceding the command, including the newline +character that terminates the last comment. +If the command is not preceded by any comments, \fIcommentSize\fR is 0. +\fBTcl_ParseCommand\fR also sets the \fIcommandStart\fR field +to point to the first character of the first +word in the command (skipping any comments and leading space) and +\fIcommandSize\fR gives the total number of bytes in the command, +including the character pointed to by \fIcommandStart\fR up to and +including the newline, close bracket, or semicolon character that +terminates the command. The \fInumWords\fR field gives the +total number of words in the command. +.PP +All parsing procedures set the remaining fields, +\fItokenPtr\fR and \fInumTokens\fR. +The \fItokenPtr\fR field points to the first in an array of Tcl_Token +structures that describe the components of the entity being parsed. +The \fInumTokens\fR field gives the total number of tokens +present in the array. +Each token contains four fields. +The \fItype\fR field selects one of several token types +that are described below. The \fIstart\fR field +points to the first character in the token and the \fIsize\fR field +gives the total number of characters in the token. Some token types, +such as \fBTCL_TOKEN_WORD\fR and \fBTCL_TOKEN_VARIABLE\fR, consist of +several component tokens, which immediately follow the parent token; +the \fInumComponents\fR field describes how many of these there are. +The \fItype\fR field has one of the following values: +.TP 20 +\fBTCL_TOKEN_WORD\fR +. +This token ordinarily describes one word of a command +but it may also describe a quoted or braced string in an expression. +The token describes a component of the script that is +the result of concatenating together a sequence of subcomponents, +each described by a separate subtoken. +The token starts with the first non-blank +character of the component (which may be a double-quote or open brace) +and includes all characters in the component up to but not including the +space, semicolon, close bracket, close quote, or close brace that +terminates the component. The \fInumComponents\fR field counts the total +number of sub-tokens that make up the word, including sub-tokens +of \fBTCL_TOKEN_VARIABLE\fR and \fBTCL_TOKEN_BS\fR tokens. +.TP +\fBTCL_TOKEN_SIMPLE_WORD\fR +. +This token has the same meaning as \fBTCL_TOKEN_WORD\fR, except that +the word is guaranteed to consist of a single \fBTCL_TOKEN_TEXT\fR +sub-token. The \fInumComponents\fR field is always 1. +.TP +\fBTCL_TOKEN_EXPAND_WORD\fR +. +This token has the same meaning as \fBTCL_TOKEN_WORD\fR, except that +the command parser notes this word began with the expansion +prefix \fB{*}\fR, indicating that after substitution, +the list value of this word should be expanded to form multiple +arguments in command evaluation. This +token type can only be created by Tcl_ParseCommand. +.TP +\fBTCL_TOKEN_TEXT\fR +. +The token describes a range of literal text that is part of a word. +The \fInumComponents\fR field is always 0. +.TP +\fBTCL_TOKEN_BS\fR +. +The token describes a backslash sequence such as \fB\en\fR or \fB\e0xa3\fR. +The \fInumComponents\fR field is always 0. +.TP +\fBTCL_TOKEN_COMMAND\fR +. +The token describes a command whose result must be substituted into +the word. The token includes the square brackets that surround the +command. The \fInumComponents\fR field is always 0 (the nested command +is not parsed; call \fBTcl_ParseCommand\fR recursively if you want to +see its tokens). +.TP +\fBTCL_TOKEN_VARIABLE\fR +. +The token describes a variable substitution, including the +\fB$\fR, variable name, and array index (if there is one) up through the +close parenthesis that terminates the index. This token is followed +by one or more additional tokens that describe the variable name and +array index. If \fInumComponents\fR is 1 then the variable is a +scalar and the next token is a \fBTCL_TOKEN_TEXT\fR token that gives the +variable name. If \fInumComponents\fR is greater than 1 then the +variable is an array: the first sub-token is a \fBTCL_TOKEN_TEXT\fR +token giving the array name and the remaining sub-tokens are +\fBTCL_TOKEN_TEXT\fR, \fBTCL_TOKEN_BS\fR, \fBTCL_TOKEN_COMMAND\fR, and +\fBTCL_TOKEN_VARIABLE\fR tokens that must be concatenated to produce the +array index. The \fInumComponents\fR field includes nested sub-tokens +that are part of \fBTCL_TOKEN_VARIABLE\fR tokens in the array index. +.TP +\fBTCL_TOKEN_SUB_EXPR\fR +. +The token describes one subexpression of an expression +(or an entire expression). +A subexpression may consist of a value +such as an integer literal, variable substitution, +or parenthesized subexpression; +it may also consist of an operator and its operands. +The token starts with the first non-blank character of the subexpression +up to but not including the space, brace, close-paren, or bracket +that terminates the subexpression. +This token is followed by one or more additional tokens +that describe the subexpression. +If the first sub-token after the \fBTCL_TOKEN_SUB_EXPR\fR token +is a \fBTCL_TOKEN_OPERATOR\fR token, +the subexpression consists of an operator and its token operands. +If the operator has no operands, the subexpression consists of +just the \fBTCL_TOKEN_OPERATOR\fR token. +Each operand is described by a \fBTCL_TOKEN_SUB_EXPR\fR token. +Otherwise, the subexpression is a value described by +one of the token types \fBTCL_TOKEN_WORD\fR, \fBTCL_TOKEN_TEXT\fR, +\fBTCL_TOKEN_BS\fR, \fBTCL_TOKEN_COMMAND\fR, +\fBTCL_TOKEN_VARIABLE\fR, and \fBTCL_TOKEN_SUB_EXPR\fR. +The \fInumComponents\fR field +counts the total number of sub-tokens that make up the subexpression; +this includes the sub-tokens for any nested \fBTCL_TOKEN_SUB_EXPR\fR tokens. +.TP +\fBTCL_TOKEN_OPERATOR\fR +. +The token describes one operator of an expression +such as \fB&&\fR or \fBhypot\fR. +A \fBTCL_TOKEN_OPERATOR\fR token is always preceded by a +\fBTCL_TOKEN_SUB_EXPR\fR token +that describes the operator and its operands; +the \fBTCL_TOKEN_SUB_EXPR\fR token's \fInumComponents\fR field +can be used to determine the number of operands. +A binary operator such as \fB*\fR +is followed by two \fBTCL_TOKEN_SUB_EXPR\fR tokens +that describe its operands. +A unary operator like \fB\-\fR +is followed by a single \fBTCL_TOKEN_SUB_EXPR\fR token +for its operand. +If the operator is a math function such as \fBlog10\fR, +the \fBTCL_TOKEN_OPERATOR\fR token will give its name and +the following \fBTCL_TOKEN_SUB_EXPR\fR tokens will describe +its operands; +if there are no operands (as with \fBrand\fR), +no \fBTCL_TOKEN_SUB_EXPR\fR tokens follow. +There is one trinary operator, \fB?\fR, +that appears in if-then-else subexpressions +such as \fIx\fB?\fIy\fB:\fIz\fR; +in this case, the \fB?\fR \fBTCL_TOKEN_OPERATOR\fR token +is followed by three \fBTCL_TOKEN_SUB_EXPR\fR tokens for the operands +\fIx\fR, \fIy\fR, and \fIz\fR. +The \fInumComponents\fR field for a \fBTCL_TOKEN_OPERATOR\fR token +is always 0. +.PP +After \fBTcl_ParseCommand\fR returns, the first token pointed to by +the \fItokenPtr\fR field of the +Tcl_Parse structure always has type \fBTCL_TOKEN_WORD\fR or +\fBTCL_TOKEN_SIMPLE_WORD\fR or \fBTCL_TOKEN_EXPAND_WORD\fR. +It is followed by the sub-tokens +that must be concatenated to produce the value of that word. +The next token is the \fBTCL_TOKEN_WORD\fR or \fBTCL_TOKEN_SIMPLE_WORD\fR +of \fBTCL_TOKEN_EXPAND_WORD\fR token for the second word, +followed by sub-tokens for that +word, and so on until all \fInumWords\fR have been accounted +for. +.PP +After \fBTcl_ParseExpr\fR returns, the first token pointed to by +the \fItokenPtr\fR field of the +Tcl_Parse structure always has type \fBTCL_TOKEN_SUB_EXPR\fR. +It is followed by the sub-tokens that must be evaluated +to produce the value of the expression. +Only the token information in the Tcl_Parse structure +is modified: the \fIcommentStart\fR, \fIcommentSize\fR, +\fIcommandStart\fR, and \fIcommandSize\fR fields are not modified +by \fBTcl_ParseExpr\fR. +.PP +After \fBTcl_ParseBraces\fR returns, +the array of tokens pointed to by the \fItokenPtr\fR field of the +Tcl_Parse structure will contain a single \fBTCL_TOKEN_TEXT\fR token +if the braced string does not contain any backslash-newlines. +If the string does contain backslash-newlines, +the array of tokens will contain one or more +\fBTCL_TOKEN_TEXT\fR or \fBTCL_TOKEN_BS\fR sub-tokens +that must be concatenated to produce the value of the string. +If the braced string was just \fB{}\fR +(that is, the string was empty), +the single \fBTCL_TOKEN_TEXT\fR token will have a \fIsize\fR field +containing zero; +this ensures that at least one token appears +to describe the braced string. +Only the token information in the Tcl_Parse structure +is modified: the \fIcommentStart\fR, \fIcommentSize\fR, +\fIcommandStart\fR, and \fIcommandSize\fR fields are not modified +by \fBTcl_ParseBraces\fR. +.PP +After \fBTcl_ParseQuotedString\fR returns, +the array of tokens pointed to by the \fItokenPtr\fR field of the +Tcl_Parse structure depends on the contents of the quoted string. +It will consist of one or more \fBTCL_TOKEN_TEXT\fR, \fBTCL_TOKEN_BS\fR, +\fBTCL_TOKEN_COMMAND\fR, and \fBTCL_TOKEN_VARIABLE\fR sub-tokens. +The array always contains at least one token; +for example, if the argument \fIstart\fR is empty, +the array returned consists of a single \fBTCL_TOKEN_TEXT\fR token +with a zero \fIsize\fR field. +Only the token information in the Tcl_Parse structure +is modified: the \fIcommentStart\fR, \fIcommentSize\fR, +\fIcommandStart\fR, and \fIcommandSize\fR fields are not modified. +.PP +After \fBTcl_ParseVarName\fR returns, the first token pointed to by +the \fItokenPtr\fR field of the +Tcl_Parse structure always has type \fBTCL_TOKEN_VARIABLE\fR. It +is followed by the sub-tokens that make up the variable name as +described above. The total length of the variable name is +contained in the \fIsize\fR field of the first token. +As in \fBTcl_ParseExpr\fR, +only the token information in the Tcl_Parse structure +is modified by \fBTcl_ParseVarName\fR: +the \fIcommentStart\fR, \fIcommentSize\fR, +\fIcommandStart\fR, and \fIcommandSize\fR fields are not modified. +.PP +All of the character pointers in the +Tcl_Parse and Tcl_Token structures refer +to characters in the \fIstart\fR argument passed to +\fBTcl_ParseCommand\fR, \fBTcl_ParseExpr\fR, \fBTcl_ParseBraces\fR, +\fBTcl_ParseQuotedString\fR, and \fBTcl_ParseVarName\fR. +.PP +There are additional fields in the Tcl_Parse structure after the +\fInumTokens\fR field, but these are for the private use of +\fBTcl_ParseCommand\fR, \fBTcl_ParseExpr\fR, \fBTcl_ParseBraces\fR, +\fBTcl_ParseQuotedString\fR, and \fBTcl_ParseVarName\fR; they should not be +referenced by code outside of these procedures. +.SH KEYWORDS +backslash substitution, braces, command, expression, parse, token, variable substitution diff --git a/tcl8.6/doc/PkgRequire.3 b/tcl8.6/doc/PkgRequire.3 new file mode 100644 index 0000000..71f3acf --- /dev/null +++ b/tcl8.6/doc/PkgRequire.3 @@ -0,0 +1,97 @@ +'\" +'\" Copyright (c) 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. +'\" +.TH Tcl_PkgRequire 3 7.5 Tcl "Tcl Library Procedures" +.so man.macros +.BS +.SH NAME +Tcl_PkgRequire, Tcl_PkgRequireEx, Tcl_PkgRequireProc, Tcl_PkgPresent, Tcl_PkgPresentEx, Tcl_PkgProvide, Tcl_PkgProvideEx \- package version control +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +const char * +\fBTcl_PkgRequire\fR(\fIinterp, name, version, exact\fR) +.sp +const char * +\fBTcl_PkgRequireEx\fR(\fIinterp, name, version, exact, clientDataPtr\fR) +.sp +int +\fBTcl_PkgRequireProc\fR(\fIinterp, name, objc, objv, clientDataPtr\fR) +.sp +const char * +\fBTcl_PkgPresent\fR(\fIinterp, name, version, exact\fR) +.sp +const char * +\fBTcl_PkgPresentEx\fR(\fIinterp, name, version, exact, clientDataPtr\fR) +.sp +int +\fBTcl_PkgProvide\fR(\fIinterp, name, version\fR) +.sp +int +\fBTcl_PkgProvideEx\fR(\fIinterp, name, version, clientData\fR) +.SH ARGUMENTS +.AS void *clientDataPtr out +.AP Tcl_Interp *interp in +Interpreter where package is needed or available. +.AP "const char" *name in +Name of package. +.AP "const char" *version in +A version string consisting of one or more decimal numbers +separated by dots. +.AP int exact in +Non-zero means that only the particular version specified by +\fIversion\fR is acceptable. +Zero means that newer versions than \fIversion\fR are also +acceptable as long as they have the same major version number +as \fIversion\fR. +.AP "const void" *clientData in +Arbitrary value to be associated with the package. +.AP void *clientDataPtr out +Pointer to place to store the value associated with the matching +package. It is only changed if the pointer is not NULL and the +function completed successfully. The storage can be any pointer +type with the same size as a void pointer. +.AP int objc in +Number of requirements. +.AP Tcl_Obj* objv[] in +Array of requirements. +.BE +.SH DESCRIPTION +.PP +These procedures provide C-level interfaces to Tcl's package and +version management facilities. +.PP +\fBTcl_PkgRequire\fR is equivalent to the \fBpackage require\fR +command, \fBTcl_PkgPresent\fR is equivalent to the \fBpackage present\fR +command, and \fBTcl_PkgProvide\fR is equivalent to the +\fBpackage provide\fR command. +.PP +See the documentation for the Tcl commands for details on what these +procedures do. +.PP +If \fBTcl_PkgPresent\fR or \fBTcl_PkgRequire\fR complete successfully +they return a pointer to the version string for the version of the package +that is provided in the interpreter (which may be different than +\fIversion\fR); if an error occurs they return NULL and leave an error +message in the interpreter's result. +.PP +\fBTcl_PkgProvide\fR returns \fBTCL_OK\fR if it completes successfully; +if an error occurs it returns \fBTCL_ERROR\fR and leaves an error message +in the interpreter's result. +.PP +\fBTcl_PkgProvideEx\fR, \fBTcl_PkgPresentEx\fR and \fBTcl_PkgRequireEx\fR +allow the setting and retrieving of the client data associated with +the package. In all other respects they are equivalent to the matching +functions. +.PP +\fBTcl_PkgRequireProc\fR is the form of \fBpackage require\fR handling +multiple requirements. The other forms are present for backward +compatibility and translate their invocations to this form. +.SH KEYWORDS +package, present, provide, require, version +.SH "SEE ALSO" +package(n), Tcl_StaticPackage(3) diff --git a/tcl8.6/doc/Preserve.3 b/tcl8.6/doc/Preserve.3 new file mode 100644 index 0000000..970bded --- /dev/null +++ b/tcl8.6/doc/Preserve.3 @@ -0,0 +1,110 @@ +'\" +'\" Copyright (c) 1990 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. +'\" +.TH Tcl_Preserve 3 7.5 Tcl "Tcl Library Procedures" +.so man.macros +.BS +.SH NAME +Tcl_Preserve, Tcl_Release, Tcl_EventuallyFree \- avoid freeing storage while it is being used +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +\fBTcl_Preserve\fR(\fIclientData\fR) +.sp +\fBTcl_Release\fR(\fIclientData\fR) +.sp +\fBTcl_EventuallyFree\fR(\fIclientData, freeProc\fR) +.SH ARGUMENTS +.AS Tcl_FreeProc clientData +.AP ClientData clientData in +Token describing structure to be freed or reallocated. Usually a pointer +to memory for structure. +.AP Tcl_FreeProc *freeProc in +Procedure to invoke to free \fIclientData\fR. +.BE +.SH DESCRIPTION +.PP +These three procedures help implement a simple reference count mechanism +for managing storage. They are designed to solve a problem +having to do with widget deletion, but are also useful in many other +situations. When a widget is deleted, its +widget record (the structure holding information specific to the +widget) must be returned to the storage allocator. +However, it is possible that the widget record is in active use +by one of the procedures on the stack at the time of the deletion. +This can happen, for example, if the command associated with a button +widget causes the button to be destroyed: an X event causes an +event-handling C procedure in the button to be invoked, which in +turn causes the button's associated Tcl command to be executed, +which in turn causes the button to be deleted, which in turn causes +the button's widget record to be de-allocated. +Unfortunately, when the Tcl command returns, the button's +event-handling procedure will need to reference the +button's widget record. +Because of this, the widget record must not be freed as part of the +deletion, but must be retained until the event-handling procedure has +finished with it. +In other situations where the widget is deleted, it may be possible +to free the widget record immediately. +.PP +\fBTcl_Preserve\fR and \fBTcl_Release\fR +implement short-term reference counts for their \fIclientData\fR +argument. +The \fIclientData\fR argument identifies an object and usually +consists of the address of a structure. +The reference counts guarantee that an object will not be freed +until each call to \fBTcl_Preserve\fR for the object has been +matched by calls to \fBTcl_Release\fR. +There may be any number of unmatched \fBTcl_Preserve\fR calls +in effect at once. +.PP +\fBTcl_EventuallyFree\fR is invoked to free up its \fIclientData\fR +argument. +It checks to see if there are unmatched \fBTcl_Preserve\fR calls +for the object. +If not, then \fBTcl_EventuallyFree\fR calls \fIfreeProc\fR immediately. +Otherwise \fBTcl_EventuallyFree\fR records the fact that \fIclientData\fR +needs eventually to be freed. +When all calls to \fBTcl_Preserve\fR have been matched with +calls to \fBTcl_Release\fR then \fIfreeProc\fR will be called by +\fBTcl_Release\fR to do the cleanup. +.PP +All the work of freeing the object is carried out by \fIfreeProc\fR. +\fIFreeProc\fR must have arguments and result that match the +type \fBTcl_FreeProc\fR: +.PP +.CS +typedef void \fBTcl_FreeProc\fR( + char *\fIblockPtr\fR); +.CE +.PP +The \fIblockPtr\fR argument to \fIfreeProc\fR will be the +same as the \fIclientData\fR argument to \fBTcl_EventuallyFree\fR. +The type of \fIblockPtr\fR (\fBchar *\fR) is different than the type of the +\fIclientData\fR argument to \fBTcl_EventuallyFree\fR for historical +reasons, but the value is the same. +.PP +When the \fIclientData\fR argument to \fBTcl_EventuallyFree\fR +refers to storage allocated and returned by a prior call to +\fBTcl_Alloc\fR, \fBckalloc\fR, or another function of the Tcl library, +then the \fIfreeProc\fR argument should be given the special value of +\fBTCL_DYNAMIC\fR. +.PP +This mechanism can be used to solve the problem described above +by placing \fBTcl_Preserve\fR and \fBTcl_Release\fR calls around +actions that may cause undesired storage re-allocation. The +mechanism is intended only for short-term use (i.e. while procedures +are pending on the stack); it will not work efficiently as a +mechanism for long-term reference counts. +The implementation does not depend in any way on the internal +structure of the objects being freed; it keeps the reference +counts in a separate structure. +.SH "SEE ALSO" +Tcl_Interp, Tcl_Alloc +.SH KEYWORDS +free, reference count, storage diff --git a/tcl8.6/doc/PrintDbl.3 b/tcl8.6/doc/PrintDbl.3 new file mode 100644 index 0000000..730794f --- /dev/null +++ b/tcl8.6/doc/PrintDbl.3 @@ -0,0 +1,51 @@ +'\" +'\" Copyright (c) 1989-1993 The Regents of the University of California. +'\" Copyright (c) 1994-1997 Sun Microsystems, Inc. +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH Tcl_PrintDouble 3 8.0 Tcl "Tcl Library Procedures" +.so man.macros +.BS +.SH NAME +Tcl_PrintDouble \- Convert floating value to string +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +\fBTcl_PrintDouble\fR(\fIinterp, value, dst\fR) +.SH ARGUMENTS +.AS Tcl_Interp *interp out +.AP Tcl_Interp *interp in +Before Tcl 8.0, the \fBtcl_precision\fR variable in this interpreter +controlled the conversion. As of Tcl 8.0, this argument is ignored and +the conversion is controlled by the \fBtcl_precision\fR variable +that is now shared by all interpreters. +.AP double value in +Floating-point value to be converted. +.AP char *dst out +Where to store the string representing \fIvalue\fR. Must have at +least \fBTCL_DOUBLE_SPACE\fR characters of storage. +.BE +.SH DESCRIPTION +.PP +\fBTcl_PrintDouble\fR generates a string that represents the value +of \fIvalue\fR and stores it in memory at the location given by +\fIdst\fR. It uses \fB%g\fR format to generate the string, with one +special twist: the string is guaranteed to contain either a +.QW . +or an +.QW e +so that it does not look like an integer. Where \fB%g\fR would +generate an integer with no decimal point, \fBTcl_PrintDouble\fR adds +.QW .0 . +.PP +If the \fBtcl_precision\fR value is non-zero, the result will have +precisely that many digits of significance. If the value is zero +(the default), the result will have the fewest digits needed to +represent the number in such a way that \fBTcl_NewDoubleObj\fR +will generate the same number when presented with the given string. +IEEE semantics of rounding to even apply to the conversion. +.SH KEYWORDS +conversion, double-precision, floating-point, string diff --git a/tcl8.6/doc/RecEvalObj.3 b/tcl8.6/doc/RecEvalObj.3 new file mode 100644 index 0000000..387cc44 --- /dev/null +++ b/tcl8.6/doc/RecEvalObj.3 @@ -0,0 +1,53 @@ +'\" +'\" Copyright (c) 1997 Sun Microsystems, Inc. +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH Tcl_RecordAndEvalObj 3 8.0 Tcl "Tcl Library Procedures" +.so man.macros +.BS +.SH NAME +Tcl_RecordAndEvalObj \- save command on history list before evaluating +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +int +\fBTcl_RecordAndEvalObj\fR(\fIinterp, cmdPtr, flags\fR) +.SH ARGUMENTS +.AS Tcl_Interp *interp +.AP Tcl_Interp *interp in +Tcl interpreter in which to evaluate command. +.AP Tcl_Obj *cmdPtr in +Points to a Tcl value containing a command (or sequence of commands) +to execute. +.AP int flags in +An OR'ed combination of flag bits. \fBTCL_NO_EVAL\fR means record the +command but do not evaluate it. \fBTCL_EVAL_GLOBAL\fR means evaluate +the command at global level instead of the current stack level. +.BE + +.SH DESCRIPTION +.PP +\fBTcl_RecordAndEvalObj\fR is invoked to record a command as an event +on the history list and then execute it using \fBTcl_EvalObjEx\fR +(or \fBTcl_GlobalEvalObj\fR if the \fBTCL_EVAL_GLOBAL\fR bit is set +in \fIflags\fR). +It returns a completion code such as \fBTCL_OK\fR just like \fBTcl_EvalObjEx\fR, +as well as a result value containing additional information +(a result value or error message) +that can be retrieved using \fBTcl_GetObjResult\fR. +If you do not want the command recorded on the history list then +you should invoke \fBTcl_EvalObjEx\fR instead of \fBTcl_RecordAndEvalObj\fR. +Normally \fBTcl_RecordAndEvalObj\fR is only called with top-level +commands typed by the user, since the purpose of history is to +allow the user to re-issue recently invoked commands. +If the \fIflags\fR argument contains the \fBTCL_NO_EVAL\fR bit then +the command is recorded without being evaluated. + +.SH "SEE ALSO" +Tcl_EvalObjEx, Tcl_GetObjResult + +.SH KEYWORDS +command, event, execute, history, interpreter, value, record diff --git a/tcl8.6/doc/RecordEval.3 b/tcl8.6/doc/RecordEval.3 new file mode 100644 index 0000000..e1625ff --- /dev/null +++ b/tcl8.6/doc/RecordEval.3 @@ -0,0 +1,55 @@ +'\" +'\" Copyright (c) 1989-1993 The Regents of the University of California. +'\" Copyright (c) 1994-1997 Sun Microsystems, Inc. +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH Tcl_RecordAndEval 3 7.4 Tcl "Tcl Library Procedures" +.so man.macros +.BS +.SH NAME +Tcl_RecordAndEval \- save command on history list before evaluating +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +int +\fBTcl_RecordAndEval\fR(\fIinterp, cmd, flags\fR) +.SH ARGUMENTS +.AS Tcl_Interp *interp +.AP Tcl_Interp *interp in +Tcl interpreter in which to evaluate command. +.AP "const char" *cmd in +Command (or sequence of commands) to execute. +.AP int flags in +An OR'ed combination of flag bits. \fBTCL_NO_EVAL\fR means record the +command but do not evaluate it. \fBTCL_EVAL_GLOBAL\fR means evaluate +the command at global level instead of the current stack level. +.BE + +.SH DESCRIPTION +.PP +\fBTcl_RecordAndEval\fR is invoked to record a command as an event +on the history list and then execute it using \fBTcl_Eval\fR +(or \fBTcl_GlobalEval\fR if the \fBTCL_EVAL_GLOBAL\fR bit is set in \fIflags\fR). +It returns a completion code such as \fBTCL_OK\fR just like \fBTcl_Eval\fR +and it leaves information in the interpreter's result. +If you do not want the command recorded on the history list then +you should invoke \fBTcl_Eval\fR instead of \fBTcl_RecordAndEval\fR. +Normally \fBTcl_RecordAndEval\fR is only called with top-level +commands typed by the user, since the purpose of history is to +allow the user to re-issue recently-invoked commands. +If the \fIflags\fR argument contains the \fBTCL_NO_EVAL\fR bit then +the command is recorded without being evaluated. +.PP +Note that \fBTcl_RecordAndEval\fR has been largely replaced by the +value-based procedure \fBTcl_RecordAndEvalObj\fR. +That value-based procedure records and optionally executes +a command held in a Tcl value instead of a string. + +.SH "SEE ALSO" +Tcl_RecordAndEvalObj + +.SH KEYWORDS +command, event, execute, history, interpreter, record diff --git a/tcl8.6/doc/RegConfig.3 b/tcl8.6/doc/RegConfig.3 new file mode 100644 index 0000000..d73e3d7 --- /dev/null +++ b/tcl8.6/doc/RegConfig.3 @@ -0,0 +1,111 @@ +'\" +'\" Copyright (c) 2002 Andreas Kupries <andreas_kupries@users.sourceforge.net> +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH Tcl_RegisterConfig 3 8.4 Tcl "Tcl Library Procedures" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +Tcl_RegisterConfig \- procedures to register embedded configuration information +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +void +\fBTcl_RegisterConfig\fR(\fIinterp, pkgName, configuration, valEncoding\fR) +.sp +.SH ARGUMENTS +.AS Tcl_Interp *configuration +.AP Tcl_Interp *interp in +Refers to the interpreter the embedded configuration information is +registered for. Must not be NULL. +.AP "const char" *pkgName in +Contains the name of the package registering the embedded +configuration as ASCII string. This means that this information is in +UTF-8 too. Must not be NULL. +.AP "const Tcl_Config" *configuration in +Refers to an array of Tcl_Config entries containing the information +embedded in the binary library. Must not be NULL. The end of the array +is signaled by either a key identical to NULL, or a key referring to +the empty string. +.AP "const char" *valEncoding in +Contains the name of the encoding used to store the configuration +values as ASCII string. This means that this information is in UTF-8 +too. Must not be NULL. +.BE +.SH DESCRIPTION +.PP +The function described here has its base in TIP 59 and provides +extensions with support for the embedding of configuration +information into their binary library and the generation of a +Tcl-level interface for querying this information. +.PP +To embed configuration information into their binary library an +extension has to define a non-volatile array of Tcl_Config entries in +one if its source files and then call \fBTcl_RegisterConfig\fR to +register that information. +.PP +\fBTcl_RegisterConfig\fR takes four arguments; first, a reference to +the interpreter we are registering the information with, second, the +name of the package registering its configuration information, third, +a pointer to an array of structures, and fourth a string declaring the +encoding used by the configuration values. +.PP +The string \fIvalEncoding\fR contains the name of an encoding known to +Tcl. All these names are use only characters in the ASCII subset of +UTF-8 and are thus implicitly in the UTF-8 encoding. It is expected +that keys are legible English text and therefore using the ASCII +subset of UTF-8. In other words, they are expected to be in UTF-8 +too. The values associated with the keys can be any string +however. For these the contents of \fIvalEncoding\fR define which +encoding was used to represent the characters of the strings. +.PP +Each element of the \fIconfiguration\fR array refers to two strings +containing the key and the value associated with that key. The end of +the array is signaled by either an empty key or a key identical to +NULL. The function makes \fBno\fR copy of the \fIconfiguration\fR +array. This means that the caller has to make sure that the memory +holding this array is never released. This is the meaning behind the +word \fBnon-volatile\fR used earlier. The easiest way to accomplish +this is to define a global static array of Tcl_Config entries. See the file +.QW generic/tclPkgConfig.c +in the sources of the Tcl core for an example. +.PP +When called \fBTcl_RegisterConfig\fR will +.IP (1) +create a namespace having the provided \fIpkgName\fR, if not yet +existing. +.IP (2) +create the command \fBpkgconfig\fR in that namespace and link it to +the provided information so that the keys from \fIconfiguration\fR and +their associated values can be retrieved through calls to +\fBpkgconfig\fR. +.PP +The command \fBpkgconfig\fR will provide two subcommands, \fBlist\fR +and \fBget\fR: +.RS +.TP +::\fIpkgName\fR::\fBpkgconfig\fR list +Returns a list containing the names of all defined keys. +.TP +::\fIpkgName\fR::\fBpkgconfig\fR get \fIkey\fR +Returns the configuration value associated with the specified +\fIkey\fR. +.RE +.SH TCL_CONFIG +.PP +The \fBTcl_Config\fR structure contains the following fields: +.PP +.CS +typedef struct Tcl_Config { + const char *\fIkey\fR; + const char *\fIvalue\fR; +} \fBTcl_Config\fR; +.CE +.\" No cross references yet. +.\" .SH "SEE ALSO" +.SH KEYWORDS +embedding, configuration, binary library diff --git a/tcl8.6/doc/RegExp.3 b/tcl8.6/doc/RegExp.3 new file mode 100644 index 0000000..aa757bc --- /dev/null +++ b/tcl8.6/doc/RegExp.3 @@ -0,0 +1,383 @@ +'\" +'\" Copyright (c) 1994 The Regents of the University of California. +'\" Copyright (c) 1994-1996 Sun Microsystems, Inc. +'\" Copyright (c) 1998-1999 Scriptics Corporation +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH Tcl_RegExpMatch 3 8.1 Tcl "Tcl Library Procedures" +.so man.macros +.BS +.SH NAME +Tcl_RegExpMatch, Tcl_RegExpCompile, Tcl_RegExpExec, Tcl_RegExpRange, Tcl_GetRegExpFromObj, Tcl_RegExpMatchObj, Tcl_RegExpExecObj, Tcl_RegExpGetInfo \- Pattern matching with regular expressions +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +int +\fBTcl_RegExpMatchObj\fR(\fIinterp\fR, \fItextObj\fR, \fIpatObj\fR) +.sp +int +\fBTcl_RegExpMatch\fR(\fIinterp\fR, \fItext\fR, \fIpattern\fR) +.sp +Tcl_RegExp +\fBTcl_RegExpCompile\fR(\fIinterp\fR, \fIpattern\fR) +.sp +int +\fBTcl_RegExpExec\fR(\fIinterp\fR, \fIregexp\fR, \fItext\fR, \fIstart\fR) +.sp +void +\fBTcl_RegExpRange\fR(\fIregexp\fR, \fIindex\fR, \fIstartPtr\fR, \fIendPtr\fR) +.sp +Tcl_RegExp +\fBTcl_GetRegExpFromObj\fR(\fIinterp\fR, \fIpatObj\fR, \fIcflags\fR) +.sp +int +\fBTcl_RegExpExecObj\fR(\fIinterp\fR, \fIregexp\fR, \fItextObj\fR, \fIoffset\fR, \fInmatches\fR, \fIeflags\fR) +.sp +void +\fBTcl_RegExpGetInfo\fR(\fIregexp\fR, \fIinfoPtr\fR) +.fi +.SH ARGUMENTS +.AS Tcl_RegExpInfo *interp in/out +.AP Tcl_Interp *interp in +Tcl interpreter to use for error reporting. The interpreter may be +NULL if no error reporting is desired. +.AP Tcl_Obj *textObj in/out +Refers to the value from which to get the text to search. The +internal representation of the value may be converted to a form that +can be efficiently searched. +.AP Tcl_Obj *patObj in/out +Refers to the value from which to get a regular expression. The +compiled regular expression is cached in the value. +.AP char *text in +Text to search for a match with a regular expression. +.AP "const char" *pattern in +String in the form of a regular expression pattern. +.AP Tcl_RegExp regexp in +Compiled regular expression. Must have been returned previously +by \fBTcl_GetRegExpFromObj\fR or \fBTcl_RegExpCompile\fR. +.AP char *start in +If \fItext\fR is just a portion of some other string, this argument +identifies the beginning of the larger string. +If it is not the same as \fItext\fR, then no +.QW \fB^\fR +matches will be allowed. +.AP int index in +Specifies which range is desired: 0 means the range of the entire +match, 1 or greater means the range that matched a parenthesized +sub-expression. +.AP "const char" **startPtr out +The address of the first character in the range is stored here, or +NULL if there is no such range. +.AP "const char" **endPtr out +The address of the character just after the last one in the range +is stored here, or NULL if there is no such range. +.AP int cflags in +OR-ed combination of the compilation flags \fBTCL_REG_ADVANCED\fR, +\fBTCL_REG_EXTENDED\fR, \fBTCL_REG_BASIC\fR, \fBTCL_REG_EXPANDED\fR, +\fBTCL_REG_QUOTE\fR, \fBTCL_REG_NOCASE\fR, \fBTCL_REG_NEWLINE\fR, +\fBTCL_REG_NLSTOP\fR, \fBTCL_REG_NLANCH\fR, \fBTCL_REG_NOSUB\fR, and +\fBTCL_REG_CANMATCH\fR. See below for more information. +.AP int offset in +The character offset into the text where matching should begin. +The value of the offset has no impact on \fB^\fR matches. This +behavior is controlled by \fIeflags\fR. +.AP int nmatches in +The number of matching subexpressions that should be remembered for +later use. If this value is 0, then no subexpression match +information will be computed. If the value is \-1, then +all of the matching subexpressions will be remembered. Any other +value will be taken as the maximum number of subexpressions to +remember. +.AP int eflags in +OR-ed combination of the execution flags \fBTCL_REG_NOTBOL\fR and +\fBTCL_REG_NOTEOL\fR. See below for more information. +.AP Tcl_RegExpInfo *infoPtr out +The address of the location where information about a previous match +should be stored by \fBTcl_RegExpGetInfo\fR. +.BE +.SH DESCRIPTION +.PP +\fBTcl_RegExpMatch\fR determines whether its \fIpattern\fR argument +matches \fIregexp\fR, where \fIregexp\fR is interpreted +as a regular expression using the rules in the \fBre_syntax\fR +reference page. +If there is a match then \fBTcl_RegExpMatch\fR returns 1. +If there is no match then \fBTcl_RegExpMatch\fR returns 0. +If an error occurs in the matching process (e.g. \fIpattern\fR +is not a valid regular expression) then \fBTcl_RegExpMatch\fR +returns \-1 and leaves an error message in the interpreter result. +\fBTcl_RegExpMatchObj\fR is similar to \fBTcl_RegExpMatch\fR except it +operates on the Tcl values \fItextObj\fR and \fIpatObj\fR instead of +UTF strings. +\fBTcl_RegExpMatchObj\fR is generally more efficient than +\fBTcl_RegExpMatch\fR, so it is the preferred interface. +.PP +\fBTcl_RegExpCompile\fR, \fBTcl_RegExpExec\fR, and \fBTcl_RegExpRange\fR +provide lower-level access to the regular expression pattern matcher. +\fBTcl_RegExpCompile\fR compiles a regular expression string into +the internal form used for efficient pattern matching. +The return value is a token for this compiled form, which can be +used in subsequent calls to \fBTcl_RegExpExec\fR or \fBTcl_RegExpRange\fR. +If an error occurs while compiling the regular expression then +\fBTcl_RegExpCompile\fR returns NULL and leaves an error message +in the interpreter result. +Note: the return value from \fBTcl_RegExpCompile\fR is only valid +up to the next call to \fBTcl_RegExpCompile\fR; it is not safe to +retain these values for long periods of time. +.PP +\fBTcl_RegExpExec\fR executes the regular expression pattern matcher. +It returns 1 if \fItext\fR contains a range of characters that +match \fIregexp\fR, 0 if no match is found, and +\-1 if an error occurs. +In the case of an error, \fBTcl_RegExpExec\fR leaves an error +message in the interpreter result. +When searching a string for multiple matches of a pattern, +it is important to distinguish between the start of the original +string and the start of the current search. +For example, when searching for the second occurrence of a +match, the \fItext\fR argument might point to the character +just after the first match; however, it is important for the +pattern matcher to know that this is not the start of the entire string, +so that it does not allow +.QW \fB^\fR +atoms in the pattern to match. +The \fIstart\fR argument provides this information by pointing +to the start of the overall string containing \fItext\fR. +\fIStart\fR will be less than or equal to \fItext\fR; if it +is less than \fItext\fR then no \fB^\fR matches will be allowed. +.PP +\fBTcl_RegExpRange\fR may be invoked after \fBTcl_RegExpExec\fR +returns; it provides detailed information about what ranges of +the string matched what parts of the pattern. +\fBTcl_RegExpRange\fR returns a pair of pointers in \fI*startPtr\fR +and \fI*endPtr\fR that identify a range of characters in +the source string for the most recent call to \fBTcl_RegExpExec\fR. +\fIIndex\fR indicates which of several ranges is desired: +if \fIindex\fR is 0, information is returned about the overall range +of characters that matched the entire pattern; otherwise, +information is returned about the range of characters that matched the +\fIindex\fR'th parenthesized subexpression within the pattern. +If there is no range corresponding to \fIindex\fR then NULL +is stored in \fI*startPtr\fR and \fI*endPtr\fR. +.PP +\fBTcl_GetRegExpFromObj\fR, \fBTcl_RegExpExecObj\fR, and +\fBTcl_RegExpGetInfo\fR are value interfaces that provide the most +direct control of Henry Spencer's regular expression library. For +users that need to modify compilation and execution options directly, +it is recommended that you use these interfaces instead of calling the +internal regexp functions. These interfaces handle the details of UTF +to Unicode translations as well as providing improved performance +through caching in the pattern and string values. +.PP +\fBTcl_GetRegExpFromObj\fR attempts to return a compiled regular +expression from the \fIpatObj\fR. If the value does not already +contain a compiled regular expression it will attempt to create one +from the string in the value and assign it to the internal +representation of the \fIpatObj\fR. The return value of this function +is of type \fBTcl_RegExp\fR. The return value is a token for this +compiled form, which can be used in subsequent calls to +\fBTcl_RegExpExecObj\fR or \fBTcl_RegExpGetInfo\fR. If an error +occurs while compiling the regular expression then +\fBTcl_GetRegExpFromObj\fR returns NULL and leaves an error message in +the interpreter result. The regular expression token can be used as +long as the internal representation of \fIpatObj\fR refers to the +compiled form. The \fIcflags\fR argument is a bit-wise OR of +zero or more of the following flags that control the compilation of +\fIpatObj\fR: +.RS 2 +.TP +\fBTCL_REG_ADVANCED\fR +Compile advanced regular expressions +.PQ ARE s . +This mode corresponds to +the normal regular expression syntax accepted by the Tcl \fBregexp\fR and +\fBregsub\fR commands. +.TP +\fBTCL_REG_EXTENDED\fR +Compile extended regular expressions +.PQ ERE s . +This mode corresponds +to the regular expression syntax recognized by Tcl 8.0 and earlier +versions. +.TP +\fBTCL_REG_BASIC\fR +Compile basic regular expressions +.PQ BRE s . +This mode corresponds +to the regular expression syntax recognized by common Unix utilities +like \fBsed\fR and \fBgrep\fR. This is the default if no flags are +specified. +.TP +\fBTCL_REG_EXPANDED\fR +Compile the regular expression (basic, extended, or advanced) using an +expanded syntax that allows comments and whitespace. This mode causes +non-backslashed non-bracket-expression white +space and #-to-end-of-line comments to be ignored. +.TP +\fBTCL_REG_QUOTE\fR +Compile a literal string, with all characters treated as ordinary characters. +.TP +\fBTCL_REG_NOCASE\fR +Compile for matching that ignores upper/lower case distinctions. +.TP +\fBTCL_REG_NEWLINE\fR +Compile for newline-sensitive matching. By default, newline is a +completely ordinary character with no special meaning in either +regular expressions or strings. With this flag, +.QW [^ +bracket expressions and +.QW . +never match newline, +.QW ^ +matches an empty string +after any newline in addition to its normal function, and +.QW $ +matches +an empty string before any newline in addition to its normal function. +\fBREG_NEWLINE\fR is the bit-wise OR of \fBREG_NLSTOP\fR and +\fBREG_NLANCH\fR. +.TP +\fBTCL_REG_NLSTOP\fR +Compile for partial newline-sensitive matching, +with the behavior of +.QW [^ +bracket expressions and +.QW . +affected, but not the behavior of +.QW ^ +and +.QW $ . +In this mode, +.QW [^ +bracket expressions and +.QW . +never match newline. +.TP +\fBTCL_REG_NLANCH\fR +Compile for inverse partial newline-sensitive matching, +with the behavior of +.QW ^ +and +.QW $ +(the +.QW anchors ) +affected, but not the behavior of +.QW [^ +bracket expressions and +.QW . . +In this mode +.QW ^ +matches an empty string +after any newline in addition to its normal function, and +.QW $ +matches +an empty string before any newline in addition to its normal function. +.TP +\fBTCL_REG_NOSUB\fR +Compile for matching that reports only success or failure, +not what was matched. This reduces compile overhead and may improve +performance. Subsequent calls to \fBTcl_RegExpGetInfo\fR or +\fBTcl_RegExpRange\fR will not report any match information. +.TP +\fBTCL_REG_CANMATCH\fR +Compile for matching that reports the potential to complete a partial +match given more text (see below). +.RE +.PP +Only one of +\fBTCL_REG_EXTENDED\fR, +\fBTCL_REG_ADVANCED\fR, +\fBTCL_REG_BASIC\fR, and +\fBTCL_REG_QUOTE\fR may be specified. +.PP +\fBTcl_RegExpExecObj\fR executes the regular expression pattern +matcher. It returns 1 if \fIobjPtr\fR contains a range of characters +that match \fIregexp\fR, 0 if no match is found, and \-1 if an error +occurs. In the case of an error, \fBTcl_RegExpExecObj\fR leaves an +error message in the interpreter result. The \fInmatches\fR value +indicates to the matcher how many subexpressions are of interest. If +\fInmatches\fR is 0, then no subexpression match information is +recorded, which may allow the matcher to make various optimizations. +If the value is \-1, then all of the subexpressions in the pattern are +remembered. If the value is a positive integer, then only that number +of subexpressions will be remembered. Matching begins at the +specified Unicode character index given by \fIoffset\fR. Unlike +\fBTcl_RegExpExec\fR, the behavior of anchors is not affected by the +offset value. Instead the behavior of the anchors is explicitly +controlled by the \fIeflags\fR argument, which is a bit-wise OR of +zero or more of the following flags: +.RS 2 +.TP +\fBTCL_REG_NOTBOL\fR +The starting character will not be treated as the beginning of a +line or the beginning of the string, so +.QW ^ +will not match there. +Note that this flag has no effect on how +.QW \fB\eA\fR +matches. +.TP +\fBTCL_REG_NOTEOL\fR +The last character in the string will not be treated as the end of a +line or the end of the string, so +.QW $ +will not match there. +Note that this flag has no effect on how +.QW \fB\eZ\fR +matches. +.RE +.PP +\fBTcl_RegExpGetInfo\fR retrieves information about the last match +performed with a given regular expression \fIregexp\fR. The +\fIinfoPtr\fR argument contains a pointer to a structure that is +defined as follows: +.PP +.CS +typedef struct Tcl_RegExpInfo { + int \fInsubs\fR; + Tcl_RegExpIndices *\fImatches\fR; + long \fIextendStart\fR; +} \fBTcl_RegExpInfo\fR; +.CE +.PP +The \fInsubs\fR field contains a count of the number of parenthesized +subexpressions within the regular expression. If the \fBTCL_REG_NOSUB\fR +was used, then this value will be zero. The \fImatches\fR field +points to an array of \fInsubs\fR+1 values that indicate the bounds of each +subexpression matched. The first element in the array refers to the +range matched by the entire regular expression, and subsequent elements +refer to the parenthesized subexpressions in the order that they +appear in the pattern. Each element is a structure that is defined as +follows: +.PP +.CS +typedef struct Tcl_RegExpIndices { + long \fIstart\fR; + long \fIend\fR; +} \fBTcl_RegExpIndices\fR; +.CE +.PP +The \fIstart\fR and \fIend\fR values are Unicode character indices +relative to the offset location within \fIobjPtr\fR where matching began. +The \fIstart\fR index identifies the first character of the matched +subexpression. The \fIend\fR index identifies the first character +after the matched subexpression. If the subexpression matched the +empty string, then \fIstart\fR and \fIend\fR will be equal. If the +subexpression did not participate in the match, then \fIstart\fR and +\fIend\fR will be set to \-1. +.PP +The \fIextendStart\fR field in \fBTcl_RegExpInfo\fR is only set if the +\fBTCL_REG_CANMATCH\fR flag was used. It indicates the first +character in the string where a match could occur. If a match was +found, this will be the same as the beginning of the current match. +If no match was found, then it indicates the earliest point at which a +match might occur if additional text is appended to the string. If it +is no match is possible even with further text, this field will be set +to \-1. +.SH "SEE ALSO" +re_syntax(n) +.SH KEYWORDS +match, pattern, regular expression, string, subexpression, Tcl_RegExpIndices, Tcl_RegExpInfo diff --git a/tcl8.6/doc/SaveResult.3 b/tcl8.6/doc/SaveResult.3 new file mode 100644 index 0000000..6dd6cb6 --- /dev/null +++ b/tcl8.6/doc/SaveResult.3 @@ -0,0 +1,120 @@ +'\" +'\" Copyright (c) 1997 by Sun Microsystems, Inc. +'\" Contributions from Don Porter, NIST, 2004. (not subject to US copyright) +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH Tcl_SaveResult 3 8.1 Tcl "Tcl Library Procedures" +.so man.macros +.BS +.SH NAME +Tcl_SaveInterpState, Tcl_RestoreInterpState, Tcl_DiscardInterpState, Tcl_SaveResult, Tcl_RestoreResult, Tcl_DiscardResult \- save and restore an interpreter's state +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +Tcl_InterpState +\fBTcl_SaveInterpState\fR(\fIinterp, status\fR) +.sp +int +\fBTcl_RestoreInterpState\fR(\fIinterp, state\fR) +.sp +\fBTcl_DiscardInterpState\fR(\fIstate\fR) +.sp +\fBTcl_SaveResult\fR(\fIinterp, savedPtr\fR) +.sp +\fBTcl_RestoreResult\fR(\fIinterp, savedPtr\fR) +.sp +\fBTcl_DiscardResult\fR(\fIsavedPtr\fR) +.SH ARGUMENTS +.AS Tcl_InterpState savedPtr +.AP Tcl_Interp *interp in +Interpreter for which state should be saved. +.AP int status in +Return code value to save as part of interpreter state. +.AP Tcl_InterpState state in +Saved state token to be restored or discarded. +.AP Tcl_SavedResult *savedPtr in +Pointer to location where interpreter result should be saved or restored. +.BE +.SH DESCRIPTION +.PP +These routines allows a C procedure to take a snapshot of the current +state of an interpreter so that it can be restored after a call +to \fBTcl_Eval\fR or some other routine that modifies the interpreter +state. There are two triplets of routines meant to work together. +.PP +The first triplet stores the snapshot of interpreter state in +an opaque token returned by \fBTcl_SaveInterpState\fR. That token +value may then be passed back to one of \fBTcl_RestoreInterpState\fR +or \fBTcl_DiscardInterpState\fR, depending on whether the interp +state is to be restored. So long as one of the latter two routines +is called, Tcl will take care of memory management. +.PP +The second triplet stores the snapshot of only the interpreter +result (not its complete state) in memory allocated by the caller. +These routines are passed a pointer to \fBTcl_SavedResult\fR +that is used to store enough information to restore the interpreter result. +\fBTcl_SavedResult\fR can be allocated on the stack of the calling +procedure. These routines do not save the state of any error +information in the interpreter (e.g. the \fB\-errorcode\fR or +\fB\-errorinfo\fR return options, when an error is in progress). +.PP +Because the routines \fBTcl_SaveInterpState\fR, +\fBTcl_RestoreInterpState\fR, and \fBTcl_DiscardInterpState\fR perform +a superset of the functions provided by the other routines, +any new code should only make use of the more powerful routines. +The older, weaker routines \fBTcl_SaveResult\fR, \fBTcl_RestoreResult\fR, +and \fBTcl_DiscardResult\fR continue to exist only for the sake +of existing programs that may already be using them. +.PP +\fBTcl_SaveInterpState\fR takes a snapshot of those portions of +interpreter state that make up the full result of script evaluation. +This include the interpreter result, the return code (passed in +as the \fIstatus\fR argument, and any return options, including +\fB\-errorinfo\fR and \fB\-errorcode\fR when an error is in progress. +This snapshot is returned as an opaque token of type \fBTcl_InterpState\fR. +The call to \fBTcl_SaveInterpState\fR does not itself change the +state of the interpreter. Unlike \fBTcl_SaveResult\fR, it does +not reset the interpreter. +.PP +\fBTcl_RestoreInterpState\fR accepts a \fBTcl_InterpState\fR token +previously returned by \fBTcl_SaveInterpState\fR and restores the +state of the interp to the state held in that snapshot. The return +value of \fBTcl_RestoreInterpState\fR is the status value originally +passed to \fBTcl_SaveInterpState\fR when the snapshot token was +created. +.PP +\fBTcl_DiscardInterpState\fR is called to release a \fBTcl_InterpState\fR +token previously returned by \fBTcl_SaveInterpState\fR when that +snapshot is not to be restored to an interp. +.PP +The \fBTcl_InterpState\fR token returned by \fBTcl_SaveInterpState\fR +must eventually be passed to either \fBTcl_RestoreInterpState\fR +or \fBTcl_DiscardInterpState\fR to avoid a memory leak. Once +the \fBTcl_InterpState\fR token is passed to one of them, the +token is no longer valid and should not be used anymore. +.PP +\fBTcl_SaveResult\fR moves the string and value results +of \fIinterp\fR into the location specified by \fIstatePtr\fR. +\fBTcl_SaveResult\fR clears the result for \fIinterp\fR and +leaves the result in its normal empty initialized state. +.PP +\fBTcl_RestoreResult\fR moves the string and value results from +\fIstatePtr\fR back into \fIinterp\fR. Any result or error that was +already in the interpreter will be cleared. The \fIstatePtr\fR is left +in an uninitialized state and cannot be used until another call to +\fBTcl_SaveResult\fR. +.PP +\fBTcl_DiscardResult\fR releases the saved interpreter state +stored at \fBstatePtr\fR. The state structure is left in an +uninitialized state and cannot be used until another call to +\fBTcl_SaveResult\fR. +.PP +Once \fBTcl_SaveResult\fR is called to save the interpreter +result, either \fBTcl_RestoreResult\fR or +\fBTcl_DiscardResult\fR must be called to properly clean up the +memory associated with the saved state. +.SH KEYWORDS +result, state, interp diff --git a/tcl8.6/doc/SetChanErr.3 b/tcl8.6/doc/SetChanErr.3 new file mode 100644 index 0000000..5bb86be --- /dev/null +++ b/tcl8.6/doc/SetChanErr.3 @@ -0,0 +1,140 @@ +'\" +'\" Copyright (c) 2005 Andreas Kupries <andreas_kupries@users.sourceforge.net> +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH Tcl_SetChannelError 3 8.5 Tcl "Tcl Library Procedures" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +Tcl_SetChannelError, Tcl_SetChannelErrorInterp, Tcl_GetChannelError, Tcl_GetChannelErrorInterp \- functions to create/intercept Tcl errors by channel drivers. +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +void +\fBTcl_SetChannelError\fR(\fIchan, msg\fR) +.sp +void +\fBTcl_SetChannelErrorInterp\fR(\fIinterp, msg\fR) +.sp +void +\fBTcl_GetChannelError\fR(\fIchan, msgPtr\fR) +.sp +void +\fBTcl_GetChannelErrorInterp\fR(\fIinterp, msgPtr\fR) +.sp +.SH ARGUMENTS +.AS Tcl_Channel chan +.AP Tcl_Channel chan in +Refers to the Tcl channel whose bypass area is accessed. +.AP Tcl_Interp* interp in +Refers to the Tcl interpreter whose bypass area is accessed. +.AP Tcl_Obj* msg in +Error message put into a bypass area. A list of return options and values, +followed by a string message. Both message and the option/value information +are optional. +.AP Tcl_Obj** msgPtr out +Reference to a place where the message stored in the accessed bypass area can +be stored in. +.BE +.SH DESCRIPTION +.PP +The current definition of a Tcl channel driver does not permit the direct +return of arbitrary error messages, except for the setting and retrieval of +channel options. All other functions are restricted to POSIX error codes. +.PP +The functions described here overcome this limitation. Channel drivers are +allowed to use \fBTcl_SetChannelError\fR and \fBTcl_SetChannelErrorInterp\fR +to place arbitrary error messages in \fBbypass areas\fR defined for channels +and interpreters. And the generic I/O layer uses \fBTcl_GetChannelError\fR and +\fBTcl_GetChannelErrorInterp\fR to look for messages in the bypass areas and +arrange for their return as errors. The POSIX error codes set by a driver are +used now if and only if no messages are present. +.PP +\fBTcl_SetChannelError\fR stores error information in the bypass area of the +specified channel. The number of references to the \fBmsg\fR value goes up by +one. Previously stored information will be discarded, by releasing the +reference held by the channel. The channel reference must not be NULL. +.PP +\fBTcl_SetChannelErrorInterp\fR stores error information in the bypass area of +the specified interpreter. The number of references to the \fBmsg\fR value +goes up by one. Previously stored information will be discarded, by releasing +the reference held by the interpreter. The interpreter reference must not be +NULL. +.PP +\fBTcl_GetChannelError\fR places either the error message held in the bypass +area of the specified channel into \fImsgPtr\fR, or NULL; and resets the +bypass, that is, after an invocation all following invocations will return +NULL, until an intervening invocation of \fBTcl_SetChannelError\fR with a +non-NULL message. The \fImsgPtr\fR must not be NULL. The reference count of +the message is not touched. The reference previously held by the channel is +now held by the caller of the function and it is its responsibility to release +that reference when it is done with the value. +.PP +\fBTcl_GetChannelErrorInterp\fR places either the error message held in the +bypass area of the specified interpreter into \fImsgPtr\fR, or NULL; and +resets the bypass, that is, after an invocation all following invocations will +return NULL, until an intervening invocation of +\fBTcl_SetChannelErrorInterp\fR with a non-NULL message. The \fImsgPtr\fR must +not be NULL. The reference count of the message is not touched. The reference +previously held by the interpreter is now held by the caller of the function +and it is its responsibility to release that reference when it is done with +the value. +.PP +Which functions of a channel driver are allowed to use which bypass function +is listed below, as is which functions of the public channel API may leave a +messages in the bypass areas. +.IP \fBTcl_DriverCloseProc\fR +May use \fBTcl_SetChannelErrorInterp\fR, and only this function. +.IP \fBTcl_DriverInputProc\fR +May use \fBTcl_SetChannelError\fR, and only this function. +.IP \fBTcl_DriverOutputProc\fR +May use \fBTcl_SetChannelError\fR, and only this function. +.IP \fBTcl_DriverSeekProc\fR +May use \fBTcl_SetChannelError\fR, and only this function. +.IP \fBTcl_DriverWideSeekProc\fR +May use \fBTcl_SetChannelError\fR, and only this function. +.IP \fBTcl_DriverSetOptionProc\fR +Has already the ability to pass arbitrary error messages. Must \fInot\fR use +any of the new functions. +.IP \fBTcl_DriverGetOptionProc\fR +Has already the ability to pass arbitrary error messages. Must +\fInot\fR use any of the new functions. +.IP \fBTcl_DriverWatchProc\fR +Must \fInot\fR use any of the new functions. Is internally called and has no +ability to return any type of error whatsoever. +.IP \fBTcl_DriverBlockModeProc\fR +May use \fBTcl_SetChannelError\fR, and only this function. +.IP \fBTcl_DriverGetHandleProc\fR +Must \fInot\fR use any of the new functions. It is only a low-level function, +and not used by Tcl commands. +.IP \fBTcl_DriverHandlerProc\fR +Must \fInot\fR use any of the new functions. Is internally called and has no +ability to return any type of error whatsoever. +.PP +Given the information above the following public functions of the Tcl C API +are affected by these changes; when these functions are called, the channel +may now contain a stored arbitrary error message requiring processing by the +caller. +.DS +.ta 1.9i 4i +\fBTcl_Flush\fR \fBTcl_GetsObj\fR \fBTcl_Gets\fR +\fBTcl_ReadChars\fR \fBTcl_ReadRaw\fR \fBTcl_Read\fR +\fBTcl_Seek\fR \fBTcl_StackChannel\fR \fBTcl_Tell\fR +\fBTcl_WriteChars\fR \fBTcl_WriteObj\fR \fBTcl_WriteRaw\fR +\fBTcl_Write\fR +.DE +.PP +All other API functions are unchanged. In particular, the functions below +leave all their error information in the interpreter result. +.DS +.ta 1.9i 4i +\fBTcl_Close\fR \fBTcl_UnstackChannel\fR \fBTcl_UnregisterChannel\fR +.DE +.SH "SEE ALSO" +Tcl_Close(3), Tcl_OpenFileChannel(3), Tcl_SetErrno(3) +.SH KEYWORDS +channel driver, error messages, channel type diff --git a/tcl8.6/doc/SetErrno.3 b/tcl8.6/doc/SetErrno.3 new file mode 100644 index 0000000..21648b1 --- /dev/null +++ b/tcl8.6/doc/SetErrno.3 @@ -0,0 +1,66 @@ +'\" +'\" Copyright (c) 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. +'\" +.TH Tcl_SetErrno 3 8.3 Tcl "Tcl Library Procedures" +.so man.macros +.BS +.SH NAME +Tcl_SetErrno, Tcl_GetErrno, Tcl_ErrnoId, Tcl_ErrnoMsg \- manipulate errno to store and retrieve error codes +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +void +\fBTcl_SetErrno\fR(\fIerrorCode\fR) +.sp +int +\fBTcl_GetErrno\fR() +.sp +const char * +\fBTcl_ErrnoId\fR() +.sp +const char * +\fBTcl_ErrnoMsg\fR(\fIerrorCode\fR) +.sp +.SH ARGUMENTS +.AS int errorCode +.AP int errorCode in +A POSIX error code such as \fBENOENT\fR. +.BE + +.SH DESCRIPTION +.PP +\fBTcl_SetErrno\fR and \fBTcl_GetErrno\fR provide portable access +to the \fBerrno\fR variable, which is used to record a POSIX error +code after system calls and other operations such as \fBTcl_Gets\fR. +These procedures are necessary because global variable accesses cannot +be made across module boundaries on some platforms. +.PP +\fBTcl_SetErrno\fR sets the \fBerrno\fR variable to the value of the +\fIerrorCode\fR argument +C procedures that wish to return error information to their callers +via \fBerrno\fR should call \fBTcl_SetErrno\fR rather than setting +\fBerrno\fR directly. +.PP +\fBTcl_GetErrno\fR returns the current value of \fBerrno\fR. +Procedures wishing to access \fBerrno\fR should call this procedure +instead of accessing \fBerrno\fR directly. +.PP +\fBTcl_ErrnoId\fR and \fBTcl_ErrnoMsg\fR return string +representations of \fBerrno\fR values. \fBTcl_ErrnoId\fR +returns a machine-readable textual identifier such as +.QW EACCES +that corresponds to the current value of \fBerrno\fR. +\fBTcl_ErrnoMsg\fR returns a human-readable string such as +.QW "permission denied" +that corresponds to the value of its +\fIerrorCode\fR argument. The \fIerrorCode\fR argument is +typically the value returned by \fBTcl_GetErrno\fR. +The strings returned by these functions are +statically allocated and the caller must not free or modify them. + +.SH KEYWORDS +errno, error code, global variables diff --git a/tcl8.6/doc/SetRecLmt.3 b/tcl8.6/doc/SetRecLmt.3 new file mode 100644 index 0000000..904d4ab --- /dev/null +++ b/tcl8.6/doc/SetRecLmt.3 @@ -0,0 +1,53 @@ +'\" +'\" Copyright (c) 1989-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. +'\" +.TH Tcl_SetRecursionLimit 3 7.0 Tcl "Tcl Library Procedures" +.so man.macros +.BS +.SH NAME +Tcl_SetRecursionLimit \- set maximum allowable nesting depth in interpreter +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +int +\fBTcl_SetRecursionLimit\fR(\fIinterp, depth\fR) +.SH ARGUMENTS +.AS Tcl_Interp *interp +.AP Tcl_Interp *interp in +Interpreter whose recursion limit is to be set. +Must be greater than zero. +.AP int depth in +New limit for nested calls to \fBTcl_Eval\fR for \fIinterp\fR. +.BE + +.SH DESCRIPTION +.PP +At any given time Tcl enforces a limit on the number of recursive +calls that may be active for \fBTcl_Eval\fR and related procedures +such as \fBTcl_GlobalEval\fR. +Any call to \fBTcl_Eval\fR that exceeds this depth is aborted with +an error. +By default the recursion limit is 1000. +.PP +\fBTcl_SetRecursionLimit\fR may be used to change the maximum +allowable nesting depth for an interpreter. +The \fIdepth\fR argument specifies a new limit for \fIinterp\fR, +and \fBTcl_SetRecursionLimit\fR returns the old limit. +To read out the old limit without modifying it, invoke +\fBTcl_SetRecursionLimit\fR with \fIdepth\fR equal to 0. +.PP +The \fBTcl_SetRecursionLimit\fR only sets the size of the Tcl +call stack: it cannot by itself prevent stack overflows on the +C stack being used by the application. If your machine has a +limit on the size of the C stack, you may get stack overflows +before reaching the limit set by \fBTcl_SetRecursionLimit\fR. +If this happens, see if there is a mechanism in your system for +increasing the maximum size of the C stack. + +.SH KEYWORDS +nesting depth, recursion diff --git a/tcl8.6/doc/SetResult.3 b/tcl8.6/doc/SetResult.3 new file mode 100644 index 0000000..e5b81d7 --- /dev/null +++ b/tcl8.6/doc/SetResult.3 @@ -0,0 +1,255 @@ +'\" +'\" Copyright (c) 1989-1993 The Regents of the University of California. +'\" Copyright (c) 1994-1997 Sun Microsystems, Inc. +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH Tcl_SetResult 3 8.0 Tcl "Tcl Library Procedures" +.so man.macros +.BS +.SH NAME +Tcl_SetObjResult, Tcl_GetObjResult, Tcl_SetResult, Tcl_GetStringResult, Tcl_AppendResult, Tcl_AppendResultVA, Tcl_AppendElement, Tcl_ResetResult, Tcl_TransferResult, Tcl_FreeResult \- manipulate Tcl result +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +\fBTcl_SetObjResult\fR(\fIinterp, objPtr\fR) +.sp +Tcl_Obj * +\fBTcl_GetObjResult\fR(\fIinterp\fR) +.sp +\fBTcl_SetResult\fR(\fIinterp, result, freeProc\fR) +.sp +const char * +\fBTcl_GetStringResult\fR(\fIinterp\fR) +.sp +\fBTcl_AppendResult\fR(\fIinterp, result, result, ... , \fB(char *) NULL\fR) +.sp +\fBTcl_AppendResultVA\fR(\fIinterp, argList\fR) +.sp +\fBTcl_ResetResult\fR(\fIinterp\fR) +.sp +.VS 8.6 +\fBTcl_TransferResult\fR(\fIsourceInterp, result, targetInterp\fR) +.VE 8.6 +.sp +\fBTcl_AppendElement\fR(\fIinterp, element\fR) +.sp +\fBTcl_FreeResult\fR(\fIinterp\fR) +.SH ARGUMENTS +.AS Tcl_FreeProc sourceInterp out +.AP Tcl_Interp *interp out +Interpreter whose result is to be modified or read. +.AP Tcl_Obj *objPtr in +Tcl value to become result for \fIinterp\fR. +.AP char *result in +String value to become result for \fIinterp\fR or to be +appended to the existing result. +.AP "const char" *element in +String value to append as a list element +to the existing result of \fIinterp\fR. +.AP Tcl_FreeProc *freeProc in +Address of procedure to call to release storage at +\fIresult\fR, or \fBTCL_STATIC\fR, \fBTCL_DYNAMIC\fR, or +\fBTCL_VOLATILE\fR. +.AP va_list argList in +An argument list which must have been initialized using +\fBva_start\fR, and cleared using \fBva_end\fR. +.AP Tcl_Interp *sourceInterp in +.VS 8.6 +Interpreter that the result and error information should be copied from. +.VE 8.6 +.AP Tcl_Interp *targetInterp in +.VS 8.6 +Interpreter that the result and error information should be copied to. +.VE 8.6 +.AP int result in +.VS 8.6 +If \fBTCL_OK\fR, only copy the result. If \fBTCL_ERROR\fR, copy the error +information as well. +.VE 8.6 +.BE +.SH DESCRIPTION +.PP +The procedures described here are utilities for manipulating the +result value in a Tcl interpreter. +The interpreter result may be either a Tcl value or a string. +For example, \fBTcl_SetObjResult\fR and \fBTcl_SetResult\fR +set the interpreter result to, respectively, a value and a string. +Similarly, \fBTcl_GetObjResult\fR and \fBTcl_GetStringResult\fR +return the interpreter result as a value and as a string. +The procedures always keep the string and value forms +of the interpreter result consistent. +For example, if \fBTcl_SetObjResult\fR is called to set +the result to a value, +then \fBTcl_GetStringResult\fR is called, +it will return the value's string representation. +.PP +\fBTcl_SetObjResult\fR +arranges for \fIobjPtr\fR to be the result for \fIinterp\fR, +replacing any existing result. +The result is left pointing to the value +referenced by \fIobjPtr\fR. +\fIobjPtr\fR's reference count is incremented +since there is now a new reference to it from \fIinterp\fR. +The reference count for any old result value +is decremented and the old result value is freed if no +references to it remain. +.PP +\fBTcl_GetObjResult\fR returns the result for \fIinterp\fR as a value. +The value's reference count is not incremented; +if the caller needs to retain a long-term pointer to the value +they should use \fBTcl_IncrRefCount\fR to increment its reference count +in order to keep it from being freed too early or accidentally changed. +.PP +\fBTcl_SetResult\fR +arranges for \fIresult\fR to be the result for the current Tcl +command in \fIinterp\fR, replacing any existing result. +The \fIfreeProc\fR argument specifies how to manage the storage +for the \fIresult\fR argument; +it is discussed in the section +\fBTHE TCL_FREEPROC ARGUMENT TO TCL_SETRESULT\fR below. +If \fIresult\fR is \fBNULL\fR, then \fIfreeProc\fR is ignored +and \fBTcl_SetResult\fR +re-initializes \fIinterp\fR's result to point to an empty string. +.PP +\fBTcl_GetStringResult\fR returns the result for \fIinterp\fR as a string. +If the result was set to a value by a \fBTcl_SetObjResult\fR call, +the value form will be converted to a string and returned. +If the value's string representation contains null bytes, +this conversion will lose information. +For this reason, programmers are encouraged to +write their code to use the new value API procedures +and to call \fBTcl_GetObjResult\fR instead. +.PP +\fBTcl_ResetResult\fR clears the result for \fIinterp\fR +and leaves the result in its normal empty initialized state. +If the result is a value, +its reference count is decremented and the result is left +pointing to an unshared value representing an empty string. +If the result is a dynamically allocated string, its memory is free*d +and the result is left as a empty string. +\fBTcl_ResetResult\fR also clears the error state managed by +\fBTcl_AddErrorInfo\fR, \fBTcl_AddObjErrorInfo\fR, +and \fBTcl_SetErrorCode\fR. +.PP +\fBTcl_AppendResult\fR makes it easy to build up Tcl results in pieces. +It takes each of its \fIresult\fR arguments and appends them in order +to the current result associated with \fIinterp\fR. +If the result is in its initialized empty state (e.g. a command procedure +was just invoked or \fBTcl_ResetResult\fR was just called), +then \fBTcl_AppendResult\fR sets the result to the concatenation of +its \fIresult\fR arguments. +\fBTcl_AppendResult\fR may be called repeatedly as additional pieces +of the result are produced. +\fBTcl_AppendResult\fR takes care of all the +storage management issues associated with managing \fIinterp\fR's +result, such as allocating a larger result area if necessary. +It also manages conversion to and from the \fIresult\fR field of the +\fIinterp\fR so as to handle backward-compatibility with old-style +extensions. +Any number of \fIresult\fR arguments may be passed in a single +call; the last argument in the list must be a NULL pointer. +.PP +\fBTcl_AppendResultVA\fR is the same as \fBTcl_AppendResult\fR except that +instead of taking a variable number of arguments it takes an argument list. +.PP +.VS 8.6 +\fBTcl_TransferResult\fR moves a result from one interpreter to another, +optionally (dependent on the \fIresult\fR parameter) including the error +information dictionary as well. The interpreters must be in the same thread. +The source interpreter will have its result reset by this operation. +.VE 8.6 +.SH "DEPRECATED INTERFACES" +.SS "OLD STRING PROCEDURES" +.PP +Use of the following procedures is deprecated +since they manipulate the Tcl result as a string. +Procedures such as \fBTcl_SetObjResult\fR +that manipulate the result as a value +can be significantly more efficient. +.PP +\fBTcl_AppendElement\fR is similar to \fBTcl_AppendResult\fR in +that it allows results to be built up in pieces. +However, \fBTcl_AppendElement\fR takes only a single \fIelement\fR +argument and it appends that argument to the current result +as a proper Tcl list element. +\fBTcl_AppendElement\fR adds backslashes or braces if necessary +to ensure that \fIinterp\fR's result can be parsed as a list and that +\fIelement\fR will be extracted as a single element. +Under normal conditions, \fBTcl_AppendElement\fR will add a space +character to \fIinterp\fR's result just before adding the new +list element, so that the list elements in the result are properly +separated. +However if the new list element is the first in a list or sub-list +(i.e. \fIinterp\fR's current result is empty, or consists of the +single character +.QW { , +or ends in the characters +.QW " {" ) +then no space is added. +.PP +\fBTcl_FreeResult\fR performs part of the work +of \fBTcl_ResetResult\fR. +It frees up the memory associated with \fIinterp\fR's result. +It also sets \fIinterp->freeProc\fR to zero, but does not +change \fIinterp->result\fR or clear error state. +\fBTcl_FreeResult\fR is most commonly used when a procedure +is about to replace one result value with another. +.SS "DIRECT ACCESS TO INTERP->RESULT" +.PP +It used to be legal for programs to +directly read and write \fIinterp->result\fR +to manipulate the interpreter result. The Tcl headers no longer +permit this access by default, and C code still doing this must +be updated to use supported routines \fBTcl_GetObjResult\fR, +\fBTcl_GetStringResult\fR, \fBTcl_SetObjResult\fR, and \fBTcl_SetResult\fR. +As a migration aid, access can be restored with the compiler directive +.CS +#define USE_INTERP_RESULT +.CE +but this is meant only to offer life support to otherwise dead code. +.SH "THE TCL_FREEPROC ARGUMENT TO TCL_SETRESULT" +.PP +\fBTcl_SetResult\fR's \fIfreeProc\fR argument specifies how +the Tcl system is to manage the storage for the \fIresult\fR argument. +If \fBTcl_SetResult\fR or \fBTcl_SetObjResult\fR are called +at a time when \fIinterp\fR holds a string result, +they do whatever is necessary to dispose of the old string result +(see the \fBTcl_Interp\fR manual entry for details on this). +.PP +If \fIfreeProc\fR is \fBTCL_STATIC\fR it means that \fIresult\fR +refers to an area of static storage that is guaranteed not to be +modified until at least the next call to \fBTcl_Eval\fR. +If \fIfreeProc\fR +is \fBTCL_DYNAMIC\fR it means that \fIresult\fR was allocated with a call +to \fBTcl_Alloc\fR and is now the property of the Tcl system. +\fBTcl_SetResult\fR will arrange for the string's storage to be +released by calling \fBTcl_Free\fR when it is no longer needed. +If \fIfreeProc\fR is \fBTCL_VOLATILE\fR it means that \fIresult\fR +points to an area of memory that is likely to be overwritten when +\fBTcl_SetResult\fR returns (e.g. it points to something in a stack frame). +In this case \fBTcl_SetResult\fR will make a copy of the string in +dynamically allocated storage and arrange for the copy to be the +result for the current Tcl command. +.PP +If \fIfreeProc\fR is not one of the values \fBTCL_STATIC\fR, +\fBTCL_DYNAMIC\fR, and \fBTCL_VOLATILE\fR, then it is the address +of a procedure that Tcl should call to free the string. +This allows applications to use non-standard storage allocators. +When Tcl no longer needs the storage for the string, it will +call \fIfreeProc\fR. \fIFreeProc\fR should have arguments and +result that match the type \fBTcl_FreeProc\fR: +.PP +.CS +typedef void \fBTcl_FreeProc\fR( + char *\fIblockPtr\fR); +.CE +.PP +When \fIfreeProc\fR is called, its \fIblockPtr\fR will be set to +the value of \fIresult\fR passed to \fBTcl_SetResult\fR. +.SH "SEE ALSO" +Tcl_AddErrorInfo, Tcl_CreateObjCommand, Tcl_SetErrorCode, Tcl_Interp +.SH KEYWORDS +append, command, element, list, value, result, return value, interpreter diff --git a/tcl8.6/doc/SetVar.3 b/tcl8.6/doc/SetVar.3 new file mode 100644 index 0000000..4aa671a --- /dev/null +++ b/tcl8.6/doc/SetVar.3 @@ -0,0 +1,249 @@ +'\" +'\" Copyright (c) 1989-1993 The Regents of the University of California. +'\" Copyright (c) 1994-1997 Sun Microsystems, Inc. +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH Tcl_SetVar 3 8.1 Tcl "Tcl Library Procedures" +.so man.macros +.BS +.SH NAME +Tcl_SetVar2Ex, Tcl_SetVar, Tcl_SetVar2, Tcl_ObjSetVar2, Tcl_GetVar2Ex, Tcl_GetVar, Tcl_GetVar2, Tcl_ObjGetVar2, Tcl_UnsetVar, Tcl_UnsetVar2 \- manipulate Tcl variables +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +Tcl_Obj * +\fBTcl_SetVar2Ex\fR(\fIinterp, name1, name2, newValuePtr, flags\fR) +.sp +const char * +\fBTcl_SetVar\fR(\fIinterp, varName, newValue, flags\fR) +.sp +const char * +\fBTcl_SetVar2\fR(\fIinterp, name1, name2, newValue, flags\fR) +.sp +Tcl_Obj * +\fBTcl_ObjSetVar2\fR(\fIinterp, part1Ptr, part2Ptr, newValuePtr, flags\fR) +.sp +Tcl_Obj * +\fBTcl_GetVar2Ex\fR(\fIinterp, name1, name2, flags\fR) +.sp +const char * +\fBTcl_GetVar\fR(\fIinterp, varName, flags\fR) +.sp +const char * +\fBTcl_GetVar2\fR(\fIinterp, name1, name2, flags\fR) +.sp +Tcl_Obj * +\fBTcl_ObjGetVar2\fR(\fIinterp, part1Ptr, part2Ptr, flags\fR) +.sp +int +\fBTcl_UnsetVar\fR(\fIinterp, varName, flags\fR) +.sp +int +\fBTcl_UnsetVar2\fR(\fIinterp, name1, name2, flags\fR) +.SH ARGUMENTS +.AS Tcl_Interp *newValuePtr +.AP Tcl_Interp *interp in +Interpreter containing variable. +.AP "const char" *name1 in +Contains the name of an array variable (if \fIname2\fR is non-NULL) +or (if \fIname2\fR is NULL) either the name of a scalar variable +or a complete name including both variable name and index. +May include \fB::\fR namespace qualifiers +to specify a variable in a particular namespace. +.AP "const char" *name2 in +If non-NULL, gives name of element within array; in this +case \fIname1\fR must refer to an array variable. +.AP Tcl_Obj *newValuePtr in +Points to a Tcl value containing the new value for the variable. +.AP int flags in +OR-ed combination of bits providing additional information. See below +for valid values. +.AP "const char" *varName in +Name of variable. +May include \fB::\fR namespace qualifiers +to specify a variable in a particular namespace. +May refer to a scalar variable or an element of +an array. +.AP "const char" *newValue in +New value for variable, specified as a null-terminated string. +A copy of this value is stored in the variable. +.AP Tcl_Obj *part1Ptr in +Points to a Tcl value containing the variable's name. +The name may include a series of \fB::\fR namespace qualifiers +to specify a variable in a particular namespace. +May refer to a scalar variable or an element of an array variable. +.AP Tcl_Obj *part2Ptr in +If non-NULL, points to a value containing the name of an element +within an array and \fIpart1Ptr\fR must refer to an array variable. +.BE + +.SH DESCRIPTION +.PP +These procedures are used to create, modify, read, and delete +Tcl variables from C code. +.PP +\fBTcl_SetVar2Ex\fR, \fBTcl_SetVar\fR, \fBTcl_SetVar2\fR, and +\fBTcl_ObjSetVar2\fR +will create a new variable or modify an existing one. +These procedures set the given variable to the value +given by \fInewValuePtr\fR or \fInewValue\fR and return a +pointer to the variable's new value, which is stored in Tcl's +variable structure. +\fBTcl_SetVar2Ex\fR and \fBTcl_ObjSetVar2\fR take the new value as a +Tcl_Obj and return +a pointer to a Tcl_Obj. \fBTcl_SetVar\fR and \fBTcl_SetVar2\fR +take the new value as a string and return a string; they are +usually less efficient than \fBTcl_ObjSetVar2\fR. Note that the +return value may be different than the \fInewValuePtr\fR or +\fInewValue\fR argument, due to modifications made by write traces. +If an error occurs in setting the variable (e.g. an array +variable is referenced without giving an index into the array) +NULL is returned and an error message is left in \fIinterp\fR's +result if the \fBTCL_LEAVE_ERR_MSG\fR \fIflag\fR bit is set. +.PP +\fBTcl_GetVar2Ex\fR, \fBTcl_GetVar\fR, \fBTcl_GetVar2\fR, and +\fBTcl_ObjGetVar2\fR +return the current value of a variable. +The arguments to these procedures are treated in the same way +as the arguments to the procedures described above. +Under normal circumstances, the return value is a pointer +to the variable's value. For \fBTcl_GetVar2Ex\fR and +\fBTcl_ObjGetVar2\fR the value is +returned as a pointer to a Tcl_Obj. For \fBTcl_GetVar\fR and +\fBTcl_GetVar2\fR the value is returned as a string; this is +usually less efficient, so \fBTcl_GetVar2Ex\fR or \fBTcl_ObjGetVar2\fR +are preferred. +If an error occurs while reading the variable (e.g. the variable +does not exist or an array element is specified for a scalar +variable), then NULL is returned and an error message is left +in \fIinterp\fR's result if the \fBTCL_LEAVE_ERR_MSG\fR \fIflag\fR +bit is set. +.PP +\fBTcl_UnsetVar\fR and \fBTcl_UnsetVar2\fR may be used to remove +a variable, so that future attempts to read the variable will return +an error. +The arguments to these procedures are treated in the same way +as the arguments to the procedures above. +If the variable is successfully removed then \fBTCL_OK\fR is returned. +If the variable cannot be removed because it does not exist then +\fBTCL_ERROR\fR is returned and an error message is left +in \fIinterp\fR's result if the \fBTCL_LEAVE_ERR_MSG\fR \fIflag\fR +bit is set. +If an array element is specified, the given element is removed +but the array remains. +If an array name is specified without an index, then the entire +array is removed. +.PP +The name of a variable may be specified to these procedures in +four ways: +.IP [1] +If \fBTcl_SetVar\fR, \fBTcl_GetVar\fR, or \fBTcl_UnsetVar\fR +is invoked, the variable name is given as +a single string, \fIvarName\fR. +If \fIvarName\fR contains an open parenthesis and ends with a +close parenthesis, then the value between the parentheses is +treated as an index (which can have any string value) and +the characters before the first open +parenthesis are treated as the name of an array variable. +If \fIvarName\fR does not have parentheses as described above, then +the entire string is treated as the name of a scalar variable. +.IP [2] +If the \fIname1\fR and \fIname2\fR arguments are provided and +\fIname2\fR is non-NULL, then an array element is specified and +the array name and index have +already been separated by the caller: \fIname1\fR contains the +name and \fIname2\fR contains the index. An error is generated +if \fIname1\fR contains an open parenthesis and ends with a +close parenthesis (array element) and \fIname2\fR is non-NULL. +.IP [3] +If \fIname2\fR is NULL, \fIname1\fR is treated just like +\fIvarName\fR in case [1] above (it can be either a scalar or an array +element variable name). +.PP +The \fIflags\fR argument may be used to specify any of several +options to the procedures. +It consists of an OR-ed combination of the following bits. +.TP +\fBTCL_GLOBAL_ONLY\fR +Under normal circumstances the procedures look up variables as follows. +If a procedure call is active in \fIinterp\fR, +the variable is looked up at the current level of procedure call. +Otherwise, the variable is looked up first in the current namespace, +then in the global namespace. +However, if this bit is set in \fIflags\fR then the variable +is looked up only in the global namespace +even if there is a procedure call active. +If both \fBTCL_GLOBAL_ONLY\fR and \fBTCL_NAMESPACE_ONLY\fR are given, +\fBTCL_GLOBAL_ONLY\fR is ignored. +.TP +\fBTCL_NAMESPACE_ONLY\fR +If this bit is set in \fIflags\fR then the variable +is looked up only in the current namespace; if a procedure is active +its variables are ignored, and the global namespace is also ignored unless +it is the current namespace. +.TP +\fBTCL_LEAVE_ERR_MSG\fR +If an error is returned and this bit is set in \fIflags\fR, then +an error message will be left in the interpreter's result, +where it can be retrieved with \fBTcl_GetObjResult\fR +or \fBTcl_GetStringResult\fR. +If this flag bit is not set then no error message is left +and the interpreter's result will not be modified. +.TP +\fBTCL_APPEND_VALUE\fR +If this bit is set then \fInewValuePtr\fR or \fInewValue\fR is +appended to the current value instead of replacing it. +If the variable is currently undefined, then the bit is ignored. +This bit is only used by the \fBTcl_Set*\fR procedures. +.TP +\fBTCL_LIST_ELEMENT\fR +If this bit is set, then \fInewValue\fR is converted to a valid +Tcl list element before setting (or appending to) the variable. +A separator space is appended before the new list element unless +the list element is going to be the first element in a list or +sublist (i.e. the variable's current value is empty, or contains +the single character +.QW { , +or ends in +.QW " }" ). +When appending, the original value of the variable must also be +a valid list, so that the operation is the appending of a new +list element onto a list. +.PP +\fBTcl_GetVar\fR and \fBTcl_GetVar2\fR +return the current value of a variable. +The arguments to these procedures are treated in the same way +as the arguments to \fBTcl_SetVar\fR and \fBTcl_SetVar2\fR. +Under normal circumstances, the return value is a pointer +to the variable's value (which is stored in Tcl's variable +structure and will not change before the next call to \fBTcl_SetVar\fR +or \fBTcl_SetVar2\fR). +\fBTcl_GetVar\fR and \fBTcl_GetVar2\fR use the flag bits \fBTCL_GLOBAL_ONLY\fR +and \fBTCL_LEAVE_ERR_MSG\fR, both of +which have +the same meaning as for \fBTcl_SetVar\fR. +If an error occurs in reading the variable (e.g. the variable +does not exist or an array element is specified for a scalar +variable), then NULL is returned. +.PP +\fBTcl_UnsetVar\fR and \fBTcl_UnsetVar2\fR may be used to remove +a variable, so that future calls to \fBTcl_GetVar\fR or \fBTcl_GetVar2\fR +for the variable will return an error. +The arguments to these procedures are treated in the same way +as the arguments to \fBTcl_GetVar\fR and \fBTcl_GetVar2\fR. +If the variable is successfully removed then \fBTCL_OK\fR is returned. +If the variable cannot be removed because it does not exist then +\fBTCL_ERROR\fR is returned. +If an array element is specified, the given element is removed +but the array remains. +If an array name is specified without an index, then the entire +array is removed. + +.SH "SEE ALSO" +Tcl_GetObjResult, Tcl_GetStringResult, Tcl_TraceVar + +.SH KEYWORDS +array, get variable, interpreter, scalar, set, unset, value, variable diff --git a/tcl8.6/doc/Signal.3 b/tcl8.6/doc/Signal.3 new file mode 100644 index 0000000..70b9d91 --- /dev/null +++ b/tcl8.6/doc/Signal.3 @@ -0,0 +1,41 @@ +'\" +'\" Copyright (c) 2001 ActiveState Tool Corp. +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH Tcl_SignalId 3 8.3 Tcl "Tcl Library Procedures" +.so man.macros +.BS +.SH NAME +Tcl_SignalId, Tcl_SignalMsg \- Convert signal codes +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +const char * +\fBTcl_SignalId\fR(\fIsig\fR) +.sp +const char * +\fBTcl_SignalMsg\fR(\fIsig\fR) +.sp +.SH ARGUMENTS +.AS int sig +.AP int sig in +A POSIX signal number such as \fBSIGPIPE\fR. +.BE + +.SH DESCRIPTION +.PP +\fBTcl_SignalId\fR and \fBTcl_SignalMsg\fR return a string +representation of the provided signal number (\fIsig\fR). +\fBTcl_SignalId\fR returns a machine-readable textual identifier such +as +.QW SIGPIPE . +\fBTcl_SignalMsg\fR returns a human-readable string such as +.QW "bus error" . +The strings returned by these functions are +statically allocated and the caller must not free or modify them. + +.SH KEYWORDS +signals, signal numbers diff --git a/tcl8.6/doc/Sleep.3 b/tcl8.6/doc/Sleep.3 new file mode 100644 index 0000000..2d36697 --- /dev/null +++ b/tcl8.6/doc/Sleep.3 @@ -0,0 +1,34 @@ +'\" +'\" Copyright (c) 1990 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. +'\" +.TH Tcl_Sleep 3 7.5 Tcl "Tcl Library Procedures" +.so man.macros +.BS +.SH NAME +Tcl_Sleep \- delay execution for a given number of milliseconds +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +\fBTcl_Sleep\fR(\fIms\fR) +.SH ARGUMENTS +.AS int ms +.AP int ms in +Number of milliseconds to sleep. +.BE +.SH DESCRIPTION +.PP +This procedure delays the calling process by the number of +milliseconds given by the \fIms\fR parameter and returns +after that time has elapsed. It is typically used for things +like flashing a button, where the delay is short and the +application need not do anything while it waits. For longer +delays where the application needs to respond to other events +during the delay, the procedure \fBTcl_CreateTimerHandler\fR +should be used instead of \fBTcl_Sleep\fR. +.SH KEYWORDS +sleep, time, wait diff --git a/tcl8.6/doc/SourceRCFile.3 b/tcl8.6/doc/SourceRCFile.3 new file mode 100644 index 0000000..0afb66b --- /dev/null +++ b/tcl8.6/doc/SourceRCFile.3 @@ -0,0 +1,32 @@ +'\" +'\" Copyright (c) 1998-2000 by Scriptics Corporation. +'\" All rights reserved. +'\" +.TH Tcl_SourceRCFile 3 8.3 Tcl "Tcl Library Procedures" +.so man.macros +.BS +.SH NAME +Tcl_SourceRCFile \- source the Tcl rc file +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +void +\fBTcl_SourceRCFile\fR(\fIinterp\fR) +.SH ARGUMENTS +.AS Tcl_Interp *interp +.AP Tcl_Interp *interp in +Tcl interpreter to source rc file into. +.BE + +.SH DESCRIPTION +.PP +\fBTcl_SourceRCFile\fR is used to source the Tcl rc file at startup. +It is typically invoked by Tcl_Main or Tk_Main. The name of the file +sourced is obtained from the global variable \fBtcl_rcFileName\fR in +the interpreter given by \fIinterp\fR. If this variable is not +defined, or if the file it indicates cannot be found, no action is +taken. + +.SH KEYWORDS +application-specific initialization, main program, rc file diff --git a/tcl8.6/doc/SplitList.3 b/tcl8.6/doc/SplitList.3 new file mode 100644 index 0000000..3439f2e --- /dev/null +++ b/tcl8.6/doc/SplitList.3 @@ -0,0 +1,188 @@ +'\" +'\" Copyright (c) 1989-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. +'\" +.TH Tcl_SplitList 3 8.0 Tcl "Tcl Library Procedures" +.so man.macros +.BS +.SH NAME +Tcl_SplitList, Tcl_Merge, Tcl_ScanElement, Tcl_ConvertElement, Tcl_ScanCountedElement, Tcl_ConvertCountedElement \- manipulate Tcl lists +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +int +\fBTcl_SplitList\fR(\fIinterp, list, argcPtr, argvPtr\fR) +.sp +char * +\fBTcl_Merge\fR(\fIargc, argv\fR) +.sp +int +\fBTcl_ScanElement\fR(\fIsrc, flagsPtr\fR) +.sp +int +\fBTcl_ScanCountedElement\fR(\fIsrc, length, flagsPtr\fR) +.sp +int +\fBTcl_ConvertElement\fR(\fIsrc, dst, flags\fR) +.sp +int +\fBTcl_ConvertCountedElement\fR(\fIsrc, length, dst, flags\fR) +.SH ARGUMENTS +.AS "const char *const" ***argvPtr out +.AP Tcl_Interp *interp out +Interpreter to use for error reporting. If NULL, then no error message +is left. +.AP char *list in +Pointer to a string with proper list structure. +.AP int *argcPtr out +Filled in with number of elements in \fIlist\fR. +.AP "const char" ***argvPtr out +\fI*argvPtr\fR will be filled in with the address of an array of +pointers to the strings that are the extracted elements of \fIlist\fR. +There will be \fI*argcPtr\fR valid entries in the array, followed by +a NULL entry. +.AP int argc in +Number of elements in \fIargv\fR. +.AP "const char *const" *argv in +Array of strings to merge together into a single list. +Each string will become a separate element of the list. +.AP "const char" *src in +String that is to become an element of a list. +.AP int *flagsPtr in +Pointer to word to fill in with information about \fIsrc\fR. +The value of *\fIflagsPtr\fR must be passed to \fBTcl_ConvertElement\fR. +.AP int length in +Number of bytes in string \fIsrc\fR. +.AP char *dst in +Place to copy converted list element. Must contain enough characters +to hold converted string. +.AP int flags in +Information about \fIsrc\fR. Must be value returned by previous +call to \fBTcl_ScanElement\fR, possibly OR-ed +with \fBTCL_DONT_USE_BRACES\fR. +.BE +.SH DESCRIPTION +.PP +These procedures may be used to disassemble and reassemble Tcl lists. +\fBTcl_SplitList\fR breaks a list up into its constituent elements, +returning an array of pointers to the elements using +\fIargcPtr\fR and \fIargvPtr\fR. +While extracting the arguments, \fBTcl_SplitList\fR obeys the usual +rules for backslash substitutions and braces. The area of +memory pointed to by \fI*argvPtr\fR is dynamically allocated; in +addition to the array of pointers, it +also holds copies of all the list elements. It is the caller's +responsibility to free up all of this storage. +For example, suppose that you have called \fBTcl_SplitList\fR with +the following code: +.PP +.CS +int argc, code; +char *string; +char **argv; +\&... +code = \fBTcl_SplitList\fR(interp, string, &argc, &argv); +.CE +.PP +Then you should eventually free the storage with a call like the +following: +.PP +.CS +Tcl_Free((char *) argv); +.CE +.PP +\fBTcl_SplitList\fR normally returns \fBTCL_OK\fR, which means the list was +successfully parsed. +If there was a syntax error in \fIlist\fR, then \fBTCL_ERROR\fR is returned +and the interpreter's result will point to an error message describing the +problem (if \fIinterp\fR was not NULL). +If \fBTCL_ERROR\fR is returned then no memory is allocated and \fI*argvPtr\fR +is not modified. +.PP +\fBTcl_Merge\fR is the inverse of \fBTcl_SplitList\fR: it +takes a collection of strings given by \fIargc\fR +and \fIargv\fR and generates a result string +that has proper list structure. +This means that commands like \fBindex\fR may be used to +extract the original elements again. +In addition, if the result of \fBTcl_Merge\fR is passed to \fBTcl_Eval\fR, +it will be parsed into \fIargc\fR words whose values will +be the same as the \fIargv\fR strings passed to \fBTcl_Merge\fR. +\fBTcl_Merge\fR will modify the list elements with braces and/or +backslashes in order to produce proper Tcl list structure. +The result string is dynamically allocated +using \fBTcl_Alloc\fR; the caller must eventually release the space +using \fBTcl_Free\fR. +.PP +If the result of \fBTcl_Merge\fR is passed to \fBTcl_SplitList\fR, +the elements returned by \fBTcl_SplitList\fR will be identical to +those passed into \fBTcl_Merge\fR. +However, the converse is not true: if \fBTcl_SplitList\fR +is passed a given string, and the resulting \fIargc\fR and +\fIargv\fR are passed to \fBTcl_Merge\fR, the resulting string +may not be the same as the original string passed to \fBTcl_SplitList\fR. +This is because \fBTcl_Merge\fR may use backslashes and braces +differently than the original string. +.PP +\fBTcl_ScanElement\fR and \fBTcl_ConvertElement\fR are the +procedures that do all of the real work of \fBTcl_Merge\fR. +\fBTcl_ScanElement\fR scans its \fIsrc\fR argument +and determines how to use backslashes and braces +when converting it to a list element. +It returns an overestimate of the number of characters +required to represent \fIsrc\fR as a list element, and +it stores information in \fI*flagsPtr\fR that is needed +by \fBTcl_ConvertElement\fR. +.PP +\fBTcl_ConvertElement\fR is a companion procedure to \fBTcl_ScanElement\fR. +It does the actual work of converting a string to a list element. +Its \fIflags\fR argument must be the same as the value returned +by \fBTcl_ScanElement\fR. +\fBTcl_ConvertElement\fR writes a proper list element to memory +starting at *\fIdst\fR and returns a count of the total number +of characters written, which will be no more than the result +returned by \fBTcl_ScanElement\fR. +\fBTcl_ConvertElement\fR writes out only the actual list element +without any leading or trailing spaces: it is up to the caller to +include spaces between adjacent list elements. +.PP +\fBTcl_ConvertElement\fR uses one of two different approaches to +handle the special characters in \fIsrc\fR. Wherever possible, it +handles special characters by surrounding the string with braces. +This produces clean-looking output, but cannot be used in some situations, +such as when \fIsrc\fR contains unmatched braces. +In these situations, \fBTcl_ConvertElement\fR handles special +characters by generating backslash sequences for them. +The caller may insist on the second approach by OR-ing the +flag value returned by \fBTcl_ScanElement\fR with +\fBTCL_DONT_USE_BRACES\fR. +Although this will produce an uglier result, it is useful in some +special situations, such as when \fBTcl_ConvertElement\fR is being +used to generate a portion of an argument for a Tcl command. +In this case, surrounding \fIsrc\fR with curly braces would cause +the command not to be parsed correctly. +.PP +By default, \fBTcl_ConvertElement\fR will use quoting in its output +to be sure the first character of an element is not the hash +character +.PQ # . +This is to be sure the first element of any list +passed to \fBeval\fR is not mis-parsed as the beginning of a comment. +When a list element is not the first element of a list, this quoting +is not necessary. When the caller can be sure that the element is +not the first element of a list, it can disable quoting of the leading +hash character by OR-ing the flag value returned by \fBTcl_ScanElement\fR +with \fBTCL_DONT_QUOTE_HASH\fR. +.PP +\fBTcl_ScanCountedElement\fR and \fBTcl_ConvertCountedElement\fR are +the same as \fBTcl_ScanElement\fR and \fBTcl_ConvertElement\fR, except +the length of string \fIsrc\fR is specified by the \fIlength\fR +argument, and the string may contain embedded nulls. +.SH "SEE ALSO" +Tcl_ListObjGetElements(3) +.SH KEYWORDS +backslash, convert, element, list, merge, split, strings diff --git a/tcl8.6/doc/SplitPath.3 b/tcl8.6/doc/SplitPath.3 new file mode 100644 index 0000000..19cee05 --- /dev/null +++ b/tcl8.6/doc/SplitPath.3 @@ -0,0 +1,97 @@ +'\" +'\" Copyright (c) 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. +'\" +.TH Tcl_SplitPath 3 7.5 Tcl "Tcl Library Procedures" +.so man.macros +.BS +.SH NAME +Tcl_SplitPath, Tcl_JoinPath, Tcl_GetPathType \- manipulate platform-dependent file paths +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +\fBTcl_SplitPath\fR(\fIpath, argcPtr, argvPtr\fR) +.sp +char * +\fBTcl_JoinPath\fR(\fIargc, argv, resultPtr\fR) +.sp +Tcl_PathType +\fBTcl_GetPathType\fR(\fIpath\fR) +.SH ARGUMENTS +.AS "const char *const" ***argvPtr in/out +.AP "const char" *path in +File path in a form appropriate for the current platform (see the +\fBfilename\fR manual entry for acceptable forms for path names). +.AP int *argcPtr out +Filled in with number of path elements in \fIpath\fR. +.AP "const char" ***argvPtr out +\fI*argvPtr\fR will be filled in with the address of an array of +pointers to the strings that are the extracted elements of \fIpath\fR. +There will be \fI*argcPtr\fR valid entries in the array, followed by +a NULL entry. +.AP int argc in +Number of elements in \fIargv\fR. +.AP "const char *const" *argv in +Array of path elements to merge together into a single path. +.AP Tcl_DString *resultPtr in/out +A pointer to an initialized \fBTcl_DString\fR to which the result of +\fBTcl_JoinPath\fR will be appended. +.BE + +.SH DESCRIPTION +.PP +These procedures have been superseded by the Tcl-value-aware procedures in +the \fBFileSystem\fR man page, which are more efficient. +.PP +These procedures may be used to disassemble and reassemble file +paths in a platform independent manner: they provide C-level access to +the same functionality as the \fBfile split\fR, \fBfile join\fR, and +\fBfile pathtype\fR commands. +.PP +\fBTcl_SplitPath\fR breaks a path into its constituent elements, +returning an array of pointers to the elements using \fIargcPtr\fR and +\fIargvPtr\fR. The area of memory pointed to by \fI*argvPtr\fR is +dynamically allocated; in addition to the array of pointers, it also +holds copies of all the path elements. It is the caller's +responsibility to free all of this storage. +For example, suppose that you have called \fBTcl_SplitPath\fR with the +following code: +.PP +.CS +int argc; +char *path; +char **argv; +\&... +Tcl_SplitPath(string, &argc, &argv); +.CE +.PP +Then you should eventually free the storage with a call like the +following: +.PP +.CS +Tcl_Free((char *) argv); +.CE +.PP +\fBTcl_JoinPath\fR is the inverse of \fBTcl_SplitPath\fR: it takes a +collection of path elements given by \fIargc\fR and \fIargv\fR and +generates a result string that is a properly constructed path. The +result string is appended to \fIresultPtr\fR. \fIResultPtr\fR must +refer to an initialized \fBTcl_DString\fR. +.PP +If the result of \fBTcl_SplitPath\fR is passed to \fBTcl_JoinPath\fR, +the result will refer to the same location, but may not be in the same +form. This is because \fBTcl_SplitPath\fR and \fBTcl_JoinPath\fR +eliminate duplicate path separators and return a normalized form for +each platform. +.PP +\fBTcl_GetPathType\fR returns the type of the specified \fIpath\fR, +where \fBTcl_PathType\fR is one of \fBTCL_PATH_ABSOLUTE\fR, +\fBTCL_PATH_RELATIVE\fR, or \fBTCL_PATH_VOLUME_RELATIVE\fR. See the +\fBfilename\fR manual entry for a description of the path types for +each platform. + +.SH KEYWORDS +file, filename, join, path, split, type diff --git a/tcl8.6/doc/StaticPkg.3 b/tcl8.6/doc/StaticPkg.3 new file mode 100644 index 0000000..5700ea7 --- /dev/null +++ b/tcl8.6/doc/StaticPkg.3 @@ -0,0 +1,70 @@ +'\" +'\" Copyright (c) 1995-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. +'\" +.TH Tcl_StaticPackage 3 7.5 Tcl "Tcl Library Procedures" +.so man.macros +.BS +.SH NAME +Tcl_StaticPackage \- make a statically linked package available via the 'load' command +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +\fBTcl_StaticPackage\fR(\fIinterp, pkgName, initProc, safeInitProc\fR) +.SH ARGUMENTS +.AS Tcl_PackageInitProc *safeInitProc +.AP Tcl_Interp *interp in +If not NULL, points to an interpreter into which the package has +already been loaded (i.e., the caller has already invoked the +appropriate initialization procedure). NULL means the package +has not yet been incorporated into any interpreter. +.AP "const char" *pkgName in +Name of the package; should be properly capitalized (first letter +upper-case, all others lower-case). +.AP Tcl_PackageInitProc *initProc in +Procedure to invoke to incorporate this package into a trusted +interpreter. +.AP Tcl_PackageInitProc *safeInitProc in +Procedure to call to incorporate this package into a safe interpreter +(one that will execute untrusted scripts). NULL means the package +cannot be used in safe interpreters. +.BE +.SH DESCRIPTION +.PP +This procedure may be invoked to announce that a package has been +linked statically with a Tcl application and, optionally, that it +has already been loaded into an interpreter. +Once \fBTcl_StaticPackage\fR has been invoked for a package, it +may be loaded into interpreters using the \fBload\fR command. +\fBTcl_StaticPackage\fR is normally invoked only by the \fBTcl_AppInit\fR +procedure for the application, not by packages for themselves +(\fBTcl_StaticPackage\fR should only be invoked for statically +loaded packages, and code in the package itself should not need +to know whether the package is dynamically or statically loaded). +.PP +When the \fBload\fR command is used later to load the package into +an interpreter, one of \fIinitProc\fR and \fIsafeInitProc\fR will +be invoked, depending on whether the target interpreter is safe +or not. +\fIinitProc\fR and \fIsafeInitProc\fR must both match the +following prototype: +.PP +.CS +typedef int \fBTcl_PackageInitProc\fR( + Tcl_Interp *\fIinterp\fR); +.CE +.PP +The \fIinterp\fR argument identifies the interpreter in which the package +is to be loaded. The initialization procedure must return \fBTCL_OK\fR or +\fBTCL_ERROR\fR to indicate whether or not it completed successfully; in +the event of an error it should set the interpreter's result to point to an +error message. The result or error from the initialization procedure will +be returned as the result of the \fBload\fR command that caused the +initialization procedure to be invoked. +.SH KEYWORDS +initialization procedure, package, static linking +.SH "SEE ALSO" +load(n), package(n), Tcl_PkgRequire(3) diff --git a/tcl8.6/doc/StdChannels.3 b/tcl8.6/doc/StdChannels.3 new file mode 100644 index 0000000..651ad7d --- /dev/null +++ b/tcl8.6/doc/StdChannels.3 @@ -0,0 +1,120 @@ +'\" +'\" Copyright (c) 2001 by ActiveState Corporation +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH "Standard Channels" 3 7.5 Tcl "Tcl Library Procedures" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +Tcl_StandardChannels \- How the Tcl library deals with the standard channels +.BE + +.SH DESCRIPTION +.PP +This page explains the initialization and use of standard channels in +the Tcl library. +.PP +The term \fIstandard channels\fR comes out of the Unix world and +refers to the three channels automatically opened by the OS for +each new application. They are \fBstdin\fR, \fBstdout\fR and +\fBstderr\fR. The first is the standard input an application can read +from, the other two refer to writable channels, one for regular +output and the other for error messages. +.PP +Tcl generalizes this concept in a cross-platform way and +exposes standard channels to the script level. +.SS "APPLICATION PROGRAMMING INTERFACES" +.PP +The public API procedures dealing directly with standard channels are +\fBTcl_GetStdChannel\fR and \fBTcl_SetStdChannel\fR. Additional public +APIs to consider are \fBTcl_RegisterChannel\fR, +\fBTcl_CreateChannel\fR and \fBTcl_GetChannel\fR. +.SH "INITIALIZATION OF TCL STANDARD CHANNELS" +.PP +Standard channels are initialized by the Tcl library in three cases: +when explicitly requested, when implicitly required before returning +channel information, or when implicitly required during registration +of a new channel. +.PP +These cases differ in how they handle unavailable platform- specific +standard channels. (A channel is not +.QW available +if it could not be +successfully opened; for example, in a Tcl application run as a +Windows NT service.) +.TP +1) +A single standard channel is initialized when it is explicitly +specified in a call to \fBTcl_SetStdChannel\fR. The states of the +other standard channels are unaffected. +.RS +.PP +Missing platform-specific standard channels do not matter here. This +approach is not available at the script level. +.RE +.TP +2) +All uninitialized standard channels are initialized to +platform-specific default values: +.RS +.TP +(a) +when open channels are listed with \fBTcl_GetChannelNames\fR (or the +\fBfile channels\fR script command), or +.TP +(b) +when information about any standard channel is requested with a call +to \fBTcl_GetStdChannel\fR, or with a call to \fBTcl_GetChannel\fR +which specifies one of the standard names (\fBstdin\fR, \fBstdout\fR +and \fBstderr\fR). +.PP +In case of missing platform-specific standard channels, the Tcl +standard channels are considered as initialized and then immediately +closed. This means that the first three Tcl channels then opened by +the application are designated as the Tcl standard channels. +.RE +.TP +3) +All uninitialized standard channels are initialized to +platform-specific default values when a user-requested channel is +registered with \fBTcl_RegisterChannel\fR. +.PP +In case of unavailable platform-specific standard channels the channel +whose creation caused the initialization of the Tcl standard channels +is made a normal channel. The next three Tcl channels opened by the +application are designated as the Tcl standard channels. In other +words, of the first four Tcl channels opened by the application the +second to fourth are designated as the Tcl standard channels. +.SH "RE-INITIALIZATION OF TCL STANDARD CHANNELS" +.PP +Once a Tcl standard channel is initialized through one of the methods +above, closing this Tcl standard channel will cause the next call to +\fBTcl_CreateChannel\fR to make the new channel the new standard +channel, too. If more than one Tcl standard channel was closed +\fBTcl_CreateChannel\fR will fill the empty slots in the order +\fBstdin\fR, \fBstdout\fR and \fBstderr\fR. +.PP +\fBTcl_CreateChannel\fR will not try to reinitialize an empty slot if +that slot was not initialized before. It is this behavior which +enables an application to employ method 1 of initialization, i.e. to +create and designate their own Tcl standard channels. +.SH "SHELL-SPECIFIC DETAILS" +.SS tclsh +.PP +The Tcl shell (or rather the function \fBTcl_Main\fR, which forms the +core of the shell's implementation) uses method 2 to initialize +the standard channels. +.SS wish +.PP +The windowing shell (or rather the function \fBTk_MainEx\fR, which +forms the core of the shell's implementation) uses method 1 to +initialize the standard channels (See \fBTk_InitConsoleChannels\fR) +on non-Unix platforms. On Unix platforms, \fBTk_MainEx\fR implicitly +uses method 2 to initialize the standard channels. +.SH "SEE ALSO" +Tcl_CreateChannel(3), Tcl_RegisterChannel(3), Tcl_GetChannel(3), Tcl_GetStdChannel(3), Tcl_SetStdChannel(3), Tk_InitConsoleChannels(3), tclsh(1), wish(1), Tcl_Main(3), Tk_MainEx(3) +.SH KEYWORDS +standard channels diff --git a/tcl8.6/doc/StrMatch.3 b/tcl8.6/doc/StrMatch.3 new file mode 100644 index 0000000..f9c2be3 --- /dev/null +++ b/tcl8.6/doc/StrMatch.3 @@ -0,0 +1,49 @@ +'\" +'\" Copyright (c) 1989-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. +'\" +.TH Tcl_StringMatch 3 8.5 Tcl "Tcl Library Procedures" +.so man.macros +.BS +.SH NAME +Tcl_StringMatch, Tcl_StringCaseMatch \- test whether a string matches a pattern +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +int +\fBTcl_StringMatch\fR(\fIstr\fR, \fIpattern\fR) +.sp +int +\fBTcl_StringCaseMatch\fR(\fIstr\fR, \fIpattern\fR, \fIflags\fR) +.SH ARGUMENTS +.AS "const char" *pattern +.AP "const char" *str in +String to test. +.AP "const char" *pattern in +Pattern to match against string. May contain special +characters from the set *?\e[]. +.AP int flags in +OR-ed combination of match flags, currently only \fBTCL_MATCH_NOCASE\fR. +0 specifies a case-sensitive search. +.BE + +.SH DESCRIPTION +.PP +This utility procedure determines whether a string matches +a given pattern. If it does, then \fBTcl_StringMatch\fR returns +1. Otherwise \fBTcl_StringMatch\fR returns 0. The algorithm +used for matching is the same algorithm used in the \fBstring match\fR +Tcl command and is similar to the algorithm used by the C-shell +for file name matching; see the Tcl manual entry for details. +.PP +In \fBTcl_StringCaseMatch\fR, the algorithm is +the same, but you have the option to make the matching case-insensitive. +If you choose this (by passing \fBTCL_MATCH_NOCASE\fR), then the string and +pattern are essentially matched in the lower case. + +.SH KEYWORDS +match, pattern, string diff --git a/tcl8.6/doc/StringObj.3 b/tcl8.6/doc/StringObj.3 new file mode 100644 index 0000000..7042cc8 --- /dev/null +++ b/tcl8.6/doc/StringObj.3 @@ -0,0 +1,387 @@ +'\" +'\" Copyright (c) 1994-1997 Sun Microsystems, Inc. +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH Tcl_StringObj 3 8.1 Tcl "Tcl Library Procedures" +.so man.macros +.BS +.SH NAME +Tcl_NewStringObj, Tcl_NewUnicodeObj, Tcl_SetStringObj, Tcl_SetUnicodeObj, Tcl_GetStringFromObj, Tcl_GetString, Tcl_GetUnicodeFromObj, Tcl_GetUnicode, Tcl_GetUniChar, Tcl_GetCharLength, Tcl_GetRange, Tcl_AppendToObj, Tcl_AppendUnicodeToObj, Tcl_AppendObjToObj, Tcl_AppendStringsToObj, Tcl_AppendStringsToObjVA, Tcl_AppendLimitedToObj, Tcl_Format, Tcl_AppendFormatToObj, Tcl_ObjPrintf, Tcl_AppendPrintfToObj, Tcl_SetObjLength, Tcl_AttemptSetObjLength, Tcl_ConcatObj \- manipulate Tcl values as strings +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +Tcl_Obj * +\fBTcl_NewStringObj\fR(\fIbytes, length\fR) +.sp +Tcl_Obj * +\fBTcl_NewUnicodeObj\fR(\fIunicode, numChars\fR) +.sp +void +\fBTcl_SetStringObj\fR(\fIobjPtr, bytes, length\fR) +.sp +void +\fBTcl_SetUnicodeObj\fR(\fIobjPtr, unicode, numChars\fR) +.sp +char * +\fBTcl_GetStringFromObj\fR(\fIobjPtr, lengthPtr\fR) +.sp +char * +\fBTcl_GetString\fR(\fIobjPtr\fR) +.sp +Tcl_UniChar * +\fBTcl_GetUnicodeFromObj\fR(\fIobjPtr, lengthPtr\fR) +.sp +Tcl_UniChar * +\fBTcl_GetUnicode\fR(\fIobjPtr\fR) +.sp +Tcl_UniChar +\fBTcl_GetUniChar\fR(\fIobjPtr, index\fR) +.sp +int +\fBTcl_GetCharLength\fR(\fIobjPtr\fR) +.sp +Tcl_Obj * +\fBTcl_GetRange\fR(\fIobjPtr, first, last\fR) +.sp +void +\fBTcl_AppendToObj\fR(\fIobjPtr, bytes, length\fR) +.sp +void +\fBTcl_AppendUnicodeToObj\fR(\fIobjPtr, unicode, numChars\fR) +.sp +void +\fBTcl_AppendObjToObj\fR(\fIobjPtr, appendObjPtr\fR) +.sp +void +\fBTcl_AppendStringsToObj\fR(\fIobjPtr, string, string, ... \fB(char *) NULL\fR) +.sp +void +\fBTcl_AppendStringsToObjVA\fR(\fIobjPtr, argList\fR) +.sp +void +\fBTcl_AppendLimitedToObj\fR(\fIobjPtr, bytes, length, limit, ellipsis\fR) +.sp +Tcl_Obj * +\fBTcl_Format\fR(\fIinterp, format, objc, objv\fR) +.sp +int +\fBTcl_AppendFormatToObj\fR(\fIinterp, objPtr, format, objc, objv\fR) +.sp +Tcl_Obj * +\fBTcl_ObjPrintf\fR(\fIformat, ...\fR) +.sp +void +\fBTcl_AppendPrintfToObj\fR(\fIobjPtr, format, ...\fR) +.sp +void +\fBTcl_SetObjLength\fR(\fIobjPtr, newLength\fR) +.sp +int +\fBTcl_AttemptSetObjLength\fR(\fIobjPtr, newLength\fR) +.sp +Tcl_Obj * +\fBTcl_ConcatObj\fR(\fIobjc, objv\fR) +.SH ARGUMENTS +.AS "const Tcl_UniChar" *appendObjPtr in/out +.AP "const char" *bytes in +Points to the first byte of an array of UTF-8-encoded bytes +used to set or append to a string value. +This byte array may contain embedded null characters +unless \fInumChars\fR is negative. (Applications needing null bytes +should represent them as the two-byte sequence \fI\e700\e600\fR, use +\fBTcl_ExternalToUtf\fR to convert, or \fBTcl_NewByteArrayObj\fR if +the string is a collection of uninterpreted bytes.) +.AP int length in +The number of bytes to copy from \fIbytes\fR when +initializing, setting, or appending to a string value. +If negative, all bytes up to the first null are used. +.AP "const Tcl_UniChar" *unicode in +Points to the first byte of an array of Unicode characters +used to set or append to a string value. +This byte array may contain embedded null characters +unless \fInumChars\fR is negative. +.AP int numChars in +The number of Unicode characters to copy from \fIunicode\fR when +initializing, setting, or appending to a string value. +If negative, all characters up to the first null character are used. +.AP int index in +The index of the Unicode character to return. +.AP int first in +The index of the first Unicode character in the Unicode range to be +returned as a new value. +.AP int last in +The index of the last Unicode character in the Unicode range to be +returned as a new value. +.AP Tcl_Obj *objPtr in/out +Points to a value to manipulate. +.AP Tcl_Obj *appendObjPtr in +The value to append to \fIobjPtr\fR in \fBTcl_AppendObjToObj\fR. +.AP int *lengthPtr out +If non-NULL, the location where \fBTcl_GetStringFromObj\fR will store +the length of a value's string representation. +.AP "const char" *string in +Null-terminated string value to append to \fIobjPtr\fR. +.AP va_list argList in +An argument list which must have been initialized using +\fBva_start\fR, and cleared using \fBva_end\fR. +.AP int limit in +Maximum number of bytes to be appended. +.AP "const char" *ellipsis in +Suffix to append when the limit leads to string truncation. +If NULL is passed then the suffix +.QW "..." +is used. +.AP "const char" *format in +Format control string including % conversion specifiers. +.AP int objc in +The number of elements to format or concatenate. +.AP Tcl_Obj *objv[] in +The array of values to format or concatenate. +.AP int newLength in +New length for the string value of \fIobjPtr\fR, not including the +final null character. +.BE +.SH DESCRIPTION +.PP +The procedures described in this manual entry allow Tcl values to +be manipulated as string values. They use the internal representation +of the value to store additional information to make the string +manipulations more efficient. In particular, they make a series of +append operations efficient by allocating extra storage space for the +string so that it does not have to be copied for each append. +Also, indexing and length computations are optimized because the +Unicode string representation is calculated and cached as needed. +When using the \fBTcl_Append*\fR family of functions where the +interpreter's result is the value being appended to, it is important +to call Tcl_ResetResult first to ensure you are not unintentionally +appending to existing data in the result value. +.PP +\fBTcl_NewStringObj\fR and \fBTcl_SetStringObj\fR create a new value +or modify an existing value to hold a copy of the string given by +\fIbytes\fR and \fIlength\fR. \fBTcl_NewUnicodeObj\fR and +\fBTcl_SetUnicodeObj\fR create a new value or modify an existing +value to hold a copy of the Unicode string given by \fIunicode\fR and +\fInumChars\fR. \fBTcl_NewStringObj\fR and \fBTcl_NewUnicodeObj\fR +return a pointer to a newly created value with reference count zero. +All four procedures set the value to hold a copy of the specified +string. \fBTcl_SetStringObj\fR and \fBTcl_SetUnicodeObj\fR free any +old string representation as well as any old internal representation +of the value. +.PP +\fBTcl_GetStringFromObj\fR and \fBTcl_GetString\fR return a value's +string representation. This is given by the returned byte pointer and +(for \fBTcl_GetStringFromObj\fR) length, which is stored in +\fIlengthPtr\fR if it is non-NULL. If the value's UTF string +representation is invalid (its byte pointer is NULL), the string +representation is regenerated from the value's internal +representation. The storage referenced by the returned byte pointer +is owned by the value manager. It is passed back as a writable +pointer so that extension author creating their own \fBTcl_ObjType\fR +will be able to modify the string representation within the +\fBTcl_UpdateStringProc\fR of their \fBTcl_ObjType\fR. Except for that +limited purpose, the pointer returned by \fBTcl_GetStringFromObj\fR +or \fBTcl_GetString\fR should be treated as read-only. It is +recommended that this pointer be assigned to a (const char *) variable. +Even in the limited situations where writing to this pointer is +acceptable, one should take care to respect the copy-on-write +semantics required by \fBTcl_Obj\fR's, with appropriate calls +to \fBTcl_IsShared\fR and \fBTcl_DuplicateObj\fR prior to any +in-place modification of the string representation. +The procedure \fBTcl_GetString\fR is used in the common case +where the caller does not need the length of the string +representation. +.PP +\fBTcl_GetUnicodeFromObj\fR and \fBTcl_GetUnicode\fR return a value's +value as a Unicode string. This is given by the returned pointer and +(for \fBTcl_GetUnicodeFromObj\fR) length, which is stored in +\fIlengthPtr\fR if it is non-NULL. The storage referenced by the returned +byte pointer is owned by the value manager and should not be modified by +the caller. The procedure \fBTcl_GetUnicode\fR is used in the common case +where the caller does not need the length of the unicode string +representation. +.PP +\fBTcl_GetUniChar\fR returns the \fIindex\fR'th character in the +value's Unicode representation. +.PP +\fBTcl_GetRange\fR returns a newly created value comprised of the +characters between \fIfirst\fR and \fIlast\fR (inclusive) in the +value's Unicode representation. If the value's Unicode +representation is invalid, the Unicode representation is regenerated +from the value's string representation. +.PP +\fBTcl_GetCharLength\fR returns the number of characters (as opposed +to bytes) in the string value. +.PP +\fBTcl_AppendToObj\fR appends the data given by \fIbytes\fR and +\fIlength\fR to the string representation of the value specified by +\fIobjPtr\fR. If the value has an invalid string representation, +then an attempt is made to convert \fIbytes\fR is to the Unicode +format. If the conversion is successful, then the converted form of +\fIbytes\fR is appended to the value's Unicode representation. +Otherwise, the value's Unicode representation is invalidated and +converted to the UTF format, and \fIbytes\fR is appended to the +value's new string representation. +.PP +\fBTcl_AppendUnicodeToObj\fR appends the Unicode string given by +\fIunicode\fR and \fInumChars\fR to the value specified by +\fIobjPtr\fR. If the value has an invalid Unicode representation, +then \fIunicode\fR is converted to the UTF format and appended to the +value's string representation. Appends are optimized to handle +repeated appends relatively efficiently (it over-allocates the string +or Unicode space to avoid repeated reallocations and copies of +value's string value). +.PP +\fBTcl_AppendObjToObj\fR is similar to \fBTcl_AppendToObj\fR, but it +appends the string or Unicode value (whichever exists and is best +suited to be appended to \fIobjPtr\fR) of \fIappendObjPtr\fR to +\fIobjPtr\fR. +.PP +\fBTcl_AppendStringsToObj\fR is similar to \fBTcl_AppendToObj\fR +except that it can be passed more than one value to append and +each value must be a null-terminated string (i.e. none of the +values may contain internal null characters). Any number of +\fIstring\fR arguments may be provided, but the last argument +must be a NULL pointer to indicate the end of the list. +.PP +\fBTcl_AppendStringsToObjVA\fR is the same as \fBTcl_AppendStringsToObj\fR +except that instead of taking a variable number of arguments it takes an +argument list. +.PP +\fBTcl_AppendLimitedToObj\fR is similar to \fBTcl_AppendToObj\fR +except that it imposes a limit on how many bytes are appended. +This can be handy when the string to be appended might be +very large, but the value being constructed should not be allowed to grow +without bound. A common usage is when constructing an error message, where the +end result should be kept short enough to be read. +Bytes from \fIbytes\fR are appended to \fIobjPtr\fR, but no more +than \fIlimit\fR bytes total are to be appended. If the limit prevents +all \fIlength\fR bytes that are available from being appended, then the +appending is done so that the last bytes appended are from the +string \fIellipsis\fR. This allows for an indication of the truncation +to be left in the string. +When \fIlength\fR is \fB-1\fR, all bytes up to the first zero byte are appended, +subject to the limit. When \fIellipsis\fR is NULL, the default +string \fB...\fR is used. When \fIellipsis\fR is non-NULL, it must point +to a zero-byte-terminated string in Tcl's internal UTF encoding. +The number of bytes appended can be less than the lesser +of \fIlength\fR and \fIlimit\fR when appending fewer +bytes is necessary to append only whole multi-byte characters. +.PP +\fBTcl_Format\fR is the C-level interface to the engine of the \fBformat\fR +command. The actual command procedure for \fBformat\fR is little more +than +.PP +.CS +\fBTcl_Format\fR(interp, \fBTcl_GetString\fR(objv[1]), objc-2, objv+2); +.CE +.PP +The \fIobjc\fR Tcl_Obj values in \fIobjv\fR are formatted into a string +according to the conversion specification in \fIformat\fR argument, following +the documentation for the \fBformat\fR command. The resulting formatted +string is converted to a new Tcl_Obj with refcount of zero and returned. +If some error happens during production of the formatted string, NULL is +returned, and an error message is recorded in \fIinterp\fR, if \fIinterp\fR +is non-NULL. +.PP +\fBTcl_AppendFormatToObj\fR is an appending alternative form +of \fBTcl_Format\fR with functionality equivalent to: +.PP +.CS +Tcl_Obj *newPtr = \fBTcl_Format\fR(interp, format, objc, objv); +if (newPtr == NULL) return TCL_ERROR; +\fBTcl_AppendObjToObj\fR(objPtr, newPtr); +\fBTcl_DecrRefCount\fR(newPtr); +return TCL_OK; +.CE +.PP +but with greater convenience and efficiency when the appending +functionality is needed. +.PP +\fBTcl_ObjPrintf\fR serves as a replacement for the common sequence +.PP +.CS +char buf[SOME_SUITABLE_LENGTH]; +sprintf(buf, format, ...); +\fBTcl_NewStringObj\fR(buf, -1); +.CE +.PP +but with greater convenience and no need to +determine \fBSOME_SUITABLE_LENGTH\fR. The formatting is done with the same +core formatting engine used by \fBTcl_Format\fR. This means the set of +supported conversion specifiers is that of the \fBformat\fR command and +not that of the \fBsprintf\fR routine where the two sets differ. When a +conversion specifier passed to \fBTcl_ObjPrintf\fR includes a precision, +the value is taken as a number of bytes, as \fBsprintf\fR does, and not +as a number of characters, as \fBformat\fR does. This is done on the +assumption that C code is more likely to know how many bytes it is +passing around than the number of encoded characters those bytes happen +to represent. The variable number of arguments passed in should be of +the types that would be suitable for passing to \fBsprintf\fR. Note in +this example usage, \fIx\fR is of type \fBint\fR. +.PP +.CS +int x = 5; +Tcl_Obj *objPtr = \fBTcl_ObjPrintf\fR("Value is %d", x); +.CE +.PP +If the value of \fIformat\fR contains internal inconsistencies or invalid +specifier formats, the formatted string result produced by +\fBTcl_ObjPrintf\fR will be an error message describing the error. +It is impossible however to provide runtime protection against +mismatches between the format and any subsequent arguments. +Compile-time protection may be provided by some compilers. +.PP +\fBTcl_AppendPrintfToObj\fR is an appending alternative form +of \fBTcl_ObjPrintf\fR with functionality equivalent to +.PP +.CS +Tcl_Obj *newPtr = \fBTcl_ObjPrintf\fR(format, ...); +\fBTcl_AppendObjToObj\fR(objPtr, newPtr); +\fBTcl_DecrRefCount\fR(newPtr); +.CE +.PP +but with greater convenience and efficiency when the appending +functionality is needed. +.PP +The \fBTcl_SetObjLength\fR procedure changes the length of the +string value of its \fIobjPtr\fR argument. If the \fInewLength\fR +argument is greater than the space allocated for the value's +string, then the string space is reallocated and the old value +is copied to the new space; the bytes between the old length of +the string and the new length may have arbitrary values. +If the \fInewLength\fR argument is less than the current length +of the value's string, with \fIobjPtr->length\fR is reduced without +reallocating the string space; the original allocated size for the +string is recorded in the value, so that the string length can be +enlarged in a subsequent call to \fBTcl_SetObjLength\fR without +reallocating storage. In all cases \fBTcl_SetObjLength\fR leaves +a null character at \fIobjPtr->bytes[newLength]\fR. +.PP +\fBTcl_AttemptSetObjLength\fR is identical in function to +\fBTcl_SetObjLength\fR except that if sufficient memory to satisfy the +request cannot be allocated, it does not cause the Tcl interpreter to +\fBpanic\fR. Thus, if \fInewLength\fR is greater than the space +allocated for the value's string, and there is not enough memory +available to satisfy the request, \fBTcl_AttemptSetObjLength\fR will take +no action and return 0 to indicate failure. If there is enough memory +to satisfy the request, \fBTcl_AttemptSetObjLength\fR behaves just like +\fBTcl_SetObjLength\fR and returns 1 to indicate success. +.PP +The \fBTcl_ConcatObj\fR function returns a new string value whose +value is the space-separated concatenation of the string +representations of all of the values in the \fIobjv\fR +array. \fBTcl_ConcatObj\fR eliminates leading and trailing white space +as it copies the string representations of the \fIobjv\fR array to the +result. If an element of the \fIobjv\fR array consists of nothing but +white space, then that value is ignored entirely. This white-space +removal was added to make the output of the \fBconcat\fR command +cleaner-looking. \fBTcl_ConcatObj\fR returns a pointer to a +newly-created value whose ref count is zero. +.SH "SEE ALSO" +Tcl_NewObj(3), Tcl_IncrRefCount(3), Tcl_DecrRefCount(3), format(n), sprintf(3) +.SH KEYWORDS +append, internal representation, value, value type, string value, +string type, string representation, concat, concatenate, unicode diff --git a/tcl8.6/doc/SubstObj.3 b/tcl8.6/doc/SubstObj.3 new file mode 100644 index 0000000..f582c5a --- /dev/null +++ b/tcl8.6/doc/SubstObj.3 @@ -0,0 +1,68 @@ +'\" +'\" Copyright (c) 2001 Donal K. Fellows +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH Tcl_SubstObj 3 8.4 Tcl "Tcl Library Procedures" +.so man.macros +.BS +.SH NAME +Tcl_SubstObj \- perform substitutions on Tcl values +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +Tcl_Obj * +\fBTcl_SubstObj\fR(\fIinterp, objPtr, flags\fR) +.SH ARGUMENTS +.AS Tcl_Interp **termPtr +.AP Tcl_Interp *interp in +Interpreter in which to execute Tcl scripts and lookup variables. If +an error occurs, the interpreter's result is modified to hold an error +message. +.AP Tcl_Obj *objPtr in +A Tcl value containing the string to perform substitutions on. +.AP int flags in +ORed combination of flag bits that specify which substitutions to +perform. The flags \fBTCL_SUBST_COMMANDS\fR, +\fBTCL_SUBST_VARIABLES\fR and \fBTCL_SUBST_BACKSLASHES\fR are +currently supported, and \fBTCL_SUBST_ALL\fR is provided as a +convenience for the common case where all substitutions are desired. +.BE +.SH DESCRIPTION +.PP +The \fBTcl_SubstObj\fR function is used to perform substitutions on +strings in the fashion of the \fBsubst\fR command. It gets the value +of the string contained in \fIobjPtr\fR and scans it, copying +characters and performing the chosen substitutions as it goes to an +output value which is returned as the result of the function. In the +event of an error occurring during the execution of a command or +variable substitution, the function returns NULL and an error message +is left in \fIinterp\fR's result. +.PP +Three kinds of substitutions are supported. When the +\fBTCL_SUBST_BACKSLASHES\fR bit is set in \fIflags\fR, sequences that +look like backslash substitutions for Tcl commands are replaced by +their corresponding character. +.PP +When the \fBTCL_SUBST_VARIABLES\fR bit is set in \fIflags\fR, +sequences that look like variable substitutions for Tcl commands are +replaced by the contents of the named variable. +.PP +When the \fBTCL_SUBST_COMMANDS\fR bit is set in \fIflags\fR, sequences +that look like command substitutions for Tcl commands are replaced by +the result of evaluating that script. Where an uncaught +.QW "continue exception" +occurs during the evaluation of a command substitution, an +empty string is substituted for the command. Where an uncaught +.QW "break exception" +occurs during the evaluation of a command substitution, the +result of the whole substitution on \fIobjPtr\fR will be truncated at +the point immediately before the start of the command substitution, +and no characters will be added to the result or substitutions +performed after that point. +.SH "SEE ALSO" +subst(n) +.SH KEYWORDS +backslash substitution, command substitution, variable substitution diff --git a/tcl8.6/doc/TCL_MEM_DEBUG.3 b/tcl8.6/doc/TCL_MEM_DEBUG.3 new file mode 100644 index 0000000..e3a6809 --- /dev/null +++ b/tcl8.6/doc/TCL_MEM_DEBUG.3 @@ -0,0 +1,80 @@ +'\" +'\" Copyright (c) 1992-1999 Karl Lehenbauer and Mark Diekhans. +'\" Copyright (c) 2000 by Scriptics Corporation. +'\" All rights reserved. +'\" +.TH TCL_MEM_DEBUG 3 8.1 Tcl "Tcl Library Procedures" +.so man.macros +.BS +.SH NAME +TCL_MEM_DEBUG \- Compile-time flag to enable Tcl memory debugging +.BE +.SH DESCRIPTION +When Tcl is compiled with \fBTCL_MEM_DEBUG\fR defined, a powerful set +of memory debugging aids is included in the compiled binary. This +includes C and Tcl functions which can aid with debugging +memory leaks, memory allocation overruns, and other memory related +errors. +.SH "ENABLING MEMORY DEBUGGING" +.PP +To enable memory debugging, Tcl should be recompiled from scratch with +\fBTCL_MEM_DEBUG\fR defined (e.g. by passing the +\fI\-\-enable\-symbols=mem\fR flag to the \fIconfigure\fR script when +building). This will also compile in a non-stub +version of \fBTcl_InitMemory\fR to add the \fBmemory\fR command to Tcl. +.PP +\fBTCL_MEM_DEBUG\fR must be either left defined for all modules or undefined +for all modules that are going to be linked together. If they are not, link +errors will occur, with either \fBTcl_DbCkfree\fR and \fBTcl_DbCkalloc\fR or +\fBTcl_Alloc\fR and \fBTcl_Free\fR being undefined. +.PP +Once memory debugging support has been compiled into Tcl, the C +functions \fBTcl_ValidateAllMemory\fR, and \fBTcl_DumpActiveMemory\fR, +and the Tcl \fBmemory\fR command can be used to validate and examine +memory usage. +.SH "GUARD ZONES" +.PP +When memory debugging is enabled, whenever a call to \fBckalloc\fR is +made, slightly more memory than requested is allocated so the memory +debugging code can keep track of the allocated memory, and eight-byte +.QW "guard zones" +are placed in front of and behind the space that will be +returned to the caller. (The sizes of the guard zones are defined by the +C #define \fBLOW_GUARD_SIZE\fR and #define \fBHIGH_GUARD_SIZE\fR +in the file \fIgeneric/tclCkalloc.c\fR \(em it can +be extended if you suspect large overwrite problems, at some cost in +performance.) A known pattern is written into the guard zones and, on +a call to \fBckfree\fR, the guard zones of the space being freed are +checked to see if either zone has been modified in any way. If one +has been, the guard bytes and their new contents are identified, and a +.QW "low guard failed" +or +.QW "high guard failed" +message is issued. The +.QW "guard failed" +message includes the address of the memory packet and +the file name and line number of the code that called \fBckfree\fR. +This allows you to detect the common sorts of one-off problems, where +not enough space was allocated to contain the data written, for +example. +.SH "DEBUGGING DIFFICULT MEMORY CORRUPTION PROBLEMS" +.PP +Normally, Tcl compiled with memory debugging enabled will make it easy +to isolate a corruption problem. Turning on memory validation with +the memory command can help isolate difficult problems. If you +suspect (or know) that corruption is occurring before the Tcl +interpreter comes up far enough for you to issue commands, you can set +\fBMEM_VALIDATE\fR define, recompile tclCkalloc.c and rebuild Tcl. +This will enable memory validation from the first call to +\fBckalloc\fR, again, at a large performance impact. +.PP +If you are desperate and validating memory on every call to +\fBckalloc\fR and \fBckfree\fR is not enough, you can explicitly call +\fBTcl_ValidateAllMemory\fR directly at any point. It takes a \fIchar +*\fR and an \fIint\fR which are normally the filename and line number +of the caller, but they can actually be anything you want. Remember +to remove the calls after you find the problem. +.SH "SEE ALSO" +ckalloc, memory, Tcl_ValidateAllMemory, Tcl_DumpActiveMemory +.SH KEYWORDS +memory, debug diff --git a/tcl8.6/doc/Tcl.n b/tcl8.6/doc/Tcl.n new file mode 100644 index 0000000..fc3b477 --- /dev/null +++ b/tcl8.6/doc/Tcl.n @@ -0,0 +1,275 @@ +'\" +'\" Copyright (c) 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. +'\" +.TH Tcl n "8.6" Tcl "Tcl Built-In Commands" +.so man.macros +.BS +.SH NAME +Tcl \- Tool Command Language +.SH SYNOPSIS +Summary of Tcl language syntax. +.BE +.SH DESCRIPTION +.PP +The following rules define the syntax and semantics of the Tcl language: +.IP "[1] \fBCommands.\fR" +A Tcl script is a string containing one or more commands. +Semi-colons and newlines are command separators unless quoted as +described below. +Close brackets are command terminators during command substitution +(see below) unless quoted. +.IP "[2] \fBEvaluation.\fR" +A command is evaluated in two steps. +First, the Tcl interpreter breaks the command into \fIwords\fR +and performs substitutions as described below. +These substitutions are performed in the same way for all +commands. +Secondly, the first word is used to locate a command procedure to +carry out the command, then all of the words of the command are +passed to the command procedure. +The command procedure is free to interpret each of its words +in any way it likes, such as an integer, variable name, list, +or Tcl script. +Different commands interpret their words differently. +.IP "[3] \fBWords.\fR" +Words of a command are separated by white space (except for +newlines, which are command separators). +.IP "[4] \fBDouble quotes.\fR" +If the first character of a word is double-quote +.PQ \N'34' +then the word is terminated by the next double-quote character. +If semi-colons, close brackets, or white space characters +(including newlines) appear between the quotes then they are treated +as ordinary characters and included in the word. +Command substitution, variable substitution, and backslash substitution +are performed on the characters between the quotes as described below. +The double-quotes are not retained as part of the word. +.IP "[5] \fBArgument expansion.\fR" +If a word starts with the string +.QW {*} +followed by a non-whitespace character, then the leading +.QW {*} +is removed and the rest of the word is parsed and substituted as any other +word. After substitution, the word is parsed as a list (without command or +variable substitutions; backslash substitutions are performed as is normal for +a list and individual internal words may be surrounded by either braces or +double-quote characters), and its words are added to the command being +substituted. For instance, +.QW "cmd a {*}{b [c]} d {*}{$e f {g h}}" +is equivalent to +.QW "cmd a b {[c]} d {$e} f {g h}" . +.IP "[6] \fBBraces.\fR" +If the first character of a word is an open brace +.PQ { +and rule [5] does not apply, then +the word is terminated by the matching close brace +.PQ } "" . +Braces nest within the word: for each additional open +brace there must be an additional close brace (however, +if an open brace or close brace within the word is +quoted with a backslash then it is not counted in locating the +matching close brace). +No substitutions are performed on the characters between the +braces except for backslash-newline substitutions described +below, nor do semi-colons, newlines, close brackets, +or white space receive any special interpretation. +The word will consist of exactly the characters between the +outer braces, not including the braces themselves. +.IP "[7] \fBCommand substitution.\fR" +If a word contains an open bracket +.PQ [ +then Tcl performs \fIcommand substitution\fR. +To do this it invokes the Tcl interpreter recursively to process +the characters following the open bracket as a Tcl script. +The script may contain any number of commands and must be terminated +by a close bracket +.PQ ] "" . +The result of the script (i.e. the result of its last command) is +substituted into the word in place of the brackets and all of the +characters between them. +There may be any number of command substitutions in a single word. +Command substitution is not performed on words enclosed in braces. +.IP "[8] \fBVariable substitution.\fR" +If a word contains a dollar-sign +.PQ $ +followed by one of the forms +described below, then Tcl performs \fIvariable +substitution\fR: the dollar-sign and the following characters are +replaced in the word by the value of a variable. +Variable substitution may take any of the following forms: +.RS +.TP 15 +\fB$\fIname\fR +. +\fIName\fR is the name of a scalar variable; the name is a sequence +of one or more characters that are a letter, digit, underscore, +or namespace separators (two or more colons). +Letters and digits are \fIonly\fR the standard ASCII ones (\fB0\fR\(en\fB9\fR, +\fBA\fR\(en\fBZ\fR and \fBa\fR\(en\fBz\fR). +.TP 15 +\fB$\fIname\fB(\fIindex\fB)\fR +. +\fIName\fR gives the name of an array variable and \fIindex\fR gives +the name of an element within that array. +\fIName\fR must contain only letters, digits, underscores, and +namespace separators, and may be an empty string. +Letters and digits are \fIonly\fR the standard ASCII ones (\fB0\fR\(en\fB9\fR, +\fBA\fR\(en\fBZ\fR and \fBa\fR\(en\fBz\fR). +Command substitutions, variable substitutions, and backslash +substitutions are performed on the characters of \fIindex\fR. +.TP 15 +\fB${\fIname\fB}\fR +. +\fIName\fR is the name of a scalar variable or array element. It may contain +any characters whatsoever except for close braces. It indicates an array +element if \fIname\fR is in the form +.QW \fIarrayName\fB(\fIindex\fB)\fR +where \fIarrayName\fR does not contain any open parenthesis characters, +.QW \fB(\fR , +or close brace characters, +.QW \fB}\fR , +and \fIindex\fR can be any sequence of characters except for close brace +characters. No further +substitutions are performed during the parsing of \fIname\fR. +.PP +There may be any number of variable substitutions in a single word. +Variable substitution is not performed on words enclosed in braces. +.PP +Note that variables may contain character sequences other than those listed +above, but in that case other mechanisms must be used to access them (e.g., +via the \fBset\fR command's single-argument form). +.RE +.IP "[9] \fBBackslash substitution.\fR" +If a backslash +.PQ \e +appears within a word then \fIbackslash substitution\fR occurs. +In all cases but those described below the backslash is dropped and +the following character is treated as an ordinary +character and included in the word. +This allows characters such as double quotes, close brackets, +and dollar signs to be included in words without triggering +special processing. +The following table lists the backslash sequences that are +handled specially, along with the value that replaces each sequence. +.RS +.TP 7 +\e\fBa\fR +Audible alert (bell) (Unicode U+000007). +.TP 7 +\e\fBb\fR +Backspace (Unicode U+000008). +.TP 7 +\e\fBf\fR +Form feed (Unicode U+00000C). +.TP 7 +\e\fBn\fR +Newline (Unicode U+00000A). +.TP 7 +\e\fBr\fR +Carriage-return (Unicode U+00000D). +.TP 7 +\e\fBt\fR +Tab (Unicode U+000009). +.TP 7 +\e\fBv\fR +Vertical tab (Unicode U+00000B). +.TP 7 +\e\fB<newline>\fIwhiteSpace\fR +. +A single space character replaces the backslash, newline, and all spaces +and tabs after the newline. This backslash sequence is unique in that it +is replaced in a separate pre-pass before the command is actually parsed. +This means that it will be replaced even when it occurs between braces, +and the resulting space will be treated as a word separator if it is not +in braces or quotes. +.TP 7 +\e\e +Backslash +.PQ \e "" . +.TP 7 +\e\fIooo\fR +. +The digits \fIooo\fR (one, two, or three of them) give a eight-bit octal +value for the Unicode character that will be inserted, in the range +\fI000\fR\(en\fI377\fR (i.e., the range U+000000\(enU+0000FF). +The parser will stop just before this range overflows, or when +the maximum of three digits is reached. The upper bits of the Unicode +character will be 0. +.TP 7 +\e\fBx\fIhh\fR +. +The hexadecimal digits \fIhh\fR (one or two of them) give an eight-bit +hexadecimal value for the Unicode character that will be inserted. The upper +bits of the Unicode character will be 0 (i.e., the character will be in the +range U+000000\(enU+0000FF). +.TP 7 +\e\fBu\fIhhhh\fR +. +The hexadecimal digits \fIhhhh\fR (one, two, three, or four of them) give a +sixteen-bit hexadecimal value for the Unicode character that will be +inserted. The upper bits of the Unicode character will be 0 (i.e., the +character will be in the range U+000000\(enU+00FFFF). +.TP 7 +\e\fBU\fIhhhhhhhh\fR +. +The hexadecimal digits \fIhhhhhhhh\fR (one up to eight of them) give a +twenty-one-bit hexadecimal value for the Unicode character that will be +inserted, in the range U+000000\(enU+10FFFF. The parser will stop just +before this range overflows, or when the maximum of eight digits +is reached. The upper bits of the Unicode character will be 0. +.RS +.PP +The range U+010000\(enU+10FFFD is reserved for the future. +.RE +.PP +Backslash substitution is not performed on words enclosed in braces, +except for backslash-newline as described above. +.RE +.IP "[10] \fBComments.\fR" +If a hash character +.PQ # +appears at a point where Tcl is +expecting the first character of the first word of a command, +then the hash character and the characters that follow it, up +through the next newline, are treated as a comment and ignored. +The comment character only has significance when it appears +at the beginning of a command. +.IP "[11] \fBOrder of substitution.\fR" +Each character is processed exactly once by the Tcl interpreter +as part of creating the words of a command. +For example, if variable substitution occurs then no further +substitutions are performed on the value of the variable; the +value is inserted into the word verbatim. +If command substitution occurs then the nested command is +processed entirely by the recursive call to the Tcl interpreter; +no substitutions are performed before making the recursive +call and no additional substitutions are performed on the result +of the nested script. +.RS +.PP +Substitutions take place from left to right, and each substitution is +evaluated completely before attempting to evaluate the next. Thus, a +sequence like +.PP +.CS +set y [set x 0][incr x][incr x] +.CE +.PP +will always set the variable \fIy\fR to the value, \fI012\fR. +.RE +.IP "[12] \fBSubstitution and word boundaries.\fR" +Substitutions do not affect the word boundaries of a command, +except for argument expansion as specified in rule [5]. +For example, during variable substitution the entire value of +the variable becomes part of a single word, even if the variable's +value contains spaces. +.SH KEYWORDS +backslash, command, comment, script, substitution, variable +'\" Local Variables: +'\" mode: nroff +'\" fill-column: 78 +'\" End: diff --git a/tcl8.6/doc/TclZlib.3 b/tcl8.6/doc/TclZlib.3 new file mode 100644 index 0000000..c6a6417 --- /dev/null +++ b/tcl8.6/doc/TclZlib.3 @@ -0,0 +1,276 @@ +'\" +'\" Copyright (c) 2008 Donal K. Fellows +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH TclZlib 3 8.6 Tcl "Tcl Library Procedures" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +Tcl_ZlibAdler32, Tcl_ZlibCRC32, Tcl_ZlibDeflate, Tcl_ZlibInflate, Tcl_ZlibStreamChecksum, Tcl_ZlibStreamClose, Tcl_ZlibStreamEof, Tcl_ZlibStreamGet, Tcl_ZlibStreamGetCommandName, Tcl_ZlibStreamInit, Tcl_ZlibStreamPut \- compression and decompression functions +.SH SYNOPSIS +.nf +#include <tcl.h> +.sp +int +\fBTcl_ZlibDeflate\fR(\fIinterp, format, dataObj, level, dictObj\fR) +.sp +int +\fBTcl_ZlibInflate\fR(\fIinterp, format, dataObj, dictObj\fR) +.sp +unsigned int +\fBTcl_ZlibCRC32\fR(\fIinitValue, bytes, length\fR) +.sp +unsigned int +\fBTcl_ZlibAdler32\fR(\fIinitValue, bytes, length\fR) +.sp +int +\fBTcl_ZlibStreamInit\fR(\fIinterp, mode, format, level, dictObj, zshandlePtr\fR) +.sp +Tcl_Obj * +\fBTcl_ZlibStreamGetCommandName\fR(\fIzshandle\fR) +.sp +int +\fBTcl_ZlibStreamEof\fR(\fIzshandle\fR) +.sp +int +\fBTcl_ZlibStreamClose\fR(\fIzshandle\fR) +.sp +int +\fBTcl_ZlibStreamReset\fR(\fIzshandle\fR) +.sp +int +\fBTcl_ZlibStreamChecksum\fR(\fIzshandle\fR) +.sp +int +\fBTcl_ZlibStreamPut\fR(\fIzshandle, dataObj, flush\fR) +.sp +int +\fBTcl_ZlibStreamGet\fR(\fIzshandle, dataObj, count\fR) +.sp +\fBTcl_ZlibStreamSetCompressionDictionary\fR(\fIzshandle, compDict\fR) +.fi +.SH ARGUMENTS +.AS Tcl_ZlibStream zshandle in +.AP Tcl_Interp *interp in +The interpreter to store resulting compressed or uncompressed data in. Also +where any error messages are written. For \fBTcl_ZlibStreamInit\fR, this can +be NULL to create a stream that is not bound to a command. +.AP int format in +What format of compressed data to work with. Must be one of +\fBTCL_ZLIB_FORMAT_ZLIB\fR for zlib-format data, \fBTCL_ZLIB_FORMAT_GZIP\fR +for gzip-format data, or \fBTCL_ZLIB_FORMAT_RAW\fR for raw compressed data. In +addition, for decompression only, \fBTCL_ZLIB_FORMAT_AUTO\fR may also be +chosen which can automatically detect whether the compressed data was in zlib +or gzip format. +.AP Tcl_Obj *dataObj in/out +A byte-array value containing the data to be compressed or decompressed, or +to which the data extracted from the stream is appended when passed to +\fBTcl_ZlibStreamGet\fR. +.AP int level in +What level of compression to use. Should be a number from 0 to 9 or one of the +following: \fBTCL_ZLIB_COMPRESS_NONE\fR for no compression, +\fBTCL_ZLIB_COMPRESS_FAST\fR for fast but inefficient compression, +\fBTCL_ZLIB_COMPRESS_BEST\fR for slow but maximal compression, or +\fBTCL_ZLIB_COMPRESS_DEFAULT\fR for the level recommended by the zlib library. +.AP Tcl_Obj *dictObj in/out +A dictionary that contains, or which will be updated to contain, a description +of the gzip header associated with the compressed data. Only useful when the +\fIformat\fR is \fBTCL_ZLIB_FORMAT_GZIP\fR or \fBTCL_ZLIB_FORMAT_AUTO\fR. If +a NULL is passed, a default header will be used on compression and the header +will be ignored (apart from integrity checks) on decompression. See the +section \fBGZIP OPTIONS DICTIONARY\fR for details about the contents of this +dictionary. +.AP "unsigned int" initValue in +The initial value for the checksum algorithm. +.AP "unsigned char" *bytes in +An array of bytes to run the checksum algorithm over, or NULL to get the +recommended initial value for the checksum algorithm. +.AP int length in +The number of bytes in the array. +.AP int mode in +What mode to operate the stream in. Should be either +\fBTCL_ZLIB_STREAM_DEFLATE\fR for a compressing stream or +\fBTCL_ZLIB_STREAM_INFLATE\fR for a decompressing stream. +.AP Tcl_ZlibStream *zshandlePtr out +A pointer to a variable in which to write the abstract token for the stream +upon successful creation. +.AP Tcl_ZlibStream zshandle in +The abstract token for the stream to operate on. +.AP int flush in +Whether and how to flush the stream after writing the data to it. Must be one +of: \fBTCL_ZLIB_NO_FLUSH\fR if no flushing is to be done, \fBTCL_ZLIB_FLUSH\fR +if the currently compressed data must be made available for access using +\fBTcl_ZlibStreamGet\fR, \fBTCL_ZLIB_FULLFLUSH\fR if the stream must be put +into a state where the decompressor can recover from on corruption, or +\fBTCL_ZLIB_FINALIZE\fR to ensure that the stream is finished and that any +trailer demanded by the format is written. +.AP int count in +The maximum number of bytes to get from the stream, or -1 to get all remaining +bytes from the stream's buffers. +.AP Tcl_Obj *compDict in +A byte array value that is the compression dictionary to use with the stream. +Note that this is \fInot a Tcl dictionary\fR, and it is recommended that this +only ever be used with streams that were created with their \fIformat\fR set +to \fBTCL_ZLIB_FORMAT_ZLIB\fR because the other formats have no mechanism to +indicate whether a compression dictionary was present other than to fail on +decompression. +.BE +.SH DESCRIPTION +These functions form the interface from the Tcl library to the Zlib +library by Jean-loup Gailly and Mark Adler. +.PP +\fBTcl_ZlibDeflate\fR and \fBTcl_ZlibInflate\fR respectively compress and +decompress the data contained in the \fIdataObj\fR argument, according to the +\fIformat\fR and, for compression, \fIlevel\fR arguments. The dictionary in +the \fIdictObj\fR parameter is used to convey additional header information +about the compressed data when the compression format supports it; currently, +the dictionary is only used when the \fIformat\fR parameter is +\fBTCL_ZLIB_FORMAT_GZIP\fR or \fBTCL_ZLIB_FORMAT_AUTO\fR. For details of the +contents of the dictionary, see the \fBGZIP OPTIONS DICTIONARY\fR section +below. Upon success, both functions leave the resulting compressed or +decompressed data in a byte-array value that is the Tcl interpreter's result; +the returned value is a standard Tcl result code. +.PP +\fBTcl_ZlibAdler32\fR and \fBTcl_ZlibCRC32\fR compute checksums on arrays of +bytes, returning the computed checksum. Checksums are computed incrementally, +allowing data to be processed one block at a time, but this requires the +caller to maintain the current checksum and pass it in as the \fIinitValue\fR +parameter; the initial value to use for this can be obtained by using NULL for +the \fIbytes\fR parameter instead of a pointer to the array of bytes to +compute the checksum over. Thus, typical usage in the single data block case +is like this: +.PP +.CS +checksum = \fBTcl_ZlibCRC32\fR(\fBTcl_ZlibCRC32\fR(0,NULL,0), data, length); +.CE +.PP +Note that the Adler-32 algorithm is not a real checksum, but instead is a +related type of hash that works best on longer data. +.SS "ZLIB STREAMS" +.PP +\fBTcl_ZlibStreamInit\fR creates a compressing or decompressing stream that is +linked to a Tcl command, according to its arguments, and provides an abstract +token for the stream and returns a normal Tcl result code; +\fBTcl_ZlibStreamGetCommandName\fR returns the name of that command given the +stream token, or NULL if the stream has no command. Streams are not designed +to be thread-safe; each stream should only ever be used from the thread that +created it. When working with gzip streams, a dictionary (fields as given in +the \fBGZIP OPTIONS DICTIONARY\fR section below) can be given via the +\fIdictObj\fR parameter that on compression allows control over the generated +headers, and on decompression allows discovery of the existing headers. Note +that the dictionary will be written to on decompression once sufficient data +has been read to have a complete header. This means that the dictionary must +be an unshared value in that case; a blank value created with +\fBTcl_NewObj\fR is suggested. +.PP +Once a stream has been constructed, \fBTcl_ZlibStreamPut\fR is used to add +data to the stream and \fBTcl_ZlibStreamGet\fR is used to retrieve data from +the stream after processing. Both return normal Tcl result codes and leave an +error message in the result of the interpreter that the stream is registered +with in the error case (if such a registration has been performed). With +\fBTcl_ZlibStreamPut\fR, the data buffer value passed to it should not be +modified afterwards. With \fBTcl_ZlibStreamGet\fR, the data buffer value +passed to it will have the data bytes appended to it. Internally to the +stream, data is kept compressed so as to minimize the cost of buffer space. +.PP +\fBTcl_ZlibStreamChecksum\fR returns the checksum computed over the +uncompressed data according to the format, and \fBTcl_ZlibStreamEof\fR returns +a boolean value indicating whether the end of the uncompressed data has been +reached. +.PP +\fBTcl_ZlibStreamSetCompressionDictionary\fR is used to control the +compression dictionary used with the stream, a compression dictionary being an +array of bytes (such as might be created with \fBTcl_NewByteArrayObj\fR) that +is used to initialize the compression engine rather than leaving it to create +it on the fly from the data being compressed. Setting a compression dictionary +allows for more efficient compression in the case where the start of the data +is highly regular, but it does require both the compressor and the +decompressor to agreee on the value to use. Compression dictionaries are only +fully supported for zlib-format data; on compression, they must be set before +any data is sent in with \fBTcl_ZlibStreamPut\fR, and on decompression they +should be set when \fBTcl_ZlibStreamGet\fR produces an \fBerror\fR with its +\fB\-errorcode\fR set to +.QW "\fBZLIB NEED_DICT\fI code\fR" ; +the \fIcode\fR will be the Adler-32 checksum (see \fBTcl_ZlibAdler32\fR) of +the compression dictionary sought. (Note that this is only true for +zlib-format streams; gzip streams ignore compression dictionaries as the +format specification doesn't permit them, and raw streams just produce a data +error if the compression dictionary is missing or incorrect.) +.PP +If you wish to clear a stream and reuse it for a new compression or +decompression action, \fBTcl_ZlibStreamReset\fR will do this and return a +normal Tcl result code to indicate whether it was successful; if the stream is +registered with an interpreter, an error message will be left in the +interpreter result when this function returns TCL_ERROR. +Finally, \fBTcl_ZlibStreamClose\fR will clean up the stream and delete the +associated command: using \fBTcl_DeleteCommand\fR on the stream's command is +equivalent (when such a command exists). +.SH "GZIP OPTIONS DICTIONARY" +.PP +The \fIdictObj\fR parameter to \fBTcl_ZlibDeflate\fR, \fBTcl_ZlibInflate\fR +and \fBTcl_ZlibStreamInit\fR is used to pass a dictionary of options about +that is used to describe the gzip header in the compressed data. When creating +compressed data, the dictionary is read and when unpacking compressed data the +dictionary is written (in which case the \fIdictObj\fR parameter must refer to +an unshared dictionary value). +.PP +The following fields in the dictionary value are understood. All other fields +are ignored. No field is required when creating a gzip-format stream. +.TP +\fBcomment\fR +. +This holds the comment field of the header, if present. If absent, no comment +was supplied (on decompression) or will be created (on compression). +.TP +\fBcrc\fR +. +A boolean value describing whether a CRC of the header is computed. Note that +the \fBgzip\fR program does \fInot\fR use or allow a CRC on the header. +.TP +\fBfilename\fR +. +The name of the file that held the uncompressed data. This should not contain +any directory separators, and should be sanitized before use on decompression +with \fBfile tail\fR. +.TP +\fBos\fR +. +The operating system type code field from the header (if not the +.QW unknown +value). See RFC 1952 for the meaning of these codes. On compression, if this +is absent then the field will be set to the +.QW unknown +value. +.TP +\fBsize\fR +. +The size of the uncompressed data. This is ignored on compression; the size +of the data compressed depends on how much data is supplied to the +compression engine. +.TP +\fBtime\fR +. +The time field from the header if non-zero, expected to be the time that the +file named by the \fBfilename\fR field was modified. Suitable for use with +\fBclock format\fR. On creation, the right value to use is that from +\fBclock seconds\fR or \fBfile mtime\fR. +.TP +\fBtype\fR +. +The type of the uncompressed data (either \fBbinary\fR or \fBtext\fR) if +known. +.SH "PORTABILITY NOTES" +These functions will fail gracefully if Tcl is not linked with the zlib +library. +.SH "SEE ALSO" +Tcl_NewByteArrayObj(3), zlib(n) +'\"Tcl_StackChannel(3) +.SH "KEYWORDS" +compress, decompress, deflate, gzip, inflate +'\" Local Variables: +'\" mode: nroff +'\" fill-column: 78 +'\" End: diff --git a/tcl8.6/doc/Tcl_Main.3 b/tcl8.6/doc/Tcl_Main.3 new file mode 100644 index 0000000..3ec33d1 --- /dev/null +++ b/tcl8.6/doc/Tcl_Main.3 @@ -0,0 +1,196 @@ +'\" +'\" Copyright (c) 1994 The Regents of the University of California. +'\" Copyright (c) 1994-1996 Sun Microsystems, Inc. +'\" Copyright (c) 2000 Ajuba Solutions. +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH Tcl_Main 3 8.4 Tcl "Tcl Library Procedures" +.so man.macros +.BS +.SH NAME +Tcl_Main, Tcl_SetStartupScript, Tcl_GetStartupScript, Tcl_SetMainLoop \- main program, startup script, and event loop definition for Tcl-based applications +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +\fBTcl_Main\fR(\fIargc, argv, appInitProc\fR) +.sp +\fBTcl_SetStartupScript\fR(\fIpath, encoding\fR) +.sp +Tcl_Obj * +\fBTcl_GetStartupScript\fR(\fIencodingPtr\fR) +.sp +\fBTcl_SetMainLoop\fR(\fImainLoopProc\fR) +.SH ARGUMENTS +.AS Tcl_MainLoopProc *mainLoopProc +.AP int argc in +Number of elements in \fIargv\fR. +.AP char *argv[] in +Array of strings containing command-line arguments. On Windows, when +using -DUNICODE, the parameter type changes to wchar_t *. +.AP Tcl_AppInitProc *appInitProc in +Address of an application-specific initialization procedure. +The value for this argument is usually \fBTcl_AppInit\fR. +.AP Tcl_Obj *path in +Name of file to use as startup script, or NULL. +.AP "const char" *encoding in +Encoding of file to use as startup script, or NULL. +.AP "const char" **encodingPtr out +If non-NULL, location to write a copy of the (const char *) +pointing to the encoding name. +.AP Tcl_MainLoopProc *mainLoopProc in +Address of an application-specific event loop procedure. +.BE +.SH DESCRIPTION +.PP +\fBTcl_Main\fR can serve as the main program for Tcl-based shell +applications. A +.QW "shell application" +is a program +like tclsh or wish that supports both interactive interpretation +of Tcl and evaluation of a script contained in a file given as +a command line argument. \fBTcl_Main\fR is offered as a convenience +to developers of shell applications, so they do not have to +reproduce all of the code for proper initialization of the Tcl +library and interactive shell operation. Other styles of embedding +Tcl in an application are not supported by \fBTcl_Main\fR. Those +must be achieved by calling lower level functions in the Tcl library +directly. +.PP +The \fBTcl_Main\fR function has been offered by the Tcl library +since release Tcl 7.4. In older releases of Tcl, the Tcl library +itself defined a function \fBmain\fR, but that lacks flexibility +of embedding style and having a function \fBmain\fR in a library +(particularly a shared library) causes problems on many systems. +Having \fBmain\fR in the Tcl library would also make it hard to use +Tcl in C++ programs, since C++ programs must have special C++ +\fBmain\fR functions. +.PP +Normally each shell application contains a small \fBmain\fR function +that does nothing but invoke \fBTcl_Main\fR. +\fBTcl_Main\fR then does all the work of creating and running a +\fBtclsh\fR-like application. +.PP +\fBTcl_Main\fR is not provided by the public interface of Tcl's +stub library. Programs that call \fBTcl_Main\fR must be linked +against the standard Tcl library. Extensions (stub-enabled or +not) are not intended to call \fBTcl_Main\fR. +.PP +\fBTcl_Main\fR is not thread-safe. It should only be called by +a single master thread of a multi-threaded application. This +restriction is not a problem with normal use described above. +.PP +\fBTcl_Main\fR and therefore all applications based upon it, like +\fBtclsh\fR, use \fBTcl_GetStdChannel\fR to initialize the standard +channels to their default values. See \fBTcl_StandardChannels\fR for +more information. +.PP +\fBTcl_Main\fR supports two modes of operation, depending on +whether the filename and encoding of a startup script has been +established. The routines \fBTcl_SetStartupScript\fR and +\fBTcl_GetStartupScript\fR are the tools for controlling this +configuration of \fBTcl_Main\fR. +.PP +\fBTcl_SetStartupScript\fR registers the value \fIpath\fR +as the name of the file for \fBTcl_Main\fR to evaluate as +its startup script. The value \fIencoding\fR is Tcl's name +for the encoding used to store the text in that file. A +value of \fBNULL\fR for \fIencoding\fR is a signal to use +the system encoding. A value of \fBNULL\fR for \fIpath\fR +erases any existing registration so that \fBTcl_Main\fR +will not evaluate any startup script. +.PP +\fBTcl_GetStartupScript\fR queries the registered file name +and encoding set by the most recent \fBTcl_SetStartupScript\fR +call in the same thread. The stored file name is returned, +and the stored encoding name is written to space pointed to +by \fIencodingPtr\fR, when that is not NULL. +.PP +The file name and encoding values managed by the routines +\fBTcl_SetStartupScript\fR and \fBTcl_GetStartupScript\fR +are stored per-thread. Although the storage and retrieval +functions of these routines work in any thread, only those +calls in the same master thread as \fBTcl_Main\fR can have +any influence on it. +.PP +The caller of \fBTcl_Main\fR may call \fBTcl_SetStartupScript\fR +first to establish its desired startup script. If \fBTcl_Main\fR +finds that no such startup script has been established, it consults +the first few arguments in \fIargv\fR. If they match +?\fB\-encoding \fIname\fR? \fIfileName\fR, +where \fIfileName\fR does not begin with the character \fI\-\fR, +then \fIfileName\fR is taken to be the name of a file containing +a \fIstartup script\fR, and \fIname\fR is taken to be the name +of the encoding of the contents of that file. \fBTcl_Main\fR +then calls \fBTcl_SetStartupScript\fR with these values. +.PP +\fBTcl_Main\fR then defines in its master interpreter +the Tcl variables \fIargc\fR, \fIargv\fR, \fIargv0\fR, and +\fItcl_interactive\fR, as described in the documentation for \fBtclsh\fR. +.PP +When it has finished its own initialization, but before it processes +commands, \fBTcl_Main\fR calls the procedure given by the +\fIappInitProc\fR argument. This procedure provides a +.QW hook +for the application to perform its own initialization of the interpreter +created by \fBTcl_Main\fR, such as defining application-specific +commands. The application initialization routine might also +call \fBTcl_SetStartupScript\fR to (re-)set the file and encoding +to be used as a startup script. The procedure must have an interface +that matches the type \fBTcl_AppInitProc\fR: +.PP +.CS +typedef int \fBTcl_AppInitProc\fR( + Tcl_Interp *\fIinterp\fR); +.CE +.PP +\fIAppInitProc\fR is almost always a pointer to \fBTcl_AppInit\fR; for more +details on this procedure, see the documentation for \fBTcl_AppInit\fR. +.PP +When the \fIappInitProc\fR is finished, \fBTcl_Main\fR calls +\fBTcl_GetStartupScript\fR to determine what startup script has +been requested, if any. If a startup script has been provided, +\fBTcl_Main\fR attempts to evaluate it. Otherwise, interactive +mode begins with examination of the variable \fItcl_rcFileName\fR +in the master interpreter. If that variable exists and holds the +name of a readable file, the contents of that file are evaluated +in the master interpreter. Then interactive operations begin, +with prompts and command evaluation results written to the standard +output channel, and commands read from the standard input channel +and then evaluated. The prompts written to the standard output +channel may be customized by defining the Tcl variables \fItcl_prompt1\fR +and \fItcl_prompt2\fR as described in the documentation for \fBtclsh\fR. +The prompts and command evaluation results are written to the standard +output channel only if the Tcl variable \fItcl_interactive\fR in the +master interpreter holds a non-zero integer value. +.PP +\fBTcl_SetMainLoop\fR allows setting an event loop procedure to be run. +This allows, for example, Tk to be dynamically loaded and set its event +loop. The event loop will run following the startup script. If you +are in interactive mode, setting the main loop procedure will cause the +prompt to become fileevent based and then the loop procedure is called. +When the loop procedure returns in interactive mode, interactive operation +will continue. +The main loop procedure must have an interface that matches the type +\fBTcl_MainLoopProc\fR: +.PP +.CS +typedef void \fBTcl_MainLoopProc\fR(void); +.CE +.PP +\fBTcl_Main\fR does not return. Normally a program based on +\fBTcl_Main\fR will terminate when the \fBexit\fR command is +evaluated. In interactive mode, if an EOF or channel error +is encountered on the standard input channel, then \fBTcl_Main\fR +itself will evaluate the \fBexit\fR command after the main loop +procedure (if any) returns. In non-interactive mode, after +\fBTcl_Main\fR evaluates the startup script, and the main loop +procedure (if any) returns, \fBTcl_Main\fR will also evaluate +the \fBexit\fR command. +.SH "SEE ALSO" +tclsh(1), Tcl_GetStdChannel(3), Tcl_StandardChannels(3), Tcl_AppInit(3), +exit(n), encoding(n) +.SH KEYWORDS +application-specific initialization, command-line arguments, main program diff --git a/tcl8.6/doc/Thread.3 b/tcl8.6/doc/Thread.3 new file mode 100644 index 0000000..5966a71 --- /dev/null +++ b/tcl8.6/doc/Thread.3 @@ -0,0 +1,242 @@ +'\" +'\" Copyright (c) 1999 Scriptics Corporation +'\" Copyright (c) 1998 Sun Microsystems, Inc. +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH Threads 3 "8.1" Tcl "Tcl Library Procedures" +.so man.macros +.BS +.SH NAME +Tcl_ConditionNotify, Tcl_ConditionWait, Tcl_ConditionFinalize, Tcl_GetThreadData, Tcl_MutexLock, Tcl_MutexUnlock, Tcl_MutexFinalize, Tcl_CreateThread, Tcl_JoinThread \- Tcl thread support +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +void +\fBTcl_ConditionNotify\fR(\fIcondPtr\fR) +.sp +void +\fBTcl_ConditionWait\fR(\fIcondPtr, mutexPtr, timePtr\fR) +.sp +void +\fBTcl_ConditionFinalize\fR(\fIcondPtr\fR) +.sp +Void * +\fBTcl_GetThreadData\fR(\fIkeyPtr, size\fR) +.sp +void +\fBTcl_MutexLock\fR(\fImutexPtr\fR) +.sp +void +\fBTcl_MutexUnlock\fR(\fImutexPtr\fR) +.sp +void +\fBTcl_MutexFinalize\fR(\fImutexPtr\fR) +.sp +int +\fBTcl_CreateThread\fR(\fIidPtr, proc, clientData, stackSize, flags\fR) +.sp +int +\fBTcl_JoinThread\fR(\fIid, result\fR) +.SH ARGUMENTS +.AS Tcl_CreateThreadProc proc out +.AP Tcl_Condition *condPtr in +A condition variable, which must be associated with a mutex lock. +.AP Tcl_Mutex *mutexPtr in +A mutex lock. +.AP "const Tcl_Time" *timePtr in +A time limit on the condition wait. NULL to wait forever. +Note that a polling value of 0 seconds does not make much sense. +.AP Tcl_ThreadDataKey *keyPtr in +This identifies a block of thread local storage. The key should be +static and process-wide, yet each thread will end up associating +a different block of storage with this key. +.AP int *size in +The size of the thread local storage block. This amount of data +is allocated and initialized to zero the first time each thread +calls \fBTcl_GetThreadData\fR. +.AP Tcl_ThreadId *idPtr out +The referred storage will contain the id of the newly created thread as +returned by the operating system. +.AP Tcl_ThreadId id in +Id of the thread waited upon. +.AP Tcl_ThreadCreateProc *proc in +This procedure will act as the \fBmain()\fR of the newly created +thread. The specified \fIclientData\fR will be its sole argument. +.AP ClientData clientData in +Arbitrary information. Passed as sole argument to the \fIproc\fR. +.AP int stackSize in +The size of the stack given to the new thread. +.AP int flags in +Bitmask containing flags allowing the caller to modify behavior of +the new thread. +.AP int *result out +The referred storage is used to place the exit code of the thread +waited upon into it. +.BE +.SH INTRODUCTION +Beginning with the 8.1 release, the Tcl core is thread safe, which +allows you to incorporate Tcl into multithreaded applications without +customizing the Tcl core. Starting with the 8.6 release, Tcl +multithreading support is on by default. To disable Tcl multithreading +support, you must include the \fB\-\|\-disable-threads\fR option to +\fBconfigure\fR when you configure and compile your Tcl core. +.PP +An important constraint of the Tcl threads implementation is that +\fIonly the thread that created a Tcl interpreter can use that +interpreter\fR. In other words, multiple threads can not access +the same Tcl interpreter. (However, a single thread can safely create +and use multiple interpreters.) +.SH DESCRIPTION +Tcl provides \fBTcl_CreateThread\fR for creating threads. The +caller can determine the size of the stack given to the new thread and +modify the behavior through the supplied \fIflags\fR. The value +\fBTCL_THREAD_STACK_DEFAULT\fR for the \fIstackSize\fR indicates that +the default size as specified by the operating system is to be used +for the new thread. As for the flags, currently only the values +\fBTCL_THREAD_NOFLAGS\fR and \fBTCL_THREAD_JOINABLE\fR are defined. The +first of them invokes the default behavior with no special settings. +Using the second value marks the new thread as \fIjoinable\fR. This +means that another thread can wait for the such marked thread to exit +and join it. +.PP +Restrictions: On some UNIX systems the pthread-library does not +contain the functionality to specify the stack size of a thread. The +specified value for the stack size is ignored on these systems. +Windows currently does not support joinable threads. This +flag value is therefore ignored on this platform. +.PP +Tcl provides the \fBTcl_ExitThread\fR and \fBTcl_FinalizeThread\fR functions +for terminating threads and invoking optional per-thread exit +handlers. See the \fBTcl_Exit\fR page for more information on these +procedures. +.PP +The \fBTcl_JoinThread\fR function is provided to allow threads to wait +upon the exit of another thread, which must have been marked as +joinable through usage of the \fBTCL_THREAD_JOINABLE\fR-flag during +its creation via \fBTcl_CreateThread\fR. +.PP +Trying to wait for the exit of a non-joinable thread or a thread which +is already waited upon will result in an error. Waiting for a joinable +thread which already exited is possible, the system will retain the +necessary information until after the call to \fBTcl_JoinThread\fR. +This means that not calling \fBTcl_JoinThread\fR for a joinable thread +will cause a memory leak. +.PP +The \fBTcl_GetThreadData\fR call returns a pointer to a block of +thread-private data. Its argument is a key that is shared by all threads +and a size for the block of storage. The storage is automatically +allocated and initialized to all zeros the first time each thread asks for it. +The storage is automatically deallocated by \fBTcl_FinalizeThread\fR. +.SS "SYNCHRONIZATION AND COMMUNICATION" +Tcl provides \fBTcl_ThreadQueueEvent\fR and \fBTcl_ThreadAlert\fR +for handling event queuing in multithreaded applications. See +the \fBNotifier\fR manual page for more information on these procedures. +.PP +A mutex is a lock that is used to serialize all threads through a piece +of code by calling \fBTcl_MutexLock\fR and \fBTcl_MutexUnlock\fR. +If one thread holds a mutex, any other thread calling \fBTcl_MutexLock\fR will +block until \fBTcl_MutexUnlock\fR is called. +A mutex can be destroyed after its use by calling \fBTcl_MutexFinalize\fR. +The result of locking a mutex twice from the same thread is undefined. +On some platforms it will result in a deadlock. +The \fBTcl_MutexLock\fR, \fBTcl_MutexUnlock\fR and \fBTcl_MutexFinalize\fR +procedures are defined as empty macros if not compiling with threads enabled. +For declaration of mutexes the \fBTCL_DECLARE_MUTEX\fR macro should be used. +This macro assures correct mutex handling even when the core is compiled +without threads enabled. +.PP +A condition variable is used as a signaling mechanism: +a thread can lock a mutex and then wait on a condition variable +with \fBTcl_ConditionWait\fR. This atomically releases the mutex lock +and blocks the waiting thread until another thread calls +\fBTcl_ConditionNotify\fR. The caller of \fBTcl_ConditionNotify\fR should +have the associated mutex held by previously calling \fBTcl_MutexLock\fR, +but this is not enforced. Notifying the +condition variable unblocks all threads waiting on the condition variable, +but they do not proceed until the mutex is released with \fBTcl_MutexUnlock\fR. +The implementation of \fBTcl_ConditionWait\fR automatically locks +the mutex before returning. +.PP +The caller of \fBTcl_ConditionWait\fR should be prepared for spurious +notifications by calling \fBTcl_ConditionWait\fR within a while loop +that tests some invariant. +.PP +A condition variable can be destroyed after its use by calling +\fBTcl_ConditionFinalize\fR. +.PP +The \fBTcl_ConditionNotify\fR, \fBTcl_ConditionWait\fR and +\fBTcl_ConditionFinalize\fR procedures are defined as empty macros if +not compiling with threads enabled. +.SS INITIALIZATION +.PP +All of these synchronization objects are self-initializing. +They are implemented as opaque pointers that should be NULL +upon first use. +The mutexes and condition variables are +either cleaned up by process exit handlers (if living that long) or +explicitly by calls to \fBTcl_MutexFinalize\fR or +\fBTcl_ConditionFinalize\fR. +Thread local storage is reclaimed during \fBTcl_FinalizeThread\fR. +.SH "SCRIPT-LEVEL ACCESS TO THREADS" +.PP +Tcl provides no built-in commands for scripts to use to create, +manage, or join threads, nor any script-level access to mutex or +condition variables. It provides such facilities only via C +interfaces, and leaves it up to packages to expose these matters to +the script level. One such package is the \fBThread\fR package. +.SH EXAMPLE +.PP +To create a thread with portable code, its implementation function should be +declared as follows: +.PP +.CS +static \fBTcl_ThreadCreateProc\fR MyThreadImplFunc; +.CE +.PP +It should then be defined like this example, which just counts up to a given +value and then finishes. +.PP +.CS +static \fBTcl_ThreadCreateType\fR +MyThreadImplFunc( + ClientData clientData) +{ + int i, limit = (int) clientData; + for (i=0 ; i<limit ; i++) { + /* doing nothing at all here */ + } + \fBTCL_THREAD_CREATE_RETURN\fR; +} +.CE +.PP +To create the above thread, make it execute, and wait for it to finish, we +would do this: +.PP +.CS +int limit = 1000000000; +ClientData limitData = (void*)((intptr_t) limit); +Tcl_ThreadId id; \fI/* holds identity of thread created */\fR +int result; + +if (\fBTcl_CreateThread\fR(&id, MyThreadImplFunc, limitData, + \fBTCL_THREAD_STACK_DEFAULT\fR, + \fBTCL_THREAD_JOINABLE\fR) != TCL_OK) { + \fI/* Thread did not create correctly */\fR + return; +} +\fI/* Do something else for a while here */\fR +if (\fBTcl_JoinThread\fR(id, &result) != TCL_OK) { + \fI/* Thread did not finish properly */\fR + return; +} +\fI/* All cleaned up nicely */\fR +.CE +.SH "SEE ALSO" +Tcl_GetCurrentThread(3), Tcl_ThreadQueueEvent(3), Tcl_ThreadAlert(3), +Tcl_ExitThread(3), Tcl_FinalizeThread(3), Tcl_CreateThreadExitHandler(3), +Tcl_DeleteThreadExitHandler(3), Thread +.SH KEYWORDS +thread, mutex, condition variable, thread local storage diff --git a/tcl8.6/doc/ToUpper.3 b/tcl8.6/doc/ToUpper.3 new file mode 100644 index 0000000..be614e7 --- /dev/null +++ b/tcl8.6/doc/ToUpper.3 @@ -0,0 +1,88 @@ +'\" +'\" Copyright (c) 1997 by Sun Microsystems, Inc. +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH Tcl_UtfToUpper 3 "8.1" Tcl "Tcl Library Procedures" +.so man.macros +.BS +.SH NAME +Tcl_UniCharToUpper, Tcl_UniCharToLower, Tcl_UniCharToTitle, Tcl_UtfToUpper, Tcl_UtfToLower, Tcl_UtfToTitle \- routines for manipulating the case of Unicode characters and UTF-8 strings +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +Tcl_UniChar +\fBTcl_UniCharToUpper\fR(\fIch\fR) +.sp +Tcl_UniChar +\fBTcl_UniCharToLower\fR(\fIch\fR) +.sp +Tcl_UniChar +\fBTcl_UniCharToTitle\fR(\fIch\fR) +.sp +int +\fBTcl_UtfToUpper\fR(\fIstr\fR) +.sp +int +\fBTcl_UtfToLower\fR(\fIstr\fR) +.sp +int +\fBTcl_UtfToTitle\fR(\fIstr\fR) +.SH ARGUMENTS +.AS char *str in/out +.AP int ch in +The Unicode character to be converted. +.AP char *str in/out +Pointer to UTF-8 string to be converted in place. +.BE + +.SH DESCRIPTION +.PP +The first three routines convert the case of individual Unicode characters: +.PP +If \fIch\fR represents a lower-case character, +\fBTcl_UniCharToUpper\fR returns the corresponding upper-case +character. If no upper-case character is defined, it returns the +character unchanged. +.PP +If \fIch\fR represents an upper-case character, +\fBTcl_UniCharToLower\fR returns the corresponding lower-case +character. If no lower-case character is defined, it returns the +character unchanged. +.PP +If \fIch\fR represents a lower-case character, +\fBTcl_UniCharToTitle\fR returns the corresponding title-case +character. If no title-case character is defined, it returns the +corresponding upper-case character. If no upper-case character is +defined, it returns the character unchanged. Title-case is defined +for a small number of characters that have a different appearance when +they are at the beginning of a capitalized word. +.PP +The next three routines convert the case of UTF-8 strings in place in +memory: +.PP +\fBTcl_UtfToUpper\fR changes every UTF-8 character in \fIstr\fR to +upper-case. Because changing the case of a character may change its +size, the byte offset of each character in the resulting string may +differ from its original location. \fBTcl_UtfToUpper\fR writes a null +byte at the end of the converted string. \fBTcl_UtfToUpper\fR returns +the new length of the string in bytes. This new length is guaranteed +to be no longer than the original string length. +.PP +\fBTcl_UtfToLower\fR is the same as \fBTcl_UtfToUpper\fR except it +turns each character in the string into its lower-case equivalent. +.PP +\fBTcl_UtfToTitle\fR is the same as \fBTcl_UtfToUpper\fR except it +turns the first character in the string into its title-case equivalent +and all following characters into their lower-case equivalents. + +.SH BUGS +.PP +At this time, the case conversions are only defined for the ISO8859-1 +characters. Unicode characters above 0x00ff are not modified by these +routines. + +.SH KEYWORDS +utf, unicode, toupper, tolower, totitle, case diff --git a/tcl8.6/doc/TraceCmd.3 b/tcl8.6/doc/TraceCmd.3 new file mode 100644 index 0000000..99914a6 --- /dev/null +++ b/tcl8.6/doc/TraceCmd.3 @@ -0,0 +1,150 @@ +'\" +'\" Copyright (c) 2002 Donal K. Fellows +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH Tcl_TraceCommand 3 7.4 Tcl "Tcl Library Procedures" +.so man.macros +.BS +.SH NAME +Tcl_CommandTraceInfo, Tcl_TraceCommand, Tcl_UntraceCommand \- monitor renames and deletes of a command +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +ClientData +\fBTcl_CommandTraceInfo(\fIinterp, cmdName, flags, proc, prevClientData\fB)\fR +.sp +int +\fBTcl_TraceCommand(\fIinterp, cmdName, flags, proc, clientData\fB)\fR +.sp +void +\fBTcl_UntraceCommand(\fIinterp, cmdName, flags, proc, clientData\fB)\fR +.SH ARGUMENTS +.AS Tcl_CommandTraceProc prevClientData +.AP Tcl_Interp *interp in +Interpreter containing the command. +.AP "const char" *cmdName in +Name of command. +.AP int flags in +OR'ed collection of the values \fBTCL_TRACE_RENAME\fR and +\fBTCL_TRACE_DELETE\fR. +.AP Tcl_CommandTraceProc *proc in +Procedure to call when specified operations occur to \fIcmdName\fR. +.AP ClientData clientData in +Arbitrary argument to pass to \fIproc\fR. +.AP ClientData prevClientData in +If non-NULL, gives last value returned by \fBTcl_CommandTraceInfo\fR, +so this call will return information about next trace. If NULL, this +call will return information about first trace. +.BE +.SH DESCRIPTION +.PP +\fBTcl_TraceCommand\fR allows a C procedure to monitor operations +performed on a Tcl command, so that the C procedure is invoked +whenever the command is renamed or deleted. If the trace is created +successfully then \fBTcl_TraceCommand\fR returns \fBTCL_OK\fR. If an error +occurred (e.g. \fIcmdName\fR specifies a non-existent command) then +\fBTCL_ERROR\fR is returned and an error message is left in the +interpreter's result. +.PP +The \fIflags\fR argument to \fBTcl_TraceCommand\fR indicates when the +trace procedure is to be invoked. It consists of an OR'ed combination +of any of the following values: +.TP +\fBTCL_TRACE_RENAME\fR +Invoke \fIproc\fR whenever the command is renamed. +.TP +\fBTCL_TRACE_DELETE\fR +Invoke \fIproc\fR when the command is deleted. +.PP +Whenever one of the specified operations occurs to the command, +\fIproc\fR will be invoked. It should have arguments and result that +match the type \fBTcl_CommandTraceProc\fR: +.PP +.CS +typedef void \fBTcl_CommandTraceProc\fR( + ClientData \fIclientData\fR, + Tcl_Interp *\fIinterp\fR, + const char *\fIoldName\fR, + const char *\fInewName\fR, + int \fIflags\fR); +.CE +.PP +The \fIclientData\fR and \fIinterp\fR parameters will have the same +values as those passed to \fBTcl_TraceCommand\fR when the trace was +created. \fIClientData\fR typically points to an application-specific +data structure that describes what to do when \fIproc\fR is invoked. +\fIOldName\fR gives the name of the command being renamed, and +\fInewName\fR gives the name that the command is being renamed to (or +NULL when the command is being deleted.) +\fIFlags\fR is an OR'ed combination of bits potentially providing +several pieces of information. One of the bits \fBTCL_TRACE_RENAME\fR and +\fBTCL_TRACE_DELETE\fR will be set in \fIflags\fR to indicate which +operation is being performed on the command. The bit +\fBTCL_TRACE_DESTROYED\fR will be set in \fIflags\fR if the trace is about +to be destroyed; this information may be useful to \fIproc\fR so that +it can clean up its own internal data structures (see the section +\fBTCL_TRACE_DESTROYED\fR below for more details). Because the +deletion of commands can take place as part of the deletion of the interp +that contains them, \fIproc\fR must be careful about checking what +the passed in \fIinterp\fR value can be called upon to do. +The routine \fBTcl_InterpDeleted\fR is an important tool for this. +When \fBTcl_InterpDeleted\fR returns 1, \fIproc\fR will not be able +to invoke any scripts in \fIinterp\fR. The function of \fIproc\fR +in that circumstance is limited to the cleanup of its own data structures. +.PP +\fBTcl_UntraceCommand\fR may be used to remove a trace. If the +command specified by \fIinterp\fR, \fIcmdName\fR, and \fIflags\fR has +a trace set with \fIflags\fR, \fIproc\fR, and \fIclientData\fR, then +the corresponding trace is removed. If no such trace exists, then the +call to \fBTcl_UntraceCommand\fR has no effect. The same bits are +valid for \fIflags\fR as for calls to \fBTcl_TraceCommand\fR. +.PP +\fBTcl_CommandTraceInfo\fR may be used to retrieve information about +traces set on a given command. +The return value from \fBTcl_CommandTraceInfo\fR is the \fIclientData\fR +associated with a particular trace. +The trace must be on the command specified by the \fIinterp\fR, +\fIcmdName\fR, and \fIflags\fR arguments (note that currently the +flags are ignored; \fIflags\fR should be set to 0 for future +compatibility) and its trace procedure must the same as the \fIproc\fR +argument. +If the \fIprevClientData\fR argument is NULL then the return +value corresponds to the first (most recently created) matching +trace, or NULL if there are no matching traces. +If the \fIprevClientData\fR argument is not NULL, then it should +be the return value from a previous call to \fBTcl_CommandTraceInfo\fR. +In this case, the new return value will correspond to the next +matching trace after the one whose \fIclientData\fR matches +\fIprevClientData\fR, or NULL if no trace matches \fIprevClientData\fR +or if there are no more matching traces after it. +This mechanism makes it possible to step through all of the +traces for a given command that have the same \fIproc\fR. +.SH "CALLING COMMANDS DURING TRACES" +.PP +During rename traces, the command being renamed is visible with both +names simultaneously, and the command still exists during delete +traces, unless the interp that contains it is being deleted. +However, there is no +mechanism for signaling that an error occurred in a trace procedure, +so great care should be taken that errors do not get silently lost. +.SH "MULTIPLE TRACES" +.PP +It is possible for multiple traces to exist on the same command. +When this happens, all of the trace procedures will be invoked on each +access, in order from most-recently-created to least-recently-created. +Attempts to delete the command during a delete trace will fail +silently, since the command is already scheduled for deletion anyway. +If the command being renamed is renamed by one of its rename traces, +that renaming takes precedence over the one that triggered the trace +and the collection of traces will not be reexecuted; if several traces +rename the command, the last renaming takes precedence. +.SH "TCL_TRACE_DESTROYED FLAG" +.PP +In a delete callback to \fIproc\fR, the \fBTCL_TRACE_DESTROYED\fR bit +is set in \fIflags\fR. +.\" Perhaps need some more comments here? - DKF +.SH KEYWORDS +clientData, trace, command diff --git a/tcl8.6/doc/TraceVar.3 b/tcl8.6/doc/TraceVar.3 new file mode 100644 index 0000000..19cb467 --- /dev/null +++ b/tcl8.6/doc/TraceVar.3 @@ -0,0 +1,380 @@ +'\" +'\" Copyright (c) 1989-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. +'\" +.TH Tcl_TraceVar 3 7.4 Tcl "Tcl Library Procedures" +.so man.macros +.BS +.SH NAME +Tcl_TraceVar, Tcl_TraceVar2, Tcl_UntraceVar, Tcl_UntraceVar2, Tcl_VarTraceInfo, Tcl_VarTraceInfo2 \- monitor accesses to a variable +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +int +\fBTcl_TraceVar(\fIinterp, varName, flags, proc, clientData\fB)\fR +.sp +int +\fBTcl_TraceVar2(\fIinterp, name1, name2, flags, proc, clientData\fB)\fR +.sp +\fBTcl_UntraceVar(\fIinterp, varName, flags, proc, clientData\fB)\fR +.sp +\fBTcl_UntraceVar2(\fIinterp, name1, name2, flags, proc, clientData\fB)\fR +.sp +ClientData +\fBTcl_VarTraceInfo(\fIinterp, varName, flags, proc, prevClientData\fB)\fR +.sp +ClientData +\fBTcl_VarTraceInfo2(\fIinterp, name1, name2, flags, proc, prevClientData\fB)\fR +.SH ARGUMENTS +.AS Tcl_VarTraceProc prevClientData +.AP Tcl_Interp *interp in +Interpreter containing variable. +.AP "const char" *varName in +Name of variable. May refer to a scalar variable, to +an array variable with no index, or to an array variable +with a parenthesized index. +.AP int flags in +OR-ed combination of the values \fBTCL_TRACE_READS\fR, +\fBTCL_TRACE_WRITES\fR, \fBTCL_TRACE_UNSETS\fR, \fBTCL_TRACE_ARRAY\fR, +\fBTCL_GLOBAL_ONLY\fR, \fBTCL_NAMESPACE_ONLY\fR, +\fBTCL_TRACE_RESULT_DYNAMIC\fR and \fBTCL_TRACE_RESULT_OBJECT\fR. +Not all flags are used by all +procedures. See below for more information. +.AP Tcl_VarTraceProc *proc in +Procedure to invoke whenever one of the traced operations occurs. +.AP ClientData clientData in +Arbitrary one-word value to pass to \fIproc\fR. +.AP "const char" *name1 in +Name of scalar or array variable (without array index). +.AP "const char" *name2 in +For a trace on an element of an array, gives the index of the +element. For traces on scalar variables or on whole arrays, +is NULL. +.AP ClientData prevClientData in +If non-NULL, gives last value returned by \fBTcl_VarTraceInfo\fR or +\fBTcl_VarTraceInfo2\fR, so this call will return information about +next trace. If NULL, this call will return information about first +trace. +.BE +.SH DESCRIPTION +.PP +\fBTcl_TraceVar\fR allows a C procedure to monitor and control +access to a Tcl variable, so that the C procedure is invoked +whenever the variable is read or written or unset. +If the trace is created successfully then \fBTcl_TraceVar\fR returns +\fBTCL_OK\fR. If an error occurred (e.g. \fIvarName\fR specifies an element +of an array, but the actual variable is not an array) then \fBTCL_ERROR\fR +is returned and an error message is left in the interpreter's result. +.PP +The \fIflags\fR argument to \fBTcl_TraceVar\fR indicates when the +trace procedure is to be invoked and provides information +for setting up the trace. It consists of an OR-ed combination +of any of the following values: +.TP +\fBTCL_GLOBAL_ONLY\fR +Normally, the variable will be looked up at the current level of +procedure call; if this bit is set then the variable will be looked +up at global level, ignoring any active procedures. +.TP +\fBTCL_NAMESPACE_ONLY\fR +Normally, the variable will be looked up at the current level of +procedure call; if this bit is set then the variable will be looked +up in the current namespace, ignoring any active procedures. +.TP +\fBTCL_TRACE_READS\fR +Invoke \fIproc\fR whenever an attempt is made to read the variable. +.TP +\fBTCL_TRACE_WRITES\fR +Invoke \fIproc\fR whenever an attempt is made to modify the variable. +.TP +\fBTCL_TRACE_UNSETS\fR +Invoke \fIproc\fR whenever the variable is unset. +A variable may be unset either explicitly by an \fBunset\fR command, +or implicitly when a procedure returns (its local variables are +automatically unset) or when the interpreter is deleted (all +variables are automatically unset). +.TP +\fBTCL_TRACE_ARRAY\fR +Invoke \fIproc\fR whenever the array command is invoked. +This gives the trace procedure a chance to update the array before +array names or array get is called. Note that this is called +before an array set, but that will trigger write traces. +.TP +\fBTCL_TRACE_RESULT_DYNAMIC\fR +The result of invoking the \fIproc\fR is a dynamically allocated +string that will be released by the Tcl library via a call to +\fBckfree\fR. Must not be specified at the same time as +\fBTCL_TRACE_RESULT_OBJECT\fR. +.TP +\fBTCL_TRACE_RESULT_OBJECT\fR +The result of invoking the \fIproc\fR is a Tcl_Obj* (cast to a char*) +with a reference count of at least one. The ownership of that +reference will be transferred to the Tcl core for release (when the +core has finished with it) via a call to \fBTcl_DecrRefCount\fR. Must +not be specified at the same time as \fBTCL_TRACE_RESULT_DYNAMIC\fR. +.PP +Whenever one of the specified operations occurs on the variable, +\fIproc\fR will be invoked. +It should have arguments and result that match the type +\fBTcl_VarTraceProc\fR: +.PP +.CS +typedef char *\fBTcl_VarTraceProc\fR( + ClientData \fIclientData\fR, + Tcl_Interp *\fIinterp\fR, + char *\fIname1\fR, + char *\fIname2\fR, + int \fIflags\fR); +.CE +.PP +The \fIclientData\fR and \fIinterp\fR parameters will +have the same values as those passed to \fBTcl_TraceVar\fR when the +trace was created. +\fIClientData\fR typically points to an application-specific +data structure that describes what to do when \fIproc\fR +is invoked. +\fIName1\fR and \fIname2\fR give the name of the traced variable +in the normal two-part form (see the description of \fBTcl_TraceVar2\fR +below for details). +\fIFlags\fR is an OR-ed combination of bits providing several +pieces of information. +One of the bits \fBTCL_TRACE_READS\fR, \fBTCL_TRACE_WRITES\fR, +\fBTCL_TRACE_ARRAY\fR, or \fBTCL_TRACE_UNSETS\fR +will be set in \fIflags\fR to indicate which operation is being performed +on the variable. +The bit \fBTCL_GLOBAL_ONLY\fR will be set whenever the variable being +accessed is a global one not accessible from the current level of +procedure call: the trace procedure will need to pass this flag +back to variable-related procedures like \fBTcl_GetVar\fR if it +attempts to access the variable. +The bit \fBTCL_NAMESPACE_ONLY\fR will be set whenever the variable being +accessed is a namespace one not accessible from the current level of +procedure call: the trace procedure will need to pass this flag +back to variable-related procedures like \fBTcl_GetVar\fR if it +attempts to access the variable. +The bit \fBTCL_TRACE_DESTROYED\fR will be set in \fIflags\fR if the trace is +about to be destroyed; this information may be useful to \fIproc\fR +so that it can clean up its own internal data structures (see +the section \fBTCL_TRACE_DESTROYED\fR below for more details). +Lastly, the bit \fBTCL_INTERP_DESTROYED\fR will be set if the entire +interpreter is being destroyed. +When this bit is set, \fIproc\fR must be especially careful in +the things it does (see the section \fBTCL_INTERP_DESTROYED\fR below). +The trace procedure's return value should normally be NULL; see +\fBERROR RETURNS\fR below for information on other possibilities. +.PP +\fBTcl_UntraceVar\fR may be used to remove a trace. +If the variable specified by \fIinterp\fR, \fIvarName\fR, and \fIflags\fR +has a trace set with \fIflags\fR, \fIproc\fR, and +\fIclientData\fR, then the corresponding trace is removed. +If no such trace exists, then the call to \fBTcl_UntraceVar\fR +has no effect. +The same bits are valid for \fIflags\fR as for calls to \fBTcl_TraceVar\fR. +.PP +\fBTcl_VarTraceInfo\fR may be used to retrieve information about +traces set on a given variable. +The return value from \fBTcl_VarTraceInfo\fR is the \fIclientData\fR +associated with a particular trace. +The trace must be on the variable specified by the \fIinterp\fR, +\fIvarName\fR, and \fIflags\fR arguments (only the \fBTCL_GLOBAL_ONLY\fR and +\fBTCL_NAMESPACE_ONLY\fR bits from \fIflags\fR is used; other bits are +ignored) and its trace procedure must the same as the \fIproc\fR +argument. +If the \fIprevClientData\fR argument is NULL then the return +value corresponds to the first (most recently created) matching +trace, or NULL if there are no matching traces. +If the \fIprevClientData\fR argument is not NULL, then it should +be the return value from a previous call to \fBTcl_VarTraceInfo\fR. +In this case, the new return value will correspond to the next +matching trace after the one whose \fIclientData\fR matches +\fIprevClientData\fR, or NULL if no trace matches \fIprevClientData\fR +or if there are no more matching traces after it. +This mechanism makes it possible to step through all of the +traces for a given variable that have the same \fIproc\fR. +.SH "TWO-PART NAMES" +.PP +The procedures \fBTcl_TraceVar2\fR, \fBTcl_UntraceVar2\fR, and +\fBTcl_VarTraceInfo2\fR are identical to \fBTcl_TraceVar\fR, +\fBTcl_UntraceVar\fR, and \fBTcl_VarTraceInfo\fR, respectively, +except that the name of the variable consists of two parts. +\fIName1\fR gives the name of a scalar variable or array, +and \fIname2\fR gives the name of an element within an array. +When \fIname2\fR is NULL, +\fIname1\fR may contain both an array and an element name: +if the name contains an open parenthesis and ends with a +close parenthesis, then the value between the parentheses is +treated as an element name (which can have any string value) and +the characters before the first open +parenthesis are treated as the name of an array variable. +If \fIname2\fR is NULL and \fIname1\fR does not refer +to an array element it means that either the variable is +a scalar or the trace is to be set on the entire array rather +than an individual element (see WHOLE-ARRAY TRACES below for +more information). +.SH "ACCESSING VARIABLES DURING TRACES" +.PP +During read, write, and array traces, the +trace procedure can read, write, or unset the traced +variable using \fBTcl_GetVar2\fR, \fBTcl_SetVar2\fR, and +other procedures. +While \fIproc\fR is executing, traces are temporarily disabled +for the variable, so that calls to \fBTcl_GetVar2\fR and +\fBTcl_SetVar2\fR will not cause \fIproc\fR or other trace procedures +to be invoked again. +Disabling only occurs for the variable whose trace procedure +is active; accesses to other variables will still be traced. +However, if a variable is unset during a read or write trace then unset +traces will be invoked. +.PP +During unset traces the variable has already been completely +expunged. +It is possible for the trace procedure to read or write the +variable, but this will be a new version of the variable. +Traces are not disabled during unset traces as they are for +read and write traces, but existing traces have been removed +from the variable before any trace procedures are invoked. +If new traces are set by unset trace procedures, these traces +will be invoked on accesses to the variable by the trace +procedures. +.SH "CALLBACK TIMING" +.PP +When read tracing has been specified for a variable, the trace +procedure will be invoked whenever the variable's value is +read. This includes \fBset\fR Tcl commands, \fB$\fR-notation +in Tcl commands, and invocations of the \fBTcl_GetVar\fR +and \fBTcl_GetVar2\fR procedures. +\fIProc\fR is invoked just before the variable's value is +returned. +It may modify the value of the variable to affect what +is returned by the traced access. +If it unsets the variable then the access will return an error +just as if the variable never existed. +.PP +When write tracing has been specified for a variable, the +trace procedure will be invoked whenever the variable's value +is modified. This includes \fBset\fR commands, +commands that modify variables as side effects (such as +\fBcatch\fR and \fBscan\fR), and calls to the \fBTcl_SetVar\fR +and \fBTcl_SetVar2\fR procedures). +\fIProc\fR will be invoked after the variable's value has been +modified, but before the new value of the variable has been +returned. +It may modify the value of the variable to override the change +and to determine the value actually returned by the traced +access. +If it deletes the variable then the traced access will return +an empty string. +.PP +When array tracing has been specified, the trace procedure +will be invoked at the beginning of the array command implementation, +before any of the operations like get, set, or names have been invoked. +The trace procedure can modify the array elements with \fBTcl_SetVar\fR +and \fBTcl_SetVar2\fR. +.PP +When unset tracing has been specified, the trace procedure +will be invoked whenever the variable is destroyed. +The traces will be called after the variable has been +completely unset. +.SH "WHOLE-ARRAY TRACES" +.PP +If a call to \fBTcl_TraceVar\fR or \fBTcl_TraceVar2\fR specifies +the name of an array variable without an index into the array, +then the trace will be set on the array as a whole. +This means that \fIproc\fR will be invoked whenever any +element of the array is accessed in the ways specified by +\fIflags\fR. +When an array is unset, a whole-array trace will be invoked +just once, with \fIname1\fR equal to the name of the array +and \fIname2\fR NULL; it will not be invoked once for each +element. +.SH "MULTIPLE TRACES" +.PP +It is possible for multiple traces to exist on the same variable. +When this happens, all of the trace procedures will be invoked on each +access, in order from most-recently-created to least-recently-created. +When there exist whole-array traces for an array as well as +traces on individual elements, the whole-array traces are invoked +before the individual-element traces. +If a read or write trace unsets the variable then all of the unset +traces will be invoked but the remainder of the read and write traces +will be skipped. +.SH "ERROR RETURNS" +.PP +Under normal conditions trace procedures should return NULL, indicating +successful completion. +If \fIproc\fR returns a non-NULL value it signifies that an +error occurred. +The return value must be a pointer to a static character string +containing an error message, +unless (\fIexactly\fR one of) the \fBTCL_TRACE_RESULT_DYNAMIC\fR and +\fBTCL_TRACE_RESULT_OBJECT\fR flags is set, which specify that the result is +either a dynamic string (to be released with \fBckfree\fR) or a +Tcl_Obj* (cast to char* and to be released with +\fBTcl_DecrRefCount\fR) containing the error message. +If a trace procedure returns an error, no further traces are +invoked for the access and the traced access aborts with the +given message. +Trace procedures can use this facility to make variables +read-only, for example (but note that the value of the variable +will already have been modified before the trace procedure is +called, so the trace procedure will have to restore the correct +value). +.PP +The return value from \fIproc\fR is only used during read and +write tracing. +During unset traces, the return value is ignored and all relevant +trace procedures will always be invoked. +.SH "RESTRICTIONS" +.PP +A trace procedure can be called at any time, even when there +is a partially formed result in the interpreter's result area. If +the trace procedure does anything that could damage this result (such +as calling \fBTcl_Eval\fR) then it must save the original values of +the interpreter's \fBresult\fR and \fBfreeProc\fR fields and restore +them before it returns. +.SH "UNDEFINED VARIABLES" +.PP +It is legal to set a trace on an undefined variable. +The variable will still appear to be undefined until the +first time its value is set. +If an undefined variable is traced and then unset, the unset will fail +with an error +.PQ "no such variable" "" , +but the trace procedure will still be invoked. +.SH "TCL_TRACE_DESTROYED FLAG" +.PP +In an unset callback to \fIproc\fR, the \fBTCL_TRACE_DESTROYED\fR bit +is set in \fIflags\fR if the trace is being removed as part +of the deletion. +Traces on a variable are always removed whenever the variable +is deleted; the only time \fBTCL_TRACE_DESTROYED\fR is not set is for +a whole-array trace invoked when only a single element of an +array is unset. +.SH "TCL_INTERP_DESTROYED" +.PP +When an interpreter is destroyed, unset traces are called for +all of its variables. +The \fBTCL_INTERP_DESTROYED\fR bit will be set in the \fIflags\fR +argument passed to the trace procedures. +Trace procedures must be extremely careful in what they do if +the \fBTCL_INTERP_DESTROYED\fR bit is set. +It is not safe for the procedures to invoke any Tcl procedures +on the interpreter, since its state is partially deleted. +All that trace procedures should do under these circumstances is +to clean up and free their own internal data structures. +.SH BUGS +.PP +Tcl does not do any error checking to prevent trace procedures +from misusing the interpreter during traces with \fBTCL_INTERP_DESTROYED\fR +set. +.PP +Array traces are not yet integrated with the Tcl \fBinfo exists\fR command, +nor is there Tcl-level access to array traces. +.SH "SEE ALSO" +trace(n) +.SH KEYWORDS +clientData, trace, variable diff --git a/tcl8.6/doc/Translate.3 b/tcl8.6/doc/Translate.3 new file mode 100644 index 0000000..38831d3 --- /dev/null +++ b/tcl8.6/doc/Translate.3 @@ -0,0 +1,71 @@ +'\" +'\" Copyright (c) 1989-1993 The Regents of the University of California. +'\" Copyright (c) 1994-1998 Sun Microsystems, Inc. +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH Tcl_TranslateFileName 3 8.1 Tcl "Tcl Library Procedures" +.so man.macros +.BS +.SH NAME +Tcl_TranslateFileName \- convert file name to native form and replace tilde with home directory +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +char * +\fBTcl_TranslateFileName\fR(\fIinterp\fR, \fIname\fR, \fIbufferPtr\fR) +.SH ARGUMENTS +.AS Tcl_DString *bufferPtr in/out +.AP Tcl_Interp *interp in +Interpreter in which to report an error, if any. +.AP "const char" *name in +File name, which may start with a +.QW ~ . +.AP Tcl_DString *bufferPtr in/out +If needed, this dynamic string is used to store the new file name. +At the time of the call it should be uninitialized or free. The +caller must eventually call \fBTcl_DStringFree\fR to free up +anything stored here. +.BE +.SH DESCRIPTION +.PP +This utility procedure translates a file name to a platform-specific form +which, after being converted to the appropriate encoding, is suitable for +passing to the local operating system. In particular, it converts +network names into native form and does tilde substitution. +.PP +However, with the advent of the newer \fBTcl_FSGetNormalizedPath\fR and +\fBTcl_FSGetNativePath\fR, there is no longer any need to use this +procedure. In particular, \fBTcl_FSGetNativePath\fR performs all the +necessary translation and encoding conversion, is virtual-filesystem +aware, and caches the native result for faster repeated calls. +Finally \fBTcl_FSGetNativePath\fR does not require you to free anything +afterwards. +.PP +If +\fBTcl_TranslateFileName\fR has to do tilde substitution or translate +the name then it uses +the dynamic string at \fI*bufferPtr\fR to hold the new string it +generates. +After \fBTcl_TranslateFileName\fR returns a non-NULL result, the caller must +eventually invoke \fBTcl_DStringFree\fR to free any information +placed in \fI*bufferPtr\fR. The caller need not know whether or +not \fBTcl_TranslateFileName\fR actually used the string; \fBTcl_TranslateFileName\fR +initializes \fI*bufferPtr\fR even if it does not use it, so the call to +\fBTcl_DStringFree\fR will be safe in either case. +.PP +If an error occurs (e.g. because there was no user by the given +name) then NULL is returned and an error message will be left +in the interpreter's result. +When an error occurs, \fBTcl_TranslateFileName\fR +frees the dynamic string itself so that the caller need not call +\fBTcl_DStringFree\fR. +.PP +The caller is responsible for making sure that the interpreter's result +has its default empty value when \fBTcl_TranslateFileName\fR is invoked. +.SH "SEE ALSO" +filename(n) +.SH KEYWORDS +file name, home directory, tilde, translate, user diff --git a/tcl8.6/doc/UniCharIsAlpha.3 b/tcl8.6/doc/UniCharIsAlpha.3 new file mode 100644 index 0000000..5ba3fc9 --- /dev/null +++ b/tcl8.6/doc/UniCharIsAlpha.3 @@ -0,0 +1,88 @@ +'\" +'\" Copyright (c) 1997 Sun Microsystems, Inc. +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH Tcl_UniCharIsAlpha 3 "8.1" Tcl "Tcl Library Procedures" +.so man.macros +.BS +.SH NAME +Tcl_UniCharIsAlnum, Tcl_UniCharIsAlpha, Tcl_UniCharIsControl, Tcl_UniCharIsDigit, Tcl_UniCharIsGraph, Tcl_UniCharIsLower, Tcl_UniCharIsPrint, Tcl_UniCharIsPunct, Tcl_UniCharIsSpace, Tcl_UniCharIsUpper, Tcl_UniCharIsWordChar \- routines for classification of Tcl_UniChar characters +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +int +\fBTcl_UniCharIsAlnum\fR(\fIch\fR) +.sp +int +\fBTcl_UniCharIsAlpha\fR(\fIch\fR) +.sp +int +\fBTcl_UniCharIsControl\fR(\fIch\fR) +.sp +int +\fBTcl_UniCharIsDigit\fR(\fIch\fR) +.sp +int +\fBTcl_UniCharIsGraph\fR(\fIch\fR) +.sp +int +\fBTcl_UniCharIsLower\fR(\fIch\fR) +.sp +int +\fBTcl_UniCharIsPrint\fR(\fIch\fR) +.sp +int +\fBTcl_UniCharIsPunct\fR(\fIch\fR) +.sp +int +\fBTcl_UniCharIsSpace\fR(\fIch\fR) +.sp +int +\fBTcl_UniCharIsUpper\fR(\fIch\fR) +.sp +int +\fBTcl_UniCharIsWordChar\fR(\fIch\fR) +.SH ARGUMENTS +.AS int ch +.AP int ch in +The Tcl_UniChar to be examined. +.BE + +.SH DESCRIPTION +.PP +All of the routines described examine Unicode characters and return a +boolean value. A non-zero return value means that the character does +belong to the character class associated with the called routine. The +rest of this document just describes the character classes associated +with the various routines. + +.SH "CHARACTER CLASSES" +.PP +\fBTcl_UniCharIsAlnum\fR tests if the character is an alphanumeric Unicode character. +.PP +\fBTcl_UniCharIsAlpha\fR tests if the character is an alphabetic Unicode character. +.PP +\fBTcl_UniCharIsControl\fR tests if the character is a Unicode control character. +.PP +\fBTcl_UniCharIsDigit\fR tests if the character is a numeric Unicode character. +.PP +\fBTcl_UniCharIsGraph\fR tests if the character is any Unicode print character except space. +.PP +\fBTcl_UniCharIsLower\fR tests if the character is a lowercase Unicode character. +.PP +\fBTcl_UniCharIsPrint\fR tests if the character is a Unicode print character. +.PP +\fBTcl_UniCharIsPunct\fR tests if the character is a Unicode punctuation character. +.PP +\fBTcl_UniCharIsSpace\fR tests if the character is a whitespace Unicode character. +.PP +\fBTcl_UniCharIsUpper\fR tests if the character is an uppercase Unicode character. +.PP +\fBTcl_UniCharIsWordChar\fR tests if the character is alphanumeric or +a connector punctuation mark. + +.SH KEYWORDS +unicode, classification diff --git a/tcl8.6/doc/UpVar.3 b/tcl8.6/doc/UpVar.3 new file mode 100644 index 0000000..9e17ed5 --- /dev/null +++ b/tcl8.6/doc/UpVar.3 @@ -0,0 +1,74 @@ +'\" +'\" Copyright (c) 1994 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. +'\" +.TH Tcl_UpVar 3 7.4 Tcl "Tcl Library Procedures" +.so man.macros +.BS +.SH NAME +Tcl_UpVar, Tcl_UpVar2 \- link one variable to another +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +int +\fBTcl_UpVar(\fIinterp, frameName, sourceName, destName, flags\fB)\fR +.sp +int +\fBTcl_UpVar2(\fIinterp, frameName, name1, name2, destName, flags\fB)\fR +.SH ARGUMENTS +.AS "const char" *sourceName +.AP Tcl_Interp *interp in +Interpreter containing variables; also used for error reporting. +.AP "const char" *frameName in +Identifies the stack frame containing source variable. +May have any of the forms accepted by +the \fBupvar\fR command, such as \fB#0\fR or \fB1\fR. +.AP "const char" *sourceName in +Name of source variable, in the frame given by \fIframeName\fR. +May refer to a scalar variable or to an array variable with a +parenthesized index. +.AP "const char" *destName in +Name of destination variable, which is to be linked to source +variable so that references to \fIdestName\fR +refer to the other variable. Must not currently exist except as +an upvar-ed variable. +.AP int flags in +One of \fBTCL_GLOBAL_ONLY\fR, \fBTCL_NAMESPACE_ONLY\fR or 0; if non-zero, +then \fIdestName\fR is a global or namespace variable; otherwise it is +local to the current procedure (or current namespace if no procedure is +active). +.AP "const char" *name1 in +First part of source variable's name (scalar name, or name of array +without array index). +.AP "const char" *name2 in +If source variable is an element of an array, gives the index of the element. +For scalar source variables, is NULL. +.BE + +.SH DESCRIPTION +.PP +\fBTcl_UpVar\fR and \fBTcl_UpVar2\fR provide the same functionality +as the \fBupvar\fR command: they make a link from a source variable +to a destination variable, so that references to the destination are +passed transparently through to the source. +The name of the source variable may be specified either as a single +string such as \fBxyx\fR or \fBa(24)\fR (by calling \fBTcl_UpVar\fR) +or in two parts where the array name has been separated from the +element name (by calling \fBTcl_UpVar2\fR). +The destination variable name is specified in a single string; it +may not be an array element. +.PP +Both procedures return either \fBTCL_OK\fR or \fBTCL_ERROR\fR, and they +leave an error message in the interpreter's result if an error occurs. +.PP +As with the \fBupvar\fR command, the source variable need not exist; +if it does exist, unsetting it later does not destroy the link. The +destination variable may exist at the time of the call, but if so +it must exist as a linked variable. + +.SH KEYWORDS +linked variable, upvar, variable diff --git a/tcl8.6/doc/Utf.3 b/tcl8.6/doc/Utf.3 new file mode 100644 index 0000000..9d0c617 --- /dev/null +++ b/tcl8.6/doc/Utf.3 @@ -0,0 +1,259 @@ +'\" +'\" Copyright (c) 1997 Sun Microsystems, Inc. +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH Utf 3 "8.1" Tcl "Tcl Library Procedures" +.so man.macros +.BS +.SH NAME +Tcl_UniChar, Tcl_UniCharToUtf, Tcl_UtfToUniChar, Tcl_UniCharToUtfDString, Tcl_UtfToUniCharDString, Tcl_UniCharLen, Tcl_UniCharNcmp, Tcl_UniCharNcasecmp, Tcl_UniCharCaseMatch, Tcl_UtfNcmp, Tcl_UtfNcasecmp, Tcl_UtfCharComplete, Tcl_NumUtfChars, Tcl_UtfFindFirst, Tcl_UtfFindLast, Tcl_UtfNext, Tcl_UtfPrev, Tcl_UniCharAtIndex, Tcl_UtfAtIndex, Tcl_UtfBackslash \- routines for manipulating UTF-8 strings +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +typedef ... \fBTcl_UniChar\fR; +.sp +int +\fBTcl_UniCharToUtf\fR(\fIch, buf\fR) +.sp +int +\fBTcl_UtfToUniChar\fR(\fIsrc, chPtr\fR) +.sp +char * +\fBTcl_UniCharToUtfDString\fR(\fIuniStr, uniLength, dsPtr\fR) +.sp +Tcl_UniChar * +\fBTcl_UtfToUniCharDString\fR(\fIsrc, length, dsPtr\fR) +.sp +int +\fBTcl_UniCharLen\fR(\fIuniStr\fR) +.sp +int +\fBTcl_UniCharNcmp\fR(\fIucs, uct, numChars\fR) +.sp +int +\fBTcl_UniCharNcasecmp\fR(\fIucs, uct, numChars\fR) +.sp +int +\fBTcl_UniCharCaseMatch\fR(\fIuniStr, uniPattern, nocase\fR) +.sp +int +\fBTcl_UtfNcmp\fR(\fIcs, ct, numChars\fR) +.sp +int +\fBTcl_UtfNcasecmp\fR(\fIcs, ct, numChars\fR) +.sp +int +\fBTcl_UtfCharComplete\fR(\fIsrc, length\fR) +.sp +int +\fBTcl_NumUtfChars\fR(\fIsrc, length\fR) +.sp +const char * +\fBTcl_UtfFindFirst\fR(\fIsrc, ch\fR) +.sp +const char * +\fBTcl_UtfFindLast\fR(\fIsrc, ch\fR) +.sp +const char * +\fBTcl_UtfNext\fR(\fIsrc\fR) +.sp +const char * +\fBTcl_UtfPrev\fR(\fIsrc, start\fR) +.sp +Tcl_UniChar +\fBTcl_UniCharAtIndex\fR(\fIsrc, index\fR) +.sp +const char * +\fBTcl_UtfAtIndex\fR(\fIsrc, index\fR) +.sp +int +\fBTcl_UtfBackslash\fR(\fIsrc, readPtr, dst\fR) +.SH ARGUMENTS +.AS "const Tcl_UniChar" *uniPattern in/out +.AP char *buf out +Buffer in which the UTF-8 representation of the Tcl_UniChar is stored. At most +\fBTCL_UTF_MAX\fR bytes are stored in the buffer. +.AP int ch in +The Unicode character to be converted or examined. +.AP Tcl_UniChar *chPtr out +Filled with the Tcl_UniChar represented by the head of the UTF-8 string. +.AP "const char" *src in +Pointer to a UTF-8 string. +.AP "const char" *cs in +Pointer to a UTF-8 string. +.AP "const char" *ct in +Pointer to a UTF-8 string. +.AP "const Tcl_UniChar" *uniStr in +A null-terminated Unicode string. +.AP "const Tcl_UniChar" *ucs in +A null-terminated Unicode string. +.AP "const Tcl_UniChar" *uct in +A null-terminated Unicode string. +.AP "const Tcl_UniChar" *uniPattern in +A null-terminated Unicode string. +.AP int length in +The length of the UTF-8 string in bytes (not UTF-8 characters). If +negative, all bytes up to the first null byte are used. +.AP int uniLength in +The length of the Unicode string in characters. Must be greater than or +equal to 0. +.AP "Tcl_DString" *dsPtr in/out +A pointer to a previously initialized \fBTcl_DString\fR. +.AP "unsigned long" numChars in +The number of characters to compare. +.AP "const char" *start in +Pointer to the beginning of a UTF-8 string. +.AP int index in +The index of a character (not byte) in the UTF-8 string. +.AP int *readPtr out +If non-NULL, filled with the number of bytes in the backslash sequence, +including the backslash character. +.AP char *dst out +Buffer in which the bytes represented by the backslash sequence are stored. +At most \fBTCL_UTF_MAX\fR bytes are stored in the buffer. +.AP int nocase in +Specifies whether the match should be done case-sensitive (0) or +case-insensitive (1). +.BE + +.SH DESCRIPTION +.PP +These routines convert between UTF-8 strings and Tcl_UniChars. A +Tcl_UniChar is a Unicode character represented as an unsigned, fixed-size +quantity. A UTF-8 character is a Unicode character represented as +a varying-length sequence of up to \fBTCL_UTF_MAX\fR bytes. A multibyte UTF-8 +sequence consists of a lead byte followed by some number of trail bytes. +.PP +\fBTCL_UTF_MAX\fR is the maximum number of bytes that it takes to +represent one Unicode character in the UTF-8 representation. +.PP +\fBTcl_UniCharToUtf\fR stores the Tcl_UniChar \fIch\fR as a UTF-8 string +in starting at \fIbuf\fR. The return value is the number of bytes stored +in \fIbuf\fR. +.PP +\fBTcl_UtfToUniChar\fR reads one UTF-8 character starting at \fIsrc\fR +and stores it as a Tcl_UniChar in \fI*chPtr\fR. The return value is the +number of bytes read from \fIsrc\fR. The caller must ensure that the +source buffer is long enough such that this routine does not run off the +end and dereference non-existent or random memory; if the source buffer +is known to be null-terminated, this will not happen. If the input is +not in proper UTF-8 format, \fBTcl_UtfToUniChar\fR will store the first +byte of \fIsrc\fR in \fI*chPtr\fR as a Tcl_UniChar between 0x0000 and +0x00ff and return 1. +.PP +\fBTcl_UniCharToUtfDString\fR converts the given Unicode string +to UTF-8, storing the result in a previously initialized \fBTcl_DString\fR. +You must specify \fIuniLength\fR, the length of the given Unicode string. +The return value is a pointer to the UTF-8 representation of the +Unicode string. Storage for the return value is appended to the +end of the \fBTcl_DString\fR. +.PP +\fBTcl_UtfToUniCharDString\fR converts the given UTF-8 string to Unicode, +storing the result in the previously initialized \fBTcl_DString\fR. +In the argument \fIlength\fR, you may either specify the length of +the given UTF-8 string in bytes or +.QW \-1 , +in which case \fBTcl_UtfToUniCharDString\fR uses \fBstrlen\fR to +calculate the length. The return value is a pointer to the Unicode +representation of the UTF-8 string. Storage for the return value +is appended to the end of the \fBTcl_DString\fR. The Unicode string +is terminated with a Unicode null character. +.PP +\fBTcl_UniCharLen\fR corresponds to \fBstrlen\fR for Unicode +characters. It accepts a null-terminated Unicode string and returns +the number of Unicode characters (not bytes) in that string. +.PP +\fBTcl_UniCharNcmp\fR and \fBTcl_UniCharNcasecmp\fR correspond to +\fBstrncmp\fR and \fBstrncasecmp\fR, respectively, for Unicode characters. +They accept two null-terminated Unicode strings and the number of characters +to compare. Both strings are assumed to be at least \fInumChars\fR characters +long. \fBTcl_UniCharNcmp\fR compares the two strings character-by-character +according to the Unicode character ordering. It returns an integer greater +than, equal to, or less than 0 if the first string is greater than, equal +to, or less than the second string respectively. \fBTcl_UniCharNcasecmp\fR +is the Unicode case insensitive version. +.PP +\fBTcl_UniCharCaseMatch\fR is the Unicode equivalent to +\fBTcl_StringCaseMatch\fR. It accepts a null-terminated Unicode string, +a Unicode pattern, and a boolean value specifying whether the match should +be case sensitive and returns whether the string matches the pattern. +.PP +\fBTcl_UtfNcmp\fR corresponds to \fBstrncmp\fR for UTF-8 strings. It +accepts two null-terminated UTF-8 strings and the number of characters +to compare. (Both strings are assumed to be at least \fInumChars\fR +characters long.) \fBTcl_UtfNcmp\fR compares the two strings +character-by-character according to the Unicode character ordering. +It returns an integer greater than, equal to, or less than 0 if the +first string is greater than, equal to, or less than the second string +respectively. +.PP +\fBTcl_UtfNcasecmp\fR corresponds to \fBstrncasecmp\fR for UTF-8 +strings. It is similar to \fBTcl_UtfNcmp\fR except comparisons ignore +differences in case when comparing upper, lower or title case +characters. +.PP +\fBTcl_UtfCharComplete\fR returns 1 if the source UTF-8 string \fIsrc\fR +of \fIlength\fR bytes is long enough to be decoded by +\fBTcl_UtfToUniChar\fR, or 0 otherwise. This function does not guarantee +that the UTF-8 string is properly formed. This routine is used by +procedures that are operating on a byte at a time and need to know if a +full Tcl_UniChar has been seen. +.PP +\fBTcl_NumUtfChars\fR corresponds to \fBstrlen\fR for UTF-8 strings. It +returns the number of Tcl_UniChars that are represented by the UTF-8 string +\fIsrc\fR. The length of the source string is \fIlength\fR bytes. If the +length is negative, all bytes up to the first null byte are used. +.PP +\fBTcl_UtfFindFirst\fR corresponds to \fBstrchr\fR for UTF-8 strings. It +returns a pointer to the first occurrence of the Tcl_UniChar \fIch\fR +in the null-terminated UTF-8 string \fIsrc\fR. The null terminator is +considered part of the UTF-8 string. +.PP +\fBTcl_UtfFindLast\fR corresponds to \fBstrrchr\fR for UTF-8 strings. It +returns a pointer to the last occurrence of the Tcl_UniChar \fIch\fR +in the null-terminated UTF-8 string \fIsrc\fR. The null terminator is +considered part of the UTF-8 string. +.PP +Given \fIsrc\fR, a pointer to some location in a UTF-8 string, +\fBTcl_UtfNext\fR returns a pointer to the next UTF-8 character in the +string. The caller must not ask for the next character after the last +character in the string if the string is not terminated by a null +character. +.PP +Given \fIsrc\fR, a pointer to some location in a UTF-8 string (or to a +null byte immediately following such a string), \fBTcl_UtfPrev\fR +returns a pointer to the closest preceding byte that starts a UTF-8 +character. +This function will not back up to a position before \fIstart\fR, +the start of the UTF-8 string. If \fIsrc\fR was already at \fIstart\fR, the +return value will be \fIstart\fR. +.PP +\fBTcl_UniCharAtIndex\fR corresponds to a C string array dereference or the +Pascal Ord() function. It returns the Tcl_UniChar represented at the +specified character (not byte) \fIindex\fR in the UTF-8 string +\fIsrc\fR. The source string must contain at least \fIindex\fR +characters. Behavior is undefined if a negative \fIindex\fR is given. +.PP +\fBTcl_UtfAtIndex\fR returns a pointer to the specified character (not +byte) \fIindex\fR in the UTF-8 string \fIsrc\fR. The source string must +contain at least \fIindex\fR characters. This is equivalent to calling +\fBTcl_UtfNext\fR \fIindex\fR times. If a negative \fIindex\fR is given, +the return pointer points to the first character in the source string. +.PP +\fBTcl_UtfBackslash\fR is a utility procedure used by several of the Tcl +commands. It parses a backslash sequence and stores the properly formed +UTF-8 character represented by the backslash sequence in the output +buffer \fIdst\fR. At most \fBTCL_UTF_MAX\fR bytes are stored in the buffer. +\fBTcl_UtfBackslash\fR modifies \fI*readPtr\fR to contain the number +of bytes in the backslash sequence, including the backslash character. +The return value is the number of bytes stored in the output buffer. +.PP +See the \fBTcl\fR manual entry for information on the valid backslash +sequences. All of the sequences described in the Tcl manual entry are +supported by \fBTcl_UtfBackslash\fR. + +.SH KEYWORDS +utf, unicode, backslash diff --git a/tcl8.6/doc/WrongNumArgs.3 b/tcl8.6/doc/WrongNumArgs.3 new file mode 100644 index 0000000..93e2ebb --- /dev/null +++ b/tcl8.6/doc/WrongNumArgs.3 @@ -0,0 +1,79 @@ +'\" +'\" Copyright (c) 1994-1997 Sun Microsystems, Inc. +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH Tcl_WrongNumArgs 3 8.0 Tcl "Tcl Library Procedures" +.so man.macros +.BS +.SH NAME +Tcl_WrongNumArgs \- generate standard error message for wrong number of arguments +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +\fBTcl_WrongNumArgs\fR(\fIinterp, objc, objv, message\fR) +.SH ARGUMENTS +.AS "Tcl_Obj *const" *message +.AP Tcl_Interp interp in +Interpreter in which error will be reported: error message gets stored +in its result value. +.AP int objc in +Number of leading arguments from \fIobjv\fR to include in error +message. +.AP "Tcl_Obj *const" objv[] in +Arguments to command that had the wrong number of arguments. +.AP "const char" *message in +Additional error information to print after leading arguments +from \fIobjv\fR. This typically gives the acceptable syntax +of the command. This argument may be NULL. +.BE +.SH DESCRIPTION +.PP +\fBTcl_WrongNumArgs\fR is a utility procedure that is invoked by +command procedures when they discover that they have received the +wrong number of arguments. \fBTcl_WrongNumArgs\fR generates a +standard error message and stores it in the result value of +\fIinterp\fR. The message includes the \fIobjc\fR initial +elements of \fIobjv\fR plus \fImessage\fR. For example, if +\fIobjv\fR consists of the values \fBfoo\fR and \fBbar\fR, +\fIobjc\fR is 1, and \fImessage\fR is +.QW "\fBfileName count\fR" +then \fIinterp\fR's result value will be set to the following +string: +.PP +.CS +wrong # args: should be "foo fileName count" +.CE +.PP +If \fIobjc\fR is 2, the result will be set to the following string: +.PP +.CS +wrong # args: should be "foo bar fileName count" +.CE +.PP +\fIObjc\fR is usually 1, but may be 2 or more for commands like +\fBstring\fR and the Tk widget commands, which use the first argument +as a subcommand. +.PP +Some of the values in the \fIobjv\fR array may be abbreviations for +a subcommand. The command +\fBTcl_GetIndexFromObj\fR will convert the abbreviated string value +into an \fIindexObject\fR. If an error occurs in the parsing of the +subcommand we would like to use the full subcommand name rather than +the abbreviation. If the \fBTcl_WrongNumArgs\fR command finds any +\fIindexObjects\fR in the \fIobjv\fR array it will use the full subcommand +name in the error message instead of the abbreviated name that was +originally passed in. Using the above example, let us assume that +\fIbar\fR is actually an abbreviation for \fIbarfly\fR and the value +is now an \fIindexObject\fR because it was passed to +\fBTcl_GetIndexFromObj\fR. In this case the error message would be: +.PP +.CS +wrong # args: should be "foo barfly fileName count" +.CE +.SH "SEE ALSO" +Tcl_GetIndexFromObj(3) +.SH KEYWORDS +command, error message, wrong number of arguments diff --git a/tcl8.6/doc/after.n b/tcl8.6/doc/after.n new file mode 100644 index 0000000..3d0d2c4 --- /dev/null +++ b/tcl8.6/doc/after.n @@ -0,0 +1,151 @@ +'\" +'\" Copyright (c) 1990-1994 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. +'\" +.TH after n 7.5 Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +after \- Execute a command after a time delay +.SH SYNOPSIS +\fBafter \fIms\fR +.sp +\fBafter \fIms \fR?\fIscript script script ...\fR? +.sp +\fBafter cancel \fIid\fR +.sp +\fBafter cancel \fIscript script script ...\fR +.sp +\fBafter idle \fR?\fIscript script script ...\fR? +.sp +\fBafter info \fR?\fIid\fR? +.BE +.SH DESCRIPTION +.PP +This command is used to delay execution of the program or to execute +a command in background sometime in the future. It has several forms, +depending on the first argument to the command: +.TP +\fBafter \fIms\fR +. +\fIMs\fR must be an integer giving a time in milliseconds. +The command sleeps for \fIms\fR milliseconds and then returns. +While the command is sleeping the application does not respond to +events. +.TP +\fBafter \fIms \fR?\fIscript script script ...\fR? +. +In this form the command returns immediately, but it arranges +for a Tcl command to be executed \fIms\fR milliseconds later as an +event handler. +The command will be executed exactly once, at the given time. +The delayed command is formed by concatenating all the \fIscript\fR +arguments in the same fashion as the \fBconcat\fR command. +The command will be executed at global level (outside the context +of any Tcl procedure). +If an error occurs while executing the delayed command then +the background error will be reported by the command +registered with \fBinterp bgerror\fR. +The \fBafter\fR command returns an identifier that can be used +to cancel the delayed command using \fBafter cancel\fR. +.TP +\fBafter cancel \fIid\fR +. +Cancels the execution of a delayed command that +was previously scheduled. +\fIId\fR indicates which command should be canceled; it must have +been the return value from a previous \fBafter\fR command. +If the command given by \fIid\fR has already been executed then +the \fBafter cancel\fR command has no effect. +.TP +\fBafter cancel \fIscript script ...\fR +. +This command also cancels the execution of a delayed command. +The \fIscript\fR arguments are concatenated together with space +separators (just as in the \fBconcat\fR command). +If there is a pending command that matches the string, it is +canceled and will never be executed; if no such command is +currently pending then the \fBafter cancel\fR command has no effect. +.TP +\fBafter idle \fIscript \fR?\fIscript script ...\fR? +. +Concatenates the \fIscript\fR arguments together with space +separators (just as in the \fBconcat\fR command), and arranges +for the resulting script to be evaluated later as an idle callback. +The script will be run exactly once, the next time the event +loop is entered and there are no events to process. +The command returns an identifier that can be used +to cancel the delayed command using \fBafter cancel\fR. +If an error occurs while executing the script then the +background error will be reported by the command +registered with \fBinterp bgerror\fR. +.TP +\fBafter info \fR?\fIid\fR? +. +This command returns information about existing event handlers. +If no \fIid\fR argument is supplied, the command returns +a list of the identifiers for all existing +event handlers created by the \fBafter\fR command for this +interpreter. +If \fIid\fR is supplied, it specifies an existing handler; +\fIid\fR must have been the return value from some previous call +to \fBafter\fR and it must not have triggered yet or been canceled. +In this case the command returns a list with two elements. +The first element of the list is the script associated +with \fIid\fR, and the second element is either +\fBidle\fR or \fBtimer\fR to indicate what kind of event +handler it is. +.LP +The \fBafter \fIms\fR and \fBafter idle\fR forms of the command +assume that the application is event driven: the delayed commands +will not be executed unless the application enters the event loop. +In applications that are not normally event-driven, such as +\fBtclsh\fR, the event loop can be entered with the \fBvwait\fR +and \fBupdate\fR commands. +.SH "EXAMPLES" +This defines a command to make Tcl do nothing at all for \fIN\fR +seconds: +.PP +.CS +proc sleep {N} { + \fBafter\fR [expr {int($N * 1000)}] +} +.CE +.PP +This arranges for the command \fIwake_up\fR to be run in eight hours +(providing the event loop is active at that time): +.PP +.CS +\fBafter\fR [expr {1000 * 60 * 60 * 8}] wake_up +.CE +.PP +The following command can be used to do long-running calculations (as +represented here by \fI::my_calc::one_step\fR, which is assumed to +return a boolean indicating whether another step should be performed) +in a step-by-step fashion, though the calculation itself needs to be +arranged so it can work step-wise. This technique is extra careful to +ensure that the event loop is not starved by the rescheduling of +processing steps (arranging for the next step to be done using an +already-triggered timer event only when the event queue has been +drained) and is useful when you want to ensure that a Tk GUI remains +responsive during a slow task. +.PP +.CS +proc doOneStep {} { + if {[::my_calc::one_step]} { + \fBafter idle\fR [list \fBafter\fR 0 doOneStep] + } +} +doOneStep +.CE +.SH "SEE ALSO" +concat(n), interp(n), update(n), vwait(n) +.SH KEYWORDS +cancel, delay, idle callback, sleep, time +'\" Local Variables: +'\" mode: nroff +'\" End: diff --git a/tcl8.6/doc/append.n b/tcl8.6/doc/append.n new file mode 100644 index 0000000..e3bf224 --- /dev/null +++ b/tcl8.6/doc/append.n @@ -0,0 +1,49 @@ +'\" +'\" Copyright (c) 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. +'\" +.TH append n "" Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +append \- Append to variable +.SH SYNOPSIS +\fBappend \fIvarName \fR?\fIvalue value value ...\fR? +.BE +.SH DESCRIPTION +.PP +Append all of the \fIvalue\fR arguments to the current value +of variable \fIvarName\fR. If \fIvarName\fR does not exist, +it is given a value equal to the concatenation of all the +\fIvalue\fR arguments. +The result of this command is the new value stored in variable +\fIvarName\fR. +This command provides an efficient way to build up long +variables incrementally. +For example, +.QW "\fBappend a $b\fR" +is much more efficient than +.QW "\fBset a $a$b\fR" +if \fB$a\fR is long. +.SH EXAMPLE +Building a string of comma-separated numbers piecemeal using a loop. +.PP +.CS +set var 0 +for {set i 1} {$i<=10} {incr i} { + \fBappend\fR var "," $i +} +puts $var +# Prints 0,1,2,3,4,5,6,7,8,9,10 +.CE +.SH "SEE ALSO" +concat(n), lappend(n) +.SH KEYWORDS +append, variable +'\" Local Variables: +'\" mode: nroff +'\" End: diff --git a/tcl8.6/doc/apply.n b/tcl8.6/doc/apply.n new file mode 100644 index 0000000..aeb2227 --- /dev/null +++ b/tcl8.6/doc/apply.n @@ -0,0 +1,102 @@ +'\" +'\" Copyright (c) 2006 Miguel Sofer +'\" Copyright (c) 2006 Donal K. Fellows +'\" +.TH apply n "" Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +apply \- Apply an anonymous function +.SH SYNOPSIS +\fBapply \fIfunc\fR ?\fIarg1 arg2 ...\fR? +.BE +.SH DESCRIPTION +.PP +The command \fBapply\fR applies the function \fIfunc\fR to the arguments +\fIarg1 arg2 ...\fR and returns the result. +.PP +The function \fIfunc\fR is a two element list \fI{args body}\fR or a three +element list \fI{args body namespace}\fR (as if the +\fBlist\fR command had been used). +The first element \fIargs\fR specifies the formal arguments to +\fIfunc\fR. The specification of the formal arguments \fIargs\fR +is shared with the \fBproc\fR command, and is described in detail in the +corresponding manual page. +.PP +The contents of \fIbody\fR are executed by the Tcl interpreter +after the local variables corresponding to the formal arguments are given +the values of the actual parameters \fIarg1 arg2 ...\fR. +When \fIbody\fR is being executed, variable names normally refer to +local variables, which are created automatically when referenced and +deleted when \fBapply\fR returns. One local variable is automatically +created for each of the function's arguments. +Global variables can only be accessed by invoking +the \fBglobal\fR command or the \fBupvar\fR command. +Namespace variables can only be accessed by invoking +the \fBvariable\fR command or the \fBupvar\fR command. +.PP +The invocation of \fBapply\fR adds a call frame to Tcl's evaluation stack +(the stack of frames accessed via \fBuplevel\fR). The execution of \fIbody\fR +proceeds in this call frame, in the namespace given by \fInamespace\fR or +in the global namespace if none was specified. If given, \fInamespace\fR is +interpreted relative to the global namespace even if its name does not start +with +.QW :: . +.PP +The semantics of \fBapply\fR can also be described by: +.PP +.CS +proc apply {fun args} { + set len [llength $fun] + if {($len < 2) || ($len > 3)} { + error "can't interpret \e"$fun\e" as anonymous function" + } + lassign $fun argList body ns + set name ::$ns::[getGloballyUniqueName] + set body0 { + rename [lindex [info level 0] 0] {} + } + proc $name $argList ${body0}$body + set code [catch {uplevel 1 $name $args} res opt] + return -options $opt $res +} +.CE +.SH EXAMPLES +.PP +This shows how to make a simple general command that applies a transformation +to each element of a list. +.PP +.CS +proc map {lambda list} { + set result {} + foreach item $list { + lappend result [\fBapply\fR $lambda $item] + } + return $result +} +map {x {return [string length $x]:$x}} {a bb ccc dddd} + \fI\(-> 1:a 2:bb 3:ccc 4:dddd\fR +map {x {expr {$x**2 + 3*$x - 2}}} {-4 -3 -2 -1 0 1 2 3 4} + \fI\(-> 2 -2 -4 -4 -2 2 8 16 26\fR +.CE +.PP +The \fBapply\fR command is also useful for defining callbacks for use in the +\fBtrace\fR command: +.PP +.CS +set vbl "123abc" +trace add variable vbl write {\fBapply\fR {{v1 v2 op} { + upvar 1 $v1 v + puts "updated variable to \e"$v\e"" +}}} +set vbl 123 +set vbl abc +.CE +.SH "SEE ALSO" +proc(n), uplevel(n) +.SH KEYWORDS +anonymous function, argument, lambda, procedure, +'\" Local Variables: +'\" mode: nroff +'\" End: diff --git a/tcl8.6/doc/array.n b/tcl8.6/doc/array.n new file mode 100644 index 0000000..25ad0c6 --- /dev/null +++ b/tcl8.6/doc/array.n @@ -0,0 +1,187 @@ +'\" +'\" Copyright (c) 1993-1994 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. +'\" +.TH array n 8.3 Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +array \- Manipulate array variables +.SH SYNOPSIS +\fBarray \fIoption arrayName\fR ?\fIarg arg ...\fR? +.BE +.SH DESCRIPTION +.PP +This command performs one of several operations on the +variable given by \fIarrayName\fR. +Unless otherwise specified for individual commands below, +\fIarrayName\fR must be the name of an existing array variable. +The \fIoption\fR argument determines what action is carried +out by the command. +The legal \fIoptions\fR (which may be abbreviated) are: +.TP +\fBarray anymore \fIarrayName searchId\fR +Returns 1 if there are any more elements left to be processed +in an array search, 0 if all elements have already been +returned. +\fISearchId\fR indicates which search on \fIarrayName\fR to +check, and must have been the return value from a previous +invocation of \fBarray startsearch\fR. +This option is particularly useful if an array has an element +with an empty name, since the return value from +\fBarray nextelement\fR will not indicate whether the search +has been completed. +.TP +\fBarray donesearch \fIarrayName searchId\fR +This command terminates an array search and destroys all the +state associated with that search. \fISearchId\fR indicates +which search on \fIarrayName\fR to destroy, and must have +been the return value from a previous invocation of +\fBarray startsearch\fR. Returns an empty string. +.TP +\fBarray exists \fIarrayName\fR +Returns 1 if \fIarrayName\fR is an array variable, 0 if there +is no variable by that name or if it is a scalar variable. +.TP +\fBarray get \fIarrayName\fR ?\fIpattern\fR? +Returns a list containing pairs of elements. The first +element in each pair is the name of an element in \fIarrayName\fR +and the second element of each pair is the value of the +array element. The order of the pairs is undefined. +If \fIpattern\fR is not specified, then all of the elements of the +array are included in the result. +If \fIpattern\fR is specified, then only those elements whose names +match \fIpattern\fR (using the matching rules of +\fBstring match\fR) are included. +If \fIarrayName\fR is not the name of an array variable, or if +the array contains no elements, then an empty list is returned. +If traces on the array modify the list of elements, the elements +returned are those that exist both before and after the call to +\fBarray get\fR. +.TP +\fBarray names \fIarrayName\fR ?\fImode\fR? ?\fIpattern\fR? +Returns a list containing the names of all of the elements in +the array that match \fIpattern\fR. \fIMode\fR may be one of +\fB\-exact\fR, \fB\-glob\fR, or \fB\-regexp\fR. If specified, \fImode\fR +designates which matching rules to use to match \fIpattern\fR against +the names of the elements in the array. If not specified, \fImode\fR +defaults to \fB\-glob\fR. See the documentation for \fBstring match\fR +for information on glob style matching, and the documentation for +\fBregexp\fR for information on regexp matching. +If \fIpattern\fR is omitted then the command returns all of +the element names in the array. If there are no (matching) elements +in the array, or if \fIarrayName\fR is not the name of an array +variable, then an empty string is returned. +.TP +\fBarray nextelement \fIarrayName searchId\fR +Returns the name of the next element in \fIarrayName\fR, or +an empty string if all elements of \fIarrayName\fR have +already been returned in this search. The \fIsearchId\fR +argument identifies the search, and must have +been the return value of an \fBarray startsearch\fR command. +Warning: if elements are added to or deleted from the array, +then all searches are automatically terminated just as if +\fBarray donesearch\fR had been invoked; this will cause +\fBarray nextelement\fR operations to fail for those searches. +.TP +\fBarray set \fIarrayName list\fR +Sets the values of one or more elements in \fIarrayName\fR. +\fIlist\fR must have a form like that returned by \fBarray get\fR, +consisting of an even number of elements. +Each odd-numbered element in \fIlist\fR is treated as an element +name within \fIarrayName\fR, and the following element in \fIlist\fR +is used as a new value for that array element. +If the variable \fIarrayName\fR does not already exist +and \fIlist\fR is empty, +\fIarrayName\fR is created with an empty array value. +.TP +\fBarray size \fIarrayName\fR +Returns a decimal string giving the number of elements in the +array. +If \fIarrayName\fR is not the name of an array then 0 is returned. +.TP +\fBarray startsearch \fIarrayName\fR +This command initializes an element-by-element search through the +array given by \fIarrayName\fR, such that invocations of the +\fBarray nextelement\fR command will return the names of the +individual elements in the array. +When the search has been completed, the \fBarray donesearch\fR +command should be invoked. +The return value is a +search identifier that must be used in \fBarray nextelement\fR +and \fBarray donesearch\fR commands; it allows multiple +searches to be underway simultaneously for the same array. +It is currently more efficient and easier to use either the \fBarray +get\fR or \fBarray names\fR, together with \fBforeach\fR, to iterate +over all but very large arrays. See the examples below for how to do +this. +.TP +\fBarray statistics \fIarrayName\fR +Returns statistics about the distribution of data within the hashtable +that represents the array. This information includes the number of +entries in the table, the number of buckets, and the utilization of +the buckets. +.TP +\fBarray unset \fIarrayName\fR ?\fIpattern\fR? +Unsets all of the elements in the array that match \fIpattern\fR (using the +matching rules of \fBstring match\fR). If \fIarrayName\fR is not the name +of an array variable or there are no matching elements in the array, no +error will be raised. If \fIpattern\fR is omitted and \fIarrayName\fR is +an array variable, then the command unsets the entire array. +The command always returns an empty string. +.SH EXAMPLES +.CS +\fBarray set\fR colorcount { + red 1 + green 5 + blue 4 + white 9 +} + +foreach {color count} [\fBarray get\fR colorcount] { + puts "Color: $color Count: $count" +} + \fB\(->\fR Color: blue Count: 4 + Color: white Count: 9 + Color: green Count: 5 + Color: red Count: 1 + +foreach color [\fBarray names\fR colorcount] { + puts "Color: $color Count: $colorcount($color)" +} + \fB\(->\fR Color: blue Count: 4 + Color: white Count: 9 + Color: green Count: 5 + Color: red Count: 1 + +foreach color [lsort [\fBarray names\fR colorcount]] { + puts "Color: $color Count: $colorcount($color)" +} + \fB\(->\fR Color: blue Count: 4 + Color: green Count: 5 + Color: red Count: 1 + Color: white Count: 9 + +\fBarray statistics\fR colorcount + \fB\(->\fR 4 entries in table, 4 buckets + number of buckets with 0 entries: 1 + number of buckets with 1 entries: 2 + number of buckets with 2 entries: 1 + number of buckets with 3 entries: 0 + number of buckets with 4 entries: 0 + number of buckets with 5 entries: 0 + number of buckets with 6 entries: 0 + number of buckets with 7 entries: 0 + number of buckets with 8 entries: 0 + number of buckets with 9 entries: 0 + number of buckets with 10 or more entries: 0 + average search distance for entry: 1.2 +.CE +.SH "SEE ALSO" +list(n), string(n), variable(n), trace(n), foreach(n) +.SH KEYWORDS +array, element names, search diff --git a/tcl8.6/doc/bgerror.n b/tcl8.6/doc/bgerror.n new file mode 100644 index 0000000..3644b3d --- /dev/null +++ b/tcl8.6/doc/bgerror.n @@ -0,0 +1,93 @@ +'\" +'\" Copyright (c) 1990-1994 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. +'\" +.TH bgerror n 7.5 Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +bgerror \- Command invoked to process background errors +.SH SYNOPSIS +\fBbgerror \fImessage\fR +.BE +.SH DESCRIPTION +.PP +Release 8.5 of Tcl supports the \fBinterp bgerror\fR command, +which allows applications to register in an interpreter the command +that will handle background errors in that interpreter. In older +releases of Tcl, this level of control was not available, and applications +could control the handling of background errors only by creating +a command with the particular command name \fBbgerror\fR in the +global namespace of an interpreter. The following documentation +describes the interface requirements of the \fBbgerror\fR command +an application might define to retain compatibility with pre-8.5 +releases of Tcl. Applications intending to support only +Tcl releases 8.5 and later should simply make use of \fBinterp bgerror\fR. +.PP +The \fBbgerror\fR command does not exist as built-in part of Tcl. Instead, +individual applications or users can define a \fBbgerror\fR +command (e.g. as a Tcl procedure) if they wish to handle background +errors. +.PP +A background error is one that occurs in an event handler or some +other command that did not originate with the application. +For example, if an error occurs while executing a command specified +with the \fBafter\fR command, then it is a background error. +For a non-background error, the error can simply be returned up +through nested Tcl command evaluations until it reaches the top-level +code in the application; then the application can report the error +in whatever way it wishes. When a background error occurs, the +unwinding ends in the Tcl library and there is no obvious way for Tcl +to report the error. +.PP +When Tcl detects a background error, it saves information about the +error and invokes a handler command registered by \fBinterp bgerror\fR +later as an idle event handler. The default handler command in turn +calls the \fBbgerror\fR command . +Before invoking \fBbgerror\fR, Tcl restores the +\fBerrorInfo\fR and \fBerrorCode\fR variables to their values at the +time the error occurred, then it invokes \fBbgerror\fR with the error +message as its only argument. Tcl assumes that the application has +implemented the \fBbgerror\fR command, and that the command will +report the error in a way that makes sense for the application. Tcl +will ignore any result returned by the \fBbgerror\fR command as long +as no error is generated. +.PP +If another Tcl error occurs within the \fBbgerror\fR command (for +example, because no \fBbgerror\fR command has been defined) then Tcl +reports the error itself by writing a message to stderr. +.PP +If several background errors accumulate before \fBbgerror\fR is +invoked to process them, \fBbgerror\fR will be invoked once for each +error, in the order they occurred. However, if \fBbgerror\fR returns +with a break exception, then any remaining errors are skipped without +calling \fBbgerror\fR. +.PP +If you are writing code that will be used by others as part of a +package or other kind of library, consider avoiding \fBbgerror\fR. +The reason for this is that the application programmer may also want +to define a \fBbgerror\fR, or use other code that does and thus will +have trouble integrating your code. +.SH "EXAMPLE" +.PP +This \fBbgerror\fR procedure appends errors to a file, with a timestamp. +.PP +.CS +proc bgerror {message} { + set timestamp [clock format [clock seconds]] + set fl [open mylog.txt {WRONLY CREAT APPEND}] + puts $fl "$timestamp: bgerror in $::argv '$message'" + close $fl +} +.CE +.SH "SEE ALSO" +after(n), errorCode(n), errorInfo(n), interp(n) +.SH KEYWORDS +background error, reporting +'\" Local Variables: +'\" mode: nroff +'\" End: diff --git a/tcl8.6/doc/binary.n b/tcl8.6/doc/binary.n new file mode 100644 index 0000000..5f25d65 --- /dev/null +++ b/tcl8.6/doc/binary.n @@ -0,0 +1,908 @@ +'\" +'\" Copyright (c) 1997 by Sun Microsystems, Inc. +'\" Copyright (c) 2008 by Donal K. Fellows +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH binary n 8.0 Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +binary \- Insert and extract fields from binary strings +.SH SYNOPSIS +.VS 8.6 +\fBbinary decode \fIformat\fR ?\fI\-option value ...\fR? \fIdata\fR +.br +\fBbinary encode \fIformat\fR ?\fI\-option value ...\fR? \fIdata\fR +.br +.VE 8.6 +\fBbinary format \fIformatString \fR?\fIarg arg ...\fR? +.br +\fBbinary scan \fIstring formatString \fR?\fIvarName varName ...\fR? +.BE +.SH DESCRIPTION +.PP +This command provides facilities for manipulating binary data. The +subcommand \fBbinary format\fR creates a binary string from normal +Tcl values. For example, given the values 16 and 22, on a 32-bit +architecture, it might produce an 8-byte binary string consisting of +two 4-byte integers, one for each of the numbers. The subcommand +\fBbinary scan\fR, does the opposite: it extracts data +from a binary string and returns it as ordinary Tcl string values. +.VS 8.6 +The \fBbinary encode\fR and \fBbinary decode\fR subcommands convert +binary data to or from string encodings such as base64 (used in MIME +messages for example). +.VE 8.6 +.PP +Note that other operations on binary data, such as taking a subsequence of it, +getting its length, or reinterpreting it as a string in some encoding, are +done by other Tcl commands (respectively \fBstring range\fR, +\fBstring length\fR and \fBencoding convertfrom\fR in the example cases). A +binary string in Tcl is merely one where all the characters it contains are in +the range \eu0000\-\eu00FF. +.SH "BINARY ENCODE AND DECODE" +.VS 8.6 +.PP +When encoding binary data as a readable string, the starting binary data is +passed to the \fBbinary encode\fR command, together with the name of the +encoding to use and any encoding-specific options desired. Data which has been +encoded can be converted back to binary form using \fBbinary decode\fR. The +following formats and options are supported. +.TP +\fBbase64\fR +. +The \fBbase64\fR binary encoding is commonly used in mail messages and XML +documents, and uses mostly upper and lower case letters and digits. It has the +distinction of being able to be rewrapped arbitrarily without losing +information. +.RS +.PP +During encoding, the following options are supported: +.TP +\fB\-maxlen \fIlength\fR +. +Indicates that the output should be split into lines of no more than +\fIlength\fR characters. By default, lines are not split. +.TP +\fB\-wrapchar \fIcharacter\fR +. +Indicates that, when lines are split because of the \fB\-maxlen\fR option, +\fIcharacter\fR should be used to separate lines. By default, this is a +newline character, +.QW \en . +.PP +During decoding, the following options are supported: +.TP +\fB\-strict\fR +. +Instructs the decoder to throw an error if it encounters whitespace characters. Otherwise it ignores them. +.RE +.TP +\fBhex\fR +. +The \fBhex\fR binary encoding converts each byte to a pair of hexadecimal +digits in big-endian form. +.RS +.PP +No options are supported during encoding. During decoding, the following +options are supported: +.TP +\fB\-strict\fR +. +Instructs the decoder to throw an error if it encounters whitespace characters. Otherwise it ignores them. +.RE +.TP +\fBuuencode\fR +. +The \fBuuencode\fR binary encoding used to be common for transfer of data +between Unix systems and on USENET, but is less common these days, having been +largely superseded by the \fBbase64\fR binary encoding. +.RS +.PP +During encoding, the following options are supported (though changing them may +produce files that other implementations of decoders cannot process): +.TP +\fB\-maxlen \fIlength\fR +. +Indicates that the output should be split into lines of no more than +\fIlength\fR characters. By default, lines are split every 61 characters, and +this must be in the range 3 to 85 due to limitations in the encoding. +.TP +\fB\-wrapchar \fIcharacter\fR +. +Indicates that, when lines are split because of the \fB\-maxlen\fR option, +\fIcharacter\fR should be used to separate lines. By default, this is a +newline character, +.QW \en . +.PP +During decoding, the following options are supported: +.TP +\fB\-strict\fR +. +Instructs the decoder to throw an error if it encounters unexpected whitespace +characters. Otherwise it ignores them. +.PP +Note that neither the encoder nor the decoder handle the header and footer of +the uuencode format. +.RE +.VE 8.6 +.SH "BINARY FORMAT" +.PP +The \fBbinary format\fR command generates a binary string whose layout +is specified by the \fIformatString\fR and whose contents come from +the additional arguments. The resulting binary value is returned. +.PP +The \fIformatString\fR consists of a sequence of zero or more field +specifiers separated by zero or more spaces. Each field specifier is +a single type character followed by an optional flag character followed +by an optional numeric \fIcount\fR. +Most field specifiers consume one argument to obtain the value to be +formatted. The type character specifies how the value is to be +formatted. The \fIcount\fR typically indicates how many items of the +specified type are taken from the value. If present, the \fIcount\fR +is a non-negative decimal integer or \fB*\fR, which normally indicates +that all of the items in the value are to be used. If the number of +arguments does not match the number of fields in the format string +that consume arguments, then an error is generated. The flag character +is ignored for \fBbinary format\fR. +.PP +Here is a small example to clarify the relation between the field +specifiers and the arguments: +.CS +\fBbinary format\fR d3d {1.0 2.0 3.0 4.0} 0.1 +.CE +.PP +The first argument is a list of four numbers, but because of the count +of 3 for the associated field specifier, only the first three will be +used. The second argument is associated with the second field +specifier. The resulting binary string contains the four numbers 1.0, +2.0, 3.0 and 0.1. +.PP +Each type-count pair moves an imaginary cursor through the binary +data, storing bytes at the current position and advancing the cursor +to just after the last byte stored. The cursor is initially at +position 0 at the beginning of the data. The type may be any one of +the following characters: +.IP \fBa\fR 5 +Stores a byte string of length \fIcount\fR in the output string. +Every character is taken as modulo 256 (i.e. the low byte of every +character is used, and the high byte discarded) so when storing +character strings not wholly expressible using the characters \eu0000-\eu00ff, +the \fBencoding convertto\fR command should be used first to change +the string into an external representation +if this truncation is not desired (i.e. if the characters are +not part of the ISO 8859\-1 character set.) +If \fIarg\fR has fewer than \fIcount\fR bytes, then additional zero +bytes are used to pad out the field. If \fIarg\fR is longer than the +specified length, the extra characters will be ignored. If +\fIcount\fR is \fB*\fR, then all of the bytes in \fIarg\fR will be +formatted. If \fIcount\fR is omitted, then one character will be +formatted. For example, +.RS +.CS +\fBbinary format\fR a7a*a alpha bravo charlie +.CE +will return a string equivalent to \fBalpha\e000\e000bravoc\fR, +.CS +\fBbinary format\fR a* [encoding convertto utf-8 \eu20ac] +.CE +will return a string equivalent to \fB\e342\e202\e254\fR (which is the +UTF-8 byte sequence for a Euro-currency character) and +.CS +\fBbinary format\fR a* [encoding convertto iso8859-15 \eu20ac] +.CE +will return a string equivalent to \fB\e244\fR (which is the ISO +8859\-15 byte sequence for a Euro-currency character). Contrast these +last two with: +.CS +\fBbinary format\fR a* \eu20ac +.CE +which returns a string equivalent to \fB\e254\fR (i.e. \fB\exac\fR) by +truncating the high-bits of the character, and which is probably not +what is desired. +.RE +.IP \fBA\fR 5 +This form is the same as \fBa\fR except that spaces are used for +padding instead of nulls. For example, +.RS +.CS +\fBbinary format\fR A6A*A alpha bravo charlie +.CE +will return \fBalpha bravoc\fR. +.RE +.IP \fBb\fR 5 +Stores a string of \fIcount\fR binary digits in low-to-high order +within each byte in the output string. \fIArg\fR must contain a +sequence of \fB1\fR and \fB0\fR characters. The resulting bytes are +emitted in first to last order with the bits being formatted in +low-to-high order within each byte. If \fIarg\fR has fewer than +\fIcount\fR digits, then zeros will be used for the remaining bits. +If \fIarg\fR has more than the specified number of digits, the extra +digits will be ignored. If \fIcount\fR is \fB*\fR, then all of the +digits in \fIarg\fR will be formatted. If \fIcount\fR is omitted, +then one digit will be formatted. If the number of bits formatted +does not end at a byte boundary, the remaining bits of the last byte +will be zeros. For example, +.RS +.CS +\fBbinary format\fR b5b* 11100 111000011010 +.CE +will return a string equivalent to \fB\ex07\ex87\ex05\fR. +.RE +.IP \fBB\fR 5 +This form is the same as \fBb\fR except that the bits are stored in +high-to-low order within each byte. For example, +.RS +.CS +\fBbinary format\fR B5B* 11100 111000011010 +.CE +will return a string equivalent to \fB\exe0\exe1\exa0\fR. +.RE +.IP \fBH\fR 5 +Stores a string of \fIcount\fR hexadecimal digits in high-to-low +within each byte in the output string. \fIArg\fR must contain a +sequence of characters in the set +.QW 0123456789abcdefABCDEF . +The resulting bytes are emitted in first to last order with the hex digits +being formatted in high-to-low order within each byte. If \fIarg\fR +has fewer than \fIcount\fR digits, then zeros will be used for the +remaining digits. If \fIarg\fR has more than the specified number of +digits, the extra digits will be ignored. If \fIcount\fR is +\fB*\fR, then all of the digits in \fIarg\fR will be formatted. If +\fIcount\fR is omitted, then one digit will be formatted. If the +number of digits formatted does not end at a byte boundary, the +remaining bits of the last byte will be zeros. For example, +.RS +.CS +\fBbinary format\fR H3H*H2 ab DEF 987 +.CE +will return a string equivalent to \fB\exab\ex00\exde\exf0\ex98\fR. +.RE +.IP \fBh\fR 5 +This form is the same as \fBH\fR except that the digits are stored in +low-to-high order within each byte. This is seldom required. For example, +.RS +.CS +\fBbinary format\fR h3h*h2 AB def 987 +.CE +will return a string equivalent to \fB\exba\ex00\exed\ex0f\ex89\fR. +.RE +.IP \fBc\fR 5 +Stores one or more 8-bit integer values in the output string. If no +\fIcount\fR is specified, then \fIarg\fR must consist of an integer +value. If \fIcount\fR is specified, \fIarg\fR must consist of a list +containing at least that many integers. The low-order 8 bits of each integer +are stored as a one-byte value at the cursor position. If \fIcount\fR +is \fB*\fR, then all of the integers in the list are formatted. If the +number of elements in the list is greater +than \fIcount\fR, then the extra elements are ignored. For example, +.RS +.CS +\fBbinary format\fR c3cc* {3 -3 128 1} 260 {2 5} +.CE +will return a string equivalent to +\fB\ex03\exfd\ex80\ex04\ex02\ex05\fR, whereas +.CS +\fBbinary format\fR c {2 5} +.CE +will generate an error. +.RE +.IP \fBs\fR 5 +This form is the same as \fBc\fR except that it stores one or more +16-bit integers in little-endian byte order in the output string. The +low-order 16-bits of each integer are stored as a two-byte value at +the cursor position with the least significant byte stored first. For +example, +.RS +.CS +\fBbinary format\fR s3 {3 -3 258 1} +.CE +will return a string equivalent to +\fB\ex03\ex00\exfd\exff\ex02\ex01\fR. +.RE +.IP \fBS\fR 5 +This form is the same as \fBs\fR except that it stores one or more +16-bit integers in big-endian byte order in the output string. For +example, +.RS +.CS +\fBbinary format\fR S3 {3 -3 258 1} +.CE +will return a string equivalent to +\fB\ex00\ex03\exff\exfd\ex01\ex02\fR. +.RE +.IP \fBt\fR 5 +This form (mnemonically \fItiny\fR) is the same as \fBs\fR and \fBS\fR +except that it stores the 16-bit integers in the output string in the +native byte order of the machine where the Tcl script is running. +To determine what the native byte order of the machine is, refer to +the \fBbyteOrder\fR element of the \fBtcl_platform\fR array. +.IP \fBi\fR 5 +This form is the same as \fBc\fR except that it stores one or more +32-bit integers in little-endian byte order in the output string. The +low-order 32-bits of each integer are stored as a four-byte value at +the cursor position with the least significant byte stored first. For +example, +.RS +.CS +\fBbinary format\fR i3 {3 -3 65536 1} +.CE +will return a string equivalent to +\fB\ex03\ex00\ex00\ex00\exfd\exff\exff\exff\ex00\ex00\ex01\ex00\fR +.RE +.IP \fBI\fR 5 +This form is the same as \fBi\fR except that it stores one or more one +or more 32-bit integers in big-endian byte order in the output string. +For example, +.RS +.CS +\fBbinary format\fR I3 {3 -3 65536 1} +.CE +will return a string equivalent to +\fB\ex00\ex00\ex00\ex03\exff\exff\exff\exfd\ex00\ex01\ex00\ex00\fR +.RE +.IP \fBn\fR 5 +This form (mnemonically \fInumber\fR or \fInormal\fR) is the same as +\fBi\fR and \fBI\fR except that it stores the 32-bit integers in the +output string in the native byte order of the machine where the Tcl +script is running. +To determine what the native byte order of the machine is, refer to +the \fBbyteOrder\fR element of the \fBtcl_platform\fR array. +.IP \fBw\fR 5 +This form is the same as \fBc\fR except that it stores one or more +64-bit integers in little-endian byte order in the output string. The +low-order 64-bits of each integer are stored as an eight-byte value at +the cursor position with the least significant byte stored first. For +example, +.RS +.CS +\fBbinary format\fR w 7810179016327718216 +.CE +will return the string \fBHelloTcl\fR +.RE +.IP \fBW\fR 5 +This form is the same as \fBw\fR except that it stores one or more one +or more 64-bit integers in big-endian byte order in the output string. +For example, +.RS +.CS +\fBbinary format\fR Wc 4785469626960341345 110 +.CE +will return the string \fBBigEndian\fR +.RE +.IP \fBm\fR 5 +This form (mnemonically the mirror of \fBw\fR) is the same as \fBw\fR +and \fBW\fR except that it stores the 64-bit integers in the output +string in the native byte order of the machine where the Tcl script is +running. +To determine what the native byte order of the machine is, refer to +the \fBbyteOrder\fR element of the \fBtcl_platform\fR array. +.IP \fBf\fR 5 +This form is the same as \fBc\fR except that it stores one or more one +or more single-precision floating point numbers in the machine's native +representation in the output string. This representation is not +portable across architectures, so it should not be used to communicate +floating point numbers across the network. The size of a floating +point number may vary across architectures, so the number of bytes +that are generated may vary. If the value overflows the +machine's native representation, then the value of FLT_MAX +as defined by the system will be used instead. Because Tcl uses +double-precision floating point numbers internally, there may be some +loss of precision in the conversion to single-precision. For example, +on a Windows system running on an Intel Pentium processor, +.RS +.CS +\fBbinary format\fR f2 {1.6 3.4} +.CE +will return a string equivalent to +\fB\excd\excc\excc\ex3f\ex9a\ex99\ex59\ex40\fR. +.RE +.IP \fBr\fR 5 +This form (mnemonically \fIreal\fR) is the same as \fBf\fR except that +it stores the single-precision floating point numbers in little-endian +order. This conversion only produces meaningful output when used on +machines which use the IEEE floating point representation (very +common, but not universal.) +.IP \fBR\fR 5 +This form is the same as \fBr\fR except that it stores the +single-precision floating point numbers in big-endian order. +.IP \fBd\fR 5 +This form is the same as \fBf\fR except that it stores one or more one +or more double-precision floating point numbers in the machine's native +representation in the output string. For example, on a +Windows system running on an Intel Pentium processor, +.RS +.CS +\fBbinary format\fR d1 {1.6} +.CE +will return a string equivalent to +\fB\ex9a\ex99\ex99\ex99\ex99\ex99\exf9\ex3f\fR. +.RE +.IP \fBq\fR 5 +This form (mnemonically the mirror of \fBd\fR) is the same as \fBd\fR +except that it stores the double-precision floating point numbers in +little-endian order. This conversion only produces meaningful output +when used on machines which use the IEEE floating point representation +(very common, but not universal.) +.IP \fBQ\fR 5 +This form is the same as \fBq\fR except that it stores the +double-precision floating point numbers in big-endian order. +.IP \fBx\fR 5 +Stores \fIcount\fR null bytes in the output string. If \fIcount\fR is +not specified, stores one null byte. If \fIcount\fR is \fB*\fR, +generates an error. This type does not consume an argument. For +example, +.RS +.CS +\fBbinary format\fR a3xa3x2a3 abc def ghi +.CE +will return a string equivalent to \fBabc\e000def\e000\e000ghi\fR. +.RE +.IP \fBX\fR 5 +Moves the cursor back \fIcount\fR bytes in the output string. If +\fIcount\fR is \fB*\fR or is larger than the current cursor position, +then the cursor is positioned at location 0 so that the next byte +stored will be the first byte in the result string. If \fIcount\fR is +omitted then the cursor is moved back one byte. This type does not +consume an argument. For example, +.RS +.CS +\fBbinary format\fR a3X*a3X2a3 abc def ghi +.CE +will return \fBdghi\fR. +.RE +.IP \fB@\fR 5 +Moves the cursor to the absolute location in the output string +specified by \fIcount\fR. Position 0 refers to the first byte in the +output string. If \fIcount\fR refers to a position beyond the last +byte stored so far, then null bytes will be placed in the uninitialized +locations and the cursor will be placed at the specified location. If +\fIcount\fR is \fB*\fR, then the cursor is moved to the current end of +the output string. If \fIcount\fR is omitted, then an error will be +generated. This type does not consume an argument. For example, +.RS +.CS +\fBbinary format\fR a5@2a1@*a3@10a1 abcde f ghi j +.CE +will return \fBabfdeghi\e000\e000j\fR. +.RE +.SH "BINARY SCAN" +.PP +The \fBbinary scan\fR command parses fields from a binary string, +returning the number of conversions performed. \fIString\fR gives the +input bytes to be parsed (one byte per character, and characters not +representable as a byte have their high bits chopped) +and \fIformatString\fR indicates how to parse it. +Each \fIvarName\fR gives the name of a variable; when a field is +scanned from \fIstring\fR the result is assigned to the corresponding +variable. +.PP +As with \fBbinary format\fR, the \fIformatString\fR consists of a +sequence of zero or more field specifiers separated by zero or more +spaces. Each field specifier is a single type character followed by +an optional flag character followed by an optional numeric \fIcount\fR. +Most field specifiers consume one +argument to obtain the variable into which the scanned values should +be placed. The type character specifies how the binary data is to be +interpreted. The \fIcount\fR typically indicates how many items of +the specified type are taken from the data. If present, the +\fIcount\fR is a non-negative decimal integer or \fB*\fR, which +normally indicates that all of the remaining items in the data are to +be used. If there are not enough bytes left after the current cursor +position to satisfy the current field specifier, then the +corresponding variable is left untouched and \fBbinary scan\fR returns +immediately with the number of variables that were set. If there are +not enough arguments for all of the fields in the format string that +consume arguments, then an error is generated. The flag character +.QW u +may be given to cause some types to be read as unsigned values. The flag +is accepted for all field types but is ignored for non-integer fields. +.PP +A similar example as with \fBbinary format\fR should explain the +relation between field specifiers and arguments in case of the binary +scan subcommand: +.CS +\fBbinary scan\fR $bytes s3s first second +.CE +.PP +This command (provided the binary string in the variable \fIbytes\fR +is long enough) assigns a list of three integers to the variable +\fIfirst\fR and assigns a single value to the variable \fIsecond\fR. +If \fIbytes\fR contains fewer than 8 bytes (i.e. four 2-byte +integers), no assignment to \fIsecond\fR will be made, and if +\fIbytes\fR contains fewer than 6 bytes (i.e. three 2-byte integers), +no assignment to \fIfirst\fR will be made. Hence: +.CS +puts [\fBbinary scan\fR abcdefg s3s first second] +puts $first +puts $second +.CE +will print (assuming neither variable is set previously): +.CS +1 +25185 25699 26213 +can't read "second": no such variable +.CE +.PP +It is \fIimportant\fR to note that the \fBc\fR, \fBs\fR, and \fBS\fR +(and \fBi\fR and \fBI\fR on 64bit systems) will be scanned into +long data size values. In doing this, values that have their high +bit set (0x80 for chars, 0x8000 for shorts, 0x80000000 for ints), +will be sign extended. Thus the following will occur: +.CS +set signShort [\fBbinary format\fR s1 0x8000] +\fBbinary scan\fR $signShort s1 val; \fI# val == 0xFFFF8000\fR +.CE +If you require unsigned values you can include the +.QW u +flag character following +the field type. For example, to read an unsigned short value: +.CS +set signShort [\fBbinary format\fR s1 0x8000] +\fBbinary scan\fR $signShort su1 val; \fI# val == 0x00008000\fR +.CE +.PP +Each type-count pair moves an imaginary cursor through the binary data, +reading bytes from the current position. The cursor is initially +at position 0 at the beginning of the data. The type may be any one of +the following characters: +.IP \fBa\fR 5 +The data is a byte string of length \fIcount\fR. If \fIcount\fR +is \fB*\fR, then all of the remaining bytes in \fIstring\fR will be +scanned into the variable. If \fIcount\fR is omitted, then one +byte will be scanned. +All bytes scanned will be interpreted as being characters in the +range \eu0000-\eu00ff so the \fBencoding convertfrom\fR command will be +needed if the string is not a binary string or a string encoded in ISO +8859\-1. +For example, +.RS +.CS +\fBbinary scan\fR abcde\e000fghi a6a10 var1 var2 +.CE +will return \fB1\fR with the string equivalent to \fBabcde\e000\fR +stored in \fIvar1\fR and \fIvar2\fR left unmodified, and +.CS +\fBbinary scan\fR \e342\e202\e254 a* var1 +set var2 [encoding convertfrom utf-8 $var1] +.CE +will store a Euro-currency character in \fIvar2\fR. +.RE +.IP \fBA\fR 5 +This form is the same as \fBa\fR, except trailing blanks and nulls are stripped from +the scanned value before it is stored in the variable. For example, +.RS +.CS +\fBbinary scan\fR "abc efghi \e000" A* var1 +.CE +will return \fB1\fR with \fBabc efghi\fR stored in \fIvar1\fR. +.RE +.IP \fBb\fR 5 +The data is turned into a string of \fIcount\fR binary digits in +low-to-high order represented as a sequence of +.QW 1 +and +.QW 0 +characters. The data bytes are scanned in first to last order with +the bits being taken in low-to-high order within each byte. Any extra +bits in the last byte are ignored. If \fIcount\fR is \fB*\fR, then +all of the remaining bits in \fIstring\fR will be scanned. If +\fIcount\fR is omitted, then one bit will be scanned. For example, +.RS +.CS +\fBbinary scan\fR \ex07\ex87\ex05 b5b* var1 var2 +.CE +will return \fB2\fR with \fB11100\fR stored in \fIvar1\fR and +\fB1110000110100000\fR stored in \fIvar2\fR. +.RE +.IP \fBB\fR 5 +This form is the same as \fBb\fR, except the bits are taken in +high-to-low order within each byte. For example, +.RS +.CS +\fBbinary scan\fR \ex70\ex87\ex05 B5B* var1 var2 +.CE +will return \fB2\fR with \fB01110\fR stored in \fIvar1\fR and +\fB1000011100000101\fR stored in \fIvar2\fR. +.RE +.IP \fBH\fR 5 +The data is turned into a string of \fIcount\fR hexadecimal digits in +high-to-low order represented as a sequence of characters in the set +.QW 0123456789abcdef . +The data bytes are scanned in first to last +order with the hex digits being taken in high-to-low order within each +byte. Any extra bits in the last byte are ignored. If \fIcount\fR is +\fB*\fR, then all of the remaining hex digits in \fIstring\fR will be +scanned. If \fIcount\fR is omitted, then one hex digit will be +scanned. For example, +.RS +.CS +\fBbinary scan\fR \ex07\exC6\ex05\ex1f\ex34 H3H* var1 var2 +.CE +will return \fB2\fR with \fB07c\fR stored in \fIvar1\fR and +\fB051f34\fR stored in \fIvar2\fR. +.RE +.IP \fBh\fR 5 +This form is the same as \fBH\fR, except the digits are taken in +reverse (low-to-high) order within each byte. For example, +.RS +.CS +\fBbinary scan\fR \ex07\ex86\ex05\ex12\ex34 h3h* var1 var2 +.CE +will return \fB2\fR with \fB706\fR stored in \fIvar1\fR and +\fB502143\fR stored in \fIvar2\fR. +.PP +Note that most code that wishes to parse the hexadecimal digits from +multiple bytes in order should use the \fBH\fR format. +.RE +.IP \fBc\fR 5 +The data is turned into \fIcount\fR 8-bit signed integers and stored +in the corresponding variable as a list. If \fIcount\fR is \fB*\fR, +then all of the remaining bytes in \fIstring\fR will be scanned. If +\fIcount\fR is omitted, then one 8-bit integer will be scanned. For +example, +.RS +.CS +\fBbinary scan\fR \ex07\ex86\ex05 c2c* var1 var2 +.CE +will return \fB2\fR with \fB7 -122\fR stored in \fIvar1\fR and \fB5\fR +stored in \fIvar2\fR. Note that the integers returned are signed, but +they can be converted to unsigned 8-bit quantities using an expression +like: +.CS +set num [expr { $num & 0xff }] +.CE +.RE +.IP \fBs\fR 5 +The data is interpreted as \fIcount\fR 16-bit signed integers +represented in little-endian byte order. The integers are stored in +the corresponding variable as a list. If \fIcount\fR is \fB*\fR, then +all of the remaining bytes in \fIstring\fR will be scanned. If +\fIcount\fR is omitted, then one 16-bit integer will be scanned. For +example, +.RS +.CS +\fBbinary scan\fR \ex05\ex00\ex07\ex00\exf0\exff s2s* var1 var2 +.CE +will return \fB2\fR with \fB5 7\fR stored in \fIvar1\fR and \fB\-16\fR +stored in \fIvar2\fR. Note that the integers returned are signed, but +they can be converted to unsigned 16-bit quantities using an expression +like: +.CS +set num [expr { $num & 0xffff }] +.CE +.RE +.IP \fBS\fR 5 +This form is the same as \fBs\fR except that the data is interpreted +as \fIcount\fR 16-bit signed integers represented in big-endian byte +order. For example, +.RS +.CS +\fBbinary scan\fR \ex00\ex05\ex00\ex07\exff\exf0 S2S* var1 var2 +.CE +will return \fB2\fR with \fB5 7\fR stored in \fIvar1\fR and \fB\-16\fR +stored in \fIvar2\fR. +.RE +.IP \fBt\fR 5 +The data is interpreted as \fIcount\fR 16-bit signed integers +represented in the native byte order of the machine running the Tcl +script. It is otherwise identical to \fBs\fR and \fBS\fR. +To determine what the native byte order of the machine is, refer to +the \fBbyteOrder\fR element of the \fBtcl_platform\fR array. +.IP \fBi\fR 5 +The data is interpreted as \fIcount\fR 32-bit signed integers +represented in little-endian byte order. The integers are stored in +the corresponding variable as a list. If \fIcount\fR is \fB*\fR, then +all of the remaining bytes in \fIstring\fR will be scanned. If +\fIcount\fR is omitted, then one 32-bit integer will be scanned. For +example, +.RS +.CS +set str \ex05\ex00\ex00\ex00\ex07\ex00\ex00\ex00\exf0\exff\exff\exff +\fBbinary scan\fR $str i2i* var1 var2 +.CE +will return \fB2\fR with \fB5 7\fR stored in \fIvar1\fR and \fB\-16\fR +stored in \fIvar2\fR. Note that the integers returned are signed, but +they can be converted to unsigned 32-bit quantities using an expression +like: +.CS +set num [expr { $num & 0xffffffff }] +.CE +.RE +.IP \fBI\fR 5 +This form is the same as \fBI\fR except that the data is interpreted +as \fIcount\fR 32-bit signed integers represented in big-endian byte +order. For example, +.RS +.CS +set str \ex00\ex00\ex00\ex05\ex00\ex00\ex00\ex07\exff\exff\exff\exf0 +\fBbinary scan\fR $str I2I* var1 var2 +.CE +will return \fB2\fR with \fB5 7\fR stored in \fIvar1\fR and \fB\-16\fR +stored in \fIvar2\fR. +.RE +.IP \fBn\fR 5 +The data is interpreted as \fIcount\fR 32-bit signed integers +represented in the native byte order of the machine running the Tcl +script. It is otherwise identical to \fBi\fR and \fBI\fR. +To determine what the native byte order of the machine is, refer to +the \fBbyteOrder\fR element of the \fBtcl_platform\fR array. +.IP \fBw\fR 5 +The data is interpreted as \fIcount\fR 64-bit signed integers +represented in little-endian byte order. The integers are stored in +the corresponding variable as a list. If \fIcount\fR is \fB*\fR, then +all of the remaining bytes in \fIstring\fR will be scanned. If +\fIcount\fR is omitted, then one 64-bit integer will be scanned. For +example, +.RS +.CS +set str \ex05\ex00\ex00\ex00\ex07\ex00\ex00\ex00\exf0\exff\exff\exff +\fBbinary scan\fR $str wi* var1 var2 +.CE +will return \fB2\fR with \fB30064771077\fR stored in \fIvar1\fR and +\fB\-16\fR stored in \fIvar2\fR. Note that the integers returned are +signed and cannot be represented by Tcl as unsigned values. +.RE +.IP \fBW\fR 5 +This form is the same as \fBw\fR except that the data is interpreted +as \fIcount\fR 64-bit signed integers represented in big-endian byte +order. For example, +.RS +.CS +set str \ex00\ex00\ex00\ex05\ex00\ex00\ex00\ex07\exff\exff\exff\exf0 +\fBbinary scan\fR $str WI* var1 var2 +.CE +will return \fB2\fR with \fB21474836487\fR stored in \fIvar1\fR and \fB\-16\fR +stored in \fIvar2\fR. +.RE +.IP \fBm\fR 5 +The data is interpreted as \fIcount\fR 64-bit signed integers +represented in the native byte order of the machine running the Tcl +script. It is otherwise identical to \fBw\fR and \fBW\fR. +To determine what the native byte order of the machine is, refer to +the \fBbyteOrder\fR element of the \fBtcl_platform\fR array. +.IP \fBf\fR 5 +The data is interpreted as \fIcount\fR single-precision floating point +numbers in the machine's native representation. The floating point +numbers are stored in the corresponding variable as a list. If +\fIcount\fR is \fB*\fR, then all of the remaining bytes in +\fIstring\fR will be scanned. If \fIcount\fR is omitted, then one +single-precision floating point number will be scanned. The size of a +floating point number may vary across architectures, so the number of +bytes that are scanned may vary. If the data does not represent a +valid floating point number, the resulting value is undefined and +compiler dependent. For example, on a Windows system running on an +Intel Pentium processor, +.RS +.CS +\fBbinary scan\fR \ex3f\excc\excc\excd f var1 +.CE +will return \fB1\fR with \fB1.6000000238418579\fR stored in +\fIvar1\fR. +.RE +.IP \fBr\fR 5 +This form is the same as \fBf\fR except that the data is interpreted +as \fIcount\fR single-precision floating point number in little-endian +order. This conversion is not portable to the minority of systems not +using IEEE floating point representations. +.IP \fBR\fR 5 +This form is the same as \fBf\fR except that the data is interpreted +as \fIcount\fR single-precision floating point number in big-endian +order. This conversion is not portable to the minority of systems not +using IEEE floating point representations. +.IP \fBd\fR 5 +This form is the same as \fBf\fR except that the data is interpreted +as \fIcount\fR double-precision floating point numbers in the +machine's native representation. For example, on a Windows system +running on an Intel Pentium processor, +.RS +.CS +\fBbinary scan\fR \ex9a\ex99\ex99\ex99\ex99\ex99\exf9\ex3f d var1 +.CE +will return \fB1\fR with \fB1.6000000000000001\fR +stored in \fIvar1\fR. +.RE +.IP \fBq\fR 5 +This form is the same as \fBd\fR except that the data is interpreted +as \fIcount\fR double-precision floating point number in little-endian +order. This conversion is not portable to the minority of systems not +using IEEE floating point representations. +.IP \fBQ\fR 5 +This form is the same as \fBd\fR except that the data is interpreted +as \fIcount\fR double-precision floating point number in big-endian +order. This conversion is not portable to the minority of systems not +using IEEE floating point representations. +.IP \fBx\fR 5 +Moves the cursor forward \fIcount\fR bytes in \fIstring\fR. If +\fIcount\fR is \fB*\fR or is larger than the number of bytes after the +current cursor position, then the cursor is positioned after +the last byte in \fIstring\fR. If \fIcount\fR is omitted, then the +cursor is moved forward one byte. Note that this type does not +consume an argument. For example, +.RS +.CS +\fBbinary scan\fR \ex01\ex02\ex03\ex04 x2H* var1 +.CE +will return \fB1\fR with \fB0304\fR stored in \fIvar1\fR. +.RE +.IP \fBX\fR 5 +Moves the cursor back \fIcount\fR bytes in \fIstring\fR. If +\fIcount\fR is \fB*\fR or is larger than the current cursor position, +then the cursor is positioned at location 0 so that the next byte +scanned will be the first byte in \fIstring\fR. If \fIcount\fR +is omitted then the cursor is moved back one byte. Note that this +type does not consume an argument. For example, +.RS +.CS +\fBbinary scan\fR \ex01\ex02\ex03\ex04 c2XH* var1 var2 +.CE +will return \fB2\fR with \fB1 2\fR stored in \fIvar1\fR and \fB020304\fR +stored in \fIvar2\fR. +.RE +.IP \fB@\fR 5 +Moves the cursor to the absolute location in the data string specified +by \fIcount\fR. Note that position 0 refers to the first byte in +\fIstring\fR. If \fIcount\fR refers to a position beyond the end of +\fIstring\fR, then the cursor is positioned after the last byte. If +\fIcount\fR is omitted, then an error will be generated. For example, +.RS +.CS +\fBbinary scan\fR \ex01\ex02\ex03\ex04 c2@1H* var1 var2 +.CE +will return \fB2\fR with \fB1 2\fR stored in \fIvar1\fR and \fB020304\fR +stored in \fIvar2\fR. +.RE +.SH "PORTABILITY ISSUES" +.PP +The \fBr\fR, \fBR\fR, \fBq\fR and \fBQ\fR conversions will only work +reliably for transferring data between computers which are all using +IEEE floating point representations. This is very common, but not +universal. To transfer floating-point numbers portably between all +architectures, use their textual representation (as produced by +\fBformat\fR) instead. +.SH EXAMPLES +.PP +This is a procedure to write a Tcl string to a binary-encoded channel as +UTF-8 data preceded by a length word: +.PP +.CS +proc \fIwriteString\fR {channel string} { + set data [encoding convertto utf-8 $string] + puts -nonewline [\fBbinary format\fR Ia* \e + [string length $data] $data] +} +.CE +.PP +This procedure reads a string from a channel that was written by the +previously presented \fIwriteString\fR procedure: +.PP +.CS +proc \fIreadString\fR {channel} { + if {![\fBbinary scan\fR [read $channel 4] I length]} { + error "missing length" + } + set data [read $channel $length] + return [encoding convertfrom utf-8 $data] +} +.CE +.PP +This converts the contents of a file (named in the variable \fIfilename\fR) to +base64 and prints them: +.PP +.CS +set f [open $filename rb] +set data [read $f] +close $f +puts [\fBbinary encode\fR base64 \-maxlen 64 $data] +.CE +.SH "SEE ALSO" +encoding(n), format(n), scan(n), string(n), tcl_platform(n) +.SH KEYWORDS +binary, format, scan +'\" Local Variables: +'\" mode: nroff +'\" fill-column: 78 +'\" End: diff --git a/tcl8.6/doc/break.n b/tcl8.6/doc/break.n new file mode 100644 index 0000000..3e4ce5f --- /dev/null +++ b/tcl8.6/doc/break.n @@ -0,0 +1,47 @@ +'\" +'\" Copyright (c) 1993-1994 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. +'\" +.TH break n "" Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +break \- Abort looping command +.SH SYNOPSIS +\fBbreak\fR +.BE +.SH DESCRIPTION +.PP +This command is typically invoked inside the body of a looping command +such as \fBfor\fR or \fBforeach\fR or \fBwhile\fR. +It returns a 3 (\fBTCL_BREAK\fR) result code, which causes a break exception +to occur. +The exception causes the current script to be aborted +out to the innermost containing loop command, which then +aborts its execution and returns normally. +Break exceptions are also handled in a few other situations, such +as the \fBcatch\fR command, Tk event bindings, and the outermost +scripts of procedure bodies. +.SH EXAMPLE +.PP +Print a line for each of the integers from 0 to 5: +.PP +.CS +for {set x 0} {$x<10} {incr x} { + if {$x > 5} { + \fBbreak\fR + } + puts "x is $x" +} +.CE +.SH "SEE ALSO" +catch(n), continue(n), for(n), foreach(n), return(n), while(n) +.SH KEYWORDS +abort, break, loop +'\" Local Variables: +'\" mode: nroff +'\" End: diff --git a/tcl8.6/doc/case.n b/tcl8.6/doc/case.n new file mode 100644 index 0000000..54d5bf4 --- /dev/null +++ b/tcl8.6/doc/case.n @@ -0,0 +1,60 @@ +'\" +'\" Copyright (c) 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. +'\" +.TH case n 7.0 Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +case \- Evaluate one of several scripts, depending on a given value +.SH SYNOPSIS +\fBcase\fI string \fR?\fBin\fR? \fIpatList body \fR?\fIpatList body \fR...? +.sp +\fBcase\fI string \fR?\fBin\fR? {\fIpatList body \fR?\fIpatList body \fR...?} +.BE + +.SH DESCRIPTION +.PP +\fINote: the \fBcase\fI command is obsolete and is supported only +for backward compatibility. At some point in the future it may be +removed entirely. You should use the \fBswitch\fI command instead.\fR +.PP +The \fBcase\fR command matches \fIstring\fR against each of +the \fIpatList\fR arguments in order. +Each \fIpatList\fR argument is a list of one or +more patterns. If any of these patterns matches \fIstring\fR then +\fBcase\fR evaluates the following \fIbody\fR argument +by passing it recursively to the Tcl interpreter and returns the result +of that evaluation. +Each \fIpatList\fR argument consists of a single +pattern or list of patterns. Each pattern may contain any of the wild-cards +described under \fBstring match\fR. If a \fIpatList\fR +argument is \fBdefault\fR, the corresponding body will be evaluated +if no \fIpatList\fR matches \fIstring\fR. If no \fIpatList\fR argument +matches \fIstring\fR and no default is given, then the \fBcase\fR +command returns an empty string. +.PP +Two syntaxes are provided for the \fIpatList\fR and \fIbody\fR arguments. +The first uses a separate argument for each of the patterns and commands; +this form is convenient if substitutions are desired on some of the +patterns or commands. +The second form places all of the patterns and commands together into +a single argument; the argument must have proper list structure, with +the elements of the list being the patterns and commands. +The second form makes it easy to construct multi-line case commands, +since the braces around the whole list make it unnecessary to include a +backslash at the end of each line. +Since the \fIpatList\fR arguments are in braces in the second form, +no command or variable substitutions are performed on them; this makes +the behavior of the second form different than the first form in some +cases. + +.SH "SEE ALSO" +switch(n) + +.SH KEYWORDS +case, match, regular expression diff --git a/tcl8.6/doc/catch.n b/tcl8.6/doc/catch.n new file mode 100644 index 0000000..d43a7ec --- /dev/null +++ b/tcl8.6/doc/catch.n @@ -0,0 +1,125 @@ +'\" +'\" Copyright (c) 1993-1994 The Regents of the University of California. +'\" Copyright (c) 1994-1996 Sun Microsystems, Inc. +'\" Contributions from Don Porter, NIST, 2003. (not subject to US copyright) +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH catch n "8.5" Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +catch \- Evaluate script and trap exceptional returns +.SH SYNOPSIS +\fBcatch\fI script \fR?\fIresultVarName\fR? ?\fIoptionsVarName\fR? +.BE +.SH DESCRIPTION +.PP +The \fBcatch\fR command may be used to prevent errors from aborting command +interpretation. The \fBcatch\fR command calls the Tcl interpreter recursively +to execute \fIscript\fR, and always returns without raising an error, +regardless of any errors that might occur while executing \fIscript\fR. +.PP +If \fIscript\fR raises an error, \fBcatch\fR will return a non-zero integer +value corresponding to the exceptional return code returned by evaluation +of \fIscript\fR. Tcl defines the normal return code from script +evaluation to be zero (0), or \fBTCL_OK\fR. Tcl also defines four exceptional +return codes: 1 (\fBTCL_ERROR\fR), 2 (\fBTCL_RETURN\fR), 3 (\fBTCL_BREAK\fR), +and 4 (\fBTCL_CONTINUE\fR). Errors during evaluation of a script are indicated +by a return code of \fBTCL_ERROR\fR. The other exceptional return codes are +returned by the \fBreturn\fR, \fBbreak\fR, and \fBcontinue\fR commands +and in other special situations as documented. Tcl packages can define +new commands that return other integer values as return codes as well, +and scripts that make use of the \fBreturn \-code\fR command can also +have return codes other than the five defined by Tcl. +.PP +If the \fIresultVarName\fR argument is given, then the variable it names is +set to the result of the script evaluation. When the return code from the +script is 1 (\fBTCL_ERROR\fR), the value stored in \fIresultVarName\fR is an +error message. When the return code from the script is 0 (\fBTCL_OK\fR), the +value stored in \fIresultVarName\fR is the value returned from \fIscript\fR. +.PP +If the \fIoptionsVarName\fR argument is given, then the variable it +names is set to a dictionary of return options returned by evaluation +of \fIscript\fR. Tcl specifies two entries that are always +defined in the dictionary: \fB\-code\fR and \fB\-level\fR. When +the return code from evaluation of \fIscript\fR is not \fBTCL_RETURN\fR, +the value of the \fB\-level\fR entry will be 0, and the value +of the \fB\-code\fR entry will be the same as the return code. +Only when the return code is \fBTCL_RETURN\fR will the values of +the \fB\-level\fR and \fB\-code\fR entries be something else, as +further described in the documentation for the \fBreturn\fR command. +.PP +When the return code from evaluation of \fIscript\fR is +\fBTCL_ERROR\fR, four additional entries are defined in the dictionary +of return options stored in \fIoptionsVarName\fR: \fB\-errorinfo\fR, +\fB\-errorcode\fR, \fB\-errorline\fR, and +.VS 8.6 +\fB\-errorstack\fR. +.VE 8.6 +The value of the \fB\-errorinfo\fR entry is a formatted stack trace containing +more information about the context in which the error happened. The formatted +stack trace is meant to be read by a person. The value of the +\fB\-errorcode\fR entry is additional information about the error stored as a +list. The \fB\-errorcode\fR value is meant to be further processed by +programs, and may not be particularly readable by people. The value of the +\fB\-errorline\fR entry is an integer indicating which line of \fIscript\fR +was being evaluated when the error occurred. +.VS 8.6 +The value of the \fB\-errorstack\fR entry is an +even-sized list made of token-parameter pairs accumulated while +unwinding the stack. The token may be +.QW \fBCALL\fR , +in which case the parameter is a list made of the proc name and arguments at +the corresponding level; or it may be +.QW \fBUP\fR , +in which case the parameter is +the relative level (as in \fBuplevel\fR) of the previous \fBCALL\fR. The +salient differences with respect to \fB\-errorinfo\fR are that: +.IP [1] +it is a machine-readable form that is amenable to processing with +[\fBforeach\fR {tok prm} ...], +.IP [2] +it contains the true (substituted) values passed to the functions, instead of +the static text of the calling sites, and +.IP [3] +it is coarser-grained, with only one element per stack frame (like procs; no +separate elements for \fBforeach\fR constructs for example). +.VE 8.6 +.PP +The values of the \fB\-errorinfo\fR and \fB\-errorcode\fR entries of +the most recent error are also available as values of the global +variables \fB::errorInfo\fR and \fB::errorCode\fR respectively. +.VS 8.6 +The value of the \fB\-errorstack\fR entry surfaces as \fBinfo errorstack\fR. +.VE 8.6 +.PP +Tcl packages may provide commands that set other entries in the +dictionary of return options, and the \fBreturn\fR command may be +used by scripts to set return options in addition to those defined +above. +.SH EXAMPLES +.PP +The \fBcatch\fR command may be used in an \fBif\fR to branch based on +the success of a script. +.PP +.CS +if { [\fBcatch\fR {open $someFile w} fid] } { + puts stderr "Could not open $someFile for writing\en$fid" + exit 1 +} +.CE +.PP +There are more complex examples of \fBcatch\fR usage in the +documentation for the \fBreturn\fR command. +.SH "SEE ALSO" +break(n), continue(n), dict(n), error(n), errorCode(n), errorInfo(n), info(n), +return(n) +.SH KEYWORDS +catch, error, exception +'\" Local Variables: +'\" mode: nroff +'\" fill-column: 78 +'\" End: diff --git a/tcl8.6/doc/cd.n b/tcl8.6/doc/cd.n new file mode 100644 index 0000000..67cdd17 --- /dev/null +++ b/tcl8.6/doc/cd.n @@ -0,0 +1,43 @@ +'\" +'\" Copyright (c) 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. +'\" +.TH cd n "" Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +cd \- Change working directory +.SH SYNOPSIS +\fBcd \fR?\fIdirName\fR? +.BE +.SH DESCRIPTION +.PP +Change the current working directory to \fIdirName\fR, or to the +home directory (as specified in the HOME environment variable) if +\fIdirName\fR is not given. +Returns an empty string. +Note that the current working directory is a per-process resource; the +\fBcd\fR command changes the working directory for all interpreters +and (in a threaded environment) all threads. +.SH EXAMPLES +.PP +Change to the home directory of the user \fBfred\fR: +.PP +.CS +\fBcd\fR ~fred +.CE +.PP +Change to the directory \fBlib\fR that is a sibling directory of the +current one: +.PP +.CS +\fBcd\fR ../lib +.CE +.SH "SEE ALSO" +filename(n), glob(n), pwd(n) +.SH KEYWORDS +working directory diff --git a/tcl8.6/doc/chan.n b/tcl8.6/doc/chan.n new file mode 100644 index 0000000..81aa9f4 --- /dev/null +++ b/tcl8.6/doc/chan.n @@ -0,0 +1,850 @@ +'\" +'\" Copyright (c) 2005-2006 Donal K. Fellows +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +.TH chan n 8.5 Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +chan \- Read, write and manipulate channels +.SH SYNOPSIS +\fBchan \fIoption\fR ?\fIarg arg ...\fR? +.BE +.SH DESCRIPTION +.PP +This command provides several operations for reading from, writing to +and otherwise manipulating open channels (such as have been created +with the \fBopen\fR and \fBsocket\fR commands, or the default named +channels \fBstdin\fR, \fBstdout\fR or \fBstderr\fR which correspond to +the process's standard input, output and error streams respectively). +\fIOption\fR indicates what to do with the channel; any unique +abbreviation for \fIoption\fR is acceptable. Valid options are: +.TP +\fBchan blocked \fIchannelId\fR +. +This tests whether the last input operation on the channel called +\fIchannelId\fR failed because it would have otherwise caused the +process to block, and returns 1 if that was the case. It returns 0 +otherwise. Note that this only ever returns 1 when the channel has +been configured to be non-blocking; all Tcl channels have blocking +turned on by default. +.TP +\fBchan close \fIchannelId\fR ?\fIdirection\fR? +. +Close and destroy the channel called \fIchannelId\fR. Note that this +deletes all existing file-events registered on the channel. +.VS 8.6 +If the \fIdirection\fR argument (which must be \fBread\fR or \fBwrite\fR or +any unique abbreviation of them) is present, the channel will only be +half-closed, so that it can go from being read-write to write-only or +read-only respectively. If a read-only channel is closed for reading, it is +the same as if the channel is fully closed, and respectively similar for +write-only channels. Without the \fIdirection\fR argument, the channel is +closed for both reading and writing (but only if those directions are +currently open). It is an error to close a read-only channel for writing, or a +write-only channel for reading. +.VE 8.6 +.RS +.PP +As part of closing the channel, all buffered output is flushed to the +channel's output device (only if the channel is ceasing to be writable), any +buffered input is discarded (only if the channel is ceasing to be readable), +the underlying operating system resource is closed and \fIchannelId\fR becomes +unavailable for future use (both only if the channel is being completely +closed). +.PP +If the channel is blocking and the channel is ceasing to be writable, the +command does not return until all output is flushed. If the channel is +non-blocking and there is unflushed output, the channel remains open and the +command returns immediately; output will be flushed in the background and the +channel will be closed when all the flushing is complete. +.PP +If \fIchannelId\fR is a blocking channel for a command pipeline then +\fBchan close\fR waits for the child processes to complete. +.PP +If the channel is shared between interpreters, then \fBchan close\fR +makes \fIchannelId\fR unavailable in the invoking interpreter but has +no other effect until all of the sharing interpreters have closed the +channel. When the last interpreter in which the channel is registered +invokes \fBchan close\fR (or \fBclose\fR), the cleanup actions +described above occur. With half-closing, the half-close of the channel only +applies to the current interpreter's view of the channel until all channels +have closed it in that direction (or completely). +See the \fBinterp\fR command for a description of channel sharing. +.PP +Channels are automatically fully closed when an interpreter is destroyed and +when the process exits. Channels are switched to blocking mode, to +ensure that all output is correctly flushed before the process exits. +.PP +The command returns an empty string, and may generate an error if +an error occurs while flushing output. If a command in a command +pipeline created with \fBopen\fR returns an error, \fBchan close\fR +generates an error (similar to the \fBexec\fR command.) +.PP +.VS 8.6 +Note that half-closes of sockets and command pipelines can have important side +effects because they result in a shutdown() or close() of the underlying +system resource, which can change how other processes or systems respond to +the Tcl program. +.VE 8.6 +.RE +.TP +\fBchan configure \fIchannelId\fR ?\fIoptionName\fR? ?\fIvalue\fR? ?\fIoptionName value\fR?... +. +Query or set the configuration options of the channel named +\fIchannelId\fR. +.RS +.PP +If no \fIoptionName\fR or \fIvalue\fR arguments are supplied, the +command returns a list containing alternating option names and values +for the channel. If \fIoptionName\fR is supplied but no \fIvalue\fR +then the command returns the current value of the given option. If +one or more pairs of \fIoptionName\fR and \fIvalue\fR are supplied, +the command sets each of the named options to the corresponding +\fIvalue\fR; in this case the return value is an empty string. +.PP +The options described below are supported for all channels. In +addition, each channel type may add options that only it supports. See +the manual entry for the command that creates each type of channel +for the options supported by that specific type of channel. For +example, see the manual entry for the \fBsocket\fR command for additional +options for sockets, and the \fBopen\fR command for additional options for +serial devices. +.TP +\fB\-blocking\fR \fIboolean\fR +. +The \fB\-blocking\fR option determines whether I/O operations on the +channel can cause the process to block indefinitely. The value of the +option must be a proper boolean value. Channels are normally in +blocking mode; if a channel is placed into non-blocking mode it will +affect the operation of the \fBchan gets\fR, \fBchan read\fR, \fBchan +puts\fR, \fBchan flush\fR, and \fBchan close\fR commands; see the +documentation for those commands for details. For non-blocking mode to +work correctly, the application must be using the Tcl event loop +(e.g. by calling \fBTcl_DoOneEvent\fR or invoking the \fBvwait\fR +command). +.TP +\fB\-buffering\fR \fInewValue\fR +. +If \fInewValue\fR is \fBfull\fR then the I/O system will buffer output +until its internal buffer is full or until the \fBchan flush\fR +command is invoked. If \fInewValue\fR is \fBline\fR, then the I/O +system will automatically flush output for the channel whenever a +newline character is output. If \fInewValue\fR is \fBnone\fR, the I/O +system will flush automatically after every output operation. The +default is for \fB\-buffering\fR to be set to \fBfull\fR except for +channels that connect to terminal-like devices; for these channels the +initial setting is \fBline\fR. Additionally, \fBstdin\fR and +\fBstdout\fR are initially set to \fBline\fR, and \fBstderr\fR is set +to \fBnone\fR. +.TP +\fB\-buffersize\fR \fInewSize\fR +. +\fINewvalue\fR must be an integer; its value is used to set the size +of buffers, in bytes, subsequently allocated for this channel to store +input or output. \fINewvalue\fR must be a number of no more than one +million, allowing buffers of up to one million bytes in size. +.TP +\fB\-encoding\fR \fIname\fR +. +This option is used to specify the encoding of the channel as one of +the named encodings returned by \fBencoding names\fR or the special +value \fBbinary\fR, so that the data can be converted to and from +Unicode for use in Tcl. For instance, in order for Tcl to read +characters from a Japanese file in \fBshiftjis\fR and properly process +and display the contents, the encoding would be set to \fBshiftjis\fR. +Thereafter, when reading from the channel, the bytes in the Japanese +file would be converted to Unicode as they are read. Writing is also +supported \- as Tcl strings are written to the channel they will +automatically be converted to the specified encoding on output. +.RS +.PP +If a file contains pure binary data (for instance, a JPEG image), the +encoding for the channel should be configured to be \fBbinary\fR. Tcl +will then assign no interpretation to the data in the file and simply +read or write raw bytes. The Tcl \fBbinary\fR command can be used to +manipulate this byte-oriented data. It is usually better to set the +\fB\-translation\fR option to \fBbinary\fR when you want to transfer +binary data, as this turns off the other automatic interpretations of +the bytes in the stream as well. +.PP +The default encoding for newly opened channels is the same platform- +and locale-dependent system encoding used for interfacing with the +operating system, as returned by \fBencoding system\fR. +.RE +.TP +\fB\-eofchar\fR \fIchar\fR +.TP +\fB\-eofchar\fR \fB{\fIinChar outChar\fB}\fR +. +This option supports DOS file systems that use Control-z (\ex1a) as an +end of file marker. If \fIchar\fR is not an empty string, then this +character signals end-of-file when it is encountered during input. +For output, the end-of-file character is output when the channel is +closed. If \fIchar\fR is the empty string, then there is no special +end of file character marker. For read-write channels, a two-element +list specifies the end of file marker for input and output, +respectively. As a convenience, when setting the end-of-file +character for a read-write channel you can specify a single value that +will apply to both reading and writing. When querying the end-of-file +character of a read-write channel, a two-element list will always be +returned. The default value for \fB\-eofchar\fR is the empty string +in all cases except for files under Windows. In that case the +\fB\-eofchar\fR is Control-z (\ex1a) for reading and the empty string +for writing. +The acceptable range for \fB\-eofchar\fR values is \ex01 - \ex7f; +attempting to set \fB\-eofchar\fR to a value outside of this range will +generate an error. +.TP +\fB\-translation\fR \fImode\fR +.TP +\fB\-translation\fR \fB{\fIinMode outMode\fB}\fR +. +In Tcl scripts the end of a line is always represented using a single +newline character (\en). However, in actual files and devices the end +of a line may be represented differently on different platforms, or +even for different devices on the same platform. For example, under +UNIX newlines are used in files, whereas carriage-return-linefeed +sequences are normally used in network connections. On input (i.e., +with \fBchan gets\fR and \fBchan read\fR) the Tcl I/O system +automatically translates the external end-of-line representation into +newline characters. Upon output (i.e., with \fBchan puts\fR), the I/O +system translates newlines to the external end-of-line representation. +The default translation mode, \fBauto\fR, handles all the common cases +automatically, but the \fB\-translation\fR option provides explicit +control over the end of line translations. +.RS +.PP +The value associated with \fB\-translation\fR is a single item for +read-only and write-only channels. The value is a two-element list for +read-write channels; the read translation mode is the first element of +the list, and the write translation mode is the second element. As a +convenience, when setting the translation mode for a read-write channel +you can specify a single value that will apply to both reading and +writing. When querying the translation mode of a read-write channel, a +two-element list will always be returned. The following values are +currently supported: +.TP +\fBauto\fR +. +As the input translation mode, \fBauto\fR treats any of newline +(\fBlf\fR), carriage return (\fBcr\fR), or carriage return followed by +a newline (\fBcrlf\fR) as the end of line representation. The end of +line representation can even change from line-to-line, and all cases +are translated to a newline. As the output translation mode, +\fBauto\fR chooses a platform specific representation; for sockets on +all platforms Tcl chooses \fBcrlf\fR, for all Unix flavors, it chooses +\fBlf\fR, and for the various flavors of Windows it chooses +\fBcrlf\fR. The default setting for \fB\-translation\fR is \fBauto\fR +for both input and output. +.TP +\fBbinary\fR +. +No end-of-line translations are performed. This is nearly identical +to \fBlf\fR mode, except that in addition \fBbinary\fR mode also sets +the end-of-file character to the empty string (which disables it) and +sets the encoding to \fBbinary\fR (which disables encoding filtering). +See the description of \fB\-eofchar\fR and \fB\-encoding\fR for more +information. +.TP +\fBcr\fR +. +The end of a line in the underlying file or device is represented by a +single carriage return character. As the input translation mode, +\fBcr\fR mode converts carriage returns to newline characters. As the +output translation mode, \fBcr\fR mode translates newline characters +to carriage returns. +.TP +\fBcrlf\fR +. +The end of a line in the underlying file or device is represented by a +carriage return character followed by a linefeed character. As the +input translation mode, \fBcrlf\fR mode converts +carriage-return-linefeed sequences to newline characters. As the +output translation mode, \fBcrlf\fR mode translates newline characters +to carriage-return-linefeed sequences. This mode is typically used on +Windows platforms and for network connections. +.TP +\fBlf\fR +. +The end of a line in the underlying file or device is represented by a +single newline (linefeed) character. In this mode no translations +occur during either input or output. This mode is typically used on +UNIX platforms. +.RE +.RE +.TP +\fBchan copy \fIinputChan outputChan\fR ?\fB\-size \fIsize\fR? ?\fB\-command \fIcallback\fR? +. +Copy data from the channel \fIinputChan\fR, which must have been +opened for reading, to the channel \fIoutputChan\fR, which must have +been opened for writing. The \fBchan copy\fR command leverages the +buffering in the Tcl I/O system to avoid extra copies and to avoid +buffering too much data in main memory when copying large files to +slow destinations like network sockets. +.RS +.PP +The \fBchan copy\fR command transfers data from \fIinputChan\fR until +end of file or \fIsize\fR bytes or characters have been transferred; +\fIsize\fR is in bytes if the two channels are using the same encoding, +and is in characters otherwise. If no \fB\-size\fR argument is given, +then the copy goes until end of file. All the data read from +\fIinputChan\fR is copied to \fIoutputChan\fR. Without the +\fB\-command\fR option, \fBchan copy\fR blocks until the copy is +complete and returns the number of bytes or characters (using the same +rules as for the \fB\-size\fR option) written to \fIoutputChan\fR. +.PP +The \fB\-command\fR argument makes \fBchan copy\fR work in the +background. In this case it returns immediately and the +\fIcallback\fR is invoked later when the copy completes. The +\fIcallback\fR is called with one or two additional arguments that +indicates how many bytes were written to \fIoutputChan\fR. If an +error occurred during the background copy, the second argument is the +error string associated with the error. With a background copy, it is +not necessary to put \fIinputChan\fR or \fIoutputChan\fR into +non-blocking mode; the \fBchan copy\fR command takes care of that +automatically. However, it is necessary to enter the event loop by +using the \fBvwait\fR command or by using Tk. +.PP +You are not allowed to do other I/O operations with \fIinputChan\fR or +\fIoutputChan\fR during a background \fBchan copy\fR. If either +\fIinputChan\fR or \fIoutputChan\fR get closed while the copy is in +progress, the current copy is stopped and the command callback is +\fInot\fR made. If \fIinputChan\fR is closed, then all data already +queued for \fIoutputChan\fR is written out. +.PP +Note that \fIinputChan\fR can become readable during a background +copy. You should turn off any \fBchan event\fR or \fBfileevent\fR +handlers during a background copy so those handlers do not interfere +with the copy. Any I/O attempted by a \fBchan event\fR or +\fBfileevent\fR handler will get a +.QW "channel busy" +error. +.PP +\fBChan copy\fR translates end-of-line sequences in \fIinputChan\fR +and \fIoutputChan\fR according to the \fB\-translation\fR option for +these channels (see \fBchan configure\fR above). The translations +mean that the number of bytes read from \fIinputChan\fR can be +different than the number of bytes written to \fIoutputChan\fR. Only +the number of bytes written to \fIoutputChan\fR is reported, either as +the return value of a synchronous \fBchan copy\fR or as the argument +to the callback for an asynchronous \fBchan copy\fR. +.PP +\fBChan copy\fR obeys the encodings and character translations +configured for the channels. This means that the incoming characters +are converted internally first UTF-8 and then into the encoding of the +channel \fBchan copy\fR writes to (see \fBchan configure\fR above for +details on the \fB\-encoding\fR and \fB\-translation\fR options). No +conversion is done if both channels are set to encoding \fBbinary\fR +and have matching translations. If only the output channel is set to +encoding \fBbinary\fR the system will write the internal UTF-8 +representation of the incoming characters. If only the input channel +is set to encoding \fBbinary\fR the system will assume that the +incoming bytes are valid UTF-8 characters and convert them according +to the output encoding. The behaviour of the system for bytes which +are not valid UTF-8 characters is undefined in this case. +.RE +.TP +\fBchan create \fImode cmdPrefix\fR +. +This subcommand creates a new script level channel using the command +prefix \fIcmdPrefix\fR as its handler. Any such channel is called a +\fBreflected\fR channel. The specified command prefix, \fBcmdPrefix\fR, +must be a non-empty list, and should provide the API described in the +\fBrefchan\fR manual page. The handle of the new channel is +returned as the result of the \fBchan create\fR command, and the +channel is open. Use either \fBclose\fR or \fBchan close\fR to remove +the channel. +.RS +.PP +The argument \fImode\fR specifies if the new channel is opened for +reading, writing, or both. It has to be a list containing any of the +strings +.QW \fBread\fR +or +.QW \fBwrite\fR . +The list must have at least one +element, as a channel you can neither write to nor read from makes no +sense. The handler command for the new channel must support the chosen +mode, or an error is thrown. +.PP +The command prefix is executed in the global namespace, at the top of +call stack, following the appending of arguments as described in the +\fBrefchan\fR manual page. Command resolution happens at the +time of the call. Renaming the command, or destroying it means that +the next call of a handler method may fail, causing the channel +command invoking the handler to fail as well. Depending on the +subcommand being invoked, the error message may not be able to explain +the reason for that failure. +.PP +Every channel created with this subcommand knows which interpreter it +was created in, and only ever executes its handler command in that +interpreter, even if the channel was shared with and/or was moved into +a different interpreter. Each reflected channel also knows the thread +it was created in, and executes its handler command only in that +thread, even if the channel was moved into a different thread. To this +end all invocations of the handler are forwarded to the original +thread by posting special events to it. This means that the original +thread (i.e. the thread that executed the \fBchan create\fR command) +must have an active event loop, i.e. it must be able to process such +events. Otherwise the thread sending them will \fIblock +indefinitely\fR. Deadlock may occur. +.PP +Note that this permits the creation of a channel whose two endpoints +live in two different threads, providing a stream-oriented bridge +between these threads. In other words, we can provide a way for +regular stream communication between threads instead of having to send +commands. +.PP +When a thread or interpreter is deleted, all channels created with +this subcommand and using this thread/interpreter as their computing +base are deleted as well, in all interpreters they have been shared +with or moved into, and in whatever thread they have been transferred +to. While this pulls the rug out under the other thread(s) and/or +interpreter(s), this cannot be avoided. Trying to use such a channel +will cause the generation of a regular error about unknown channel +handles. +.PP +This subcommand is \fBsafe\fR and made accessible to safe +interpreters. While it arranges for the execution of arbitrary Tcl +code the system also makes sure that the code is always executed +within the safe interpreter. +.RE +.TP +\fBchan eof \fIchannelId\fR +. +Test whether the last input operation on the channel called +\fIchannelId\fR failed because the end of the data stream was reached, +returning 1 if end-of-file was reached, and 0 otherwise. +.TP +\fBchan event \fIchannelId event\fR ?\fIscript\fR? +. +Arrange for the Tcl script \fIscript\fR to be installed as a \fIfile +event handler\fR to be called whenever the channel called +\fIchannelId\fR enters the state described by \fIevent\fR (which must +be either \fBreadable\fR or \fBwritable\fR); only one such handler may +be installed per event per channel at a time. If \fIscript\fR is the +empty string, the current handler is deleted (this also happens if the +channel is closed or the interpreter deleted). If \fIscript\fR is +omitted, the currently installed script is returned (or an empty +string if no such handler is installed). The callback is only +performed if the event loop is being serviced (e.g. via \fBvwait\fR or +\fBupdate\fR). +.RS +.PP +A file event handler is a binding between a channel and a script, such +that the script is evaluated whenever the channel becomes readable or +writable. File event handlers are most commonly used to allow data to +be received from another process on an event-driven basis, so that the +receiver can continue to interact with the user or with other channels +while waiting for the data to arrive. If an application invokes +\fBchan gets\fR or \fBchan read\fR on a blocking channel when there is +no input data available, the process will block; until the input data +arrives, it will not be able to service other events, so it will +appear to the user to +.QW "freeze up" . +With \fBchan event\fR, the +process can tell when data is present and only invoke \fBchan gets\fR +or \fBchan read\fR when they will not block. +.PP +A channel is considered to be readable if there is unread data +available on the underlying device. A channel is also considered to +be readable if there is unread data in an input buffer, except in the +special case where the most recent attempt to read from the channel +was a \fBchan gets\fR call that could not find a complete line in the +input buffer. This feature allows a file to be read a line at a time +in non-blocking mode using events. A channel is also considered to be +readable if an end of file or error condition is present on the +underlying file or device. It is important for \fIscript\fR to check +for these conditions and handle them appropriately; for example, if +there is no special check for end of file, an infinite loop may occur +where \fIscript\fR reads no data, returns, and is immediately invoked +again. +.PP +A channel is considered to be writable if at least one byte of data +can be written to the underlying file or device without blocking, or +if an error condition is present on the underlying file or device. +Note that client sockets opened in asynchronous mode become writable +when they become connected or if the connection fails. +.PP +Event-driven I/O works best for channels that have been placed into +non-blocking mode with the \fBchan configure\fR command. In blocking +mode, a \fBchan puts\fR command may block if you give it more data +than the underlying file or device can accept, and a \fBchan gets\fR +or \fBchan read\fR command will block if you attempt to read more data +than is ready; no events will be processed while the commands block. +In non-blocking mode \fBchan puts\fR, \fBchan read\fR, and \fBchan +gets\fR never block. +.PP +The script for a file event is executed at global level (outside the +context of any Tcl procedure) in the interpreter in which the \fBchan +event\fR command was invoked. If an error occurs while executing the +script then the command registered with \fBinterp bgerror\fR is used +to report the error. In addition, the file event handler is deleted +if it ever returns an error; this is done in order to prevent infinite +loops due to buggy handlers. +.RE +.TP +\fBchan flush \fIchannelId\fR +. +Ensures that all pending output for the channel called \fIchannelId\fR +is written. +.RS +.PP +If the channel is in blocking mode the command does not return until +all the buffered output has been flushed to the channel. If the +channel is in non-blocking mode, the command may return before all +buffered output has been flushed; the remainder will be flushed in the +background as fast as the underlying file or device is able to absorb +it. +.RE +.TP +\fBchan gets \fIchannelId\fR ?\fIvarName\fR? +. +Reads the next line from the channel called \fIchannelId\fR. If +\fIvarName\fR is not specified, the result of the command will be the +line that has been read (without a trailing newline character) or an +empty string upon end-of-file or, in non-blocking mode, if the data +available is exhausted. If \fIvarName\fR is specified, the line that +has been read will be written to the variable called \fIvarName\fR and +result will be the number of characters that have been read or -1 if +end-of-file was reached or, in non-blocking mode, if the data +available is exhausted. +.RS +.PP +If an end-of-file occurs while part way through reading a line, the +partial line will be returned (or written into \fIvarName\fR). When +\fIvarName\fR is not specified, the end-of-file case can be +distinguished from an empty line using the \fBchan eof\fR command, and +the partial-line-but-non-blocking case can be distinguished with the +\fBchan blocked\fR command. +.RE +.TP +\fBchan names\fR ?\fIpattern\fR? +. +Produces a list of all channel names. If \fIpattern\fR is specified, +only those channel names that match it (according to the rules of +\fBstring match\fR) will be returned. +.TP +\fBchan pending \fImode channelId\fR +. +Depending on whether \fImode\fR is \fBinput\fR or \fBoutput\fR, +returns the number of +bytes of input or output (respectively) currently buffered +internally for \fIchannelId\fR (especially useful in a readable event +callback to impose application-specific limits on input line lengths to avoid +a potential denial-of-service attack where a hostile user crafts +an extremely long line that exceeds the available memory to buffer it). +Returns -1 if the channel was not opened for the mode in question. +.TP +\fBchan pipe\fR +.VS 8.6 +Creates a standalone pipe whose read- and write-side channels are +returned as a 2-element list, the first element being the read side and +the second the write side. Can be useful e.g. to redirect +separately \fBstderr\fR and \fBstdout\fR from a subprocess. To do +this, spawn with "2>@" or +">@" redirection operators onto the write side of a pipe, and then +immediately close it in the parent. This is necessary to get an EOF on +the read side once the child has exited or otherwise closed its output. +.RS +.PP +Note that the pipe buffering semantics can vary at the operating system level +substantially; it is not safe to assume that a write performed on the output +side of the pipe will appear instantly to the input side. This is a +fundamental difference and Tcl cannot conceal it. The overall stream semantics +\fIare\fR compatible, so blocking reads and writes will not see most of the +differences, but the details of what exactly gets written when are not. This +is most likely to show up when using pipelines for testing; care should be +taken to ensure that deadlocks do not occur and that potential short reads are +allowed for. +.RE +.VE 8.6 +.TP +\fBchan pop \fIchannelId\fR +.VS 8.6 +Removes the topmost transformation from the channel \fIchannelId\fR, if there +is any. If there are no transformations added to \fIchannelId\fR, this is +equivalent to \fBchan close\fR of that channel. The result is normally the +empty string, but can be an error in some situations (i.e. where the +underlying system stream is closed and that results in an error). +.VE 8.6 +.TP +\fBchan postevent \fIchannelId eventSpec\fR +. +This subcommand is used by command handlers specified with \fBchan +create\fR. It notifies the channel represented by the handle +\fIchannelId\fR that the event(s) listed in the \fIeventSpec\fR have +occurred. The argument has to be a list containing any of the strings +\fBread\fR and \fBwrite\fR. The list must contain at least one +element as it does not make sense to invoke the command if there are +no events to post. +.RS +.PP +Note that this subcommand can only be used with channel handles that +were created/opened by \fBchan create\fR. All other channels will +cause this subcommand to report an error. +.PP +As only the Tcl level of a channel, i.e. its command handler, should +post events to it we also restrict the usage of this command to the +interpreter that created the channel. In other words, posting events +to a reflected channel from an interpreter that does not contain it's +implementation is not allowed. Attempting to post an event from any +other interpreter will cause this subcommand to report an error. +.PP +Another restriction is that it is not possible to post events that the +I/O core has not registered an interest in. Trying to do so will cause +the method to throw an error. See the command handler method +\fBwatch\fR described in \fBrefchan\fR, the document specifying +the API of command handlers for reflected channels. +.PP +This command is \fBsafe\fR and made accessible to safe interpreters. +It can trigger the execution of \fBchan event\fR handlers, whether in the +current interpreter or in other interpreters or other threads, even +where the event is posted from a safe interpreter and listened for by +a trusted interpreter. \fBChan event\fR handlers are \fIalways\fR +executed in the interpreter that set them up. +.RE +.TP +\fBchan push \fIchannelId cmdPrefix\fR +.VS 8.6 +Adds a new transformation on top of the channel \fIchannelId\fR. The +\fIcmdPrefix\fR argument describes a list of one or more words which represent +a handler that will be used to implement the transformation. The command +prefix must provide the API described in the \fBtranschan\fR manual page. +The result of this subcommand is a handle to the transformation. Note that it +is important to make sure that the transformation is capable of supporting the +channel mode that it is used with or this can make the channel neither +readable nor writable. +.VE 8.6 +.TP +\fBchan puts\fR ?\fB\-nonewline\fR? ?\fIchannelId\fR? \fIstring\fR +. +Writes \fIstring\fR to the channel named \fIchannelId\fR followed by a +newline character. A trailing newline character is written unless the +optional flag \fB\-nonewline\fR is given. If \fIchannelId\fR is +omitted, the string is written to the standard output channel, +\fBstdout\fR. +.RS +.PP +Newline characters in the output are translated by \fBchan puts\fR to +platform-specific end-of-line sequences according to the currently +configured value of the \fB\-translation\fR option for the channel +(for example, on PCs newlines are normally replaced with +carriage-return-linefeed sequences; see \fBchan configure\fR above for +details). +.PP +Tcl buffers output internally, so characters written with \fBchan +puts\fR may not appear immediately on the output file or device; Tcl +will normally delay output until the buffer is full or the channel is +closed. You can force output to appear immediately with the \fBchan +flush\fR command. +.PP +When the output buffer fills up, the \fBchan puts\fR command will +normally block until all the buffered data has been accepted for +output by the operating system. If \fIchannelId\fR is in non-blocking +mode then the \fBchan puts\fR command will not block even if the +operating system cannot accept the data. Instead, Tcl continues to +buffer the data and writes it in the background as fast as the +underlying file or device can accept it. The application must use the +Tcl event loop for non-blocking output to work; otherwise Tcl never +finds out that the file or device is ready for more output data. It +is possible for an arbitrarily large amount of data to be buffered for +a channel in non-blocking mode, which could consume a large amount of +memory. To avoid wasting memory, non-blocking I/O should normally be +used in an event-driven fashion with the \fBchan event\fR command +(do not invoke \fBchan puts\fR unless you have recently been notified +via a file event that the channel is ready for more output data). +.RE +.TP +\fBchan read \fIchannelId\fR ?\fInumChars\fR? +.TP +\fBchan read \fR?\fB\-nonewline\fR? \fIchannelId\fR +. +In the first form, the result will be the next \fInumChars\fR +characters read from the channel named \fIchannelId\fR; if +\fInumChars\fR is omitted, all characters up to the point when the +channel would signal a failure (whether an end-of-file, blocked or +other error condition) are read. In the second form (i.e. when +\fInumChars\fR has been omitted) the flag \fB\-nonewline\fR may be +given to indicate that any trailing newline in the string that has +been read should be trimmed. +.RS +.PP +If \fIchannelId\fR is in non-blocking mode, \fBchan read\fR may not +read as many characters as requested: once all available input has +been read, the command will return the data that is available rather +than blocking for more input. If the channel is configured to use a +multi-byte encoding, then there may actually be some bytes remaining +in the internal buffers that do not form a complete character. These +bytes will not be returned until a complete character is available or +end-of-file is reached. The \fB\-nonewline\fR switch is ignored if +the command returns before reaching the end of the file. +.PP +\fBChan read\fR translates end-of-line sequences in the input into +newline characters according to the \fB\-translation\fR option for the +channel (see \fBchan configure\fR above for a discussion on the ways +in which \fBchan configure\fR will alter input). +.PP +When reading from a serial port, most applications should configure +the serial port channel to be non-blocking, like this: +.PP +.CS +\fBchan configure \fIchannelId \fB\-blocking \fI0\fR. +.CE +.PP +Then \fBchan read\fR behaves much like described above. Note that +most serial ports are comparatively slow; it is entirely possible to +get a \fBreadable\fR event for each character read from them. Care +must be taken when using \fBchan read\fR on blocking serial ports: +.TP +\fBchan read \fIchannelId numChars\fR +. +In this form \fBchan read\fR blocks until \fInumChars\fR have been +received from the serial port. +.TP +\fBchan read \fIchannelId\fR +. +In this form \fBchan read\fR blocks until the reception of the +end-of-file character, see \fBchan configure -eofchar\fR. If there no +end-of-file character has been configured for the channel, then +\fBchan read\fR will block forever. +.RE +.TP +\fBchan seek \fIchannelId offset\fR ?\fIorigin\fR? +. +Sets the current access position within the underlying data stream for +the channel named \fIchannelId\fR to be \fIoffset\fR bytes relative to +\fIorigin\fR. \fIOffset\fR must be an integer (which may be negative) +and \fIorigin\fR must be one of the following: +.RS +.TP 10 +\fBstart\fR +. +The new access position will be \fIoffset\fR bytes from the start +of the underlying file or device. +.TP 10 +\fBcurrent\fR +. +The new access position will be \fIoffset\fR bytes from the current +access position; a negative \fIoffset\fR moves the access position +backwards in the underlying file or device. +.TP 10 +\fBend\fR +. +The new access position will be \fIoffset\fR bytes from the end of the +file or device. A negative \fIoffset\fR places the access position +before the end of file, and a positive \fIoffset\fR places the access +position after the end of file. +.PP +The \fIorigin\fR argument defaults to \fBstart\fR. +.PP +\fBChan seek\fR flushes all buffered output for the channel before the +command returns, even if the channel is in non-blocking mode. It also +discards any buffered and unread input. This command returns an empty +string. An error occurs if this command is applied to channels whose +underlying file or device does not support seeking. +.PP +Note that \fIoffset\fR values are byte offsets, not character offsets. +Both \fBchan seek\fR and \fBchan tell\fR operate in terms of bytes, +not characters, unlike \fBchan read\fR. +.RE +.TP +\fBchan tell \fIchannelId\fR +. +Returns a number giving the current access position within the +underlying data stream for the channel named \fIchannelId\fR. This +value returned is a byte offset that can be passed to \fBchan seek\fR +in order to set the channel to a particular position. Note that this +value is in terms of bytes, not characters like \fBchan read\fR. The +value returned is -1 for channels that do not support seeking. +.TP +\fBchan truncate \fIchannelId\fR ?\fIlength\fR? +. +Sets the byte length of the underlying data stream for the channel +named \fIchannelId\fR to be \fIlength\fR (or to the current byte +offset within the underlying data stream if \fIlength\fR is +omitted). The channel is flushed before truncation. +. +.SH EXAMPLES +.PP +This opens a file using a known encoding (CP1252, a very common encoding +on Windows), searches for a string, rewrites that part, and truncates the +file after a further two lines. +.PP +.CS +set f [open somefile.txt r+] +\fBchan configure\fR $f -encoding cp1252 +set offset 0 + +\fI# Search for string "FOOBAR" in the file\fR +while {[\fBchan gets\fR $f line] >= 0} { + set idx [string first FOOBAR $line] + if {$idx > -1} { + \fI# Found it; rewrite line\fR + + \fBchan seek\fR $f [expr {$offset + $idx}] + \fBchan puts\fR -nonewline $f BARFOO + + \fI# Skip to end of following line, and truncate\fR + \fBchan gets\fR $f + \fBchan gets\fR $f + \fBchan truncate\fR $f + + \fI# Stop searching the file now\fR + break + } + + \fI# Save offset of start of next line for later\fR + set offset [\fBchan tell\fR $f] +} +\fBchan close\fR $f +.CE +.PP +A network server that does echoing of its input line-by-line without +preventing servicing of other connections at the same time. +.PP +.CS +# This is a very simple logger... +proc log {message} { + \fBchan puts\fR stdout $message +} + +# This is called whenever a new client connects to the server +proc connect {chan host port} { + set clientName [format <%s:%d> $host $port] + log "connection from $clientName" + \fBchan configure\fR $chan -blocking 0 -buffering line + \fBchan event\fR $chan readable [list echoLine $chan $clientName] +} + +# This is called whenever either at least one byte of input +# data is available, or the channel was closed by the client. +proc echoLine {chan clientName} { + \fBchan gets\fR $chan line + if {[\fBchan eof\fR $chan]} { + log "finishing connection from $clientName" + \fBchan close\fR $chan + } elseif {![\fBchan blocked\fR $chan]} { + # Didn't block waiting for end-of-line + log "$clientName - $line" + \fBchan puts\fR $chan $line + } +} + +# Create the server socket and enter the event-loop to wait +# for incoming connections... +socket -server connect 12345 +vwait forever +.CE +.SH "SEE ALSO" +close(n), eof(n), fblocked(n), fconfigure(n), fcopy(n), file(n), +fileevent(n), flush(n), gets(n), open(n), puts(n), read(n), seek(n), +socket(n), tell(n), refchan(n), transchan(n) +.SH KEYWORDS +channel, input, output, events, offset +'\" Local Variables: +'\" mode: nroff +'\" End: diff --git a/tcl8.6/doc/class.n b/tcl8.6/doc/class.n new file mode 100644 index 0000000..198ae41 --- /dev/null +++ b/tcl8.6/doc/class.n @@ -0,0 +1,136 @@ +'\" +'\" Copyright (c) 2007 Donal K. Fellows +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH class n 0.1 TclOO "TclOO Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +oo::class \- class of all classes +.SH SYNOPSIS +.nf +package require TclOO + +\fBoo::class\fI method \fR?\fIarg ...\fR? +.fi +.SH "CLASS HIERARCHY" +.nf +\fBoo::object\fR + \(-> \fBoo::class\fR +.fi +.BE +.SH DESCRIPTION +.PP +Classes are objects that can manufacture other objects according to a pattern +stored in the factory object (the class). An instance of the class is created +by calling one of the class's factory methods, typically either \fBcreate\fR +if an explicit name is being given, or \fBnew\fR if an arbitrary unique name +is to be automatically selected. +.PP +The \fBoo::class\fR class is the class of all classes; every class is an +instance of this class, which is consequently an instance of itself. This +class is a subclass of \fBoo::object\fR, so every class is also an object. +Additional metaclasses (i.e., classes of classes) can be defined if necessary +by subclassing \fBoo::class\fR. Note that the \fBoo::class\fR object hides the +\fBnew\fR method on itself, so new classes should always be made using the +\fBcreate\fR method. +.SS CONSTRUCTOR +.PP +The constructor of the \fBoo::class\fR class takes an optional argument which, +if present, is sent to the \fBoo::define\fR command (along with the name of +the newly-created class) to allow the class to be conveniently configured at +creation time. +.SS DESTRUCTOR +The \fBoo::class\fR class does not define an explicit destructor. However, +when a class is destroyed, all its subclasses and instances are also +destroyed, along with all objects that it has been mixed into. +.SS "EXPORTED METHODS" +.TP +\fIcls \fBcreate \fIname \fR?\fIarg ...\fR? +. +This creates a new instance of the class \fIcls\fR called \fIname\fR (which is +resolved within the calling context's namespace if not fully qualified), +passing the arguments, \fIarg ...\fR, to the constructor, and (if that returns +a successful result) returning the fully qualified name of the created object +(the result of the constructor is ignored). If the constructor fails (i.e. +returns a non-OK result) then the object is destroyed and the error message is +the result of this method call. +.TP +\fIcls \fBnew \fR?\fIarg ...\fR? +. +This creates a new instance of the class \fIcls\fR with a new unique name, +passing the arguments, \fIarg ...\fR, to the constructor, and (if that returns +a successful result) returning the fully qualified name of the created object +(the result of the constructor is ignored). If the constructor fails (i.e., +returns a non-OK result) then the object is destroyed and the error message is +the result of this method call. +.RS +.PP +Note that this method is not exported by the \fBoo::class\fR object itself, so +classes should not be created using this method. +.RE +.SS "NON-EXPORTED METHODS" +.PP +The \fBoo::class\fR class supports the following non-exported methods: +.TP +\fIcls \fBcreateWithNamespace\fI name nsName\fR ?\fIarg ...\fR? +. +This creates a new instance of the class \fIcls\fR called \fIname\fR (which is +resolved within the calling context's namespace if not fully qualified), +passing the arguments, \fIarg ...\fR, to the constructor, and (if that returns +a successful result) returning the fully qualified name of the created object +(the result of the constructor is ignored). The name of the instance's +internal namespace will be \fInsName\fR unless that namespace already exists +(when an arbitrary name will be chosen instead). If the constructor fails +(i.e., returns a non-OK result) then the object is destroyed and the error +message is the result of this method call. +.SH EXAMPLES +.PP +This example defines a simple class hierarchy and creates a new instance of +it. It then invokes a method of the object before destroying the hierarchy and +showing that the destruction is transitive. +.PP +.CS +\fBoo::class create\fR fruit { + method eat {} { + puts "yummy!" + } +} +\fBoo::class create\fR banana { + superclass fruit + constructor {} { + my variable peeled + set peeled 0 + } + method peel {} { + my variable peeled + set peeled 1 + puts "skin now off" + } + method edible? {} { + my variable peeled + return $peeled + } + method eat {} { + if {![my edible?]} { + my peel + } + next + } +} +set b [banana \fBnew\fR] +$b eat \fI\(-> prints "skin now off" and "yummy!"\fR +fruit destroy +$b eat \fI\(-> error "unknown command"\fR +.CE +.SH "SEE ALSO" +oo::define(n), oo::object(n) +.SH KEYWORDS +class, metaclass, object +.\" Local variables: +.\" mode: nroff +.\" fill-column: 78 +.\" End: diff --git a/tcl8.6/doc/clock.n b/tcl8.6/doc/clock.n new file mode 100644 index 0000000..889a5da --- /dev/null +++ b/tcl8.6/doc/clock.n @@ -0,0 +1,938 @@ +'\" +'\" Generated from file './doc/clock.dt' by tcllib/doctools with format 'nroff' +'\" Copyright (c) 2004 Kevin B. Kenny <kennykb@acm.org>. All rights reserved. +'\" +.TH "clock" n 8.5 Tcl "Tcl Built-In Commands" +.so man.macros +.BS +.SH NAME +clock \- Obtain and manipulate dates and times +.SH "SYNOPSIS" +package require \fBTcl 8.5\fR +.sp +\fBclock add\fR \fItimeVal\fR ?\fIcount unit...\fR? ?\fI\-option value\fR? +.sp +\fBclock clicks\fR ?\fI\-option\fR? +.sp +\fBclock format\fR \fItimeVal\fR ?\fI\-option value\fR...? +.sp +\fBclock microseconds\fR +.sp +\fBclock milliseconds\fR +.sp +\fBclock scan\fR \fIinputString\fR ?\fI\-option value\fR...? +.sp +\fBclock seconds\fR +.sp +.BE +.SH "DESCRIPTION" +.PP +The \fBclock\fR command performs several operations that obtain and +manipulate values that represent times. The command supports several +subcommands that determine what action is carried out by the command. +.TP +\fBclock add\fR \fItimeVal\fR ?\fIcount unit...\fR? ?\fI\-option value\fR? +Adds a (possibly negative) offset to a time that is expressed as an +integer number of seconds. See \fBCLOCK ARITHMETIC\fR for a full description. +.TP +\fBclock clicks\fR ?\fI\-option\fR? +If no \fI\-option\fR argument is supplied, returns a high-resolution +time value as a system-dependent integer value. The unit of the value +is system-dependent but should be the highest resolution clock available +on the system such as a CPU cycle counter. See \fBHIGH RESOLUTION TIMERS\fR for a full description. +.RS +.PP +If the \fI\-option\fR argument is \fB\-milliseconds\fR, then the command +is synonymous with \fBclock milliseconds\fR (see below). This +usage is obsolete, and \fBclock milliseconds\fR is to be +considered the preferred way of obtaining a count of milliseconds. +.PP +If the \fI\-option\fR argument is \fB\-microseconds\fR, then the command +is synonymous with \fBclock microseconds\fR (see below). This +usage is obsolete, and \fBclock microseconds\fR is to be +considered the preferred way of obtaining a count of microseconds. +.RE +.TP +\fBclock format\fR \fItimeVal\fR ?\fI\-option value\fR...? +Formats a time that is expressed as an integer number of seconds into a format +intended for consumption by users or external programs. +See \fBFORMATTING TIMES\fR for a full description. +.TP +\fBclock microseconds\fR +Returns the current time as an integer number of microseconds. See \fBHIGH RESOLUTION TIMERS\fR for a full description. +.TP +\fBclock milliseconds\fR +Returns the current time as an integer number of milliseconds. See \fBHIGH RESOLUTION TIMERS\fR for a full description. +.TP +\fBclock scan\fR \fIinputString\fR ?\fI\-option value\fR...? +Scans a time that is expressed as a character string and produces an +integer number of seconds. +See \fBSCANNING TIMES\fR for a full description. +.TP +\fBclock seconds\fR +Returns the current time as an integer number of seconds. +.SS "PARAMETERS" +.TP +\fIcount\fR +An integer representing a count of some unit of time. See +\fBCLOCK ARITHMETIC\fR for the details. +.TP +\fItimeVal\fR +An integer value passed to the \fBclock\fR command that represents an +absolute time as a number of seconds from the \fIepoch time\fR of +1 January 1970, 00:00 UTC. Note that the count of seconds does not +include any leap seconds; seconds are counted as if each UTC day has +exactly 86400 seconds. Tcl responds to leap seconds by speeding or +slowing its clock by a tiny fraction for some minutes until it is +back in sync with UTC; its data model does not represent minutes that +have 59 or 61 seconds. +.TP +\fIunit\fR +One of the words, \fBseconds\fR, \fBminutes\fR, \fBhours\fR, +\fBdays\fR, \fBweeks\fR, \fBmonths\fR, or \fByears\fR, or +any unique prefix of such a word. Used in conjunction with \fIcount\fR +to identify an interval of time, for example, \fI3 seconds\fR or +\fI1 year\fR. +.SS "OPTIONS" +.TP +\fB\-base\fR time +Specifies that any relative times present in a \fBclock scan\fR command +are to be given relative to \fItime\fR. \fItime\fR must be expressed as +a count of nominal seconds from the epoch time of 1 January 1970, 00:00 UTC. +.TP +\fB\-format\fR format +Specifies the desired output format for \fBclock format\fR or the +expected input format for \fBclock scan\fR. The \fIformat\fR string consists +of any number of characters other than the per-cent sign +.PQ \fB%\fR +interspersed with any number of \fIformat groups\fR, which are two-character +sequences beginning with the per-cent sign. The permissible format groups, +and their interpretation, are described under \fBFORMAT GROUPS\fR. +.RS +.PP +On \fBclock format\fR, the default format is +.PP +.CS +%a %b %d %H:%M:%S %Z %Y +.CE +.PP +On \fBclock scan\fR, the lack of a \fB\-format\fR option indicates that a +.QW "free format scan" +is requested; see \fBFREE FORM SCAN\fR for a description of what happens. +.RE +.TP +\fB\-gmt\fR boolean +If \fIboolean\fR is true, specifies that a time specified to \fBclock add\fR, +\fBclock format\fR or \fBclock scan\fR should be processed in +UTC. If \fIboolean\fR is false, the processing defaults to the local time +zone. This usage is obsolete; the correct current usage is to +specify the UTC time zone with +.QW "\fB\-timezone\fR \fI:UTC\fR" +or any of the equivalent ways to specify it. +.TP +\fB\-locale\fR localeName +Specifies that locale-dependent scanning and formatting (and date arithmetic +for dates preceding the adoption of the Gregorian calendar) is to be done in +the locale identified by \fIlocaleName\fR. The locale name may be any of +the locales acceptable to the \fBmsgcat\fR package, or it may be the special +name \fIsystem\fR, which represents the current locale of the process, or +the null string, which represents Tcl's default locale. +.RS +.PP +The effect of locale on scanning and formatting is discussed in the +descriptions of the individual format groups under \fBFORMAT GROUPS\fR. +The effect of locale on clock arithmetic is discussed under +\fBCLOCK ARITHMETIC\fR. +.RE +.TP +\fB\-timezone\fR zoneName +Specifies that clock arithmetic, formatting, and scanning are to be done +according to the rules for the time zone specified by \fIzoneName\fR. +The permissible values, and their interpretation, are discussed under +\fBTIME ZONES\fR. +On subcommands that expect a \fB\-timezone\fR argument, the default +is to use the \fIcurrent time zone\fR. The current time zone is +determined, in order of preference, by: +.RS +.IP [1] +the environment variable \fBTCL_TZ\fR. +.IP [2] +the environment variable \fBTZ\fR. +.IP [3] +on Windows systems, the time zone settings from the Control Panel. +.RE +.PP +If none of these is present, the C \fBlocaltime\fR and \fBmktime\fR +functions are used to attempt to convert times between local and +Greenwich. On 32-bit systems, this approach is likely to have bugs, +particularly for times that lie outside the window (approximately the +years 1902 to 2037) that can be represented in a 32-bit integer. +.SH "CLOCK ARITHMETIC" +.PP +The \fBclock add\fR command performs clock arithmetic on a value +(expressed as nominal seconds from the epoch time of 1 January 1970, 00:00 UTC) +given as its first argument. The remaining arguments (other than the +possible \fB\-timezone\fR, \fB\-locale\fR and \fB\-gmt\fR options) +are integers and keywords in alternation, where the keywords are chosen +from \fBseconds\fR, \fBminutes\fR, \fBhours\fR, +\fBdays\fR, \fBweeks\fR, \fBmonths\fR, or \fByears\fR, or +any unique prefix of such a word. +.PP +Addition of seconds, minutes and hours is fairly straightforward; +the given time increment (times sixty for minutes, or 3600 for hours) +is simply added to the \fItimeVal\fR given +to the \fBclock add\fR command. The result is interpreted as +a nominal number of seconds from the Epoch. +.PP +Surprising results +may be obtained when crossing a point at which a leap second is +inserted or removed; the \fBclock add\fR command simply ignores +leap seconds and therefore assumes that times come in sequence, +23:59:58, 23:59:59, 00:00:00. (This assumption is handled by +the fact that Tcl's model of time reacts to leap seconds by speeding +or slowing the clock by a minuscule amount until Tcl's time +is back in step with the world. +.PP +The fact that adding and subtracting hours is defined in terms of +absolute time means that it will add fixed amounts of time in time zones +that observe summer time (Daylight Saving Time). For example, +the following code sets the value of \fBx\fR to \fB04:00:00\fR because +the clock has changed in the interval in question. +.PP +.CS +set s [\fBclock scan\fR {2004-10-30 05:00:00} \e + -format {%Y-%m-%d %H:%M:%S} \e + -timezone :America/New_York] +set a [\fBclock add\fR $s 24 hours -timezone :America/New_York] +set x [\fBclock format\fR $a \e + -format {%H:%M:%S} -timezone :America/New_York] +.CE +.PP +Adding and subtracting days and weeks is accomplished by converting +the given time to a calendar day and time of day in the appropriate +time zone and locale. The requisite number of days (weeks are converted +to days by multiplying by seven) is added to the calendar day, and +the date and time are then converted back to a count of seconds from +the epoch time. +.PP +Adding and subtracting a given number of days across the point that +the time changes at the start or end of summer time (Daylight Saving Time) +results in the \fIsame local time\fR on the day in question. For +instance, the following code sets the value of \fBx\fR to \fB05:00:00\fR. +.PP +.CS +set s [\fBclock scan\fR {2004-10-30 05:00:00} \e + -format {%Y-%m-%d %H:%M:%S} \e + -timezone :America/New_York] +set a [\fBclock add\fR $s 1 day -timezone :America/New_York] +set x [\fBclock format\fR $a \e + -format {%H:%M:%S} -timezone :America/New_York] +.CE +.PP +In cases of ambiguity, where the same local time happens twice +on the same day, the earlier time is used. In cases where the conversion +yields an impossible time (for instance, 02:30 during the Spring +Daylight Saving Time change using US rules), the time is converted +as if the clock had not changed. Thus, the following code +will set the value of \fBx\fR to \fB03:30:00\fR. +.PP +.CS +set s [\fBclock scan\fR {2004-04-03 02:30:00} \e + -format {%Y-%m-%d %H:%M:%S} \e + -timezone :America/New_York] +set a [\fBclock add\fR $s 1 day -timezone :America/New_York] +set x [\fBclock format\fR $a \e + -format {%H:%M:%S} -timezone :America/New_York] +.CE +.PP +Adding a given number of days or weeks works correctly across the conversion +between the Julian and Gregorian calendars; the omitted days are skipped. +The following code sets \fBz\fR to \fB1752-09-14\fR. +.PP +.CS +set x [\fBclock scan\fR 1752-09-02 -format %Y-%m-%d -locale en_US] +set y [\fBclock add\fR $x 1 day -locale en_US] +set z [\fBclock format\fR $y -format %Y-%m-%d -locale en_US] +.CE +.PP +In the bizarre case that adding the given number of days yields a date +that does not exist because it falls within the dropped days of the +Julian-to-Gregorian conversion, the date is converted as if it was +on the Julian calendar. +.PP +Adding a number of months, or a number of years, is similar; it +converts the given time to a calendar date and time of day. It then +adds the requisite number of months or years, and reconverts the resulting +date and time of day to an absolute time. +.PP +If the resulting date is impossible because the month has too few days +(for example, when adding 1 month to 31 January), the last day of the +month is substituted. Thus, adding 1 month to 31 January will result in +28 February in a common year or 29 February in a leap year. +.PP +The rules for handling anomalies relating to summer time and to the +Gregorian calendar are the same when adding/subtracting months and +years as they are when adding/subtracting days and weeks. +.PP +If multiple \fIcount unit\fR pairs are present on the command, they +are evaluated consecutively, from left to right. +.SH "HIGH RESOLUTION TIMERS" +.PP +Most of the subcommands supported by the \fBclock\fR command deal with +times represented as a count of seconds from the epoch time, and this is the +representation that \fBclock seconds\fR returns. There are three exceptions, +which are all intended for use where higher-resolution times are required. +\fBclock milliseconds\fR returns the count of milliseconds from the +epoch time, and \fBclock microseconds\fR returns the count of microseconds +from the epoch time. In addition, there is a \fBclock clicks\fR command +that returns a platform-dependent high-resolution timer. Unlike +\fBclock seconds\fR and \fBclock milliseconds\fR, the value +of \fBclock clicks\fR is not guaranteed to be tied to any fixed +epoch; it is simply intended to be the most precise interval timer +available, and is intended only for relative timing studies such as +benchmarks. +.SH "FORMATTING TIMES" +.PP +The \fBclock format\fR command produces times for display to a user +or writing to an external medium. The command accepts times that are +expressed in seconds from the epoch time of 1 January 1970, 00:00 UTC, +as returned by \fBclock seconds\fR, \fBclock scan\fR, \fBclock add\fR, +\fBfile atime\fR or \fBfile mtime\fR. +.PP +If a \fB\-format\fR option is present, the following argument is +a string that specifies how the date and time are to be formatted. +The string consists +of any number of characters other than the per-cent sign +.PQ \fB%\fR +interspersed with any number of \fIformat groups\fR, which are two-character +sequences beginning with the per-cent sign. The permissible format groups, +and their interpretation, are described under \fBFORMAT GROUPS\fR. +.PP +If a \fB\-timezone\fR option is present, the following +argument is a string that specifies the time zone in which the date and time +are to be formatted. As an alternative to +.QW "\fB\-timezone\fR \fI:UTC\fR" , +the obsolete usage +.QW "\fB\-gmt\fR \fItrue\fR" +may be used. See +\fBTIME ZONES\fR for the permissible variants for the time zone. +.PP +If a \fB\-locale\fR option is present, the following argument is +a string that specifies the locale in which the time is to be formatted, +in the same format that is used for the \fBmsgcat\fR package. Note +that the default, if \fB\-locale\fR is not specified, is the root locale +\fB{}\fR rather than the current locale. The current locale may +be obtained by using \fB\-locale\fR \fBcurrent\fR. +In addition, some platforms support a \fBsystem\fR locale that +reflects the user's current choices. For instance, on Windows, the +format that the user has selected from dates and times in the Control +Panel can be obtained by using the \fBsystem\fR locale. On +platforms that do not define a user selection of date and time formats +separate from \fBLC_TIME\fR, \fB\-locale\fR \fBsystem\fR is +synonymous with \fB\-locale\fR \fBcurrent\fR. +.SH "SCANNING TIMES" +.PP +The \fBclock scan\fR command accepts times that are formatted as +strings and converts them to counts of seconds from the epoch time +of 1 January 1970, 00:00 UTC. It normally takes a \fB\-format\fR +option that is followed by a string describing +the expected format of the input. (See +\fBFREE FORM SCAN\fR for the effect of \fBclock scan\fR +without such an argument.) The string consists of any number of +characters other than the per-cent sign +.PQ \fB%\fR "" , +interspersed with any number of \fIformat groups\fR, which are two-character +sequences beginning with the per-cent sign. The permissible format groups, +and their interpretation, are described under \fBFORMAT GROUPS\fR. +.PP +If a \fB\-timezone\fR option is present, the following +argument is a string that specifies the time zone in which the date and time +are to be interpreted. As an alternative to \fB\-timezone\fR \fI:UTC\fR, +the obsolete usage \fB\-gmt\fR \fItrue\fR may be used. See +\fBTIME ZONES\fR for the permissible variants for the time zone. +.PP +If a \fB\-locale\fR option is present, the following argument is +a string that specifies the locale in which the time is to be interpreted, +in the same format that is used for the \fBmsgcat\fR package. Note +that the default, if \fB\-locale\fR is not specified, is the root locale +\fB{}\fR rather than the current locale. The current locale may +be obtained by using \fB\-locale\fR \fBcurrent\fR. +In addition, some platforms support a \fBsystem\fR locale that +reflects the user's current choices. For instance, on Windows, the +format that the user has selected from dates and times in the Control +Panel can be obtained by using the \fBsystem\fR locale. On +platforms that do not define a user selection of date and time formats +separate from \fBLC_TIME\fR, \fB\-locale\fR \fBsystem\fR is +synonymous with \fB\-locale\fR \fBcurrent\fR. +.PP +If a \fB\-base\fR option is present, the following argument is +a time (expressed in seconds from the epoch time) that is used as +a \fIbase time\fR for interpreting relative times. If no +\fB\-base\fR option is present, the base time is the current time. +.PP +Scanning of times in fixed format works by determining three things: +the date, the time of day, and the time zone. These three are then +combined into a point in time, which is returned as the number of seconds +from the epoch. +.PP +Before scanning begins, the format string is preprocessed +to replace \fB%c\fR, \fB%Ec\fR, \fB%x\fR, \fB%Ex\fR, +\fB%X\fR. \fB%Ex\fR, \fB%r\fR, \fB%R\fR, \fB%T\fR, +\fB%D\fR, \fB%EY\fR and \fB%+\fR format groups with counterparts +that are appropriate to the current locale and contain none of the +above groups. For instance, \fB%D\fR will (in the \fBen_US\fR locale) +be replaced with \fB%m/%d/%Y\fR. +.PP +The date is determined according to the fields that are present in the +preprocessed format string. In order of preference: +.IP [1] +If the string contains a \fB%s\fR format group, representing +seconds from the epoch, that group is used to determine the date. +.IP [2] +If the string contains a \fB%J\fR format group, representing +the Julian Day Number, that group is used to determine the date. +.IP [3] +If the string contains a complete set of format groups specifying +century, year, month, and day of month; century, year, and day of year; +or ISO8601 fiscal year, week of year, and day of week; those groups are +combined and used to determine the date. If more than one complete +set is present, the one at the rightmost position in the string is +used. +.IP [4] +If the string lacks a century but contains a set of format +groups specifying year of century, month and day of month; year of +century and day of year; or two-digit ISO8601 fiscal year, week of year, +and day of week; those groups are +combined and used to determine the date. If more than one complete +set is present, the one at the rightmost position in the string is +used. The year is presumed to lie in the range 1938 to 2037 inclusive. +.IP [5] +If the string entirely lacks any specification for the year +(or contains the year only on the locale's alternative calendar) +and contains a set of format groups specifying month and day of month, +day of year, or week of year and day of week, those groups are +combined and used to determine the date. If more than one complete +set is present, the one at the rightmost position in the string is +used. The year is determined by interpreting the base time in the given +time zone. +.IP [6] +If the string contains none of the above sets, but has a day +of the month or day of the week, the day of the month or day of the week +are used to determine the date by interpreting the base time in the +given time zone and returning the given day of the current week or month. +(The week runs from Monday to Sunday, ISO8601-fashion.) If both day +of month and day of week are present, the day of the month takes +priority. +.IP [7] +If none of the above rules results in a usable date, the date +of the base time in the given time zone is used. +.PP +The time is also determined according to the fields that are present in the +preprocessed format string. In order of preference: +.IP [1] +If the string contains a \fB%s\fR format group, representing +seconds from the epoch, that group determines the time of day. +.IP [2] +If the string contains either an hour on the 24-hour clock +or an hour on the 12-hour clock plus an AM/PM indicator, that hour determines +the hour of the day. If the string further contains a group specifying +the minute of the hour, that group combines with the hour. If the string +further contains a group specifying the second of the minute, that group +combines with the hour and minute. +.IP [3] +If the string contains neither a \fB%s\fR format group nor +a group specifying the hour of the day, then midnight (\fB00:00\fR, the start +of the given date) is used. +The time zone is determined by either the \fB\-timezone\fR or \fB\-gmt\fR +options, or by using the current time zone. +.PP +If a format string lacks a \fB%z\fR or \fB%Z\fR format group, +it is possible for the time to be ambiguous because it appears twice +in the same day, once without and once with Daylight Saving Time. +If this situation occurs, the first occurrence of the time is chosen. +(For this reason, it is wise to have the input string contain the +time zone when converting local times. This caveat does not apply to +UTC times.) +.SH "FORMAT GROUPS" +.PP +The following format groups are recognized by the \fBclock scan\fR and +\fBclock format\fR commands. +.TP +\fB%a\fR +On output, receives an abbreviation (\fIe.g.,\fR \fBMon\fR) for the day +of the week in the given locale. On input, matches the name of the day +of the week in the given locale (in either abbreviated or full form, or +any unique prefix of either form). +.TP +\fB%A\fR +On output, receives the full name (\fIe.g.,\fR \fBMonday\fR) of the day +of the week in the given locale. On input, matches the name of the day +of the week in the given locale (in either abbreviated or full form, or +any unique prefix of either form). +.TP +\fB%b\fR +On output, receives an abbreviation (\fIe.g.,\fR \fBJan\fR) for the name +of the month in the given locale. On input, matches the name of the month +in the given locale (in either abbreviated or full form, or +any unique prefix of either form). +.TP +\fB%B\fR +On output, receives the full name (\fIe.g.,\fR \fBJanuary\fR) +of the month in the given locale. On input, matches the name of the month +in the given locale (in either abbreviated or full form, or +any unique prefix of either form). +.TP +\fB%c\fR +On output, receives a localized representation of date and time of day; +the localized representation is expected to use the Gregorian calendar. +On input, matches whatever \fB%c\fR produces. +.TP +\fB%C\fR +On output, receives the number of the century in Indo-Arabic numerals. +On input, matches one or two digits, possibly with leading whitespace, +that are expected to be the number of the century. +.TP +\fB%d\fR +On output, produces the number of the day of the month, as two decimal +digits. On input, matches one or two digits, possibly with leading +whitespace, that are expected to be the number of the day of the month. +.TP +\fB%D\fR +This format group is synonymous with \fB%m/%d/%Y\fR. It should be +used only in exchanging data within the \fBen_US\fR locale, since +other locales typically do not use this order for the fields of the date. +.TP +\fB%e\fR +On output, produces the number of the day of the month, as one or +two decimal digits (with a leading blank for one-digit dates). +On input, matches one or two digits, possibly with leading +whitespace, that are expected to be the number of the day of the month. +.TP +\fB%Ec\fR +On output, produces a locale-dependent representation of the date and +time of day in the locale's alternative calendar. On input, matches +whatever \fB%Ec\fR produces. The locale's alternative calendar need not +be the Gregorian calendar. +.TP +\fB%EC\fR +On output, produces a locale-dependent name of an era in the locale's +alternative calendar. On input, matches the name of the era or any +unique prefix. +.TP +\fB%EE\fR +On output, produces the string \fBB.C.E.\fR or \fBC.E.\fR, or a +string of the same meaning in the locale, to indicate whether \fB%Y\fR refers +to years before or after Year 1 of the Common Era. On input, accepts +the string \fBB.C.E.\fR, \fBB.C.\fR, \fBC.E.\fR, \fBA.D.\fR, or the +abbreviation appropriate to the current locale, and uses it to fix +whether \fB%Y\fR refers to years before or after Year 1 of the +Common Era. +.TP +\fB%Ex\fR +On output, produces a locale-dependent representation of the date +in the locale's alternative calendar. On input, matches +whatever \fB%Ex\fR produces. The locale's alternative calendar need not +be the Gregorian calendar. +.TP +\fB%EX\fR +On output, produces a locale-dependent representation of the +time of day in the locale's alternative numerals. On input, matches +whatever \fB%EX\fR produces. +.TP +\fB%Ey\fR +On output, produces a locale-dependent number of the year of the era +in the locale's alternative calendar and numerals. On input, matches +such a number. +.TP +\fB%EY\fR +On output, produces a representation of the year in the locale's +alternative calendar and numerals. On input, matches what \fB%EY\fR +produces. Often synonymous with \fB%EC%Ey\fR. +.TP +\fB%g\fR +On output, produces a two-digit year number suitable for use with +the week-based ISO8601 calendar; that is, the year number corresponds +to the week number produced by \fB%V\fR. On input, accepts such +a two-digit year number, possibly with leading whitespace. +.TP +\fB%G\fR +On output, produces a four-digit year number suitable for use with +the week-based ISO8601 calendar; that is, the year number corresponds +to the week number produced by \fB%V\fR. On input, accepts such +a four-digit year number, possibly with leading whitespace. +.TP +\fB%h\fR +This format group is synonymous with \fB%b\fR. +.TP +\fB%H\fR +On output, produces a two-digit number giving the hour of the day +(00-23) on a 24-hour clock. On input, accepts such a number. +.TP +\fB%I\fR +On output, produces a two-digit number giving the hour of the day +(12-11) on a 12-hour clock. On input, accepts such a number. +.TP +\fB%j\fR +On output, produces a three-digit number giving the day of the year +(001-366). On input, accepts such a number. +.TP +\fB%J\fR +On output, produces a string of digits giving the Julian Day Number. +On input, accepts a string of digits and interprets it as a Julian Day Number. +The Julian Day Number is a count of the number of calendar days +that have elapsed since 1 January, 4713 BCE of the proleptic +Julian calendar. The epoch time of 1 January 1970 corresponds +to Julian Day Number 2440588. +.TP +\fB%k\fR +On output, produces a one- or two-digit number giving the hour of the day +(0-23) on a 24-hour clock. On input, accepts such a number. +.TP +\fB%l\fR +On output, produces a one- or two-digit number giving the hour of the day +(12-11) on a 12-hour clock. On input, accepts such a number. +.TP +\fB%m\fR +On output, produces the number of the month (01-12) with exactly two +digits. On input, accepts two digits and interprets them as the number +of the month. +.TP +\fB%M\fR +On output, produces the number of the minute of the hour (00-59) +with exactly two digits. On input, accepts two digits and interprets them +as the number of the minute of the hour. +.TP +\fB%N\fR +On output, produces the number of the month (1-12) with one or two digits, +and a leading blank for one-digit dates. +On input, accepts one or two digits, possibly with leading whitespace, +and interprets them as the number of the month. +.TP +\fB%Od\fR, \fB%Oe\fR, \fB%OH\fR, \fB%OI\fR, \fB%Ok\fR, \fB%Ol\fR, \fB%Om\fR, \fB%OM\fR, \fB%OS\fR, \fB%Ou\fR, \fB%Ow\fR, \fB%Oy\fR +All of these format groups are synonymous with their counterparts +without the +.QW \fBO\fR , +except that the string is produced and parsed in the +locale-dependent alternative numerals. +.TP +\fB%p\fR +On output, produces an indicator for the part of the day, \fBAM\fR +or \fBPM\fR, appropriate to the given locale. If the script of the +given locale supports multiple letterforms, lowercase is preferred. +On input, matches the representation \fBAM\fR or \fBPM\fR in +the given locale, in either case. +.TP +\fB%P\fR +On output, produces an indicator for the part of the day, \fBam\fR +or \fBpm\fR, appropriate to the given locale. If the script of the +given locale supports multiple letterforms, uppercase is preferred. +On input, matches the representation \fBAM\fR or \fBPM\fR in +the given locale, in either case. +.TP +\fB%Q\fR +This format group is reserved for internal use within the Tcl library. +.TP +\fB%r\fR +On output, produces a locale-dependent time of day representation on a +12-hour clock. On input, accepts whatever \fB%r\fR produces. +.TP +\fB%R\fR +On output, the time in 24-hour notation (%H:%M). For a version +including the seconds, see \fB%T\fR below. On input, accepts whatever +\fB%R\fR produces. +.TP +\fB%s\fR +On output, simply formats the \fItimeVal\fR argument as a decimal +integer and inserts it into the output string. On input, accepts +a decimal integer and uses is as the time value without any further +processing. Since \fB%s\fR uniquely determines a point in time, it +overrides all other input formats. +.TP +\fB%S\fR +On output, produces a two-digit number of the second of the minute +(00-59). On input, accepts two digits and uses them as the second of the +minute. +.TP +\fB%t\fR +On output, produces a TAB character. On input, matches a TAB character. +.TP +\fB%T\fR +Synonymous with \fB%H:%M:%S\fR. +.TP +\fB%u\fR +On output, produces the number of the day of the week +(\fB1\fR\(->Monday, \fB7\fR\(->Sunday). On input, accepts a single digit and +interprets it as the day of the week. Sunday may be either \fB0\fR or +\fB7\fR. +.TP +\fB%U\fR +On output, produces the ordinal number of the week of the year +(00-53). The first Sunday of the year is the first day of week 01. On +input accepts two digits which are otherwise ignored. This format +group is never used in determining an input date. This interpretation +of the week of the year was once common in US banking but is now +largely obsolete. See \fB%V\fR for the ISO8601 week number. +.TP +\fB%V\fR +On output, produces the number of the ISO8601 week as a two digit +number (01-53). Week 01 is the week containing January 4; or the first +week of the year containing at least 4 days; or the week containing +the first Thursday of the year (the three statements are +equivalent). Each week begins on a Monday. On input, accepts the +ISO8601 week number. +.TP +\fB%w\fR +On output, produces the ordinal number of the day of the week +(Sunday==0; Saturday==6). On input, accepts a single digit and +interprets it as the day of the week; Sunday may be represented as +either 0 or 7. Note that \fB%w\fR is not the ISO8601 weekday number, +which is produced and accepted by \fB%u\fR. +.TP +\fB%W\fR +On output, produces a week number (00-53) within the year; week 01 +begins on the first Monday of the year. On input, accepts two digits, +which are otherwise ignored. This format group is never used in +determining an input date. It is not the ISO8601 week number; that +week is produced and accepted by \fB%V\fR. +.TP +\fB%x\fR +On output, produces the date in a locale-dependent representation. On +input, accepts whatever \fB%x\fR produces and is used to determine +calendar date. +.TP +\fB%X\fR +On output, produces the time of day in a locale-dependent +representation. On input, accepts whatever \fB%X\fR produces and is used +to determine time of day. +.TP +\fB%y\fR +On output, produces the two-digit year of the century. On input, +accepts two digits, and is used to determine calendar date. The +date is presumed to lie between 1938 and 2037 inclusive. Note +that \fB%y\fR does not yield a year appropriate for use with the ISO8601 +week number \fB%V\fR; programs should use \fB%g\fR for that purpose. +.TP +\fB%Y\fR +On output, produces the four-digit calendar year. On input, +accepts four digits and may be used to determine calendar date. Note +that \fB%Y\fR does not yield a year appropriate for use with the ISO8601 +week number \fB%V\fR; programs should use \fB%G\fR for that purpose. +.TP +\fB%z\fR +On output, produces the current time zone, expressed in hours and +minutes east (+hhmm) or west (\-hhmm) of Greenwich. On input, accepts a +time zone specifier (see \fBTIME ZONES\fR below) that will be used to +determine the time zone. +.TP +\fB%Z\fR +On output, produces the current time zone's name, possibly +translated to the given locale. On input, accepts a time zone +specifier (see \fBTIME ZONES\fR below) that will be used to determine the +time zone. This option should, in general, be used on input only when +parsing RFC822 dates. Other uses are fraught with ambiguity; for +instance, the string \fBBST\fR may represent British Summer Time or +Brazilian Standard Time. It is recommended that date/time strings for +use by computers use numeric time zones instead. +.TP +\fB%%\fR +On output, produces a literal +.QW \fB%\fR +character. On input, matches a literal +.QW \fB%\fR +character. +.TP +\fB%+\fR +Synonymous with +.QW "\fB%a %b %e %H:%M:%S %Z %Y\fR" . +.SH "TIME ZONES" +.PP +When the \fBclock\fR command is processing a local time, it has several +possible sources for the time zone to use. In order of preference, they +are: +.IP [1] +A time zone specified inside a string being parsed and matched by a \fB%z\fR +or \fB%Z\fR format group. +.IP [2] +A time zone specified with the \fB\-timezone\fR option to the \fBclock\fR +command (or, equivalently, by \fB\-gmt\fR \fB1\fR). +.IP [3] +A time zone specified in an environment variable \fBTCL_TZ\fR. +.IP [4] +A time zone specified in an environment variable \fBTZ\fR. +.IP [5] +The local time zone from the Control Panel on Windows systems. +.IP [6] +The C library's idea of the local time zone, as defined by the +\fBmktime\fR and \fBlocaltime\fR functions. +.PP +In case [1] \fIonly,\fR the string is tested to see if it is one +of the strings: +.PP +.CS + gmt ut utc bst wet wat at + nft nst ndt ast adt est edt + cst cdt mst mdt pst pdt yst + ydt hst hdt cat ahst nt idlw + cet cest met mewt mest swt sst + eet eest bt it zp4 zp5 ist + zp6 wast wadt jt cct jst cast + cadt east eadt gst nzt nzst nzdt + idle +.CE +.PP +If it is a string in the above list, it designates a known +time zone, and is interpreted as such. +.PP +For time zones in case [1] that do not match any of the above strings, +and always for cases [2]-[6], the following rules apply. +.PP +If the time zone begins with a colon, it is one of a +standardized list of names like \fB:America/New_York\fR +that give the rules for various locales. A complete list +of the location names is too lengthy to be listed here. +On most Tcl installations, the definitions of the locations +are to be found in named files in the directory +.QW "\fI/no_backup/tools/lib/tcl8.5/clock/tzdata\fR" . +On some Unix systems, these files are omitted, and the definitions are +instead obtained from system files in +.QW "\fI/usr/share/zoneinfo\fR" , +.QW "\fI/usr/share/lib/zoneinfo\fR" +or +.QW "\fI/usr/local/etc/zoneinfo\fR" . +As a special case, the name \fB:localtime\fR refers to +the local time zone as defined by the C library. +.PP +A time zone string consisting of a plus or minus sign followed by +four or six decimal digits is interpreted as an offset in +hours, minutes, and seconds (if six digits are present) from +UTC. The plus sign denotes a sign east of Greenwich; +the minus sign one west of Greenwich. +.PP +A time zone string conforming to the Posix specification of the \fBTZ\fR +environment variable will be recognized. The specification +may be found at +\fIhttp://www.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap08.html\fR. +.PP +If the Posix time zone string contains a DST (Daylight Savings Time) +part, but doesn't contain a rule stating when DST starts or ends, +then default rules are used. For Timezones with an offset between 0 +and +12, the current European/Russian rules are used, otherwise the +current US rules are used. In Europe (offset +0 to +2) the switch +to summertime is done each last Sunday in March at 1:00 GMT, and +the switch back is each last Sunday in October at 2:00 GMT. In +Russia (offset +3 to +12), the switch dates are the same, only +the switch to summertime is at 2:00 local time, and the switch +back is at 3:00 local time in all time zones. The US switch to +summertime takes place each second Sunday in March at 2:00 local +time, and the switch back is each first Sunday in November at +3:00 local time. These default rules mean that in all European, +Russian and US (or compatible) time zones, DST calculations will +be correct for dates in 2007 and later, unless in the future the +rules change again. +.PP +Any other time zone string is processed by prefixing a colon and attempting +to use it as a location name, as above. +.SH "LOCALIZATION" +.PP +Developers wishing to localize the date and time formatting and parsing +are referred to \fIhttp://tip.tcl.tk/173\fR for a +specification. +.SH "FREE FORM SCAN" +.PP +If the \fBclock scan\fR command is invoked without a \fB\-format\fR +option, then it requests a \fIfree-form scan.\fR \fI +This form of scan is deprecated.\fR The reason for the deprecation +is that there are too many ambiguities. (Does the string +.QW 2000 +represent a year, a time of day, or a quantity?) No set of rules +for interpreting free-form dates and times has been found to +give unsurprising results in all cases. +.PP +If free-form scan is used, only the \fB\-base\fR and \fB\-gmt\fR +options are accepted. The \fB\-timezone\fR and \fB\-locale\fR +options will result in an error if \fB\-format\fR is not supplied. +.PP +For the benefit of users who need to understand legacy code that +uses free-form scan, the documentation for how free-form scan +interprets a string is included here: +.PP +If only a time is +specified, the current date is assumed. If the \fIinputString\fR +does not contain a +time zone mnemonic, the local time zone is assumed, unless the \fB\-gmt\fR +argument is true, in which case the clock value is calculated assuming +that the specified time is relative to Greenwich Mean Time. +\fB\-gmt\fR, if specified, affects only the computed time value; it does not +impact the interpretation of \fB\-base\fR. +.PP +If the \fB\-base\fR flag is specified, the next argument should contain +an integer clock value. Only the date in this value is used, not the +time. This is useful for determining the time on a specific day or +doing other date-relative conversions. +.PP +The \fIinputString\fR argument consists of zero or more specifications of the +following form: +.TP +\fItime\fR +A time of day, which is of the form: \fBhh?:mm?:ss?? ?meridian? ?zone?\fR +or \fBhhmm ?meridian? ?zone?\fR +If no meridian is specified, \fBhh\fR is interpreted on +a 24-hour clock. +.TP +\fIdate\fR +A specific month and day with optional year. The +acceptable formats are +.QW "\fBmm/dd\fR?\fB/yy\fR?" , +.QW "\fBmonthname dd\fR?\fB, yy\fR?" , +.QW "\fBday, dd monthname \fR?\fByy\fR?" , +.QW "\fBdd monthname yy\fR" , +.QW "?\fBCC\fR?\fByymmdd\fR" , +and +.QW "\fBdd-monthname-\fR?\fBCC\fR?\fByy\fR" . +The default year is the current year. If the year is less +than 100, we treat the years 00-68 as 2000-2068 and the years 69-99 +as 1969-1999. Not all platforms can represent the years 38-70, so +an error may result if these years are used. +.TP +\fIISO 8601 point-in-time\fR +An ISO 8601 point-in-time specification, such as +.QW \fICCyymmdd\fBT\fIhhmmss\fR, +where \fBT\fR is the literal +.QW T , +.QW "\fICCyymmdd hhmmss\fR" , +or +.QW \fICCyymmdd\fBT\fIhh:mm:ss\fR . +Note that only these three formats are accepted. +The command does \fInot\fR accept the full range of point-in-time +specifications specified in ISO8601. Other formats can be recognized by +giving an explicit \fB\-format\fR option to the \fBclock scan\fR command. +.TP +\fIrelative time\fR +A specification relative to the current time. The format is \fBnumber +unit\fR. Acceptable units are \fByear\fR, \fBfortnight\fR, +\fBmonth\fR, \fBweek\fR, \fBday\fR, +\fBhour\fR, \fBminute\fR (or \fBmin\fR), and \fBsecond\fR (or \fBsec\fR). The +unit can be specified as a singular or plural, as in \fB3 weeks\fR. +These modifiers may also be specified: +\fBtomorrow\fR, \fByesterday\fR, \fBtoday\fR, \fBnow\fR, +\fBlast\fR, \fBthis\fR, \fBnext\fR, \fBago\fR. +.PP +The actual date is calculated according to the following steps. +.PP +First, any absolute date and/or time is processed and converted. +Using that time as the base, day-of-week specifications are added. +Next, relative specifications are used. If a date or day is +specified, and no absolute or relative time is given, midnight is +used. Finally, a correction is applied so that the correct hour of +the day is produced after allowing for daylight savings time +differences and the correct date is given when going from the end +of a long month to a short month. +.SH "SEE ALSO" +msgcat(n) +.SH KEYWORDS +clock, date, time +.SH "COPYRIGHT" +Copyright (c) 2004 Kevin B. Kenny <kennykb@acm.org>. All rights reserved. +'\" Local Variables: +'\" mode: nroff +'\" End: diff --git a/tcl8.6/doc/close.n b/tcl8.6/doc/close.n new file mode 100644 index 0000000..63da75b --- /dev/null +++ b/tcl8.6/doc/close.n @@ -0,0 +1,108 @@ +'\" +'\" Copyright (c) 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. +'\" +.TH close n 7.5 Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +close \- Close an open channel +.SH SYNOPSIS +\fBclose \fIchannelId\fR ?r(ead)|w(rite)? +.BE +.SH DESCRIPTION +.PP +Closes or half-closes the channel given by \fIchannelId\fR. +.PP +\fIChannelId\fR must be an identifier for an open channel such as a +Tcl standard channel (\fBstdin\fR, \fBstdout\fR, or \fBstderr\fR), +the return value from an invocation of \fBopen\fR or \fBsocket\fR, or +the result of a channel creation command provided by a Tcl extension. +.PP +The single-argument form is a simple +.QW "full-close" : +all buffered output is flushed to the channel's output device, +any buffered input is discarded, the underlying file or device is closed, +and \fIchannelId\fR becomes unavailable for use. +.PP +If the channel is blocking, the command does not return until all output +is flushed. +If the channel is nonblocking and there is unflushed output, the +channel remains open and the command +returns immediately; output will be flushed in the background and the +channel will be closed when all the flushing is complete. +.PP +If \fIchannelId\fR is a blocking channel for a command pipeline then +\fBclose\fR waits for the child processes to complete. +.PP +If the channel is shared between interpreters, then \fBclose\fR +makes \fIchannelId\fR unavailable in the invoking interpreter but has no +other effect until all of the sharing interpreters have closed the +channel. +When the last interpreter in which the channel is registered invokes +\fBclose\fR, the cleanup actions described above occur. See the +\fBinterp\fR command for a description of channel sharing. +.PP +Channels are automatically closed when an interpreter is destroyed and +when the process exits. +.VS 8.6 +From 8.6 on (TIP#398), nonblocking channels are no longer switched to blocking mode when exiting; this guarantees a timely exit even when the peer or a communication channel is stalled. To ensure proper flushing of stalled nonblocking channels on exit, one must now either (a) actively switch them back to blocking or (b) use the environment variable TCL_FLUSH_NONBLOCKING_ON_EXIT, which when set and not equal to "0" restores the previous behavior. +.VE 8.6 +.PP +The command returns an empty string, and may generate an error if +an error occurs while flushing output. If a command in a command +pipeline created with \fBopen\fR returns an error, \fBclose\fR +generates an error (similar to the \fBexec\fR command.) +.PP +.VS 8.6 +The two-argument form is a +.QW "half-close" : +given a bidirectional channel like a +socket or command pipeline and a (possibly abbreviated) direction, it closes +only the sub-stream going in that direction. This means a shutdown() on a +socket, and a close() of one end of a pipe for a command pipeline. Then, the +Tcl-level channel data structure is either kept or freed depending on whether +the other direction is still open. +.PP +A single-argument close on an already half-closed bidirectional channel is +defined to just +.QW "finish the job" . +A half-close on an already closed half, or on a wrong-sided unidirectional +channel, raises an error. +.PP +In the case of a command pipeline, the child-reaping duty falls upon the +shoulders of the last close or half-close, which is thus allowed to report an +abnormal exit error. +.PP +Currently only sockets and command pipelines support half-close. A future +extension will allow reflected and stacked channels to do so. +.VE 8.6 +.SH EXAMPLE +.PP +This illustrates how you can use Tcl to ensure that files get closed +even when errors happen by combining \fBcatch\fR, \fBclose\fR and +\fBreturn\fR: +.PP +.CS +proc withOpenFile {filename channelVar script} { + upvar 1 $channelVar chan + set chan [open $filename] + catch { + uplevel 1 $script + } result options + \fBclose\fR $chan + return -options $options $result +} +.CE +.SH "SEE ALSO" +file(n), open(n), socket(n), eof(n), Tcl_StandardChannels(3) +.SH KEYWORDS +blocking, channel, close, nonblocking, half-close +'\" Local Variables: +'\" mode: nroff +'\" fill-column: 78 +'\" End: diff --git a/tcl8.6/doc/concat.n b/tcl8.6/doc/concat.n new file mode 100644 index 0000000..23c6c91 --- /dev/null +++ b/tcl8.6/doc/concat.n @@ -0,0 +1,59 @@ +'\" +'\" Copyright (c) 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. +'\" +.TH concat n 8.3 Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +concat \- Join lists together +.SH SYNOPSIS +\fBconcat\fI \fR?\fIarg arg ...\fR? +.BE +.SH DESCRIPTION +.PP +This command joins each of its arguments together with spaces after +trimming leading and trailing white-space from each of them. If all of the +arguments are lists, this has the same effect as concatenating them +into a single list. +Arguments that are empty (after trimming) are ignored entirely. +It permits any number of arguments; +if no \fIarg\fRs are supplied, the result is an empty string. +.SH EXAMPLES +Although \fBconcat\fR will concatenate lists, flattening them in the process +(so giving the following interactive session): +.PP +.CS +\fI%\fR \fBconcat\fR a b {c d e} {f {g h}} +\fIa b c d e f {g h}\fR +.CE +.PP +it will also concatenate things that are not lists, as can be seen from this +session: +.PP +.CS +\fI%\fR \fBconcat\fR " a b {c " d " e} f" +\fIa b {c d e} f\fR +.CE +.PP +Note also that the concatenation does not remove spaces from the middle of +values, as can be seen here: +.PP +.CS +\fI%\fR \fBconcat\fR "a b c" { d e f } +\fIa b c d e f\fR +.CE +.PP +(i.e., there are three spaces between each of the \fBa\fR, the \fBb\fR and the +\fBc\fR). +.SH "SEE ALSO" +append(n), eval(n), join(n) +.SH KEYWORDS +concatenate, join, list +'\" Local Variables: +'\" mode: nroff +'\" End: diff --git a/tcl8.6/doc/continue.n b/tcl8.6/doc/continue.n new file mode 100644 index 0000000..17d16b4 --- /dev/null +++ b/tcl8.6/doc/continue.n @@ -0,0 +1,47 @@ +'\" +'\" Copyright (c) 1993-1994 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. +'\" +.TH continue n "" Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +continue \- Skip to the next iteration of a loop +.SH SYNOPSIS +\fBcontinue\fR +.BE +.SH DESCRIPTION +.PP +This command is typically invoked inside the body of a looping command +such as \fBfor\fR or \fBforeach\fR or \fBwhile\fR. +It returns a 4 (\fBTCL_CONTINUE\fR) result code, which causes a continue +exception to occur. +The exception causes the current script to be aborted +out to the innermost containing loop command, which then +continues with the next iteration of the loop. +Catch exceptions are also handled in a few other situations, such +as the \fBcatch\fR command and the outermost scripts of procedure +bodies. +.SH EXAMPLE +.PP +Print a line for each of the integers from 0 to 10 \fIexcept\fR 5: +.PP +.CS +for {set x 0} {$x<10} {incr x} { + if {$x == 5} { + \fBcontinue\fR + } + puts "x is $x" +} +.CE +.SH "SEE ALSO" +break(n), for(n), foreach(n), return(n), while(n) +.SH KEYWORDS +continue, iteration, loop +'\" Local Variables: +'\" mode: nroff +'\" End: diff --git a/tcl8.6/doc/copy.n b/tcl8.6/doc/copy.n new file mode 100644 index 0000000..789a76c --- /dev/null +++ b/tcl8.6/doc/copy.n @@ -0,0 +1,76 @@ +'\" +'\" Copyright (c) 2007 Donal K. Fellows +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH copy n 0.1 TclOO "TclOO Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +oo::copy \- create copies of objects and classes +.SH SYNOPSIS +.nf +package require TclOO + +\fBoo::copy\fI sourceObject \fR?\fItargetObject\fR? ?\fItargetNamespace\fR? +.fi +.BE +.SH DESCRIPTION +.PP +The \fBoo::copy\fR command creates a copy of an object or class. It takes the +name of the object or class to be copied, \fIsourceObject\fR, and optionally +the name of the object or class to create, \fItargetObject\fR, which will be +resolved relative to the current namespace if not an absolute qualified name +and +.VS TIP473 +\fItargetNamespace\fR which is the name of the namespace that will hold the +internal state of the object (\fBmy\fR command, etc.); it \fImust not\fR +refer to an existing namespace. +If either \fItargetObject\fR or \fItargetNamespace\fR is omitted or is given +as the empty string, a new name is chosen. Names, unless specified, are +chosen with the same algorithm used by the \fBnew\fR method of +\fBoo::class\fR. +.VE TIP473 +The copied object will be of the same class as the source object, and will have +all its per-object methods copied. If it is a class, it will also have all the +class methods in the class copied, but it will not have any of its instances +copied. +.PP +.VS +After the \fItargetObject\fR has been created and all definitions of its +configuration (e.g., methods, filters, mixins) copied, the \fB<cloned>\fR +method of \fItargetObject\fR will be invoked, to allow for customization of +the created object such as installing related variable traces. The only +argument given will be \fIsourceObject\fR. The default implementation of this +method (in \fBoo::object\fR) just copies the procedures and variables in the +namespace of \fIsourceObject\fR to the namespace of \fItargetObject\fR. If +this method call does not return a result that is successful (i.e., an error +or other kind of exception) then the \fItargetObject\fR will be deleted and an +error returned. +.VE +.PP +The result of the \fBoo::copy\fR command will be the fully-qualified name of +the new object or class. +.SH EXAMPLES +.PP +This example creates an object, copies it, modifies the source object, and +then demonstrates that the copied object is indeed a copy. +.PP +.CS +oo::object create src +oo::objdefine src method msg {} {puts foo} +\fBoo::copy\fR src dst +oo::objdefine src method msg {} {puts bar} +src msg \fI\(-> prints "bar"\fR +dst msg \fI\(-> prints "foo"\fR +.CE +.SH "SEE ALSO" +oo::class(n), oo::define(n), oo::object(n) +.SH KEYWORDS +clone, copy, duplication, object +.\" Local variables: +.\" mode: nroff +.\" fill-column: 78 +.\" End: diff --git a/tcl8.6/doc/coroutine.n b/tcl8.6/doc/coroutine.n new file mode 100644 index 0000000..c99f8d3 --- /dev/null +++ b/tcl8.6/doc/coroutine.n @@ -0,0 +1,205 @@ +'\" +'\" Copyright (c) 2009 Donal K. Fellows. +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH coroutine n 8.6 Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +coroutine, yield, yieldto \- Create and produce values from coroutines +.SH SYNOPSIS +.nf +\fBcoroutine \fIname command\fR ?\fIarg...\fR? +\fByield\fR ?\fIvalue\fR? +.VS TIP396 +\fByieldto\fR \fIcommand\fR ?\fIarg...\fR? +\fIname\fR ?\fIvalue...\fR? +.VE TIP396 +.fi +.BE +.SH DESCRIPTION +.PP +The \fBcoroutine\fR command creates a new coroutine context (with associated +command) named \fIname\fR and executes that context by calling \fIcommand\fR, +passing in the other remaining arguments without further interpretation. Once +\fIcommand\fR returns normally or with an exception (e.g., an error) the +coroutine context \fIname\fR is deleted. +.PP +Within the context, values may be generated as results by using the +\fByield\fR command; if no \fIvalue\fR is supplied, the empty string is used. +When that is called, the context will suspend execution and the +\fBcoroutine\fR command will return the argument to \fByield\fR. The execution +of the context can then be resumed by calling the context command, optionally +passing in the \fIsingle\fR value to use as the result of the \fByield\fR call +that caused +the context to be suspended. If the coroutine context never yields and instead +returns conventionally, the result of the \fBcoroutine\fR command will be the +result of the evaluation of the context. +.PP +.VS TIP396 +The coroutine may also suspend its execution by use of the \fByieldto\fR +command, which instead of returning, cedes execution to some command called +\fIcommand\fR (resolved in the context of the coroutine) and to which \fIany +number\fR of arguments may be passed. Since every coroutine has a context +command, \fByieldto\fR can be used to transfer control directly from one +coroutine to another (this is only advisable if the two coroutines are +expecting this to happen) but \fIany\fR command may be the target. If a +coroutine is suspended by this mechanism, the coroutine processing can be +resumed by calling the context command optionally passing in an arbitrary +number of arguments. The return value of the \fByieldto\fR call will be the +list of arguments passed to the context command; it is up to the caller to +decide what to do with those values. +.PP +The recommended way of writing a version of \fByield\fR that allows resumption +with multiple arguments is by using \fByieldto\fR and the \fBreturn\fR +command, like this: +.PP +.CS +proc yieldm {value} { + \fByieldto\fR return -level 0 $value +} +.CE +.VE TIP396 +.PP +The coroutine can also be deleted by destroying the command \fIname\fR, and +the name of the current coroutine can be retrieved by using +\fBinfo coroutine\fR. +If there are deletion traces on variables in the coroutine's +implementation, they will fire at the point when the coroutine is explicitly +deleted (or, naturally, if the command returns conventionally). +.PP +At the point when \fIcommand\fR is called, the current namespace will be the +global namespace and there will be no stack frames above it (in the sense of +\fBupvar\fR and \fBuplevel\fR). However, which command to call will be +determined in the namespace that the \fBcoroutine\fR command was called from. +.SH EXAMPLES +.PP +This example shows a coroutine that will produce an infinite sequence of +even values, and a loop that consumes the first ten of them. +.PP +.CS +proc allNumbers {} { + \fByield\fR + set i 0 + while 1 { + \fByield\fR $i + incr i 2 + } +} +\fBcoroutine\fR nextNumber allNumbers +for {set i 0} {$i < 10} {incr i} { + puts "received [\fInextNumber\fR]" +} +rename nextNumber {} +.CE +.PP +In this example, the coroutine acts to add up the arguments passed to it. +.PP +.CS +\fBcoroutine\fR accumulator apply {{} { + set x 0 + while 1 { + incr x [\fByield\fR $x] + } +}} +for {set i 0} {$i < 10} {incr i} { + puts "$i -> [\fIaccumulator\fR $i]" +} +.CE +.PP +This example demonstrates the use of coroutines to implement the classic Sieve +of Eratosthenes algorithm for finding prime numbers. Note the creation of +coroutines inside a coroutine. +.PP +.CS +proc filterByFactor {source n} { + \fByield\fR [info coroutine] + while 1 { + set x [\fI$source\fR] + if {$x % $n} { + \fByield\fR $x + } + } +} +\fBcoroutine\fR allNumbers apply {{} {while 1 {\fByield\fR [incr x]}}} +\fBcoroutine\fR eratosthenes apply {c { + \fByield\fR + while 1 { + set n [\fI$c\fR] + \fByield\fR $n + set c [\fBcoroutine\fR prime$n filterByFactor $c $n] + } +}} allNumbers +for {set i 1} {$i <= 20} {incr i} { + puts "prime#$i = [\fIeratosthenes\fR]" +} +.CE +.PP +.VS TIP396 +This example shows how a value can be passed around a group of three +coroutines that yield to each other: +.PP +.CS +proc juggler {name target {value ""}} { + if {$value eq ""} { + set value [\fByield\fR [info coroutine]] + } + while {$value ne ""} { + puts "$name : $value" + set value [string range $value 0 end-1] + lassign [\fByieldto\fR $target $value] value + } +} +\fBcoroutine\fR j1 juggler Larry [ + \fBcoroutine\fR j2 juggler Curly [ + \fBcoroutine\fR j3 juggler Moe j1]] "Nyuck!Nyuck!Nyuck!" +.CE +.VE TIP396 +.SS "DETAILED SEMANTICS" +.PP +This example demonstrates that coroutines start from the global namespace, and +that \fIcommand\fR resolution happens before the coroutine stack is created. +.PP +.CS +proc report {where level} { + # Where was the caller called from? + set ns [uplevel 2 {namespace current}] + \fByield\fR "made $where $level context=$ns name=[info coroutine]" +} +proc example {} { + report outer [info level] +} +namespace eval demo { + proc example {} { + report inner [info level] + } + proc makeExample {} { + puts "making from [info level]" + puts [\fBcoroutine\fR coroEg example] + } + makeExample +} +.CE +.PP +Which produces the output below. In particular, we can see that stack +manipulation has occurred (comparing the levels from the first and second +line) and that the parent level in the coroutine is the global namespace. We +can also see that coroutine names are local to the current namespace if not +qualified, and that coroutines may yield at depth (e.g., in called +procedures). +.PP +.CS +making from 2 +made inner 1 context=:: name=::demo::coroEg +.CE +.SH "SEE ALSO" +apply(n), info(n), proc(n), return(n) +.SH KEYWORDS +coroutine, generator +'\" Local Variables: +'\" mode: nroff +'\" fill-column: 78 +'\" End: diff --git a/tcl8.6/doc/dde.n b/tcl8.6/doc/dde.n new file mode 100644 index 0000000..ac3d8ed --- /dev/null +++ b/tcl8.6/doc/dde.n @@ -0,0 +1,189 @@ +'\" +'\" Copyright (c) 1997 Sun Microsystems, Inc. +'\" Copyright (c) 2001 ActiveState Corporation. +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH dde n 1.4 dde "Tcl Bundled Packages" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +dde \- Execute a Dynamic Data Exchange command +.SH SYNOPSIS +.sp +\fBpackage require dde 1.4\fR +.sp +\fBdde servername\fR ?\fB\-force\fR? ?\fB\-handler \fIproc\fR? ?\fB\-\|\-\fR? ?\fItopic\fR? +.sp +.VS 8.6 +\fBdde execute\fR ?\fB\-async\fR? ?\fB\-binary\fR? \fIservice topic data\fR +.sp +\fBdde poke\fR ?\fB\-binary\fR? \fIservice topic item data\fR +.VE 8.6 +.sp +\fBdde request\fR ?\fB\-binary\fR? \fIservice topic item\fR +.sp +\fBdde services \fIservice topic\fR +.sp +\fBdde eval\fR ?\fB\-async\fR? \fItopic cmd \fR?\fIarg arg ...\fR? +.BE + +.SH DESCRIPTION +.PP +This command allows an application to send Dynamic Data Exchange (DDE) +command when running under Microsoft Windows. Dynamic Data Exchange is +a mechanism where applications can exchange raw data. Each DDE +transaction needs a \fIservice name\fR and a \fItopic\fR. Both the +\fIservice name\fR and \fItopic\fR are application defined; Tcl uses +the service name \fBTclEval\fR, while the topic name is the name of the +interpreter given by \fBdde servername\fR. Other applications have their +own \fIservice names\fR and \fItopics\fR. For instance, Microsoft Excel +has the service name \fBExcel\fR. +.PP +.SH "DDE COMMANDS" +.PP +The following commands are a subset of the full Dynamic Data Exchange +set of commands. +.TP +\fBdde servername \fR?\fB\-force\fR? ?\fB\-handler \fIproc\fR? ?\fB\-\|\-\fR? ?\fItopic\fR? +. +\fBdde servername\fR registers the interpreter as a DDE server with +the service name \fBTclEval\fR and the topic name specified by \fItopic\fR. +If no \fItopic\fR is given, \fBdde servername\fR returns the name +of the current topic or the empty string if it is not registered as a +service. If the given \fItopic\fR name is already in use, then a +suffix of the form +.QW " #2" +or +.QW " #3" +is appended to the name to make it +unique. The command's result will be the name actually used. The +\fB\-force\fR option is used to force registration of precisely the +given \fItopic\fR name. +.RS +.PP +The \fB\-handler\fR option specifies a Tcl procedure that will be called to +process calls to the dde server. If the package has been loaded into a +safe interpreter then a \fB\-handler\fR procedure must be defined. The +procedure is called with all the arguments provided by the remote +call. +.RE +.TP +\fBdde execute\fR ?\fB\-async\fR? ?\fB\-binary\fR? \fIservice topic data\fR +. +\fBdde execute\fR takes the \fIdata\fR and sends it to the server indicated +by \fIservice\fR with the topic indicated by \fItopic\fR. Typically, +\fIservice\fR is the name of an application, and \fItopic\fR is a file to +work on. The \fIdata\fR field is given to the remote application. +Typically, the application treats the \fIdata\fR field as a script, and the +script is run in the application. The \fB\-async\fR option requests +asynchronous invocation. The command returns an error message if the +script did not run, unless the \fB\-async\fR flag was used, in which case +the command returns immediately with no error. +.VS 8.6 +Without the \fB\-binary\fR option all data will be sent in unicode. For +dde clients which don't implement the CF_UNICODE clipboard format, this +will automatically be translated to the system encoding. You can use +the \fB\-binary\fR option in combination with the result of +\fBencoding convertto\fR to send data in any other encoding. +.VE 8.6 +.TP +\fBdde poke\fR ?\fB\-binary\fR? \fIservice topic item data\fR +. +\fBdde poke\fR passes the \fIdata\fR to the server indicated by +\fIservice\fR using the \fItopic\fR and \fIitem\fR specified. Typically, +\fIservice\fR is the name of an application. \fItopic\fR is application +specific but can be a command to the server or the name of a file to work +on. The \fIitem\fR is also application specific and is often not used, but +it must always be non-null. The \fIdata\fR field is given to the remote +application. +.VS 8.6 +Without the \fB\-binary\fR option all data will be sent in unicode. For +dde clients which don't implement the CF_UNICODE clipboard format, this +will automatically be translated to the system encoding. You can use +the \fB\-binary\fR option in combination with the result of +\fBencoding convertto\fR to send data in any other encoding. +.VE 8.6 +.TP +\fBdde request\fR ?\fB\-binary\fR? \fIservice topic item\fR +. +\fBdde request\fR is typically used to get the value of something; the +value of a cell in Microsoft Excel or the text of a selection in +Microsoft Word. \fIservice\fR is typically the name of an application, +\fItopic\fR is typically the name of the file, and \fIitem\fR is +application-specific. The command returns the value of \fIitem\fR as +defined in the application. Normally this is interpreted to be a +string with terminating null. If \fB\-binary\fR is specified, the +result is returned as a byte array. +.TP +\fBdde services \fIservice topic\fR +. +\fBdde services\fR returns a list of service-topic pairs that +currently exist on the machine. If \fIservice\fR and \fItopic\fR are +both empty strings ({}), then all service-topic pairs currently +available on the system are returned. If \fIservice\fR is empty and +\fItopic\fR is not, then all services with the specified topic are +returned. If \fIservice\fR is non-empty and \fItopic\fR is, all topics +for a given service are returned. If both are non-empty, if that +service-topic pair currently exists, it is returned; otherwise, an +empty string is returned. +.TP +\fBdde eval\fR ?\fB\-async\fR? \fItopic cmd \fR?\fIarg arg ...\fR? +. +\fBdde eval\fR evaluates a command and its arguments using the interpreter +specified by \fItopic\fR. The DDE service must be the \fBTclEval\fR +service. The \fB\-async\fR option requests asynchronous invocation. The +command returns an error message if the script did not run, unless the +\fB\-async\fR flag was used, in which case the command returns immediately +with no error. This command can be used to replace send on Windows. +.SH "DDE AND TCL" +.PP +A Tcl interpreter always has a service name of \fBTclEval\fR. Each +different interpreter of all running Tcl applications must be +given a unique +name specified by \fBdde servername\fR. Each interp is available as a +DDE topic only if the \fBdde servername\fR command was used to set the +name of the topic for each interp. So a \fBdde services TclEval {}\fR +command will return a list of service-topic pairs, where each of the +currently running interps will be a topic. +.PP +When Tcl processes a \fBdde execute\fR command, the data for the +execute is run as a script in the interp named by the topic of the +\fBdde execute\fR command. +.PP +When Tcl processes a \fBdde request\fR command, it returns the value of the +variable given in the dde command in the context of the interp named by the +dde topic. Tcl reserves the variable \fB$TCLEVAL$EXECUTE$RESULT\fR for +internal use, and \fBdde request\fR commands for that variable will give +unpredictable results. +.PP +An external application which wishes to run a script in Tcl should have +that script store its result in a variable, run the \fBdde execute\fR +command, and then run \fBdde request\fR to get the value of the +variable. +.PP +When using DDE, be careful to ensure that the event queue is flushed +using either \fBupdate\fR or \fBvwait\fR. This happens by default +when using \fBwish\fR unless a blocking command is called (such as \fBexec\fR +without adding the \fB&\fR to place the process in the background). +If for any reason the event queue is not flushed, DDE commands may +hang until the event queue is flushed. This can create a deadlock +situation. +.SH EXAMPLE +.PP +This asks Internet Explorer (which must already be running) to go to a +particularly important website: +.PP +.CS +package require dde +\fBdde execute\fR -async iexplore WWW_OpenURL http://www.tcl.tk/ +.CE +.SH "SEE ALSO" +tk(n), winfo(n), send(n) +.SH KEYWORDS +application, dde, name, remote execution +'\"Local Variables: +'\"mode: nroff +'\"End: diff --git a/tcl8.6/doc/define.n b/tcl8.6/doc/define.n new file mode 100644 index 0000000..7599ec0 --- /dev/null +++ b/tcl8.6/doc/define.n @@ -0,0 +1,404 @@ +'\" +'\" Copyright (c) 2007 Donal K. Fellows +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH define n 0.3 TclOO "TclOO Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +oo::define, oo::objdefine \- define and configure classes and objects +.SH SYNOPSIS +.nf +package require TclOO + +\fBoo::define\fI class defScript\fR +\fBoo::define\fI class subcommand arg\fR ?\fIarg ...\fR? +\fBoo::objdefine\fI object defScript\fR +\fBoo::objdefine\fI object subcommand arg\fR ?\fIarg ...\fR? +.fi +.BE + +.SH DESCRIPTION +The \fBoo::define\fR command is used to control the configuration of classes, +and the \fBoo::objdefine\fR command is used to control the configuration of +objects (including classes as instance objects), with the configuration being +applied to the entity named in the \fIclass\fR or the \fIobject\fR argument. +Configuring a class also updates the +configuration of all subclasses of the class and all objects that are +instances of that class or which mix it in (as modified by any per-instance +configuration). The way in which the configuration is done is controlled by +either the \fIdefScript\fR argument or by the \fIsubcommand\fR and following +\fIarg\fR arguments; when the second is present, it is exactly as if all the +arguments from \fIsubcommand\fR onwards are made into a list and that list is +used as the \fIdefScript\fR argument. +.SS "CONFIGURING CLASSES" +.PP +The following commands are supported in the \fIdefScript\fR for +\fBoo::define\fR, each of which may also be used in the \fIsubcommand\fR form: +.TP +\fBconstructor\fI argList bodyScript\fR +. +This creates or updates the constructor for a class. The formal arguments to +the constructor (defined using the same format as for the Tcl \fBproc\fR +command) will be \fIargList\fR, and the body of the constructor will be +\fIbodyScript\fR. When the body of the constructor is evaluated, the current +namespace of the constructor will be a namespace that is unique to the object +being constructed. Within the constructor, the \fBnext\fR command should be +used to call the superclasses' constructors. If \fIbodyScript\fR is the empty +string, the constructor will be deleted. +.TP +\fBdeletemethod\fI name\fR ?\fIname ...\fR +. +This deletes each of the methods called \fIname\fR from a class. The methods +must have previously existed in that class. Does not affect the superclasses +of the class, nor does it affect the subclasses or instances of the class +(except when they have a call chain through the class being modified). +.TP +\fBdestructor\fI bodyScript\fR +. +This creates or updates the destructor for a class. Destructors take no +arguments, and the body of the destructor will be \fIbodyScript\fR. The +destructor is called when objects of the class are deleted, and when called +will have the object's unique namespace as the current namespace. Destructors +should use the \fBnext\fR command to call the superclasses' destructors. Note +that destructors are not called in all situations (e.g. if the interpreter is +destroyed). If \fIbodyScript\fR is the empty string, the destructor will be +deleted. +.RS +Note that errors during the evaluation of a destructor \fIare not returned\fR +to the code that causes the destruction of an object. Instead, they are passed +to the currently-defined \fBbgerror\fR handler. +.RE +.TP +\fBexport\fI name \fR?\fIname ...\fR? +. +This arranges for each of the named methods, \fIname\fR, to be exported +(i.e. usable outside an instance through the instance object's command) by the +class being defined. Note that the methods themselves may be actually defined +by a superclass; subclass exports override superclass visibility, and may in +turn be overridden by instances. +.TP +\fBfilter\fR ?\fI\-slotOperation\fR? ?\fImethodName ...\fR? +.VS +This slot (see \fBSLOTTED DEFINITIONS\fR below) +.VE +sets or updates the list of method names that are used to guard whether +method call to instances of the class may be called and what the method's +results are. Each \fImethodName\fR names a single filtering method (which may +be exposed or not exposed); it is not an error for a non-existent method to be +named since they may be defined by subclasses. +.VS +By default, this slot works by appending. +.VE +.TP +\fBforward\fI name cmdName \fR?\fIarg ...\fR? +. +This creates or updates a forwarded method called \fIname\fR. The method is +defined be forwarded to the command called \fIcmdName\fR, with additional +arguments, \fIarg\fR etc., added before those arguments specified by the +caller of the method. The \fIcmdName\fR will always be resolved using the +rules of the invoking objects' namespaces, i.e., when \fIcmdName\fR is not +fully-qualified, the command will be searched for in each object's namespace, +using the instances' namespace's path, or by looking in the global namespace. +The method will be exported if \fIname\fR starts with a lower-case letter, and +non-exported otherwise. +.TP +\fBmethod\fI name argList bodyScript\fR +. +This creates or updates a method that is implemented as a procedure-like +script. The name of the method is \fIname\fR, the formal arguments to the +method (defined using the same format as for the Tcl \fBproc\fR command) will +be \fIargList\fR, and the body of the method will be \fIbodyScript\fR. When +the body of the method is evaluated, the current namespace of the method will +be a namespace that is unique to the current object. The method will be +exported if \fIname\fR starts with a lower-case letter, and non-exported +otherwise; this behavior can be overridden via \fBexport\fR and +\fBunexport\fR. +.TP +\fBmixin\fR ?\fI\-slotOperation\fR? ?\fIclassName ...\fR? +.VS +This slot (see \fBSLOTTED DEFINITIONS\fR below) +.VE +sets or updates the list of additional classes that are to be mixed into +all the instances of the class being defined. Each \fIclassName\fR argument +names a single class that is to be mixed in. +.VS +By default, this slot works by replacement. +.VE +.TP +\fBrenamemethod\fI fromName toName\fR +. +This renames the method called \fIfromName\fR in a class to \fItoName\fR. The +method must have previously existed in the class, and \fItoName\fR must not +previously refer to a method in that class. Does not affect the superclasses +of the class, nor does it affect the subclasses or instances of the class +(except when they have a call chain through the class being modified). Does +not change the export status of the method; if it was exported before, it will +be afterwards. +.TP +\fBself\fI subcommand arg ...\fR +.TP +\fBself\fI script\fR +. +This command is equivalent to calling \fBoo::objdefine\fR on the class being +defined (see \fBCONFIGURING OBJECTS\fR below for a description of the +supported values of \fIsubcommand\fR). It follows the same general pattern of +argument handling as the \fBoo::define\fR and \fBoo::objdefine\fR commands, +and +.QW "\fBoo::define \fIcls \fBself \fIsubcommand ...\fR" +operates identically to +.QW "\fBoo::objdefine \fIcls subcommand ...\fR" . +.TP +\fBsuperclass\fR ?\fI\-slotOperation\fR? ?\fIclassName ...\fR? +.VS +This slot (see \fBSLOTTED DEFINITIONS\fR below) +.VE +allows the alteration of the superclasses of the class being defined. +Each \fIclassName\fR argument names one class that is to be a superclass of +the defined class. Note that objects must not be changed from being classes to +being non-classes or vice-versa, that an empty parent class is equivalent to +\fBoo::object\fR, and that the parent classes of \fBoo::object\fR and +\fBoo::class\fR may not be modified. +.VS +By default, this slot works by replacement. +.VE +.TP +\fBunexport\fI name \fR?\fIname ...\fR? +. +This arranges for each of the named methods, \fIname\fR, to be not exported +(i.e. not usable outside the instance through the instance object's command, +but instead just through the \fBmy\fR command visible in each object's +context) by the class being defined. Note that the methods themselves may be +actually defined by a superclass; subclass unexports override superclass +visibility, and may be overridden by instance unexports. +.TP +\fBvariable\fR ?\fI\-slotOperation\fR? ?\fIname ...\fR? +.VS +This slot (see \fBSLOTTED DEFINITIONS\fR below) arranges for each of the named +variables to be automatically made +available in the methods, constructor and destructor declared by the class +being defined. Each variable name must not have any namespace +separators and must not look like an array access. All variables will be +actually present in the instance object on which the method is executed. Note +that the variable lists declared by a superclass or subclass are completely +disjoint, as are variable lists declared by instances; the list of variable +names is just for methods (and constructors and destructors) declared by this +class. By default, this slot works by appending. +.VE +.SS "CONFIGURING OBJECTS" +.PP +The following commands are supported in the \fIdefScript\fR for +\fBoo::objdefine\fR, each of which may also be used in the \fIsubcommand\fR +form: +.TP +\fBclass\fI className\fR +. +This allows the class of an object to be changed after creation. Note that the +class's constructors are not called when this is done, and so the object may +well be in an inconsistent state unless additional configuration work is done. +.TP +\fBdeletemethod\fI name\fR ?\fIname ...\fR +. +This deletes each of the methods called \fIname\fR from an object. The methods +must have previously existed in that object. Does not affect the classes that +the object is an instance of. +.TP +\fBexport\fI name \fR?\fIname ...\fR? +. +This arranges for each of the named methods, \fIname\fR, to be exported +(i.e. usable outside the object through the object's command) by the object +being defined. Note that the methods themselves may be actually defined by a +class or superclass; object exports override class visibility. +.TP +\fBfilter\fR ?\fI\-slotOperation\fR? ?\fImethodName ...\fR? +.VS +This slot (see \fBSLOTTED DEFINITIONS\fR below) +.VE +sets or updates the list of method names that are used to guard whether a +method call to the object may be called and what the method's results are. +Each \fImethodName\fR names a single filtering method (which may be exposed or +not exposed); it is not an error for a non-existent method to be named. Note +that the actual list of filters also depends on the filters set upon any +classes that the object is an instance of. +.VS +By default, this slot works by appending. +.VE +.TP +\fBforward\fI name cmdName \fR?\fIarg ...\fR? +. +This creates or updates a forwarded object method called \fIname\fR. The +method is defined be forwarded to the command called \fIcmdName\fR, with +additional arguments, \fIarg\fR etc., added before those arguments specified +by the caller of the method. Forwarded methods should be deleted using the +\fBmethod\fR subcommand. The method will be exported if \fIname\fR starts with +a lower-case letter, and non-exported otherwise. +.TP +\fBmethod\fI name argList bodyScript\fR +. +This creates, updates or deletes an object method. The name of the method is +\fIname\fR, the formal arguments to the method (defined using the same format +as for the Tcl \fBproc\fR command) will be \fIargList\fR, and the body of the +method will be \fIbodyScript\fR. When the body of the method is evaluated, the +current namespace of the method will be a namespace that is unique to the +object. The method will be exported if \fIname\fR starts with a lower-case +letter, and non-exported otherwise. +.TP +\fBmixin\fR ?\fI\-slotOperation\fR? ?\fIclassName ...\fR? +.VS +This slot (see \fBSLOTTED DEFINITIONS\fR below) +.VE +sets or updates a per-object list of additional classes that are to be +mixed into the object. Each argument, \fIclassName\fR, names a single class +that is to be mixed in. +.VS +By default, this slot works by replacement. +.VE +.TP +\fBrenamemethod\fI fromName toName\fR +. +This renames the method called \fIfromName\fR in an object to \fItoName\fR. +The method must have previously existed in the object, and \fItoName\fR must +not previously refer to a method in that object. Does not affect the classes +that the object is an instance of. Does not change the export status of the +method; if it was exported before, it will be afterwards. +.TP +\fBunexport\fI name \fR?\fIname ...\fR? +. +This arranges for each of the named methods, \fIname\fR, to be not exported +(i.e. not usable outside the object through the object's command, but instead +just through the \fBmy\fR command visible in the object's context) by the +object being defined. Note that the methods themselves may be actually defined +by a class; instance unexports override class visibility. +.TP +\fBvariable\fR ?\fI\-slotOperation\fR? ?\fIname ...\fR? +.VS +This slot (see \fBSLOTTED DEFINITIONS\fR below) arranges for each of the named +variables to be automatically made available in the methods declared by the +object being defined. Each variable name must not have any namespace +separators and must not look like an array access. All variables will be +actually present in the object on which the method is executed. Note that the +variable lists declared by the classes and mixins of which the object is an +instance are completely disjoint; the list of variable names is just for +methods declared by this object. By default, this slot works by appending. +.SH "SLOTTED DEFINITIONS" +Some of the configurable definitions of a class or object are \fIslotted +definitions\fR. This means that the configuration is implemented by a slot +object, that is an instance of the class \fBoo::Slot\fR, which manages a list +of values (class names, variable names, etc.) that comprises the contents of +the slot. The class defines three operations (as methods) that may be done on +the slot: +.VE +.TP +\fIslot\fR \fB\-append\fR ?\fImember ...\fR? +.VS +This appends the given \fImember\fR elements to the slot definition. +.VE +.TP +\fIslot\fR \fB\-clear\fR +.VS +This sets the slot definition to the empty list. +.VE +.TP +\fIslot\fR \fB\-set\fR ?\fImember ...\fR? +.VS +This replaces the slot definition with the given \fImember\fR elements. +.PP +A consequence of this is that any use of a slot's default operation where the +first member argument begins with a hyphen will be an error. One of the above +operations should be used explicitly in those circumstances. +.SS "SLOT IMPLEMENTATION" +Internally, slot objects also define a method \fB\-\-default\-operation\fR +which is forwarded to the default operation of the slot (thus, for the class +.QW \fBvariable\fR +slot, this is forwarded to +.QW "\fBmy \-append\fR" ), +and these methods which provide the implementation interface: +.VE +.TP +\fIslot\fR \fBGet\fR +.VS +Returns a list that is the current contents of the slot. This method must +always be called from a stack frame created by a call to \fBoo::define\fR or +\fBoo::objdefine\fR. +.VE +.TP +\fIslot\fR \fBSet \fIelementList\fR +.VS +Sets the contents of the slot to the list \fIelementList\fR and returns the +empty string. This method must always be called from a stack frame created by +a call to \fBoo::define\fR or \fBoo::objdefine\fR. +.PP +The implementation of these methods is slot-dependent (and responsible for +accessing the correct part of the class or object definition). Slots also have +an unknown method handler to tie all these pieces together, and they hide +their \fBdestroy\fR method so that it is not invoked inadvertently. It is +\fIrecommended\fR that any user changes to the slot mechanism be restricted to +defining new operations whose names start with a hyphen. +.VE +.SH EXAMPLES +This example demonstrates how to use both forms of the \fBoo::define\fR and +\fBoo::objdefine\fR commands (they work in the same way), as well as +illustrating four of the subcommands of them. +.PP +.CS +oo::class create c +c create o +\fBoo::define\fR c \fBmethod\fR foo {} { + puts "world" +} +\fBoo::objdefine\fR o { + \fBmethod\fR bar {} { + my Foo "hello " + my foo + } + \fBforward\fR Foo ::puts -nonewline + \fBunexport\fR foo +} +o bar \fI\(-> prints "hello world"\fR +o foo \fI\(-> error "unknown method foo"\fR +o Foo Bar \fI\(-> error "unknown method Foo"\fR +\fBoo::objdefine\fR o \fBrenamemethod\fR bar lollipop +o lollipop \fI\(-> prints "hello world"\fR +.CE +.PP +This example shows how additional classes can be mixed into an object. It also +shows how \fBmixin\fR is a slot that supports appending: +.PP +.CS +oo::object create inst +inst m1 \fI\(-> error "unknown method m1"\fR +inst m2 \fI\(-> error "unknown method m2"\fR + +oo::class create A { + \fBmethod\fR m1 {} { + puts "red brick" + } +} +\fBoo::objdefine\fR inst { + \fBmixin\fR A +} +inst m1 \fI\(-> prints "red brick"\fR +inst m2 \fI\(-> error "unknown method m2"\fR + +oo::class create B { + \fBmethod\fR m2 {} { + puts "blue brick" + } +} +\fBoo::objdefine\fR inst { + \fBmixin -append\fR B +} +inst m1 \fI\(-> prints "red brick"\fR +inst m2 \fI\(-> prints "blue brick"\fR +.CE +.SH "SEE ALSO" +next(n), oo::class(n), oo::object(n) +.SH KEYWORDS +class, definition, method, object, slot +.\" Local variables: +.\" mode: nroff +.\" fill-column: 78 +.\" End: diff --git a/tcl8.6/doc/dict.n b/tcl8.6/doc/dict.n new file mode 100644 index 0000000..cd7e94c --- /dev/null +++ b/tcl8.6/doc/dict.n @@ -0,0 +1,445 @@ +'\" +'\" Copyright (c) 2003 Donal K. Fellows +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH dict n 8.5 Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +dict \- Manipulate dictionaries +.SH SYNOPSIS +\fBdict \fIoption arg \fR?\fIarg ...\fR? +.BE +.SH DESCRIPTION +.PP +Performs one of several operations on dictionary values or variables +containing dictionary values (see the \fBDICTIONARY VALUES\fR section +below for a description), depending on \fIoption\fR. The legal +\fIoption\fRs (which may be abbreviated) are: +.TP +\fBdict append \fIdictionaryVariable key \fR?\fIstring ...\fR? +. +This appends the given string (or strings) to the value that the given +key maps to in the dictionary value contained in the given variable, +writing the resulting dictionary value back to that variable. +Non-existent keys are treated as if they map to an empty string. The +updated dictionary value is returned. +.TP +\fBdict create \fR?\fIkey value ...\fR? +. +Return a new dictionary that contains each of the key/value mappings +listed as arguments (keys and values alternating, with each key being +followed by its associated value.) +.TP +\fBdict exists \fIdictionaryValue key \fR?\fIkey ...\fR? +. +This returns a boolean value indicating whether the given key (or path +of keys through a set of nested dictionaries) exists in the given +dictionary value. This returns a true value exactly when \fBdict +get\fR on that path will succeed. +.TP +\fBdict filter \fIdictionaryValue filterType arg \fR?\fIarg ...\fR? +. +This takes a dictionary value and returns a new dictionary that +contains just those key/value pairs that match the specified filter +type (which may be abbreviated.) Supported filter types are: +.RS +.TP +\fBdict filter \fIdictionaryValue \fBkey\fR ?\fIglobPattern ...\fR? +.VS 8.6 +The key rule only matches those key/value pairs whose keys match any +of the given patterns (in the style of \fBstring match\fR.) +.VE 8.6 +.TP +\fBdict filter \fIdictionaryValue \fBscript {\fIkeyVariable valueVariable\fB} \fIscript\fR +. +The script rule tests for matching by assigning the key to the +\fIkeyVariable\fR and the value to the \fIvalueVariable\fR, and then evaluating +the given script which should return a boolean value (with the +key/value pair only being included in the result of the \fBdict +filter\fR when a true value is returned.) Note that the first +argument after the rule selection word is a two-element list. If the +\fIscript\fR returns with a condition of \fBTCL_BREAK\fR, no further +key/value pairs are considered for inclusion in the resulting +dictionary, and a condition of \fBTCL_CONTINUE\fR is equivalent to a false +result. The key/value pairs are tested in the order in which the keys +were inserted into the dictionary. +.TP +\fBdict filter \fIdictionaryValue \fBvalue \fR?\fIglobPattern ...\fR? +.VS 8.6 +The value rule only matches those key/value pairs whose values match any +of the given patterns (in the style of \fBstring match\fR.) +.VE 8.6 +.RE +.TP +\fBdict for {\fIkeyVariable valueVariable\fB} \fIdictionaryValue body\fR +. +This command takes three arguments, the first a two-element list of +variable names (for the key and value respectively of each mapping in +the dictionary), the second the dictionary value to iterate across, +and the third a script to be evaluated for each mapping with the key +and value variables set appropriately (in the manner of \fBforeach\fR.) +The result of the command is an empty string. If any evaluation of the +body generates a \fBTCL_BREAK\fR result, no further pairs from the +dictionary will be iterated over and the \fBdict for\fR command will +terminate successfully immediately. If any evaluation of the body +generates a \fBTCL_CONTINUE\fR result, this shall be treated exactly like a +normal \fBTCL_OK\fR result. The order of iteration is the order in +which the keys were inserted into the dictionary. +.TP +\fBdict get \fIdictionaryValue \fR?\fIkey ...\fR? +. +Given a dictionary value (first argument) and a key (second argument), +this will retrieve the value for that key. Where several keys are +supplied, the behaviour of the command shall be as if the result of +\fBdict get $dictVal $key\fR was passed as the first argument to +\fBdict get\fR with the remaining arguments as second (and possibly +subsequent) arguments. This facilitates lookups in nested +dictionaries. For example, the following two commands are equivalent: +.RS +.PP +.CS +dict get $dict foo bar spong +dict get [dict get [dict get $dict foo] bar] spong +.CE +.PP +If no keys are provided, \fBdict get\fR will return a list containing pairs of +elements in a manner similar to \fBarray get\fR. That is, the first +element of each pair would be the key and the second element would be +the value for that key. +.PP +It is an error to attempt to retrieve a value for a key that is not +present in the dictionary. +.RE +.TP +\fBdict incr \fIdictionaryVariable key \fR?\fIincrement\fR? +. +This adds the given increment value (an integer that defaults to 1 if +not specified) to the value that the given key maps to in the +dictionary value contained in the given variable, writing the +resulting dictionary value back to that variable. Non-existent keys +are treated as if they map to 0. It is an error to increment a value +for an existing key if that value is not an integer. The updated +dictionary value is returned. +.TP +\fBdict info \fIdictionaryValue\fR +. +This returns information (intended for display to people) about the +given dictionary though the format of this data is dependent on the +implementation of the dictionary. For dictionaries that are +implemented by hash tables, it is expected that this will return the +string produced by \fBTcl_HashStats\fR, similar to \fBarray statistics\fR. +.TP +\fBdict keys \fIdictionaryValue \fR?\fIglobPattern\fR? +. +Return a list of all keys in the given dictionary value. If a pattern +is supplied, only those keys that match it (according to the rules of +\fBstring match\fR) will be returned. The returned keys will be in the +order that they were inserted into the dictionary. +.TP +\fBdict lappend \fIdictionaryVariable key \fR?\fIvalue ...\fR? +. +This appends the given items to the list value that the given key maps +to in the dictionary value contained in the given variable, writing +the resulting dictionary value back to that variable. Non-existent +keys are treated as if they map to an empty list, and it is legal for +there to be no items to append to the list. It is an error for the +value that the key maps to to not be representable as a list. The +updated dictionary value is returned. +.TP +\fBdict map \fR{\fIkeyVariable valueVariable\fR} \fIdictionaryValue body\fR +. +This command applies a transformation to each element of a dictionary, +returning a new dictionary. It takes three arguments: the first is a +two-element list of variable names (for the key and value respectively of each +mapping in the dictionary), the second the dictionary value to iterate across, +and the third a script to be evaluated for each mapping with the key and value +variables set appropriately (in the manner of \fBlmap\fR). In an iteration +where the evaluated script completes normally (\fBTCL_OK\fR, as opposed to an +\fBerror\fR, etc.) the result of the script is put into an accumulator +dictionary using the key that is the current contents of the \fIkeyVariable\fR +variable at that point. The result of the \fBdict map\fR command is the +accumulator dictionary after all keys have been iterated over. +.RS +.PP +If the evaluation of the body for any particular step generates a \fBbreak\fR, +no further pairs from the dictionary will be iterated over and the \fBdict +map\fR command will terminate successfully immediately. If the evaluation of +the body for a particular step generates a \fBcontinue\fR result, the current +iteration is aborted and the accumulator dictionary is not modified. The order +of iteration is the natural order of the dictionary (typically the order in +which the keys were added to the dictionary; the order is the same as that +used in \fBdict for\fR). +.RE +.TP +\fBdict merge \fR?\fIdictionaryValue ...\fR? +. +Return a dictionary that contains the contents of each of the +\fIdictionaryValue\fR arguments. Where two (or more) dictionaries +contain a mapping for the same key, the resulting dictionary maps that +key to the value according to the last dictionary on the command line +containing a mapping for that key. +.TP +\fBdict remove \fIdictionaryValue \fR?\fIkey ...\fR? +. +Return a new dictionary that is a copy of an old one passed in as +first argument except without mappings for each of the keys listed. +It is legal for there to be no keys to remove, and it also legal for +any of the keys to be removed to not be present in the input +dictionary in the first place. +.TP +\fBdict replace \fIdictionaryValue \fR?\fIkey value ...\fR? +. +Return a new dictionary that is a copy of an old one passed in as +first argument except with some values different or some extra +key/value pairs added. It is legal for this command to be called with +no key/value pairs, but illegal for this command to be called with a +key but no value. +.TP +\fBdict set \fIdictionaryVariable key \fR?\fIkey ...\fR? \fIvalue\fR +. +This operation takes the name of a variable containing a dictionary +value and places an updated dictionary value in that variable +containing a mapping from the given key to the given value. When +multiple keys are present, this operation creates or updates a chain +of nested dictionaries. The updated dictionary value is returned. +.TP +\fBdict size \fIdictionaryValue\fR +. +Return the number of key/value mappings in the given dictionary value. +.TP +\fBdict unset \fIdictionaryVariable key \fR?\fIkey ...\fR? +. +This operation (the companion to \fBdict set\fR) takes the name of a +variable containing a dictionary value and places an updated +dictionary value in that variable that does not contain a mapping for +the given key. Where multiple keys are present, this describes a path +through nested dictionaries to the mapping to remove. At least one key +must be specified, but the last key on the key-path need not exist. +All other components on the path must exist. The updated dictionary +value is returned. +.TP +\fBdict update \fIdictionaryVariable key varName \fR?\fIkey varName ...\fR? \fIbody\fR +. +Execute the Tcl script in \fIbody\fR with the value for each \fIkey\fR +(as found by reading the dictionary value in \fIdictionaryVariable\fR) +mapped to the variable \fIvarName\fR. There may be multiple +\fIkey\fR/\fIvarName\fR pairs. If a \fIkey\fR does not have a mapping, +that corresponds to an unset \fIvarName\fR. When \fIbody\fR +terminates, any changes made to the \fIvarName\fRs is reflected back +to the dictionary within \fIdictionaryVariable\fR (unless +\fIdictionaryVariable\fR itself becomes unreadable, when all updates +are silently discarded), even if the result of \fIbody\fR is an error +or some other kind of exceptional exit. The result of \fBdict +update\fR is (unless some kind of error occurs) the result of the +evaluation of \fIbody\fR. +.RS +.PP +Each \fIvarName\fR is mapped in the scope enclosing the \fBdict update\fR; +it is recommended that this command only be used in a local scope +(\fBproc\fRedure, lambda term for \fBapply\fR, or method). Because of +this, the variables set by \fBdict update\fR will continue to +exist after the command finishes (unless explicitly \fBunset\fR). +Note that the mapping of values to variables +does not use traces; changes to the \fIdictionaryVariable\fR's +contents only happen when \fIbody\fR terminates. +.RE +.TP +\fBdict values \fIdictionaryValue \fR?\fIglobPattern\fR? +. +Return a list of all values in the given dictionary value. If a +pattern is supplied, only those values that match it (according to the +rules of \fBstring match\fR) will be returned. The returned values +will be in the order of that the keys associated with those values +were inserted into the dictionary. +.TP +\fBdict with \fIdictionaryVariable \fR?\fIkey ...\fR? \fIbody\fR +. +Execute the Tcl script in \fIbody\fR with the value for each key in +\fIdictionaryVariable\fR mapped (in a manner similarly to \fBdict +update\fR) to a variable with the same name. Where one or more +\fIkey\fRs are available, these indicate a chain of nested +dictionaries, with the innermost dictionary being the one opened out +for the execution of \fIbody\fR. As with \fBdict update\fR, making +\fIdictionaryVariable\fR unreadable will make the updates to the +dictionary be discarded, and this also happens if the contents of +\fIdictionaryVariable\fR are adjusted so that the chain of +dictionaries no longer exists. The result of \fBdict with\fR is +(unless some kind of error occurs) the result of the evaluation of +\fIbody\fR. +.RS +.PP +The variables are mapped in the scope enclosing the \fBdict with\fR; +it is recommended that this command only be used in a local scope +(\fBproc\fRedure, lambda term for \fBapply\fR, or method). Because of +this, the variables set by \fBdict with\fR will continue to +exist after the command finishes (unless explicitly \fBunset\fR). +Note that the mapping of values to variables does not use +traces; changes to the \fIdictionaryVariable\fR's contents only happen +when \fIbody\fR terminates. +.PP +If the \fIdictionaryVariable\fR contains a value that is not a dictionary at +the point when the \fIbody\fR terminates (which can easily happen if the name +is the same as any of the keys in dictionary) then an error occurs at that +point. This command is thus not recommended for use when the keys in the +dictionary are expected to clash with the \fIdictionaryVariable\fR name +itself. Where the contained key does map to a dictionary, the net effect is to +combine that inner dictionary into the outer dictionary; see the +\fBEXAMPLES\fR below for an illustration of this. +.RE +.SH "DICTIONARY VALUES" +.PP +Dictionaries are values that contain an efficient, order-preserving +mapping from arbitrary keys to arbitrary values. +Each key in the dictionary maps to a single value. +They have a textual format that is exactly that of any list with an +even number of elements, with each mapping in the dictionary being +represented as two items in the list. When a command takes a +dictionary and produces a new dictionary based on it (either returning +it or writing it back into the variable that the starting dictionary +was read from) the new dictionary will have the same order of keys, +modulo any deleted keys and with new keys added on to the end. +When a string is interpreted as a dictionary and it would otherwise +have duplicate keys, only the last value for a particular key is used; +the others are ignored, meaning that, +.QW "apple banana" +and +.QW "apple carrot apple banana" +are equivalent dictionaries (with different string representations). +.PP +Operations that derive a new dictionary from an old one (e.g., updates +like \fBdict set\fR and \fBdict unset\fR) preserve the order of keys +in the dictionary. The exceptions to this are for any new keys they +add, which are appended to the sequence, and any keys that are +removed, which are excised from the order. +.SH EXAMPLES +.PP +Basic dictionary usage: +.PP +.CS +# Make a dictionary to map extensions to descriptions +set filetypes [\fBdict create\fR .txt "Text File" .tcl "Tcl File"] + +# Add/update the dictionary +\fBdict set\fR filetypes .tcl "Tcl Script" +\fBdict set\fR filetypes .tm "Tcl Module" +\fBdict set\fR filetypes .gif "GIF Image" +\fBdict set\fR filetypes .png "PNG Image" + +# Simple read from the dictionary +set ext ".tcl" +set desc [\fBdict get\fR $filetypes $ext] +puts "$ext is for a $desc" + +# Somewhat more complex, with existence test +foreach filename [glob *] { + set ext [file extension $filename] + if {[\fBdict exists\fR $filetypes $ext]} { + puts "$filename is a [\fBdict get\fR $filetypes $ext]" + } +} +.CE +.PP +Constructing and using nested dictionaries: +.PP +.CS +# Data for one employee +\fBdict set\fR employeeInfo 12345-A forenames "Joe" +\fBdict set\fR employeeInfo 12345-A surname "Schmoe" +\fBdict set\fR employeeInfo 12345-A street "147 Short Street" +\fBdict set\fR employeeInfo 12345-A city "Springfield" +\fBdict set\fR employeeInfo 12345-A phone "555-1234" +# Data for another employee +\fBdict set\fR employeeInfo 98372-J forenames "Anne" +\fBdict set\fR employeeInfo 98372-J surname "Other" +\fBdict set\fR employeeInfo 98372-J street "32995 Oakdale Way" +\fBdict set\fR employeeInfo 98372-J city "Springfield" +\fBdict set\fR employeeInfo 98372-J phone "555-8765" +# The above data probably ought to come from a database... + +# Print out some employee info +set i 0 +puts "There are [\fBdict size\fR $employeeInfo] employees" +\fBdict for\fR {id info} $employeeInfo { + puts "Employee #[incr i]: $id" + \fBdict with\fR info { + puts " Name: $forenames $surname" + puts " Address: $street, $city" + puts " Telephone: $phone" + } +} +# Another way to iterate and pick out names... +foreach id [\fBdict keys\fR $employeeInfo] { + puts "Hello, [\fBdict get\fR $employeeInfo $id forenames]!" +} +.CE +.PP +A localizable version of \fBstring toupper\fR: +.PP +.CS +# Set up the basic C locale +set capital [\fBdict create\fR C [\fBdict create\fR]] +foreach c [split {abcdefghijklmnopqrstuvwxyz} ""] { + \fBdict set\fR capital C $c [string toupper $c] +} + +# English locales can luckily share the "C" locale +\fBdict set\fR capital en [\fBdict get\fR $capital C] +\fBdict set\fR capital en_US [\fBdict get\fR $capital C] +\fBdict set\fR capital en_GB [\fBdict get\fR $capital C] + +# ... and so on for other supported languages ... + +# Now get the mapping for the current locale and use it. +set upperCaseMap [\fBdict get\fR $capital $env(LANG)] +set upperCase [string map $upperCaseMap $string] +.CE +.PP +Showing the detail of \fBdict with\fR: +.PP +.CS +proc sumDictionary {varName} { + upvar 1 $varName vbl + foreach key [\fBdict keys\fR $vbl] { + # Manufacture an entry in the subdictionary + \fBdict set\fR vbl $key total 0 + # Add the values and remove the old + \fBdict with\fR vbl $key { + set total [expr {$x + $y + $z}] + unset x y z + } + } + puts "last total was $total, for key $key" +} + +set myDict { + a {x 1 y 2 z 3} + b {x 6 y 5 z 4} +} + +sumDictionary myDict +# prints: \fIlast total was 15, for key b\fR + +puts "dictionary is now \\"$myDict\\"" +# prints: \fIdictionary is now "a {total 6} b {total 15}"\fR +.CE +.PP +When \fBdict with\fR is used with a key that clashes with the name of the +dictionary variable: +.PP +.CS +set foo {foo {a b} bar 2 baz 3} +\fBdict with\fR foo {} +puts $foo +# prints: \fIa b foo {a b} bar 2 baz 3\fR +.CE +.SH "SEE ALSO" +append(n), array(n), foreach(n), incr(n), list(n), lappend(n), lmap(n), set(n) +.SH KEYWORDS +dictionary, create, update, lookup, iterate, filter, map +'\" Local Variables: +'\" mode: nroff +'\" End: diff --git a/tcl8.6/doc/encoding.n b/tcl8.6/doc/encoding.n new file mode 100644 index 0000000..50ad083 --- /dev/null +++ b/tcl8.6/doc/encoding.n @@ -0,0 +1,115 @@ +'\" +'\" Copyright (c) 1998 by Scriptics Corporation. +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH encoding n "8.1" Tcl "Tcl Built-In Commands" +.so man.macros +.BS +.SH NAME +encoding \- Manipulate encodings +.SH SYNOPSIS +\fBencoding \fIoption\fR ?\fIarg arg ...\fR? +.BE +.SH INTRODUCTION +.PP +Strings in Tcl are logically a sequence of 16-bit Unicode characters. +These strings are represented in memory as a sequence of bytes that +may be in one of several encodings: modified UTF\-8 (which uses 1 to 3 +bytes per character), 16-bit +.QW Unicode +(which uses 2 bytes per character, with an endianness that is +dependent on the host architecture), and binary (which uses a single +byte per character but only handles a restricted range of characters). +Tcl does not guarantee to always use the same encoding for the same +string. +.PP +Different operating system interfaces or applications may generate +strings in other encodings such as Shift\-JIS. The \fBencoding\fR +command helps to bridge the gap between Unicode and these other +formats. +.SH DESCRIPTION +.PP +Performs one of several encoding related operations, depending on +\fIoption\fR. The legal \fIoption\fRs are: +.TP +\fBencoding convertfrom\fR ?\fIencoding\fR? \fIdata\fR +. +Convert \fIdata\fR to Unicode from the specified \fIencoding\fR. The +characters in \fIdata\fR are treated as binary data where the lower +8-bits of each character is taken as a single byte. The resulting +sequence of bytes is treated as a string in the specified +\fIencoding\fR. If \fIencoding\fR is not specified, the current +system encoding is used. +.TP +\fBencoding convertto\fR ?\fIencoding\fR? \fIstring\fR +. +Convert \fIstring\fR from Unicode to the specified \fIencoding\fR. +The result is a sequence of bytes that represents the converted +string. Each byte is stored in the lower 8-bits of a Unicode +character (indeed, the resulting string is a binary string as far as +Tcl is concerned, at least initially). If \fIencoding\fR is not +specified, the current system encoding is used. +.TP +\fBencoding dirs\fR ?\fIdirectoryList\fR? +. +Tcl can load encoding data files from the file system that describe +additional encodings for it to work with. This command sets the search +path for \fB*.enc\fR encoding data files to the list of directories +\fIdirectoryList\fR. If \fIdirectoryList\fR is omitted then the +command returns the current list of directories that make up the +search path. It is an error for \fIdirectoryList\fR to not be a valid +list. If, when a search for an encoding data file is happening, an +element in \fIdirectoryList\fR does not refer to a readable, +searchable directory, that element is ignored. +.TP +\fBencoding names\fR +. +Returns a list containing the names of all of the encodings that are +currently available. +The encodings +.QW utf-8 +and +.QW iso8859-1 +are guaranteed to be present in the list. +.TP +\fBencoding system\fR ?\fIencoding\fR? +. +Set the system encoding to \fIencoding\fR. If \fIencoding\fR is +omitted then the command returns the current system encoding. The +system encoding is used whenever Tcl passes strings to system calls. +.SH EXAMPLE +.PP +It is common practice to write script files using a text editor that +produces output in the euc-jp encoding, which represents the ASCII +characters as singe bytes and Japanese characters as two bytes. This +makes it easy to embed literal strings that correspond to non-ASCII +characters by simply typing the strings in place in the script. +However, because the \fBsource\fR command always reads files using the +current system encoding, Tcl will only source such files correctly +when the encoding used to write the file is the same. This tends not +to be true in an internationalized setting. For example, if such a +file was sourced in North America (where the ISO8859\-1 is normally +used), each byte in the file would be treated as a separate character +that maps to the 00 page in Unicode. The resulting Tcl strings will +not contain the expected Japanese characters. Instead, they will +contain a sequence of Latin-1 characters that correspond to the bytes +of the original string. The \fBencoding\fR command can be used to +convert this string to the expected Japanese Unicode characters. For +example, +.PP +.CS +set s [\fBencoding convertfrom\fR euc-jp "\exA4\exCF"] +.CE +.PP +would return the Unicode string +.QW "\eu306F" , +which is the Hiragana letter HA. +.SH "SEE ALSO" +Tcl_GetEncoding(3) +.SH KEYWORDS +encoding, unicode +.\" Local Variables: +.\" mode: nroff +.\" End: diff --git a/tcl8.6/doc/eof.n b/tcl8.6/doc/eof.n new file mode 100644 index 0000000..75f3c48 --- /dev/null +++ b/tcl8.6/doc/eof.n @@ -0,0 +1,61 @@ +'\" +'\" Copyright (c) 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. +'\" +.TH eof n 7.5 Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +eof \- Check for end of file condition on channel +.SH SYNOPSIS +\fBeof \fIchannelId\fR +.BE +.SH DESCRIPTION +.PP +Returns 1 if an end of file condition occurred during the most +recent input operation on \fIchannelId\fR (such as \fBgets\fR), +0 otherwise. +.PP +\fIChannelId\fR must be an identifier for an open channel such as a +Tcl standard channel (\fBstdin\fR, \fBstdout\fR, or \fBstderr\fR), +the return value from an invocation of \fBopen\fR or \fBsocket\fR, or +the result of a channel creation command provided by a Tcl extension. +.SH EXAMPLES +.PP +Read and print out the contents of a file line-by-line: +.PP +.CS +set f [open somefile.txt] +while {1} { + set line [gets $f] + if {[\fBeof\fR $f]} { + close $f + break + } + puts "Read line: $line" +} +.CE +.PP +Read and print out the contents of a file by fixed-size records: +.PP +.CS +set f [open somefile.dat] +fconfigure $f -translation binary +set recordSize 40 +while {1} { + set record [read $f $recordSize] + if {[\fBeof\fR $f]} { + close $f + break + } + puts "Read record: $record" +} +.CE +.SH "SEE ALSO" +file(n), open(n), close(n), fblocked(n), Tcl_StandardChannels(3) +.SH KEYWORDS +channel, end of file diff --git a/tcl8.6/doc/error.n b/tcl8.6/doc/error.n new file mode 100644 index 0000000..c05f8b9 --- /dev/null +++ b/tcl8.6/doc/error.n @@ -0,0 +1,78 @@ +'\" +'\" Copyright (c) 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. +'\" +.TH error n "" Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +error \- Generate an error +.SH SYNOPSIS +\fBerror \fImessage\fR ?\fIinfo\fR? ?\fIcode\fR? +.BE + +.SH DESCRIPTION +.PP +Returns a \fBTCL_ERROR\fR code, which causes command interpretation to be +unwound. \fIMessage\fR is a string that is returned to the application +to indicate what went wrong. +.PP +The \fB\-errorinfo\fR return option of an interpreter is used +to accumulate a stack trace of what was in progress when an +error occurred; as nested commands unwind, +the Tcl interpreter adds information to the \fB\-errorinfo\fR +return option. If the \fIinfo\fR argument is present, it is +used to initialize the \fB\-errorinfo\fR return options and +the first increment of unwind information +will not be added by the Tcl interpreter. +In other +words, the command containing the \fBerror\fR command will not appear +in the stack trace; in its place will be \fIinfo\fR. +Historically, this feature had been most useful in conjunction +with the \fBcatch\fR command: +if a caught error cannot be handled successfully, \fIinfo\fR can be used +to return a stack trace reflecting the original point of occurrence +of the error: +.PP +.CS +catch {...} errMsg +set savedInfo $::errorInfo +\&... +\fBerror\fR $errMsg $savedInfo +.CE +.PP +When working with Tcl 8.5 or later, the following code +should be used instead: +.PP +.CS +catch {...} errMsg options +\&... +return -options $options $errMsg +.CE +.PP +If the \fIcode\fR argument is present, then its value is stored +in the \fB\-errorcode\fR return option. The \fB\-errorcode\fR +return option is intended to hold a machine-readable description +of the error in cases where such information is available; see +the \fBreturn\fR manual page for information on the proper format +for this option's value. +.SH EXAMPLE +.PP +Generate an error if a basic mathematical operation fails: +.PP +.CS +if {1+2 != 3} { + \fBerror\fR "something is very wrong with addition" +} +.CE +.SH "SEE ALSO" +catch(n), return(n) +.SH KEYWORDS +error, exception +'\" Local Variables: +'\" mode: nroff +'\" End: diff --git a/tcl8.6/doc/eval.n b/tcl8.6/doc/eval.n new file mode 100644 index 0000000..3ef5023 --- /dev/null +++ b/tcl8.6/doc/eval.n @@ -0,0 +1,84 @@ +'\" +'\" Copyright (c) 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. +'\" +.TH eval n "" Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +eval \- Evaluate a Tcl script +.SH SYNOPSIS +\fBeval \fIarg \fR?\fIarg ...\fR? +.BE +.SH DESCRIPTION +.PP +\fBEval\fR takes one or more arguments, which together comprise a Tcl +script containing one or more commands. +\fBEval\fR concatenates all its arguments in the same +fashion as the \fBconcat\fR command, passes the concatenated string to the +Tcl interpreter recursively, and returns the result of that +evaluation (or any error generated by it). +Note that the \fBlist\fR command quotes sequences of words in such a +way that they are not further expanded by the \fBeval\fR command. +.SH EXAMPLES +.PP +Often, it is useful to store a fragment of a script in a variable and +execute it later on with extra values appended. This technique is used +in a number of places throughout the Tcl core (e.g. in \fBfcopy\fR, +\fBlsort\fR and \fBtrace\fR command callbacks). This example shows how +to do this using core Tcl commands: +.PP +.CS +set script { + puts "logging now" + lappend $myCurrentLogVar +} +set myCurrentLogVar log1 +# Set up a switch of logging variable part way through! +after 20000 set myCurrentLogVar log2 + +for {set i 0} {$i<10} {incr i} { + # Introduce a random delay + after [expr {int(5000 * rand())}] + update ;# Check for the asynch log switch + \fBeval\fR $script $i [clock clicks] +} +.CE +.PP +Note that in the most common case (where the script fragment is +actually just a list of words forming a command prefix), it is better +to use \fB{*}$script\fR when doing this sort of invocation +pattern. It is less general than the \fBeval\fR command, and hence +easier to make robust in practice. +The following procedure acts in a way that is analogous to the +\fBlappend\fR command, except it inserts the argument values at the +start of the list in the variable: +.PP +.CS +proc lprepend {varName args} { + upvar 1 $varName var + # Ensure that the variable exists and contains a list + lappend var + # Now we insert all the arguments in one go + set var [\fBeval\fR [list linsert $var 0] $args] +} +.CE +.PP +However, the last line would now normally be written without +\fBeval\fR, like this: +.PP +.CS +set var [linsert $var 0 {*}$args] +.CE +.SH "SEE ALSO" +catch(n), concat(n), error(n), errorCode(n), errorInfo(n), interp(n), list(n), +namespace(n), subst(n), uplevel(n) +.SH KEYWORDS +concatenate, evaluate, script +'\" Local Variables: +'\" mode: nroff +'\" End: diff --git a/tcl8.6/doc/exec.n b/tcl8.6/doc/exec.n new file mode 100644 index 0000000..70ace32 --- /dev/null +++ b/tcl8.6/doc/exec.n @@ -0,0 +1,452 @@ +'\" +'\" Copyright (c) 1993 The Regents of the University of California. +'\" Copyright (c) 1994-1996 Sun Microsystems, Inc. +'\" Copyright (c) 2006 Donal K. Fellows. +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH exec n 8.5 Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +exec \- Invoke subprocesses +.SH SYNOPSIS +\fBexec \fR?\fIswitches\fR? \fIarg \fR?\fIarg ...\fR? ?\fB&\fR? +.BE +.SH DESCRIPTION +.PP +This command treats its arguments as the specification +of one or more subprocesses to execute. +The arguments take the form of a standard shell pipeline +where each \fIarg\fR becomes one word of a command, and +each distinct command becomes a subprocess. +.PP +If the initial arguments to \fBexec\fR start with \fB\-\fR then +they are treated as command-line switches and are not part +of the pipeline specification. The following switches are +currently supported: +.TP 13 +\fB\-ignorestderr\fR +. +Stops the \fBexec\fR command from treating the output of messages to the +pipeline's standard error channel as an error case. +.TP 13 +\fB\-keepnewline\fR +. +Retains a trailing newline in the pipeline's output. +Normally a trailing newline will be deleted. +.TP 13 +\fB\-\|\-\fR +. +Marks the end of switches. The argument following this one will +be treated as the first \fIarg\fR even if it starts with a \fB\-\fR. +.PP +If an \fIarg\fR (or pair of \fIarg\fRs) has one of the forms +described below then it is used by \fBexec\fR to control the +flow of input and output among the subprocess(es). +Such arguments will not be passed to the subprocess(es). In forms +such as +.QW "\fB<\fR \fIfileName\fR" , +\fIfileName\fR may either be in a separate argument from +.QW \fB<\fR +or in the same argument with no intervening space (i.e. +.QW \fB<\fIfileName\fR ). +.TP 15 +\fB|\fR +. +Separates distinct commands in the pipeline. The standard output +of the preceding command will be piped into the standard input +of the next command. +.TP 15 +\fB|&\fR +. +Separates distinct commands in the pipeline. Both standard output +and standard error of the preceding command will be piped into +the standard input of the next command. +This form of redirection overrides forms such as 2> and >&. +.TP 15 +\fB<\0\fIfileName\fR +. +The file named by \fIfileName\fR is opened and used as the standard +input for the first command in the pipeline. +.TP 15 +\fB<@\0\fIfileId\fR +. +\fIFileId\fR must be the identifier for an open file, such as the return +value from a previous call to \fBopen\fR. +It is used as the standard input for the first command in the pipeline. +\fIFileId\fR must have been opened for reading. +.TP 15 +\fB<<\0\fIvalue\fR +. +\fIValue\fR is passed to the first command as its standard input. +.TP 15 +\fB>\0\fIfileName\fR +. +Standard output from the last command is redirected to the file named +\fIfileName\fR, overwriting its previous contents. +.TP 15 +\fB2>\0\fIfileName\fR +. +Standard error from all commands in the pipeline is redirected to the +file named \fIfileName\fR, overwriting its previous contents. +.TP 15 +\fB>&\0\fIfileName\fR +. +Both standard output from the last command and standard error from all +commands are redirected to the file named \fIfileName\fR, overwriting +its previous contents. +.TP 15 +\fB>>\0\fIfileName\fR +. +Standard output from the last command is +redirected to the file named \fIfileName\fR, appending to it rather +than overwriting it. +.TP 15 +\fB2>>\0\fIfileName\fR +. +Standard error from all commands in the pipeline is +redirected to the file named \fIfileName\fR, appending to it rather +than overwriting it. +.TP 15 +\fB>>&\0\fIfileName\fR +. +Both standard output from the last command and standard error from +all commands are redirected to the file named \fIfileName\fR, +appending to it rather than overwriting it. +.TP 15 +\fB>@\0\fIfileId\fR +. +\fIFileId\fR must be the identifier for an open file, such as the return +value from a previous call to \fBopen\fR. +Standard output from the last command is redirected to \fIfileId\fR's +file, which must have been opened for writing. +.TP 15 +\fB2>@\0\fIfileId\fR +. +\fIFileId\fR must be the identifier for an open file, such as the return +value from a previous call to \fBopen\fR. +Standard error from all commands in the pipeline is +redirected to \fIfileId\fR's file. +The file must have been opened for writing. +.TP 15 +\fB2>@1\0\fR +. +Standard error from all commands in the pipeline is redirected to the +command result. This operator is only valid at the end of the command +pipeline. +.TP 15 +\fB>&@\0\fIfileId\fR +. +\fIFileId\fR must be the identifier for an open file, such as the return +value from a previous call to \fBopen\fR. +Both standard output from the last command and standard error from +all commands are redirected to \fIfileId\fR's file. +The file must have been opened for writing. +.PP +If standard output has not been redirected then the \fBexec\fR +command returns the standard output from the last command +in the pipeline, unless +.QW 2>@1 +was specified, in which case standard error is included as well. +If any of the commands in the pipeline exit abnormally or +are killed or suspended, then \fBexec\fR will return an error +and the error message will include the pipeline's output followed by +error messages describing the abnormal terminations; the +\fB\-errorcode\fR return option will contain additional information +about the last abnormal termination encountered. +If any of the commands writes to its standard error file and that +standard error is not redirected +and \fB\-ignorestderr\fR is not specified, +then \fBexec\fR will return an error; the error message +will include the pipeline's standard output, followed by messages +about abnormal terminations (if any), followed by the standard error +output. +.PP +If the last character of the result or error message +is a newline then that character is normally deleted +from the result or error message. +This is consistent with other Tcl return values, which do not +normally end with newlines. +However, if \fB\-keepnewline\fR is specified then the trailing +newline is retained. +.PP +If standard input is not redirected with +.QW < , +.QW << +or +.QW <@ +then the standard input for the first command in the +pipeline is taken from the application's current standard input. +.PP +If the last \fIarg\fR is +.QW & +then the pipeline will be executed in background. +In this case the \fBexec\fR command will return a list whose +elements are the process identifiers for all of the subprocesses +in the pipeline. +The standard output from the last command in the pipeline will +go to the application's standard output if it has not been +redirected, and error output from all of +the commands in the pipeline will go to the application's +standard error file unless redirected. +.PP +The first word in each command is taken as the command name; +tilde-substitution is performed on it, and if the result contains +no slashes then the directories +in the PATH environment variable are searched for +an executable by the given name. +If the name contains a slash then it must refer to an executable +reachable from the current directory. +No +.QW glob +expansion or other shell-like substitutions +are performed on the arguments to commands. +.SH "PORTABILITY ISSUES" +.TP +\fBWindows\fR (all versions) +. +Reading from or writing to a socket, using the +.QW \fB@\0\fIfileId\fR +notation, does not work. When reading from a socket, a 16-bit DOS +application will hang and a 32-bit application will return immediately with +end-of-file. When either type of application writes to a socket, the +information is instead sent to the console, if one is present, or is +discarded. +.RS +.PP +The Tk console text widget does not provide real standard IO capabilities. +Under Tk, when redirecting from standard input, all applications will see an +immediate end-of-file; information redirected to standard output or standard +error will be discarded. +.PP +Either forward or backward slashes are accepted as path separators for +arguments to Tcl commands. When executing an application, the path name +specified for the application may also contain forward or backward slashes +as path separators. Bear in mind, however, that most Windows applications +accept arguments with forward slashes only as option delimiters and +backslashes only in paths. Any arguments to an application that specify a +path name with forward slashes will not automatically be converted to use +the backslash character. If an argument contains forward slashes as the +path separator, it may or may not be recognized as a path name, depending on +the program. +.PP +Additionally, when calling a 16-bit DOS or Windows 3.X application, all path +names must use the short, cryptic, path format (e.g., using +.QW applba~1.def +instead of +.QW applbakery.default ), +which can be obtained with the +.QW "\fBfile attributes\fI fileName \fB\-shortname\fR" +command. +.PP +Two or more forward or backward slashes in a row in a path refer to a +network path. For example, a simple concatenation of the root directory +\fBc:/\fR with a subdirectory \fB/windows/system\fR will yield +\fBc://windows/system\fR (two slashes together), which refers to the mount +point called \fBsystem\fR on the machine called \fBwindows\fR (and the +\fBc:/\fR is ignored), and is not equivalent to \fBc:/windows/system\fR, +which describes a directory on the current computer. The \fBfile join\fR +command should be used to concatenate path components. +.PP +Note that there are two general types of Win32 console applications: +.RS +.IP [1] +CLI \(em CommandLine Interface, simple stdio exchange. \fBnetstat.exe\fR for +example. +.IP [2] +TUI \(em Textmode User Interface, any application that accesses the console +API for doing such things as cursor movement, setting text color, detecting +key presses and mouse movement, etc. An example would be \fBtelnet.exe\fR +from Windows 2000. These types of applications are not common in a windows +environment, but do exist. +.RE +.PP +\fBexec\fR will not work well with TUI applications when a console is not +present, as is done when launching applications under wish. It is desirable +to have console applications hidden and detached. This is a designed-in +limitation as \fBexec\fR wants to communicate over pipes. The Expect +extension addresses this issue when communicating with a TUI application. +.PP +When attempting to execute an application, \fBexec\fR first searches for +the name as it was specified. Then, in order, +\fB.com\fR, \fB.exe\fR, \fB.bat\fR and \fB.cmd\fR +are appended to the end of the specified name and it searches +for the longer name. If a directory name was not specified as part of the +application name, the following directories are automatically searched in +order when attempting to locate the application: +.IP \(bu 3 +The directory from which the Tcl executable was loaded. +.IP \(bu 3 +The current directory. +.IP \(bu 3 +The Windows NT 32-bit system directory. +.IP \(bu 3 +The Windows NT 16-bit system directory. +.IP \(bu 3 +The Windows NT home directory. +.IP \(bu 3 +The directories listed in the path. +.PP +In order to execute shell built-in commands like \fBdir\fR and \fBcopy\fR, +the caller must prepend the desired command with +.QW "\fBcmd.exe /c\0\fR" +because built-in commands are not implemented using executables. +.RE +.TP +\fBUnix\fR (including Mac OS X) +. +The \fBexec\fR command is fully functional and works as described. +.SH "UNIX EXAMPLES" +.PP +Here are some examples of the use of the \fBexec\fR command on Unix. +To execute a simple program and get its result: +.PP +.CS +\fBexec\fR uname -a +.CE +.SS "WORKING WITH NON-ZERO RESULTS" +.PP +To execute a program that can return a non-zero result, you should +wrap the call to \fBexec\fR in \fBcatch\fR and check the contents +of the \fB\-errorcode\fR return option if you have an error: +.PP +.CS +set status 0 +if {[catch {\fBexec\fR grep foo bar.txt} results options]} { + set details [dict get $options -errorcode] + if {[lindex $details 0] eq "CHILDSTATUS"} { + set status [lindex $details 2] + } else { + # Some other error; regenerate it to let caller handle + return -options $options -level 0 $results + } +} +.CE +.VS 8.6 +.PP +This is more easily written using the \fBtry\fR command, as that makes +it simpler to trap specific types of errors. This is +done using code like this: +.PP +.CS +try { + set results [\fBexec\fR grep foo bar.txt] + set status 0 +} trap CHILDSTATUS {results options} { + set status [lindex [dict get $options -errorcode] 2] +} +.CE +.VE 8.6 +.SS "WORKING WITH QUOTED ARGUMENTS" +.PP +When translating a command from a Unix shell invocation, care should +be taken over the fact that single quote characters have no special +significance to Tcl. Thus: +.PP +.CS +awk '{sum += $1} END {print sum}' numbers.list +.CE +.PP +would be translated into something like: +.PP +.CS +\fBexec\fR awk {{sum += $1} END {print sum}} numbers.list +.CE +.SS "WORKING WITH GLOBBING" +.PP +If you are converting invocations involving shell globbing, you should +remember that Tcl does not handle globbing or expand things into +multiple arguments by default. Instead you should write things like +this: +.PP +.CS +\fBexec\fR ls -l {*}[glob *.tcl] +.CE +.SS "WORKING WITH USER-SUPPLIED SHELL SCRIPT FRAGMENTS" +.PP +One useful technique can be to expose to users of a script the ability +to specify a fragment of shell script to execute that will have some +data passed in on standard input that was produced by the Tcl program. +This is a common technique for using the \fIlpr\fR program for +printing. By far the simplest way of doing this is to pass the user's +script to the user's shell for processing, as this avoids a lot of +complexity with parsing other languages. +.PP +.CS +set lprScript [\fIget from user...\fR] +set postscriptData [\fIgenerate somehow...\fR] + +\fBexec\fR $env(SHELL) -c $lprScript << $postscriptData +.CE +.SH "WINDOWS EXAMPLES" +.PP +Here are some examples of the use of the \fBexec\fR command on Windows. +To start an instance of \fInotepad\fR editing a file without waiting +for the user to finish editing the file: +.PP +.CS +\fBexec\fR notepad myfile.txt & +.CE +.PP +To print a text file using \fInotepad\fR: +.PP +.CS +\fBexec\fR notepad /p myfile.txt +.CE +.SS "WORKING WITH CONSOLE PROGRAMS" +.PP +If a program calls other programs, such as is common with compilers, +then you may need to resort to batch files to hide the console windows +that sometimes pop up: +.PP +.CS +\fBexec\fR cmp.bat somefile.c -o somefile +.CE +.PP +With the file \fIcmp.bat\fR looking something like: +.PP +.CS +@gcc %1 %2 %3 %4 %5 %6 %7 %8 %9 +.CE +.SS "WORKING WITH COMMAND BUILT-INS" +.PP +Sometimes you need to be careful, as different programs may have the +same name and be in the path. It can then happen that typing a command +at the DOS prompt finds \fIa different program\fR than the same +command run via \fBexec\fR. This is because of the (documented) +differences in behaviour between \fBexec\fR and DOS batch files. +.PP +When in doubt, use the command \fBauto_execok\fR: it will return the +complete path to the program as seen by the \fBexec\fR command. This +applies especially when you want to run +.QW internal +commands like +\fIdir\fR from a Tcl script (if you just want to list filenames, use +the \fBglob\fR command.) To do that, use this: +.PP +.CS +\fBexec\fR {*}[auto_execok dir] *.tcl +.CE +.SS "WORKING WITH NATIVE FILENAMES" +.PP +Many programs on Windows require filename arguments to be passed in with +backslashes as pathname separators. This is done with the help of the +\fBfile nativename\fR command. For example, to make a directory (on NTFS) +encrypted so that only the current user can access it requires use of +the \fICIPHER\fR command, like this: +.PP +.CS +set secureDir "~/Desktop/Secure Directory" +file mkdir $secureDir +\fBexec\fR CIPHER /e /s:[file nativename $secureDir] +.CE +.SH "SEE ALSO" +error(n), file(n), open(n) +.SH KEYWORDS +execute, pipeline, redirection, subprocess +'\" Local Variables: +'\" mode: nroff +'\" End: diff --git a/tcl8.6/doc/exit.n b/tcl8.6/doc/exit.n new file mode 100644 index 0000000..9b4ad20 --- /dev/null +++ b/tcl8.6/doc/exit.n @@ -0,0 +1,51 @@ +'\" +'\" Copyright (c) 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. +'\" +.TH exit n "" Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +exit \- End the application +.SH SYNOPSIS +\fBexit \fR?\fIreturnCode\fR? +.BE + +.SH DESCRIPTION +.PP +Terminate the process, returning \fIreturnCode\fR to the +system as the exit status. +If \fIreturnCode\fR is not specified then it defaults +to 0. +.SH EXAMPLE +.PP +Since non-zero exit codes are usually interpreted as error cases by +the calling process, the \fBexit\fR command is an important part of +signaling that something fatal has gone wrong. This code fragment is +useful in scripts to act as a general problem trap: +.PP +.CS +proc main {} { + # ... put the real main code in here ... +} + +if {[catch {main} msg options]} { + puts stderr "unexpected script error: $msg" + if {[info exists env(DEBUG)]} { + puts stderr "---- BEGIN TRACE ----" + puts stderr [dict get $options -errorinfo] + puts stderr "---- END TRACE ----" + } + + # Reserve code 1 for "expected" error exits... + \fBexit\fR 2 +} +.CE +.SH "SEE ALSO" +exec(n) +.SH KEYWORDS +abort, exit, process diff --git a/tcl8.6/doc/expr.n b/tcl8.6/doc/expr.n new file mode 100644 index 0000000..b76b6a2 --- /dev/null +++ b/tcl8.6/doc/expr.n @@ -0,0 +1,475 @@ +'\" +'\" Copyright (c) 1993 The Regents of the University of California. +'\" Copyright (c) 1994-2000 Sun Microsystems, Inc. +'\" Copyright (c) 2005 by Kevin B. Kenny <kennykb@acm.org>. All rights reserved +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH expr n 8.5 Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +expr \- Evaluate an expression +.SH SYNOPSIS +\fBexpr \fIarg \fR?\fIarg arg ...\fR? +.BE +.SH DESCRIPTION +.PP +Concatenates \fIarg\fRs (adding separator spaces between them), +evaluates the result as a Tcl expression, and returns the value. +The operators permitted in Tcl expressions include a subset of +the operators permitted in C expressions. For those operators +common to both Tcl and C, Tcl applies the same meaning and precedence +as the corresponding C operators. +Expressions almost always yield numeric results +(integer or floating-point values). +For example, the expression +.PP +.CS +\fBexpr\fR 8.2 + 6 +.CE +.PP +evaluates to 14.2. +Tcl expressions differ from C expressions in the way that +operands are specified. Also, Tcl expressions support +non-numeric operands and string comparisons, as well as some +additional operators not found in C. +.SS OPERANDS +.PP +A Tcl expression consists of a combination of operands, operators, +parentheses and commas. +White space may be used between the operands and operators and +parentheses (or commas); it is ignored by the expression's instructions. +Where possible, operands are interpreted as integer values. +Integer values may be specified in decimal (the normal case), in binary +(if the first two characters of the operand are \fB0b\fR), in octal +(if the first two characters of the operand are \fB0o\fR), or in hexadecimal +(if the first two characters of the operand are \fB0x\fR). For +compatibility with older Tcl releases, an octal integer value is also +indicated simply when the first character of the operand is \fB0\fR, +whether or not the second character is also \fBo\fR. +If an operand does not have one of the integer formats given +above, then it is treated as a floating-point number if that is +possible. Floating-point numbers may be specified in any of several +common formats making use of the decimal digits, the decimal point \fB.\fR, +the characters \fBe\fR or \fBE\fR indicating scientific notation, and +the sign characters \fB+\fR or \fB\-\fR. For example, all of the +following are valid floating-point numbers: 2.1, 3., 6e4, 7.91e+16. +Also recognized as floating point values are the strings \fBInf\fR +and \fBNaN\fR making use of any case for each character. +If no numeric interpretation is possible (note that all literal +operands that are not numeric or boolean must be quoted with either +braces or with double quotes), then an operand is left as a string +(and only a limited set of operators may be applied to it). +.PP +Operands may be specified in any of the following ways: +.IP [1] +As a numeric value, either integer or floating-point. +.IP [2] +As a boolean value, using any form understood by \fBstring is\fR +\fBboolean\fR. +.IP [3] +As a Tcl variable, using standard \fB$\fR notation. +The variable's value will be used as the operand. +.IP [4] +As a string enclosed in double-quotes. +The expression parser will perform backslash, variable, and +command substitutions on the information between the quotes, +and use the resulting value as the operand +.IP [5] +As a string enclosed in braces. +The characters between the open brace and matching close brace +will be used as the operand without any substitutions. +.IP [6] +As a Tcl command enclosed in brackets. +The command will be executed and its result will be used as +the operand. +.IP [7] +As a mathematical function whose arguments have any of the above +forms for operands, such as \fBsin($x)\fR. See \fBMATH FUNCTIONS\fR below for +a discussion of how mathematical functions are handled. +.PP +Where the above substitutions occur (e.g. inside quoted strings), they +are performed by the expression's instructions. +However, the command parser may already have performed one round of +substitution before the expression processor was called. +As discussed below, it is usually best to enclose expressions +in braces to prevent the command parser from performing substitutions +on the contents. +.PP +For some examples of simple expressions, suppose the variable +\fBa\fR has the value 3 and +the variable \fBb\fR has the value 6. +Then the command on the left side of each of the lines below +will produce the value on the right side of the line: +.PP +.CS +.ta 6c +\fBexpr\fR 3.1 + $a \fI6.1\fR +\fBexpr\fR 2 + "$a.$b" \fI5.6\fR +\fBexpr\fR 4*[llength "6 2"] \fI8\fR +\fBexpr\fR {{word one} < "word $a"} \fI0\fR +.CE +.SS OPERATORS +.PP +The valid operators (most of which are also available as commands in +the \fBtcl::mathop\fR namespace; see the \fBmathop\fR(n) manual page +for details) are listed below, grouped in decreasing order of precedence: +.TP 20 +\fB\-\0\0+\0\0~\0\0!\fR +. +Unary minus, unary plus, bit-wise NOT, logical NOT. None of these operators +may be applied to string operands, and bit-wise NOT may be +applied only to integers. +.TP 20 +\fB**\fR +. +Exponentiation. Valid for any numeric operands. +.TP 20 +\fB*\0\0/\0\0%\fR +. +Multiply, divide, remainder. None of these operators may be +applied to string operands, and remainder may be applied only +to integers. +The remainder will always have the same sign as the divisor and +an absolute value smaller than the absolute value of the divisor. +.RS +.PP +When applied to integers, the division and remainder operators can be +considered to partition the number line into a sequence of equal-sized +adjacent non-overlapping pieces where each piece is the size of the divisor; +the division result identifies which piece the divisor lay within, and the +remainder result identifies where within that piece the divisor lay. A +consequence of this is that the result of +.QW "-57 \fB/\fR 10" +is always -6, and the result of +.QW "-57 \fB%\fR 10" +is always 3. +.RE +.TP 20 +\fB+\0\0\-\fR +. +Add and subtract. Valid for any numeric operands. +.TP 20 +\fB<<\0\0>>\fR +. +Left and right shift. Valid for integer operands only. +A right shift always propagates the sign bit. +.TP 20 +\fB<\0\0>\0\0<=\0\0>=\fR +. +Boolean less, greater, less than or equal, and greater than or equal. +Each operator produces 1 if the condition is true, 0 otherwise. +These operators may be applied to strings as well as numeric operands, +in which case string comparison is used. +.TP 20 +\fB==\0\0!=\fR +. +Boolean equal and not equal. Each operator produces a zero/one result. +Valid for all operand types. +.TP 20 +\fBeq\0\0ne\fR +. +Boolean string equal and string not equal. Each operator produces a +zero/one result. The operand types are interpreted only as strings. +.TP 20 +\fBin\0\0ni\fR +. +List containment and negated list containment. Each operator produces +a zero/one result and treats its first argument as a string and its +second argument as a Tcl list. The \fBin\fR operator indicates +whether the first argument is a member of the second argument list; +the \fBni\fR operator inverts the sense of the result. +.TP 20 +\fB&\fR +. +Bit-wise AND. Valid for integer operands only. +.TP 20 +\fB^\fR +. +Bit-wise exclusive OR. Valid for integer operands only. +.TP 20 +\fB|\fR +. +Bit-wise OR. Valid for integer operands only. +.TP 20 +\fB&&\fR +. +Logical AND. Produces a 1 result if both operands are non-zero, +0 otherwise. +Valid for boolean and numeric (integers or floating-point) operands only. +.TP 20 +\fB||\fR +. +Logical OR. Produces a 0 result if both operands are zero, 1 otherwise. +Valid for boolean and numeric (integers or floating-point) operands only. +.TP 20 +\fIx\fB?\fIy\fB:\fIz\fR +. +If-then-else, as in C. If \fIx\fR +evaluates to non-zero, then the result is the value of \fIy\fR. +Otherwise the result is the value of \fIz\fR. +The \fIx\fR operand must have a boolean or numeric value. +.PP +See the C manual for more details on the results +produced by each operator. +The exponentiation operator promotes types like the multiply and +divide operators, and produces a result that is the same as the output +of the \fBpow\fR function (after any type conversions.) +All of the binary operators but exponentiation group left-to-right +within the same precedence level; exponentiation groups right-to-left. For example, the command +.PP +.CS +\fBexpr\fR {4*2 < 7} +.CE +.PP +returns 0, while +.PP +.CS +\fBexpr\fR {2**3**2} +.CE +.PP +returns 512. +.PP +The \fB&&\fR, \fB||\fR, and \fB?:\fR operators have +.QW "lazy evaluation" , +just as in C, which means that operands are not evaluated if they are +not needed to determine the outcome. For example, in the command +.PP +.CS +\fBexpr\fR {$v ? [a] : [b]} +.CE +.PP +only one of +.QW \fB[a]\fR +or +.QW \fB[b]\fR +will actually be evaluated, +depending on the value of \fB$v\fR. Note, however, that this is +only true if the entire expression is enclosed in braces; otherwise +the Tcl parser will evaluate both +.QW \fB[a]\fR +and +.QW \fB[b]\fR +before invoking the \fBexpr\fR command. +.SS "MATH FUNCTIONS" +.PP +When the expression parser encounters a mathematical function +such as \fBsin($x)\fR, it replaces it with a call to an ordinary +Tcl function in the \fBtcl::mathfunc\fR namespace. The processing +of an expression such as: +.PP +.CS +\fBexpr\fR {sin($x+$y)} +.CE +.PP +is the same in every way as the processing of: +.PP +.CS +\fBexpr\fR {[tcl::mathfunc::sin [\fBexpr\fR {$x+$y}]]} +.CE +.PP +which in turn is the same as the processing of: +.PP +.CS +tcl::mathfunc::sin [\fBexpr\fR {$x+$y}] +.CE +.PP +The executor will search for \fBtcl::mathfunc::sin\fR using the usual +rules for resolving functions in namespaces. Either +\fB::tcl::mathfunc::sin\fR or \fB[namespace +current]::tcl::mathfunc::sin\fR will satisfy the request, and others +may as well (depending on the current \fBnamespace path\fR setting). +.PP +Some mathematical functions have several arguments, separated by commas like in C. Thus: +.PP +.CS +\fBexpr\fR {hypot($x,$y)} +.CE +.PP +ends up as +.PP +.CS +tcl::mathfunc::hypot $x $y +.CE +.PP +See the \fBmathfunc\fR(n) manual page for the math functions that are +available by default. +.SS "TYPES, OVERFLOW, AND PRECISION" +.PP +All internal computations involving integers are done calling on the +LibTomMath multiple precision integer library as required so that all +integer calculations are performed exactly. Note that in Tcl releases +prior to 8.5, integer calculations were performed with one of the C types +\fIlong int\fR or \fITcl_WideInt\fR, causing implicit range truncation +in those calculations where values overflowed the range of those types. +Any code that relied on these implicit truncations will need to explicitly +add \fBint()\fR or \fBwide()\fR function calls to expressions at the points +where such truncation is required to take place. +.PP +All internal computations involving floating-point are +done with the C type \fIdouble\fR. +When converting a string to floating-point, exponent overflow is +detected and results in the \fIdouble\fR value of \fBInf\fR or +\fB\-Inf\fR as appropriate. Floating-point overflow and underflow +are detected to the degree supported by the hardware, which is generally +pretty reliable. +.PP +Conversion among internal representations for integer, floating-point, +and string operands is done automatically as needed. +For arithmetic computations, integers are used until some +floating-point number is introduced, after which floating-point is used. +For example, +.PP +.CS +\fBexpr\fR {5 / 4} +.CE +.PP +returns 1, while +.PP +.CS +\fBexpr\fR {5 / 4.0} +\fBexpr\fR {5 / ( [string length "abcd"] + 0.0 )} +.CE +.PP +both return 1.25. +Floating-point values are always returned with a +.QW \fB.\fR +or an +.QW \fBe\fR +so that they will not look like integer values. For example, +.PP +.CS +\fBexpr\fR {20.0/5.0} +.CE +.PP +returns \fB4.0\fR, not \fB4\fR. +.SS "STRING OPERATIONS" +.PP +String values may be used as operands of the comparison operators, +although the expression evaluator tries to do comparisons as integer +or floating-point when it can, +i.e., when all arguments to the operator allow numeric interpretations, +except in the case of the \fBeq\fR and \fBne\fR operators. +If one of the operands of a comparison is a string and the other +has a numeric value, a canonical string representation of the numeric +operand value is generated to compare with the string operand. +Canonical string representation for integer values is a decimal string +format. Canonical string representation for floating-point values +is that produced by the \fB%g\fR format specifier of Tcl's +\fBformat\fR command. For example, the commands +.PP +.CS +\fBexpr\fR {"0x03" > "2"} +\fBexpr\fR {"0y" > "0x12"} +.CE +.PP +both return 1. The first comparison is done using integer +comparison, and the second is done using string comparison. +Because of Tcl's tendency to treat values as numbers whenever +possible, it is not generally a good idea to use operators like \fB==\fR +when you really want string comparison and the values of the +operands could be arbitrary; it is better in these cases to use +the \fBeq\fR or \fBne\fR operators, or the \fBstring\fR command instead. +.SH "PERFORMANCE CONSIDERATIONS" +.PP +Enclose expressions in braces for the best speed and the smallest +storage requirements. +This allows the Tcl bytecode compiler to generate the best code. +.PP +As mentioned above, expressions are substituted twice: +once by the Tcl parser and once by the \fBexpr\fR command. +For example, the commands +.PP +.CS +set a 3 +set b {$a + 2} +\fBexpr\fR $b*4 +.CE +.PP +return 11, not a multiple of 4. +This is because the Tcl parser will first substitute \fB$a + 2\fR for +the variable \fBb\fR, +then the \fBexpr\fR command will evaluate the expression \fB$a + 2*4\fR. +.PP +Most expressions do not require a second round of substitutions. +Either they are enclosed in braces or, if not, +their variable and command substitutions yield numbers or strings +that do not themselves require substitutions. +However, because a few unbraced expressions +need two rounds of substitutions, +the bytecode compiler must emit +additional instructions to handle this situation. +The most expensive code is required for +unbraced expressions that contain command substitutions. +These expressions must be implemented by generating new code +each time the expression is executed. +When the expression is unbraced to allow the substitution of a function or +operator, consider using the commands documented in the \fBmathfunc\fR(n) or +\fBmathop\fR(n) manual pages directly instead. +.SH EXAMPLES +.PP +Define a procedure that computes an +.QW interesting +mathematical function: +.PP +.CS +proc tcl::mathfunc::calc {x y} { + \fBexpr\fR { ($x**2 - $y**2) / exp($x**2 + $y**2) } +} +.CE +.PP +Convert polar coordinates into cartesian coordinates: +.PP +.CS +# convert from ($radius,$angle) +set x [\fBexpr\fR { $radius * cos($angle) }] +set y [\fBexpr\fR { $radius * sin($angle) }] +.CE +.PP +Convert cartesian coordinates into polar coordinates: +.PP +.CS +# convert from ($x,$y) +set radius [\fBexpr\fR { hypot($y, $x) }] +set angle [\fBexpr\fR { atan2($y, $x) }] +.CE +.PP +Print a message describing the relationship of two string values to +each other: +.PP +.CS +puts "a and b are [\fBexpr\fR {$a eq $b ? {equal} : {different}}]" +.CE +.PP +Set a variable to whether an environment variable is both defined at +all and also set to a true boolean value: +.PP +.CS +set isTrue [\fBexpr\fR { + [info exists ::env(SOME_ENV_VAR)] && + [string is true -strict $::env(SOME_ENV_VAR)] +}] +.CE +.PP +Generate a random integer in the range 0..99 inclusive: +.PP +.CS +set randNum [\fBexpr\fR { int(100 * rand()) }] +.CE +.SH "SEE ALSO" +array(n), for(n), if(n), mathfunc(n), mathop(n), namespace(n), proc(n), +string(n), Tcl(n), while(n) +.SH KEYWORDS +arithmetic, boolean, compare, expression, fuzzy comparison +.SH COPYRIGHT +.nf +Copyright (c) 1993 The Regents of the University of California. +Copyright (c) 1994-2000 Sun Microsystems Incorporated. +Copyright (c) 2005 by Kevin B. Kenny <kennykb@acm.org>. All rights reserved. +.fi +'\" Local Variables: +'\" mode: nroff +'\" End: diff --git a/tcl8.6/doc/fblocked.n b/tcl8.6/doc/fblocked.n new file mode 100644 index 0000000..2841aee --- /dev/null +++ b/tcl8.6/doc/fblocked.n @@ -0,0 +1,67 @@ +'\" +'\" Copyright (c) 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. +'\" +.TH fblocked n 7.5 Tcl "Tcl Built-In Commands" +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +fblocked \- Test whether the last input operation exhausted all available input +.SH SYNOPSIS +\fBfblocked \fIchannelId\fR +.BE + +.SH DESCRIPTION +.PP +The \fBfblocked\fR command returns 1 if the most recent input operation +on \fIchannelId\fR returned less information than requested because all +available input was exhausted. +For example, if \fBgets\fR is invoked when there are only three +characters available for input and no end-of-line sequence, \fBgets\fR +returns an empty string and a subsequent call to \fBfblocked\fR will +return 1. +.PP +\fIChannelId\fR must be an identifier for an open channel such as a +Tcl standard channel (\fBstdin\fR, \fBstdout\fR, or \fBstderr\fR), +the return value from an invocation of \fBopen\fR or \fBsocket\fR, or +the result of a channel creation command provided by a Tcl extension. +.SH EXAMPLE +The \fBfblocked\fR command is particularly useful when writing network +servers, as it allows you to write your code in a line-by-line style +without preventing the servicing of other connections. This can be +seen in this simple echo-service: +.PP +.CS +# This is called whenever a new client connects to the server +proc connect {chan host port} { + set clientName [format <%s:%d> $host $port] + puts "connection from $clientName" + fconfigure $chan -blocking 0 -buffering line + fileevent $chan readable [list echoLine $chan $clientName] +} + +# This is called whenever either at least one byte of input +# data is available, or the channel was closed by the client. +proc echoLine {chan clientName} { + gets $chan line + if {[eof $chan]} { + puts "finishing connection from $clientName" + close $chan + } elseif {![\fBfblocked\fR $chan]} { + # Didn't block waiting for end-of-line + puts "$clientName - $line" + puts $chan $line + } +} + +# Create the server socket and enter the event-loop to wait +# for incoming connections... +socket -server connect 12345 +vwait forever +.CE +.SH "SEE ALSO" +gets(n), open(n), read(n), socket(n), Tcl_StandardChannels(3) +.SH KEYWORDS +blocking, nonblocking diff --git a/tcl8.6/doc/fconfigure.n b/tcl8.6/doc/fconfigure.n new file mode 100644 index 0000000..8da76c6 --- /dev/null +++ b/tcl8.6/doc/fconfigure.n @@ -0,0 +1,289 @@ +'\" +'\" Copyright (c) 1995-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. +'\" +.TH fconfigure n 8.3 Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +fconfigure \- Set and get options on a channel +.SH SYNOPSIS +.nf +\fBfconfigure \fIchannelId\fR +\fBfconfigure \fIchannelId\fR \fIname\fR +\fBfconfigure \fIchannelId\fR \fIname value \fR?\fIname value ...\fR? +.fi +.BE +.SH DESCRIPTION +.PP +The \fBfconfigure\fR command sets and retrieves options for channels. +.PP +\fIChannelId\fR identifies the channel for which to set or query an +option and must refer to an open channel such as a Tcl standard +channel (\fBstdin\fR, \fBstdout\fR, or \fBstderr\fR), the return +value from an invocation of \fBopen\fR or \fBsocket\fR, or the result +of a channel creation command provided by a Tcl extension. +.PP +If no \fIname\fR or \fIvalue\fR arguments are supplied, the command +returns a list containing alternating option names and values for the channel. +If \fIname\fR is supplied but no \fIvalue\fR then the command returns +the current value of the given option. +If one or more pairs of \fIname\fR and \fIvalue\fR are supplied, the +command sets each of the named options to the corresponding \fIvalue\fR; +in this case the return value is an empty string. +.PP +The options described below are supported for all channels. In addition, +each channel type may add options that only it supports. See the manual +entry for the command that creates each type of channels for the options +that that specific type of channel supports. For example, see the manual +entry for the \fBsocket\fR command for additional options for sockets, and +the \fBopen\fR command for additional options for serial devices. +.TP +\fB\-blocking\fR \fIboolean\fR +The \fB\-blocking\fR option determines whether I/O operations on the +channel can cause the process to block indefinitely. +The value of the option must be a proper boolean value. +Channels are normally in blocking mode; if a channel is placed into +nonblocking mode it will affect the operation of the \fBgets\fR, +\fBread\fR, \fBputs\fR, \fBflush\fR, and \fBclose\fR commands by +allowing them to operate asynchronously; +see the documentation for those commands for details. +For nonblocking mode to work correctly, the application must be +using the Tcl event loop (e.g. by calling \fBTcl_DoOneEvent\fR or +invoking the \fBvwait\fR command). +.TP +\fB\-buffering\fR \fInewValue\fR +. +If \fInewValue\fR is \fBfull\fR then the I/O system will buffer output +until its internal buffer is full or until the \fBflush\fR command is +invoked. If \fInewValue\fR is \fBline\fR, then the I/O system will +automatically flush output for the channel whenever a newline character +is output. If \fInewValue\fR is \fBnone\fR, the I/O system will flush +automatically after every output operation. The default is for +\fB\-buffering\fR to be set to \fBfull\fR except for channels that +connect to terminal-like devices; for these channels the initial setting +is \fBline\fR. Additionally, \fBstdin\fR and \fBstdout\fR are +initially set to \fBline\fR, and \fBstderr\fR is set to \fBnone\fR. +.TP +\fB\-buffersize\fR \fInewSize\fR +. +\fINewvalue\fR must be an integer; its value is used to set the size of +buffers, in bytes, subsequently allocated for this channel to store input +or output. \fINewvalue\fR must be between one and one million, allowing +buffers of one to one million bytes in size. +.TP +\fB\-encoding\fR \fIname\fR +. +This option is used to specify the encoding of the channel, so that the data +can be converted to and from Unicode for use in Tcl. For instance, in +order for Tcl to read characters from a Japanese file in \fBshiftjis\fR +and properly process and display the contents, the encoding would be set +to \fBshiftjis\fR. Thereafter, when reading from the channel, the bytes in +the Japanese file would be converted to Unicode as they are read. +Writing is also supported \- as Tcl strings are written to the channel they +will automatically be converted to the specified encoding on output. +.RS +.PP +If a file contains pure binary data (for instance, a JPEG image), the +encoding for the channel should be configured to be \fBbinary\fR. Tcl +will then assign no interpretation to the data in the file and simply read or +write raw bytes. The Tcl \fBbinary\fR command can be used to manipulate this +byte-oriented data. It is usually better to set the +\fB\-translation\fR option to \fBbinary\fR when you want to transfer +binary data, as this turns off the other automatic interpretations of +the bytes in the stream as well. +.PP +The default encoding for newly opened channels is the same platform- and +locale-dependent system encoding used for interfacing with the operating +system, as returned by \fBencoding system\fR. +.RE +.TP +\fB\-eofchar\fR \fIchar\fR +.TP +\fB\-eofchar\fR \fB{\fIinChar outChar\fB}\fR +. +This option supports DOS file systems that use Control-z (\ex1a) as an +end of file marker. If \fIchar\fR is not an empty string, then this +character signals end-of-file when it is encountered during input. For +output, the end-of-file character is output when the channel is closed. +If \fIchar\fR is the empty string, then there is no special end of file +character marker. For read-write channels, a two-element list specifies +the end of file marker for input and output, respectively. As a +convenience, when setting the end-of-file character for a read-write +channel you can specify a single value that will apply to both reading +and writing. When querying the end-of-file character of a read-write +channel, a two-element list will always be returned. The default value +for \fB\-eofchar\fR is the empty string in all cases except for files +under Windows. In that case the \fB\-eofchar\fR is Control-z (\ex1a) for +reading and the empty string for writing. +The acceptable range for \fB\-eofchar\fR values is \ex01 - \ex7f; +attempting to set \fB\-eofchar\fR to a value outside of this range will +generate an error. +.TP +\fB\-translation\fR \fImode\fR +.TP +\fB\-translation\fR \fB{\fIinMode outMode\fB}\fR +. +In Tcl scripts the end of a line is always represented using a single +newline character (\en). However, in actual files and devices the end of +a line may be represented differently on different platforms, or even for +different devices on the same platform. For example, under UNIX newlines +are used in files, whereas carriage-return-linefeed sequences are +normally used in network connections. On input (i.e., with \fBgets\fR +and \fBread\fR) the Tcl I/O system automatically translates the external +end-of-line representation into newline characters. Upon output (i.e., +with \fBputs\fR), the I/O system translates newlines to the external +end-of-line representation. The default translation mode, \fBauto\fR, +handles all the common cases automatically, but the \fB\-translation\fR +option provides explicit control over the end of line translations. +.RS +.PP +The value associated with \fB\-translation\fR is a single item for +read-only and write-only channels. The value is a two-element list for +read-write channels; the read translation mode is the first element of +the list, and the write translation mode is the second element. As a +convenience, when setting the translation mode for a read-write channel +you can specify a single value that will apply to both reading and +writing. When querying the translation mode of a read-write channel, a +two-element list will always be returned. The following values are +currently supported: +.TP +\fBauto\fR +. +As the input translation mode, \fBauto\fR treats any of newline +(\fBlf\fR), carriage return (\fBcr\fR), or carriage return followed by a +newline (\fBcrlf\fR) as the end of line representation. The end of line +representation can even change from line-to-line, and all cases are +translated to a newline. As the output translation mode, \fBauto\fR +chooses a platform specific representation; for sockets on all platforms +Tcl chooses \fBcrlf\fR, for all Unix flavors, it chooses \fBlf\fR, and +for the various flavors of Windows it chooses \fBcrlf\fR. The default +setting for \fB\-translation\fR is \fBauto\fR for both input and output. +.TP +\fBbinary\fR +. +No end-of-line translations are performed. This is nearly identical to +\fBlf\fR mode, except that in addition \fBbinary\fR mode also sets the +end-of-file character to the empty string (which disables it) and sets the +encoding to \fBbinary\fR (which disables encoding filtering). See the +description of \fB\-eofchar\fR and \fB\-encoding\fR for more information. +.RS +.PP +Internally, i.e. when it comes to the actual behaviour of the +translator this value \fBis\fR identical to \fBlf\fR and is therefore +reported as such when queried. Even if \fBbinary\fR was used to set +the translation. +.RE +.TP +\fBcr\fR +. +The end of a line in the underlying file or device is represented by a +single carriage return character. As the input translation mode, +\fBcr\fR mode converts carriage returns to newline characters. As the +output translation mode, \fBcr\fR mode translates newline characters to +carriage returns. +.TP +\fBcrlf\fR +. +The end of a line in the underlying file or device is represented by a +carriage return character followed by a linefeed character. As the input +translation mode, \fBcrlf\fR mode converts carriage-return-linefeed +sequences to newline characters. As the output translation mode, +\fBcrlf\fR mode translates newline characters to carriage-return-linefeed +sequences. This mode is typically used on Windows platforms and for +network connections. +.TP +\fBlf\fR +. +The end of a line in the underlying file or device is represented by a +single newline (linefeed) character. In this mode no translations occur +during either input or output. This mode is typically used on UNIX +platforms. +.RE +.PP +.SH "STANDARD CHANNELS" +.PP +The Tcl standard channels (\fBstdin\fR, \fBstdout\fR, and \fBstderr\fR) +can be configured through this command like every other channel opened +by the Tcl library. Beyond the standard options described above they +will also support any special option according to their current type. +If, for example, a Tcl application is started by the \fBinet\fR +super-server common on Unix system its Tcl standard channels will be +sockets and thus support the socket options. +.SH EXAMPLES +.PP +Instruct Tcl to always send output to \fBstdout\fR immediately, +whether or not it is to a terminal: +.PP +.CS +\fBfconfigure\fR stdout -buffering none +.CE +.PP +Open a socket and read lines from it without ever blocking the +processing of other events: +.PP +.CS +set s [socket some.where.com 12345] +\fBfconfigure\fR $s -blocking 0 +fileevent $s readable "readMe $s" +proc readMe chan { + if {[gets $chan line] < 0} { + if {[eof $chan]} { + close $chan + return + } + # Could not read a complete line this time; Tcl's + # internal buffering will hold the partial line for us + # until some more data is available over the socket. + } else { + puts stdout $line + } +} +.CE +.PP +Read a PPM-format image from a file: +.PP +.CS +# Open the file and put it into Unix ASCII mode +set f [open teapot.ppm] +\fBfconfigure\fR $f \-encoding ascii \-translation lf + +# Get the header +if {[gets $f] ne "P6"} { + error "not a raw\-bits PPM" +} + +# Read lines until we have got non-comment lines +# that supply us with three decimal values. +set words {} +while {[llength $words] < 3} { + gets $f line + if {[string match "#*" $line]} continue + lappend words {*}[join [scan $line %d%d%d]] +} + +# Those words supply the size of the image and its +# overall depth per channel. Assign to variables. +lassign $words xSize ySize depth + +# Now switch to binary mode to pull in the data, +# one byte per channel (red,green,blue) per pixel. +\fBfconfigure\fR $f \-translation binary +set numDataBytes [expr {3 * $xSize * $ySize}] +set data [read $f $numDataBytes] + +close $f +.CE +.SH "SEE ALSO" +close(n), flush(n), gets(n), open(n), puts(n), read(n), socket(n), +Tcl_StandardChannels(3) +.SH KEYWORDS +blocking, buffering, carriage return, end of line, flushing, linemode, +newline, nonblocking, platform, translation, encoding, filter, byte array, +binary +'\" Local Variables: +'\" mode: nroff +'\" End: diff --git a/tcl8.6/doc/fcopy.n b/tcl8.6/doc/fcopy.n new file mode 100644 index 0000000..d39c803 --- /dev/null +++ b/tcl8.6/doc/fcopy.n @@ -0,0 +1,182 @@ +'\" +'\" Copyright (c) 1993 The Regents of the University of California. +'\" Copyright (c) 1994-1997 Sun Microsystems, Inc. +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH fcopy n 8.0 Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +fcopy \- Copy data from one channel to another +.SH SYNOPSIS +\fBfcopy \fIinchan\fR \fIoutchan\fR ?\fB\-size \fIsize\fR? ?\fB\-command \fIcallback\fR? +.BE + +.SH DESCRIPTION +.PP +The \fBfcopy\fR command copies data from one I/O channel, \fIinchan\fR to another I/O channel, \fIoutchan\fR. +The \fBfcopy\fR command leverages the buffering in the Tcl I/O system to +avoid extra copies and to avoid buffering too much data in +main memory when copying large files to slow destinations like +network sockets. +.PP +The \fBfcopy\fR +command transfers data from \fIinchan\fR until end of file +or \fIsize\fR bytes or characters have been +transferred; \fIsize\fR is in bytes if the two channels are using the +same encoding, and is in characters otherwise. +If no \fB\-size\fR argument is given, +then the copy goes until end of file. +All the data read from \fIinchan\fR is copied to \fIoutchan\fR. +Without the \fB\-command\fR option, \fBfcopy\fR blocks until the copy is complete +and returns the number of bytes or characters (using the same rules as +for the \fB\-size\fR option) written to \fIoutchan\fR. +.PP +The \fB\-command\fR argument makes \fBfcopy\fR work in the background. +In this case it returns immediately and the \fIcallback\fR is invoked +later when the copy completes. +The \fIcallback\fR is called with +one or two additional +arguments that indicates how many bytes were written to \fIoutchan\fR. +If an error occurred during the background copy, the second argument is the +error string associated with the error. +With a background copy, +it is not necessary to put \fIinchan\fR or \fIoutchan\fR into +non-blocking mode; the \fBfcopy\fR command takes care of that automatically. +However, it is necessary to enter the event loop by using +the \fBvwait\fR command or by using Tk. +.PP +You are not allowed to do other input operations with \fIinchan\fR, or +output operations with \fIoutchan\fR, during a background +\fBfcopy\fR. The converse is entirely legitimate, as exhibited by the +bidirectional fcopy example below. +.PP +If either \fIinchan\fR or \fIoutchan\fR get closed +while the copy is in progress, the current copy is stopped +and the command callback is \fInot\fR made. +If \fIinchan\fR is closed, +then all data already queued for \fIoutchan\fR is written out. +.PP +Note that \fIinchan\fR can become readable during a background copy. +You should turn off any \fBfileevent\fR handlers during a background +copy so those handlers do not interfere with the copy. +Any wrong-sided I/O attempted (by a \fBfileevent\fR handler or otherwise) will get a +.QW "channel busy" +error. +.PP +\fBFcopy\fR translates end-of-line sequences in \fIinchan\fR and \fIoutchan\fR +according to the \fB\-translation\fR option +for these channels. +See the manual entry for \fBfconfigure\fR for details on the +\fB\-translation\fR option. +The translations mean that the number of bytes read from \fIinchan\fR +can be different than the number of bytes written to \fIoutchan\fR. +Only the number of bytes written to \fIoutchan\fR is reported, +either as the return value of a synchronous \fBfcopy\fR or +as the argument to the callback for an asynchronous \fBfcopy\fR. +.PP +\fBFcopy\fR obeys the encodings and character translations configured +for the channels. This +means that the incoming characters are converted internally first +UTF-8 and then into the encoding of the channel \fBfcopy\fR writes +to. See the manual entry for \fBfconfigure\fR for details on the +\fB\-encoding\fR and \fB\-translation\fR options. No conversion is +done if both channels are +set to encoding +.QW binary +and have matching translations. If only the output channel is set to encoding +.QW binary +the system will write the internal UTF-8 representation of the incoming +characters. If only the input channel is set to encoding +.QW binary +the system will assume that the incoming +bytes are valid UTF-8 characters and convert them according to the +output encoding. The behaviour of the system for bytes which are not +valid UTF-8 characters is undefined in this case. +.SH EXAMPLES +.PP +The first example transfers the contents of one channel exactly to +another. Note that when copying one file to another, it is better to +use \fBfile copy\fR which also copies file metadata (e.g. the file +access permissions) where possible. +.PP +.CS +fconfigure $in -translation binary +fconfigure $out -translation binary +\fBfcopy\fR $in $out +.CE +.PP +This second example shows how the callback gets +passed the number of bytes transferred. +It also uses vwait to put the application into the event loop. +Of course, this simplified example could be done without the command +callback. +.PP +.CS +proc Cleanup {in out bytes {error {}}} { + global total + set total $bytes + close $in + close $out + if {[string length $error] != 0} { + # error occurred during the copy + } +} +set in [open $file1] +set out [socket $server $port] +\fBfcopy\fR $in $out -command [list Cleanup $in $out] +vwait total +.CE +.PP +The third example copies in chunks and tests for end of file +in the command callback. +.PP +.CS +proc CopyMore {in out chunk bytes {error {}}} { + global total done + incr total $bytes + if {([string length $error] != 0) || [eof $in]} { + set done $total + close $in + close $out + } else { + \fBfcopy\fR $in $out -size $chunk \e + -command [list CopyMore $in $out $chunk] + } +} +set in [open $file1] +set out [socket $server $port] +set chunk 1024 +set total 0 +\fBfcopy\fR $in $out -size $chunk \e + -command [list CopyMore $in $out $chunk] +vwait done +.CE +.PP +The fourth example starts an asynchronous, bidirectional fcopy between +two sockets. Those could also be pipes from two [open "|hal 9000" r+] +(though their conversation would remain secret to the script, since +all four fileevent slots are busy). +.PP +.CS +set flows 2 +proc Done {dir args} { + global flows done + puts "$dir is over." + incr flows -1 + if {$flows<=0} {set done 1} +} +\fBfcopy\fR $sok1 $sok2 -command [list Done UP] +\fBfcopy\fR $sok2 $sok1 -command [list Done DOWN] +vwait done +.CE +.SH "SEE ALSO" +eof(n), fblocked(n), fconfigure(n), file(n) +.SH KEYWORDS +blocking, channel, end of line, end of file, nonblocking, read, translation +'\" Local Variables: +'\" mode: nroff +'\" End: diff --git a/tcl8.6/doc/file.n b/tcl8.6/doc/file.n new file mode 100644 index 0000000..2f8b70c --- /dev/null +++ b/tcl8.6/doc/file.n @@ -0,0 +1,549 @@ +'\" +'\" Copyright (c) 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. +'\" +.TH file n 8.3 Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +file \- Manipulate file names and attributes +.SH SYNOPSIS +\fBfile \fIoption\fR \fIname\fR ?\fIarg arg ...\fR? +.BE +.SH DESCRIPTION +.PP +This command provides several operations on a file's name or attributes. +\fIName\fR is the name of a file; if it starts with a tilde, then tilde +substitution is done before executing the command (see the manual entry for +\fBfilename\fR for details). \fIOption\fR indicates what to do with the +file name. Any unique abbreviation for \fIoption\fR is acceptable. The +valid options are: +.TP +\fBfile atime \fIname\fR ?\fItime\fR? +. +Returns a decimal string giving the time at which file \fIname\fR was last +accessed. If \fItime\fR is specified, it is an access time to set +for the file. The time is measured in the standard POSIX fashion as +seconds from a fixed starting time (often January 1, 1970). If the file +does not exist or its access time cannot be queried or set then an error is +generated. On Windows, FAT file systems do not support access time. +.TP +\fBfile attributes \fIname\fR +.TP +\fBfile attributes \fIname\fR ?\fIoption\fR? +.TP +\fBfile attributes \fIname\fR ?\fIoption value option value...\fR? +. +This subcommand returns or sets platform specific values associated +with a file. The first form returns a list of the platform specific +flags and their values. The second form returns the value for the +specific option. The third form sets one or more of the values. The +values are as follows: +.RS +.PP +On Unix, \fB\-group\fR gets or sets the group name for the file. A group id +can be given to the command, but it returns a group name. \fB\-owner\fR gets +or sets the user name of the owner of the file. The command returns the +owner name, but the numerical id can be passed when setting the +owner. \fB\-permissions\fR sets or retrieves the octal code that chmod(1) +uses. This command does also has limited support for setting using the +symbolic attributes for chmod(1), of the form [ugo]?[[+\-=][rwxst],[...]], +where multiple symbolic attributes can be separated by commas (example: +\fBu+s,go\-rw\fR add sticky bit for user, remove read and write +permissions for group and other). A simplified \fBls\fR style string, +of the form rwxrwxrwx (must be 9 characters), is also supported +(example: \fBrwxr\-xr\-t\fR is equivalent to 01755). +On versions of Unix supporting file flags, \fB\-readonly\fR gives the +value or sets or clears the readonly attribute of the file, +i.e. the user immutable flag \fBuchg\fR to chflags(1). +.PP +On Windows, \fB\-archive\fR gives the value or sets or clears the +archive attribute of the file. \fB\-hidden\fR gives the value or sets +or clears the hidden attribute of the file. \fB\-longname\fR will +expand each path element to its long version. This attribute cannot be +set. \fB\-readonly\fR gives the value or sets or clears the readonly +attribute of the file. \fB\-shortname\fR gives a string where every +path element is replaced with its short (8.3) version of the +name. This attribute cannot be set. \fB\-system\fR gives or sets or +clears the value of the system attribute of the file. +.PP +On Mac OS X and Darwin, \fB\-creator\fR gives or sets the +Finder creator type of the file. \fB\-hidden\fR gives or sets or clears +the hidden attribute of the file. \fB\-readonly\fR gives or sets or +clears the readonly attribute of the file. \fB\-rsrclength\fR gives +the length of the resource fork of the file, this attribute can only be +set to the value 0, which results in the resource fork being stripped +off the file. +.RE +.TP +\fBfile channels\fR ?\fIpattern\fR? +. +If \fIpattern\fR is not specified, returns a list of names of all +registered open channels in this interpreter. If \fIpattern\fR is +specified, only those names matching \fIpattern\fR are returned. Matching +is determined using the same rules as for \fBstring match\fR. +.TP +\fBfile copy \fR?\fB\-force\fR? ?\fB\-\|\-\fR? \fIsource\fR \fItarget\fR +.TP +\fBfile copy \fR?\fB\-force\fR? ?\fB\-\|\-\fR? \fIsource\fR ?\fIsource\fR ...? \fItargetDir\fR +. +The first form makes a copy of the file or directory \fIsource\fR under +the pathname \fItarget\fR. If \fItarget\fR is an existing directory, +then the second form is used. The second form makes a copy inside +\fItargetDir\fR of each \fIsource\fR file listed. If a directory is +specified as a \fIsource\fR, then the contents of the directory will be +recursively copied into \fItargetDir\fR. Existing files will not be +overwritten unless the \fB\-force\fR option is specified (when Tcl will +also attempt to adjust permissions on the destination file or directory +if that is necessary to allow the copy to proceed). When copying +within a single filesystem, \fIfile copy\fR will copy soft links (i.e. +the links themselves are copied, not the things they point to). Trying +to overwrite a non-empty directory, overwrite a directory with a file, +or overwrite a file with a directory will all result in errors even if +\fB\-force\fR was specified. Arguments are processed in the order +specified, halting at the first error, if any. A \fB\-\|\-\fR marks +the end of switches; the argument following the \fB\-\|\-\fR will be +treated as a \fIsource\fR even if it starts with a \fB\-\fR. +.TP +\fBfile delete \fR?\fB\-force\fR? ?\fB\-\|\-\fR? ?\fIpathname\fR ... ? +. +Removes the file or directory specified by each \fIpathname\fR +argument. Non-empty directories will be removed only if the +\fB\-force\fR option is specified. When operating on symbolic links, +the links themselves will be deleted, not the objects they point to. +Trying to delete a non-existent file is not considered an error. +Trying to delete a read-only file will cause the file to be deleted, +even if the \fB\-force\fR flags is not specified. If the \fB\-force\fR +option is specified on a directory, Tcl will attempt both to change +permissions and move the current directory +.QW pwd +out of the given path if that is necessary to allow the deletion to +proceed. Arguments are processed in the order specified, halting at +the first error, if any. +A \fB\-\|\-\fR marks the end of switches; the argument following the +\fB\-\|\-\fR will be treated as a \fIpathname\fR even if it starts with +a \fB\-\fR. +.TP +\fBfile dirname \fIname\fR +Returns a name comprised of all of the path components in \fIname\fR +excluding the last element. If \fIname\fR is a relative file name and +only contains one path element, then returns +.QW \fB.\fR . +If \fIname\fR refers to a root directory, then the root directory is +returned. For example, +.RS +.PP +.CS +\fBfile dirname\fR c:/ +.CE +.PP +returns \fBc:/\fR. +.PP +Note that tilde substitution will only be +performed if it is necessary to complete the command. For example, +.PP +.CS +\fBfile dirname\fR ~/src/foo.c +.CE +.PP +returns \fB~/src\fR, whereas +.PP +.CS +\fBfile dirname\fR ~ +.CE +.PP +returns \fB/home\fR (or something similar). +.RE +.TP +\fBfile executable \fIname\fR +. +Returns \fB1\fR if file \fIname\fR is executable by the current user, +\fB0\fR otherwise. On Windows, which does not have an executable attribute, +the command treats all directories and any files with extensions +\fBexe\fR, \fBcom\fR, \fBcmd\fR or \fBbat\fR as executable. +.TP +\fBfile exists \fIname\fR +. +Returns \fB1\fR if file \fIname\fR exists and the current user has +search privileges for the directories leading to it, \fB0\fR otherwise. +.TP +\fBfile extension \fIname\fR +. +Returns all of the characters in \fIname\fR after and including the last +dot in the last element of \fIname\fR. If there is no dot in the last +element of \fIname\fR then returns the empty string. +.TP +\fBfile isdirectory \fIname\fR +. +Returns \fB1\fR if file \fIname\fR is a directory, \fB0\fR otherwise. +.TP +\fBfile isfile \fIname\fR +. +Returns \fB1\fR if file \fIname\fR is a regular file, \fB0\fR otherwise. +.TP +\fBfile join \fIname\fR ?\fIname ...\fR? +. +Takes one or more file names and combines them, using the correct path +separator for the current platform. If a particular \fIname\fR is +relative, then it will be joined to the previous file name argument. +Otherwise, any earlier arguments will be discarded, and joining will +proceed from the current argument. For example, +.RS +.PP +.CS +\fBfile join\fR a b /foo bar +.CE +.PP +returns \fB/foo/bar\fR. +.PP +Note that any of the names can contain separators, and that the result +is always canonical for the current platform: \fB/\fR for Unix and +Windows. +.RE +.TP +\fBfile link\fR ?\fI\-linktype\fR? \fIlinkName\fR ?\fItarget\fR? +. +If only one argument is given, that argument is assumed to be +\fIlinkName\fR, and this command returns the value of the link given by +\fIlinkName\fR (i.e. the name of the file it points to). If +\fIlinkName\fR is not a link or its value cannot be read (as, for example, +seems to be the case with hard links, which look just like ordinary +files), then an error is returned. +.RS +.PP +If 2 arguments are given, then these are assumed to be \fIlinkName\fR +and \fItarget\fR. If \fIlinkName\fR already exists, or if \fItarget\fR +does not exist, an error will be returned. Otherwise, Tcl creates a new +link called \fIlinkName\fR which points to the existing filesystem +object at \fItarget\fR (which is also the returned value), where the +type of the link is platform-specific (on Unix a symbolic link will be +the default). This is useful for the case where the user wishes to +create a link in a cross-platform way, and does not care what type of +link is created. +.PP +If the user wishes to make a link of a specific type only, (and signal an +error if for some reason that is not possible), then the optional +\fI\-linktype\fR argument should be given. Accepted values for +\fI\-linktype\fR are +.QW \fB\-symbolic\fR +and +.QW \fB\-hard\fR . +.PP +On Unix, symbolic links can be made to relative paths, and those paths +must be relative to the actual \fIlinkName\fR's location (not to the +cwd), but on all other platforms where relative links are not supported, +target paths will always be converted to absolute, normalized form +before the link is created (and therefore relative paths are interpreted +as relative to the cwd). Furthermore, +.QW ~user +paths are always expanded +to absolute form. When creating links on filesystems that either do not +support any links, or do not support the specific type requested, an +error message will be returned. Most Unix platforms support both +symbolic and hard links (the latter for files only). Windows +supports symbolic directory links and hard file links on NTFS drives. +.RE +.TP +\fBfile lstat \fIname varName\fR +. +Same as \fBstat\fR option (see below) except uses the \fIlstat\fR +kernel call instead of \fIstat\fR. This means that if \fIname\fR +refers to a symbolic link the information returned in \fIvarName\fR +is for the link rather than the file it refers to. On systems that +do not support symbolic links this option behaves exactly the same +as the \fBstat\fR option. +.TP +\fBfile mkdir\fR ?\fIdir\fR ...? +. +Creates each directory specified. For each pathname \fIdir\fR specified, +this command will create all non-existing parent directories as +well as \fIdir\fR itself. If an existing directory is specified, then +no action is taken and no error is returned. Trying to overwrite an existing +file with a directory will result in an error. Arguments are processed in +the order specified, halting at the first error, if any. +.TP +\fBfile mtime \fIname\fR ?\fItime\fR? +. +Returns a decimal string giving the time at which file \fIname\fR was last +modified. If \fItime\fR is specified, it is a modification time to set for +the file (equivalent to Unix \fBtouch\fR). The time is measured in the +standard POSIX fashion as seconds from a fixed starting time (often January +1, 1970). If the file does not exist or its modified time cannot be queried +or set then an error is generated. +.TP +\fBfile nativename \fIname\fR +. +Returns the platform-specific name of the file. This is useful if the +filename is needed to pass to a platform-specific call, such as to a +subprocess via \fBexec\fR under Windows (see \fBEXAMPLES\fR below). +.TP +\fBfile normalize \fIname\fR +. +Returns a unique normalized path representation for the file-system +object (file, directory, link, etc), whose string value can be used as a +unique identifier for it. A normalized path is an absolute path which has +all +.QW ../ +and +.QW ./ +removed. Also it is one which is in the +.QW standard +format for the native platform. On Unix, this means the segments +leading up to the path must be free of symbolic links/aliases (but the +very last path component may be a symbolic link), and on Windows it also +means we want the long form with that form's case-dependence (which +gives us a unique, case-dependent path). The one exception concerning the +last link in the path is necessary, because Tcl or the user may wish to +operate on the actual symbolic link itself (for example \fBfile delete\fR, +\fBfile rename\fR, \fBfile copy\fR are defined to operate on symbolic +links, not on the things that they point to). +.TP +\fBfile owned \fIname\fR +. +Returns \fB1\fR if file \fIname\fR is owned by the current user, \fB0\fR +otherwise. +.TP +\fBfile pathtype \fIname\fR +. +Returns one of \fBabsolute\fR, \fBrelative\fR, \fBvolumerelative\fR. If +\fIname\fR refers to a specific file on a specific volume, the path type will +be \fBabsolute\fR. If \fIname\fR refers to a file relative to the current +working directory, then the path type will be \fBrelative\fR. If \fIname\fR +refers to a file relative to the current working directory on a specified +volume, or to a specific file on the current working volume, then the path +type is \fBvolumerelative\fR. +.TP +\fBfile readable \fIname\fR +. +Returns \fB1\fR if file \fIname\fR is readable by the current user, +\fB0\fR otherwise. +.TP +\fBfile readlink \fIname\fR +. +Returns the value of the symbolic link given by \fIname\fR (i.e. the name +of the file it points to). If \fIname\fR is not a symbolic link or its +value cannot be read, then an error is returned. On systems that do not +support symbolic links this option is undefined. +.TP +\fBfile rename \fR?\fB\-force\fR? ?\fB\-\|\-\fR? \fIsource\fR \fItarget\fR +.TP +\fBfile rename \fR?\fB\-force\fR? ?\fB\-\|\-\fR? \fIsource\fR ?\fIsource\fR ...? \fItargetDir\fR +. +The first form takes the file or directory specified by pathname +\fIsource\fR and renames it to \fItarget\fR, moving the file if the +pathname \fItarget\fR specifies a name in a different directory. If +\fItarget\fR is an existing directory, then the second form is used. +The second form moves each \fIsource\fR file or directory into the +directory \fItargetDir\fR. Existing files will not be overwritten +unless the \fB\-force\fR option is specified. When operating inside a +single filesystem, Tcl will rename symbolic links rather than the +things that they point to. Trying to overwrite a non-empty directory, +overwrite a directory with a file, or a file with a directory will all +result in errors. Arguments are processed in the order specified, +halting at the first error, if any. A \fB\-\|\-\fR marks the end of +switches; the argument following the \fB\-\|\-\fR will be treated as a +\fIsource\fR even if it starts with a \fB\-\fR. +.TP +\fBfile rootname \fIname\fR +. +Returns all of the characters in \fIname\fR up to but not including the +last +.QW . +character in the last component of name. If the last +component of \fIname\fR does not contain a dot, then returns \fIname\fR. +.TP +\fBfile separator\fR ?\fIname\fR? +. +If no argument is given, returns the character which is used to separate +path segments for native files on this platform. If a path is given, +the filesystem responsible for that path is asked to return its +separator character. If no file system accepts \fIname\fR, an error +is generated. +.TP +\fBfile size \fIname\fR +. +Returns a decimal string giving the size of file \fIname\fR in bytes. If +the file does not exist or its size cannot be queried then an error is +generated. +.TP +\fBfile split \fIname\fR +. +Returns a list whose elements are the path components in \fIname\fR. The +first element of the list will have the same path type as \fIname\fR. +All other elements will be relative. Path separators will be discarded +unless they are needed to ensure that an element is unambiguously relative. +For example, under Unix +.RS +.PP +.CS +\fBfile split\fR /foo/~bar/baz +.CE +.PP +returns +.QW \fB/\0\0foo\0\0./~bar\0\0baz\fR +to ensure that later commands +that use the third component do not attempt to perform tilde +substitution. +.RE +.TP +\fBfile stat \fIname varName\fR +. +Invokes the \fBstat\fR kernel call on \fIname\fR, and uses the variable +given by \fIvarName\fR to hold information returned from the kernel call. +\fIVarName\fR is treated as an array variable, and the following elements +of that variable are set: \fBatime\fR, \fBctime\fR, \fBdev\fR, \fBgid\fR, +\fBino\fR, \fBmode\fR, \fBmtime\fR, \fBnlink\fR, \fBsize\fR, \fBtype\fR, +\fBuid\fR. Each element except \fBtype\fR is a decimal string with the +value of the corresponding field from the \fBstat\fR return structure; +see the manual entry for \fBstat\fR for details on the meanings of the +values. The \fBtype\fR element gives the type of the file in the same +form returned by the command \fBfile type\fR. This command returns an +empty string. +.TP +\fBfile system \fIname\fR +. +Returns a list of one or two elements, the first of which is the name of +the filesystem to use for the file, and the second, if given, an +arbitrary string representing the filesystem-specific nature or type of +the location within that filesystem. If a filesystem only supports one +type of file, the second element may not be supplied. For example the +native files have a first element +.QW native , +and a second element which when given is a platform-specific type name +for the file's system (e.g. +.QW NTFS , +.QW FAT , +on Windows). A generic virtual file system might return +the list +.QW "vfs ftp" +to represent a file on a remote ftp site mounted as a +virtual filesystem through an extension called +.QW vfs . +If the file does not belong to any filesystem, an error is generated. +.TP +\fBfile tail \fIname\fR +. +Returns all of the characters in the last filesystem component of +\fIname\fR. Any trailing directory separator in \fIname\fR is ignored. +If \fIname\fR contains no separators then returns \fIname\fR. So, +\fBfile tail a/b\fR, \fBfile tail a/b/\fR and \fBfile tail b\fR all +return \fBb\fR. +.TP +\fBfile tempfile\fR ?\fInameVar\fR? ?\fItemplate\fR? +'\" TIP #210 +.VS 8.6 +Creates a temporary file and returns a read-write channel opened on that file. +If the \fInameVar\fR is given, it specifies a variable that the name of the +temporary file will be written into; if absent, Tcl will attempt to arrange +for the temporary file to be deleted once it is no longer required. If the +\fItemplate\fR is present, it specifies parts of the template of the filename +to use when creating it (such as the directory, base-name or extension) though +some platforms may ignore some or all of these parts and use a built-in +default instead. +.RS +.PP +Note that temporary files are \fIonly\fR ever created on the native +filesystem. As such, they can be relied upon to be used with operating-system +native APIs and external programs that require a filename. +.RE +.VE 8.6 +.TP +\fBfile type \fIname\fR +. +Returns a string giving the type of file \fIname\fR, which will be one of +\fBfile\fR, \fBdirectory\fR, \fBcharacterSpecial\fR, \fBblockSpecial\fR, +\fBfifo\fR, \fBlink\fR, or \fBsocket\fR. +.TP +\fBfile volumes\fR +. +Returns the absolute paths to the volumes mounted on the system, as a +proper Tcl list. Without any virtual filesystems mounted as root +volumes, on UNIX, the command will always return +.QW / , +since all filesystems are locally mounted. +On Windows, it will return a list of the available local drives +(e.g. +.QW "a:/ c:/" ). +If any virtual filesystem has mounted additional +volumes, they will be in the returned list. +.TP +\fBfile writable \fIname\fR +. +Returns \fB1\fR if file \fIname\fR is writable by the current user, +\fB0\fR otherwise. +.SH "PORTABILITY ISSUES" +.TP +\fBUnix\fR\0\0\0\0\0\0\0 +. +These commands always operate using the real user and group identifiers, +not the effective ones. +.TP +\fBWindows\fR\0\0\0\0 +. +The \fBfile owned\fR subcommand uses the user identifier (SID) of +the process token, not the thread token which may be impersonating +some other user. +.SH EXAMPLES +.PP +This procedure shows how to search for C files in a given directory +that have a correspondingly-named object file in the current +directory: +.PP +.CS +proc findMatchingCFiles {dir} { + set files {} + switch $::tcl_platform(platform) { + windows { + set ext .obj + } + unix { + set ext .o + } + } + foreach file [glob \-nocomplain \-directory $dir *.c] { + set objectFile [\fBfile tail\fR [\fBfile rootname\fR $file]]$ext + if {[\fBfile exists\fR $objectFile]} { + lappend files $file + } + } + return $files +} +.CE +.PP +Rename a file and leave a symbolic link pointing from the old location +to the new place: +.PP +.CS +set oldName foobar.txt +set newName foo/bar.txt +# Make sure that where we're going to move to exists... +if {![\fBfile isdirectory\fR [\fBfile dirname\fR $newName]]} { + \fBfile mkdir\fR [\fBfile dirname\fR $newName] +} +\fBfile rename\fR $oldName $newName +\fBfile link\fR \-symbolic $oldName $newName +.CE +.PP +On Windows, a file can be +.QW started +easily enough (equivalent to double-clicking on it in the Explorer +interface) but the name passed to the operating system must be in +native format: +.PP +.CS +exec {*}[auto_execok start] {} [\fBfile nativename\fR ~/example.txt] +.CE +.SH "SEE ALSO" +filename(n), open(n), close(n), eof(n), gets(n), tell(n), seek(n), +fblocked(n), flush(n) +.SH KEYWORDS +attributes, copy files, delete files, directory, file, move files, name, +rename files, stat, user +'\" Local Variables: +'\" mode: nroff +'\" fill-column: 78 +'\" End: diff --git a/tcl8.6/doc/fileevent.n b/tcl8.6/doc/fileevent.n new file mode 100644 index 0000000..2751040 --- /dev/null +++ b/tcl8.6/doc/fileevent.n @@ -0,0 +1,156 @@ +'\" +'\" Copyright (c) 1994 The Regents of the University of California. +'\" Copyright (c) 1994-1996 Sun Microsystems, Inc. +'\" Copyright (c) 2008 Pat Thoyts +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH fileevent n 7.5 Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +fileevent \- Execute a script when a channel becomes readable or writable +.SH SYNOPSIS +\fBfileevent \fIchannelId \fBreadable \fR?\fIscript\fR? +.sp +\fBfileevent \fIchannelId \fBwritable \fR?\fIscript\fR? +.BE + +.SH DESCRIPTION +.PP +This command is used to create \fIfile event handlers\fR. A file event +handler is a binding between a channel and a script, such that the script +is evaluated whenever the channel becomes readable or writable. File event +handlers are most commonly used to allow data to be received from another +process on an event-driven basis, so that the receiver can continue to +interact with the user while waiting for the data to arrive. If an +application invokes \fBgets\fR or \fBread\fR on a blocking channel when +there is no input data available, the process will block; until the input +data arrives, it will not be able to service other events, so it will +appear to the user to +.QW "freeze up" . +With \fBfileevent\fR, the process can +tell when data is present and only invoke \fBgets\fR or \fBread\fR when +they will not block. +.PP +The \fIchannelId\fR argument to \fBfileevent\fR refers to an open +channel such as a Tcl standard channel (\fBstdin\fR, \fBstdout\fR, +or \fBstderr\fR), the return value from an invocation of \fBopen\fR +or \fBsocket\fR, or the result of a channel creation command provided +by a Tcl extension. +.PP +If the \fIscript\fR argument is specified, then \fBfileevent\fR +creates a new event handler: \fIscript\fR will be evaluated +whenever the channel becomes readable or writable (depending on the +second argument to \fBfileevent\fR). +In this case \fBfileevent\fR returns an empty string. +The \fBreadable\fR and \fBwritable\fR event handlers for a file +are independent, and may be created and deleted separately. +However, there may be at most one \fBreadable\fR and one \fBwritable\fR +handler for a file at a given time in a given interpreter. +If \fBfileevent\fR is called when the specified handler already +exists in the invoking interpreter, the new script replaces the old one. +.PP +If the \fIscript\fR argument is not specified, \fBfileevent\fR +returns the current script for \fIchannelId\fR, or an empty string +if there is none. +If the \fIscript\fR argument is specified as an empty string +then the event handler is deleted, so that no script will be invoked. +A file event handler is also deleted automatically whenever +its channel is closed or its interpreter is deleted. +.PP +A channel is considered to be readable if there is unread data +available on the underlying device. +A channel is also considered to be readable if there is unread +data in an input buffer, except in the special case where the +most recent attempt to read from the channel was a \fBgets\fR +call that could not find a complete line in the input buffer. +This feature allows a file to be read a line at a time in nonblocking mode +using events. +A channel is also considered to be readable if an end of file or +error condition is present on the underlying file or device. +It is important for \fIscript\fR to check for these conditions +and handle them appropriately; for example, if there is no special +check for end of file, an infinite loop may occur where \fIscript\fR +reads no data, returns, and is immediately invoked again. +.PP +A channel is considered to be writable if at least one byte of data +can be written to the underlying file or device without blocking, +or if an error condition is present on the underlying file or device. +.PP +Event-driven I/O works best for channels that have been placed into +nonblocking mode with the \fBfconfigure\fR command. In blocking mode, +a \fBputs\fR command may block if you give it more data than the +underlying file or device can accept, and a \fBgets\fR or \fBread\fR +command will block if you attempt to read more data than is ready; a +readable underlying file or device may not even guarantee that a +blocking [read 1] will succeed (counter-examples being multi-byte +encodings, compression or encryption transforms ). In all such cases, +no events will be processed while the commands block. +.PP +In nonblocking mode \fBputs\fR, \fBread\fR, and \fBgets\fR never block. +See the documentation for the individual commands for information +on how they handle blocking and nonblocking channels. +.PP +Testing for the end of file condition should be done after any attempts +read the channel data. The eof flag is set once an attempt to read the +end of data has occurred and testing before this read will require an +additional event to be fired. +.PP +The script for a file event is executed at global level (outside the +context of any Tcl procedure) in the interpreter in which the +\fBfileevent\fR command was invoked. +If an error occurs while executing the script then the +command registered with \fBinterp bgerror\fR is used to report the error. +In addition, the file event handler is deleted if it ever returns +an error; this is done in order to prevent infinite loops due to +buggy handlers. +.SH EXAMPLE +.PP +In this setup \fBGetData\fR will be called with the channel as an +argument whenever $chan becomes readable. The \fBread\fR call will +read whatever binary data is currently available without blocking. +Here the channel has the fileevent removed when an end of file +occurs to avoid being continually called (see above). Alternatively +the channel may be closed on this condition. +.PP +.CS +proc GetData {chan} { + set data [read $chan] + puts "[string length $data] $data" + if {[eof $chan]} { + fileevent $chan readable {} + } +} + +fconfigure $chan -blocking 0 -encoding binary +\fBfileevent\fR $chan readable [list GetData $chan] +.CE +.PP +The next example demonstrates use of \fBgets\fR to read line-oriented +data. +.PP +.CS +proc GetData {chan} { + if {[gets $chan line] >= 0} { + puts $line + } + if {[eof $chan]} { + close $chan + } +} + +fconfigure $chan -blocking 0 -buffering line -translation crlf +\fBfileevent\fR $chan readable [list GetData $chan] +.CE +.SH CREDITS +.PP +\fBfileevent\fR is based on the \fBaddinput\fR command created +by Mark Diekhans. +.SH "SEE ALSO" +fconfigure(n), gets(n), interp(n), puts(n), read(n), Tcl_StandardChannels(3) +.SH KEYWORDS +asynchronous I/O, blocking, channel, event handler, nonblocking, readable, +script, writable. diff --git a/tcl8.6/doc/filename.n b/tcl8.6/doc/filename.n new file mode 100644 index 0000000..87ba467 --- /dev/null +++ b/tcl8.6/doc/filename.n @@ -0,0 +1,178 @@ +'\" +'\" Copyright (c) 1995-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. +'\" +.TH filename n 7.5 Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +filename \- File name conventions supported by Tcl commands +.BE +.SH INTRODUCTION +.PP +All Tcl commands and C procedures that take file names as arguments +expect the file names to be in one of three forms, depending on the +current platform. On each platform, Tcl supports file names in the +standard forms(s) for that platform. In addition, on all platforms, +Tcl supports a Unix-like syntax intended to provide a convenient way +of constructing simple file names. However, scripts that are intended +to be portable should not assume a particular form for file names. +Instead, portable scripts must use the \fBfile split\fR and \fBfile +join\fR commands to manipulate file names (see the \fBfile\fR manual +entry for more details). +.SH "PATH TYPES" +.PP +File names are grouped into three general types based on the starting point +for the path used to specify the file: absolute, relative, and +volume-relative. Absolute names are completely qualified, giving a path to +the file relative to a particular volume and the root directory on that +volume. Relative names are unqualified, giving a path to the file relative +to the current working directory. Volume-relative names are partially +qualified, either giving the path relative to the root directory on the +current volume, or relative to the current directory of the specified +volume. The \fBfile pathtype\fR command can be used to determine the +type of a given path. +.SH "PATH SYNTAX" +.PP +The rules for native names depend on the value reported in the Tcl +\fBplatform\fR element of the \fBtcl_platform\fR array: +.TP 10 +\fBUnix\fR +On Unix and Apple MacOS X platforms, Tcl uses path names where the +components are separated by slashes. Path names may be relative or +absolute, and file names may contain any character other than slash. +The file names \fB\&.\fR and \fB\&..\fR are special and refer to the +current directory and the parent of the current directory respectively. +Multiple adjacent slash characters are interpreted as a single +separator. Any number of trailing slash characters at the end of a +path are simply ignored, so the paths \fBfoo\fR, \fBfoo/\fR and +\fBfoo//\fR are all identical, and in particular \fBfoo/\fR does not +necessarily mean a directory is being referred. +.RS +.PP +The following examples illustrate various forms of path +names: +.TP 15 +\fB/\fR +Absolute path to the root directory. +.TP 15 +\fB/etc/passwd\fR +Absolute path to the file named \fBpasswd\fR in the directory +\fBetc\fR in the root directory. +.TP 15 +\fB\&.\fR +Relative path to the current directory. +.TP 15 +\fBfoo\fR +Relative path to the file \fBfoo\fR in the current directory. +.TP 15 +\fBfoo/bar\fR +Relative path to the file \fBbar\fR in the directory \fBfoo\fR in the +current directory. +.TP 15 +\fB\&../foo\fR +Relative path to the file \fBfoo\fR in the directory above the current +directory. +.RE +.TP +\fBWindows\fR +On Microsoft Windows platforms, Tcl supports both drive-relative and UNC +style names. Both \fB/\fR and \fB\e\fR may be used as directory separators +in either type of name. Drive-relative names consist of an optional drive +specifier followed by an absolute or relative path. UNC paths follow the +general form \fB\e\eservername\esharename\epath\efile\fR, but must at +the very least contain the server and share components, i.e. +\fB\e\eservername\esharename\fR. In both forms, +the file names \fB.\fR and \fB..\fR are special and refer to the current +directory and the parent of the current directory respectively. The +following examples illustrate various forms of path names: +.RS +.TP 15 +\fB\&\e\eHost\eshare/file\fR +Absolute UNC path to a file called \fBfile\fR in the root directory of +the export point \fBshare\fR on the host \fBHost\fR. Note that +repeated use of \fBfile dirname\fR on this path will give +\fB//Host/share\fR, and will never give just \fB//Host\fR. +.TP 15 +\fBc:foo\fR +Volume-relative path to a file \fBfoo\fR in the current directory on drive +\fBc\fR. +.TP 15 +\fBc:/foo\fR +Absolute path to a file \fBfoo\fR in the root directory of drive +\fBc\fR. +.TP 15 +\fBfoo\ebar\fR +Relative path to a file \fBbar\fR in the \fBfoo\fR directory in the current +directory on the current volume. +.TP 15 +\fB\&\efoo\fR +Volume-relative path to a file \fBfoo\fR in the root directory of the current +volume. +.TP 15 +\fB\&\e\efoo\fR +Volume-relative path to a file \fBfoo\fR in the root directory of the current +volume. This is not a valid UNC path, so the assumption is that the +extra backslashes are superfluous. +.RE +.SH "TILDE SUBSTITUTION" +.PP +In addition to the file name rules described above, Tcl also supports +\fIcsh\fR-style tilde substitution. If a file name starts with a tilde, +then the file name will be interpreted as if the first element is +replaced with the location of the home directory for the given user. If +the tilde is followed immediately by a separator, then the \fB$HOME\fR +environment variable is substituted. Otherwise the characters between +the tilde and the next separator are taken as a user name, which is used +to retrieve the user's home directory for substitution. This works on +Unix, MacOS X and Windows (except very old releases). +.PP +Old Windows platforms do not support tilde substitution when a user name +follows the tilde. On these platforms, attempts to use a tilde followed +by a user name will generate an error that the user does not exist when +Tcl attempts to interpret that part of the path or otherwise access the +file. The behaviour of these paths when not trying to interpret them is +the same as on Unix. File names that have a tilde without a user name +will be correctly substituted using the \fB$HOME\fR environment +variable, just like for Unix. +.SH "PORTABILITY ISSUES" +.PP +Not all file systems are case sensitive, so scripts should avoid code +that depends on the case of characters in a file name. In addition, +the character sets allowed on different devices may differ, so scripts +should choose file names that do not contain special characters like: +\fB<>:?"/\e|\fR. +'\""\" reset emacs highlighting +The safest approach is to use names consisting of +alphanumeric characters only. Care should be taken with filenames +which contain spaces (common on Windows systems) and +filenames where the backslash is the directory separator (Windows +native path names). Also Windows 3.1 only supports file +names with a root of no more than 8 characters and an extension of no +more than 3 characters. +.PP +On Windows platforms there are file and path length restrictions. +Complete paths or filenames longer than about 260 characters will lead +to errors in most file operations. +.PP +Another Windows peculiarity is that any number of trailing dots +.QW . +in filenames are totally ignored, so, for example, attempts to create a +file or directory with a name +.QW foo. +will result in the creation of a file/directory with name +.QW foo . +This fact is reflected in the results of \fBfile normalize\fR. +Furthermore, a file name consisting only of dots +.QW ......... +or dots with trailing characters +.QW .....abc +is illegal. +.SH "SEE ALSO" +file(n), glob(n) +.SH KEYWORDS +current directory, absolute file name, relative file name, +volume-relative file name, portability diff --git a/tcl8.6/doc/flush.n b/tcl8.6/doc/flush.n new file mode 100644 index 0000000..d266d91 --- /dev/null +++ b/tcl8.6/doc/flush.n @@ -0,0 +1,45 @@ +'\" +'\" Copyright (c) 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. +'\" +.TH flush n 7.5 Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +flush \- Flush buffered output for a channel +.SH SYNOPSIS +\fBflush \fIchannelId\fR +.BE +.SH DESCRIPTION +.PP +Flushes any output that has been buffered for \fIchannelId\fR. +.PP +\fIChannelId\fR must be an identifier for an open channel such as a +Tcl standard channel (\fBstdout\fR or \fBstderr\fR), the return +value from an invocation of \fBopen\fR or \fBsocket\fR, or the result +of a channel creation command provided by a Tcl extension. The +channel must have been opened for writing. +.PP +If the channel is in blocking mode the command does not return until all the +buffered output has been flushed to the channel. If the channel is in +nonblocking mode, the command may return before all buffered output has been +flushed; the remainder will be flushed in the background as fast as the +underlying file or device is able to absorb it. +.SH EXAMPLE +.PP +Prompt for the user to type some information in on the console: +.PP +.CS +puts -nonewline "Please type your name: " +\fBflush\fR stdout +gets stdin name +puts "Hello there, $name!" +.CE +.SH "SEE ALSO" +file(n), open(n), socket(n), Tcl_StandardChannels(3) +.SH KEYWORDS +blocking, buffer, channel, flush, nonblocking, output diff --git a/tcl8.6/doc/for.n b/tcl8.6/doc/for.n new file mode 100644 index 0000000..9a3235f --- /dev/null +++ b/tcl8.6/doc/for.n @@ -0,0 +1,87 @@ +'\" +'\" Copyright (c) 1993 The Regents of the University of California. +'\" Copyright (c) 1994-1997 Sun Microsystems, Inc. +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH for n "" Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +for \- 'For' loop +.SH SYNOPSIS +\fBfor \fIstart test next body\fR +.BE + +.SH DESCRIPTION +.PP +\fBFor\fR is a looping command, similar in structure to the C +\fBfor\fR statement. The \fIstart\fR, \fInext\fR, and +\fIbody\fR arguments must be Tcl command strings, and \fItest\fR +is an expression string. +The \fBfor\fR command first invokes the Tcl interpreter to +execute \fIstart\fR. Then it repeatedly evaluates \fItest\fR as +an expression; if the result is non-zero it invokes the Tcl +interpreter on \fIbody\fR, then invokes the Tcl interpreter on \fInext\fR, +then repeats the loop. The command terminates when \fItest\fR evaluates +to 0. If a \fBcontinue\fR command is invoked within \fIbody\fR then +any remaining commands in the current execution of \fIbody\fR are skipped; +processing continues by invoking the Tcl interpreter on \fInext\fR, then +evaluating \fItest\fR, and so on. If a \fBbreak\fR command is invoked +within \fIbody\fR +or \fInext\fR, +then the \fBfor\fR command will +return immediately. +The operation of \fBbreak\fR and \fBcontinue\fR are similar to the +corresponding statements in C. +\fBFor\fR returns an empty string. +.PP +Note: \fItest\fR should almost always be enclosed in braces. If not, +variable substitutions will be made before the \fBfor\fR +command starts executing, which means that variable changes +made by the loop body will not be considered in the expression. +This is likely to result in an infinite loop. If \fItest\fR is +enclosed in braces, variable substitutions are delayed until the +expression is evaluated (before +each loop iteration), so changes in the variables will be visible. +See below for an example: +.SH EXAMPLES +.PP +Print a line for each of the integers from 0 to 9: +.PP +.CS +\fBfor\fR {set x 0} {$x<10} {incr x} { + puts "x is $x" +} +.CE +.PP +Either loop infinitely or not at all because the expression being +evaluated is actually the constant, or even generate an error! The +actual behaviour will depend on whether the variable \fIx\fR exists +before the \fBfor\fR command is run and whether its value is a value +that is less than or greater than/equal to ten, and this is because +the expression will be substituted before the \fBfor\fR command is +executed. +.PP +.CS +\fBfor\fR {set x 0} $x<10 {incr x} { + puts "x is $x" +} +.CE +.PP +Print out the powers of two from 1 to 1024: +.PP +.CS +\fBfor\fR {set x 1} {$x<=1024} {set x [expr {$x * 2}]} { + puts "x is $x" +} +.CE +.SH "SEE ALSO" +break(n), continue(n), foreach(n), while(n) +.SH KEYWORDS +boolean, for, iteration, loop +'\" Local Variables: +'\" mode: nroff +'\" End: diff --git a/tcl8.6/doc/foreach.n b/tcl8.6/doc/foreach.n new file mode 100644 index 0000000..89a11f6 --- /dev/null +++ b/tcl8.6/doc/foreach.n @@ -0,0 +1,104 @@ +'\" +'\" Copyright (c) 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. +'\" +.TH foreach n "" Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +foreach \- Iterate over all elements in one or more lists +.SH SYNOPSIS +\fBforeach \fIvarname list body\fR +.br +\fBforeach \fIvarlist1 list1\fR ?\fIvarlist2 list2 ...\fR? \fIbody\fR +.BE + +.SH DESCRIPTION +.PP +The \fBforeach\fR command implements a loop where the loop +variable(s) take on values from one or more lists. +In the simplest case there is one loop variable, \fIvarname\fR, +and one list, \fIlist\fR, that is a list of values to assign to \fIvarname\fR. +The \fIbody\fR argument is a Tcl script. +For each element of \fIlist\fR (in order +from first to last), \fBforeach\fR assigns the contents of the +element to \fIvarname\fR as if the \fBlindex\fR command had been used +to extract the element, then calls the Tcl interpreter to execute +\fIbody\fR. +.PP +In the general case there can be more than one value list +(e.g., \fIlist1\fR and \fIlist2\fR), +and each value list can be associated with a list of loop variables +(e.g., \fIvarlist1\fR and \fIvarlist2\fR). +During each iteration of the loop +the variables of each \fIvarlist\fR are assigned +consecutive values from the corresponding \fIlist\fR. +Values in each \fIlist\fR are used in order from first to last, +and each value is used exactly once. +The total number of loop iterations is large enough to use +up all the values from all the value lists. +If a value list does not contain enough +elements for each of its loop variables in each iteration, +empty values are used for the missing elements. +.PP +The \fBbreak\fR and \fBcontinue\fR statements may be +invoked inside \fIbody\fR, with the same effect as in the \fBfor\fR +command. \fBForeach\fR returns an empty string. +.SH EXAMPLES +.PP +This loop prints every value in a list together with the square and +cube of the value: +.PP +.CS +'\" Maintainers: notice the tab hacking below! +.ta 3i +set values {1 3 5 7 2 4 6 8} ;# Odd numbers first, for fun! +puts "Value\etSquare\etCube" ;# Neat-looking header +\fBforeach\fR x $values { ;# Now loop and print... + puts " $x\et [expr {$x**2}]\et [expr {$x**3}]" +} +.CE +.PP +The following loop uses i and j as loop variables to iterate over +pairs of elements of a single list. +.PP +.CS +set x {} +\fBforeach\fR {i j} {a b c d e f} { + lappend x $j $i +} +# The value of x is "b a d c f e" +# There are 3 iterations of the loop. +.CE +.PP +The next loop uses i and j to iterate over two lists in parallel. +.PP +.CS +set x {} +\fBforeach\fR i {a b c} j {d e f g} { + lappend x $i $j +} +# The value of x is "a d b e c f {} g" +# There are 4 iterations of the loop. +.CE +.PP +The two forms are combined in the following example. +.PP +.CS +set x {} +\fBforeach\fR i {a b c} {j k} {d e f g} { + lappend x $i $j $k +} +# The value of x is "a d e b f g c {} {}" +# There are 3 iterations of the loop. +.CE + +.SH "SEE ALSO" +for(n), while(n), break(n), continue(n) + +.SH KEYWORDS +foreach, iteration, list, loop diff --git a/tcl8.6/doc/format.n b/tcl8.6/doc/format.n new file mode 100644 index 0000000..ba044f2 --- /dev/null +++ b/tcl8.6/doc/format.n @@ -0,0 +1,285 @@ +'\" +'\" Copyright (c) 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. +'\" +.TH format n 8.1 Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +format \- Format a string in the style of sprintf +.SH SYNOPSIS +\fBformat \fIformatString \fR?\fIarg arg ...\fR? +.BE + +.SH INTRODUCTION +.PP +This command generates a formatted string in a fashion similar to the +ANSI C \fBsprintf\fR procedure. +\fIFormatString\fR indicates how to format the result, using +\fB%\fR conversion specifiers as in \fBsprintf\fR, and the additional +arguments, if any, provide values to be substituted into the result. +The return value from \fBformat\fR is the formatted string. +.SH "DETAILS ON FORMATTING" +.PP +The command operates by scanning \fIformatString\fR from left to right. +Each character from the format string is appended to the result +string unless it is a percent sign. +If the character is a \fB%\fR then it is not copied to the result string. +Instead, the characters following the \fB%\fR character are treated as +a conversion specifier. +The conversion specifier controls the conversion of the next successive +\fIarg\fR to a particular format and the result is appended to +the result string in place of the conversion specifier. +If there are multiple conversion specifiers in the format string, +then each one controls the conversion of one additional \fIarg\fR. +The \fBformat\fR command must be given enough \fIarg\fRs to meet the needs +of all of the conversion specifiers in \fIformatString\fR. +.PP +Each conversion specifier may contain up to six different parts: +an XPG3 position specifier, +a set of flags, a minimum field width, a precision, a size modifier, +and a conversion character. +Any of these fields may be omitted except for the conversion character. +The fields that are present must appear in the order given above. +The paragraphs below discuss each of these fields in turn. +.SS "OPTIONAL POSITIONAL SPECIFIER" +.PP +If the \fB%\fR is followed by a decimal number and a \fB$\fR, as in +.QW \fB%2$d\fR , +then the value to convert is not taken from the next sequential argument. +Instead, it is taken from the argument indicated by the number, +where 1 corresponds to the first \fIarg\fR. +If the conversion specifier requires multiple arguments because +of \fB*\fR characters in the specifier then +successive arguments are used, starting with the argument +given by the number. +This follows the XPG3 conventions for positional specifiers. +If there are any positional specifiers in \fIformatString\fR +then all of the specifiers must be positional. +.SS "OPTIONAL FLAGS" +.PP +The second portion of a conversion specifier may contain any of the +following flag characters, in any order: +.TP 10 +\fB\-\fR +Specifies that the converted argument should be left-justified +in its field (numbers are normally right-justified with leading +spaces if needed). +.TP 10 +\fB+\fR +Specifies that a number should always be printed with a sign, +even if positive. +.TP 10 +\fIspace\fR +Specifies that a space should be added to the beginning of the +number if the first character is not a sign. +.TP 10 +\fB0\fR +Specifies that the number should be padded on the left with +zeroes instead of spaces. +.TP 10 +\fB#\fR +Requests an alternate output form. For \fBo\fR and \fBO\fR +conversions it guarantees that the first digit is always \fB0\fR. +For \fBx\fR or \fBX\fR conversions, \fB0x\fR or \fB0X\fR (respectively) +will be added to the beginning of the result unless it is zero. +For \fBb\fR conversions, \fB0b\fR +will be added to the beginning of the result unless it is zero. +For all floating-point conversions (\fBe\fR, \fBE\fR, \fBf\fR, +\fBg\fR, and \fBG\fR) it guarantees that the result always +has a decimal point. +For \fBg\fR and \fBG\fR conversions it specifies that +trailing zeroes should not be removed. +.SS "OPTIONAL FIELD WIDTH" +.PP +The third portion of a conversion specifier is a decimal number giving a +minimum field width for this conversion. +It is typically used to make columns line up in tabular printouts. +If the converted argument contains fewer characters than the +minimum field width then it will be padded so that it is as wide +as the minimum field width. +Padding normally occurs by adding extra spaces on the left of the +converted argument, but the \fB0\fR and \fB\-\fR flags +may be used to specify padding with zeroes on the left or with +spaces on the right, respectively. +If the minimum field width is specified as \fB*\fR rather than +a number, then the next argument to the \fBformat\fR command +determines the minimum field width; it must be an integer value. +.SS "OPTIONAL PRECISION/BOUND" +.PP +The fourth portion of a conversion specifier is a precision, +which consists of a period followed by a number. +The number is used in different ways for different conversions. +For \fBe\fR, \fBE\fR, and \fBf\fR conversions it specifies the number +of digits to appear to the right of the decimal point. +For \fBg\fR and \fBG\fR conversions it specifies the total number +of digits to appear, including those on both sides of the decimal +point (however, trailing zeroes after the decimal point will still +be omitted unless the \fB#\fR flag has been specified). +For integer conversions, it specifies a minimum number of digits +to print (leading zeroes will be added if necessary). +For \fBs\fR conversions it specifies the maximum number of characters to be +printed; if the string is longer than this then the trailing characters will be dropped. +If the precision is specified with \fB*\fR rather than a number +then the next argument to the \fBformat\fR command determines the precision; +it must be a numeric string. +.SS "OPTIONAL SIZE MODIFIER" +.PP +The fifth part of a conversion specifier is a size modifier, +which must be \fBll\fR, \fBh\fR, or \fBl\fR. +If it is \fBll\fR it specifies that an integer value is taken +without truncation for conversion to a formatted substring. +If it is \fBh\fR it specifies that an integer value is +truncated to a 16-bit range before converting. This option is rarely useful. +If it is \fBl\fR it specifies that the integer value is +truncated to the same range as that produced by the \fBwide()\fR +function of the \fBexpr\fR command (at least a 64-bit range). +If neither \fBh\fR nor \fBl\fR are present, the integer value is +truncated to the same range as that produced by the \fBint()\fR +function of the \fBexpr\fR command (at least a 32-bit range, but +determined by the value of the \fBwordSize\fR element of the +\fBtcl_platform\fR array). +.SS "MANDATORY CONVERSION TYPE" +.PP +The last thing in a conversion specifier is an alphabetic character +that determines what kind of conversion to perform. +The following conversion characters are currently supported: +.TP 10 +\fBd\fR +Convert integer to signed decimal string. +.TP 10 +\fBu\fR +Convert integer to unsigned decimal string. +.TP 10 +\fBi\fR +Convert integer to signed decimal string (equivalent to \fBd\fR). +.TP 10 +\fBo\fR +Convert integer to unsigned octal string. +.TP 10 +\fBx\fR or \fBX\fR +Convert integer to unsigned hexadecimal string, using digits +.QW 0123456789abcdef +for \fBx\fR and +.QW 0123456789ABCDEF +for \fBX\fR). +.TP 10 +\fBb\fR +Convert integer to binary string, using digits 0 and 1. +.TP 10 +\fBc\fR +Convert integer to the Unicode character it represents. +.TP 10 +\fBs\fR +No conversion; just insert string. +.TP 10 +\fBf\fR +Convert number to signed decimal string of +the form \fIxx.yyy\fR, where the number of \fIy\fR's is determined by +the precision (default: 6). +If the precision is 0 then no decimal point is output. +.TP 10 +\fBe\fR or \fBE\fR +Convert number to scientific notation in the +form \fIx.yyy\fBe\(+-\fIzz\fR, where the number of \fIy\fR's is determined +by the precision (default: 6). +If the precision is 0 then no decimal point is output. +If the \fBE\fR form is used then \fBE\fR is +printed instead of \fBe\fR. +.TP 10 +\fBg\fR or \fBG\fR +If the exponent is less than \-4 or greater than or equal to the +precision, then convert number as for \fB%e\fR or +\fB%E\fR. +Otherwise convert as for \fB%f\fR. +Trailing zeroes and a trailing decimal point are omitted. +.TP 10 +\fB%\fR +No conversion: just insert \fB%\fR. +.SH "DIFFERENCES FROM ANSI SPRINTF" +.PP +The behavior of the format command is the same as the +ANSI C \fBsprintf\fR procedure except for the following +differences: +.IP [1] +Tcl guarantees that it will be working with UNICODE characters. +.IP [2] +\fB%p\fR and \fB%n\fR specifiers are not supported. +.IP [3] +For \fB%c\fR conversions the argument must be an integer value, +which will then be converted to the corresponding character value. +.IP [4] +The size modifiers are ignored when formatting floating-point values. +The \fBll\fR modifier has no \fBsprintf\fR counterpart. +The \fBb\fR specifier has no \fBsprintf\fR counterpart. +.SH EXAMPLES +.PP +Convert the numeric value of a UNICODE character to the character +itself: +.PP +.CS +set value 120 +set char [\fBformat\fR %c $value] +.CE +.PP +Convert the output of \fBtime\fR into seconds to an accuracy of +hundredths of a second: +.PP +.CS +set us [lindex [time $someTclCode] 0] +puts [\fBformat\fR "%.2f seconds to execute" [expr {$us / 1e6}]] +.CE +.PP +Create a packed X11 literal color specification: +.PP +.CS +# Each color-component should be in range (0..255) +set color [\fBformat\fR "#%02x%02x%02x" $r $g $b] +.CE +.PP +Use XPG3 format codes to allow reordering of fields (a technique that +is often used in localized message catalogs; see \fBmsgcat\fR) without +reordering the data values passed to \fBformat\fR: +.PP +.CS +set fmt1 "Today, %d shares in %s were bought at $%.2f each" +puts [\fBformat\fR $fmt1 123 "Global BigCorp" 19.37] + +set fmt2 "Bought %2\e$s equity ($%3$.2f x %1\e$d) today" +puts [\fBformat\fR $fmt2 123 "Global BigCorp" 19.37] +.CE +.PP +Print a small table of powers of three: +.PP +.CS +# Set up the column widths +set w1 5 +set w2 10 + +# Make a nice header (with separator) for the table first +set sep +-[string repeat - $w1]-+-[string repeat - $w2]-+ +puts $sep +puts [\fBformat\fR "| %-*s | %-*s |" $w1 "Index" $w2 "Power"] +puts $sep + +# Print the contents of the table +set p 1 +for {set i 0} {$i<=20} {incr i} { + puts [\fBformat\fR "| %*d | %*ld |" $w1 $i $w2 $p] + set p [expr {wide($p) * 3}] +} + +# Finish off by printing the separator again +puts $sep +.CE +.SH "SEE ALSO" +scan(n), sprintf(3), string(n) +.SH KEYWORDS +conversion specifier, format, sprintf, string, substitution +'\" Local Variables: +'\" mode: nroff +'\" End: diff --git a/tcl8.6/doc/gets.n b/tcl8.6/doc/gets.n new file mode 100644 index 0000000..0150f29 --- /dev/null +++ b/tcl8.6/doc/gets.n @@ -0,0 +1,71 @@ +'\" +'\" Copyright (c) 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. +'\" +.TH gets n 7.5 Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +gets \- Read a line from a channel +.SH SYNOPSIS +\fBgets \fIchannelId\fR ?\fIvarName\fR? +.BE + +.SH DESCRIPTION +.PP +This command reads the next line from \fIchannelId\fR, returns everything +in the line up to (but not including) the end-of-line character(s), and +discards the end-of-line character(s). +.PP +\fIChannelId\fR must be an identifier for an open channel such as the +Tcl standard input channel (\fBstdin\fR), the return value from an +invocation of \fBopen\fR or \fBsocket\fR, or the result of a channel +creation command provided by a Tcl extension. The channel must have +been opened for input. +.PP +If \fIvarName\fR is omitted the line is returned as the result of the +command. +If \fIvarName\fR is specified then the line is placed in the variable by +that name and the return value is a count of the number of characters +returned. +.PP +If end of file occurs while scanning for an end of +line, the command returns whatever input is available up to the end of file. +If \fIchannelId\fR is in non-blocking mode and there is not a full +line of input available, the command returns an empty string and +does not consume any input. +If \fIvarName\fR is specified and an empty string is returned in +\fIvarName\fR because of end-of-file or because of insufficient +data in non-blocking mode, then the return count is -1. +Note that if \fIvarName\fR is not specified then the end-of-file +and no-full-line-available cases can +produce the same results as if there were an input line consisting +only of the end-of-line character(s). +The \fBeof\fR and \fBfblocked\fR commands can be used to distinguish +these three cases. +.SH "EXAMPLE" +This example reads a file one line at a time and prints it out with +the current line number attached to the start of each line. +.PP +.CS +set chan [open "some.file.txt"] +set lineNumber 0 +while {[\fBgets\fR $chan line] >= 0} { + puts "[incr lineNumber]: $line" +} +close $chan +.CE + +.SH "SEE ALSO" +file(n), eof(n), fblocked(n), Tcl_StandardChannels(3) + +.SH KEYWORDS +blocking, channel, end of file, end of line, line, non-blocking, read +'\" Local Variables: +'\" mode: nroff +'\" fill-column: 78 +'\" End: diff --git a/tcl8.6/doc/glob.n b/tcl8.6/doc/glob.n new file mode 100644 index 0000000..a2cbce2 --- /dev/null +++ b/tcl8.6/doc/glob.n @@ -0,0 +1,267 @@ +'\" +'\" Copyright (c) 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. +.TH glob n 8.3 Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +glob \- Return names of files that match patterns +.SH SYNOPSIS +\fBglob \fR?\fIswitches\fR? ?\fIpattern ...\fR? +.BE +.SH DESCRIPTION +.PP +This command performs file name +.QW globbing +in a fashion similar to +the csh shell or bash shell. +It returns a list of the files whose names match any +of the \fIpattern\fR arguments. No particular order is guaranteed +in the list, so if a sorted list is required the caller should use +\fBlsort\fR. +.SS OPTIONS +.PP +If the initial arguments to \fBglob\fR start with \fB\-\fR then +they are treated as switches. The following switches are +currently supported: +.TP +\fB\-directory\fR \fIdirectory\fR +. +Search for files which match the given patterns starting in the given +\fIdirectory\fR. This allows searching of directories whose name +contains glob-sensitive characters without the need to quote such +characters explicitly. This option may not be used in conjunction with +\fB\-path\fR, which is used to allow searching for complete file paths +whose names may contain glob-sensitive characters. +.TP +\fB\-join\fR +. +The remaining pattern arguments, after option processing, are treated +as a single pattern obtained by joining the arguments with directory +separators. +.TP +\fB\-nocomplain\fR +. +Allows an empty list to be returned without error; without this +switch an error is returned if the result list would be empty. +.TP +\fB\-path\fR \fIpathPrefix\fR +. +Search for files with the given \fIpathPrefix\fR where the rest of the name +matches the given patterns. This allows searching for files with names +similar to a given file (as opposed to a directory) even when the names +contain glob-sensitive +characters. This option may not be used in conjunction with +\fB\-directory\fR. For example, to find all files with the same root name +as $path, but differing extensions, you should use +.QW "\fBglob \-path [file rootname $path] .*\fR" +which will work even if \fB$path\fR contains +numerous glob-sensitive characters. +.TP +\fB\-tails\fR +. +Only return the part of each file found which follows the last directory +named in any \fB\-directory\fR or \fB\-path\fR path specification. +Thus +.QW "\fBglob \-tails \-directory $dir *\fR" +is equivalent to +.QW "\fBset pwd [pwd]; cd $dir; glob *; cd $pwd\fR" . +For \fB\-path\fR specifications, the returned names will include the last +path segment, so +.QW "\fBglob \-tails \-path [file rootname ~/foo.tex] .*\fR" +will return paths like \fBfoo.aux foo.bib foo.tex\fR etc. +.TP +\fB\-types\fR \fItypeList\fR +. +Only list files or directories which match \fItypeList\fR, where the items +in the list have two forms. The first form is like the \-type option of +the Unix find command: +\fIb\fR (block special file), +\fIc\fR (character special file), +\fId\fR (directory), +\fIf\fR (plain file), +\fIl\fR (symbolic link), +\fIp\fR (named pipe), +or \fIs\fR (socket), where multiple types may be specified in the list. +\fBGlob\fR will return all files which match at least one of the types given. +Note that symbolic links will be returned both if \fB\-types l\fR is given, +or if the target of a link matches the requested type. So, a link to +a directory will be returned if \fB\-types d\fR was specified. +.RS +.PP +The second form specifies types where all the types given must match. +These are \fIr\fR, \fIw\fR, \fIx\fR as file permissions, and +\fIreadonly\fR, \fIhidden\fR as special permission cases. On the +Macintosh, MacOS types and creators are also supported, where any item +which is four characters long is assumed to be a MacOS type +(e.g. \fBTEXT\fR). Items which are of the form \fI{macintosh type XXXX}\fR +or \fI{macintosh creator XXXX}\fR will match types or creators +respectively. Unrecognized types, or specifications of multiple MacOS +types/creators will signal an error. +.PP +The two forms may be mixed, so \fB\-types {d f r w}\fR will find all +regular files OR directories that have both read AND write permissions. +The following are equivalent: +.PP +.CS +\fBglob \-type d *\fR +\fBglob */\fR +.CE +.PP +except that the first case doesn't return the trailing +.QW / +and is more platform independent. +.RE +.TP +\fB\-\|\-\fR +. +Marks the end of switches. The argument following this one will +be treated as a \fIpattern\fR even if it starts with a \fB\-\fR. +.SS "GLOBBING PATTERNS" +.PP +The \fIpattern\fR arguments may contain any of the following +special characters, which are a superset of those supported by +\fBstring match\fR: +.TP 10 +\fB?\fR +. +Matches any single character. +.TP 10 +\fB*\fR +. +Matches any sequence of zero or more characters. +.TP 10 +\fB[\fIchars\fB]\fR +. +Matches any single character in \fIchars\fR. If \fIchars\fR +contains a sequence of the form \fIa\fB\-\fIb\fR then any +character between \fIa\fR and \fIb\fR (inclusive) will match. +.TP 10 +\fB\e\fIx\fR +. +Matches the character \fIx\fR. +.TP 10 +\fB{\fIa\fB,\fIb\fB,\fI...\fR} +. +Matches any of the sub-patterns \fIa\fR, \fIb\fR, etc. +.PP +On Unix, as with csh, a +.QW . \| +at the beginning of a file's name or just after a +.QW / +must be matched explicitly or with a {} construct, unless the +\fB\-types hidden\fR flag is given (since +.QW . \| +at the beginning of a file's name indicates that it is hidden). On +other platforms, files beginning with a +.QW . \| +are handled no differently to any others, except the special directories +.QW . \| +and +.QW .. \| +which must be matched explicitly (this is to avoid a recursive pattern like +.QW "glob \-join * * * *" +from recursing up the directory hierarchy as well as down). In addition, all +.QW / +characters must be matched explicitly. +.LP +If the first character in a \fIpattern\fR is +.QW ~ +then it refers to the home directory for the user whose name follows the +.QW ~ . +If the +.QW ~ +is followed immediately by +.QW / +then the value of the HOME environment variable is used. +.PP +The \fBglob\fR command differs from csh globbing in two ways. +First, it does not sort its result list (use the \fBlsort\fR +command if you want the list sorted). +Second, \fBglob\fR only returns the names of files that actually +exist; in csh no check for existence is made unless a pattern +contains a ?, *, or [] construct. +.LP +When the \fBglob\fR command returns relative paths whose filenames +start with a tilde +.QW ~ +(for example through \fBglob *\fR or \fBglob \-tails\fR, the returned +list will not quote the tilde with +.QW ./ . +This means care must be taken if those names are later to +be used with \fBfile join\fR, to avoid them being interpreted as +absolute paths pointing to a given user's home directory. +.SH "WINDOWS PORTABILITY ISSUES" +.PP +For Windows UNC names, the servername and sharename components of the path +may not contain ?, *, or [] constructs. On Windows NT, if \fIpattern\fR is +of the form +.QW \fB~\fIusername\fB@\fIdomain\fR , +it refers to the home +directory of the user whose account information resides on the specified NT +domain server. Otherwise, user account information is obtained from +the local computer. +.PP +Since the backslash character has a special meaning to the glob +command, glob patterns containing Windows style path separators need +special care. The pattern +.QW \fIC:\e\efoo\e\e*\fR +is interpreted as +.QW \fIC:\efoo\e*\fR +where +.QW \fI\ef\fR +will match the single character +.QW \fIf\fR +and +.QW \fI\e*\fR +will match the single character +.QW \fI*\fR +and will not be +interpreted as a wildcard character. One solution to this problem is +to use the Unix style forward slash as a path separator. Windows style +paths can be converted to Unix style paths with the command +.QW "\fBfile join\fR \fB$path\fR" +or +.QW "\fBfile normalize\fR \fB$path\fR" . +.SH EXAMPLES +.PP +Find all the Tcl files in the current directory: +.PP +.CS +\fBglob\fR *.tcl +.CE +.PP +Find all the Tcl files in the user's home directory, irrespective of +what the current directory is: +.PP +.CS +\fBglob\fR \-directory ~ *.tcl +.CE +.PP +Find all subdirectories of the current directory: +.PP +.CS +\fBglob\fR \-type d * +.CE +.PP +Find all files whose name contains an +.QW a , +a +.QW b +or the sequence +.QW cde : +.PP +.CS +\fBglob\fR \-type f *{a,b,cde}* +.CE +.SH "SEE ALSO" +file(n) +.SH KEYWORDS +exist, file, glob, pattern +'\" Local Variables: +'\" mode: nroff +'\" End: diff --git a/tcl8.6/doc/global.n b/tcl8.6/doc/global.n new file mode 100644 index 0000000..9848817 --- /dev/null +++ b/tcl8.6/doc/global.n @@ -0,0 +1,58 @@ +'\" +'\" Copyright (c) 1993 The Regents of the University of California. +'\" Copyright (c) 1994-1997 Sun Microsystems, Inc. +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH global n "" Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +global \- Access global variables +.SH SYNOPSIS +\fBglobal \fR?\fIvarname ...\fR? +.BE +.SH DESCRIPTION +.PP +This command has no effect unless executed in the context of a proc body. +If the \fBglobal\fR command is executed in the context of a proc body, it +creates local variables linked to the corresponding global variables (though +these linked variables, like those created by \fBupvar\fR, are not included +in the list returned by \fBinfo locals\fR). +.PP +If \fIvarname\fR contains namespace qualifiers, the local variable's name is +the unqualified name of the global variable, as determined by the +\fBnamespace tail\fR command. +.PP +\fIvarname\fR is always treated as the name of a variable, not an +array element. An error is returned if the name looks like an array element, +such as \fBa(b)\fR. +.SH EXAMPLES +.PP +This procedure sets the namespace variable \fI::a::x\fR +.PP +.CS +proc reset {} { + \fBglobal\fR a::x + set x 0 +} +.CE +.PP +This procedure accumulates the strings passed to it in a global +buffer, separated by newlines. It is useful for situations when you +want to build a message piece-by-piece (as if with \fBputs\fR) but +send that full message in a single piece (e.g. over a connection +opened with \fBsocket\fR or as part of a counted HTTP response). +.PP +.CS +proc accum {string} { + \fBglobal\fR accumulator + append accumulator $string \en +} +.CE +.SH "SEE ALSO" +namespace(n), upvar(n), variable(n) +.SH KEYWORDS +global, namespace, procedure, variable diff --git a/tcl8.6/doc/history.n b/tcl8.6/doc/history.n new file mode 100644 index 0000000..e1f9781 --- /dev/null +++ b/tcl8.6/doc/history.n @@ -0,0 +1,102 @@ +'\" +'\" Copyright (c) 1993 The Regents of the University of California. +'\" Copyright (c) 1994-1997 Sun Microsystems, Inc. +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH history n "" Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +history \- Manipulate the history list +.SH SYNOPSIS +\fBhistory \fR?\fIoption\fR? ?\fIarg arg ...\fR? +.BE +.SH DESCRIPTION +.PP +The \fBhistory\fR command performs one of several operations related to +recently-executed commands recorded in a history list. Each of +these recorded commands is referred to as an +.QW event . +When specifying an event to the \fBhistory\fR command, the following +forms may be used: +.IP [1] +A number: if positive, it refers to the event with +that number (all events are numbered starting at 1). If the number +is negative, it selects an event relative to the current event +(\fB\-1\fR refers to the previous event, \fB\-2\fR to the one before that, and +so on). Event \fB0\fR refers to the current event. +.IP [2] +A string: selects the most recent event that matches the string. +An event is considered to match the string either if the string is +the same as the first characters of the event, or if the string +matches the event in the sense of the \fBstring match\fR command. +.PP +The \fBhistory\fR command can take any of the following forms: +.TP +\fBhistory\fR +Same +as \fBhistory info\fR, described below. +.TP +\fBhistory add\fI command \fR?\fBexec\fR? +Adds the \fIcommand\fR argument to the history list as a new event. If +\fBexec\fR is specified (or abbreviated) then the command is also +executed and its result is returned. If \fBexec\fR is not specified +then an empty string is returned as result. +.TP +\fBhistory change\fI newValue\fR ?\fIevent\fR? +Replaces the value recorded for an event with \fInewValue\fR. \fIEvent\fR +specifies the event to replace, and +defaults to the \fIcurrent\fR event (not event \fB\-1\fR). This command +is intended for use in commands that implement new forms of history +substitution and wish to replace the current event (which invokes the +substitution) with the command created through substitution. The return +value is an empty string. +.TP +\fBhistory clear\fR +Erase the history list. The current keep limit is retained. +The history event numbers are reset. +.TP +\fBhistory event\fR ?\fIevent\fR? +Returns the value of the event given by \fIevent\fR. \fIEvent\fR +defaults to \fB\-1\fR. +.TP +\fBhistory info \fR?\fIcount\fR? +Returns a formatted string (intended for humans to read) giving +the event number and contents for each of the events in the history +list except the current event. If \fIcount\fR is specified +then only the most recent \fIcount\fR events are returned. +.TP +\fBhistory keep \fR?\fIcount\fR? +This command may be used to change the size of the history list to +\fIcount\fR events. Initially, 20 events are retained in the history +list. If \fIcount\fR is not specified, the current keep limit is returned. +.TP +\fBhistory nextid\fR +Returns the number of the next event to be recorded +in the history list. It is useful for things like printing the +event number in command-line prompts. +.TP +\fBhistory redo \fR?\fIevent\fR? +Re-executes the command indicated by \fIevent\fR and returns its result. +\fIEvent\fR defaults to \fB\-1\fR. This command results in history +revision: see below for details. +.SH "HISTORY REVISION" +.PP +Pre-8.0 Tcl had a complex history revision mechanism. +The current mechanism is more limited, and the old +history operations \fBsubstitute\fR and \fBwords\fR have been removed. +(As a consolation, the \fBclear\fR operation was added.) +.PP +The history option \fBredo\fR results in much simpler +.QW "history revision" . +When this option is invoked then the most recent event +is modified to eliminate the history command and replace it with +the result of the history command. +If you want to redo an event without modifying history, then use +the \fBevent\fR operation to retrieve some event, +and the \fBadd\fR operation to add it to history and execute it. +.SH KEYWORDS +event, history, record diff --git a/tcl8.6/doc/http.n b/tcl8.6/doc/http.n new file mode 100644 index 0000000..40ced23 --- /dev/null +++ b/tcl8.6/doc/http.n @@ -0,0 +1,650 @@ +'\" +'\" Copyright (c) 1995-1997 Sun Microsystems, Inc. +'\" Copyright (c) 1998-2000 by Ajuba Solutions. +'\" Copyright (c) 2004 ActiveState Corporation. +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH "http" n 2.7 http "Tcl Bundled Packages" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +http \- Client-side implementation of the HTTP/1.1 protocol +.SH SYNOPSIS +\fBpackage require http ?2.7?\fR +.\" See Also -useragent option documentation in body! +.sp +\fB::http::config ?\fI\-option value\fR ...? +.sp +\fB::http::geturl \fIurl\fR ?\fI\-option value\fR ...? +.sp +\fB::http::formatQuery\fR \fIkey value\fR ?\fIkey value\fR ...? +.sp +\fB::http::reset\fR \fItoken\fR ?\fIwhy\fR? +.sp +\fB::http::wait \fItoken\fR +.sp +\fB::http::status \fItoken\fR +.sp +\fB::http::size \fItoken\fR +.sp +\fB::http::code \fItoken\fR +.sp +\fB::http::ncode \fItoken\fR +.sp +\fB::http::meta \fItoken\fR +.sp +\fB::http::data \fItoken\fR +.sp +\fB::http::error \fItoken\fR +.sp +\fB::http::cleanup \fItoken\fR +.sp +\fB::http::register \fIproto port command\fR +.sp +\fB::http::unregister \fIproto\fR +.BE +.SH DESCRIPTION +.PP +The \fBhttp\fR package provides the client side of the HTTP/1.1 +protocol, as defined in RFC 2616. +The package implements the GET, POST, and HEAD operations +of HTTP/1.1. It allows configuration of a proxy host to get through +firewalls. The package is compatible with the \fBSafesock\fR security +policy, so it can be used by untrusted applets to do URL fetching from +a restricted set of hosts. This package can be extended to support +additional HTTP transport protocols, such as HTTPS, by providing +a custom \fBsocket\fR command, via \fB::http::register\fR. +.PP +The \fB::http::geturl\fR procedure does a HTTP transaction. +Its \fIoptions \fR determine whether a GET, POST, or HEAD transaction +is performed. +The return value of \fB::http::geturl\fR is a token for the transaction. +The value is also the name of an array in the ::http namespace +that contains state information about the transaction. The elements +of this array are described in the \fBSTATE ARRAY\fR section. +.PP +If the \fB\-command\fR option is specified, then +the HTTP operation is done in the background. +\fB::http::geturl\fR returns immediately after generating the +HTTP request and the callback is invoked +when the transaction completes. For this to work, the Tcl event loop +must be active. In Tk applications this is always true. For pure-Tcl +applications, the caller can use \fB::http::wait\fR after calling +\fB::http::geturl\fR to start the event loop. +.SH COMMANDS +.TP +\fB::http::config\fR ?\fIoptions\fR? +. +The \fB::http::config\fR command is used to set and query the name of the +proxy server and port, and the User-Agent name used in the HTTP +requests. If no options are specified, then the current configuration +is returned. If a single argument is specified, then it should be one +of the flags described below. In this case the current value of +that setting is returned. Otherwise, the options should be a set of +flags and values that define the configuration: +.RS +.TP +\fB\-accept\fR \fImimetypes\fR +. +The Accept header of the request. The default is */*, which means that +all types of documents are accepted. Otherwise you can supply a +comma-separated list of mime type patterns that you are +willing to receive. For example, +.QW "image/gif, image/jpeg, text/*" . +.TP +\fB\-proxyhost\fR \fIhostname\fR +. +The name of the proxy host, if any. If this value is the +empty string, the URL host is contacted directly. +.TP +\fB\-proxyport\fR \fInumber\fR +. +The proxy port number. +.TP +\fB\-proxyfilter\fR \fIcommand\fR +. +The command is a callback that is made during +\fB::http::geturl\fR +to determine if a proxy is required for a given host. One argument, a +host name, is added to \fIcommand\fR when it is invoked. If a proxy +is required, the callback should return a two-element list containing +the proxy server and proxy port. Otherwise the filter should return +an empty list. The default filter returns the values of the +\fB\-proxyhost\fR and \fB\-proxyport\fR settings if they are +non-empty. +.TP +\fB\-urlencoding\fR \fIencoding\fR +. +The \fIencoding\fR used for creating the x-url-encoded URLs with +\fB::http::formatQuery\fR. The default is \fButf-8\fR, as specified by RFC +2718. Prior to http 2.5 this was unspecified, and that behavior can be +returned by specifying the empty string (\fB{}\fR), although +\fIiso8859-1\fR is recommended to restore similar behavior but without the +\fB::http::formatQuery\fR throwing an error processing non-latin-1 +characters. +.TP +\fB\-useragent\fR \fIstring\fR +. +The value of the User-Agent header in the HTTP request. The default is +.QW "\fBTcl http client package 2.7\fR" . +.RE +.TP +\fB::http::geturl\fR \fIurl\fR ?\fIoptions\fR? +. +The \fB::http::geturl\fR command is the main procedure in the package. +The \fB\-query\fR option causes a POST operation and +the \fB\-validate\fR option causes a HEAD operation; +otherwise, a GET operation is performed. The \fB::http::geturl\fR command +returns a \fItoken\fR value that can be used to get +information about the transaction. See the \fBSTATE ARRAY\fR and +\fBERRORS\fR section for +details. The \fB::http::geturl\fR command blocks until the operation +completes, unless the \fB\-command\fR option specifies a callback +that is invoked when the HTTP transaction completes. +\fB::http::geturl\fR takes several options: +.RS +.TP +\fB\-binary\fR \fIboolean\fR +. +Specifies whether to force interpreting the URL data as binary. Normally +this is auto-detected (anything not beginning with a \fBtext\fR content +type or whose content encoding is \fBgzip\fR or \fBcompress\fR is +considered binary data). +.TP +\fB\-blocksize\fR \fIsize\fR +. +The block size used when reading the URL. +At most \fIsize\fR bytes are read at once. After each block, a call to the +\fB\-progress\fR callback is made (if that option is specified). +.TP +\fB\-channel\fR \fIname\fR +. +Copy the URL contents to channel \fIname\fR instead of saving it in +\fBstate(body)\fR. +.TP +\fB\-command\fR \fIcallback\fR +. +Invoke \fIcallback\fR after the HTTP transaction completes. +This option causes \fB::http::geturl\fR to return immediately. +The \fIcallback\fR gets an additional argument that is the \fItoken\fR returned +from \fB::http::geturl\fR. This token is the name of an array that is +described in the \fBSTATE ARRAY\fR section. Here is a template for the +callback: +.RS +.PP +.CS +proc httpCallback {token} { + upvar #0 $token state + # Access state as a Tcl array +} +.CE +.RE +.TP +\fB\-handler\fR \fIcallback\fR +. +Invoke \fIcallback\fR whenever HTTP data is available; if present, nothing +else will be done with the HTTP data. This procedure gets two additional +arguments: the socket for the HTTP data and the \fItoken\fR returned from +\fB::http::geturl\fR. The token is the name of a global array that is +described in the \fBSTATE ARRAY\fR section. The procedure is expected +to return the number of bytes read from the socket. Here is a +template for the callback: +.RS +.PP +.CS +proc httpHandlerCallback {socket token} { + upvar #0 $token state + # Access socket, and state as a Tcl array + # For example... + ... + set data [read $socket 1000] + set nbytes [string length $data] + ... + return $nbytes +} +.CE +.RE +.TP +\fB\-headers\fR \fIkeyvaluelist\fR +. +This option is used to add headers not already specified +by \fB::http::config\fR to the HTTP request. The +\fIkeyvaluelist\fR argument must be a list with an even number of +elements that alternate between keys and values. The keys become +header field names. Newlines are stripped from the values so the +header cannot be corrupted. For example, if \fIkeyvaluelist\fR is +\fBPragma no-cache\fR then the following header is included in the +HTTP request: +.RS +.PP +.CS +Pragma: no-cache +.CE +.RE +.TP +\fB\-keepalive\fR \fIboolean\fR +. +If true, attempt to keep the connection open for servicing +multiple requests. Default is 0. +.TP +\fB\-method\fR \fItype\fR +. +Force the HTTP request method to \fItype\fR. \fB::http::geturl\fR will +auto-select GET, POST or HEAD based on other options, but this option +enables choices like PUT and DELETE for webdav support. +.TP +\fB\-myaddr\fR \fIaddress\fR +. +Pass an specific local address to the underlying \fBsocket\fR call in case +multiple interfaces are available. +.TP +\fB\-progress\fR \fIcallback\fR +. +The \fIcallback\fR is made after each transfer of data from the URL. +The callback gets three additional arguments: the \fItoken\fR from +\fB::http::geturl\fR, the expected total size of the contents from the +\fBContent-Length\fR meta-data, and the current number of bytes +transferred so far. The expected total size may be unknown, in which +case zero is passed to the callback. Here is a template for the +progress callback: +.RS +.PP +.CS +proc httpProgress {token total current} { + upvar #0 $token state +} +.CE +.RE +.TP +\fB\-protocol\fR \fIversion\fR +. +Select the HTTP protocol version to use. This should be 1.0 or 1.1 (the +default). Should only be necessary for servers that do not understand or +otherwise complain about HTTP/1.1. +.TP +\fB\-query\fR \fIquery\fR +. +This flag causes \fB::http::geturl\fR to do a POST request that passes the +\fIquery\fR to the server. The \fIquery\fR must be an x-url-encoding +formatted query. The \fB::http::formatQuery\fR procedure can be used to +do the formatting. +.TP +\fB\-queryblocksize\fR \fIsize\fR +. +The block size used when posting query data to the URL. +At most +\fIsize\fR +bytes are written at once. After each block, a call to the +\fB\-queryprogress\fR +callback is made (if that option is specified). +.TP +\fB\-querychannel\fR \fIchannelID\fR +. +This flag causes \fB::http::geturl\fR to do a POST request that passes the +data contained in \fIchannelID\fR to the server. The data contained in +\fIchannelID\fR must be an x-url-encoding +formatted query unless the \fB\-type\fR option below is used. +If a Content-Length header is not specified via the \fB\-headers\fR options, +\fB::http::geturl\fR attempts to determine the size of the post data +in order to create that header. If it is +unable to determine the size, it returns an error. +.TP +\fB\-queryprogress\fR \fIcallback\fR +. +The \fIcallback\fR is made after each transfer of data to the URL +(i.e. POST) and acts exactly like the \fB\-progress\fR option (the +callback format is the same). +.TP +\fB\-strict\fR \fIboolean\fR +. +Whether to enforce RFC 3986 URL validation on the request. Default is 1. +.TP +\fB\-timeout\fR \fImilliseconds\fR +. +If \fImilliseconds\fR is non-zero, then \fB::http::geturl\fR sets up a timeout +to occur after the specified number of milliseconds. +A timeout results in a call to \fB::http::reset\fR and to +the \fB\-command\fR callback, if specified. +The return value of \fB::http::status\fR is \fBtimeout\fR +after a timeout has occurred. +.TP +\fB\-type\fR \fImime-type\fR +. +Use \fImime-type\fR as the \fBContent-Type\fR value, instead of the +default value (\fBapplication/x-www-form-urlencoded\fR) during a +POST operation. +.TP +\fB\-validate\fR \fIboolean\fR +. +If \fIboolean\fR is non-zero, then \fB::http::geturl\fR does an HTTP HEAD +request. This request returns meta information about the URL, but the +contents are not returned. The meta information is available in the +\fBstate(meta) \fR variable after the transaction. See the +\fBSTATE ARRAY\fR section for details. +.RE +.TP +\fB::http::formatQuery\fR \fIkey value\fR ?\fIkey value\fR ...? +. +This procedure does x-url-encoding of query data. It takes an even +number of arguments that are the keys and values of the query. It +encodes the keys and values, and generates one string that has the +proper & and = separators. The result is suitable for the +\fB\-query\fR value passed to \fB::http::geturl\fR. +.TP +\fB::http::reset\fR \fItoken\fR ?\fIwhy\fR? +. +This command resets the HTTP transaction identified by \fItoken\fR, if any. +This sets the \fBstate(status)\fR value to \fIwhy\fR, which defaults to +\fBreset\fR, and then calls the registered \fB\-command\fR callback. +.TP +\fB::http::wait\fR \fItoken\fR +. +This is a convenience procedure that blocks and waits for the +transaction to complete. This only works in trusted code because it +uses \fBvwait\fR. Also, it is not useful for the case where +\fB::http::geturl\fR is called \fIwithout\fR the \fB\-command\fR option +because in this case the \fB::http::geturl\fR call does not return +until the HTTP transaction is complete, and thus there is nothing to +wait for. +.TP +\fB::http::data\fR \fItoken\fR +. +This is a convenience procedure that returns the \fBbody\fR element +(i.e., the URL data) of the state array. +.TP +\fB::http::error\fR \fItoken\fR +. +This is a convenience procedure that returns the \fBerror\fR element +of the state array. +.TP +\fB::http::status\fR \fItoken\fR +. +This is a convenience procedure that returns the \fBstatus\fR element of +the state array. +.TP +\fB::http::code\fR \fItoken\fR +. +This is a convenience procedure that returns the \fBhttp\fR element of the +state array. +.TP +\fB::http::ncode\fR \fItoken\fR +. +This is a convenience procedure that returns just the numeric return +code (200, 404, etc.) from the \fBhttp\fR element of the state array. +.TP +\fB::http::size\fR \fItoken\fR +. +This is a convenience procedure that returns the \fBcurrentsize\fR +element of the state array, which represents the number of bytes +received from the URL in the \fB::http::geturl\fR call. +.TP +\fB::http::meta\fR \fItoken\fR +. +This is a convenience procedure that returns the \fBmeta\fR +element of the state array which contains the HTTP response +headers. See below for an explanation of this element. +.TP +\fB::http::cleanup\fR \fItoken\fR +. +This procedure cleans up the state associated with the connection +identified by \fItoken\fR. After this call, the procedures +like \fB::http::data\fR cannot be used to get information +about the operation. It is \fIstrongly\fR recommended that you call +this function after you are done with a given HTTP request. Not doing +so will result in memory not being freed, and if your app calls +\fB::http::geturl\fR enough times, the memory leak could cause a +performance hit...or worse. +.TP +\fB::http::register\fR \fIproto port command\fR +. +This procedure allows one to provide custom HTTP transport types +such as HTTPS, by registering a prefix, the default port, and the +command to execute to create the Tcl \fBchannel\fR. E.g.: +.RS +.PP +.CS +package require http +package require tls + +::http::register https 443 ::tls::socket + +set token [::http::geturl https://my.secure.site/] +.CE +.RE +.TP +\fB::http::unregister\fR \fIproto\fR +. +This procedure unregisters a protocol handler that was previously +registered via \fB::http::register\fR, returning a two-item list of +the default port and handler command that was previously installed +(via \fB::http::register\fR) if there was such a handler, and an error if +there was no such handler. +.SH ERRORS +The \fB::http::geturl\fR procedure will raise errors in the following cases: +invalid command line options, +an invalid URL, +a URL on a non-existent host, +or a URL at a bad port on an existing host. +These errors mean that it +cannot even start the network transaction. +It will also raise an error if it gets an I/O error while +writing out the HTTP request header. +For synchronous \fB::http::geturl\fR calls (where \fB\-command\fR is +not specified), it will raise an error if it gets an I/O error while +reading the HTTP reply headers or data. Because \fB::http::geturl\fR +does not return a token in these cases, it does all the required +cleanup and there is no issue of your app having to call +\fB::http::cleanup\fR. +.PP +For asynchronous \fB::http::geturl\fR calls, all of the above error +situations apply, except that if there is any error while reading the +HTTP reply headers or data, no exception is thrown. This is because +after writing the HTTP headers, \fB::http::geturl\fR returns, and the +rest of the HTTP transaction occurs in the background. The command +callback can check if any error occurred during the read by calling +\fB::http::status\fR to check the status and if its \fIerror\fR, +calling \fB::http::error\fR to get the error message. +.PP +Alternatively, if the main program flow reaches a point where it needs +to know the result of the asynchronous HTTP request, it can call +\fB::http::wait\fR and then check status and error, just as the +callback does. +.PP +In any case, you must still call +\fB::http::cleanup\fR to delete the state array when you are done. +.PP +There are other possible results of the HTTP transaction +determined by examining the status from \fB::http::status\fR. +These are described below. +.TP +\fBok\fR +. +If the HTTP transaction completes entirely, then status will be \fBok\fR. +However, you should still check the \fB::http::code\fR value to get +the HTTP status. The \fB::http::ncode\fR procedure provides just +the numeric error (e.g., 200, 404 or 500) while the \fB::http::code\fR +procedure returns a value like +.QW "HTTP 404 File not found" . +.TP +\fBeof\fR +. +If the server closes the socket without replying, then no error +is raised, but the status of the transaction will be \fBeof\fR. +.TP +\fBerror\fR +. +The error message will also be stored in the \fBerror\fR status +array element, accessible via \fB::http::error\fR. +.PP +Another error possibility is that \fB::http::geturl\fR is unable to +write all the post query data to the server before the server +responds and closes the socket. +The error message is saved in the \fBposterror\fR status array +element and then \fB::http::geturl\fR attempts to complete the +transaction. +If it can read the server's response +it will end up with an \fBok\fR status, otherwise it will have +an \fBeof\fR status. +.SH "STATE ARRAY" +The \fB::http::geturl\fR procedure returns a \fItoken\fR that can be used to +get to the state of the HTTP transaction in the form of a Tcl array. +Use this construct to create an easy-to-use array variable: +.PP +.CS +upvar #0 $token state +.CE +.PP +Once the data associated with the URL is no longer needed, the state +array should be unset to free up storage. +The \fB::http::cleanup\fR procedure is provided for that purpose. +The following elements of +the array are supported: +.RS +.TP +\fBbody\fR +. +The contents of the URL. This will be empty if the \fB\-channel\fR +option has been specified. This value is returned by the \fB::http::data\fR command. +.TP +\fBcharset\fR +. +The value of the charset attribute from the \fBContent-Type\fR meta-data +value. If none was specified, this defaults to the RFC standard +\fBiso8859-1\fR, or the value of \fB$::http::defaultCharset\fR. Incoming +text data will be automatically converted from this charset to utf-8. +.TP +\fBcoding\fR +. +A copy of the \fBContent-Encoding\fR meta-data value. +.TP +\fBcurrentsize\fR +. +The current number of bytes fetched from the URL. +This value is returned by the \fB::http::size\fR command. +.TP +\fBerror\fR +. +If defined, this is the error string seen when the HTTP transaction +was aborted. +.TP +\fBhttp\fR +. +The HTTP status reply from the server. This value +is returned by the \fB::http::code\fR command. The format of this value is: +.RS +.PP +.CS +\fIHTTP/1.1 code string\fR +.CE +.PP +The \fIcode\fR is a three-digit number defined in the HTTP standard. +A code of 200 is OK. Codes beginning with 4 or 5 indicate errors. +Codes beginning with 3 are redirection errors. In this case the +\fBLocation\fR meta-data specifies a new URL that contains the +requested information. +.RE +.TP +\fBmeta\fR +. +The HTTP protocol returns meta-data that describes the URL contents. +The \fBmeta\fR element of the state array is a list of the keys and +values of the meta-data. This is in a format useful for initializing +an array that just contains the meta-data: +.RS +.PP +.CS +array set meta $state(meta) +.CE +.PP +Some of the meta-data keys are listed below, but the HTTP standard defines +more, and servers are free to add their own. +.TP +\fBContent-Type\fR +. +The type of the URL contents. Examples include \fBtext/html\fR, +\fBimage/gif,\fR \fBapplication/postscript\fR and +\fBapplication/x-tcl\fR. +.TP +\fBContent-Length\fR +. +The advertised size of the contents. The actual size obtained by +\fB::http::geturl\fR is available as \fBstate(currentsize)\fR. +.TP +\fBLocation\fR +. +An alternate URL that contains the requested data. +.RE +.TP +\fBposterror\fR +. +The error, if any, that occurred while writing +the post query data to the server. +.TP +\fBstatus\fR +. +Either \fBok\fR, for successful completion, \fBreset\fR for +user-reset, \fBtimeout\fR if a timeout occurred before the transaction +could complete, or \fBerror\fR for an error condition. During the +transaction this value is the empty string. +.TP +\fBtotalsize\fR +. +A copy of the \fBContent-Length\fR meta-data value. +.TP +\fBtype\fR +. +A copy of the \fBContent-Type\fR meta-data value. +.TP +\fBurl\fR +. +The requested URL. +.RE +.SH EXAMPLE +.PP +This example creates a procedure to copy a URL to a file while printing a +progress meter, and prints the meta-data associated with the URL. +.PP +.CS +proc httpcopy { url file {chunk 4096} } { + set out [open $file w] + set token [\fB::http::geturl\fR $url -channel $out \e + -progress httpCopyProgress -blocksize $chunk] + close $out + + # This ends the line started by httpCopyProgress + puts stderr "" + + upvar #0 $token state + set max 0 + foreach {name value} $state(meta) { + if {[string length $name] > $max} { + set max [string length $name] + } + if {[regexp -nocase ^location$ $name]} { + # Handle URL redirects + puts stderr "Location:$value" + return [httpcopy [string trim $value] $file $chunk] + } + } + incr max + foreach {name value} $state(meta) { + puts [format "%-*s %s" $max $name: $value] + } + + return $token +} +proc httpCopyProgress {args} { + puts -nonewline stderr . + flush stderr +} +.CE +.SH "SEE ALSO" +safe(n), socket(n), safesock(n) +.SH KEYWORDS +internet, security policy, socket, www +'\" Local Variables: +'\" mode: nroff +'\" End: diff --git a/tcl8.6/doc/if.n b/tcl8.6/doc/if.n new file mode 100644 index 0000000..776f811 --- /dev/null +++ b/tcl8.6/doc/if.n @@ -0,0 +1,88 @@ +'\" +'\" Copyright (c) 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. +'\" +.TH if n "" Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +if \- Execute scripts conditionally +.SH SYNOPSIS +\fBif \fIexpr1 \fR?\fBthen\fR? \fIbody1 \fBelseif \fIexpr2 \fR?\fBthen\fR? \fIbody2\fR \fBelseif\fR ... ?\fBelse\fR? ?\fIbodyN\fR? +.BE + +.SH DESCRIPTION +.PP +The \fIif\fR command evaluates \fIexpr1\fR as an expression (in the +same way that \fBexpr\fR evaluates its argument). The value of the +expression must be a boolean +(a numeric value, where 0 is false and +anything is true, or a string value such as \fBtrue\fR or \fByes\fR +for true and \fBfalse\fR or \fBno\fR for false); +if it is true then \fIbody1\fR is executed by passing it to the +Tcl interpreter. +Otherwise \fIexpr2\fR is evaluated as an expression and if it is true +then \fBbody2\fR is executed, and so on. +If none of the expressions evaluates to true then \fIbodyN\fR is +executed. +The \fBthen\fR and \fBelse\fR arguments are optional +.QW "noise words" +to make the command easier to read. +There may be any number of \fBelseif\fR clauses, including zero. +\fIBodyN\fR may also be omitted as long as \fBelse\fR is omitted too. +The return value from the command is the result of the body script +that was executed, or an empty string +if none of the expressions was non-zero and there was no \fIbodyN\fR. +.SH EXAMPLES +.PP +A simple conditional: +.PP +.CS +\fBif\fR {$vbl == 1} { puts "vbl is one" } +.CE +.PP +With an \fBelse\fR-clause: +.PP +.CS +\fBif\fR {$vbl == 1} { + puts "vbl is one" +} \fBelse\fR { + puts "vbl is not one" +} +.CE +.PP +With an \fBelseif\fR-clause too: +.PP +.CS +\fBif\fR {$vbl == 1} { + puts "vbl is one" +} \fBelseif\fR {$vbl == 2} { + puts "vbl is two" +} \fBelse\fR { + puts "vbl is not one or two" +} +.CE +.PP +Remember, expressions can be multi-line, but in that case it can be a +good idea to use the optional \fBthen\fR keyword for clarity: +.PP +.CS +\fBif\fR { + $vbl == 1 + || $vbl == 2 + || $vbl == 3 +} \fBthen\fR { + puts "vbl is one, two or three" +} +.CE +.SH "SEE ALSO" +expr(n), for(n), foreach(n) +.SH KEYWORDS +boolean, conditional, else, false, if, true +'\" Local Variables: +'\" mode: nroff +'\" End: diff --git a/tcl8.6/doc/incr.n b/tcl8.6/doc/incr.n new file mode 100644 index 0000000..9052c5a --- /dev/null +++ b/tcl8.6/doc/incr.n @@ -0,0 +1,61 @@ +'\" +'\" Copyright (c) 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. +'\" +.TH incr n "" Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +incr \- Increment the value of a variable +.SH SYNOPSIS +\fBincr \fIvarName \fR?\fIincrement\fR? +.BE +.SH DESCRIPTION +.PP +Increments the value stored in the variable whose name is \fIvarName\fR. +The value of the variable must be an integer. +If \fIincrement\fR is supplied then its value (which must be an +integer) is added to the value of variable \fIvarName\fR; otherwise +1 is added to \fIvarName\fR. +The new value is stored as a decimal string in variable \fIvarName\fR +and also returned as result. +.PP +Starting with the Tcl 8.5 release, the variable \fIvarName\fR passed +to \fBincr\fR may be unset, and in that case, it will be set to +the value \fIincrement\fR or to the default increment value of \fB1\fR. +.SH EXAMPLES +.PP +Add one to the contents of the variable \fIx\fR: +.PP +.CS +\fBincr\fR x +.CE +.PP +Add 42 to the contents of the variable \fIx\fR: +.PP +.CS +\fBincr\fR x 42 +.CE +.PP +Add the contents of the variable \fIy\fR to the contents of the +variable \fIx\fR: +.PP +.CS +\fBincr\fR x $y +.CE +.PP +Add nothing at all to the variable \fIx\fR (often useful for checking +whether an argument to a procedure is actually integral and generating +an error if it is not): +.PP +.CS +\fBincr\fR x 0 +.CE +.SH "SEE ALSO" +expr(n), set(n) +.SH KEYWORDS +add, increment, variable, value diff --git a/tcl8.6/doc/info.n b/tcl8.6/doc/info.n new file mode 100644 index 0000000..1ad908d --- /dev/null +++ b/tcl8.6/doc/info.n @@ -0,0 +1,777 @@ +'\" +'\" Copyright (c) 1993 The Regents of the University of California. +'\" Copyright (c) 1994-1997 Sun Microsystems, Inc. +'\" Copyright (c) 1993-1997 Bell Labs Innovations for Lucent Technologies +'\" Copyright (c) 1998-2000 Ajuba Solutions +'\" Copyright (c) 2007-2012 Donal K. Fellows +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH info n 8.4 Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +info \- Return information about the state of the Tcl interpreter +.SH SYNOPSIS +\fBinfo \fIoption \fR?\fIarg arg ...\fR? +.BE +.SH DESCRIPTION +.PP +This command provides information about various internals of the Tcl +interpreter. +The legal \fIoption\fRs (which may be abbreviated) are: +.TP +\fBinfo args \fIprocname\fR +. +Returns a list containing the names of the arguments to procedure +\fIprocname\fR, in order. \fIProcname\fR must be the name of a +Tcl command procedure. +.TP +\fBinfo body \fIprocname\fR +. +Returns the body of procedure \fIprocname\fR. \fIProcname\fR must be +the name of a Tcl command procedure. +.TP +\fBinfo class\fI subcommand class\fR ?\fIarg ...\fR +.VS 8.6 +Returns information about the class, \fIclass\fR. The \fIsubcommand\fRs are +described in \fBCLASS INTROSPECTION\fR below. +.VE 8.6 +.TP +\fBinfo cmdcount\fR +. +Returns a count of the total number of commands that have been invoked +in this interpreter. +.TP +\fBinfo commands \fR?\fIpattern\fR? +. +If \fIpattern\fR is not specified, +returns a list of names of all the Tcl commands visible +(i.e. executable without using a qualified name) to the current namespace, +including both the built-in commands written in C and +the command procedures defined using the \fBproc\fR command. +If \fIpattern\fR is specified, +only those names matching \fIpattern\fR are returned. +Matching is determined using the same rules as for \fBstring match\fR. +\fIpattern\fR can be a qualified name like \fBFoo::print*\fR. +That is, it may specify a particular namespace +using a sequence of namespace names separated by double colons (\fB::\fR), +and may have pattern matching special characters +at the end to specify a set of commands in that namespace. +If \fIpattern\fR is a qualified name, +the resulting list of command names has each one qualified with the name +of the specified namespace, and only the commands defined in the named +namespace are returned. +.\" Technically, most of this hasn't changed; that's mostly just the +.\" way it always worked. Hardly anyone knew that though. +.TP +\fBinfo complete \fIcommand\fR +. +Returns 1 if \fIcommand\fR is a complete Tcl command in the sense of +having no unclosed quotes, braces, brackets or array element names. +If the command does not appear to be complete then 0 is returned. +This command is typically used in line-oriented input environments +to allow users to type in commands that span multiple lines; if the +command is not complete, the script can delay evaluating it until additional +lines have been typed to complete the command. +.TP +\fBinfo coroutine\fR +.VS 8.6 +Returns the name of the currently executing \fBcoroutine\fR, or the empty +string if either no coroutine is currently executing, or the current coroutine +has been deleted (but has not yet returned or yielded since deletion). +.VE 8.6 +.TP +\fBinfo default \fIprocname arg varname\fR +. +\fIProcname\fR must be the name of a Tcl command procedure and \fIarg\fR +must be the name of an argument to that procedure. If \fIarg\fR +does not have a default value then the command returns \fB0\fR. +Otherwise it returns \fB1\fR and places the default value of \fIarg\fR +into variable \fIvarname\fR. +.TP +\fBinfo errorstack \fR?\fIinterp\fR? +.VS 8.6 +Returns, in a form that is programmatically easy to parse, the function names +and arguments at each level from the call stack of the last error in the given +\fIinterp\fR, or in the current one if not specified. +.RS +.PP +This form is an even-sized list alternating tokens and parameters. Tokens are +currently either \fBCALL\fR, \fBUP\fR, or \fBINNER\fR, but other values may be +introduced in the future. \fBCALL\fR indicates a procedure call, and its +parameter is the corresponding \fBinfo level\fR \fB0\fR. \fBUP\fR indicates a +shift in variable frames generated by \fBuplevel\fR or similar, and applies to +the previous \fBCALL\fR item. Its parameter is the level offset. \fBINNER\fR +identifies the +.QW "inner context" , +which is the innermost atomic command or bytecode instruction that raised the +error, along with its arguments when available. While \fBCALL\fR and \fBUP\fR +allow to follow complex call paths, \fBINNER\fR homes in on the offending +operation in the innermost procedure call, even going to sub-expression +granularity. +.PP +This information is also present in the \fB\-errorstack\fR entry of the +options dictionary returned by 3-argument \fBcatch\fR; \fBinfo errorstack\fR +is a convenient way of retrieving it for uncaught errors at top-level in an +interactive \fBtclsh\fR. +.RE +.VE 8.6 +.TP +\fBinfo exists \fIvarName\fR +. +Returns \fB1\fR if the variable named \fIvarName\fR exists in the +current context (either as a global or local variable) and has been +defined by being given a value, returns \fB0\fR otherwise. +.TP +\fBinfo frame\fR ?\fInumber\fR? +. +This command provides access to all frames on the stack, even those +hidden from \fBinfo level\fR. If \fInumber\fR is not specified, this +command returns a number giving the frame level of the command. This +is 1 if the command is invoked at top-level. If \fInumber\fR is +specified, then the result is a dictionary containing the location +information for the command at the \fInumber\fRed level on the stack. +.RS +.PP +If \fInumber\fR is positive (> 0) then it selects a particular stack +level (1 refers to the outer-most active command, 2 to the command it +called, and so on, up to the current frame level which refers to +\fBinfo frame\fR itself); otherwise it gives a level relative to the +current command (0 refers to the current command, i.e., \fBinfo +frame\fR itself, -1 to its caller, and so on). +.PP +This is similar to how \fBinfo level\fR works, except that this +subcommand reports all frames, like \fBsource\fRd scripts, +\fBeval\fRs, \fBuplevel\fRs, etc. +.PP +Note that for nested commands, like +.QW "foo [bar [x]]" , +only +.QW x +will be seen by an \fBinfo frame\fR invoked within +.QW x . +This is the same as for \fBinfo level\fR and error stack traces. +.PP +The result dictionary may contain the keys listed below, with the +specified meanings for their values: +.TP +\fBtype\fR +. +This entry is always present and describes the nature of the location +for the command. The recognized values are \fBsource\fR, \fBproc\fR, +\fBeval\fR, and \fBprecompiled\fR. +.RS +.TP +\fBsource\fR\0\0\0\0\0\0\0\0 +. +means that the command is found in a script loaded by the \fBsource\fR +command. +.TP +\fBproc\fR\0\0\0\0\0\0\0\0 +. +means that the command is found in dynamically created procedure body. +.TP +\fBeval\fR\0\0\0\0\0\0\0\0 +. +means that the command is executed by \fBeval\fR or \fBuplevel\fR. +.TP +\fBprecompiled\fR\0\0\0\0\0\0\0\0 +. +means that the command is found in a pre-compiled script (loadable by +the package \fBtbcload\fR), and no further information will be +available. +.RE +.TP +\fBline\fR +. +This entry provides the number of the line the command is at inside of +the script it is a part of. This information is not present for type +\fBprecompiled\fR. For type \fBsource\fR this information is counted +relative to the beginning of the file, whereas for the last two types +the line is counted relative to the start of the script. +.TP +\fBfile\fR +. +This entry is present only for type \fBsource\fR. It provides the +normalized path of the file the command is in. +.TP +\fBcmd\fR +. +This entry provides the string representation of the command. This is +usually the unsubstituted form, however for commands which are a +canonically-constructed list (e.g., as produced by the \fBlist\fR command) +executed by \fBeval\fR it is the substituted form as they have no other +string representation. Care is taken that the canonicality property of +the latter is not spoiled. +.TP +\fBproc\fR +. +This entry is present only if the command is found in the body of a +regular Tcl procedure. It then provides the name of that procedure. +.TP +\fBlambda\fR +. +This entry is present only if the command is found in the body of an +anonymous Tcl procedure, i.e. a lambda. It then provides the entire +definition of the lambda in question. +.TP +\fBlevel\fR +. +This entry is present only if the queried frame has a corresponding +frame returned by \fBinfo level\fR. It provides the index of this +frame, relative to the current level (0 and negative numbers). +.PP +A thing of note is that for procedures statically defined in files the +locations of commands in their bodies will be reported with type +\fBsource\fR and absolute line numbers, and not as type +\fBproc\fR. The same is true for procedures nested in statically +defined procedures, and literal eval scripts in files or statically +defined procedures. +.PP +In contrast, procedure definitions and \fBeval\fR within a dynamically +\fBeval\fRuated environment count line numbers relative to the start of +their script, even if they would be able to count relative to the +start of the outer dynamic script. That type of number usually makes +more sense. +.PP +A different way of describing this behaviour is that file based +locations are tracked as deeply as possible, and where this is not +possible the lines are counted based on the smallest possible +\fBeval\fR or procedure body, as that scope is usually easier to find +than any dynamic outer scope. +.PP +The syntactic form \fB{*}\fR is handled like \fBeval\fR. I.e. if it +is given a literal list argument the system tracks the line number +within the list words as well, and otherwise all line numbers are +counted relative to the start of each word (smallest scope) +.RE +.TP +\fBinfo functions \fR?\fIpattern\fR? +. +If \fIpattern\fR is not specified, returns a list of all the math +functions currently defined. +If \fIpattern\fR is specified, only those functions whose name matches +\fIpattern\fR are returned. Matching is determined using the same +rules as for \fBstring match\fR. +.TP +\fBinfo globals \fR?\fIpattern\fR? +. +If \fIpattern\fR is not specified, returns a list of all the names +of currently-defined global variables. +Global variables are variables in the global namespace. +If \fIpattern\fR is specified, only those names matching \fIpattern\fR +are returned. Matching is determined using the same rules as for +\fBstring match\fR. +.TP +\fBinfo hostname\fR +. +Returns the name of the computer on which this invocation is being +executed. +Note that this name is not guaranteed to be the fully qualified domain +name of the host. Where machines have several different names (as is +common on systems with both TCP/IP (DNS) and NetBIOS-based networking +installed,) it is the name that is suitable for TCP/IP networking that +is returned. +.TP +\fBinfo level\fR ?\fInumber\fR? +. +If \fInumber\fR is not specified, this command returns a number +giving the stack level of the invoking procedure, or 0 if the +command is invoked at top-level. If \fInumber\fR is specified, +then the result is a list consisting of the name and arguments for the +procedure call at level \fInumber\fR on the stack. If \fInumber\fR +is positive then it selects a particular stack level (1 refers +to the top-most active procedure, 2 to the procedure it called, and +so on); otherwise it gives a level relative to the current level +(0 refers to the current procedure, -1 to its caller, and so on). +See the \fBuplevel\fR command for more information on what stack +levels mean. +.TP +\fBinfo library\fR +. +Returns the name of the library directory in which standard Tcl +scripts are stored. +This is actually the value of the \fBtcl_library\fR +variable and may be changed by setting \fBtcl_library\fR. +.TP +\fBinfo loaded \fR?\fIinterp\fR? +. +Returns a list describing all of the packages that have been loaded into +\fIinterp\fR with the \fBload\fR command. +Each list element is a sub-list with two elements consisting of the +name of the file from which the package was loaded and the name of +the package. +For statically-loaded packages the file name will be an empty string. +If \fIinterp\fR is omitted then information is returned for all packages +loaded in any interpreter in the process. +To get a list of just the packages in the current interpreter, specify +an empty string for the \fIinterp\fR argument. +.TP +\fBinfo locals \fR?\fIpattern\fR? +. +If \fIpattern\fR is not specified, returns a list of all the names +of currently-defined local variables, including arguments to the +current procedure, if any. +Variables defined with the \fBglobal\fR, \fBupvar\fR and +\fBvariable\fR commands will not be returned. +If \fIpattern\fR is specified, only those names matching \fIpattern\fR +are returned. Matching is determined using the same rules as for +\fBstring match\fR. +.TP +\fBinfo nameofexecutable\fR +. +Returns the full path name of the binary file from which the application +was invoked. If Tcl was unable to identify the file, then an empty +string is returned. +.TP +\fBinfo object\fI subcommand object\fR ?\fIarg ...\fR +.VS 8.6 +Returns information about the object, \fIobject\fR. The \fIsubcommand\fRs are +described in \fBOBJECT INTROSPECTION\fR below. +.VE 8.6 +.TP +\fBinfo patchlevel\fR +. +Returns the value of the global variable \fBtcl_patchLevel\fR, which holds +the exact version of the Tcl library by default. +.TP +\fBinfo procs \fR?\fIpattern\fR? +. +If \fIpattern\fR is not specified, returns a list of all the +names of Tcl command procedures in the current namespace. +If \fIpattern\fR is specified, +only those procedure names in the current namespace +matching \fIpattern\fR are returned. +Matching is determined using the same rules as for +\fBstring match\fR. +If \fIpattern\fR contains any namespace separators, they are used to +select a namespace relative to the current namespace (or relative to +the global namespace if \fIpattern\fR starts with \fB::\fR) to match +within; the matching pattern is taken to be the part after the last +namespace separator. +.TP +\fBinfo script\fR ?\fIfilename\fR? +. +If a Tcl script file is currently being evaluated (i.e. there is a +call to \fBTcl_EvalFile\fR active or there is an active invocation +of the \fBsource\fR command), then this command returns the name +of the innermost file being processed. If \fIfilename\fR is specified, +then the return value of this command will be modified for the +duration of the active invocation to return that name. This is +useful in virtual file system applications. +Otherwise the command returns an empty string. +.TP +\fBinfo sharedlibextension\fR +. +Returns the extension used on this platform for the names of files +containing shared libraries (for example, \fB.so\fR under Solaris). +If shared libraries are not supported on this platform then an empty +string is returned. +.TP +\fBinfo tclversion\fR +. +Returns the value of the global variable \fBtcl_version\fR, which holds the +major and minor version of the Tcl library by default. +.TP +\fBinfo vars\fR ?\fIpattern\fR? +. +If \fIpattern\fR is not specified, +returns a list of all the names of currently-visible variables. +This includes locals and currently-visible globals. +If \fIpattern\fR is specified, only those names matching \fIpattern\fR +are returned. Matching is determined using the same rules as for +\fBstring match\fR. +\fIpattern\fR can be a qualified name like \fBFoo::option*\fR. +That is, it may specify a particular namespace +using a sequence of namespace names separated by double colons (\fB::\fR), +and may have pattern matching special characters +at the end to specify a set of variables in that namespace. +If \fIpattern\fR is a qualified name, +the resulting list of variable names +has each matching namespace variable qualified with the name +of its namespace. +Note that a currently-visible variable may not yet +.QW exist +if it has not +been set (e.g. a variable declared but not set by \fBvariable\fR). +.SS "CLASS INTROSPECTION" +.VS 8.6 +.PP +The following \fIsubcommand\fR values are supported by \fBinfo class\fR: +.VE 8.6 +.TP +\fBinfo class call\fI class method\fR +.VS +Returns a description of the method implementations that are used to provide a +stereotypical instance of \fIclass\fR's implementation of \fImethod\fR +(stereotypical instances being objects instantiated by a class without having +any object-specific definitions added). This consists of a list of lists of +four elements, where each sublist consists of a word that describes the +general type of method implementation (being one of \fBmethod\fR for an +ordinary method, \fBfilter\fR for an applied filter, and \fBunknown\fR for a +method that is invoked as part of unknown method handling), a word giving the +name of the particular method invoked (which is always the same as +\fImethod\fR for the \fBmethod\fR type, and +.QW \fBunknown\fR +for the \fBunknown\fR type), a word giving the fully qualified name of the +class that defined the method, and a word describing the type of method +implementation (see \fBinfo class methodtype\fR). +.RS +.PP +Note that there is no inspection of whether the method implementations +actually use \fBnext\fR to transfer control along the call chain. +.RE +.VE 8.6 +.TP +\fBinfo class constructor\fI class\fR +.VS 8.6 +This subcommand returns a description of the definition of the constructor of +class \fIclass\fR. The definition is described as a two element list; the first +element is the list of arguments to the constructor in a form suitable for +passing to another call to \fBproc\fR or a method definition, and the second +element is the body of the constructor. If no constructor is present, this +returns the empty list. +.VE 8.6 +.TP +\fBinfo class definition\fI class method\fR +.VS 8.6 +This subcommand returns a description of the definition of the method named +\fImethod\fR of class \fIclass\fR. The definition is described as a two element +list; the first element is the list of arguments to the method in a form +suitable for passing to another call to \fBproc\fR or a method definition, and +the second element is the body of the method. +.VE 8.6 +.TP +\fBinfo class destructor\fI class\fR +.VS 8.6 +This subcommand returns the body of the destructor of class \fIclass\fR. If no +destructor is present, this returns the empty string. +.VE 8.6 +.TP +\fBinfo class filters\fI class\fR +.VS 8.6 +This subcommand returns the list of filter methods set on the class. +.VE 8.6 +.TP +\fBinfo class forward\fI class method\fR +.VS 8.6 +This subcommand returns the argument list for the method forwarding called +\fImethod\fR that is set on the class called \fIclass\fR. +.VE 8.6 +.TP +\fBinfo class instances\fI class\fR ?\fIpattern\fR? +.VS 8.6 +This subcommand returns a list of instances of class \fIclass\fR. If the +optional \fIpattern\fR argument is present, it constrains the list of returned +instances to those that match it according to the rules of \fBstring match\fR. +.VE 8.6 +.TP +\fBinfo class methods\fI class\fR ?\fIoptions...\fR? +.VS 8.6 +This subcommand returns a list of all public (i.e. exported) methods of the +class called \fIclass\fR. Any of the following \fIoption\fRs may be +specified, controlling exactly which method names are returned: +.RS +.VE 8.6 +.TP +\fB\-all\fR +.VS 8.6 +If the \fB\-all\fR flag is given, the list of methods will include those +methods defined not just by the class, but also by the class's superclasses +and mixins. +.VE 8.6 +.TP +\fB\-private\fR +.VS 8.6 +If the \fB\-private\fR flag is given, the list of methods will also include +the private (i.e. non-exported) methods of the class (and superclasses and +mixins, if \fB\-all\fR is also given). +.RE +.VE 8.6 +.TP +\fBinfo class methodtype\fI class method\fR +.VS 8.6 +This subcommand returns a description of the type of implementation used for +the method named \fImethod\fR of class \fIclass\fR. When the result is +\fBmethod\fR, further information can be discovered with \fBinfo class +definition\fR, and when the result is \fBforward\fR, further information can +be discovered with \fBinfo class forward\fR. +.VE 8.6 +.TP +\fBinfo class mixins\fI class\fR +.VS 8.6 +This subcommand returns a list of all classes that have been mixed into the +class named \fIclass\fR. +.VE 8.6 +.TP +\fBinfo class subclasses\fI class\fR ?\fIpattern\fR? +.VS 8.6 +This subcommand returns a list of direct subclasses of class \fIclass\fR. If +the optional \fIpattern\fR argument is present, it constrains the list of +returned classes to those that match it according to the rules of +\fBstring match\fR. +.VE 8.6 +.TP +\fBinfo class superclasses\fI class\fR +.VS 8.6 +This subcommand returns a list of direct superclasses of class \fIclass\fR in +inheritance precedence order. +.VE 8.6 +.TP +\fBinfo class variables\fI class\fR +.VS 8.6 +This subcommand returns a list of all variables that have been declared for +the class named \fIclass\fR (i.e. that are automatically present in the +class's methods, constructor and destructor). +.SS "OBJECT INTROSPECTION" +.PP +The following \fIsubcommand\fR values are supported by \fBinfo object\fR: +.VE 8.6 +.TP +\fBinfo object call\fI object method\fR +.VS 8.6 +Returns a description of the method implementations that are used to provide +\fIobject\fR's implementation of \fImethod\fR. This consists of a list of +lists of four elements, where each sublist consists of a word that describes +the general type of method implementation (being one of \fBmethod\fR for an +ordinary method, \fBfilter\fR for an applied filter, and \fBunknown\fR for a +method that is invoked as part of unknown method handling), a word giving the +name of the particular method invoked (which is always the same as +\fImethod\fR for the \fBmethod\fR type, and +.QW \fBunknown\fR +for the \fBunknown\fR type), a word giving what defined the method (the fully +qualified name of the class, or the literal string \fBobject\fR if the method +implementation is on an instance), and a word describing the type of method +implementation (see \fBinfo object methodtype\fR). +.RS +.PP +Note that there is no inspection of whether the method implementations +actually use \fBnext\fR to transfer control along the call chain. +.RE +.VE 8.6 +.TP +\fBinfo object class\fI object\fR ?\fIclassName\fR? +.VS 8.6 +If \fIclassName\fR is unspecified, this subcommand returns class of the +\fIobject\fR object. If \fIclassName\fR is present, this subcommand returns a +boolean value indicating whether the \fIobject\fR is of that class. +.VE 8.6 +.TP +\fBinfo object definition\fI object method\fR +.VS 8.6 +This subcommand returns a description of the definition of the method named +\fImethod\fR of object \fIobject\fR. The definition is described as a two +element list; the first element is the list of arguments to the method in a +form suitable for passing to another call to \fBproc\fR or a method definition, +and the second element is the body of the method. +.VE 8.6 +.TP +\fBinfo object filters\fI object\fR +.VS 8.6 +This subcommand returns the list of filter methods set on the object. +.VE 8.6 +.TP +\fBinfo object forward\fI object method\fR +.VS 8.6 +This subcommand returns the argument list for the method forwarding called +\fImethod\fR that is set on the object called \fIobject\fR. +.VE 8.6 +.TP +\fBinfo object isa\fI category object\fR ?\fIarg\fR? +.VS 8.6 +This subcommand tests whether an object belongs to a particular category, +returning a boolean value that indicates whether the \fIobject\fR argument +meets the criteria for the category. The supported categories are: +.VE 8.6 +.RS +.TP +\fBinfo object isa class\fI object\fR +.VS 8.6 +This returns whether \fIobject\fR is a class (i.e. an instance of +\fBoo::class\fR or one of its subclasses). +.VE 8.6 +.TP +\fBinfo object isa metaclass\fI object\fR +.VS 8.6 +This returns whether \fIobject\fR is a class that can manufacture classes +(i.e. is \fBoo::class\fR or a subclass of it). +.VE 8.6 +.TP +\fBinfo object isa mixin\fI object class\fR +.VS 8.6 +This returns whether \fIclass\fR is directly mixed into \fIobject\fR. +.VE 8.6 +.TP +\fBinfo object isa object\fI object\fR +.VS 8.6 +This returns whether \fIobject\fR really is an object. +.VE 8.6 +.TP +\fBinfo object isa typeof\fI object class\fR +.VS 8.6 +This returns whether \fIclass\fR is the type of \fIobject\fR (i.e. whether +\fIobject\fR is an instance of \fIclass\fR or one of its subclasses, whether +direct or indirect). +.RE +.VE 8.6 +.TP +\fBinfo object methods\fI object\fR ?\fIoption...\fR? +.VS 8.6 +This subcommand returns a list of all public (i.e. exported) methods of the +object called \fIobject\fR. Any of the following \fIoption\fRs may be +specified, controlling exactly which method names are returned: +.RS +.VE 8.6 +.TP +\fB\-all\fR +.VS 8.6 +If the \fB\-all\fR flag is given, the list of methods will include those +methods defined not just by the object, but also by the object's class and +mixins, plus the superclasses of those classes. +.VE 8.6 +.TP +\fB\-private\fR +.VS 8.6 +If the \fB\-private\fR flag is given, the list of methods will also include +the private (i.e. non-exported) methods of the object (and classes, if +\fB\-all\fR is also given). +.RE +.VE 8.6 +.TP +\fBinfo object methodtype\fI object method\fR +.VS 8.6 +This subcommand returns a description of the type of implementation used for +the method named \fImethod\fR of object \fIobject\fR. When the result is +\fBmethod\fR, further information can be discovered with \fBinfo object +definition\fR, and when the result is \fBforward\fR, further information can +be discovered with \fBinfo object forward\fR. +.VE 8.6 +.TP +\fBinfo object mixins\fI object\fR +.VS 8.6 +This subcommand returns a list of all classes that have been mixed into the +object named \fIobject\fR. +.VE 8.6 +.TP +\fBinfo object namespace\fI object\fR +.VS 8.6 +This subcommand returns the name of the internal namespace of the object named +\fIobject\fR. +.VE 8.6 +.TP +\fBinfo object variables\fI object\fR +.VS 8.6 +This subcommand returns a list of all variables that have been declared for +the object named \fIobject\fR (i.e. that are automatically present in the +object's methods). +.VE 8.6 +.TP +\fBinfo object vars\fI object\fR ?\fIpattern\fR? +.VS 8.6 +This subcommand returns a list of all variables in the private namespace of +the object named \fIobject\fR. If the optional \fIpattern\fR argument is +given, it is a filter (in the syntax of a \fBstring match\fR glob pattern) +that constrains the list of variables returned. Note that this is different +from the list returned by \fBinfo object variables\fR; that can include +variables that are currently unset, whereas this can include variables that +are not automatically included by any of \fIobject\fR's methods (or those of +its class, superclasses or mixins). +.VE 8.6 +.SH EXAMPLES +.PP +This command prints out a procedure suitable for saving in a Tcl +script: +.PP +.CS +proc printProc {procName} { + set result [list proc $procName] + set formals {} + foreach var [\fBinfo args\fR $procName] { + if {[\fBinfo default\fR $procName $var def]} { + lappend formals [list $var $def] + } else { + # Still need the list-quoting because variable + # names may properly contain spaces. + lappend formals [list $var] + } + } + puts [lappend result $formals [\fBinfo body\fR $procName]] +} +.CE +.SS "EXAMPLES WITH OBJECTS" +.VS 8.6 +.PP +Every object necessarily knows what its class is; this information is +trivially extractable through introspection: +.PP +.CS +oo::class create c +c create o +puts [\fBinfo object class\fR o] + \fI\(-> prints "::c"\fR +puts [\fBinfo object class\fR c] + \fI\(-> prints "::oo::class"\fR +.CE +.PP +The introspection capabilities can be used to discover what class implements a +method and get how it is defined. This procedure illustrates how: +.PP +.CS +proc getDef {obj method} { + foreach inf [\fBinfo object call\fR $obj $method] { + lassign $inf calltype name locus methodtype + # Assume no forwards or filters, and hence no $calltype + # or $methodtype checks... + if {$locus eq "object"} { + return [\fBinfo object definition\fR $obj $name] + } else { + return [\fBinfo class definition\fR $locus $name] + } + } + error "no definition for $method" +} +.CE +.PP +This is an alternate way of looking up the definition; it is implemented by +manually scanning the list of methods up the inheritance tree. This code +assumes that only single inheritance is in use, and that there is no complex +use of mixed-in classes (in such cases, using \fBinfo object call\fR as above +is the simplest way of doing this by far): +.PP +.CS +proc getDef {obj method} { + if {$method in [\fBinfo object methods\fR $obj]} { + # Assume no forwards + return [\fBinfo object definition\fR $obj $method] + } + set cls [\fBinfo object class\fR $obj] + while {$method ni [\fBinfo class methods\fR $cls]} { + # Assume the simple case + set cls [lindex [\fBinfo class superclass\fR $cls] 0] + if {$cls eq ""} { + error "no definition for $method" + } + } + # Assume no forwards + return [\fBinfo class definition\fR $cls $method] +} +.CE +.VE 8.6 +.SH "SEE ALSO" +.VS 8.6 +global(n), oo::class(n), oo::define(n), oo::object(n), proc(n), self(n), +.VE 8.6 +tcl_library(n), tcl_patchLevel(n), tcl_version(n) +.SH KEYWORDS +command, information, interpreter, introspection, level, namespace, +.VS 8.6 +object, +.VE 8.6 +procedure, variable +'\" Local Variables: +'\" mode: nroff +'\" fill-column: 78 +'\" End: diff --git a/tcl8.6/doc/interp.n b/tcl8.6/doc/interp.n new file mode 100644 index 0000000..92113a6 --- /dev/null +++ b/tcl8.6/doc/interp.n @@ -0,0 +1,910 @@ +'\" +'\" Copyright (c) 1995-1996 Sun Microsystems, Inc. +'\" Copyright (c) 2004 Donal K. Fellows +'\" Copyright (c) 2006-2008 Joe Mistachkin. +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH interp n 8.6 Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +interp \- Create and manipulate Tcl interpreters +.SH SYNOPSIS +\fBinterp \fIsubcommand \fR?\fIarg arg ...\fR? +.BE +.SH DESCRIPTION +.PP +This command makes it possible to create one or more new Tcl +interpreters that co-exist with the creating interpreter in the +same application. The creating interpreter is called the \fImaster\fR +and the new interpreter is called a \fIslave\fR. +A master can create any number of slaves, and each slave can +itself create additional slaves for which it is master, resulting +in a hierarchy of interpreters. +.PP +Each interpreter is independent from the others: it has its own name +space for commands, procedures, and global variables. +A master interpreter may create connections between its slaves and +itself using a mechanism called an \fIalias\fR. An \fIalias\fR is +a command in a slave interpreter which, when invoked, causes a +command to be invoked in its master interpreter or in another slave +interpreter. The only other connections between interpreters are +through environment variables (the \fBenv\fR variable), which are +normally shared among all interpreters in the application, +and by resource limit exceeded callbacks. Note that the +name space for files (such as the names returned by the \fBopen\fR command) +is no longer shared between interpreters. Explicit commands are provided to +share files and to transfer references to open files from one interpreter +to another. +.PP +The \fBinterp\fR command also provides support for \fIsafe\fR +interpreters. A safe interpreter is a slave whose functions have +been greatly restricted, so that it is safe to execute untrusted +scripts without fear of them damaging other interpreters or the +application's environment. For example, all IO channel creation +commands and subprocess creation commands are made inaccessible to safe +interpreters. +See \fBSAFE INTERPRETERS\fR below for more information on +what features are present in a safe interpreter. +The dangerous functionality is not removed from the safe interpreter; +instead, it is \fIhidden\fR, so that only trusted interpreters can obtain +access to it. For a detailed explanation of hidden commands, see +\fBHIDDEN COMMANDS\fR, below. +The alias mechanism can be used for protected communication (analogous to a +kernel call) between a slave interpreter and its master. +See \fBALIAS INVOCATION\fR, below, for more details +on how the alias mechanism works. +.PP +A qualified interpreter name is a proper Tcl lists containing a subset of its +ancestors in the interpreter hierarchy, terminated by the string naming the +interpreter in its immediate master. Interpreter names are relative to the +interpreter in which they are used. For example, if +.QW \fBa\fR +is a slave of the current interpreter and it has a slave +.QW \fBa1\fR , +which in turn has a slave +.QW \fBa11\fR , +the qualified name of +.QW \fBa11\fR +in +.QW \fBa\fR +is the list +.QW "\fBa1 a11\fR" . +.PP +The \fBinterp\fR command, described below, accepts qualified interpreter +names as arguments; the interpreter in which the command is being evaluated +can always be referred to as \fB{}\fR (the empty list or string). Note that +it is impossible to refer to a master (ancestor) interpreter by name in a +slave interpreter except through aliases. Also, there is no global name by +which one can refer to the first interpreter created in an application. +Both restrictions are motivated by safety concerns. +.SH "THE INTERP COMMAND" +.PP +The \fBinterp\fR command is used to create, delete, and manipulate +slave interpreters, and to share or transfer +channels between interpreters. It can have any of several forms, depending +on the \fIsubcommand\fR argument: +.TP +\fBinterp\fR \fBalias\fR \fIsrcPath\fR \fIsrcToken\fR +. +Returns a Tcl list whose elements are the \fItargetCmd\fR and +\fIarg\fRs associated with the alias represented by \fIsrcToken\fR +(this is the value returned when the alias was +created; it is possible that the name of the source command in the +slave is different from \fIsrcToken\fR). +.TP +\fBinterp\fR \fBalias\fR \fIsrcPath\fR \fIsrcToken\fR \fB{}\fR +. +Deletes the alias for \fIsrcToken\fR in the slave interpreter identified by +\fIsrcPath\fR. +\fIsrcToken\fR refers to the value returned when the alias +was created; if the source command has been renamed, the renamed +command will be deleted. +.TP +\fBinterp\fR \fBalias\fR \fIsrcPath\fR \fIsrcCmd\fR \fItargetPath\fR \fItargetCmd \fR?\fIarg arg ...\fR? +. +This command creates an alias between one slave and another (see the +\fBalias\fR slave command below for creating aliases between a slave +and its master). In this command, either of the slave interpreters +may be anywhere in the hierarchy of interpreters under the interpreter +invoking the command. +\fISrcPath\fR and \fIsrcCmd\fR identify the source of the alias. +\fISrcPath\fR is a Tcl list whose elements select a particular +interpreter. For example, +.QW "\fBa b\fR" +identifies an interpreter +.QW \fBb\fR , +which is a slave of interpreter +.QW \fBa\fR , +which is a slave of the invoking interpreter. An empty list specifies +the interpreter invoking the command. \fIsrcCmd\fR gives the name of +a new command, which will be created in the source interpreter. +\fITargetPath\fR and \fItargetCmd\fR specify a target interpreter +and command, and the \fIarg\fR arguments, if any, specify additional +arguments to \fItargetCmd\fR which are prepended to any arguments specified +in the invocation of \fIsrcCmd\fR. +\fITargetCmd\fR may be undefined at the time of this call, or it may +already exist; it is not created by this command. +The alias arranges for the given target command to be invoked +in the target interpreter whenever the given source command is +invoked in the source interpreter. See \fBALIAS INVOCATION\fR below for +more details. +The command returns a token that uniquely identifies the command created +\fIsrcCmd\fR, even if the command is renamed afterwards. The token may but +does not have to be equal to \fIsrcCmd\fR. +.TP +\fBinterp\fR \fBaliases \fR?\fIpath\fR? +. +This command returns a Tcl list of the tokens of all the source commands for +aliases defined in the interpreter identified by \fIpath\fR. The tokens +correspond to the values returned when +the aliases were created (which may not be the same +as the current names of the commands). +.TP +\fBinterp bgerror \fIpath\fR ?\fIcmdPrefix\fR? +. +This command either gets or sets the current background exception handler +for the interpreter identified by \fIpath\fR. If \fIcmdPrefix\fR is +absent, the current background exception handler is returned, and if it is +present, it is a list of words (of minimum length one) that describes +what to set the interpreter's background exception handler to. See the +\fBBACKGROUND EXCEPTION HANDLING\fR section for more details. +.TP +\fBinterp\fR \fBcancel \fR?\fB\-unwind\fR? ?\fB\-\|\-\fR? ?\fIpath\fR? ?\fIresult\fR? +.VS 8.6 +Cancels the script being evaluated in the interpreter identified by +\fIpath\fR. Without the \fB\-unwind\fR switch the evaluation stack for +the interpreter is unwound until an enclosing catch command is found or +there are no further invocations of the interpreter left on the call +stack. With the \fB\-unwind\fR switch the evaluation stack for the +interpreter is unwound without regard to any intervening catch command +until there are no further invocations of the interpreter left on the +call stack. The \fB\-\|\-\fR switch can be used to mark the end of +switches; it may be needed if \fIpath\fR is an unusual value such +as \fB\-safe\fR. If \fIresult\fR is present, it will be used as the +error message string; otherwise, a default error message string will be +used. +.VE 8.6 +.TP +\fBinterp\fR \fBcreate \fR?\fB\-safe\fR? ?\fB\-\|\-\fR? ?\fIpath\fR? +. +Creates a slave interpreter identified by \fIpath\fR and a new command, +called a \fIslave command\fR. The name of the slave command is the last +component of \fIpath\fR. The new slave interpreter and the slave command +are created in the interpreter identified by the path obtained by removing +the last component from \fIpath\fR. For example, if \fIpath\fR is \fBa b +c\fR then a new slave interpreter and slave command named \fBc\fR are +created in the interpreter identified by the path \fBa b\fR. +The slave command may be used to manipulate the new interpreter as +described below. If \fIpath\fR is omitted, Tcl creates a unique name of the +form \fBinterp\fIx\fR, where \fIx\fR is an integer, and uses it for the +interpreter and the slave command. If the \fB\-safe\fR switch is specified +(or if the master interpreter is a safe interpreter), the new slave +interpreter will be created as a safe interpreter with limited +functionality; otherwise the slave will include the full set of Tcl +built-in commands and variables. The \fB\-\|\-\fR switch can be used to +mark the end of switches; it may be needed if \fIpath\fR is an unusual +value such as \fB\-safe\fR. The result of the command is the name of the +new interpreter. The name of a slave interpreter must be unique among all +the slaves for its master; an error occurs if a slave interpreter by the +given name already exists in this master. +The initial recursion limit of the slave interpreter is set to the +current recursion limit of its parent interpreter. +.TP +\fBinterp\fR \fBdebug \fIpath\fR ?\fB\-frame\fR ?\fIbool\fR?? +. +Controls whether frame-level stack information is captured in the +slave interpreter identified by \fIpath\fR. If no arguments are +given, option and current setting are returned. If \fB\-frame\fR +is given, the debug setting is set to the given boolean if provided +and the current setting is returned. +This only effects the output of \fBinfo frame\fR, in that exact +frame-level information for command invocation at the bytecode level +is only captured with this setting on. +.RS +.PP +For example, with code like +.PP +.CS +\fBproc\fR mycontrol {... script} { + ... + \fBuplevel\fR 1 $script + ... +} + +\fBproc\fR dosomething {...} { + ... + mycontrol { + somecode + } +} +.CE +.PP +the standard setting will provide a relative line number for the +command \fBsomecode\fR and the relevant frame will be of type +\fBeval\fR. With frame-debug active on the other hand the tracking +extends so far that the system will be able to determine the file and +absolute line number of this command, and return a frame of type +\fBsource\fR. This more exact information is paid for with slower +execution of all commands. +.PP +Note that once it is on, this flag cannot be switched back off: such +attempts are silently ignored. This is needed to maintain the +consistency of the underlying interpreter's state. +.RE +.TP +\fBinterp\fR \fBdelete \fR?\fIpath ...?\fR +. +Deletes zero or more interpreters given by the optional \fIpath\fR +arguments, and for each interpreter, it also deletes its slaves. The +command also deletes the slave command for each interpreter deleted. +For each \fIpath\fR argument, if no interpreter by that name +exists, the command raises an error. +.TP +\fBinterp\fR \fBeval\fR \fIpath arg \fR?\fIarg ...\fR? +. +This command concatenates all of the \fIarg\fR arguments in the same +fashion as the \fBconcat\fR command, then evaluates the resulting string as +a Tcl script in the slave interpreter identified by \fIpath\fR. The result +of this evaluation (including all \fBreturn\fR options, +such as \fB\-errorinfo\fR and \fB\-errorcode\fR information, if an +error occurs) is returned to the invoking interpreter. +Note that the script will be executed in the current context stack frame of the +\fIpath\fR interpreter; this is so that the implementations (in a master +interpreter) of aliases in a slave interpreter can execute scripts in +the slave that find out information about the slave's current state +and stack frame. +.TP +\fBinterp exists \fIpath\fR +. +Returns \fB1\fR if a slave interpreter by the specified \fIpath\fR +exists in this master, \fB0\fR otherwise. If \fIpath\fR is omitted, the +invoking interpreter is used. +.TP +\fBinterp expose \fIpath\fR \fIhiddenName\fR ?\fIexposedCmdName\fR? +. +Makes the hidden command \fIhiddenName\fR exposed, eventually bringing +it back under a new \fIexposedCmdName\fR name (this name is currently +accepted only if it is a valid global name space name without any ::), +in the interpreter +denoted by \fIpath\fR. +If an exposed command with the targeted name already exists, this command +fails. +Hidden commands are explained in more detail in \fBHIDDEN COMMANDS\fR, below. +.TP +\fBinterp\fR \fBhide\fR \fIpath\fR \fIexposedCmdName\fR ?\fIhiddenCmdName\fR? +. +Makes the exposed command \fIexposedCmdName\fR hidden, renaming +it to the hidden command \fIhiddenCmdName\fR, or keeping the same name if +\fIhiddenCmdName\fR is not given, in the interpreter denoted +by \fIpath\fR. +If a hidden command with the targeted name already exists, this command +fails. +Currently both \fIexposedCmdName\fR and \fIhiddenCmdName\fR can +not contain namespace qualifiers, or an error is raised. +Commands to be hidden by \fBinterp hide\fR are looked up in the global +namespace even if the current namespace is not the global one. This +prevents slaves from fooling a master interpreter into hiding the wrong +command, by making the current namespace be different from the global one. +Hidden commands are explained in more detail in \fBHIDDEN COMMANDS\fR, below. +.TP +\fBinterp\fR \fBhidden\fR \fIpath\fR +. +Returns a list of the names of all hidden commands in the interpreter +identified by \fIpath\fR. +.TP +\fBinterp\fR \fBinvokehidden\fR \fIpath\fR ?\fI\-option ...\fR? \fIhiddenCmdName\fR ?\fIarg ...\fR? +. +Invokes the hidden command \fIhiddenCmdName\fR with the arguments supplied +in the interpreter denoted by \fIpath\fR. No substitutions or evaluation +are applied to the arguments. Three \fI\-option\fRs are supported, all +of which start with \fB\-\fR: \fB\-namespace\fR (which takes a single +argument afterwards, \fInsName\fR), \fB\-global\fR, and \fB\-\|\-\fR. +If the \fB\-namespace\fR flag is present, the hidden command is invoked in +the namespace called \fInsName\fR in the target interpreter. +If the \fB\-global\fR flag is present, the hidden command is invoked at the +global level in the target interpreter; otherwise it is invoked at the +current call frame and can access local variables in that and outer call +frames. +The \fB\-\|\-\fR flag allows the \fIhiddenCmdName\fR argument to start with a +.QW \- +character, and is otherwise unnecessary. +If both the \fB\-namespace\fR and \fB\-global\fR flags are present, the +\fB\-namespace\fR flag is ignored. +Note that the hidden command will be executed (by default) in the +current context stack frame of the \fIpath\fR interpreter. +Hidden commands are explained in more detail in \fBHIDDEN COMMANDS\fR, below. +.TP +\fBinterp issafe\fR ?\fIpath\fR? +. +Returns \fB1\fR if the interpreter identified by the specified \fIpath\fR +is safe, \fB0\fR otherwise. +.TP +\fBinterp\fR \fBlimit\fR \fIpath\fR \fIlimitType\fR ?\fI\-option\fR? ?\fIvalue\fR \fI...\fR? +. +Sets up, manipulates and queries the configuration of the resource +limit \fIlimitType\fR for the interpreter denoted by \fIpath\fR. If +no \fI\-option\fR is specified, return the current configuration of the +limit. If \fI\-option\fR is the sole argument, return the value of that +option. Otherwise, a list of \fI\-option\fR/\fIvalue\fR argument pairs +must supplied. See \fBRESOURCE LIMITS\fR below for a more detailed +explanation of what limits and options are supported. +.TP +\fBinterp marktrusted\fR \fIpath\fR +. +Marks the interpreter identified by \fIpath\fR as trusted. Does +not expose the hidden commands. This command can only be invoked from a +trusted interpreter. +The command has no effect if the interpreter identified by \fIpath\fR is +already trusted. +.TP +\fBinterp\fR \fBrecursionlimit\fR \fIpath\fR ?\fInewlimit\fR? +. +Returns the maximum allowable nesting depth for the interpreter +specified by \fIpath\fR. If \fInewlimit\fR is specified, +the interpreter recursion limit will be set so that nesting +of more than \fInewlimit\fR calls to \fBTcl_Eval\fR +and related procedures in that interpreter will return an error. +The \fInewlimit\fR value is also returned. +The \fInewlimit\fR value must be a positive integer between 1 and the +maximum value of a non-long integer on the platform. +.RS +.PP +The command sets the maximum size of the Tcl call stack only. It cannot +by itself prevent stack overflows on the C stack being used by the +application. If your machine has a limit on the size of the C stack, you +may get stack overflows before reaching the limit set by the command. If +this happens, see if there is a mechanism in your system for increasing +the maximum size of the C stack. +.RE +.TP +\fBinterp\fR \fBshare\fR \fIsrcPath channelId destPath\fR +. +Causes the IO channel identified by \fIchannelId\fR to become shared +between the interpreter identified by \fIsrcPath\fR and the interpreter +identified by \fIdestPath\fR. Both interpreters have the same permissions +on the IO channel. +Both interpreters must close it to close the underlying IO channel; IO +channels accessible in an interpreter are automatically closed when an +interpreter is destroyed. +.TP +\fBinterp\fR \fBslaves\fR ?\fIpath\fR? +. +Returns a Tcl list of the names of all the slave interpreters associated +with the interpreter identified by \fIpath\fR. If \fIpath\fR is omitted, +the invoking interpreter is used. +.TP +\fBinterp\fR \fBtarget\fR \fIpath alias\fR +. +Returns a Tcl list describing the target interpreter for an alias. The +alias is specified with an interpreter path and source command name, just +as in \fBinterp alias\fR above. The name of the target interpreter is +returned as an interpreter path, relative to the invoking interpreter. +If the target interpreter for the alias is the invoking interpreter then an +empty list is returned. If the target interpreter for the alias is not the +invoking interpreter or one of its descendants then an error is generated. +The target command does not have to be defined at the time of this invocation. +.TP +\fBinterp\fR \fBtransfer\fR \fIsrcPath channelId destPath\fR +. +Causes the IO channel identified by \fIchannelId\fR to become available in +the interpreter identified by \fIdestPath\fR and unavailable in the +interpreter identified by \fIsrcPath\fR. +.SH "SLAVE COMMAND" +.PP +For each slave interpreter created with the \fBinterp\fR command, a +new Tcl command is created in the master interpreter with the same +name as the new interpreter. This command may be used to invoke +various operations on the interpreter. It has the following +general form: +.PP +.CS +\fIslave command \fR?\fIarg arg ...\fR? +.CE +.PP +\fISlave\fR is the name of the interpreter, and \fIcommand\fR +and the \fIarg\fRs determine the exact behavior of the command. +The valid forms of this command are: +.TP +\fIslave \fBaliases\fR +. +Returns a Tcl list whose elements are the tokens of all the +aliases in \fIslave\fR. The tokens correspond to the values returned when +the aliases were created (which may not be the same +as the current names of the commands). +.TP +\fIslave \fBalias \fIsrcToken\fR +. +Returns a Tcl list whose elements are the \fItargetCmd\fR and +\fIarg\fRs associated with the alias represented by \fIsrcToken\fR +(this is the value returned when the alias was +created; it is possible that the actual source command in the +slave is different from \fIsrcToken\fR). +.TP +\fIslave \fBalias \fIsrcToken \fB{}\fR +. +Deletes the alias for \fIsrcToken\fR in the slave interpreter. +\fIsrcToken\fR refers to the value returned when the alias +was created; if the source command has been renamed, the renamed +command will be deleted. +.TP +\fIslave \fBalias \fIsrcCmd targetCmd \fR?\fIarg ..\fR? +. +Creates an alias such that whenever \fIsrcCmd\fR is invoked +in \fIslave\fR, \fItargetCmd\fR is invoked in the master. +The \fIarg\fR arguments will be passed to \fItargetCmd\fR as additional +arguments, prepended before any arguments passed in the invocation of +\fIsrcCmd\fR. +See \fBALIAS INVOCATION\fR below for details. +The command returns a token that uniquely identifies the command created +\fIsrcCmd\fR, even if the command is renamed afterwards. The token may but +does not have to be equal to \fIsrcCmd\fR. +.TP +\fIslave \fBbgerror\fR ?\fIcmdPrefix\fR? +. +This command either gets or sets the current background exception handler +for the \fIslave\fR interpreter. If \fIcmdPrefix\fR is +absent, the current background exception handler is returned, and if it is +present, it is a list of words (of minimum length one) that describes +what to set the interpreter's background exception handler to. See the +\fBBACKGROUND EXCEPTION HANDLING\fR section for more details. +.TP +\fIslave \fBeval \fIarg \fR?\fIarg ..\fR? +. +This command concatenates all of the \fIarg\fR arguments in +the same fashion as the \fBconcat\fR command, then evaluates +the resulting string as a Tcl script in \fIslave\fR. +The result of this evaluation (including all \fBreturn\fR options, +such as \fB\-errorinfo\fR and \fB\-errorcode\fR information, if an +error occurs) is returned to the invoking interpreter. +Note that the script will be executed in the current context stack frame +of \fIslave\fR; this is so that the implementations (in a master +interpreter) of aliases in a slave interpreter can execute scripts in +the slave that find out information about the slave's current state +and stack frame. +.TP +\fIslave \fBexpose \fIhiddenName \fR?\fIexposedCmdName\fR? +. +This command exposes the hidden command \fIhiddenName\fR, eventually bringing +it back under a new \fIexposedCmdName\fR name (this name is currently +accepted only if it is a valid global name space name without any ::), +in \fIslave\fR. +If an exposed command with the targeted name already exists, this command +fails. +For more details on hidden commands, see \fBHIDDEN COMMANDS\fR, below. +.TP +\fIslave \fBhide \fIexposedCmdName\fR ?\fIhiddenCmdName\fR? +. +This command hides the exposed command \fIexposedCmdName\fR, renaming it to +the hidden command \fIhiddenCmdName\fR, or keeping the same name if the +argument is not given, in the \fIslave\fR interpreter. +If a hidden command with the targeted name already exists, this command +fails. +Currently both \fIexposedCmdName\fR and \fIhiddenCmdName\fR can +not contain namespace qualifiers, or an error is raised. +Commands to be hidden are looked up in the global +namespace even if the current namespace is not the global one. This +prevents slaves from fooling a master interpreter into hiding the wrong +command, by making the current namespace be different from the global one. +For more details on hidden commands, see \fBHIDDEN COMMANDS\fR, below. +.TP +\fIslave \fBhidden\fR +. +Returns a list of the names of all hidden commands in \fIslave\fR. +.TP +\fIslave \fBinvokehidden\fR ?\fI\-option ...\fR? \fIhiddenName \fR?\fIarg ..\fR? +. +This command invokes the hidden command \fIhiddenName\fR with the +supplied arguments, in \fIslave\fR. No substitutions or evaluations are +applied to the arguments. Three \fI\-option\fRs are supported, all +of which start with \fB\-\fR: \fB\-namespace\fR (which takes a single +argument afterwards, \fInsName\fR), \fB\-global\fR, and \fB\-\|\-\fR. +If the \fB\-namespace\fR flag is given, the hidden command is invoked in +the specified namespace in the slave. +If the \fB\-global\fR flag is given, the command is invoked at the global +level in the slave; otherwise it is invoked at the current call frame and +can access local variables in that or outer call frames. +The \fB\-\|\-\fR flag allows the \fIhiddenCmdName\fR argument to start with a +.QW \- +character, and is otherwise unnecessary. +If both the \fB\-namespace\fR and \fB\-global\fR flags are given, the +\fB\-namespace\fR flag is ignored. +Note that the hidden command will be executed (by default) in the +current context stack frame of \fIslave\fR. +For more details on hidden commands, +see \fBHIDDEN COMMANDS\fR, below. +.TP +\fIslave \fBissafe\fR +. +Returns \fB1\fR if the slave interpreter is safe, \fB0\fR otherwise. +.TP +\fIslave \fBlimit\fR \fIlimitType\fR ?\fI\-option\fR? ?\fIvalue\fR \fI...\fR? +. +Sets up, manipulates and queries the configuration of the resource +limit \fIlimitType\fR for the slave interpreter. If no \fI\-option\fR +is specified, return the current configuration of the limit. If +\fI\-option\fR is the sole argument, return the value of that option. +Otherwise, a list of \fI\-option\fR/\fIvalue\fR argument pairs must +supplied. See \fBRESOURCE LIMITS\fR below for a more detailed explanation of +what limits and options are supported. +.TP +\fIslave \fBmarktrusted\fR +. +Marks the slave interpreter as trusted. Can only be invoked by a +trusted interpreter. This command does not expose any hidden +commands in the slave interpreter. The command has no effect if the slave +is already trusted. +.TP +\fIslave\fR \fBrecursionlimit\fR ?\fInewlimit\fR? +. +Returns the maximum allowable nesting depth for the \fIslave\fR interpreter. +If \fInewlimit\fR is specified, the recursion limit in \fIslave\fR will be +set so that nesting of more than \fInewlimit\fR calls to \fBTcl_Eval()\fR +and related procedures in \fIslave\fR will return an error. +The \fInewlimit\fR value is also returned. +The \fInewlimit\fR value must be a positive integer between 1 and the +maximum value of a non-long integer on the platform. +.RS +.PP +The command sets the maximum size of the Tcl call stack only. It cannot +by itself prevent stack overflows on the C stack being used by the +application. If your machine has a limit on the size of the C stack, you +may get stack overflows before reaching the limit set by the command. If +this happens, see if there is a mechanism in your system for increasing +the maximum size of the C stack. +.RE +.SH "SAFE INTERPRETERS" +.PP +A safe interpreter is one with restricted functionality, so that +is safe to execute an arbitrary script from your worst enemy without +fear of that script damaging the enclosing application or the rest +of your computing environment. In order to make an interpreter +safe, certain commands and variables are removed from the interpreter. +For example, commands to create files on disk are removed, and the +\fBexec\fR command is removed, since it could be used to cause damage +through subprocesses. +Limited access to these facilities can be provided, by creating +aliases to the master interpreter which check their arguments carefully +and provide restricted access to a safe subset of facilities. +For example, file creation might be allowed in a particular subdirectory +and subprocess invocation might be allowed for a carefully selected and +fixed set of programs. +.PP +A safe interpreter is created by specifying the \fB\-safe\fR switch +to the \fBinterp create\fR command. Furthermore, any slave created +by a safe interpreter will also be safe. +.PP +A safe interpreter is created with exactly the following set of +built-in commands: +.DS +.ta 1.2i 2.4i 3.6i +\fBafter\fR \fBappend\fR \fBapply\fR \fBarray\fR +\fBbinary\fR \fBbreak\fR \fBcatch\fR \fBchan\fR +\fBclock\fR \fBclose\fR \fBconcat\fR \fBcontinue\fR +\fBdict\fR \fBeof\fR \fBerror\fR \fBeval\fR +\fBexpr\fR \fBfblocked\fR \fBfcopy\fR \fBfileevent\fR +\fBflush\fR \fBfor\fR \fBforeach\fR \fBformat\fR +\fBgets\fR \fBglobal\fR \fBif\fR \fBincr\fR +\fBinfo\fR \fBinterp\fR \fBjoin\fR \fBlappend\fR +\fBlassign\fR \fBlindex\fR \fBlinsert\fR \fBlist\fR +\fBllength\fR \fBlrange\fR \fBlrepeat\fR \fBlreplace\fR +\fBlsearch\fR \fBlset\fR \fBlsort\fR \fBnamespace\fR +\fBpackage\fR \fBpid\fR \fBproc\fR \fBputs\fR +\fBread\fR \fBregexp\fR \fBregsub\fR \fBrename\fR +\fBreturn\fR \fBscan\fR \fBseek\fR \fBset\fR +\fBsplit\fR \fBstring\fR \fBsubst\fR \fBswitch\fR +\fBtell\fR \fBtime\fR \fBtrace\fR \fBunset\fR +\fBupdate\fR \fBuplevel\fR \fBupvar\fR \fBvariable\fR +\fBvwait\fR \fBwhile\fR +.DE +The following commands are hidden by \fBinterp create\fR when it +creates a safe interpreter: +.DS +.ta 1.2i 2.4i 3.6i +\fBcd\fR \fBencoding\fR \fBexec\fR \fBexit\fR +\fBfconfigure\fR \fBfile\fR \fBglob\fR \fBload\fR +\fBopen\fR \fBpwd\fR \fBsocket\fR \fBsource\fR +\fBunload\fR +.DE +These commands can be recreated later as Tcl procedures or aliases, or +re-exposed by \fBinterp expose\fR. +.PP +The following commands from Tcl's library of support procedures are +not present in a safe interpreter: +.DS +.ta 1.6i 3.2i +\fBauto_exec_ok\fR \fBauto_import\fR \fBauto_load\fR +\fBauto_load_index\fR \fBauto_qualify\fR \fBunknown\fR +.DE +Note in particular that safe interpreters have no default \fBunknown\fR +command, so Tcl's default autoloading facilities are not available. +Autoload access to Tcl's commands that are normally autoloaded: +.DS +.ta 2.1i +\fBauto_mkindex\fR \fBauto_mkindex_old\fR +\fBauto_reset\fR \fBhistory\fR +\fBparray\fR \fBpkg_mkIndex\fR +\fB::pkg::create\fR \fB::safe::interpAddToAccessPath\fR +\fB::safe::interpCreate\fR \fB::safe::interpConfigure\fR +\fB::safe::interpDelete\fR \fB::safe::interpFindInAccessPath\fR +\fB::safe::interpInit\fR \fB::safe::setLogCmd\fR +\fBtcl_endOfWord\fR \fBtcl_findLibrary\fR +\fBtcl_startOfNextWord\fR \fBtcl_startOfPreviousWord\fR +\fBtcl_wordBreakAfter\fR \fBtcl_wordBreakBefore\fR +.DE +can only be provided by explicit definition of an \fBunknown\fR command +in the safe interpreter. This will involve exposing the \fBsource\fR +command. This is most easily accomplished by creating the safe interpreter +with Tcl's \fBSafe\-Tcl\fR mechanism. \fBSafe\-Tcl\fR provides safe +versions of \fBsource\fR, \fBload\fR, and other Tcl commands needed +to support autoloading of commands and the loading of packages. +.PP +In addition, the \fBenv\fR variable is not present in a safe interpreter, +so it cannot share environment variables with other interpreters. The +\fBenv\fR variable poses a security risk, because users can store +sensitive information in an environment variable. For example, the PGP +manual recommends storing the PGP private key protection password in +the environment variable \fIPGPPASS\fR. Making this variable available +to untrusted code executing in a safe interpreter would incur a +security risk. +.PP +If extensions are loaded into a safe interpreter, they may also restrict +their own functionality to eliminate unsafe commands. For a discussion of +management of extensions for safety see the manual entries for +\fBSafe\-Tcl\fR and the \fBload\fR Tcl command. +.PP +A safe interpreter may not alter the recursion limit of any interpreter, +including itself. +.SH "ALIAS INVOCATION" +.PP +The alias mechanism has been carefully designed so that it can +be used safely when an untrusted script is executing +in a safe slave and the target of the alias is a trusted +master. The most important thing in guaranteeing safety is to +ensure that information passed from the slave to the master is +never evaluated or substituted in the master; if this were to +occur, it would enable an evil script in the slave to invoke +arbitrary functions in the master, which would compromise security. +.PP +When the source for an alias is invoked in the slave interpreter, the +usual Tcl substitutions are performed when parsing that command. +These substitutions are carried out in the source interpreter just +as they would be for any other command invoked in that interpreter. +The command procedure for the source command takes its arguments +and merges them with the \fItargetCmd\fR and \fIarg\fRs for the +alias to create a new array of arguments. If the words +of \fIsrcCmd\fR were +.QW "\fIsrcCmd arg1 arg2 ... argN\fR" , +the new set of words will be +.QW "\fItargetCmd arg arg ... arg arg1 arg2 ... argN\fR" , +where \fItargetCmd\fR and \fIarg\fRs are the values supplied when the +alias was created. \fITargetCmd\fR is then used to locate a command +procedure in the target interpreter, and that command procedure +is invoked with the new set of arguments. An error occurs if +there is no command named \fItargetCmd\fR in the target interpreter. +No additional substitutions are performed on the words: the +target command procedure is invoked directly, without +going through the normal Tcl evaluation mechanism. +Substitutions are thus performed on each word exactly once: +\fItargetCmd\fR and \fIargs\fR were substituted when parsing the command +that created the alias, and \fIarg1 - argN\fR are substituted when +the alias's source command is parsed in the source interpreter. +.PP +When writing the \fItargetCmd\fRs for aliases in safe interpreters, +it is very important that the arguments to that command never be +evaluated or substituted, since this would provide an escape +mechanism whereby the slave interpreter could execute arbitrary +code in the master. This in turn would compromise the security +of the system. +.SH "HIDDEN COMMANDS" +.PP +Safe interpreters greatly restrict the functionality available to Tcl +programs executing within them. +Allowing the untrusted Tcl program to have direct access to this +functionality is unsafe, because it can be used for a variety of +attacks on the environment. +However, there are times when there is a legitimate need to use the +dangerous functionality in the context of the safe interpreter. For +example, sometimes a program must be \fBsource\fRd into the interpreter. +Another example is Tk, where windows are bound to the hierarchy of windows +for a specific interpreter; some potentially dangerous functions, e.g. +window management, must be performed on these windows within the +interpreter context. +.PP +The \fBinterp\fR command provides a solution to this problem in the form of +\fIhidden commands\fR. Instead of removing the dangerous commands entirely +from a safe interpreter, these commands are hidden so they become +unavailable to Tcl scripts executing in the interpreter. However, such +hidden commands can be invoked by any trusted ancestor of the safe +interpreter, in the context of the safe interpreter, using \fBinterp +invoke\fR. Hidden commands and exposed commands reside in separate name +spaces. It is possible to define a hidden command and an exposed command by +the same name within one interpreter. +.PP +Hidden commands in a slave interpreter can be invoked in the body of +procedures called in the master during alias invocation. For example, an +alias for \fBsource\fR could be created in a slave interpreter. When it is +invoked in the slave interpreter, a procedure is called in the master +interpreter to check that the operation is allowable (e.g. it asks to +source a file that the slave interpreter is allowed to access). The +procedure then it invokes the hidden \fBsource\fR command in the slave +interpreter to actually source in the contents of the file. Note that two +commands named \fBsource\fR exist in the slave interpreter: the alias, and +the hidden command. +.PP +Because a master interpreter may invoke a hidden command as part of +handling an alias invocation, great care must be taken to avoid evaluating +any arguments passed in through the alias invocation. +Otherwise, malicious slave interpreters could cause a trusted master +interpreter to execute dangerous commands on their behalf. See the section +on \fBALIAS INVOCATION\fR for a more complete discussion of this topic. +To help avoid this problem, no substitutions or evaluations are +applied to arguments of \fBinterp invokehidden\fR. +.PP +Safe interpreters are not allowed to invoke hidden commands in themselves +or in their descendants. This prevents safe slaves from gaining access to +hidden functionality in themselves or their descendants. +.PP +The set of hidden commands in an interpreter can be manipulated by a trusted +interpreter using \fBinterp expose\fR and \fBinterp hide\fR. The \fBinterp +expose\fR command moves a hidden command to the +set of exposed commands in the interpreter identified by \fIpath\fR, +potentially renaming the command in the process. If an exposed command by +the targeted name already exists, the operation fails. Similarly, +\fBinterp hide\fR moves an exposed command to the set of hidden commands in +that interpreter. Safe interpreters are not allowed to move commands +between the set of hidden and exposed commands, in either themselves or +their descendants. +.PP +Currently, the names of hidden commands cannot contain namespace +qualifiers, and you must first rename a command in a namespace to the +global namespace before you can hide it. +Commands to be hidden by \fBinterp hide\fR are looked up in the global +namespace even if the current namespace is not the global one. This +prevents slaves from fooling a master interpreter into hiding the wrong +command, by making the current namespace be different from the global one. +.SH "RESOURCE LIMITS" +.PP +Every interpreter has two kinds of resource limits that may be imposed by any +master interpreter upon its slaves. Command limits (of type \fBcommand\fR) +restrict the total number of Tcl commands that may be executed by an +interpreter (as can be inspected via the \fBinfo cmdcount\fR command), and +time limits (of type \fBtime\fR) place a limit by which execution within the +interpreter must complete. Note that time limits are expressed as +\fIabsolute\fR times (as in \fBclock seconds\fR) and not relative times (as in +\fBafter\fR) because they may be modified after creation. +.PP +When a limit is exceeded for an interpreter, first any handler callbacks +defined by master interpreters are called. If those callbacks increase or +remove the limit, execution within the (previously) limited interpreter +continues. If the limit is still in force, an error is generated at that point +and normal processing of errors within the interpreter (by the \fBcatch\fR +command) is disabled, so the error propagates outwards (building a stack-trace +as it goes) to the point where the limited interpreter was invoked (e.g. by +\fBinterp eval\fR) where it becomes the responsibility of the calling code to +catch and handle. +.SS "LIMIT OPTIONS" +.PP +Every limit has a number of options associated with it, some of which are +common across all kinds of limits, and others of which are particular to the +kind of limit. +.TP +\fB\-command\fR +. +This option (common for all limit types) specifies (if non-empty) a Tcl script +to be executed in the global namespace of the interpreter reading and writing +the option when the particular limit in the limited interpreter is exceeded. +The callback may modify the limit on the interpreter if it wishes the limited +interpreter to continue executing. If the callback generates an exception, it +is reported through the background exception mechanism (see +\fBBACKGROUND EXCEPTION HANDLING\fR). +Note that the callbacks defined by one interpreter are +completely isolated from the callbacks defined by another, and that the order +in which those callbacks are called is undefined. +.TP +\fB\-granularity\fR +. +This option (common for all limit types) specifies how frequently (out of the +points when the Tcl interpreter is in a consistent state where limit checking +is possible) that the limit is actually checked. This allows the tuning of how +frequently a limit is checked, and hence how often the limit-checking overhead +(which may be substantial in the case of time limits) is incurred. +.TP +\fB\-milliseconds\fR +. +This option specifies the number of milliseconds after the moment defined in +the \fB\-seconds\fR option that the time limit will fire. It should only ever +be specified in conjunction with the \fB\-seconds\fR option (whether it was +set previously or is being set this invocation.) +.TP +\fB\-seconds\fR +. +This option specifies the number of seconds after the epoch (see \fBclock +seconds\fR) that the time limit for the interpreter will be triggered. The +limit will be triggered at the start of the second unless specified at a +sub-second level using the \fB\-milliseconds\fR option. This option may be the +empty string, which indicates that a time limit is not set for the +interpreter. +.TP +\fB\-value\fR +. +This option specifies the number of commands that the interpreter may execute +before triggering the command limit. This option may be the empty string, +which indicates that a command limit is not set for the interpreter. +.PP +Where an interpreter with a resource limit set on it creates a slave +interpreter, that slave interpreter will have resource limits imposed on it +that are at least as restrictive as the limits on the creating master +interpreter. If the master interpreter of the limited master wishes to relax +these conditions, it should hide the \fBinterp\fR command in the child and +then use aliases and the \fBinterp invokehidden\fR subcommand to provide such +access as it chooses to the \fBinterp\fR command to the limited master as +necessary. +.SH "BACKGROUND EXCEPTION HANDLING" +.PP +When an exception happens in a situation where it cannot be reported directly up +the stack (e.g. when processing events in an \fBupdate\fR or \fBvwait\fR call) +the exception is instead reported through the background exception handling mechanism. +Every interpreter has a background exception handler registered; the default exception +handler arranges for the \fBbgerror\fR command in the interpreter's global +namespace to be called, but other exception handlers may be installed and process +background exceptions in substantially different ways. +.PP +A background exception handler consists of a non-empty list of words to which will +be appended two further words at invocation time. The first word will be the +interpreter result at time of the exception, typically an error message, +and the second will be the dictionary of return options at the time of +the exception. These are the same values that \fBcatch\fR can capture +when it controls script evaluation in a non-background situation. +The resulting list will then be executed +in the interpreter's global namespace without further substitutions being +performed. +.SH CREDITS +The safe interpreter mechanism is based on the Safe-Tcl prototype implemented +by Nathaniel Borenstein and Marshall Rose. +.SH EXAMPLES +.PP +Creating and using an alias for a command in the current interpreter: +.PP +.CS +\fBinterp alias\fR {} getIndex {} lsearch {alpha beta gamma delta} +set idx [getIndex delta] +.CE +.PP +Executing an arbitrary command in a safe interpreter where every +invocation of \fBlappend\fR is logged: +.PP +.CS +set i [\fBinterp create\fR -safe] +\fBinterp hide\fR $i lappend +\fBinterp alias\fR $i lappend {} loggedLappend $i +proc loggedLappend {i args} { + puts "logged invocation of lappend $args" + \fBinterp invokehidden\fR $i lappend {*}$args +} +\fBinterp eval\fR $i $someUntrustedScript +.CE +.PP +Setting a resource limit on an interpreter so that an infinite loop +terminates. +.PP +.CS +set i [\fBinterp create\fR] +\fBinterp limit\fR $i command -value 1000 +\fBinterp eval\fR $i { + set x 0 + while {1} { + puts "Counting up... [incr x]" + } +} +.CE +.SH "SEE ALSO" +bgerror(n), load(n), safe(n), Tcl_CreateSlave(3), Tcl_Eval(3), Tcl_BackgroundException(3) +.SH KEYWORDS +alias, master interpreter, safe interpreter, slave interpreter +'\"Local Variables: +'\"mode: nroff +'\"End: diff --git a/tcl8.6/doc/join.n b/tcl8.6/doc/join.n new file mode 100644 index 0000000..c8179bb --- /dev/null +++ b/tcl8.6/doc/join.n @@ -0,0 +1,44 @@ +'\" +'\" Copyright (c) 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. +'\" +.TH join n "" Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +join \- Create a string by joining together list elements +.SH SYNOPSIS +\fBjoin \fIlist \fR?\fIjoinString\fR? +.BE +.SH DESCRIPTION +.PP +The \fIlist\fR argument must be a valid Tcl list. +This command returns the string +formed by joining all of the elements of \fIlist\fR together with +\fIjoinString\fR separating each adjacent pair of elements. +The \fIjoinString\fR argument defaults to a space character. +.SH EXAMPLES +.PP +Making a comma-separated list: +.PP +.CS +set data {1 2 3 4 5} +\fBjoin\fR $data ", " + \fB\(-> 1, 2, 3, 4, 5\fR +.CE +.PP +Using \fBjoin\fR to flatten a list by a single level: +.PP +.CS +set data {1 {2 3} 4 {5 {6 7} 8}} +\fBjoin\fR $data + \fB\(-> 1 2 3 4 5 {6 7} 8\fR +.CE +.SH "SEE ALSO" +list(n), lappend(n), split(n) +.SH KEYWORDS +element, join, list, separator diff --git a/tcl8.6/doc/lappend.n b/tcl8.6/doc/lappend.n new file mode 100644 index 0000000..a324ca3 --- /dev/null +++ b/tcl8.6/doc/lappend.n @@ -0,0 +1,49 @@ +'\" +'\" Copyright (c) 1993 The Regents of the University of California. +'\" Copyright (c) 1994-1996 Sun Microsystems, Inc. +'\" Copyright (c) 2001 Kevin B. Kenny <kennykb@acm.org>. All rights reserved. +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH lappend n "" Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +lappend \- Append list elements onto a variable +.SH SYNOPSIS +\fBlappend \fIvarName \fR?\fIvalue value value ...\fR? +.BE +.SH DESCRIPTION +.PP +This command treats the variable given by \fIvarName\fR as a list +and appends each of the \fIvalue\fR arguments to that list as a separate +element, with spaces between elements. +If \fIvarName\fR does not exist, it is created as a list with elements +given by the \fIvalue\fR arguments. +\fBLappend\fR is similar to \fBappend\fR except that the \fIvalue\fRs +are appended as list elements rather than raw text. +This command provides a relatively efficient way to build up +large lists. For example, +.QW "\fBlappend a $b\fR" +is much more efficient than +.QW "\fBset a [concat $a [list $b]]\fR" +when \fB$a\fR is long. +.SH EXAMPLE +.PP +Using \fBlappend\fR to build up a list of numbers. +.PP +.CS +% set var 1 +1 +% \fBlappend\fR var 2 +1 2 +% \fBlappend\fR var 3 4 5 +1 2 3 4 5 +.CE +.SH "SEE ALSO" +list(n), lindex(n), linsert(n), llength(n), lset(n), +lsort(n), lrange(n) +.SH KEYWORDS +append, element, list, variable diff --git a/tcl8.6/doc/lassign.n b/tcl8.6/doc/lassign.n new file mode 100644 index 0000000..e250729 --- /dev/null +++ b/tcl8.6/doc/lassign.n @@ -0,0 +1,60 @@ +'\" +'\" Copyright (c) 1992-1999 Karl Lehenbauer & Mark Diekhans +'\" Copyright (c) 2004 Donal K. Fellows +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH lassign n 8.5 Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +lassign \- Assign list elements to variables +.SH SYNOPSIS +\fBlassign \fIlist \fR?\fIvarName ...\fR? +.BE +.SH DESCRIPTION +.PP +This command treats the value \fIlist\fR as a list and assigns +successive elements from that list to the variables given by the +\fIvarName\fR arguments in order. If there are more variable names +than list elements, the remaining variables are set to the empty +string. If there are more list elements than variables, a list of +unassigned elements is returned. +.SH EXAMPLES +.PP +An illustration of how multiple assignment works, and what happens +when there are either too few or too many elements. +.PP +.CS +\fBlassign\fR {a b c} x y z ;# Empty return +puts $x ;# Prints "a" +puts $y ;# Prints "b" +puts $z ;# Prints "c" + +\fBlassign\fR {d e} x y z ;# Empty return +puts $x ;# Prints "d" +puts $y ;# Prints "e" +puts $z ;# Prints "" + +\fBlassign\fR {f g h i} x y ;# Returns "h i" +puts $x ;# Prints "f" +puts $y ;# Prints "g" +.CE +.PP +The \fBlassign\fR command has other uses. It can be used to create +the analogue of the +.QW shift +command in many shell languages like this: +.PP +.CS +set ::argv [\fBlassign\fR $::argv argumentToReadOff] +.CE +.SH "SEE ALSO" +lindex(n), list(n), lrange(n), lset(n), set(n) +.SH KEYWORDS +assign, element, list, multiple, set, variable +'\"Local Variables: +'\"mode: nroff +'\"End: diff --git a/tcl8.6/doc/library.n b/tcl8.6/doc/library.n new file mode 100644 index 0000000..6f8f265 --- /dev/null +++ b/tcl8.6/doc/library.n @@ -0,0 +1,320 @@ +'\" +'\" 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. +'\" +.TH library n "8.0" Tcl "Tcl Built-In Commands" +.so man.macros +.BS +.SH NAME +auto_execok, auto_import, auto_load, auto_mkindex, 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_qualify \fIcommand namespace\fR +\fBauto_reset\fR +\fBtcl_findLibrary \fIbasename version patch initScript enVarName varName\fR +\fBparray \fIarrayName\fR ?\fIpattern\fR? +\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 +.BE +.SH INTRODUCTION +.PP +Tcl includes a library of Tcl procedures for commonly-needed functions. +The procedures defined in the Tcl library are generic ones suitable +for use by many different applications. +The location of the Tcl library is returned by the \fBinfo library\fR +command. +In addition to the Tcl library, each application will normally have +its own library of support procedures as well; the location of this +library is normally given by the value of the \fB$\fIapp\fB_library\fR +global variable, where \fIapp\fR is the name of the application. +For example, the location of the Tk library is kept in the variable +\fBtk_library\fR. +.PP +To access the procedures in the Tcl library, an application should +source the file \fBinit.tcl\fR in the library, for example with +the Tcl command +.PP +.CS +\fBsource [file join [info library] init.tcl]\fR +.CE +.PP +If 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 procedure +and arrange for the other procedures to be loaded on-demand using +the auto-load mechanism defined below. +.SH "COMMAND PROCEDURES" +.PP +The following procedures are provided in the Tcl library: +.TP +\fBauto_execok \fIcmd\fR +Determines whether there is an executable file or shell builtin +by the name \fIcmd\fR. If so, it returns a list of arguments to be +passed to \fBexec\fR to execute the executable file or shell builtin +named by \fIcmd\fR. If not, it returns an empty string. This command +examines the directories in the current search path (given by the PATH +environment variable) in its search for an executable file named +\fIcmd\fR. On Windows platforms, the search is expanded with the same +directories and file extensions as used by \fBexec\fR. \fBAuto_execok\fR +remembers information about previous searches in an array named +\fBauto_execs\fR; this avoids the path search in future calls for the +same \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 if +the imported commands specified by \fIpattern\fR reside in an +autoloaded library. If so, the commands are loaded so that they will +be available to the interpreter for creating the import links. If the +commands do not reside in an autoloaded library, \fBauto_import\fR +does nothing. The pattern matching is performed according to the +matching rules of \fBnamespace import\fR. +.TP +\fBauto_load \fIcmd\fR +This 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 of one or more directories. The auto-load path is given by the +global variable \fBauto_path\fR if it exists. If there is no +\fBauto_path\fR variable, then the TCLLIBPATH environment variable 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 one or more +commands defined in that directory and 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 appropriate script is evaluated to create the +command. The \fBauto_load\fR command returns 1 if \fIcmd\fR was +successfully created. The command returns 0 if there was no index +entry for \fIcmd\fR or if the script did not actually define \fIcmd\fR +(e.g. because index information is out of date). If an error occurs +while processing the script, then that error is returned. +\fBAuto_load\fR only reads the index information once and saves it in +the array \fBauto_index\fR; future calls to \fBauto_load\fR check for +\fIcmd\fR in the array rather than re-reading the index files. The +cached index information may be deleted with the command +\fBauto_reset\fR. This will force the next \fBauto_load\fR command to +reload the index database from disk. +.TP +\fBauto_mkindex \fIdir pattern pattern ...\fR +. +Generates an index suitable for use by \fBauto_load\fR. The command +searches \fIdir\fR for all files whose names match any of the +\fIpattern\fR arguments (matching is done with the \fBglob\fR +command), generates an index of all the Tcl command procedures defined +in all the matching files, and stores the index 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 +.PP +.CS +\fBauto_mkindex foo *.tcl\fR +.CE +.PP +will read all the \fB.tcl\fR files in subdirectory \fBfoo\fR and +generate a new index file \fBfoo/tclIndex\fR. +.PP +\fBAuto_mkindex\fR parses the Tcl scripts by sourcing them into a +slave interpreter and monitoring the proc and namespace commands that +are executed. Extensions can use the (undocumented) +auto_mkindex_parser package to register other commands that can +contribute to the auto_load index. You will have to read through +auto.tcl to see how this works. +.PP +\fBAuto_mkindex_old\fR +(which has the same syntax as \fBauto_mkindex\fR) +parses the Tcl scripts in a relatively +unsophisticated way: if any line contains the word +.QW \fBproc\fR +as its first characters then it is assumed to be a procedure +definition and the next word of the line is taken as the +procedure's name. +Procedure definitions that do not appear in this way (e.g.\ they +have spaces before the \fBproc\fR) will not be indexed. If your +script contains +.QW dangerous +code, such as global initialization +code or procedure names with special characters like \fB$\fR, +\fB*\fR, \fB[\fR or \fB]\fR, you are safer using \fBauto_mkindex_old\fR. +.RE +.TP +\fBauto_reset\fR +. +Destroys all the information cached by \fBauto_execok\fR and +\fBauto_load\fR. This information will be re-read from disk the next +time it is needed. \fBAuto_reset\fR also deletes any procedures +listed in the auto-load index, so that fresh copies of them will be +loaded the next time that they are used. +.TP +\fBauto_qualify \fIcommand namespace\fR +Computes a list of fully qualified names for \fIcommand\fR. This list +mirrors the path a standard Tcl interpreter follows for command +lookups: first it looks for the command in the current namespace, and +then in the global namespace. Accordingly, if \fIcommand\fR is +relative and \fInamespace\fR is not \fB::\fR, the list returned has +two elements: \fIcommand\fR scoped by \fInamespace\fR, as if it were +a command in the \fInamespace\fR namespace; and \fIcommand\fR as if it +were 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 as +if it were a command in the global namespace. +.RS +.PP +\fBAuto_qualify\fR is used by the auto-loading facilities in Tcl, both +for producing auto-loading indexes such as \fIpkgIndex.tcl\fR, and for +performing the actual auto-loading of functions at runtime. +.RE +.TP +\fBtcl_findLibrary \fIbasename version patch initScript enVarName varName\fR +This is a standard search procedure for use by extensions during +their initialization. They call this procedure to look for their +script library in several standard directories. +The last component of the name of the library directory is +normally \fIbasenameversion\fR +(e.g., tk8.0), but it might be +.QW library +when in the build hierarchies. +The \fIinitScript\fR file will be sourced into the interpreter +once it is found. The directory in which this file is found is +stored into the global variable \fIvarName\fR. +If this variable is already defined (e.g., by C code during +application initialization) then no searching is done. +Otherwise the search looks in these directories: +the directory named by the environment variable \fIenVarName\fR; +relative to the Tcl library directory; +relative to the executable file in the standard installation +bin or bin/\fIarch\fR directory; +relative to the executable file in the current build tree; +relative to the executable file in a parallel build tree. +.TP +\fBparray \fIarrayName\fR ?\fIpattern\fR? +Prints on standard output the names and values of all the elements in the +array \fIarrayName\fR, or just the names that match \fIpattern\fR (using the +matching rules of \fBstring match\fR) and their values if \fIpattern\fR is +given. +\fIArrayName\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 +Returns the index of the first end-of-word location that occurs after +a starting index \fIstart\fR in the string \fIstr\fR. An end-of-word +location is defined to be the first non-word character following the +first word character after the starting point. Returns -1 if there +are no more end-of-word locations after the starting point. See the +description of \fBtcl_wordchars\fR and \fBtcl_nonwordchars\fR below +for more details on how Tcl determines which characters are word +characters. +.TP +\fBtcl_startOfNextWord \fIstr start\fR +Returns the index of the first start-of-word location that occurs +after a starting index \fIstart\fR in the string \fIstr\fR. A +start-of-word location is defined to be the first word character +following a non-word character. Returns \-1 if there are no more +start-of-word locations after the starting point. +.TP +\fBtcl_startOfPreviousWord \fIstr start\fR +Returns the index of the first start-of-word location that occurs +before a starting index \fIstart\fR in the string \fIstr\fR. Returns +\-1 if there are no more start-of-word locations before the starting +point. +.TP +\fBtcl_wordBreakAfter \fIstr start\fR +Returns the index of the first word boundary after the starting index +\fIstart\fR in the string \fIstr\fR. Returns \-1 if there are no more +boundaries after the starting point in the given string. The index +returned refers to the second character of the pair that comprises a +boundary. +.TP +\fBtcl_wordBreakBefore \fIstr start\fR +Returns the index of the first word boundary before the starting index +\fIstart\fR in the string \fIstr\fR. Returns \-1 if there are no more +boundaries before the starting point in the given string. The index +returned refers to the second character of the pair that comprises a +boundary. +.SH "VARIABLES" +.PP +The following global variables are defined or used by the procedures in +the Tcl library. They fall into two broad classes, handling unknown +commands and packages, and determining what are words. +.SS "AUTOLOADING AND PACKAGE MANAGEMENT VARIABLES" +.TP +\fBauto_execs\fR +Used by \fBauto_execok\fR to record information about whether +particular commands exist as executable files. +.TP +\fBauto_index\fR +Used by \fBauto_load\fR to save the index information read from +disk. +.TP +\fBauto_noexec\fR +If set to any value, then \fBunknown\fR will not attempt to auto-exec +any commands. +.TP +\fBauto_noload\fR +If set to any value, then \fBunknown\fR will not attempt to auto-load +any commands. +.TP +\fBauto_path\fR +. +If set, then it must contain a valid Tcl list giving directories to +search during auto-load operations (including for package index +files when using the default \fBpackage unknown\fR handler). +This variable is initialized during startup to contain, in order: +the directories listed in the \fBTCLLIBPATH\fR environment variable, +the directory named by the \fBtcl_library\fR global variable, +the parent directory of \fBtcl_library\fR, +the directories listed in the \fBtcl_pkgPath\fR variable. +Additional locations to look for files and package indices should +normally be added to this variable using \fBlappend\fR. +.TP +\fBenv(TCL_LIBRARY)\fR +If set, then it specifies the location of the directory containing +library scripts (the value of this variable will be +assigned to the \fBtcl_library\fR variable and therefore returned by +the command \fBinfo library\fR). If this variable is not set then +a default value is used. +.TP +\fBenv(TCLLIBPATH)\fR +If set, then it must contain a valid Tcl list giving directories to +search during auto-load operations. Directories must be specified in +Tcl format, using +.QW / +as the path separator, regardless of platform. +This variable is only used when initializing the \fBauto_path\fR variable. +.SS "WORD BOUNDARY DETERMINATION VARIABLES" +These variables are only used in the \fBtcl_endOfWord\fR, +\fBtcl_startOfNextWord\fR, \fBtcl_startOfPreviousWord\fR, +\fBtcl_wordBreakAfter\fR, and \fBtcl_wordBreakBefore\fR commands. +.TP +\fBtcl_nonwordchars\fR +This variable contains a regular expression that is used by routines +like \fBtcl_endOfWord\fR to identify whether a character is part of a +word or not. If the pattern matches a character, the character is +considered 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 considered +non-word characters. +.TP +\fBtcl_wordchars\fR +This variable contains a regular expression that is used by routines +like \fBtcl_endOfWord\fR to identify whether a character is part of a +word or not. If the pattern matches a character, the character is +considered to be a word character. On Windows platforms, words are +comprised of any character that is not a space, tab, or newline. Under +Unix, words are comprised of numbers, letters or underscores. +.SH "SEE ALSO" +env(n), info(n), re_syntax(n) +.SH KEYWORDS +auto-exec, auto-load, library, unknown, word, whitespace +'\"Local Variables: +'\"mode: nroff +'\"End: diff --git a/tcl8.6/doc/license.terms b/tcl8.6/doc/license.terms new file mode 100644 index 0000000..d8049cd --- /dev/null +++ b/tcl8.6/doc/license.terms @@ -0,0 +1,40 @@ +This software is copyrighted by the Regents of the University of +California, Sun Microsystems, Inc., Scriptics Corporation, ActiveState +Corporation and other parties. The following terms apply to all files +associated with the software unless explicitly disclaimed in +individual files. + +The authors hereby grant permission to use, copy, modify, distribute, +and license this software and its documentation for any purpose, provided +that existing copyright notices are retained in all copies and that this +notice is included verbatim in any distributions. No written agreement, +license, or royalty fee is required for any of the authorized uses. +Modifications to this software may be copyrighted by their authors +and need not follow the licensing terms described here, provided that +the new terms are clearly indicated on the first page of each file where +they apply. + +IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY +FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES +ARISING OUT OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY +DERIVATIVES THEREOF, EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. + +THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES, +INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. THIS SOFTWARE +IS PROVIDED ON AN "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE +NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR +MODIFICATIONS. + +GOVERNMENT USE: If you are acquiring this software on behalf of the +U.S. government, the Government shall have only "Restricted Rights" +in the software and related documentation as defined in the Federal +Acquisition Regulations (FARs) in Clause 52.227.19 (c) (2). If you +are acquiring the software on behalf of the Department of Defense, the +software shall be classified as "Commercial Computer Software" and the +Government shall have only "Restricted Rights" as defined in Clause +252.227-7014 (b) (3) of DFARs. Notwithstanding the foregoing, the +authors grant the U.S. Government and others acting in its behalf +permission to use and distribute the software in accordance with the +terms specified in this license. diff --git a/tcl8.6/doc/lindex.n b/tcl8.6/doc/lindex.n new file mode 100644 index 0000000..d5605bc --- /dev/null +++ b/tcl8.6/doc/lindex.n @@ -0,0 +1,125 @@ +'\" +'\" Copyright (c) 1993 The Regents of the University of California. +'\" Copyright (c) 1994-1996 Sun Microsystems, Inc. +'\" Copyright (c) 2001 by Kevin B. Kenny <kennykb@acm.org>. All rights reserved. +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH lindex n 8.4 Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +lindex \- Retrieve an element from a list +.SH SYNOPSIS +\fBlindex \fIlist ?index ...?\fR +.BE +.SH DESCRIPTION +.PP +The \fBlindex\fR command accepts a parameter, \fIlist\fR, which +it treats as a Tcl list. It also accepts zero or more \fIindices\fR into +the list. The indices may be presented either consecutively on the +command line, or grouped in a +Tcl list and presented as a single argument. +.PP +If no indices are presented, the command takes the form: +.PP +.CS +\fBlindex \fIlist\fR +.CE +.PP +or +.PP +.CS +\fBlindex \fIlist\fR {} +.CE +.PP +In this case, the return value of \fBlindex\fR is simply the value of the +\fIlist\fR parameter. +.PP +When presented with a single index, the \fBlindex\fR command +treats \fIlist\fR as a Tcl list and returns the +\fIindex\fR'th element from it (0 refers to the first element of the list). +In extracting the element, \fBlindex\fR observes the same rules +concerning braces and quotes and backslashes as the Tcl command +interpreter; however, variable +substitution and command substitution do not occur. +If \fIindex\fR is negative or greater than or equal to the number +of elements in \fIvalue\fR, then an empty +string is returned. +The interpretation of each simple \fIindex\fR value is the same as +for the command \fBstring index\fR, supporting simple index +arithmetic and indices relative to the end of the list. +.PP +If additional \fIindex\fR arguments are supplied, then each argument is +used in turn to select an element from the previous indexing operation, +allowing the script to select elements from sublists. The command, +.PP +.CS +\fBlindex\fR $a 1 2 3 +.CE +.PP +or +.PP +.CS +\fBlindex\fR $a {1 2 3} +.CE +.PP +is synonymous with +.PP +.CS +\fBlindex\fR [\fBlindex\fR [\fBlindex\fR $a 1] 2] 3 +.CE +.SH EXAMPLES +.PP +Lists can be indexed into from either end: +.PP +.CS +\fBlindex\fR {a b c} 0 + \fI\(-> a\fR +\fBlindex\fR {a b c} 2 + \fI\(-> c\fR +\fBlindex\fR {a b c} end + \fI\(-> c\fR +\fBlindex\fR {a b c} end-1 + \fI\(-> b\fR +.CE +.PP +Lists or sequences of indices allow selection into lists of lists: +.PP +.CS +\fBlindex\fR {a b c} + \fI\(-> a b c\fR +\fBlindex\fR {a b c} {} + \fI\(-> a b c\fR +\fBlindex\fR {{a b c} {d e f} {g h i}} 2 1 + \fI\(-> h\fR +\fBlindex\fR {{a b c} {d e f} {g h i}} {2 1} + \fI\(-> h\fR +\fBlindex\fR {{{a b} {c d}} {{e f} {g h}}} 1 1 0 + \fI\(-> g\fR +\fBlindex\fR {{{a b} {c d}} {{e f} {g h}}} {1 1 0} + \fI\(-> g\fR +.CE +.PP +List indices may also perform limited computation, adding or subtracting fixed +amounts from other indices: +.PP +.CS +set idx 1 +\fBlindex\fR {a b c d e f} $idx+2 + \fI\(-> d\fR +set idx 3 +\fBlindex\fR {a b c d e f} $idx+2 + \fI\(-> f\fR +.CE +.SH "SEE ALSO" +list(n), lappend(n), linsert(n), llength(n), lsearch(n), +lset(n), lsort(n), lrange(n), lreplace(n), +string(n) +.SH KEYWORDS +element, index, list +'\"Local Variables: +'\"mode: nroff +'\"End: diff --git a/tcl8.6/doc/linsert.n b/tcl8.6/doc/linsert.n new file mode 100644 index 0000000..91db726 --- /dev/null +++ b/tcl8.6/doc/linsert.n @@ -0,0 +1,55 @@ +'\" +'\" Copyright (c) 1993 The Regents of the University of California. +'\" Copyright (c) 1994-1996 Sun Microsystems, Inc. +'\" Copyright (c) 2001 Kevin B. Kenny <kennykb@acm.org>. All rights reserved. +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH linsert n 8.2 Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +linsert \- Insert elements into a list +.SH SYNOPSIS +\fBlinsert \fIlist index \fR?\fIelement element ...\fR? +.BE +.SH DESCRIPTION +.PP +This command produces a new list from \fIlist\fR by inserting all of the +\fIelement\fR arguments just before the \fIindex\fR'th element of +\fIlist\fR. Each \fIelement\fR argument will become a separate element of +the new list. If \fIindex\fR is less than or equal to zero, then the new +elements are inserted at the beginning of the list, and if \fIindex\fR is +greater or equal to the length of \fIlist\fR, it is as if it was \fBend\fR. +As with \fBstring index\fR, the \fIindex\fR value supports both simple index +arithmetic and end-relative indexing. +.PP +Subject to the restrictions that indices must refer to locations inside the +list and that the \fIelement\fRs will always be inserted in order, insertions +are done so that when \fIindex\fR is start-relative, the first \fIelement\fR +will be at that index in the resulting list, and when \fIindex\fR is +end-relative, the last \fIelement\fR will be at that index in the resulting +list. +.SH EXAMPLE +.PP +Putting some values into a list, first indexing from the start and +then indexing from the end, and then chaining them together: +.PP +.CS +set oldList {the fox jumps over the dog} +set midList [\fBlinsert\fR $oldList 1 quick] +set newList [\fBlinsert\fR $midList end-1 lazy] +# The old lists still exist though... +set newerList [\fBlinsert\fR [\fBlinsert\fR $oldList end-1 quick] 1 lazy] +.CE +.SH "SEE ALSO" +list(n), lappend(n), lindex(n), llength(n), lsearch(n), +lset(n), lsort(n), lrange(n), lreplace(n), +string(n) +.SH KEYWORDS +element, insert, list +'\" Local Variables: +'\" mode: nroff +'\" End: diff --git a/tcl8.6/doc/list.n b/tcl8.6/doc/list.n new file mode 100644 index 0000000..c2797f3 --- /dev/null +++ b/tcl8.6/doc/list.n @@ -0,0 +1,56 @@ +'\" +'\" Copyright (c) 1993 The Regents of the University of California. +'\" Copyright (c) 1994-1996 Sun Microsystems, Inc. +'\" Copyright (c) 2001 Kevin B. Kenny <kennykb@acm.org>. All rights reserved. +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH list n "" Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +list \- Create a list +.SH SYNOPSIS +\fBlist \fR?\fIarg arg ...\fR? +.BE +.SH DESCRIPTION +.PP +This command returns a list comprised of all the \fIarg\fRs, +or an empty string if no \fIarg\fRs are specified. +Braces and backslashes get added as necessary, so that the \fBlindex\fR command +may be used on the result to re-extract the original arguments, and also +so that \fBeval\fR may be used to execute the resulting list, with +\fIarg1\fR comprising the command's name and the other \fIarg\fRs comprising +its arguments. \fBList\fR produces slightly different results than +\fBconcat\fR: \fBconcat\fR removes one level of grouping before forming +the list, while \fBlist\fR works directly from the original arguments. +.SH EXAMPLE +.PP +The command +.PP +.CS +\fBlist\fR a b "c d e " " f {g h}" +.CE +.PP +will return +.PP +.CS +\fBa b {c d e } { f {g h}}\fR +.CE +.PP +while \fBconcat\fR with the same arguments will return +.PP +.CS +\fBa b c d e f {g h}\fR +.CE +.SH "SEE ALSO" +lappend(n), lindex(n), linsert(n), llength(n), lrange(n), +lrepeat(n), +lreplace(n), lsearch(n), lset(n), lsort(n) +.SH KEYWORDS +element, list, quoting +'\"Local Variables: +'\"mode: nroff +'\"End: diff --git a/tcl8.6/doc/llength.n b/tcl8.6/doc/llength.n new file mode 100644 index 0000000..79f93c0 --- /dev/null +++ b/tcl8.6/doc/llength.n @@ -0,0 +1,55 @@ +'\" +'\" Copyright (c) 1993 The Regents of the University of California. +'\" Copyright (c) 1994-1996 Sun Microsystems, Inc. +'\" Copyright (c) 2001 Kevin B. Kenny <kennykb@acm.org>. All rights reserved. +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH llength n "" Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +llength \- Count the number of elements in a list +.SH SYNOPSIS +\fBllength \fIlist\fR +.BE +.SH DESCRIPTION +.PP +Treats \fIlist\fR as a list and returns a decimal string giving +the number of elements in it. +.SH EXAMPLES +.PP +The result is the number of elements: +.PP +.CS +% \fBllength\fR {a b c d e} +5 +% \fBllength\fR {a b c} +3 +% \fBllength\fR {} +0 +.CE +.PP +Elements are not guaranteed to be exactly words in a dictionary sense +of course, especially when quoting is used: +.PP +.CS +% \fBllength\fR {a b {c d} e} +4 +% \fBllength\fR {a b { } c d e} +6 +.CE +.PP +An empty list is not necessarily an empty string: +.PP +.CS +% set var { }; puts "[string length $var],[\fBllength\fR $var]" +1,0 +.CE +.SH "SEE ALSO" +list(n), lappend(n), lindex(n), linsert(n), lsearch(n), +lset(n), lsort(n), lrange(n), lreplace(n) +.SH KEYWORDS +element, list, length diff --git a/tcl8.6/doc/lmap.n b/tcl8.6/doc/lmap.n new file mode 100644 index 0000000..1a7858d --- /dev/null +++ b/tcl8.6/doc/lmap.n @@ -0,0 +1,85 @@ +'\" +'\" Copyright (c) 2012 Trevor Davel +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH lmap n "" Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +lmap \- Iterate over all elements in one or more lists and collect results +.SH SYNOPSIS +\fBlmap \fIvarname list body\fR +.br +\fBlmap \fIvarlist1 list1\fR ?\fIvarlist2 list2 ...\fR? \fIbody\fR +.BE +.SH DESCRIPTION +.PP +The \fBlmap\fR command implements a loop where the loop variable(s) take on +values from one or more lists, and the loop returns a list of results +collected from each iteration. +.PP +In the simplest case there is one loop variable, \fIvarname\fR, and one list, +\fIlist\fR, that is a list of values to assign to \fIvarname\fR. The +\fIbody\fR argument is a Tcl script. For each element of \fIlist\fR (in order +from first to last), \fBlmap\fR assigns the contents of the element to +\fIvarname\fR as if the \fBlindex\fR command had been used to extract the +element, then calls the Tcl interpreter to execute \fIbody\fR. If execution of +the body completes normally then the result of the body is appended to an +accumulator list. \fBlmap\fR returns the accumulator list. +.PP +In the general case there can be more than one value list (e.g., \fIlist1\fR +and \fIlist2\fR), and each value list can be associated with a list of loop +variables (e.g., \fIvarlist1\fR and \fIvarlist2\fR). During each iteration of +the loop the variables of each \fIvarlist\fR are assigned consecutive values +from the corresponding \fIlist\fR. Values in each \fIlist\fR are used in order +from first to last, and each value is used exactly once. The total number of +loop iterations is large enough to use up all the values from all the value +lists. If a value list does not contain enough elements for each of its loop +variables in each iteration, empty values are used for the missing elements. +.PP +The \fBbreak\fR and \fBcontinue\fR statements may be invoked inside +\fIbody\fR, with the same effect as in the \fBfor\fR and \fBforeach\fR +commands. In these cases the body does not complete normally and the result is +not appended to the accumulator list. +.SH EXAMPLES +.PP +Zip lists together: +.PP +.CS +set list1 {a b c d} +set list2 {1 2 3 4} +set zipped [\fBlmap\fR a $list1 b $list2 {list $a $b}] +# The value of zipped is "{a 1} {b 2} {c 3} {d 4}" +.CE +.PP +Filter a list to remove odd values: +.PP +.CS +set values {1 2 3 4 5 6 7 8} +proc isEven {n} {expr {($n % 2) == 0}} +set goodOnes [\fBlmap\fR x $values {expr { + [isEven $x] ? $x : [continue] +}}] +# The value of goodOnes is "2 4 6 8" +.CE +.PP +Take a prefix from a list based on the contents of the list: +.PP +.CS +set values {8 7 6 5 4 3 2 1} +proc isGood {counter} {expr {$n > 3}} +set prefix [\fBlmap\fR x $values {expr { + [isGood $x] ? $x : [break] +}}] +# The value of prefix is "8 7 6 5 4" +.CE +.SH "SEE ALSO" +break(n), continue(n), for(n), foreach(n), while(n) +.SH KEYWORDS +foreach, iteration, list, loop, map +'\" Local Variables: +'\" mode: nroff +'\" End: diff --git a/tcl8.6/doc/load.n b/tcl8.6/doc/load.n new file mode 100644 index 0000000..2ab8f2e --- /dev/null +++ b/tcl8.6/doc/load.n @@ -0,0 +1,196 @@ +'\" +'\" Copyright (c) 1995-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. +'\" +.TH load n 7.5 Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +load \- Load machine code and initialize new commands +.SH SYNOPSIS +\fBload\fR ?\fB\-global\fR? ?\fB\-lazy\fR? ?\fB\-\-\fR? \fIfileName\fR +.br +\fBload\fR ?\fB\-global\fR? ?\fB\-lazy\fR? ?\fB\-\-\fR? \fIfileName packageName\fR +.br +\fBload\fR ?\fB\-global\fR? ?\fB\-lazy\fR? ?\fB\-\-\fR? \fIfileName packageName interp\fR +.BE +.SH DESCRIPTION +.PP +This command loads binary code from a file into the +application's address space and calls an initialization procedure +in the package to incorporate it into an interpreter. \fIfileName\fR +is the name of the file containing the code; its exact form varies +from system to system but on most systems it is a shared library, +such as a \fB.so\fR file under Solaris or a DLL under Windows. +\fIpackageName\fR is the name of the package, and is used to +compute the name of an initialization procedure. +\fIinterp\fR is the path name of the interpreter into which to load +the package (see the \fBinterp\fR manual entry for details); +if \fIinterp\fR is omitted, it defaults to the +interpreter in which the \fBload\fR command was invoked. +.PP +Once the file has been loaded into the application's address space, +one of two initialization procedures will be invoked in the new code. +Typically the initialization procedure will add new commands to a +Tcl interpreter. +The name of the initialization procedure is determined by +\fIpackageName\fR and whether or not the target interpreter +is a safe one. For normal interpreters the name of the initialization +procedure will have the form \fIpkg\fB_Init\fR, where \fIpkg\fR +is the same as \fIpackageName\fR except that the first letter is +converted to upper case and all other letters +are converted to lower case. For example, if \fIpackageName\fR is +\fBfoo\fR or \fBFOo\fR, the initialization procedure's name will +be \fBFoo_Init\fR. +.PP +If the target interpreter is a safe interpreter, then the name +of the initialization procedure will be \fIpkg\fB_SafeInit\fR +instead of \fIpkg\fB_Init\fR. +The \fIpkg\fB_SafeInit\fR function should be written carefully, so that it +initializes the safe interpreter only with partial functionality provided +by the package that is safe for use by untrusted code. For more information +on Safe\-Tcl, see the \fBsafe\fR manual entry. +.PP +The initialization procedure must match the following prototype: +.PP +.CS +typedef int \fBTcl_PackageInitProc\fR( + Tcl_Interp *\fIinterp\fR); +.CE +.PP +The \fIinterp\fR argument identifies the interpreter in which the +package is to be loaded. The initialization procedure must return +\fBTCL_OK\fR or \fBTCL_ERROR\fR to indicate whether or not it completed +successfully; in the event of an error it should set the interpreter's result +to point to an error message. The result of the \fBload\fR command +will be the result returned by the initialization procedure. +.PP +The actual loading of a file will only be done once for each \fIfileName\fR +in an application. If a given \fIfileName\fR is loaded into multiple +interpreters, then the first \fBload\fR will load the code and +call the initialization procedure; subsequent \fBload\fRs will +call the initialization procedure without loading the code again. +For Tcl versions lower than 8.5, it is not possible to unload or reload a +package. From version 8.5 however, the \fBunload\fR command allows the unloading +of libraries loaded with \fBload\fR, for libraries that are aware of the +Tcl's unloading mechanism. +.PP +The \fBload\fR command also supports packages that are statically +linked with the application, if those packages have been registered +by calling the \fBTcl_StaticPackage\fR procedure. +If \fIfileName\fR is an empty string, then \fIpackageName\fR must +be specified. +.PP +If \fIpackageName\fR is omitted or specified as an empty string, +Tcl tries to guess the name of the package. +This may be done differently on different platforms. +The default guess, which is used on most UNIX platforms, is to +take the last element of \fIfileName\fR, strip off the first +three characters if they are \fBlib\fR, and use any following +alphabetic and underline characters as the module name. +For example, the command \fBload libxyz4.2.so\fR uses the module +name \fBxyz\fR and the command \fBload bin/last.so {}\fR uses the +module name \fBlast\fR. +.PP +If \fIfileName\fR is an empty string, then \fIpackageName\fR must +be specified. +The \fBload\fR command first searches for a statically loaded package +(one that has been registered by calling the \fBTcl_StaticPackage\fR +procedure) by that name; if one is found, it is used. +Otherwise, the \fBload\fR command searches for a dynamically loaded +package by that name, and uses it if it is found. If several +different files have been \fBload\fRed with different versions of +the package, Tcl picks the file that was loaded first. +.PP +If \fB\-global\fR is specified preceding the filename, all symbols +found in the shared library are exported for global use by other +libraries. The option \fB\-lazy\fR delays the actual loading of +symbols until their first actual use. The options may be abbreviated. +The option \fB\-\-\fR indicates the end of the options, and should +be used if you wish to use a filename which starts with \fB\-\fR +and you provide a packageName to the \fBload\fR command. +.PP +On platforms which do not support the \fB\-global\fR or \fB\-lazy\fR +options, the options still exist but have no effect. Note that use +of the \fB\-global\fR or \fB\-lazy\fR option may lead to crashes +in your application later (in case of symbol conflicts resp. missing +symbols), which cannot be detected during the \fBload\fR. So, only +use this when you know what you are doing, you will not get a nice +error message when something is wrong with the loaded library. +.SH "PORTABILITY ISSUES" +.TP +\fBWindows\fR\0\0\0\0\0 +. +When a load fails with +.QW "library not found" +error, it is also possible +that a dependent library was not found. To see the dependent libraries, +type +.QW "dumpbin -imports <dllname>" +in a DOS console to see what the library must import. +When loading a DLL in the current directory, Windows will ignore +.QW ./ +as a path specifier and use a search heuristic to find the DLL instead. +To avoid this, load the DLL with: +.RS +.PP +.CS +\fBload\fR [file join [pwd] mylib.DLL] +.CE +.RE +.SH BUGS +.PP +If the same file is \fBload\fRed by different \fIfileName\fRs, it will +be loaded into the process's address space multiple times. The +behavior of this varies from system to system (some systems may +detect the redundant loads, others may not). +.SH EXAMPLE +.PP +The following is a minimal extension: +.PP +.CS +#include <tcl.h> +#include <stdio.h> +static int fooCmd(ClientData clientData, + Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { + printf("called with %d arguments\en", objc); + return TCL_OK; +} +int Foo_Init(Tcl_Interp *interp) { + if (Tcl_InitStubs(interp, "8.1", 0) == NULL) { + return TCL_ERROR; + } + printf("creating foo command"); + Tcl_CreateObjCommand(interp, "foo", fooCmd, NULL, NULL); + return TCL_OK; +} +.CE +.PP +When built into a shared/dynamic library with a suitable name +(e.g. \fBfoo.dll\fR on Windows, \fBlibfoo.so\fR on Solaris and Linux) +it can then be loaded into Tcl with the following: +.PP +.CS +# Load the extension +switch $tcl_platform(platform) { + windows { + \fBload\fR [file join [pwd] foo.dll] + } + unix { + \fBload\fR [file join [pwd] libfoo[info sharedlibextension]] + } +} + +# Now execute the command defined by the extension +foo +.CE +.SH "SEE ALSO" +info sharedlibextension, package(n), Tcl_StaticPackage(3), safe(n) +.SH KEYWORDS +binary code, dynamic library, load, safe interpreter, shared library +'\"Local Variables: +'\"mode: nroff +'\"End: diff --git a/tcl8.6/doc/lrange.n b/tcl8.6/doc/lrange.n new file mode 100644 index 0000000..ffa6dba --- /dev/null +++ b/tcl8.6/doc/lrange.n @@ -0,0 +1,78 @@ +'\" +'\" Copyright (c) 1993 The Regents of the University of California. +'\" Copyright (c) 1994-1996 Sun Microsystems, Inc. +'\" Copyright (c) 2001 Kevin B. Kenny <kennykb@acm.org>. All rights reserved. +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH lrange n 7.4 Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +lrange \- Return one or more adjacent elements from a list +.SH SYNOPSIS +\fBlrange \fIlist first last\fR +.BE +.SH DESCRIPTION +.PP +\fIList\fR must be a valid Tcl list. This command will +return a new list consisting of elements +\fIfirst\fR through \fIlast\fR, inclusive. +The index values \fIfirst\fR and \fIlast\fR are interpreted +the same as index values for the command \fBstring index\fR, +supporting simple index arithmetic and indices relative to the +end of the list. +If \fIfirst\fR is less than zero, it is treated as if it were zero. +If \fIlast\fR is greater than or equal to the number of elements +in the list, then it is treated as if it were \fBend\fR. +If \fIfirst\fR is greater than \fIlast\fR then an empty string +is returned. +Note: +.QW "\fBlrange \fIlist first first\fR" +does not always produce the same result as +.QW "\fBlindex \fIlist first\fR" +(although it often does for simple fields that are not enclosed in +braces); it does, however, produce exactly the same results as +.QW "\fBlist [lindex \fIlist first\fB]\fR" +.SH EXAMPLES +.PP +Selecting the first two elements: +.PP +.CS +% \fBlrange\fR {a b c d e} 0 1 +a b +.CE +.PP +Selecting the last three elements: +.PP +.CS +% \fBlrange\fR {a b c d e} end-2 end +c d e +.CE +.PP +Selecting everything except the first and last element: +.PP +.CS +% \fBlrange\fR {a b c d e} 1 end-1 +b c d +.CE +.PP +Selecting a single element with \fBlrange\fR is not the same as doing +so with \fBlindex\fR: +.PP +.CS +% set var {some {elements to} select} +some {elements to} select +% lindex $var 1 +elements to +% \fBlrange\fR $var 1 1 +{elements to} +.CE +.SH "SEE ALSO" +list(n), lappend(n), lindex(n), linsert(n), llength(n), lsearch(n), +lset(n), lreplace(n), lsort(n), +string(n) +.SH KEYWORDS +element, list, range, sublist diff --git a/tcl8.6/doc/lrepeat.n b/tcl8.6/doc/lrepeat.n new file mode 100644 index 0000000..466339d --- /dev/null +++ b/tcl8.6/doc/lrepeat.n @@ -0,0 +1,38 @@ +'\" +'\" Copyright (c) 2003 by Simon Geard. All rights reserved. +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH lrepeat n 8.5 Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +lrepeat \- Build a list by repeating elements +.SH SYNOPSIS +\fBlrepeat \fIcount \fR?\fIelement ...\fR? +.BE +.SH DESCRIPTION +.PP +The \fBlrepeat\fR command creates a list of size \fIcount * number of +elements\fR by repeating \fIcount\fR times the sequence of elements +\fIelement ...\fR. \fIcount\fR must be a non-negative integer, +\fIelement\fR can be any Tcl value. Note that \fBlrepeat 1 element ...\fR +is identical to \fBlist element ...\fR. +.SH EXAMPLES +.CS +\fBlrepeat\fR 3 a + \fI\(-> a a a\fR +\fBlrepeat\fR 3 [\fBlrepeat\fR 3 0] + \fI\(-> {0 0 0} {0 0 0} {0 0 0}\fR +\fBlrepeat\fR 3 a b c + \fI\(-> a b c a b c a b c\fR +\fBlrepeat\fR 3 [\fBlrepeat\fR 2 a] b c + \fI\(-> {a a} b c {a a} b c {a a} b c\fR +.CE +.SH "SEE ALSO" +list(n), lappend(n), linsert(n), llength(n), lset(n) + +.SH KEYWORDS +element, index, list diff --git a/tcl8.6/doc/lreplace.n b/tcl8.6/doc/lreplace.n new file mode 100644 index 0000000..d19f0cd --- /dev/null +++ b/tcl8.6/doc/lreplace.n @@ -0,0 +1,86 @@ +'\" +'\" Copyright (c) 1993 The Regents of the University of California. +'\" Copyright (c) 1994-1996 Sun Microsystems, Inc. +'\" Copyright (c) 2001 Kevin B. Kenny <kennykb@acm.org>. All rights reserved. +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH lreplace n 7.4 Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +lreplace \- Replace elements in a list with new elements +.SH SYNOPSIS +\fBlreplace \fIlist first last \fR?\fIelement element ...\fR? +.BE +.SH DESCRIPTION +.PP +\fBlreplace\fR returns a new list formed by replacing one or more elements of +\fIlist\fR with the \fIelement\fR arguments. +\fIfirst\fR and \fIlast\fR are index values specifying the first and +last elements of the range to replace. +The index values \fIfirst\fR and \fIlast\fR are interpreted +the same as index values for the command \fBstring index\fR, +supporting simple index arithmetic and indices relative to the +end of the list. +0 refers to the first element of the +list, and \fBend\fR refers to the last element of the list. +If \fIlist\fR is empty, then \fIfirst\fR and \fIlast\fR are ignored. +.PP +If \fIfirst\fR is less than zero, it is considered to refer to before the +first element of the list. For non-empty lists, the element indicated +by \fIfirst\fR must exist or \fIfirst\fR must indicate before the +start of the list. +.PP +If \fIlast\fR is less than \fIfirst\fR, then any specified elements +will be inserted into the list before the point specified by \fIfirst\fR +with no elements being deleted. +.PP +The \fIelement\fR arguments specify zero or more new arguments to +be added to the list in place of those that were deleted. +Each \fIelement\fR argument will become a separate element of +the list. If no \fIelement\fR arguments are specified, then the elements +between \fIfirst\fR and \fIlast\fR are simply deleted. If \fIlist\fR +is empty, any \fIelement\fR arguments are added to the end of the list. +.SH EXAMPLES +.PP +Replacing an element of a list with another: +.PP +.CS +% \fBlreplace\fR {a b c d e} 1 1 foo +a foo c d e +.CE +.PP +Replacing two elements of a list with three: +.PP +.CS +% \fBlreplace\fR {a b c d e} 1 2 three more elements +a three more elements d e +.CE +.PP +Deleting the last element from a list in a variable: +.PP +.CS +% set var {a b c d e} +a b c d e +% set var [\fBlreplace\fR $var end end] +a b c d +.CE +.PP +A procedure to delete a given element from a list: +.PP +.CS +proc lremove {listVariable value} { + upvar 1 $listVariable var + set idx [lsearch -exact $var $value] + set var [\fBlreplace\fR $var $idx $idx] +} +.CE +.SH "SEE ALSO" +list(n), lappend(n), lindex(n), linsert(n), llength(n), lsearch(n), +lset(n), lrange(n), lsort(n), +string(n) +.SH KEYWORDS +element, list, replace diff --git a/tcl8.6/doc/lreverse.n b/tcl8.6/doc/lreverse.n new file mode 100644 index 0000000..51a9e57 --- /dev/null +++ b/tcl8.6/doc/lreverse.n @@ -0,0 +1,34 @@ +'\" +'\" Copyright (c) 2006 by Donal K. Fellows. All rights reserved. +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH lreverse n 8.5 Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +lreverse \- Reverse the order of a list +.SH SYNOPSIS +\fBlreverse \fIlist\fR +.BE +.SH DESCRIPTION +.PP +The \fBlreverse\fR command returns a list that has the same elements as its +input list, \fIlist\fR, except with the elements in the reverse order. +.SH EXAMPLES +.CS +\fBlreverse\fR {a a b c} + \fI\(-> c b a a\fR +\fBlreverse\fR {a b {c d} e f} + \fI\(-> f e {c d} b a\fR +.CE +.SH "SEE ALSO" +list(n), lsearch(n), lsort(n) + +.SH KEYWORDS +element, list, reverse +'\" Local Variables: +'\" mode: nroff +'\" End: diff --git a/tcl8.6/doc/lsearch.n b/tcl8.6/doc/lsearch.n new file mode 100644 index 0000000..c2644b8 --- /dev/null +++ b/tcl8.6/doc/lsearch.n @@ -0,0 +1,220 @@ +'\" +'\" Copyright (c) 1993 The Regents of the University of California. +'\" Copyright (c) 1994-1996 Sun Microsystems, Inc. +'\" Copyright (c) 2001 Kevin B. Kenny <kennykb@acm.org>. All rights reserved. +'\" Copyright (c) 2003-2004 Donal K. Fellows. +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH lsearch n 8.6 Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +lsearch \- See if a list contains a particular element +.SH SYNOPSIS +\fBlsearch \fR?\fIoptions\fR? \fIlist pattern\fR +.BE +.SH DESCRIPTION +.PP +This command searches the elements of \fIlist\fR to see if one +of them matches \fIpattern\fR. If so, the command returns the index +of the first matching element +(unless the options \fB\-all\fR or \fB\-inline\fR are specified.) +If not, the command returns \fB\-1\fR. The \fIoption\fR arguments +indicates how the elements of the list are to be matched against +\fIpattern\fR and must have one of the values below: +.SS "MATCHING STYLE OPTIONS" +.PP +If all matching style options are omitted, the default matching style +is \fB\-glob\fR. If more than one matching style is specified, the +last matching style given takes precedence. +.TP +\fB\-exact\fR +. +\fIPattern\fR is a literal string that is compared for exact equality +against each list element. +.TP +\fB\-glob\fR +. +\fIPattern\fR is a glob-style pattern which is matched against each list +element using the same rules as the \fBstring match\fR command. +.TP +\fB\-regexp\fR +. +\fIPattern\fR is treated as a regular expression and matched against +each list element using the rules described in the \fBre_syntax\fR +reference page. +.TP +\fB\-sorted\fR +. +The list elements are in sorted order. If this option is specified, +\fBlsearch\fR will use a more efficient searching algorithm to search +\fIlist\fR. If no other options are specified, \fIlist\fR is assumed +to be sorted in increasing order, and to contain ASCII strings. This +option is mutually exclusive with \fB\-glob\fR and \fB\-regexp\fR, and +is treated exactly like \fB\-exact\fR when either \fB\-all\fR or +\fB\-not\fR are specified. +.SS "GENERAL MODIFIER OPTIONS" +.PP +These options may be given with all matching styles. +.TP +\fB\-all\fR +. +Changes the result to be the list of all matching indices (or all matching +values if \fB\-inline\fR is specified as well.) If indices are returned, the +indices will be in numeric order. If values are returned, the order of the +values will be the order of those values within the input \fIlist\fR. +.TP +\fB\-inline\fR +. +The matching value is returned instead of its index (or an empty +string if no value matches.) If \fB\-all\fR is also specified, then +the result of the command is the list of all values that matched. +.TP +\fB\-not\fR +. +This negates the sense of the match, returning the index of the first +non-matching value in the list. +.TP +\fB\-start\fR\0\fIindex\fR +. +The list is searched starting at position \fIindex\fR. +The interpretation of the \fIindex\fR value is the same as +for the command \fBstring index\fR, supporting simple index +arithmetic and indices relative to the end of the list. +.SS "CONTENTS DESCRIPTION OPTIONS" +.PP +These options describe how to interpret the items in the list being +searched. They are only meaningful when used with the \fB\-exact\fR +and \fB\-sorted\fR options. If more than one is specified, the last +one takes precedence. The default is \fB\-ascii\fR. +.TP +\fB\-ascii\fR +. +The list elements are to be examined as Unicode strings (the name is +for backward-compatibility reasons.) +.TP +\fB\-dictionary\fR +. +The list elements are to be compared using dictionary-style +comparisons (see \fBlsort\fR for a fuller description). Note that this +only makes a meaningful difference from the \fB\-ascii\fR option when +the \fB\-sorted\fR option is given, because values are only +dictionary-equal when exactly equal. +.TP +\fB\-integer\fR +. +The list elements are to be compared as integers. +.TP +\fB\-nocase\fR +. +Causes comparisons to be handled in a case-insensitive manner. Has no +effect if combined with the \fB\-dictionary\fR, \fB\-integer\fR, or +\fB\-real\fR options. +.TP +\fB\-real\fR +. +The list elements are to be compared as floating-point values. +.SS "SORTED LIST OPTIONS" +.PP +These options (only meaningful with the \fB\-sorted\fR option) specify +how the list is sorted. If more than one is given, the last one takes +precedence. The default option is \fB\-increasing\fR. +.TP +\fB\-decreasing\fR +. +The list elements are sorted in decreasing order. This option is only +meaningful when used with \fB\-sorted\fR. +.TP +\fB\-increasing\fR +. +The list elements are sorted in increasing order. This option is only +meaningful when used with \fB\-sorted\fR. +.TP +\fB\-bisect\fR +.VS 8.6 +Inexact search when the list elements are in sorted order. For an increasing +list the last index where the element is less than or equal to the pattern +is returned. For a decreasing list the last index where the element is greater +than or equal to the pattern is returned. If the pattern is before the first +element or the list is empty, -1 is returned. +This option implies \fB\-sorted\fR and cannot be used with either \fB\-all\fR +or \fB\-not\fR. +.VE 8.6 +.SS "NESTED LIST OPTIONS" +.PP +These options are used to search lists of lists. They may be used +with any other options. +.TP +\fB\-index\fR\0\fIindexList\fR +. +This option is designed for use when searching within nested lists. +The \fIindexList\fR argument gives a path of indices (much as might be +used with the \fBlindex\fR or \fBlset\fR commands) within each element +to allow the location of the term being matched against. +.TP +\fB\-subindices\fR +. +If this option is given, the index result from this command (or every +index result when \fB\-all\fR is also specified) will be a complete +path (suitable for use with \fBlindex\fR or \fBlset\fR) within the +overall list to the term found. This option has no effect unless the +\fB\-index\fR is also specified, and is just a convenience short-cut. +.SH EXAMPLES +.PP +Basic searching: +.PP +.CS +\fBlsearch\fR {a b c d e} c + \fI\(-> 2\fR +\fBlsearch\fR -all {a b c a b c} c + \fI\(-> 2 5\fR +.CE +.PP +Using \fBlsearch\fR to filter lists: +.PP +.CS +\fBlsearch\fR -inline {a20 b35 c47} b* + \fI\(-> b35\fR +\fBlsearch\fR -inline -not {a20 b35 c47} b* + \fI\(-> a20\fR +\fBlsearch\fR -all -inline -not {a20 b35 c47} b* + \fI\(-> a20 c47\fR +\fBlsearch\fR -all -not {a20 b35 c47} b* + \fI\(-> 0 2\fR +.CE +.PP +This can even do a +.QW set-like +removal operation: +.PP +.CS +\fBlsearch\fR -all -inline -not -exact {a b c a d e a f g a} a + \fI\(-> b c d e f g\fR +.CE +.PP +Searching may start part-way through the list: +.PP +.CS +\fBlsearch\fR -start 3 {a b c a b c} c + \fI\(-> 5\fR +.CE +.PP +It is also possible to search inside elements: +.PP +.CS +\fBlsearch\fR -index 1 -all -inline {{a abc} {b bcd} {c cde}} *bc* + \fI\(-> {a abc} {b bcd}\fR +.CE +.SH "SEE ALSO" +foreach(n), list(n), lappend(n), lindex(n), linsert(n), llength(n), +lset(n), lsort(n), lrange(n), lreplace(n), +string(n) +.SH KEYWORDS +binary search, linear search, +list, match, pattern, regular expression, search, string +'\" Local Variables: +'\" mode: nroff +'\" End: diff --git a/tcl8.6/doc/lset.n b/tcl8.6/doc/lset.n new file mode 100644 index 0000000..e425274 --- /dev/null +++ b/tcl8.6/doc/lset.n @@ -0,0 +1,146 @@ +'\" +'\" Copyright (c) 2001 by Kevin B. Kenny <kennykb@acm.org>. All rights reserved. +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH lset n 8.4 Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +lset \- Change an element in a list +.SH SYNOPSIS +\fBlset \fIvarName ?index ...? newValue\fR +.BE +.SH DESCRIPTION +.PP +The \fBlset\fR command accepts a parameter, \fIvarName\fR, which +it interprets as the name of a variable containing a Tcl list. +It also accepts zero or more \fIindices\fR into +the list. The indices may be presented either consecutively on the +command line, or grouped in a +Tcl list and presented as a single argument. +Finally, it accepts a new value for an element of \fIvarName\fR. +.PP +If no indices are presented, the command takes the form: +.PP +.CS +\fBlset\fR varName newValue +.CE +.PP +or +.PP +.CS +\fBlset\fR varName {} newValue +.CE +.PP +In this case, \fInewValue\fR replaces the old value of the variable +\fIvarName\fR. +.PP +When presented with a single index, the \fBlset\fR command +treats the content of the \fIvarName\fR variable as a Tcl list. +It addresses the \fIindex\fR'th element in it +(0 refers to the first element of the list). +When interpreting the list, \fBlset\fR observes the same rules +concerning braces and quotes and backslashes as the Tcl command +interpreter; however, variable +substitution and command substitution do not occur. +The command constructs a new list in which the designated element is +replaced with \fInewValue\fR. This new list is stored in the +variable \fIvarName\fR, and is also the return value from the \fBlset\fR +command. +.PP +If \fIindex\fR is negative or greater than the number +of elements in \fI$varName\fR, then an error occurs. +.PP +If \fIindex\fR is equal to the number of elements in \fI$varName\fR, +then the given element is appended to the list. +.PP +The interpretation of each simple \fIindex\fR value is the same as +for the command \fBstring index\fR, supporting simple index +arithmetic and indices relative to the end of the list. +.PP +If additional \fIindex\fR arguments are supplied, then each argument is +used in turn to address an element within a sublist designated +by the previous indexing operation, +allowing the script to alter elements in sublists (or append elements +to sublists). The command, +.PP +.CS +\fBlset\fR a 1 2 newValue +.CE +.PP +or +.PP +.CS +\fBlset\fR a {1 2} newValue +.CE +.PP +replaces element 2 of sublist 1 with \fInewValue\fR. +.PP +The integer appearing in each \fIindex\fR argument must be greater +than or equal to zero. The integer appearing in each \fIindex\fR +argument must be less than or equal to the length of the corresponding +list. In other words, the \fBlset\fR command can change the size +of a list only by appending an element (setting the one after the current +end). If an index is outside the permitted range, an error is reported. +.SH EXAMPLES +.PP +In each of these examples, the initial value of \fIx\fR is: +.PP +.CS +set x [list [list a b c] [list d e f] [list g h i]] + \fI\(-> {a b c} {d e f} {g h i}\fR +.CE +.PP +The indicated return value also becomes the new value of \fIx\fR +(except in the last case, which is an error which leaves the value of +\fIx\fR unchanged.) +.PP +.CS +\fBlset\fR x {j k l} + \fI\(-> j k l\fR +\fBlset\fR x {} {j k l} + \fI\(-> j k l\fR +\fBlset\fR x 0 j + \fI\(-> j {d e f} {g h i}\fR +\fBlset\fR x 2 j + \fI\(-> {a b c} {d e f} j\fR +\fBlset\fR x end j + \fI\(-> {a b c} {d e f} j\fR +\fBlset\fR x end-1 j + \fI\(-> {a b c} j {g h i}\fR +\fBlset\fR x 2 1 j + \fI\(-> {a b c} {d e f} {g j i}\fR +\fBlset\fR x {2 1} j + \fI\(-> {a b c} {d e f} {g j i}\fR +\fBlset\fR x {2 3} j + \fI\(-> list index out of range\fR +.CE +.PP +In the following examples, the initial value of \fIx\fR is: +.PP +.CS +set x [list [list [list a b] [list c d]] \e + [list [list e f] [list g h]]] + \fI\(-> {{a b} {c d}} {{e f} {g h}}\fR +.CE +.PP +The indicated return value also becomes the new value of \fIx\fR. +.PP +.CS +\fBlset\fR x 1 1 0 j + \fI\(-> {{a b} {c d}} {{e f} {j h}}\fR +\fBlset\fR x {1 1 0} j + \fI\(-> {{a b} {c d}} {{e f} {j h}}\fR +.CE +.SH "SEE ALSO" +list(n), lappend(n), lindex(n), linsert(n), llength(n), lsearch(n), +lsort(n), lrange(n), lreplace(n), +string(n) +.SH KEYWORDS +element, index, list, replace, set +'\"Local Variables: +'\"mode: nroff +'\"End: diff --git a/tcl8.6/doc/lsort.n b/tcl8.6/doc/lsort.n new file mode 100644 index 0000000..c3245b2 --- /dev/null +++ b/tcl8.6/doc/lsort.n @@ -0,0 +1,275 @@ +'\" +'\" Copyright (c) 1993 The Regents of the University of California. +'\" Copyright (c) 1994-1996 Sun Microsystems, Inc. +'\" Copyright (c) 1999 Scriptics Corporation +'\" Copyright (c) 2001 Kevin B. Kenny <kennykb@acm.org>. All rights reserved. +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH lsort n 8.5 Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +lsort \- Sort the elements of a list +.SH SYNOPSIS +\fBlsort \fR?\fIoptions\fR? \fIlist\fR +.BE +.SH DESCRIPTION +.PP +This command sorts the elements of \fIlist\fR, returning a new +list in sorted order. The implementation of the \fBlsort\fR command +uses the merge\-sort algorithm which is a stable sort that has O(n log +n) performance characteristics. +.PP +By default ASCII sorting is used with the result returned in +increasing order. However, any of the following options may be +specified before \fIlist\fR to control the sorting process (unique +abbreviations are accepted): +.TP +\fB\-ascii\fR +. +Use string comparison with Unicode code-point collation order (the +name is for backward-compatibility reasons.) This is the default. +.TP +\fB\-dictionary\fR +. +Use dictionary-style comparison. This is the same as \fB\-ascii\fR +except (a) case is ignored except as a tie-breaker and (b) if two +strings contain embedded numbers, the numbers compare as integers, +not characters. For example, in \fB\-dictionary\fR mode, \fBbigBoy\fR +sorts between \fBbigbang\fR and \fBbigboy\fR, and \fBx10y\fR +sorts between \fBx9y\fR and \fBx11y\fR. Overrides the \fB\-nocase\fR +option. +.TP +\fB\-integer\fR +. +Convert list elements to integers and use integer comparison. +.TP +\fB\-real\fR +. +Convert list elements to floating-point values and use floating comparison. +.TP +\fB\-command\0\fIcommand\fR +. +Use \fIcommand\fR as a comparison command. +To compare two elements, evaluate a Tcl script consisting of +\fIcommand\fR with the two elements appended as additional +arguments. The script should return an integer less than, +equal to, or greater than zero if the first element is to +be considered less than, equal to, or greater than the second, +respectively. +.TP +\fB\-increasing\fR +. +Sort the list in increasing order +.PQ smallest "items first" . +This is the default. +.TP +\fB\-decreasing\fR +. +Sort the list in decreasing order +.PQ largest "items first" . +.TP +\fB\-indices\fR +. +Return a list of indices into \fIlist\fR in sorted order instead of +the values themselves. +.TP +\fB\-index\0\fIindexList\fR +. +If this option is specified, each of the elements of \fIlist\fR must +itself be a proper Tcl sublist (unless \fB\-stride\fR is used). +Instead of sorting based on whole sublists, \fBlsort\fR will extract +the \fIindexList\fR'th element from each sublist (as if the overall +element and the \fIindexList\fR were passed to \fBlindex\fR) and sort +based on the given element. +For example, +.RS +.PP +.CS +\fBlsort\fR -integer -index 1 \e + {{First 24} {Second 18} {Third 30}} +.CE +.PP +returns \fB{Second 18} {First 24} {Third 30}\fR, +.PP +'\" +'\" This example is from the test suite! +'\" +.CS +\fBlsort\fR -index end-1 \e + {{a 1 e i} {b 2 3 f g} {c 4 5 6 d h}} +.CE +.PP +returns \fB{c 4 5 6 d h} {a 1 e i} {b 2 3 f g}\fR, +and +.PP +.CS +\fBlsort\fR -index {0 1} { + {{b i g} 12345} + {{d e m o} 34512} + {{c o d e} 54321} +} +.CE +.PP +returns \fB{{d e m o} 34512} {{b i g} 12345} {{c o d e} 54321}\fR +(because \fBe\fR sorts before \fBi\fR which sorts before \fBo\fR.) +This option is much more efficient than using \fB\-command\fR +to achieve the same effect. +.RE +.TP +\fB\-stride\0\fIstrideLength\fR +. +If this option is specified, the list is treated as consisting of +groups of \fIstrideLength\fR elements and the groups are sorted by +either their first element or, if the \fB\-index\fR option is used, +by the element within each group given by the first index passed to +\fB\-index\fR (which is then ignored by \fB\-index\fR). Elements +always remain in the same position within their group. +.RS +.PP +The list length must be an integer multiple of \fIstrideLength\fR, which +in turn must be at least 2. +.PP +For example, +.PP +.CS +\fBlsort\fR \-stride 2 {carrot 10 apple 50 banana 25} +.CE +.PP +returns +.QW "apple 50 banana 25 carrot 10" , +and +.PP +.CS +\fBlsort\fR \-stride 2 \-index 1 \-integer {carrot 10 apple 50 banana 25} +.CE +.PP +returns +.QW "carrot 10 banana 25 apple 50" . +.RE +.TP +\fB\-nocase\fR +. +Causes comparisons to be handled in a case-insensitive manner. Has no +effect if combined with the \fB\-dictionary\fR, \fB\-integer\fR, or +\fB\-real\fR options. +.TP +\fB\-unique\fR +. +If this option is specified, then only the last set of duplicate +elements found in the list will be retained. Note that duplicates are +determined relative to the comparison used in the sort. Thus if +\fB\-index 0\fR is used, \fB{1 a}\fR and \fB{1 b}\fR would be +considered duplicates and only the second element, \fB{1 b}\fR, would +be retained. +.SH "NOTES" +.PP +The options to \fBlsort\fR only control what sort of comparison is +used, and do not necessarily constrain what the values themselves +actually are. This distinction is only noticeable when the list to be +sorted has fewer than two elements. +.PP +The \fBlsort\fR command is reentrant, meaning it is safe to use as +part of the implementation of a command used in the \fB\-command\fR +option. +.SH "EXAMPLES" +.PP +Sorting a list using ASCII sorting: +.PP +.CS +\fI%\fR \fBlsort\fR {a10 B2 b1 a1 a2} +B2 a1 a10 a2 b1 +.CE +.PP +Sorting a list using Dictionary sorting: +.PP +.CS +\fI%\fR \fBlsort\fR -dictionary {a10 B2 b1 a1 a2} +a1 a2 a10 b1 B2 +.CE +.PP +Sorting lists of integers: +.PP +.CS +\fI%\fR \fBlsort\fR -integer {5 3 1 2 11 4} +1 2 3 4 5 11 +\fI%\fR \fBlsort\fR -integer {1 2 0x5 7 0 4 -1} +-1 0 1 2 4 0x5 7 +.CE +.PP +Sorting lists of floating-point numbers: +.PP +.CS +\fI%\fR \fBlsort\fR -real {5 3 1 2 11 4} +1 2 3 4 5 11 +\fI%\fR \fBlsort\fR -real {.5 0.07e1 0.4 6e-1} +0.4 .5 6e-1 0.07e1 +.CE +.PP +Sorting using indices: +.PP +.CS +\fI%\fR # Note the space character before the c +\fI%\fR \fBlsort\fR {{a 5} { c 3} {b 4} {e 1} {d 2}} +{ c 3} {a 5} {b 4} {d 2} {e 1} +\fI%\fR \fBlsort\fR -index 0 {{a 5} { c 3} {b 4} {e 1} {d 2}} +{a 5} {b 4} { c 3} {d 2} {e 1} +\fI%\fR \fBlsort\fR -index 1 {{a 5} { c 3} {b 4} {e 1} {d 2}} +{e 1} {d 2} { c 3} {b 4} {a 5} +.CE +.PP +.VS 8.6 +Sorting a dictionary: +.PP +.CS +\fI%\fR set d [dict create c d a b h i f g c e] +c e a b h i f g +\fI%\fR \fBlsort\fR -stride 2 $d +a b c e f g h i +.CE +.PP +Sorting using striding and multiple indices: +.PP +.CS +\fI%\fR # Note the first index value is relative to the group +\fI%\fR \fBlsort\fR \-stride 3 \-index {0 1} \e + {{Bob Smith} 25 Audi {Jane Doe} 40 Ford} +{{Jane Doe} 40 Ford {Bob Smith} 25 Audi} +.CE +.VE 8.6 +.PP +Stripping duplicate values using sorting: +.PP +.CS +\fI%\fR \fBlsort\fR -unique {a b c a b c a b c} +a b c +.CE +.PP +More complex sorting using a comparison function: +.PP +.CS +\fI%\fR proc compare {a b} { + set a0 [lindex $a 0] + set b0 [lindex $b 0] + if {$a0 < $b0} { + return -1 + } elseif {$a0 > $b0} { + return 1 + } + return [string compare [lindex $a 1] [lindex $b 1]] +} +\fI%\fR \fBlsort\fR -command compare \e + {{3 apple} {0x2 carrot} {1 dingo} {2 banana}} +{1 dingo} {2 banana} {0x2 carrot} {3 apple} +.CE +.SH "SEE ALSO" +list(n), lappend(n), lindex(n), linsert(n), llength(n), lsearch(n), +lset(n), lrange(n), lreplace(n) +.SH KEYWORDS +element, list, order, sort +'\" Local Variables: +'\" mode: nroff +'\" End: diff --git a/tcl8.6/doc/man.macros b/tcl8.6/doc/man.macros new file mode 100644 index 0000000..ddd073d --- /dev/null +++ b/tcl8.6/doc/man.macros @@ -0,0 +1,267 @@ +.\" The -*- nroff -*- 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 ?manpage? +.\" Start of list of standard options for a Tk widget. The manpage +.\" argument defines where to look up the standard options; if +.\" omitted, defaults to "options". The options follow on successive +.\" lines, in three 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. +.\" +.\" .QW arg1 ?arg2? +.\" Print arg1 in quotes, then arg2 normally (for trailing punctuation). +.\" +.\" .PQ arg1 ?arg2? +.\" Print an open parenthesis, arg1 in quotes, then arg2 normally +.\" (for trailing punctuation) and then a closing parenthesis. +.\" +.\" # 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 +'ie '\\$1'' .ds So \\fBoptions\\fR +'el .ds So \\fB\\$1\\fR +.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 \\*(So 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 +.. +.\" # UL - underline word +.de UL +\\$1\l'|0\(ul'\\$2 +.. +.\" # QW - apply quotation marks to word +.de QW +.ie '\\*(lq'"' ``\\$1''\\$2 +.\"" fix emacs highlighting +.el \\*(lq\\$1\\*(rq\\$2 +.. +.\" # PQ - apply parens and quotation marks to word +.de PQ +.ie '\\*(lq'"' (``\\$1''\\$2)\\$3 +.\"" fix emacs highlighting +.el (\\*(lq\\$1\\*(rq\\$2)\\$3 +.. +.\" # QR - quoted range +.de QR +.ie '\\*(lq'"' ``\\$1''\\-``\\$2''\\$3 +.\"" fix emacs highlighting +.el \\*(lq\\$1\\*(rq\\-\\*(lq\\$2\\*(rq\\$3 +.. +.\" # MT - "empty" string +.de MT +.QW "" +.. diff --git a/tcl8.6/doc/mathfunc.n b/tcl8.6/doc/mathfunc.n new file mode 100644 index 0000000..7233d46 --- /dev/null +++ b/tcl8.6/doc/mathfunc.n @@ -0,0 +1,305 @@ +'\" +'\" Copyright (c) 1993 The Regents of the University of California. +'\" Copyright (c) 1994-2000 Sun Microsystems, Inc. +'\" Copyright (c) 2005 by Kevin B. Kenny <kennykb@acm.org>. All rights reserved +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH mathfunc n 8.5 Tcl "Tcl Mathematical Functions" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +mathfunc \- Mathematical functions for Tcl expressions +.SH SYNOPSIS +package require \fBTcl 8.5\fR +.sp +\fB::tcl::mathfunc::abs\fR \fIarg\fR +.br +\fB::tcl::mathfunc::acos\fR \fIarg\fR +.br +\fB::tcl::mathfunc::asin\fR \fIarg\fR +.br +\fB::tcl::mathfunc::atan\fR \fIarg\fR +.br +\fB::tcl::mathfunc::atan2\fR \fIy\fR \fIx\fR +.br +\fB::tcl::mathfunc::bool\fR \fIarg\fR +.br +\fB::tcl::mathfunc::ceil\fR \fIarg\fR +.br +\fB::tcl::mathfunc::cos\fR \fIarg\fR +.br +\fB::tcl::mathfunc::cosh\fR \fIarg\fR +.br +\fB::tcl::mathfunc::double\fR \fIarg\fR +.br +\fB::tcl::mathfunc::entier\fR \fIarg\fR +.br +\fB::tcl::mathfunc::exp\fR \fIarg\fR +.br +\fB::tcl::mathfunc::floor\fR \fIarg\fR +.br +\fB::tcl::mathfunc::fmod\fR \fIx\fR \fIy\fR +.br +\fB::tcl::mathfunc::hypot\fR \fIx\fR \fIy\fR +.br +\fB::tcl::mathfunc::int\fR \fIarg\fR +.br +\fB::tcl::mathfunc::isqrt\fR \fIarg\fR +.br +\fB::tcl::mathfunc::log\fR \fIarg\fR +.br +\fB::tcl::mathfunc::log10\fR \fIarg\fR +.br +\fB::tcl::mathfunc::max\fR \fIarg\fR ?\fIarg\fR ...? +.br +\fB::tcl::mathfunc::min\fR \fIarg\fR ?\fIarg\fR ...? +.br +\fB::tcl::mathfunc::pow\fR \fIx\fR \fIy\fR +.br +\fB::tcl::mathfunc::rand\fR +.br +\fB::tcl::mathfunc::round\fR \fIarg\fR +.br +\fB::tcl::mathfunc::sin\fR \fIarg\fR +.br +\fB::tcl::mathfunc::sinh\fR \fIarg\fR +.br +\fB::tcl::mathfunc::sqrt\fR \fIarg\fR +.br +\fB::tcl::mathfunc::srand\fR \fIarg\fR +.br +\fB::tcl::mathfunc::tan\fR \fIarg\fR +.br +\fB::tcl::mathfunc::tanh\fR \fIarg\fR +.br +\fB::tcl::mathfunc::wide\fR \fIarg\fR +.sp +.BE +.SH "DESCRIPTION" +.PP +The \fBexpr\fR command handles mathematical functions of the form +\fBsin($x)\fR or \fBatan2($y,$x)\fR by converting them to calls of the +form \fB[tcl::mathfunc::sin [expr {$x}]]\fR or +\fB[tcl::mathfunc::atan2 [expr {$y}] [expr {$x}]]\fR. +A number of math functions are available by default within the +namespace \fB::tcl::mathfunc\fR; these functions are also available +for code apart from \fBexpr\fR, by invoking the given commands +directly. +.PP +Tcl supports the following mathematical functions in expressions, all +of which work solely with floating-point numbers unless otherwise noted: +.DS +.ta 3c 6c 9c +\fBabs\fR \fBacos\fR \fBasin\fR \fBatan\fR +\fBatan2\fR \fBbool\fR \fBceil\fR \fBcos\fR +\fBcosh\fR \fBdouble\fR \fBentier\fR \fBexp\fR +\fBfloor\fR \fBfmod\fR \fBhypot\fR \fBint\fR +\fBisqrt\fR \fBlog\fR \fBlog10\fR \fBmax\fR +\fBmin\fR \fBpow\fR \fBrand\fR \fBround\fR +\fBsin\fR \fBsinh\fR \fBsqrt\fR \fBsrand\fR +\fBtan\fR \fBtanh\fR \fBwide\fR +.DE +.PP +In addition to these predefined functions, applications may +define additional functions by using \fBproc\fR (or any other method, +such as \fBinterp alias\fR or \fBTcl_CreateObjCommand\fR) to define +new commands in the \fBtcl::mathfunc\fR namespace. In addition, an +obsolete interface named \fBTcl_CreateMathFunc\fR() is available to +extensions that are written in C. The latter interface is not recommended +for new implementations. +.SS "DETAILED DEFINITIONS" +.TP +\fBabs \fIarg\fR +. +Returns the absolute value of \fIarg\fR. \fIArg\fR may be either +integer or floating-point, and the result is returned in the same form. +.TP +\fBacos \fIarg\fR +. +Returns the arc cosine of \fIarg\fR, in the range [\fI0\fR,\fIpi\fR] +radians. \fIArg\fR should be in the range [\fI\-1\fR,\fI1\fR]. +.TP +\fBasin \fIarg\fR +. +Returns the arc sine of \fIarg\fR, in the range [\fI\-pi/2\fR,\fIpi/2\fR] +radians. \fIArg\fR should be in the range [\fI\-1\fR,\fI1\fR]. +.TP +\fBatan \fIarg\fR +. +Returns the arc tangent of \fIarg\fR, in the range [\fI\-pi/2\fR,\fIpi/2\fR] +radians. +.TP +\fBatan2 \fIy x\fR +. +Returns the arc tangent of \fIy\fR/\fIx\fR, in the range [\fI\-pi\fR,\fIpi\fR] +radians. \fIx\fR and \fIy\fR cannot both be 0. If \fIx\fR is greater +than \fI0\fR, this is equivalent to +.QW "\fBatan \fR[\fBexpr\fR {\fIy\fB/\fIx\fR}]" . +.TP +\fBbool \fIarg\fR +. +Accepts any numeric value, or any string acceptable to +\fBstring is boolean\fR, and returns the corresponding +boolean value \fB0\fR or \fB1\fR. Non-zero numbers are true. +Other numbers are false. Non-numeric strings produce boolean value in +agreement with \fBstring is true\fR and \fBstring is false\fR. +.TP +\fBceil \fIarg\fR +. +Returns the smallest integral floating-point value (i.e. with a zero +fractional part) not less than \fIarg\fR. The argument may be any +numeric value. +.TP +\fBcos \fIarg\fR +. +Returns the cosine of \fIarg\fR, measured in radians. +.TP +\fBcosh \fIarg\fR +. +Returns the hyperbolic cosine of \fIarg\fR. If the result would cause +an overflow, an error is returned. +.TP +\fBdouble \fIarg\fR +. +The argument may be any numeric value, +If \fIarg\fR is a floating-point value, returns \fIarg\fR, otherwise converts +\fIarg\fR to floating-point and returns the converted value. May return +\fBInf\fR or \fB\-Inf\fR when the argument is a numeric value that exceeds +the floating-point range. +.TP +\fBentier \fIarg\fR +. +The argument may be any numeric value. The integer part of \fIarg\fR +is determined and returned. The integer range returned by this function +is unlimited, unlike \fBint\fR and \fBwide\fR which +truncate their range to fit in particular storage widths. +.TP +\fBexp \fIarg\fR +. +Returns the exponential of \fIarg\fR, defined as \fIe\fR**\fIarg\fR. +If the result would cause an overflow, an error is returned. +.TP +\fBfloor \fIarg\fR +. +Returns the largest integral floating-point value (i.e. with a zero +fractional part) not greater than \fIarg\fR. The argument may be +any numeric value. +.TP +\fBfmod \fIx y\fR +. +Returns the floating-point remainder of the division of \fIx\fR by +\fIy\fR. If \fIy\fR is 0, an error is returned. +.TP +\fBhypot \fIx y\fR +. +Computes the length of the hypotenuse of a right-angled triangle, +approximately +.QW "\fBsqrt\fR [\fBexpr\fR {\fIx\fB*\fIx\fB+\fIy\fB*\fIy\fR}]" +except for being more numerically stable when the two arguments have +substantially different magnitudes. +.TP +\fBint \fIarg\fR +. +The argument may be any numeric value. The integer part of \fIarg\fR +is determined, and then the low order bits of that integer value up +to the machine word size are returned as an integer value. For reference, +the number of bytes in the machine word are stored in the \fBwordSize\fR +element of the \fBtcl_platform\fR array. +.TP +\fBisqrt \fIarg\fR +. +Computes the integer part of the square root of \fIarg\fR. \fIArg\fR must be +a positive value, either an integer or a floating point number. +Unlike \fBsqrt\fR, which is limited to the precision of a floating point +number, \fIisqrt\fR will return a result of arbitrary precision. +.TP +\fBlog \fIarg\fR +. +Returns the natural logarithm of \fIarg\fR. \fIArg\fR must be a +positive value. +.TP +\fBlog10 \fIarg\fR +. +Returns the base 10 logarithm of \fIarg\fR. \fIArg\fR must be a +positive value. +.TP +\fBmax \fIarg\fB \fI...\fR +. +Accepts one or more numeric arguments. Returns the one argument +with the greatest value. +.TP +\fBmin \fIarg\fB \fI...\fR +. +Accepts one or more numeric arguments. Returns the one argument +with the least value. +.TP +\fBpow \fIx y\fR +. +Computes the value of \fIx\fR raised to the power \fIy\fR. If \fIx\fR +is negative, \fIy\fR must be an integer value. +.TP +\fBrand\fR +. +Returns a pseudo-random floating-point value in the range (\fI0\fR,\fI1\fR). +The generator algorithm is a simple linear congruential generator that +is not cryptographically secure. Each result from \fBrand\fR completely +determines all future results from subsequent calls to \fBrand\fR, so +\fBrand\fR should not be used to generate a sequence of secrets, such as +one-time passwords. The seed of the generator is initialized from the +internal clock of the machine or may be set with the \fBsrand\fR function. +.TP +\fBround \fIarg\fR +. +If \fIarg\fR is an integer value, returns \fIarg\fR, otherwise converts +\fIarg\fR to integer by rounding and returns the converted value. +.TP +\fBsin \fIarg\fR +. +Returns the sine of \fIarg\fR, measured in radians. +.TP +\fBsinh \fIarg\fR +. +Returns the hyperbolic sine of \fIarg\fR. If the result would cause +an overflow, an error is returned. +.TP +\fBsqrt \fIarg\fR +. +The argument may be any non-negative numeric value. Returns a floating-point +value that is the square root of \fIarg\fR. May return \fBInf\fR when the +argument is a numeric value that exceeds the square of the maximum value of +the floating-point range. +.TP +\fBsrand \fIarg\fR +. +The \fIarg\fR, which must be an integer, is used to reset the seed for +the random number generator of \fBrand\fR. Returns the first random +number (see \fBrand\fR) from that seed. Each interpreter has its own seed. +.TP +\fBtan \fIarg\fR +. +Returns the tangent of \fIarg\fR, measured in radians. +.TP +\fBtanh \fIarg\fR +. +Returns the hyperbolic tangent of \fIarg\fR. +.TP +\fBwide \fIarg\fR +. +The argument may be any numeric value. The integer part of \fIarg\fR +is determined, and then the low order 64 bits of that integer value +are returned as an integer value. +.SH "SEE ALSO" +expr(n), mathop(n), namespace(n) +.SH "COPYRIGHT" +.nf +Copyright (c) 1993 The Regents of the University of California. +Copyright (c) 1994-2000 Sun Microsystems Incorporated. +Copyright (c) 2005, 2006 by Kevin B. Kenny <kennykb@acm.org>. +.fi +'\" Local Variables: +'\" mode: nroff +'\" fill-column: 78 +'\" End: diff --git a/tcl8.6/doc/mathop.n b/tcl8.6/doc/mathop.n new file mode 100644 index 0000000..4c16d76 --- /dev/null +++ b/tcl8.6/doc/mathop.n @@ -0,0 +1,310 @@ +.\" +.\" Copyright (c) 2006-2007 Donal K. Fellows. +.\" +.\" See the file "license.terms" for information on usage and redistribution +.\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +.\" +.TH mathop n 8.5 Tcl "Tcl Mathematical Operator Commands" +.so man.macros +.BS +.\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +mathop \- Mathematical operators as Tcl commands +.SH SYNOPSIS +package require \fBTcl 8.5\fR +.sp +\fB::tcl::mathop::!\fR \fInumber\fR +.br +\fB::tcl::mathop::~\fR \fInumber\fR +.br +\fB::tcl::mathop::+\fR ?\fInumber\fR ...? +.br +\fB::tcl::mathop::\-\fR \fInumber\fR ?\fInumber\fR ...? +.br +\fB::tcl::mathop::*\fR ?\fInumber\fR ...? +.br +\fB::tcl::mathop::/\fR \fInumber\fR ?\fInumber\fR ...? +.br +\fB::tcl::mathop::%\fR \fInumber number\fR +.br +\fB::tcl::mathop::**\fR ?\fInumber\fR ...? +.br +\fB::tcl::mathop::&\fR ?\fInumber\fR ...? +.br +\fB::tcl::mathop::|\fR ?\fInumber\fR ...? +.br +\fB::tcl::mathop::^\fR ?\fInumber\fR ...? +.br +\fB::tcl::mathop::<<\fR \fInumber number\fR +.br +\fB::tcl::mathop::>>\fR \fInumber number\fR +.br +\fB::tcl::mathop::==\fR ?\fIarg\fR ...? +.br +\fB::tcl::mathop::!=\fR \fIarg arg\fR +.br +\fB::tcl::mathop::<\fR ?\fIarg\fR ...? +.br +\fB::tcl::mathop::<=\fR ?\fIarg\fR ...? +.br +\fB::tcl::mathop::>=\fR ?\fIarg\fR ...? +.br +\fB::tcl::mathop::>\fR ?\fIarg\fR ...? +.br +\fB::tcl::mathop::eq\fR ?\fIarg\fR ...? +.br +\fB::tcl::mathop::ne\fR \fIarg arg\fR +.br +\fB::tcl::mathop::in\fR \fIarg list\fR +.br +\fB::tcl::mathop::ni\fR \fIarg list\fR +.sp +.BE +.SH DESCRIPTION +.PP +The commands in the \fB::tcl::mathop\fR namespace implement the same set of +operations as supported by the \fBexpr\fR command. All are exported from the +namespace, but are not imported into any other namespace by default. Note that +renaming, reimplementing or deleting any of the commands in the namespace does +\fInot\fR alter the way that the \fBexpr\fR command behaves, and nor does +defining any new commands in the \fB::tcl::mathop\fR namespace. +.PP +The following operator commands are supported: +.DS +.ta 2c 4c 6c 8c +\fB~\fR \fB!\fR \fB+\fR \fB\-\fR \fB*\fR +\fB/\fR \fB%\fR \fB**\fR \fB&\fR \fB|\fR +\fB^\fR \fB>>\fR \fB<<\fR \fB==\fR \fBeq\fR +\fB!=\fR \fBne\fR \fB<\fR \fB<=\fR \fB>\fR +\fB>=\fR \fBin\fR \fBni\fR +.DE +.SS "MATHEMATICAL OPERATORS" +.PP +The behaviors of the mathematical operator commands are as follows: +.TP +\fB!\fR \fIboolean\fR +. +Returns the boolean negation of \fIboolean\fR, where \fIboolean\fR may be any +numeric value or any other form of boolean value (i.e. it returns truth if the +argument is falsity or zero, and falsity if the argument is truth or +non-zero). +.TP +\fB+\fR ?\fInumber\fR ...? +. +Returns the sum of arbitrarily many arguments. Each \fInumber\fR argument may +be any numeric value. If no arguments are given, the result will be zero (the +summation identity). +.TP +\fB\-\fR \fInumber\fR ?\fInumber\fR ...? +. +If only a single \fInumber\fR argument is given, returns the negation of that +numeric value. Otherwise returns the number that results when all subsequent +numeric values are subtracted from the first one. All \fInumber\fR arguments +must be numeric values. At least one argument must be given. +.TP +\fB*\fR ?\fInumber\fR ...? +. +Returns the product of arbitrarily many arguments. Each \fInumber\fR may be +any numeric value. If no arguments are given, the result will be one (the +multiplicative identity). +.TP +\fB/\fR \fInumber\fR ?\fInumber\fR ...? +. +If only a single \fInumber\fR argument is given, returns the reciprocal of that +numeric value (i.e. the value obtained by dividing 1.0 by that value). +Otherwise returns the number that results when the first numeric argument is +divided by all subsequent numeric arguments. All \fInumber\fR arguments must +be numeric values. At least one argument must be given. +.RS +.PP +Note that when the leading values in the list of arguments are integers, +integer division will be used for those initial steps (i.e. the intermediate +results will be as if the functions \fIfloor\fR and \fIint\fR are applied to +them, in that order). If all values in the operation are integers, the result +will be an integer. +.RE +.TP +\fB%\fR \fInumber number\fR +. +Returns the integral modulus (i.e., remainder) of the first argument +with respect to the second. +Each \fInumber\fR must have an integral value. +Also, the sign of the result will be the same as the sign of the second +\fInumber\fR, which must not be zero. +.RS +.PP +Note that Tcl defines this operation exactly even for negative numbers, so +that the following command returns a true value (omitting the namespace for +clarity): +.PP +.CS +\fB==\fR [\fB*\fR [\fB/\fI x y\fR] \fIy\fR] [\fB\-\fI x\fR [\fB%\fI x y\fR]] +.CE +.RE +.TP +\fB**\fR ?\fInumber\fR ...? +. +Returns the result of raising each value to the power of the result of +recursively operating on the result of processing the following arguments, so +.QW "\fB** 2 3 4\fR" +is the same as +.QW "\fB** 2 [** 3 4]\fR" . +Each \fInumber\fR may be +any numeric value, though the second number must not be fractional if the +first is negative. If no arguments are given, the result will be one, and if +only one argument is given, the result will be that argument. The +result will have an integral value only when all arguments are +integral values. +.SS "COMPARISON OPERATORS" +.PP +The behaviors of the comparison operator commands (most of which operate +preferentially on numeric arguments) are as follows: +.TP +\fB==\fR ?\fIarg\fR ...? +. +Returns whether each argument is equal to the arguments on each side of it in +the sense of the \fBexpr\fR == operator (\fIi.e.\fR, numeric comparison if +possible, exact string comparison otherwise). If fewer than two arguments +are given, this operation always returns a true value. +.TP +\fBeq\fR ?\fIarg\fR ...? +. +Returns whether each argument is equal to the arguments on each side of it +using exact string comparison. If fewer than two arguments are given, this +operation always returns a true value. +.TP +\fB!=\fR \fIarg arg\fR +. +Returns whether the two arguments are not equal to each other, in the sense of +the \fBexpr\fR != operator (\fIi.e.\fR, numeric comparison if possible, exact +string comparison otherwise). +.TP +\fBne\fR \fIarg arg\fR +. +Returns whether the two arguments are not equal to each other using exact +string comparison. +.TP +\fB<\fR ?\fIarg\fR ...? +. +Returns whether the arbitrarily-many arguments are ordered, with each argument +after the first having to be strictly more than the one preceding it. +Comparisons are performed preferentially on the numeric values, and are +otherwise performed using UNICODE string comparison. If fewer than two +arguments are present, this operation always returns a true value. When the +arguments are numeric but should be compared as strings, the \fBstring +compare\fR command should be used instead. +.TP +\fB<=\fR ?\fIarg\fR ...? +. +Returns whether the arbitrarily-many arguments are ordered, with each argument +after the first having to be equal to or more than the one preceding it. +Comparisons are performed preferentially on the numeric values, and are +otherwise performed using UNICODE string comparison. If fewer than two +arguments are present, this operation always returns a true value. When the +arguments are numeric but should be compared as strings, the \fBstring +compare\fR command should be used instead. +.TP +\fB>\fR ?\fIarg\fR ...? +. +Returns whether the arbitrarily-many arguments are ordered, with each argument +after the first having to be strictly less than the one preceding it. +Comparisons are performed preferentially on the numeric values, and are +otherwise performed using UNICODE string comparison. If fewer than two +arguments are present, this operation always returns a true value. When the +arguments are numeric but should be compared as strings, the \fBstring +compare\fR command should be used instead. +.TP +\fB>=\fR ?\fIarg\fR ...? +. +Returns whether the arbitrarily-many arguments are ordered, with each argument +after the first having to be equal to or less than the one preceding it. +Comparisons are performed preferentially on the numeric values, and are +otherwise performed using UNICODE string comparison. If fewer than two +arguments are present, this operation always returns a true value. When the +arguments are numeric but should be compared as strings, the \fBstring +compare\fR command should be used instead. +.SS "BIT-WISE OPERATORS" +.PP +The behaviors of the bit-wise operator commands (all of which only operate on +integral arguments) are as follows: +.TP +\fB~\fR \fInumber\fR +. +Returns the bit-wise negation of \fInumber\fR. \fINumber\fR may be an integer +of any size. Note that the result of this operation will always have the +opposite sign to the input \fInumber\fR. +.TP +\fB&\fR ?\fInumber\fR ...? +. +Returns the bit-wise AND of each of the arbitrarily many arguments. Each +\fInumber\fR must have an integral value. If no arguments are given, the +result will be minus one. +.TP +\fB|\fR ?\fInumber\fR ...? +. +Returns the bit-wise OR of each of the arbitrarily many arguments. Each +\fInumber\fR must have an integral value. If no arguments are given, the +result will be zero. +.TP +\fB^\fR ?\fInumber\fR ...? +. +Returns the bit-wise XOR of each of the arbitrarily many arguments. Each +\fInumber\fR must have an integral value. If no arguments are given, the +result will be zero. +.TP +\fB<<\fR \fInumber number\fR +. +Returns the result of bit-wise shifting the first argument left by the +number of bits specified in the second argument. Each \fInumber\fR +must have an integral value. +.TP +\fB>>\fR \fInumber number\fR +. +Returns the result of bit-wise shifting the first argument right by +the number of bits specified in the second argument. Each \fInumber\fR +must have an integral value. +.SS "LIST OPERATORS" +.PP +The behaviors of the list-oriented operator commands are as follows: +.TP +\fBin\fR \fIarg list\fR +. +Returns whether the value \fIarg\fR is present in the list \fIlist\fR +(according to exact string comparison of elements). +.TP +\fBni\fR \fIarg list\fR +. +Returns whether the value \fIarg\fR is not present in the list \fIlist\fR +(according to exact string comparison of elements). +.SH EXAMPLES +.PP +The simplest way to use the operators is often by using \fBnamespace path\fR +to make the commands available. This has the advantage of not affecting the +set of commands defined by the current namespace. +.PP +.CS +namespace path {\fB::tcl::mathop\fR ::tcl::mathfunc} + +\fI# Compute the sum of some numbers\fR +set sum [\fB+\fR 1 2 3] + +\fI# Compute the average of a list\fR +set list {1 2 3 4 5 6} +set mean [\fB/\fR [\fB+\fR {*}$list] [double [llength $list]]] + +\fI# Test for list membership\fR +set gotIt [\fBin\fR 3 $list] + +\fI# Test to see if a value is within some defined range\fR +set inRange [\fB<=\fR 1 $x 5] + +\fI# Test to see if a list is sorted\fR +set sorted [\fB<=\fR {*}$list] +.CE +.SH "SEE ALSO" +expr(n), mathfunc(n), namespace(n) +.SH KEYWORDS +command, expression, operator +'\" Local Variables: +'\" mode: nroff +'\" End: diff --git a/tcl8.6/doc/memory.n b/tcl8.6/doc/memory.n new file mode 100644 index 0000000..c8cdb21 --- /dev/null +++ b/tcl8.6/doc/memory.n @@ -0,0 +1,115 @@ +'\" +'\" Copyright (c) 1992-1999 by Karl Lehenbauer and Mark Diekhans +'\" Copyright (c) 2000 by Scriptics Corporation. +'\" All rights reserved. +'\" +.TH memory n 8.1 Tcl "Tcl Built-In Commands" +.so man.macros +.BS +.SH NAME +memory \- Control Tcl memory debugging capabilities +.SH SYNOPSIS +\fBmemory \fIoption \fR?\fIarg arg ...\fR? +.BE +.SH DESCRIPTION +.PP +The \fBmemory\fR command gives the Tcl developer control of Tcl's memory +debugging capabilities. The memory command has several suboptions, which are +described below. It is only available when Tcl has been compiled with +memory debugging enabled (when \fBTCL_MEM_DEBUG\fR is defined at +compile time), and after \fBTcl_InitMemory\fR has been called. +.TP +\fBmemory active\fR \fIfile\fR +. +Write a list of all currently allocated memory to the specified \fIfile\fR. +.TP +\fBmemory break_on_malloc\fR \fIcount\fR +. +After the \fIcount\fR allocations have been performed, \fBckalloc\fR +outputs a message to this effect and that it is now attempting to enter +the C debugger. Tcl will then issue a \fISIGINT\fR signal against itself. +If you are running Tcl under a C debugger, it should then enter the debugger +command mode. +.TP +\fBmemory info\fR +. +Returns a report containing the total allocations and frees since +Tcl began, the current packets allocated (the current +number of calls to \fBckalloc\fR not met by a corresponding call +to \fBckfree\fR), the current bytes allocated, and the maximum number +of packets and bytes allocated. +.TP +\fBmemory init \fR[\fBon\fR|\fBoff\fR] +. +Turn on or off the pre-initialization of all allocated memory +with bogus bytes. Useful for detecting the use of uninitialized +values. +.TP +\fBmemory objs \fIfile\fR +. +Causes a list of all allocated Tcl_Obj values to be written to the specified +\fIfile\fR immediately, together with where they were allocated. Useful for +checking for leaks of values. +.TP +\fBmemory onexit\fR \fIfile\fR +. +Causes a list of all allocated memory to be written to the specified \fIfile\fR +during the finalization of Tcl's memory subsystem. Useful for checking +that memory is properly cleaned up during process exit. +.TP +\fBmemory tag\fR \fIstring\fR +. +Each packet of memory allocated by \fBckalloc\fR can have associated +with it a string-valued tag. In the lists of allocated memory generated +by \fBmemory active\fR and \fBmemory onexit\fR, the tag for each packet +is printed along with other information about the packet. The +\fBmemory tag\fR command sets the tag value for subsequent calls +to \fBckalloc\fR to be \fIstring\fR. +.TP +\fBmemory trace \fR[\fBon\fR|\fBoff\fR] +. +Turns memory tracing on or off. When memory tracing is on, every call +to \fBckalloc\fR causes a line of trace information to be written to +\fIstderr\fR, consisting of the word \fIckalloc\fR, followed by the +address returned, the amount of memory allocated, and the C filename +and line number of the code performing the allocation. For example: +.RS +.PP +.CS +ckalloc 40e478 98 tclProc.c 1406 +.CE +.PP +Calls to \fBckfree\fR are traced in the same manner. +.RE +.TP +\fBmemory trace_on_at_malloc\fR \fIcount\fR +. +Enable memory tracing after \fIcount\fR \fBckalloc\fRs have been performed. +For example, if you enter \fBmemory trace_on_at_malloc 100\fR, +after the 100th call to \fBckalloc\fR, memory trace information will begin +being displayed for all allocations and frees. Since there can be a lot +of memory activity before a problem occurs, judicious use of this option +can reduce the slowdown caused by tracing (and the amount of trace information +produced), if you can identify a number of allocations that occur before +the problem sets in. The current number of memory allocations that have +occurred since Tcl started is printed on a guard zone failure. +.TP +\fBmemory validate \fR[\fBon\fR|\fBoff\fR] +. +Turns memory validation on or off. When memory validation is enabled, +on every call to \fBckalloc\fR or \fBckfree\fR, the guard zones are +checked for every piece of memory currently in existence that was +allocated by \fBckalloc\fR. This has a large performance impact and +should only be used when overwrite problems are strongly suspected. +The advantage of enabling memory validation is that a guard zone +overwrite can be detected on the first call to \fBckalloc\fR or +\fBckfree\fR after the overwrite occurred, rather than when the +specific memory with the overwritten guard zone(s) is freed, which may +occur long after the overwrite occurred. +.SH "SEE ALSO" +ckalloc, ckfree, Tcl_ValidateAllMemory, Tcl_DumpActiveMemory, TCL_MEM_DEBUG +.SH KEYWORDS +memory, debug +'\"Local Variables: +'\"mode: nroff +'\"End: diff --git a/tcl8.6/doc/msgcat.n b/tcl8.6/doc/msgcat.n new file mode 100644 index 0000000..2fc1eee --- /dev/null +++ b/tcl8.6/doc/msgcat.n @@ -0,0 +1,651 @@ +'\" +'\" Copyright (c) 1998 Mark Harrison. +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH "msgcat" n 1.5 msgcat "Tcl Bundled Packages" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +msgcat \- Tcl message catalog +.SH SYNOPSIS +\fBpackage require Tcl 8.5\fR +.sp +\fBpackage require msgcat 1.6\fR +.sp +\fB::msgcat::mc \fIsrc-string\fR ?\fIarg arg ...\fR? +.sp +\fB::msgcat::mcmax ?\fIsrc-string src-string ...\fR? +.sp +.VS "TIP 412" +\fB::msgcat::mcexists\fR ?\fB-exactnamespace\fR? ?\fB-exactlocale\fR? \fIsrc-string\fR +.VE "TIP 412" +.sp +\fB::msgcat::mclocale \fR?\fInewLocale\fR? +.sp +\fB::msgcat::mcpreferences\fR +.sp +.VS "TIP 412" +\fB::msgcat::mcloadedlocales subcommand\fR ?\fIlocale\fR? +.VE "TIP 412" +.sp +\fB::msgcat::mcload \fIdirname\fR +.sp +\fB::msgcat::mcset \fIlocale src-string \fR?\fItranslate-string\fR? +.sp +\fB::msgcat::mcmset \fIlocale src-trans-list\fR +.sp +\fB::msgcat::mcflset \fIsrc-string \fR?\fItranslate-string\fR? +.sp +\fB::msgcat::mcflmset \fIsrc-trans-list\fR +.sp +\fB::msgcat::mcunknown \fIlocale src-string\fR ?\fIarg arg ...\fR? +.sp +.VS "TIP 412" +\fB::msgcat::mcpackagelocale subcommand\fR ?\fIlocale\fR? +.sp +\fB::msgcat::mcpackageconfig subcommand\fR \fIoption\fR ?\fIvalue\fR? +.sp +\fB::msgcat::mcforgetpackage\fR +.VE "TIP 412" +.BE +.SH DESCRIPTION +.PP +The \fBmsgcat\fR package provides a set of functions +that can be used to manage multi-lingual user interfaces. +Text strings are defined in a +.QW "message catalog" +which is independent from the application, and +which can be edited or localized without modifying +the application source code. New languages +or locales may be provided by adding a new file to +the message catalog. +.PP +\fBmsgcat\fR distinguises packages by its namespace. +Each package has its own message catalog and configuration settings in \fBmsgcat\fR. +.PP +A \fIlocale\fR is a specification string describing a user language like \fBde_ch\fR for Swiss German. +In \fBmsgcat\fR, there is a global locale initialized by the system locale of the current system. +Each package may decide to use the global locale or to use a package specific locale. +.PP +The global locale may be changed on demand, for example by a user initiated language change or within a multi user application like a web server. +.SH COMMANDS +.TP +\fB::msgcat::mc \fIsrc-string\fR ?\fIarg arg ...\fR? +. +Returns a translation of \fIsrc-string\fR according to the +current locale. If additional arguments past \fIsrc-string\fR +are given, the \fBformat\fR command is used to substitute the +additional arguments in the translation of \fIsrc-string\fR. +.RS +.PP +\fB::msgcat::mc\fR will search the messages defined +in the current namespace for a translation of \fIsrc-string\fR; if +none is found, it will search in the parent of the current namespace, +and so on until it reaches the global namespace. If no translation +string exists, \fB::msgcat::mcunknown\fR is called and the string +returned from \fB::msgcat::mcunknown\fR is returned. +.PP +\fB::msgcat::mc\fR is the main function used to localize an +application. Instead of using an English string directly, an +application can pass the English string through \fB::msgcat::mc\fR and +use the result. If an application is written for a single language in +this fashion, then it is easy to add support for additional languages +later simply by defining new message catalog entries. +.RE +.TP +\fB::msgcat::mcmax ?\fIsrc-string src-string ...\fR? +. +Given several source strings, \fB::msgcat::mcmax\fR returns the length +of the longest translated string. This is useful when designing +localized GUIs, which may require that all buttons, for example, be a +fixed width (which will be the width of the widest button). +.TP +\fB::msgcat::mcexists\fR ?\fB-exactnamespace\fR? ?\fB-exactlocale\fR? \fIsrc-string\fR +. +.VS "TIP 412" +Return true, if there is a translation for the given \fIsrc-string\fR. +.PP +.RS +The search may be limited by the option \fB\-exactnamespace\fR to only check the current namespace and not any parent namespaces. +.PP +It may also be limited by the option \fB\-exactlocale\fR to only check the first prefered locale (e.g. first element returned by \fB::msgcat::mcpreferences\fR if global locale is used). +.RE +.VE "TIP 412" +.TP +\fB::msgcat::mclocale \fR?\fInewLocale\fR? +. +This function sets the locale to \fInewLocale\fR. If \fInewLocale\fR +is omitted, the current locale is returned, otherwise the current locale +is set to \fInewLocale\fR. msgcat stores and compares the locale in a +case-insensitive manner, and returns locales in lowercase. +The initial locale is determined by the locale specified in +the user's environment. See \fBLOCALE SPECIFICATION\fR +below for a description of the locale string format. +.RS +.PP +.VS "TIP 412" +If the locale is set, the preference list of locales is evaluated. +Locales in this list are loaded now, if not jet loaded. +.VE "TIP 412" +.RE +.TP +\fB::msgcat::mcpreferences\fR +. +Returns an ordered list of the locales preferred by +the user, based on the user's language specification. +The list is ordered from most specific to least +preference. The list is derived from the current +locale set in msgcat by \fB::msgcat::mclocale\fR, and +cannot be set independently. For example, if the +current locale is en_US_funky, then \fB::msgcat::mcpreferences\fR +returns \fB{en_us_funky en_us en {}}\fR. +.TP +\fB::msgcat:mcloadedlocales subcommand\fR ?\fIlocale\fR? +. +This group of commands manage the list of loaded locales for packages not setting a package locale. +.PP +.RS +The subcommand \fBget\fR returns the list of currently loaded locales. +.PP +The subcommand \fBpresent\fR requires the argument \fIlocale\fR and returns true, if this locale is loaded. +.PP +The subcommand \fBclear\fR removes all locales and their data, which are not in the current preference list. +.RE +.TP +\fB::msgcat::mcload \fIdirname\fR +. +.VS "TIP 412" +Searches the specified directory for files that match +the language specifications returned by \fB::msgcat::mcloadedlocales get\fR +(or \fBmsgcat::mcpackagelocale preferences\fR if a package locale is set) (note that these are all lowercase), extended by the file extension +.QW .msg . +Each matching file is +read in order, assuming a UTF-8 encoding. The file contents are +then evaluated as a Tcl script. This means that Unicode characters +may be present in the message file either directly in their UTF-8 +encoded form, or by use of the backslash-u quoting recognized by Tcl +evaluation. The number of message files which matched the specification +and were loaded is returned. +.RS +.PP +In addition, the given folder is stored in the \fBmsgcat\fR package configuration option \fImcfolder\fR to eventually load message catalog files required by a locale change. +.VE "TIP 412" +.RE +.TP +\fB::msgcat::mcset \fIlocale src-string \fR?\fItranslate-string\fR? +. +Sets the translation for \fIsrc-string\fR to \fItranslate-string\fR +in the specified \fIlocale\fR and the current namespace. If +\fItranslate-string\fR is not specified, \fIsrc-string\fR is used +for both. The function returns \fItranslate-string\fR. +.TP +\fB::msgcat::mcmset \fIlocale src-trans-list\fR +. +Sets the translation for multiple source strings in +\fIsrc-trans-list\fR in the specified \fIlocale\fR and the current +namespace. +\fIsrc-trans-list\fR must have an even number of elements and is in +the form {\fIsrc-string translate-string\fR ?\fIsrc-string +translate-string ...\fR?} \fB::msgcat::mcmset\fR can be significantly +faster than multiple invocations of \fB::msgcat::mcset\fR. The function +returns the number of translations set. +.TP +\fB::msgcat::mcflset \fIsrc-string \fR?\fItranslate-string\fR? +Sets the translation for \fIsrc-string\fR to \fItranslate-string\fR in the +current namespace for the locale implied by the name of the message catalog +being loaded via \fB::msgcat::mcload\fR. If \fItranslate-string\fR is not +specified, \fIsrc-string\fR is used for both. The function returns +\fItranslate-string\fR. +.TP +\fB::msgcat::mcflmset \fIsrc-trans-list\fR +Sets the translation for multiple source strings in \fIsrc-trans-list\fR in +the current namespace for the locale implied by the name of the message +catalog being loaded via \fB::msgcat::mcload\fR. \fIsrc-trans-list\fR must +have an even number of elements and is in the form {\fIsrc-string +translate-string\fR ?\fIsrc-string translate-string ...\fR?} +\fB::msgcat::mcflmset\fR can be significantly faster than multiple invocations +of \fB::msgcat::mcflset\fR. The function returns the number of translations set. +.TP +\fB::msgcat::mcunknown \fIlocale src-string\fR ?\fIarg arg ...\fR? +. +This routine is called by \fB::msgcat::mc\fR in the case when +a translation for \fIsrc-string\fR is not defined in the +current locale. The default action is to return +\fIsrc-string\fR passed by format if there are any arguments. This +procedure can be redefined by the +application, for example to log error messages for each unknown +string. The \fB::msgcat::mcunknown\fR procedure is invoked at the +same stack context as the call to \fB::msgcat::mc\fR. The return value +of \fB::msgcat::mcunknown\fR is used as the return value for the call +to \fB::msgcat::mc\fR. +.VS "TIP 412" +.RS +.PP +Note that this routine is only called if the concerned package did not set a package locale unknown command name. +.RE +.TP +\fB::msgcat::mcforgetpackage\fR +. +The calling package clears all its state within the \fBmsgcat\fR package including all settings and translations. +.VE "TIP 412" +.PP +.SH "LOCALE SPECIFICATION" +.PP +The locale is specified to \fBmsgcat\fR by a locale string +passed to \fB::msgcat::mclocale\fR. +The locale string consists of +a language code, an optional country code, and an optional +system-specific code, each separated by +.QW _ . +The country and language +codes are specified in standards ISO-639 and ISO-3166. +For example, the locale +.QW en +specifies English and +.QW en_US +specifies U.S. English. +.PP +When the msgcat package is first loaded, the locale is initialized +according to the user's environment. The variables \fBenv(LC_ALL)\fR, +\fBenv(LC_MESSAGES)\fR, and \fBenv(LANG)\fR are examined in order. +The first of them to have a non-empty value is used to determine the +initial locale. The value is parsed according to the XPG4 pattern +.PP +.CS +language[_country][.codeset][@modifier] +.CE +.PP +to extract its parts. The initial locale is then set by calling +\fB::msgcat::mclocale\fR with the argument +.PP +.CS +language[_country][_modifier] +.CE +.PP +On Windows and Cygwin, if none of those environment variables is set, +msgcat will attempt to extract locale information from the registry. +From Windows Vista on, the RFC4747 locale name "lang-script-country-options" +is transformed to the locale as "lang_country_script" (Example: +sr-Latn-CS -> sr_cs_latin). For Windows XP, the language id is +transformed analoguously (Example: 0c1a -> sr_yu_cyrillic). +If all these attempts to discover an initial locale from the user's +environment fail, msgcat defaults to an initial locale of +.QW C . +.PP +When a locale is specified by the user, a +.QW "best match" +search is performed during string translation. For example, if a user +specifies +en_GB_Funky, the locales +.QW en_gb_funky , +.QW en_gb , +.QW en +and +.MT +(the empty string) +are searched in order until a matching translation +string is found. If no translation string is available, then +the unknown handler is called. +.SH "NAMESPACES AND MESSAGE CATALOGS" +.PP +Strings stored in the message catalog are stored relative +to the namespace from which they were added. This allows +multiple packages to use the same strings without fear +of collisions with other packages. It also allows the +source string to be shorter and less prone to typographical +error. +.PP +For example, executing the code +.PP +.CS +\fB::msgcat::mcset\fR en hello "hello from ::" +namespace eval foo { + \fB::msgcat::mcset\fR en hello "hello from ::foo" +} +puts [\fB::msgcat::mc\fR hello] +namespace eval foo {puts [\fB::msgcat::mc\fR hello]} +.CE +.PP +will print +.PP +.CS +hello from :: +hello from ::foo +.CE +.PP +When searching for a translation of a message, the +message catalog will search first the current namespace, +then the parent of the current namespace, and so on until +the global namespace is reached. This allows child namespaces to +.QW inherit +messages from their parent namespace. +.PP +For example, executing (in the +.QW en +locale) the code +.PP +.CS +\fB::msgcat::mcset\fR en m1 ":: message1" +\fB::msgcat::mcset\fR en m2 ":: message2" +\fB::msgcat::mcset\fR en m3 ":: message3" +namespace eval ::foo { + \fB::msgcat::mcset\fR en m2 "::foo message2" + \fB::msgcat::mcset\fR en m3 "::foo message3" +} +namespace eval ::foo::bar { + \fB::msgcat::mcset\fR en m3 "::foo::bar message3" +} +namespace import \fB::msgcat::mc\fR +puts "[\fBmc\fR m1]; [\fBmc\fR m2]; [\fBmc\fR m3]" +namespace eval ::foo {puts "[\fBmc\fR m1]; [\fBmc\fR m2]; [\fBmc\fR m3]"} +namespace eval ::foo::bar {puts "[\fBmc\fR m1]; [\fBmc\fR m2]; [\fBmc\fR m3]"} +.CE +.PP +will print +.PP +.CS +:: message1; :: message2; :: message3 +:: message1; ::foo message2; ::foo message3 +:: message1; ::foo message2; ::foo::bar message3 +.CE +.SH "LOCATION AND FORMAT OF MESSAGE FILES" +.PP +Message files can be located in any directory, subject +to the following conditions: +.IP [1] +All message files for a package are in the same directory. +.IP [2] +The message file name is a msgcat locale specifier (all lowercase) followed by +.QW .msg . +For example: +.PP +.CS +es.msg \(em spanish +en_gb.msg \(em United Kingdom English +.CE +.PP +\fIException:\fR The message file for the root locale +.MT +is called +.QW \fBROOT.msg\fR . +This exception is made so as not to +cause peculiar behavior, such as marking the message file as +.QW hidden +on Unix file systems. +.IP [3] +The file contains a series of calls to \fBmcflset\fR and +\fBmcflmset\fR, setting the necessary translation strings +for the language, likely enclosed in a \fBnamespace eval\fR +so that all source strings are tied to the namespace of +the package. For example, a short \fBes.msg\fR might contain: +.PP +.CS +namespace eval ::mypackage { + \fB::msgcat::mcflset\fR "Free Beer" "Cerveza Gratis" +} +.CE +.SH "RECOMMENDED MESSAGE SETUP FOR PACKAGES" +.PP +If a package is installed into a subdirectory of the +\fBtcl_pkgPath\fR and loaded via \fBpackage require\fR, the +following procedure is recommended. +.IP [1] +During package installation, create a subdirectory +\fBmsgs\fR under your package directory. +.IP [2] +Copy your *.msg files into that directory. +.IP [3] +Add the following command to your package initialization script: +.PP +.CS +# load language files, stored in msgs subdirectory +\fB::msgcat::mcload\fR [file join [file dirname [info script]] msgs] +.CE +.SH "POSITIONAL CODES FOR FORMAT AND SCAN COMMANDS" +.PP +It is possible that a message string used as an argument +to \fBformat\fR might have positionally dependent parameters that +might need to be repositioned. For example, it might be +syntactically desirable to rearrange the sentence structure +while translating. +.PP +.CS +format "We produced %d units in location %s" $num $city +format "In location %s we produced %d units" $city $num +.CE +.PP +This can be handled by using the positional +parameters: +.PP +.CS +format "We produced %1\e$d units in location %2\e$s" $num $city +format "In location %2\e$s we produced %1\e$d units" $num $city +.CE +.PP +Similarly, positional parameters can be used with \fBscan\fR to +extract values from internationalized strings. Note that it is not +necessary to pass the output of \fB::msgcat::mc\fR to \fBformat\fR +directly; by passing the values to substitute in as arguments, the +formatting substitution is done directly. +.PP +.CS +\fBmsgcat::mc\fR {Produced %1$d at %2$s} $num $city +# ... where that key is mapped to one of the +# human-oriented versions by \fBmsgcat::mcset\fR +.CE +.VS "TIP 412" +.SH Package private locale +.PP +A package using \fBmsgcat\fR may choose to use its own package private +locale and its own set of loaded locales, independent to the global +locale set by \fB::msgcat::mclocale\fR. +.PP +This allows a package to change its locale without causing any locales load or removal in other packages and not to invoke the global locale change callback (see below). +.PP +This action is controled by the following ensemble: +.TP +\fB::msgcat::mcpackagelocale set\fR ?\fIlocale\fR? +. +Set or change a package private locale. +The package private locale is set to the given \fIlocale\fR if the \fIlocale\fR is given. +If the option \fIlocale\fR is not given, the package is set to package private locale mode, but no locale is changed (e.g. if the global locale was valid for the package before, it is copied to the package private locale). +.PP +.RS +This command may cause the load of locales. +.RE +.TP +\fB::msgcat::mcpackagelocale get\fR +. +Return the package private locale or the global locale, if no package private locale is set. +.TP +\fB::msgcat::mcpackagelocale preferences\fR +. +Return the package private preferences or the global preferences, +if no package private locale is set. +.TP +\fB::msgcat::mcpackagelocale loaded\fR +. +Return the list of locales loaded for this package. +.TP +\fB::msgcat::mcpackagelocale isset\fR +. +Returns true, if a package private locale is set. +.TP +\fB::msgcat::mcpackagelocale unset\fR +. +Unset the package private locale and use the globale locale. +Load and remove locales to adjust the list of loaded locales for the +package to the global loaded locales list. +.TP +\fB::msgcat::mcpackagelocale present\fR \fIlocale\fR +. +Returns true, if the given locale is loaded for the package. +.TP +\fB::msgcat::mcpackagelocale clear\fR +. +Clear any loaded locales of the package not present in the package preferences. +.PP +.SH Changing package options +.PP +Each package using msgcat has a set of options within \fBmsgcat\fR. +The package options are described in the next sectionPackage options. +Each package option may be set or unset individually using the following ensemble: +.TP +\fB::msgcat::mcpackageconfig get\fR \fIoption\fR +. +Return the current value of the given \fIoption\fR. +This call returns an error if the option is not set for the package. +.TP +\fB::msgcat::mcpackageconfig isset\fR \fIoption\fR +. +Returns 1, if the given \fIoption\fR is set for the package, 0 otherwise. +.TP +\fB::msgcat::mcpackageconfig set\fR \fIoption\fR \fIvalue\fR +. +Set the given \fIoption\fR to the given \fIvalue\fR. +This may invoke additional actions in dependency of the \fIoption\fR. +The return value is 0 or the number of loaded packages for the option \fBmcfolder\fR. +.TP +\fB::msgcat::mcpackageconfig unset\fR \fIoption\fR +. +Unsets the given \fIoption\fR for the package. +No action is taken if the \fIoption\fR is not set for the package. +The empty string is returned. +.SS Package options +.PP +The following package options are available for each package: +.TP +\fBmcfolder\fR +. +This is the message folder of the package. This option is set by mcload and by the subcommand set. Both are identical and both return the number of loaded message catalog files. +.RS +.PP +Setting or changing this value will load all locales contained in the preferences valid for the package. This implies also to invoke any set loadcmd (see below). +.PP +Unsetting this value will disable message file load for the package. +.RE +.TP +\fBloadcmd\fR +. +This callback is invoked before a set of message catalog files are loaded for the package which has this property set. +.PP +.RS +This callback may be used to do any preparation work for message file load or to get the message data from another source like a data base. In this case, no message files are used (mcfolder is unset). +.PP +See section \fBcallback invocation\fR below. +The parameter list appended to this callback is the list of locales to load. +.PP +If this callback is changed, it is called with the preferences valid for the package. +.RE +.TP +\fBchangecmd\fR +. +This callback is invoked when a default local change was performed. Its purpose is to allow a package to update any dependency on the default locale like showing the GUI in another language. +.PP +.RS +See the callback invocation section below. +The parameter list appended to this callback is \fBmcpreferences\fR. +The registered callbacks are invoked in no particular order. +.RE +.TP +\fBunknowncmd\fR +. +Use a package locale mcunknown procedure instead of the standard version supplied by the msgcat package (msgcat::mcunknown). +.PP +.RS +The called procedure must return the formatted message which will finally be returned by msgcat::mc. +.PP +A generic unknown handler is used if set to the empty string. This consists in returning the key if no arguments are given. With given arguments, format is used to process the arguments. +.PP +See section \fBcallback invocation\fR below. +The appended arguments are identical to \fB::msgcat::mcunknown\fR. +.RE +.SS Callback invocation +A package may decide to register one or multiple callbacks, as described above. +.PP +Callbacks are invoked, if: +.PP +1. the callback command is set, +.PP +2. the command is not the empty string, +.PP +3. the registering namespace exists. +.PP +If a called routine fails with an error, the \fBbgerror\fR routine for the interpreter is invoked after command completion. +Only exception is the callback \fBunknowncmd\fR, where an error causes the invoking \fBmc\fR-command to fail with that error. +.PP +.SS Examples +Packages which display a GUI may update their widgets when the global locale changes. +To register to a callback, use: +.CS +namespace eval gui { + msgcat::mcpackageconfig changecmd updateGUI + + proc updateGui args { + puts "New locale is '[lindex $args 0]'." + } +} +% msgcat::mclocale fr +fr +% New locale is 'fr'. +.CE +.PP +If locales (or additional locales) are contained in another source like a data base, a package may use the load callback and not mcload: +.CS +namespace eval db { + msgcat::mcpackageconfig loadcmd loadMessages + + proc loadMessages args { + foreach locale $args { + if {[LocaleInDB $locale]} { + msgcat::mcmset $locale [GetLocaleList $locale] + } + } + } +} +.CE +.PP +The \fBclock\fR command implementation uses \fBmsgcat\fR with a package locale to implement the command line parameter \fB-locale\fR. +Here are some sketches of the implementation: +.PP +First, a package locale is initialized and the generic unknown function is desactivated: +.CS +msgcat::mcpackagelocale set +msgcat::mcpackageconfig unknowncmd "" +.CE +As an example, the user requires the week day in a certain locale as follows: +.CS +clock format clock seconds -format %A -locale fr +.CE +\fBclock\fR sets the package locale to \fBfr\fR and looks for the day name as follows: +.CS +msgcat::mcpackagelocale set $locale +return [lindex [msgcat::mc DAYS_OF_WEEK_FULL] $day] +### Returns "mercredi" +.CE +Within \fBclock\fR, some message-catalog items are heavy in computation and thus are dynamically cached using: +.CS +proc ::tcl::clock::LocalizeFormat { locale format } { + set key FORMAT_$format + if { [::msgcat::mcexists -exactlocale -exactnamespace $key] } { + return [mc $key] + } + #...expensive computation of format clipped... + mcset $locale $key $format + return $format +} +.CE +.VE "TIP 412" +.SH CREDITS +.PP +The message catalog code was developed by Mark Harrison. +.SH "SEE ALSO" +format(n), scan(n), namespace(n), package(n) +.SH KEYWORDS +internationalization, i18n, localization, l10n, message, text, translation +.\" Local Variables: +.\" mode: nroff +.\" End: diff --git a/tcl8.6/doc/my.n b/tcl8.6/doc/my.n new file mode 100644 index 0000000..2a9769b --- /dev/null +++ b/tcl8.6/doc/my.n @@ -0,0 +1,56 @@ +'\" +'\" Copyright (c) 2007 Donal K. Fellows +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH my n 0.1 TclOO "TclOO Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +my \- invoke any method of current object +.SH SYNOPSIS +.nf +package require TclOO + +\fBmy\fI methodName\fR ?\fIarg ...\fR? +.fi +.BE +.SH DESCRIPTION +.PP +The \fBmy\fR command is used to allow methods of objects to invoke any method +of the object (or its class). In particular, the set of valid values for +\fImethodName\fR is the set of all methods supported by an object and its +superclasses, including those that are not exported. The object upon which the +method is invoked is always the one that is the current context of the method +(i.e. the object that is returned by \fBself object\fR) from which the +\fBmy\fR command is invoked. +.PP +Each object has its own \fBmy\fR command, contained in its instance namespace. +.SH EXAMPLES +.PP +This example shows basic use of \fBmy\fR to use the \fBvariables\fR method of +the \fBoo::object\fR class, which is not publicly visible by default: +.PP +.CS +oo::class create c { + method count {} { + \fBmy\fR variable counter + puts [incr counter] + } +} +c create o +o count \fI\(-> prints "1"\fR +o count \fI\(-> prints "2"\fR +o count \fI\(-> prints "3"\fR +.CE +.SH "SEE ALSO" +next(n), oo::object(n), self(n) +.SH KEYWORDS +method, method visibility, object, private method, public method + +.\" Local variables: +.\" mode: nroff +.\" fill-column: 78 +.\" End: diff --git a/tcl8.6/doc/namespace.n b/tcl8.6/doc/namespace.n new file mode 100644 index 0000000..1f4e85f --- /dev/null +++ b/tcl8.6/doc/namespace.n @@ -0,0 +1,969 @@ +'\" +'\" Copyright (c) 1993-1997 Bell Labs Innovations for Lucent Technologies +'\" Copyright (c) 1997 Sun Microsystems, Inc. +'\" Copyright (c) 2000 Scriptics Corporation. +'\" Copyright (c) 2004-2005 Donal K. Fellows. +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH namespace n 8.5 Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +namespace \- create and manipulate contexts for commands and variables +.SH SYNOPSIS +\fBnamespace \fR?\fIsubcommand\fR? ?\fIarg ...\fR? +.BE +.SH DESCRIPTION +.PP +The \fBnamespace\fR command lets you create, access, and destroy +separate contexts for commands and variables. +See the section \fBWHAT IS A NAMESPACE?\fR below +for a brief overview of namespaces. +The legal values of \fIsubcommand\fR are listed below. +Note that you can abbreviate the \fIsubcommand\fRs. +.TP +\fBnamespace children \fR?\fInamespace\fR? ?\fIpattern\fR? +. +Returns a list of all child namespaces that belong to the +namespace \fInamespace\fR. +If \fInamespace\fR is not specified, +then the children are returned for the current namespace. +This command returns fully-qualified names, +which start with a double colon (\fB::\fR). +If the optional \fIpattern\fR is given, +then this command returns only the names that match the glob-style pattern. +The actual pattern used is determined as follows: +a pattern that starts with double colon (\fB::\fR) is used directly, +otherwise the namespace \fInamespace\fR +(or the fully-qualified name of the current namespace) +is prepended onto the pattern. +.TP +\fBnamespace code \fIscript\fR +. +Captures the current namespace context for later execution +of the script \fIscript\fR. +It returns a new script in which \fIscript\fR has been wrapped +in a \fBnamespace inscope\fR command. +The new script has two important properties. +First, it can be evaluated in any namespace and will cause +\fIscript\fR to be evaluated in the current namespace +(the one where the \fBnamespace code\fR command was invoked). +Second, additional arguments can be appended to the resulting script +and they will be passed to \fIscript\fR as additional arguments. +For example, suppose the command +\fBset script [namespace code {foo bar}]\fR +is invoked in namespace \fB::a::b\fR. +Then \fBeval $script [list x y]\fR +can be executed in any namespace (assuming the value of +\fBscript\fR has been passed in properly) +and will have the same effect as the command +\fB::namespace eval ::a::b {foo bar x y}\fR. +This command is needed because +extensions like Tk normally execute callback scripts +in the global namespace. +A scoped command captures a command together with its namespace context +in a way that allows it to be executed properly later. +See the section \fBSCOPED SCRIPTS\fR for some examples +of how this is used to create callback scripts. +.TP +\fBnamespace current\fR +. +Returns the fully-qualified name for the current namespace. +The actual name of the global namespace is +.MT +(i.e., an empty string), +but this command returns \fB::\fR for the global namespace +as a convenience to programmers. +.TP +\fBnamespace delete \fR?\fInamespace namespace ...\fR? +. +Each namespace \fInamespace\fR is deleted +and all variables, procedures, and child namespaces +contained in the namespace are deleted. +If a procedure is currently executing inside the namespace, +the namespace will be kept alive until the procedure returns; +however, the namespace is marked to prevent other code from +looking it up by name. +If a namespace does not exist, this command returns an error. +If no namespace names are given, this command does nothing. +.TP +\fBnamespace ensemble\fR \fIsubcommand\fR ?\fIarg ...\fR? +. +Creates and manipulates a command that is formed out of an ensemble of +subcommands. See the section \fBENSEMBLES\fR below for further +details. +.TP +\fBnamespace eval\fR \fInamespace arg\fR ?\fIarg ...\fR? +. +Activates a namespace called \fInamespace\fR and evaluates some code +in that context. +If the namespace does not already exist, it is created. +If more than one \fIarg\fR argument is specified, +the arguments are concatenated together with a space between each one +in the same fashion as the \fBeval\fR command, +and the result is evaluated. +.RS +.PP +If \fInamespace\fR has leading namespace qualifiers +and any leading namespaces do not exist, +they are automatically created. +.RE +.TP +\fBnamespace exists\fR \fInamespace\fR +. +Returns \fB1\fR if \fInamespace\fR is a valid namespace in the current +context, returns \fB0\fR otherwise. +.TP +\fBnamespace export \fR?\fB\-clear\fR? ?\fIpattern pattern ...\fR? +. +Specifies which commands are exported from a namespace. +The exported commands are those that can be later imported +into another namespace using a \fBnamespace import\fR command. +Both commands defined in a namespace and +commands the namespace has previously imported +can be exported by a namespace. +The commands do not have to be defined +at the time the \fBnamespace export\fR command is executed. +Each \fIpattern\fR may contain glob-style special characters, +but it may not include any namespace qualifiers. +That is, the pattern can only specify commands +in the current (exporting) namespace. +Each \fIpattern\fR is appended onto the namespace's list of export patterns. +If the \fB\-clear\fR flag is given, +the namespace's export pattern list is reset to empty before any +\fIpattern\fR arguments are appended. +If no \fIpattern\fRs are given and the \fB\-clear\fR flag is not given, +this command returns the namespace's current export list. +.TP +\fBnamespace forget \fR?\fIpattern pattern ...\fR? +. +Removes previously imported commands from a namespace. +Each \fIpattern\fR is a simple or qualified name such as +\fBx\fR, \fBfoo::x\fR or \fBa::b::p*\fR. +Qualified names contain double colons (\fB::\fR) and qualify a name +with the name of one or more namespaces. +Each +.QW "qualified pattern" +is qualified with the name of an exporting namespace +and may have glob-style special characters in the command name +at the end of the qualified name. +Glob characters may not appear in a namespace name. +For each +.QW "simple pattern" +this command deletes the matching commands of the +current namespace that were imported from a different namespace. +For +.QW "qualified patterns" , +this command first finds the matching exported commands. +It then checks whether any of those commands +were previously imported by the current namespace. +If so, this command deletes the corresponding imported commands. +In effect, this un-does the action of a \fBnamespace import\fR command. +.TP +\fBnamespace import \fR?\fB\-force\fR? ?\fIpattern\fR \fIpattern ...\fR? +. +Imports commands into a namespace, or queries the set of imported +commands in a namespace. When no arguments are present, +\fBnamespace import\fR returns the list of commands in +the current namespace that have been imported from other +namespaces. The commands in the returned list are in +the format of simple names, with no namespace qualifiers at all. +This format is suitable for composition with \fBnamespace forget\fR +(see \fBEXAMPLES\fR below). +.RS +.PP +When \fIpattern\fR arguments are present, +each \fIpattern\fR is a qualified name like +\fBfoo::x\fR or \fBa::p*\fR. +That is, it includes the name of an exporting namespace +and may have glob-style special characters in the command name +at the end of the qualified name. +Glob characters may not appear in a namespace name. +When the namespace name is not fully qualified (i.e., does not start +with a namespace separator) it is resolved as a namespace name in the +way described in the \fBNAME RESOLUTION\fR section; it is an error if +no namespace with that name can be found. +.PP +All the commands that match a \fIpattern\fR string +and which are currently exported from their namespace +are added to the current namespace. +This is done by creating a new command in the current namespace +that points to the exported command in its original namespace; +when the new imported command is called, it invokes the exported command. +This command normally returns an error +if an imported command conflicts with an existing command. +However, if the \fB\-force\fR option is given, +imported commands will silently replace existing commands. +The \fBnamespace import\fR command has snapshot semantics: +that is, only requested commands that are currently defined +in the exporting namespace are imported. +In other words, you can import only the commands that are in a namespace +at the time when the \fBnamespace import\fR command is executed. +If another command is defined and exported in this namespace later on, +it will not be imported. +.RE +.TP +\fBnamespace inscope\fR \fInamespace\fR \fIscript\fR ?\fIarg ...\fR? +. +Executes a script in the context of the specified \fInamespace\fR. +This command is not expected to be used directly by programmers; +calls to it are generated implicitly when applications +use \fBnamespace code\fR commands to create callback scripts +that the applications then register with, e.g., Tk widgets. +The \fBnamespace inscope\fR command is much like the \fBnamespace eval\fR +command except that the \fInamespace\fR must already exist, +and \fBnamespace inscope\fR appends additional \fIarg\fRs +as proper list elements. +.RS +.PP +.CS +\fBnamespace inscope ::foo $script $x $y $z\fR +.CE +.PP +is equivalent to +.PP +.CS +\fBnamespace eval ::foo [concat $script [list $x $y $z]]\fR +.CE +.PP +thus additional arguments will not undergo a second round of substitution, +as is the case with \fBnamespace eval\fR. +.RE +.TP +\fBnamespace origin \fIcommand\fR +. +Returns the fully-qualified name of the original command +to which the imported command \fIcommand\fR refers. +When a command is imported into a namespace, +a new command is created in that namespace +that points to the actual command in the exporting namespace. +If a command is imported into a sequence of namespaces +\fIa, b,...,n\fR where each successive namespace +just imports the command from the previous namespace, +this command returns the fully-qualified name of the original command +in the first namespace, \fIa\fR. +If \fIcommand\fR does not refer to an imported command, +the command's own fully-qualified name is returned. +.TP +\fBnamespace parent\fR ?\fInamespace\fR? +. +Returns the fully-qualified name of the parent namespace +for namespace \fInamespace\fR. +If \fInamespace\fR is not specified, +the fully-qualified name of the current namespace's parent is returned. +.TP +\fBnamespace path\fR ?\fInamespaceList\fR? +. +Returns the command resolution path of the current namespace. If +\fInamespaceList\fR is specified as a list of named namespaces, the +current namespace's command resolution path is set to those namespaces +and returns the empty list. The default command resolution path is +always empty. See the section \fBNAME RESOLUTION\fR below for an +explanation of the rules regarding name resolution. +.TP +\fBnamespace qualifiers\fR \fIstring\fR +. +Returns any leading namespace qualifiers for \fIstring\fR. +Qualifiers are namespace names separated by double colons (\fB::\fR). +For the \fIstring\fR \fB::foo::bar::x\fR, +this command returns \fB::foo::bar\fR, +and for \fB::\fR it returns an empty string. +This command is the complement of the \fBnamespace tail\fR command. +Note that it does not check whether the +namespace names are, in fact, +the names of currently defined namespaces. +.TP +\fBnamespace tail\fR \fIstring\fR +. +Returns the simple name at the end of a qualified string. +Qualifiers are namespace names separated by double colons (\fB::\fR). +For the \fIstring\fR \fB::foo::bar::x\fR, +this command returns \fBx\fR, +and for \fB::\fR it returns an empty string. +This command is the complement of the \fBnamespace qualifiers\fR command. +It does not check whether the namespace names are, in fact, +the names of currently defined namespaces. +.TP +\fBnamespace upvar\fR \fInamespace\fR ?\fIotherVar myVar \fR...? +. +This command arranges for zero or more local variables in the current +procedure to refer to variables in \fInamespace\fR. The namespace name is +resolved as described in section \fBNAME RESOLUTION\fR. +The command +\fBnamespace upvar $ns a b\fR has the same behaviour as +\fBupvar 0 ${ns}::a b\fR, with the sole exception of the resolution rules +used for qualified namespace or variable names. +\fBnamespace upvar\fR returns an empty string. +.TP +\fBnamespace unknown\fR ?\fIscript\fR? +. +Sets or returns the unknown command handler for the current namespace. +The handler is invoked when a command called from within the namespace +cannot be found in the current namespace, the namespace's path nor in +the global namespace. +The \fIscript\fR argument, if given, should be a well +formed list representing a command name and optional arguments. When +the handler is invoked, the full invocation line will be appended to the +script and the result evaluated in the context of the namespace. The +default handler for all namespaces is \fB::unknown\fR. If no argument +is given, it returns the handler for the current namespace. +.TP +\fBnamespace which\fR ?\fB\-command\fR? ?\fB\-variable\fR? \fIname\fR +. +Looks up \fIname\fR as either a command or variable +and returns its fully-qualified name. +For example, if \fIname\fR does not exist in the current namespace +but does exist in the global namespace, +this command returns a fully-qualified name in the global namespace. +If the command or variable does not exist, +this command returns an empty string. If the variable has been +created but not defined, such as with the \fBvariable\fR command +or through a \fBtrace\fR on the variable, this command will return the +fully-qualified name of the variable. +If no flag is given, \fIname\fR is treated as a command name. +See the section \fBNAME RESOLUTION\fR below for an explanation of +the rules regarding name resolution. +.SH "WHAT IS A NAMESPACE?" +.PP +A namespace is a collection of commands and variables. +It encapsulates the commands and variables to ensure that they +will not interfere with the commands and variables of other namespaces. +Tcl has always had one such collection, +which we refer to as the \fIglobal namespace\fR. +The global namespace holds all global variables and commands. +The \fBnamespace eval\fR command lets you create new namespaces. +For example, +.PP +.CS +\fBnamespace eval\fR Counter { + \fBnamespace export\fR bump + variable num 0 + + proc bump {} { + variable num + incr num + } +} +.CE +.PP +creates a new namespace containing the variable \fBnum\fR and +the procedure \fBbump\fR. +The commands and variables in this namespace are separate from +other commands and variables in the same program. +If there is a command named \fBbump\fR in the global namespace, +for example, it will be different from the command \fBbump\fR +in the \fBCounter\fR namespace. +.PP +Namespace variables resemble global variables in Tcl. +They exist outside of the procedures in a namespace +but can be accessed in a procedure via the \fBvariable\fR command, +as shown in the example above. +.PP +Namespaces are dynamic. +You can add and delete commands and variables at any time, +so you can build up the contents of a +namespace over time using a series of \fBnamespace eval\fR commands. +For example, the following series of commands has the same effect +as the namespace definition shown above: +.PP +.CS +\fBnamespace eval\fR Counter { + variable num 0 + proc bump {} { + variable num + return [incr num] + } +} +\fBnamespace eval\fR Counter { + proc test {args} { + return $args + } +} +\fBnamespace eval\fR Counter { + rename test "" +} +.CE +.PP +Note that the \fBtest\fR procedure is added to the \fBCounter\fR namespace, +and later removed via the \fBrename\fR command. +.PP +Namespaces can have other namespaces within them, +so they nest hierarchically. +A nested namespace is encapsulated inside its parent namespace +and can not interfere with other namespaces. +.SH "QUALIFIED NAMES" +.PP +Each namespace has a textual name such as +\fBhistory\fR or \fB::safe::interp\fR. +Since namespaces may nest, +qualified names are used to refer to +commands, variables, and child namespaces contained inside namespaces. +Qualified names are similar to the hierarchical path names for +Unix files or Tk widgets, +except that \fB::\fR is used as the separator +instead of \fB/\fR or \fB.\fR. +The topmost or global namespace has the name +.MT +(i.e., an empty string), although \fB::\fR is a synonym. +As an example, the name \fB::safe::interp::create\fR +refers to the command \fBcreate\fR in the namespace \fBinterp\fR +that is a child of namespace \fB::safe\fR, +which in turn is a child of the global namespace, \fB::\fR. +.PP +If you want to access commands and variables from another namespace, +you must use some extra syntax. +Names must be qualified by the namespace that contains them. +From the global namespace, +we might access the \fBCounter\fR procedures like this: +.PP +.CS +Counter::bump 5 +Counter::Reset +.CE +.PP +We could access the current count like this: +.PP +.CS +puts "count = $Counter::num" +.CE +.PP +When one namespace contains another, you may need more than one +qualifier to reach its elements. +If we had a namespace \fBFoo\fR that contained the namespace \fBCounter\fR, +you could invoke its \fBbump\fR procedure +from the global namespace like this: +.PP +.CS +Foo::Counter::bump 3 +.CE +.PP +You can also use qualified names when you create and rename commands. +For example, you could add a procedure to the \fBFoo\fR +namespace like this: +.PP +.CS +proc Foo::Test {args} {return $args} +.CE +.PP +And you could move the same procedure to another namespace like this: +.PP +.CS +rename Foo::Test Bar::Test +.CE +.PP +There are a few remaining points about qualified names +that we should cover. +Namespaces have nonempty names except for the global namespace. +\fB::\fR is disallowed in simple command, variable, and namespace names +except as a namespace separator. +Extra colons in any separator part of a qualified name are ignored; +i.e. two or more colons are treated as a namespace separator. +A trailing \fB::\fR in a qualified variable or command name +refers to the variable or command named {}. +However, a trailing \fB::\fR in a qualified namespace name is ignored. +.SH "NAME RESOLUTION" +.PP +In general, all Tcl commands that take variable and command names +support qualified names. +This means you can give qualified names to such commands as +\fBset\fR, \fBproc\fR, \fBrename\fR, and \fBinterp alias\fR. +If you provide a fully-qualified name that starts with a \fB::\fR, +there is no question about what command, variable, or namespace +you mean. +However, if the name does not start with a \fB::\fR +(i.e., is \fIrelative\fR), +Tcl follows basic rules for looking it up: +.IP \(bu +\fBVariable names\fR are always resolved by looking first in the current +namespace, and then in the global namespace. +.IP \(bu +\fBCommand names\fR are always resolved by looking in the current namespace +first. If not found there, they are searched for in every namespace on the +current namespace's command path (which is empty by default). If not found +there, command names are looked up in the global namespace (or, failing that, +are processed by the appropriate \fBnamespace unknown\fR handler.) +.IP \(bu +\fBNamespace names\fR are always resolved by looking in only the current +namespace. +.PP +In the following example, +.PP +.CS +set traceLevel 0 +\fBnamespace eval\fR Debug { + printTrace $traceLevel +} +.CE +.PP +Tcl looks for \fBtraceLevel\fR in the namespace \fBDebug\fR +and then in the global namespace. +It looks up the command \fBprintTrace\fR in the same way. +If a variable or command name is not found in either context, +the name is undefined. +To make this point absolutely clear, consider the following example: +.PP +.CS +set traceLevel 0 +\fBnamespace eval\fR Foo { + variable traceLevel 3 + + \fBnamespace eval\fR Debug { + printTrace $traceLevel + } +} +.CE +.PP +Here Tcl looks for \fBtraceLevel\fR first in the namespace \fBFoo::Debug\fR. +Since it is not found there, Tcl then looks for it +in the global namespace. +The variable \fBFoo::traceLevel\fR is completely ignored +during the name resolution process. +.PP +You can use the \fBnamespace which\fR command to clear up any question +about name resolution. +For example, the command: +.PP +.CS +\fBnamespace eval\fR Foo::Debug {\fBnamespace which\fR \-variable traceLevel} +.CE +.PP +returns \fB::traceLevel\fR. +On the other hand, the command, +.PP +.CS +\fBnamespace eval\fR Foo {\fBnamespace which\fR \-variable traceLevel} +.CE +.PP +returns \fB::Foo::traceLevel\fR. +.PP +As mentioned above, +namespace names are looked up differently +than the names of variables and commands. +Namespace names are always resolved in the current namespace. +This means, for example, +that a \fBnamespace eval\fR command that creates a new namespace +always creates a child of the current namespace +unless the new namespace name begins with \fB::\fR. +.PP +Tcl has no access control to limit what variables, commands, +or namespaces you can reference. +If you provide a qualified name that resolves to an element +by the name resolution rule above, +you can access the element. +.PP +You can access a namespace variable +from a procedure in the same namespace +by using the \fBvariable\fR command. +Much like the \fBglobal\fR command, +this creates a local link to the namespace variable. +If necessary, it also creates the variable in the current namespace +and initializes it. +Note that the \fBglobal\fR command only creates links +to variables in the global namespace. +It is not necessary to use a \fBvariable\fR command +if you always refer to the namespace variable using an +appropriate qualified name. +.SH "IMPORTING COMMANDS" +.PP +Namespaces are often used to represent libraries. +Some library commands are used so frequently +that it is a nuisance to type their qualified names. +For example, suppose that all of the commands in a package +like BLT are contained in a namespace called \fBBlt\fR. +Then you might access these commands like this: +.PP +.CS +Blt::graph .g \-background red +Blt::table . .g 0,0 +.CE +.PP +If you use the \fBgraph\fR and \fBtable\fR commands frequently, +you may want to access them without the \fBBlt::\fR prefix. +You can do this by importing the commands into the current namespace, +like this: +.PP +.CS +\fBnamespace import\fR Blt::* +.CE +.PP +This adds all exported commands from the \fBBlt\fR namespace +into the current namespace context, so you can write code like this: +.PP +.CS +graph .g \-background red +table . .g 0,0 +.CE +.PP +The \fBnamespace import\fR command only imports commands +from a namespace that that namespace exported +with a \fBnamespace export\fR command. +.PP +Importing \fIevery\fR command from a namespace is generally +a bad idea since you do not know what you will get. +It is better to import just the specific commands you need. +For example, the command +.PP +.CS +\fBnamespace import\fR Blt::graph Blt::table +.CE +.PP +imports only the \fBgraph\fR and \fBtable\fR commands into the +current context. +.PP +If you try to import a command that already exists, you will get an +error. This prevents you from importing the same command from two +different packages. But from time to time (perhaps when debugging), +you may want to get around this restriction. You may want to +reissue the \fBnamespace import\fR command to pick up new commands +that have appeared in a namespace. In that case, you can use the +\fB\-force\fR option, and existing commands will be silently overwritten: +.PP +.CS +\fBnamespace import\fR \-force Blt::graph Blt::table +.CE +.PP +If for some reason, you want to stop using the imported commands, +you can remove them with a \fBnamespace forget\fR command, like this: +.PP +.CS +\fBnamespace forget\fR Blt::* +.CE +.PP +This searches the current namespace for any commands imported from \fBBlt\fR. +If it finds any, it removes them. Otherwise, it does nothing. +After this, the \fBBlt\fR commands must be accessed with the \fBBlt::\fR +prefix. +.PP +When you delete a command from the exporting namespace like this: +.PP +.CS +rename Blt::graph "" +.CE +.PP +the command is automatically removed from all namespaces that import it. +.SH "EXPORTING COMMANDS" +You can export commands from a namespace like this: +.PP +.CS +\fBnamespace eval\fR Counter { + \fBnamespace export\fR bump reset + variable Num 0 + variable Max 100 + + proc bump {{by 1}} { + variable Num + incr Num $by + Check + return $Num + } + proc reset {} { + variable Num + set Num 0 + } + proc Check {} { + variable Num + variable Max + if {$Num > $Max} { + error "too high!" + } + } +} +.CE +.PP +The procedures \fBbump\fR and \fBreset\fR are exported, +so they are included when you import from the \fBCounter\fR namespace, +like this: +.PP +.CS +\fBnamespace import\fR Counter::* +.CE +.PP +However, the \fBCheck\fR procedure is not exported, +so it is ignored by the import operation. +.PP +The \fBnamespace import\fR command only imports commands +that were declared as exported by their namespace. +The \fBnamespace export\fR command specifies what commands +may be imported by other namespaces. +If a \fBnamespace import\fR command specifies a command +that is not exported, the command is not imported. +.SH "SCOPED SCRIPTS" +.PP +The \fBnamespace code\fR command is the means by which a script may be +packaged for evaluation in a namespace other than the one in which it +was created. It is used most often to create event handlers, Tk bindings, +and traces for evaluation in the global context. For instance, the following +code indicates how to direct a variable \fBtrace\fR callback into the current +namespace: +.PP +.CS +\fBnamespace eval\fR a { + variable b + proc theTraceCallback { n1 n2 op } { + upvar 1 $n1 var + puts "the value of $n1 has changed to $var" + return + } + trace add variable b write [\fBnamespace code\fR theTraceCallback] +} +set a::b c +.CE +.PP +When executed, it prints the message: +.PP +.CS +the value of a::b has changed to c +.CE +.SH ENSEMBLES +.PP +The \fBnamespace ensemble\fR is used to create and manipulate ensemble +commands, which are commands formed by grouping subcommands together. +The commands typically come from the current namespace when the +ensemble was created, though this is configurable. Note that there +may be any number of ensembles associated with any namespace +(including none, which is true of all namespaces by default), though +all the ensembles associated with a namespace are deleted when that +namespace is deleted. The link between an ensemble command and its +namespace is maintained however the ensemble is renamed. +.PP +Three subcommands of the \fBnamespace ensemble\fR command are defined: +.TP +\fBnamespace ensemble create\fR ?\fIoption value ...\fR? +. +Creates a new ensemble command linked to the current namespace, +returning the fully qualified name of the command created. The +arguments to \fBnamespace ensemble create\fR allow the configuration +of the command as if with the \fBnamespace ensemble configure\fR +command. If not overridden with the \fB\-command\fR option, this +command creates an ensemble with exactly the same name as the linked +namespace. See the section \fBENSEMBLE OPTIONS\fR below for a full +list of options supported and their effects. +.TP +\fBnamespace ensemble configure \fIcommand\fR ?\fIoption\fR? ?\fIvalue ...\fR? +. +Retrieves the value of an option associated with the ensemble command +named \fIcommand\fR, or updates some options associated with that +ensemble command. See the section \fBENSEMBLE OPTIONS\fR below for a +full list of options supported and their effects. +.TP +\fBnamespace ensemble exists\fR \fIcommand\fR +. +Returns a boolean value that describes whether the command +\fIcommand\fR exists and is an ensemble command. This command only +ever returns an error if the number of arguments to the command is +wrong. +.PP +When called, an ensemble command takes its first argument and looks it +up (according to the rules described below) to discover a list of +words to replace the ensemble command and subcommand with. The +resulting list of words is then evaluated (with no further +substitutions) as if that was what was typed originally (i.e. by +passing the list of words through \fBTcl_EvalObjv\fR) and returning +the result of the command. Note that it is legal to make the target +of an ensemble rewrite be another (or even the same) ensemble +command. The ensemble command will not be visible through the use of +the \fBuplevel\fR or \fBinfo level\fR commands. +.SS "ENSEMBLE OPTIONS" +.PP +The following options, supported by the \fBnamespace ensemble +create\fR and \fBnamespace ensemble configure\fR commands, control how +an ensemble command behaves: +.TP +\fB\-map\fR +. +When non-empty, this option supplies a dictionary that provides a +mapping from subcommand names to a list of prefix words to substitute +in place of the ensemble command and subcommand words (in a manner +similar to an alias created with \fBinterp alias\fR; the words are not +reparsed after substitution); if the first word of any target is not +fully qualified when set, it is assumed to be relative to the +\fIcurrent\fR namespace and changed to be exactly that (that is, it is +always fully qualified when read). When this option is empty, the mapping +will be from the local name of the subcommand to its fully-qualified +name. Note that when this option is non-empty and the +\fB\-subcommands\fR option is empty, the ensemble subcommand names +will be exactly those words that have mappings in the dictionary. +.TP +\fB\-parameters\fR +.VS 8.6 +This option gives a list of named arguments (the names being used during +generation of error messages) that are passed by the caller of the ensemble +between the name of the ensemble and the subcommand argument. By default, it +is the empty list. +.VE 8.6 +.TP +\fB\-prefixes\fR +. +This option (which is enabled by default) controls whether the +ensemble command recognizes unambiguous prefixes of its subcommands. +When turned off, the ensemble command requires exact matching of +subcommand names. +.TP +\fB\-subcommands\fR +. +When non-empty, this option lists exactly what subcommands are in the +ensemble. The mapping for each of those commands will be either whatever +is defined in the \fB\-map\fR option, or to the command with the same +name in the namespace linked to the ensemble. If this option is +empty, the subcommands of the namespace will either be the keys of the +dictionary listed in the \fB\-map\fR option or the exported commands +of the linked namespace at the time of the invocation of the ensemble +command. +.TP +\fB\-unknown\fR +. +When non-empty, this option provides a partial command (to which all +the words that are arguments to the ensemble command, including the +fully-qualified name of the ensemble, are appended) to handle the case +where an ensemble subcommand is not recognized and would otherwise +generate an error. When empty (the default) an error (in the style of +\fBTcl_GetIndexFromObj\fR) is generated whenever the ensemble is +unable to determine how to implement a particular subcommand. See +\fBUNKNOWN HANDLER BEHAVIOUR\fR for more details. +.PP +The following extra option is allowed by \fBnamespace ensemble +create\fR: +.TP +\fB\-command\fR +. +This write-only option allows the name of the ensemble created by +\fBnamespace ensemble create\fR to be anything in any existing +namespace. The default value for this option is the fully-qualified +name of the namespace in which the \fBnamespace ensemble create\fR +command is invoked. +.PP +The following extra option is allowed by \fBnamespace ensemble +configure\fR: +.TP +\fB\-namespace\fR +. +This read-only option allows the retrieval of the fully-qualified name +of the namespace which the ensemble was created within. +.SS "UNKNOWN HANDLER BEHAVIOUR" +.PP +If an unknown handler is specified for an ensemble, that handler is +called when the ensemble command would otherwise return an error due +to it being unable to decide which subcommand to invoke. The exact +conditions under which that occurs are controlled by the +\fB\-subcommands\fR, \fB\-map\fR and \fB\-prefixes\fR options as +described above. +.PP +To execute the unknown handler, the ensemble mechanism takes the +specified \fB\-unknown\fR option and appends each argument of the +attempted ensemble command invocation (including the ensemble command +itself, expressed as a fully qualified name). It invokes the resulting +command in the scope of the attempted call. If the execution of the +unknown handler terminates normally, the ensemble engine reparses the +subcommand (as described below) and tries to dispatch it again, which +is ideal for when the ensemble's configuration has been updated by the +unknown subcommand handler. Any other kind of termination of the +unknown handler is treated as an error. +.PP +The result of the unknown handler is expected to be a list (it is an +error if it is not). If the list is an empty list, the ensemble +command attempts to look up the original subcommand again and, if it +is not found this time, an error will be generated just as if the +\fB\-unknown\fR handler was not there (i.e. for any particular +invocation of an ensemble, its unknown handler will be called at most +once.) This makes it easy for the unknown handler to update the +ensemble or its backing namespace so as to provide an implementation +of the desired subcommand and reparse. +.PP +When the result is a non-empty list, the words of that list are used +to replace the ensemble command and subcommand, just as if they had +been looked up in the \fB\-map\fR. It is up to the unknown handler to +supply all namespace qualifiers if the implementing subcommand is not +in the namespace of the caller of the ensemble command. Also note that +when ensemble commands are chained (e.g. if you make one of the +commands that implement an ensemble subcommand into an ensemble, in a +manner similar to the \fBtext\fR widget's tag and mark subcommands) then the +rewrite happens in the context of the caller of the outermost +ensemble. That is to say that ensembles do not in themselves place any +namespace contexts on the Tcl call stack. +.PP +Where an empty \fB\-unknown\fR handler is given (the default), the +ensemble command will generate an error message based on the list of +commands that the ensemble has defined (formatted similarly to the +error message from \fBTcl_GetIndexFromObj\fR). This is the error that +will be thrown when the subcommand is still not recognized during +reparsing. It is also an error for an \fB\-unknown\fR handler to +delete its namespace. +.SH EXAMPLES +Create a namespace containing a variable and an exported command: +.PP +.CS +\fBnamespace eval\fR foo { + variable bar 0 + proc grill {} { + variable bar + puts "called [incr bar] times" + } + \fBnamespace export\fR grill +} +.CE +.PP +Call the command defined in the previous example in various ways. +.PP +.CS +# Direct call +::foo::grill + +# Use the command resolution path to find the name +\fBnamespace eval\fR boo { + \fBnamespace path\fR ::foo + grill +} + +# Import into current namespace, then call local alias +\fBnamespace import\fR foo::grill +grill + +# Create two ensembles, one with the default name and one with a +# specified name. Then call through the ensembles. +\fBnamespace eval\fR foo { + \fBnamespace ensemble\fR create + \fBnamespace ensemble\fR create -command ::foobar +} +foo grill +foobar grill +.CE +.PP +Look up where the command imported in the previous example came from: +.PP +.CS +puts "grill came from [\fBnamespace origin\fR grill]" +.CE +.PP +Remove all imported commands from the current namespace: +.PP +.CS +namespace forget {*}[namespace import] +.CE +.PP +.VS 8.6 +Create an ensemble for simple working with numbers, using the +\fB\-parameters\fR option to allow the operator to be put between the first +and second arguments. +.PP +.CS +\fBnamespace eval\fR do { + \fBnamespace export\fR * + \fBnamespace ensemble\fR create -parameters x + proc plus {x y} {expr { $x + $y }} + proc minus {x y} {expr { $x - $y }} +} + +# In use, the ensemble works like this: +puts [do 1 plus [do 9 minus 7]] +.CE +.VE 8.6 +.SH "SEE ALSO" +interp(n), upvar(n), variable(n) +.SH KEYWORDS +command, ensemble, exported, internal, variable +'\" Local Variables: +'\" mode: nroff +'\" End: diff --git a/tcl8.6/doc/next.n b/tcl8.6/doc/next.n new file mode 100644 index 0000000..62782e5 --- /dev/null +++ b/tcl8.6/doc/next.n @@ -0,0 +1,208 @@ +'\" +'\" Copyright (c) 2007 Donal K. Fellows +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH next n 0.1 TclOO "TclOO Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +next, nextto \- invoke superclass method implementations +.SH SYNOPSIS +.nf +package require TclOO + +\fBnext\fR ?\fIarg ...\fR? +\fBnextto\fI class\fR ?\fIarg ...\fR? +.fi +.BE + +.SH DESCRIPTION +.PP +The \fBnext\fR command is used to call implementations of a method by a class, +superclass or mixin that are overridden by the current method. It can only be +used from within a method. It is also used within filters to indicate the +point where a filter calls the actual implementation (the filter may decide to +not go along the chain, and may process the results of going along the chain +of methods as it chooses). The result of the \fBnext\fR command is the result +of the next method in the method chain; if there are no further methods in the +method chain, the result of \fBnext\fR will be an error. The arguments, +\fIarg\fR, to \fBnext\fR are the arguments to pass to the next method in the +chain. +.PP +The \fBnextto\fR command is the same as the \fBnext\fR command, except that it +takes an additional \fIclass\fR argument that identifies a class whose +implementation of the current method chain (see \fBinfo object\fR \fBcall\fR) should +be used; the method implementation selected will be the one provided by the +given class, and it must refer to an existing non-filter invocation that lies +further along the chain than the current implementation. +.SH "THE METHOD CHAIN" +.PP +When a method of an object is invoked, things happen in several stages: +.IP [1] +The structure of the object, its class, superclasses, filters, and mixins, are +examined to build a \fImethod chain\fR, which contains a list of method +implementations to invoke. +.IP [2] +The first method implementation on the chain is invoked. +.IP [3] +If that method implementation invokes the \fBnext\fR command, the next method +implementation is invoked (with its arguments being those that were passed to +\fBnext\fR). +.IP [4] +The result from the overall method call is the result from the outermost +method implementation; inner method implementations return their results +through \fBnext\fR. +.IP [5] +The method chain is cached for future use. +.SS "METHOD SEARCH ORDER" +.PP +When constructing the method chain, method implementations are searched for in +the following order: +.IP [1] +In the classes mixed into the object, in class traversal order. The list of +mixins is checked in natural order. +.IP [2] +In the classes mixed into the classes of the object, with sources of mixing in +being searched in class traversal order. Within each class, the list of mixins +is processed in natural order. +.IP [3] +In the object itself. +.IP [4] +In the object's class. +.IP [5] +In the superclasses of the class, following each superclass in a depth-first +fashion in the natural order of the superclass list. +.PP +Any particular method implementation always comes as \fIlate\fR in the +resulting list of implementations as possible; this means that if some class, +A, is both mixed into a class, B, and is also a superclass of B, the instances +of B will always treat A as a superclass from the perspective of inheritance. +This is true even when the multiple inheritance is processed indirectly. +.SS FILTERS +.PP +When an object has a list of filter names set upon it, or is an instance of a +class (or has mixed in a class) that has a list of filter names set upon it, +before every invocation of any method the filters are processed. Filter +implementations are found in class traversal order, as are the lists of filter +names (each of which is traversed in natural list order). Explicitly invoking +a method used as a filter will cause that method to be invoked twice, once as +a filter and once as a normal method. +.PP +Each filter should decide for itself whether to permit the execution to go +forward to the proper implementation of the method (which it does by invoking +the \fBnext\fR command as filters are inserted into the front of the method +call chain) and is responsible for returning the result of \fBnext\fR. +.PP +Filters are invoked when processing an invokation of the \fBunknown\fR +method because of a failure to locate a method implementation, but \fInot\fR +when invoking either constructors or destructors. (Note however that the +\fBdestroy\fR method is a conventional method, and filters are invoked as +normal when it is called.) +.SH EXAMPLES +.PP +This example demonstrates how to use the \fBnext\fR command to call the +(super)class's implementation of a method. The script: +.PP +.CS +oo::class create theSuperclass { + method example {args} { + puts "in the superclass, args = $args" + } +} +oo::class create theSubclass { + superclass theSuperclass + method example {args} { + puts "before chaining from subclass, args = $args" + \fBnext\fR a {*}$args b + \fBnext\fR pureSynthesis + puts "after chaining from subclass" + } +} +theSubclass create obj +oo::objdefine obj method example args { + puts "per-object method, args = $args" + \fBnext\fR x {*}$args y + \fBnext\fR +} +obj example 1 2 3 +.CE +.PP +prints the following: +.PP +.CS +per-object method, args = 1 2 3 +before chaining from subclass, args = x 1 2 3 y +in the superclass, args = a x 1 2 3 y b +in the superclass, args = pureSynthesis +after chaining from subclass +before chaining from subclass, args = +in the superclass, args = a b +in the superclass, args = pureSynthesis +after chaining from subclass +.CE +.PP +This example demonstrates how to build a simple cache class that applies +memoization to all the method calls of the objects it is mixed into, and shows +how it can make a difference to computation times: +.PP +.CS +oo::class create cache { + filter Memoize + method Memoize args { + \fI# Do not filter the core method implementations\fR + if {[lindex [self target] 0] eq "::oo::object"} { + return [\fBnext\fR {*}$args] + } + + \fI# Check if the value is already in the cache\fR + my variable ValueCache + set key [self target],$args + if {[info exist ValueCache($key)]} { + return $ValueCache($key) + } + + \fI# Compute value, insert into cache, and return it\fR + return [set ValueCache($key) [\fBnext\fR {*}$args]] + } + method flushCache {} { + my variable ValueCache + unset ValueCache + \fI# Skip the caching\fR + return -level 2 "" + } +} + +oo::object create demo +oo::objdefine demo { + mixin cache + method compute {a b c} { + after 3000 \fI;# Simulate deep thought\fR + return [expr {$a + $b * $c}] + } + method compute2 {a b c} { + after 3000 \fI;# Simulate deep thought\fR + return [expr {$a * $b + $c}] + } +} + +puts [demo compute 1 2 3] \fI\(-> prints "7" after delay\fR +puts [demo compute2 4 5 6] \fI\(-> prints "26" after delay\fR +puts [demo compute 1 2 3] \fI\(-> prints "7" instantly\fR +puts [demo compute2 4 5 6] \fI\(-> prints "26" instantly\fR +puts [demo compute 4 5 6] \fI\(-> prints "34" after delay\fR +puts [demo compute 4 5 6] \fI\(-> prints "34" instantly\fR +puts [demo compute 1 2 3] \fI\(-> prints "7" instantly\fR +demo flushCache +puts [demo compute 1 2 3] \fI\(-> prints "7" after delay\fR +.CE +.SH "SEE ALSO" +oo::class(n), oo::define(n), oo::object(n), self(n) +.SH KEYWORDS +call, method, method chain +.\" Local variables: +.\" mode: nroff +.\" fill-column: 78 +.\" End: diff --git a/tcl8.6/doc/object.n b/tcl8.6/doc/object.n new file mode 100644 index 0000000..df657a9 --- /dev/null +++ b/tcl8.6/doc/object.n @@ -0,0 +1,128 @@ +'\" +'\" Copyright (c) 2007-2008 Donal K. Fellows +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH object n 0.1 TclOO "TclOO Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +oo::object \- root class of the class hierarchy +.SH SYNOPSIS +.nf +package require TclOO + +\fBoo::object\fI method \fR?\fIarg ...\fR? +.fi +.SH "CLASS HIERARCHY" +.nf +\fBoo::object\fR +.fi +.BE +.SH DESCRIPTION +.PP +The \fBoo::object\fR class is the root class of the object hierarchy; every +object is an instance of this class. Since classes are themselves objects, +they are instances of this class too. Objects are always referred to by their +name, and may be \fBrename\fRd while maintaining their identity. +.PP +Instances of objects may be made with either the \fBcreate\fR or \fBnew\fR +methods of the \fBoo::object\fR object itself, or by invoking those methods on +any of the subclass objects; see \fBoo::class\fR for more details. The +configuration of individual objects (i.e., instance-specific methods, mixed-in +classes, etc.) may be controlled with the \fBoo::objdefine\fR command. +.PP +Each object has a unique namespace associated with it, the instance namespace. +This namespace holds all the instance variables of the object, and will be the +current namespace whenever a method of the object is invoked (including a +method of the class of the object). When the object is destroyed, its instance +namespace is deleted. The instance namespace contains the object's \fBmy\fR +command, which may be used to invoke non-exported methods of the object or to +create a reference to the object for the purpose of invocation which persists +across renamings of the object. +.SS CONSTRUCTOR +The \fBoo::object\fR class does not define an explicit constructor. +.SS DESTRUCTOR +The \fBoo::object\fR class does not define an explicit destructor. +.SS "EXPORTED METHODS" +The \fBoo::object\fR class supports the following exported methods: +.TP +\fIobj \fBdestroy\fR +. +This method destroys the object, \fIobj\fR, that it is invoked upon, invoking +any destructors on the object's class in the process. It is equivalent to +using \fBrename\fR to delete the object command. The result of this method is +always the empty string. +.SS "NON-EXPORTED METHODS" +.PP +The \fBoo::object\fR class supports the following non-exported methods: +.TP +\fIobj \fBeval\fR ?\fIarg ...\fR? +. +This method concatenates the arguments, \fIarg\fR, as if with \fBconcat\fR, +and then evaluates the resulting script in the namespace that is uniquely +associated with \fIobj\fR, returning the result of the evaluation. +.TP +\fIobj \fBunknown ?\fImethodName\fR? ?\fIarg ...\fR? +. +This method is called when an attempt to invoke the method \fImethodName\fR on +object \fIobj\fR fails. The arguments that the user supplied to the method are +given as \fIarg\fR arguments. +.VS +If \fImethodName\fR is absent, the object was invoked with no method name at +all (or any other arguments). +.VE +The default implementation (i.e., the one defined by the \fBoo::object\fR +class) generates a suitable error, detailing what methods the object supports +given whether the object was invoked by its public name or through the +\fBmy\fR command. +.TP +\fIobj \fBvariable \fR?\fIvarName ...\fR? +. +This method arranges for each variable called \fIvarName\fR to be linked from +the object \fIobj\fR's unique namespace into the caller's context. Thus, if it +is invoked from inside a procedure then the namespace variable in the object +is linked to the local variable in the procedure. Each \fIvarName\fR argument +must not have any namespace separators in it. The result is the empty string. +.TP +\fIobj \fBvarname \fIvarName\fR +. +This method returns the globally qualified name of the variable \fIvarName\fR +in the unique namespace for the object \fIobj\fR. +.TP +\fIobj \fB<cloned> \fIsourceObjectName\fR +.VS +This method is used by the \fBoo::object\fR command to copy the state of one +object to another. It is responsible for copying the procedures and variables +of the namespace of the source object (\fIsourceObjectName\fR) to the current +object. It does not copy any other types of commands or any traces on the +variables; that can be added if desired by overriding this method in a +subclass. +.VE +.SH EXAMPLES +.PP +This example demonstrates basic use of an object. +.PP +.CS +set obj [\fBoo::object\fR new] +$obj foo \fI\(-> error "unknown method foo"\fR +oo::objdefine $obj method foo {} { + my \fBvariable\fR count + puts "bar[incr count]" +} +$obj foo \fI\(-> prints "bar1"\fR +$obj foo \fI\(-> prints "bar2"\fR +$obj variable count \fI\(-> error "unknown method variable"\fR +$obj \fBdestroy\fR +$obj foo \fI\(-> error "unknown command obj"\fR +.CE +.SH "SEE ALSO" +my(n), oo::class(n) +.SH KEYWORDS +base class, class, object, root class +.\" Local variables: +.\" mode: nroff +.\" fill-column: 78 +.\" End: diff --git a/tcl8.6/doc/open.n b/tcl8.6/doc/open.n new file mode 100644 index 0000000..1cccc0a --- /dev/null +++ b/tcl8.6/doc/open.n @@ -0,0 +1,430 @@ +'\" +'\" Copyright (c) 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. +'\" +.TH open n 8.3 Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +open \- Open a file-based or command pipeline channel +.SH SYNOPSIS +.sp +\fBopen \fIfileName\fR +.br +\fBopen \fIfileName access\fR +.br +\fBopen \fIfileName access permissions\fR +.BE +.SH DESCRIPTION +.PP +This command opens a file, serial port, or command pipeline and returns a +channel identifier that may be used in future invocations of commands like +\fBread\fR, \fBputs\fR, and \fBclose\fR. +If the first character of \fIfileName\fR is not \fB|\fR then +the command opens a file: +\fIfileName\fR gives the name of the file to open, and it must conform to the +conventions described in the \fBfilename\fR manual entry. +.PP +The \fIaccess\fR argument, if present, indicates the way in which the file +(or command pipeline) is to be accessed. +In the first form \fIaccess\fR may have any of the following values: +.TP 15 +\fBr\fR +. +Open the file for reading only; the file must already exist. This is the +default value if \fIaccess\fR is not specified. +.TP 15 +\fBr+\fR +. +Open the file for both reading and writing; the file must +already exist. +.TP 15 +\fBw\fR +. +Open the file for writing only. Truncate it if it exists. If it does not +exist, create a new file. +.TP 15 +\fBw+\fR +. +Open the file for reading and writing. Truncate it if it exists. +If it does not exist, create a new file. +.TP 15 +\fBa\fR +. +Open the file for writing only. If the file does not exist, +create a new empty file. +Set the file pointer to the end of the file prior to each write. +.TP 15 +\fBa+\fR +. +Open the file for reading and writing. If the file does not exist, +create a new empty file. +Set the initial access position to the end of the file. +.PP +All of the legal \fIaccess\fR values above may have the character +\fBb\fR added as the second or third character in the value to +indicate that the opened channel should be configured as if with the +\fBfconfigure\fR \fB\-translation binary\fR option, making the channel suitable for +reading or writing of binary data. +.PP +In the second form, \fIaccess\fR consists of a list of any of the +following flags, all of which have the standard POSIX meanings. +One of the flags must be either \fBRDONLY\fR, \fBWRONLY\fR or \fBRDWR\fR. +.TP 15 +\fBRDONLY\fR +. +Open the file for reading only. +.TP 15 +\fBWRONLY\fR +. +Open the file for writing only. +.TP 15 +\fBRDWR\fR +. +Open the file for both reading and writing. +.TP 15 +\fBAPPEND\fR +. +Set the file pointer to the end of the file prior to each write. +.TP 15 +\fBBINARY\fR +. +Configure the opened channel with the \fB\-translation binary\fR option. +.TP 15 +\fBCREAT\fR +. +Create the file if it does not already exist (without this flag it +is an error for the file not to exist). +.TP 15 +\fBEXCL\fR +. +If \fBCREAT\fR is also specified, an error is returned if the +file already exists. +.TP 15 +\fBNOCTTY\fR +. +If the file is a terminal device, this flag prevents the file from +becoming the controlling terminal of the process. +.TP 15 +\fBNONBLOCK\fR +. +Prevents the process from blocking while opening the file, and +possibly in subsequent I/O operations. The exact behavior of +this flag is system- and device-dependent; its use is discouraged +(it is better to use the \fBfconfigure\fR command to put a file +in nonblocking mode). +For details refer to your system documentation on the \fBopen\fR system +call's \fBO_NONBLOCK\fR flag. +.TP 15 +\fBTRUNC\fR +. +If the file exists it is truncated to zero length. +.PP +If a new file is created as part of opening it, \fIpermissions\fR +(an integer) is used to set the permissions for the new file in +conjunction with the process's file mode creation mask. +\fIPermissions\fR defaults to 0666. +.SH "COMMAND PIPELINES" +.PP +If the first character of \fIfileName\fR is +.QW \fB|\fR +then the +remaining characters of \fIfileName\fR are treated as a list of arguments +that describe a command pipeline to invoke, in the same style as the +arguments for \fBexec\fR. +In this case, the channel identifier returned by \fBopen\fR may be used +to write to the command's input pipe or read from its output pipe, +depending on the value of \fIaccess\fR. +If write-only access is used (e.g. \fIaccess\fR is +.QW \fBw\fR ), +then standard output for the pipeline is directed to the current standard +output unless overridden by the command. +If read-only access is used (e.g. \fIaccess\fR is +.QW \fBr\fR ), +standard input for the pipeline is taken from the current standard +input unless overridden by the command. +The id of the spawned process is accessible through the \fBpid\fR +command, using the channel id returned by \fBopen\fR as argument. +.PP +If the command (or one of the commands) executed in the command +pipeline returns an error (according to the definition in \fBexec\fR), +a Tcl error is generated when \fBclose\fR is called on the channel +unless the pipeline is in non-blocking mode then no exit status is +returned (a silent \fBclose\fR with -blocking 0). +.PP +It is often useful to use the \fBfileevent\fR command with pipelines +so other processing may happen at the same time as running the command +in the background. +.SH "SERIAL COMMUNICATIONS" +.PP +If \fIfileName\fR refers to a serial port, then the specified serial port +is opened and initialized in a platform-dependent manner. Acceptable +values for the \fIfileName\fR to use to open a serial port are described in +the PORTABILITY ISSUES section. +.PP +The \fBfconfigure\fR command can be used to query and set additional +configuration options specific to serial ports (where supported): +.TP +\fB\-mode\fR \fIbaud\fB,\fIparity\fB,\fIdata\fB,\fIstop\fR +. +This option is a set of 4 comma-separated values: the baud rate, parity, +number of data bits, and number of stop bits for this serial port. The +\fIbaud\fR rate is a simple integer that specifies the connection speed. +\fIParity\fR is one of the following letters: \fBn\fR, \fBo\fR, \fBe\fR, +\fBm\fR, \fBs\fR; respectively signifying the parity options of +.QW none , +.QW odd , +.QW even , +.QW mark , +or +.QW space . +\fIData\fR is the number of +data bits and should be an integer from 5 to 8, while \fIstop\fR is the +number of stop bits and should be the integer 1 or 2. +.TP +\fB\-handshake\fR \fItype\fR +. +(Windows and Unix). This option is used to setup automatic handshake +control. Note that not all handshake types maybe supported by your operating +system. The \fItype\fR parameter is case-independent. +.RS +.PP +If \fItype\fR is \fBnone\fR then any handshake is switched off. +\fBrtscts\fR activates hardware handshake. Hardware handshake signals +are described below. +For software handshake \fBxonxoff\fR the handshake characters can be redefined +with \fB\-xchar\fR. +An additional hardware handshake \fBdtrdsr\fR is available only under Windows. +There is no default handshake configuration, the initial value depends +on your operating system settings. +The \fB\-handshake\fR option cannot be queried. +.RE +.TP +\fB\-queue\fR +. +(Windows and Unix). The \fB\-queue\fR option can only be queried. +It returns a list of two integers representing the current number +of bytes in the input and output queue respectively. +.TP +\fB\-timeout\fR \fImsec\fR +. +(Windows and Unix). This option is used to set the timeout for blocking +read operations. It specifies the maximum interval between the +reception of two bytes in milliseconds. +For Unix systems the granularity is 100 milliseconds. +The \fB\-timeout\fR option does not affect write operations or +nonblocking reads. +This option cannot be queried. +.TP +\fB\-ttycontrol\fR \fI{signal boolean signal boolean ...}\fR +. +(Windows and Unix). This option is used to setup the handshake +output lines (see below) permanently or to send a BREAK over the serial line. +The \fIsignal\fR names are case-independent. +\fB{RTS 1 DTR 0}\fR sets the RTS output to high and the DTR output to low. +The BREAK condition (see below) is enabled and disabled with \fB{BREAK 1}\fR and +\fB{BREAK 0}\fR respectively. +It is not a good idea to change the \fBRTS\fR (or \fBDTR\fR) signal +with active hardware handshake \fBrtscts\fR (or \fBdtrdsr\fR). +The result is unpredictable. +The \fB\-ttycontrol\fR option cannot be queried. +.TP +\fB\-ttystatus\fR +. +(Windows and Unix). The \fB\-ttystatus\fR option can only be +queried. It returns the current modem status and handshake input signals +(see below). +The result is a list of signal,value pairs with a fixed order, +e.g. \fB{CTS 1 DSR 0 RING 1 DCD 0}\fR. +The \fIsignal\fR names are returned upper case. +.TP +\fB\-xchar\fR \fI{xonChar xoffChar}\fR +. +(Windows and Unix). This option is used to query or change the software +handshake characters. Normally the operating system default should be +DC1 (0x11) and DC3 (0x13) representing the ASCII standard +XON and XOFF characters. +.TP +\fB\-pollinterval\fR \fImsec\fR +. +(Windows only). This option is used to set the maximum time between +polling for fileevents. +This affects the time interval between checking for events throughout the Tcl +interpreter (the smallest value always wins). Use this option only if +you want to poll the serial port more or less often than 10 msec +(the default). +.TP +\fB\-sysbuffer\fR \fIinSize\fR +.TP +\fB\-sysbuffer\fR \fI{inSize outSize}\fR +. +(Windows only). This option is used to change the size of Windows +system buffers for a serial channel. Especially at higher communication +rates the default input buffer size of 4096 bytes can overrun +for latent systems. The first form specifies the input buffer size, +in the second form both input and output buffers are defined. +.TP +\fB\-lasterror\fR +. +(Windows only). This option is query only. +In case of a serial communication error, \fBread\fR or \fBputs\fR +returns a general Tcl file I/O error. +\fBfconfigure\fR \fB\-lasterror\fR can be called to get a list of error details. +See below for an explanation of the various error codes. +.SH "SERIAL PORT SIGNALS" +.PP +RS-232 is the most commonly used standard electrical interface for serial +communications. A negative voltage (-3V..-12V) define a mark (on=1) bit and +a positive voltage (+3..+12V) define a space (off=0) bit (RS-232C). The +following signals are specified for incoming and outgoing data, status +lines and handshaking. Here we are using the terms \fIworkstation\fR for +your computer and \fImodem\fR for the external device, because some signal +names (DCD, RI) come from modems. Of course your external device may use +these signal lines for other purposes. +.IP \fBTXD\fR(output) +\fBTransmitted Data:\fR Outgoing serial data. +.IP \fBRXD\fR(input) +\fBReceived Data:\fRIncoming serial data. +.IP \fBRTS\fR(output) +\fBRequest To Send:\fR This hardware handshake line informs the modem that +your workstation is ready to receive data. Your workstation may +automatically reset this signal to indicate that the input buffer is full. +.IP \fBCTS\fR(input) +\fBClear To Send:\fR The complement to RTS. Indicates that the modem is +ready to receive data. +.IP \fBDTR\fR(output) +\fBData Terminal Ready:\fR This signal tells the modem that the workstation +is ready to establish a link. DTR is often enabled automatically whenever a +serial port is opened. +.IP \fBDSR\fR(input) +\fBData Set Ready:\fR The complement to DTR. Tells the workstation that the +modem is ready to establish a link. +.IP \fBDCD\fR(input) +\fBData Carrier Detect:\fR This line becomes active when a modem detects a +.QW Carrier +signal. +.IP \fBRI\fR(input) +\fBRing Indicator:\fR Goes active when the modem detects an incoming call. +.IP \fBBREAK\fR +A BREAK condition is not a hardware signal line, but a logical zero on the +TXD or RXD lines for a long period of time, usually 250 to 500 +milliseconds. Normally a receive or transmit data signal stays at the mark +(on=1) voltage until the next character is transferred. A BREAK is sometimes +used to reset the communications line or change the operating mode of +communications hardware. +.SH "ERROR CODES (Windows only)" +.PP +A lot of different errors may occur during serial read operations or during +event polling in background. The external device may have been switched +off, the data lines may be noisy, system buffers may overrun or your mode +settings may be wrong. That is why a reliable software should always +\fBcatch\fR serial read operations. In cases of an error Tcl returns a +general file I/O error. Then \fBfconfigure\fR \fB\-lasterror\fR may help to +locate the problem. The following error codes may be returned. +.TP 10 +\fBRXOVER\fR +. +Windows input buffer overrun. The data comes faster than your scripts reads +it or your system is overloaded. Use \fBfconfigure\fR \fB\-sysbuffer\fR to avoid a +temporary bottleneck and/or make your script faster. +.TP 10 +\fBTXFULL\fR +. +Windows output buffer overrun. Complement to RXOVER. This error should +practically not happen, because Tcl cares about the output buffer status. +.TP 10 +\fBOVERRUN\fR +. +UART buffer overrun (hardware) with data lost. +The data comes faster than the system driver receives it. +Check your advanced serial port settings to enable the FIFO (16550) buffer +and/or setup a lower(1) interrupt threshold value. +.TP 10 +\fBRXPARITY\fR +. +A parity error has been detected by your UART. +Wrong parity settings with \fBfconfigure\fR \fB\-mode\fR or a noisy data line (RXD) +may cause this error. +.TP 10 +\fBFRAME\fR +. +A stop-bit error has been detected by your UART. +Wrong mode settings with \fBfconfigure\fR \fB\-mode\fR or a noisy data line (RXD) +may cause this error. +.TP 10 +\fBBREAK\fR +. +A BREAK condition has been detected by your UART (see above). +.SH "PORTABILITY ISSUES" +.TP +\fBWindows \fR +. +Valid values for \fIfileName\fR to open a serial port are of the form +\fBcom\fIX\fB\fR, where \fIX\fR is a number, generally from 1 to 9. +A legacy form accepted as well is \fBcom\fIX\fB:\fR. This notation only +works for serial ports from 1 to 9. An attempt to open a serial port that +does not exist or has a number greater than 9 will fail. An alternate +form of opening serial ports is to use the filename \fB//./comX\fR, +where X is any number that corresponds to a serial port. +.PP +.RS +When running Tcl interactively, there may be some strange interactions +between the real console, if one is present, and a command pipeline that uses +standard input or output. If a command pipeline is opened for reading, some +of the lines entered at the console will be sent to the command pipeline and +some will be sent to the Tcl evaluator. If a command pipeline is opened for +writing, keystrokes entered into the console are not visible until the +pipe is closed. These problems only occur because both Tcl and the child +application are competing for the console at the same time. If the command +pipeline is started from a script, so that Tcl is not accessing the console, +or if the command pipeline does not use standard input or output, but is +redirected from or to a file, then the above problems do not occur. +.RE +.TP +\fBUnix\fR\0\0\0\0\0\0\0 +. +Valid values for \fIfileName\fR to open a serial port are generally of the +form \fB/dev/tty\fIX\fR, where \fIX\fR is \fBa\fR or \fBb\fR, but the name +of any pseudo-file that maps to a serial port may be used. +Advanced configuration options are only supported for serial ports +when Tcl is built to use the POSIX serial interface. +.RS +.PP +When running Tcl interactively, there may be some strange interactions +between the console, if one is present, and a command pipeline that uses +standard input. If a command pipeline is opened for reading, some +of the lines entered at the console will be sent to the command pipeline and +some will be sent to the Tcl evaluator. This problem only occurs because +both Tcl and the child application are competing for the console at the +same time. If the command pipeline is started from a script, so that Tcl is +not accessing the console, or if the command pipeline does not use standard +input, but is redirected from a file, then the above problem does not occur. +.RE +.PP +See the \fBPORTABILITY ISSUES\fR section of the \fBexec\fR command for +additional information not specific to command pipelines about executing +applications on the various platforms +.SH "EXAMPLE" +.PP +Open a command pipeline and catch any errors: +.PP +.CS +set fl [\fBopen\fR "| ls this_file_does_not_exist"] +set data [read $fl] +if {[catch {close $fl} err]} { + puts "ls command failed: $err" +} +.CE +.SH "SEE ALSO" +file(n), close(n), filename(n), fconfigure(n), gets(n), read(n), +puts(n), exec(n), pid(n), fopen(3) +.SH KEYWORDS +access mode, append, create, file, non-blocking, open, permissions, +pipeline, process, serial +'\"Local Variables: +'\"mode: nroff +'\"End: diff --git a/tcl8.6/doc/package.n b/tcl8.6/doc/package.n new file mode 100644 index 0000000..a6a972f --- /dev/null +++ b/tcl8.6/doc/package.n @@ -0,0 +1,370 @@ +'\" +'\" Copyright (c) 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. +'\" +.TH package n 7.5 Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +package \- Facilities for package loading and version control +.SH SYNOPSIS +.nf +\fBpackage forget\fR ?\fIpackage package ...\fR? +\fBpackage ifneeded \fIpackage version\fR ?\fIscript\fR? +\fBpackage names\fR +\fBpackage present \fIpackage \fR?\fIrequirement...\fR? +\fBpackage present \-exact \fIpackage version\fR +\fBpackage provide \fIpackage \fR?\fIversion\fR? +\fBpackage require \fIpackage \fR?\fIrequirement...\fR? +\fBpackage require \-exact \fIpackage version\fR +\fBpackage unknown \fR?\fIcommand\fR? +\fBpackage vcompare \fIversion1 version2\fR +\fBpackage versions \fIpackage\fR +\fBpackage vsatisfies \fIversion requirement...\fR +\fBpackage prefer \fR?\fBlatest\fR|\fBstable\fR? +.fi +.BE +.SH DESCRIPTION +.PP +This command keeps a simple database of the packages available for +use by the current interpreter and how to load them into the +interpreter. +It supports multiple versions of each package and arranges +for the correct version of a package to be loaded based on what +is needed by the application. +This command also detects and reports version clashes. +Typically, only the \fBpackage require\fR and \fBpackage provide\fR +commands are invoked in normal Tcl scripts; the other commands are used +primarily by system scripts that maintain the package database. +.PP +The behavior of the \fBpackage\fR command is determined by its first argument. +The following forms are permitted: +.TP +\fBpackage forget\fR ?\fIpackage package ...\fR? +. +Removes all information about each specified package from this interpreter, +including information provided by both \fBpackage ifneeded\fR and +\fBpackage provide\fR. +.TP +\fBpackage ifneeded \fIpackage version\fR ?\fIscript\fR? +. +This command typically appears only in system configuration +scripts to set up the package database. +It indicates that a particular version of +a particular package is available if needed, and that the package +can be added to the interpreter by executing \fIscript\fR. +The script is saved in a database for use by subsequent +\fBpackage require\fR commands; typically, \fIscript\fR +sets up auto-loading for the commands in the package (or calls +\fBload\fR and/or \fBsource\fR directly), then invokes +\fBpackage provide\fR to indicate that the package is present. +There may be information in the database for several different +versions of a single package. +If the database already contains information for \fIpackage\fR +and \fIversion\fR, the new \fIscript\fR replaces the existing +one. +If the \fIscript\fR argument is omitted, the current script for +version \fIversion\fR of package \fIpackage\fR is returned, +or an empty string if no \fBpackage ifneeded\fR command has +been invoked for this \fIpackage\fR and \fIversion\fR. +.TP +\fBpackage names\fR +. +Returns a list of the names of all packages in the +interpreter for which a version has been provided (via +\fBpackage provide\fR) or for which a \fBpackage ifneeded\fR +script is available. +The order of elements in the list is arbitrary. +.TP +\fBpackage present\fR ?\fB\-exact\fR? \fIpackage\fR ?\fIrequirement...\fR? +. +This command is equivalent to \fBpackage require\fR except that it +does not try and load the package if it is not already loaded. +.TP +\fBpackage provide \fIpackage \fR?\fIversion\fR? +. +This command is invoked to indicate that version \fIversion\fR +of package \fIpackage\fR is now present in the interpreter. +It is typically invoked once as part of an \fBifneeded\fR script, +and again by the package itself when it is finally loaded. +An error occurs if a different version of \fIpackage\fR has been +provided by a previous \fBpackage provide\fR command. +If the \fIversion\fR argument is omitted, then the command +returns the version number that is currently provided, or an +empty string if no \fBpackage provide\fR command has been +invoked for \fIpackage\fR in this interpreter. +.TP +\fBpackage require \fR\fIpackage \fR?\fIrequirement...\fR? +. +This command is typically invoked by Tcl code that wishes to use +a particular version of a particular package. The arguments +indicate which package is wanted, and the command ensures that +a suitable version of the package is loaded into the interpreter. +If the command succeeds, it returns the version number that is +loaded; otherwise it generates an error. +.RS +.PP +A suitable version of the package is any version which satisfies at +least one of the requirements, per the rules of \fBpackage +vsatisfies\fR. If multiple versions are suitable the implementation +with the highest version is chosen. This last part is additionally +influenced by the selection mode set with \fBpackage prefer\fR. +.PP +In the +.QW stable +selection mode the command will select the highest +stable version satisfying the requirements, if any. If no stable +version satisfies the requirements, the highest unstable version +satisfying the requirements will be selected. In the +.QW latest +selection mode the command will accept the highest version satisfying +all the requirements, regardless of its stableness. +.PP +If a version of \fIpackage\fR has already been provided (by invoking +the \fBpackage provide\fR command), then its version number must +satisfy the \fIrequirement\fRs and the command returns immediately. +Otherwise, the command searches the database of information provided by +previous \fBpackage ifneeded\fR commands to see if an acceptable +version of the package is available. +If so, the script for the highest acceptable version number is evaluated +in the global namespace; +it must do whatever is necessary to load the package, +including calling \fBpackage provide\fR for the package. +If the \fBpackage ifneeded\fR database does not contain an acceptable +version of the package and a \fBpackage unknown\fR command has been +specified for the interpreter then that command is evaluated in the +global namespace; when +it completes, Tcl checks again to see if the package is now provided +or if there is a \fBpackage ifneeded\fR script for it. +If all of these steps fail to provide an acceptable version of the +package, then the command returns an error. +.RE +.TP +\fBpackage require \-exact \fIpackage version\fR +. +This form of the command is used when only the given \fIversion\fR +of \fIpackage\fR is acceptable to the caller. This command is +equivalent to \fBpackage require \fIpackage version\fR-\fIversion\fR. +.TP +\fBpackage unknown \fR?\fIcommand\fR? +. +This command supplies a +.QW "last resort" +command to invoke during +\fBpackage require\fR if no suitable version of a package can be found +in the \fBpackage ifneeded\fR database. +If the \fIcommand\fR argument is supplied, it contains the first part +of a command; when the command is invoked during a \fBpackage require\fR +command, Tcl appends one or more additional arguments giving the desired +package name and requirements. +For example, if \fIcommand\fR is \fBfoo bar\fR and later the command +\fBpackage require test 2.4\fR is invoked, then Tcl will execute +the command \fBfoo bar test 2.4\fR to load the package. +If no requirements are supplied to the \fBpackage require\fR command, +then only the name will be added to invoked command. +If the \fBpackage unknown\fR command is invoked without a \fIcommand\fR +argument, then the current \fBpackage unknown\fR script is returned, +or an empty string if there is none. +If \fIcommand\fR is specified as an empty string, then the current +\fBpackage unknown\fR script is removed, if there is one. +.TP +\fBpackage vcompare \fIversion1 version2\fR +. +Compares the two version numbers given by \fIversion1\fR and \fIversion2\fR. +Returns -1 if \fIversion1\fR is an earlier version than \fIversion2\fR, +0 if they are equal, and 1 if \fIversion1\fR is later than \fIversion2\fR. +.TP +\fBpackage versions \fIpackage\fR +. +Returns a list of all the version numbers of \fIpackage\fR +for which information has been provided by \fBpackage ifneeded\fR +commands. +.TP +\fBpackage vsatisfies \fIversion requirement...\fR +. +Returns 1 if the \fIversion\fR satisfies at least one of the given +requirements, and 0 otherwise. Each \fIrequirement\fR is allowed to +have any of the forms: +.RS +.TP +min +. +This form is called +.QW min-bounded . +.TP +min- +. +This form is called +.QW min-unbound . +.TP +min-max +. +This form is called +.QW bounded . +.RE +.RS +.PP +where +.QW min +and +.QW max +are valid version numbers. The legacy syntax is +a special case of the extended syntax, keeping backward +compatibility. Regarding satisfaction the rules are: +.RE +.RS +.IP [1] +The \fIversion\fR has to pass at least one of the listed +\fIrequirement\fRs to be satisfactory. +.IP [2] +A version satisfies a +.QW bounded +requirement when +.RS +.IP [a] +For \fImin\fR equal to the \fImax\fR if, and only if the \fIversion\fR +is equal to the \fImin\fR. +.IP [b] +Otherwise if, and only if the \fIversion\fR is greater than or equal +to the \fImin\fR, and less than the \fImax\fR, where both \fImin\fR +and \fImax\fR have been padded internally with +.QW a0 . +Note that while the comparison to \fImin\fR is inclusive, the +comparison to \fImax\fR is exclusive. +.RE +.IP [3] +A +.QW min-bounded +requirement is a +.QW bounded +requirement in disguise, +with the \fImax\fR part implicitly specified as the next higher major +version number of the \fImin\fR part. A version satisfies it per the +rules above. +.IP [4] +A \fIversion\fR satisfies a +.QW min-unbound +requirement if, and only if it is greater than or equal to the +\fImin\fR, where the \fImin\fR has been padded internally with +.QW a0 . +There is no constraint to a maximum. +.RE +.TP +\fBpackage prefer \fR?\fBlatest\fR|\fBstable\fR? +With no arguments, the commands returns either +.QW latest +or +.QW stable , +whichever describes the current mode of selection logic used by +\fBpackage require\fR. +.RS +.PP +When passed the argument +.QW latest , +it sets the selection logic mode to +.QW latest . +.PP +When passed the argument +.QW stable , +if the mode is already +.QW stable , +that value is kept. If the mode is already +.QW latest , +then the attempt to set it back to +.QW stable +is ineffective and the mode value remains +.QW latest . +.PP +When passed any other value as an argument, raise an invalid argument +error. +.PP +When an interpreter is created, its initial selection mode value is set to +.QW stable +unless the environment variable \fBTCL_PKG_PREFER_LATEST\fR +is set. If that environment variable is defined (with any value) then +the initial (and permanent) selection mode value is set to +.QW latest . +.RE +.SH "VERSION NUMBERS" +.PP +Version numbers consist of one or more decimal numbers separated +by dots, such as 2 or 1.162 or 3.1.13.1. +The first number is called the major version number. +Larger numbers correspond to later versions of a package, with +leftmost numbers having greater significance. +For example, version 2.1 is later than 1.3 and version +3.4.6 is later than 3.3.5. +Missing fields are equivalent to zeroes: version 1.3 is the +same as version 1.3.0 and 1.3.0.0, so it is earlier than 1.3.1 or 1.3.0.2. +In addition, the letters +.QW a +(alpha) and/or +.QW b +(beta) may appear +exactly once to replace a dot for separation. These letters +semantically add a negative specifier into the version, where +.QW a +is \-2, and +.QW b +is \-1. Each may be specified only once, and +.QW a +or +.QW b +are mutually exclusive in a specifier. Thus 1.3a1 becomes (semantically) +1.3.\-2.1, 1.3b1 is 1.3.\-1.1. Negative numbers are not directly allowed +in version specifiers. +A version number not containing the letters +.QW a +or +.QW b +as specified +above is called a \fBstable\fR version, whereas presence of the letters +causes the version to be called is \fBunstable\fR. +A later version number is assumed to be upwards compatible with +an earlier version number as long as both versions have the same +major version number. +For example, Tcl scripts written for version 2.3 of a package should +work unchanged under versions 2.3.2, 2.4, and 2.5.1. +Changes in the major version number signify incompatible changes: +if code is written to use version 2.1 of a package, it is not guaranteed +to work unmodified with either version 1.7.3 or version 3.1. +.SH "PACKAGE INDICES" +.PP +The recommended way to use packages in Tcl is to invoke \fBpackage require\fR +and \fBpackage provide\fR commands in scripts, and use the procedure +\fBpkg_mkIndex\fR to create package index files. +Once you have done this, packages will be loaded automatically +in response to \fBpackage require\fR commands. +See the documentation for \fBpkg_mkIndex\fR for details. +.SH EXAMPLES +.PP +To state that a Tcl script requires the Tk and http packages, put this +at the top of the script: +.PP +.CS +\fBpackage require\fR Tk +\fBpackage require\fR http +.CE +.PP +To test to see if the Snack package is available and load if it is +(often useful for optional enhancements to programs where the loss of +the functionality is not critical) do this: +.PP +.CS +if {[catch {\fBpackage require\fR Snack}]} { + # Error thrown - package not found. + # Set up a dummy interface to work around the absence +} else { + # We have the package, configure the app to use it +} +.CE +.SH "SEE ALSO" +msgcat(n), packagens(n), pkgMkIndex(n) +.SH KEYWORDS +package, version +'\" Local Variables: +'\" mode: nroff +'\" End: diff --git a/tcl8.6/doc/packagens.n b/tcl8.6/doc/packagens.n new file mode 100644 index 0000000..61e7eca --- /dev/null +++ b/tcl8.6/doc/packagens.n @@ -0,0 +1,50 @@ +'\" +'\" Copyright (c) 1998-2000 by Scriptics Corporation. +'\" All rights reserved. +'\" +.TH pkg::create n 8.3 Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +pkg::create \- Construct an appropriate 'package ifneeded' command for a given package specification +.SH SYNOPSIS +\fB::pkg::create\fR \fB\-name \fIpackageName \fB\-version \fIpackageVersion\fR ?\fB\-load \fIfilespec\fR? ... ?\fB\-source \fIfilespec\fR? ... +.BE + +.SH DESCRIPTION +.PP +\fB::pkg::create\fR is a utility procedure that is part of the standard Tcl +library. It is used to create an appropriate \fBpackage ifneeded\fR +command for a given package specification. It can be used to construct a +\fBpkgIndex.tcl\fR file for use with the \fBpackage\fR mechanism. + +.SH OPTIONS +The parameters supported are: +.TP +\fB\-name \fIpackageName\fR +This parameter specifies the name of the package. It is required. +.TP +\fB\-version \fIpackageVersion\fR +This parameter specifies the version of the package. It is required. +.TP +\fB\-load \fIfilespec\fR +This parameter specifies a binary library that must be loaded with the +\fBload\fR command. \fIfilespec\fR is a list with two elements. The +first element is the name of the file to load. The second, optional +element is a list of commands supplied by loading that file. If the +list of procedures is empty or omitted, \fB::pkg::create\fR will +set up the library for direct loading (see \fBpkg_mkIndex\fR). Any +number of \fB\-load\fR parameters may be specified. +.TP +\fB\-source \fIfilespec\fR +This parameter is similar to the \fB\-load\fR parameter, except that it +specifies a Tcl library that must be loaded with the +\fBsource\fR command. Any number of \fB\-source\fR parameters may be +specified. +.PP +At least one \fB\-load\fR or \fB\-source\fR parameter must be given. +.SH "SEE ALSO" +package(n) +.SH KEYWORDS +auto-load, index, package, version diff --git a/tcl8.6/doc/pid.n b/tcl8.6/doc/pid.n new file mode 100644 index 0000000..a4df2f3 --- /dev/null +++ b/tcl8.6/doc/pid.n @@ -0,0 +1,48 @@ +'\" +'\" Copyright (c) 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. +'\" +.TH pid n 7.0 Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +pid \- Retrieve process identifiers +.SH SYNOPSIS +\fBpid \fR?\fIfileId\fR? +.BE + +.SH DESCRIPTION +.PP +If the \fIfileId\fR argument is given then it should normally +refer to a process pipeline created with the \fBopen\fR command. +In this case the \fBpid\fR command will return a list whose elements +are the process identifiers of all the processes in the pipeline, +in order. +The list will be empty if \fIfileId\fR refers to an open file +that is not a process pipeline. +If no \fIfileId\fR argument is given then \fBpid\fR returns the process +identifier of the current process. +All process identifiers are returned as decimal strings. +.SH EXAMPLE +Print process information about the processes in a pipeline using the +SysV \fBps\fR program before reading the output of that pipeline: +.PP +.CS +set pipeline [open "| zcat somefile.gz | grep foobar | sort -u"] +# Print process information +exec ps -fp [\fBpid\fR $pipeline] >@stdout +# Print a separator and then the output of the pipeline +puts [string repeat - 70] +puts [read $pipeline] +close $pipeline +.CE + +.SH "SEE ALSO" +exec(n), open(n) + +.SH KEYWORDS +file, pipeline, process identifier diff --git a/tcl8.6/doc/pkgMkIndex.n b/tcl8.6/doc/pkgMkIndex.n new file mode 100644 index 0000000..ec39be9 --- /dev/null +++ b/tcl8.6/doc/pkgMkIndex.n @@ -0,0 +1,233 @@ +'\" +'\" Copyright (c) 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. +'\" +.TH pkg_mkIndex n 8.3 Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +pkg_mkIndex \- Build an index for automatic loading of packages +.SH SYNOPSIS +.nf +\fBpkg_mkIndex\fR ?\fIoptions...\fR? \fIdir\fR ?\fIpattern pattern ...\fR? +.fi +.BE +.SH DESCRIPTION +.PP +\fBPkg_mkIndex\fR is a utility procedure that is part of the standard +Tcl library. +It is used to create index files that allow packages to be loaded +automatically when \fBpackage require\fR commands are executed. +To use \fBpkg_mkIndex\fR, follow these steps: +.IP [1] +Create the package(s). +Each package may consist of one or more Tcl script files or binary files. +Binary files must be suitable for loading with the \fBload\fR command +with a single argument; for example, if the file is \fBtest.so\fR it must +be possible to load this file with the command \fBload test.so\fR. +Each script file must contain a \fBpackage provide\fR command to declare +the package and version number, and each binary file must contain +a call to \fBTcl_PkgProvide\fR. +.IP [2] +Create the index by invoking \fBpkg_mkIndex\fR. +The \fIdir\fR argument gives the name of a directory and each +\fIpattern\fR argument is a \fBglob\fR-style pattern that selects +script or binary files in \fIdir\fR. +The default pattern is \fB*.tcl\fR and \fB*.[info sharedlibextension]\fR. +.RS +.PP +\fBPkg_mkIndex\fR will create a file \fBpkgIndex.tcl\fR in \fIdir\fR +with package information about all the files given by the \fIpattern\fR +arguments. +It does this by loading each file into a slave +interpreter and seeing what packages +and new commands appear (this is why it is essential to have +\fBpackage provide\fR commands or \fBTcl_PkgProvide\fR calls +in the files, as described above). +If you have a package split among scripts and binary files, +or if you have dependencies among files, +you may have to use the \fB\-load\fR option +or adjust the order in which \fBpkg_mkIndex\fR processes +the files. See \fBCOMPLEX CASES\fR below. +.RE +.IP [3] +Install the package as a subdirectory of one of the directories given by +the \fBtcl_pkgPath\fR variable. If \fB$tcl_pkgPath\fR contains more +than one directory, machine-dependent packages (e.g., those that +contain binary shared libraries) should normally be installed +under the first directory and machine-independent packages (e.g., +those that contain only Tcl scripts) should be installed under the +second directory. +The subdirectory should include +the package's script and/or binary files as well as the \fBpkgIndex.tcl\fR +file. As long as the package is installed as a subdirectory of a +directory in \fB$tcl_pkgPath\fR it will automatically be found during +\fBpackage require\fR commands. +.RS +.PP +If you install the package anywhere else, then you must ensure that +the directory containing the package is in the \fBauto_path\fR global variable +or an immediate subdirectory of one of the directories in \fBauto_path\fR. +\fBAuto_path\fR contains a list of directories that are searched +by both the auto-loader and the package loader; by default it +includes \fB$tcl_pkgPath\fR. +The package loader also checks all of the subdirectories of the +directories in \fBauto_path\fR. +You can add a directory to \fBauto_path\fR explicitly in your +application, or you can add the directory to your \fBTCLLIBPATH\fR +environment variable: if this environment variable is present, +Tcl initializes \fBauto_path\fR from it during application startup. +.RE +.IP [4] +Once the above steps have been taken, all you need to do to use a +package is to invoke \fBpackage require\fR. +For example, if versions 2.1, 2.3, and 3.1 of package \fBTest\fR +have been indexed by \fBpkg_mkIndex\fR, the command +\fBpackage require Test\fR will make version 3.1 available +and the command \fBpackage require \-exact Test 2.1\fR will +make version 2.1 available. +There may be many versions of a package in the various index files +in \fBauto_path\fR, but only one will actually be loaded in a given +interpreter, based on the first call to \fBpackage require\fR. +Different versions of a package may be loaded in different +interpreters. +.SH OPTIONS +The optional switches are: +.TP 15 +\fB\-direct\fR +The generated index will implement direct loading of the package +upon \fBpackage require\fR. This is the default. +.TP 15 +\fB\-lazy\fR +The generated index will manage to delay loading the package until the +use of one of the commands provided by the package, instead of loading +it immediately upon \fBpackage require\fR. This is not compatible with +the use of \fIauto_reset\fR, and therefore its use is discouraged. +.TP 15 +\fB\-load \fIpkgPat\fR +The index process will pre-load any packages that exist in the +current interpreter and match \fIpkgPat\fR into the slave interpreter used to +generate the index. The pattern match uses string match rules, but without +making case distinctions. +See \fBCOMPLEX CASES\fR below. +.TP 15 +\fB\-verbose\fR +Generate output during the indexing process. Output is via +the \fBtclLog\fR procedure, which by default prints to stderr. +.TP 15 +\fB\-\-\fR +End of the flags, in case \fIdir\fR begins with a dash. +.SH "PACKAGES AND THE AUTO-LOADER" +.PP +The package management facilities overlap somewhat with the auto-loader, +in that both arrange for files to be loaded on-demand. +However, package management is a higher-level mechanism that uses +the auto-loader for the last step in the loading process. +It is generally better to index a package with \fBpkg_mkIndex\fR +rather than \fBauto_mkindex\fR because the package mechanism provides +version control: several versions of a package can be made available +in the index files, with different applications using different +versions based on \fBpackage require\fR commands. +In contrast, \fBauto_mkindex\fR does not understand versions so +it can only handle a single version of each package. +It is probably not a good idea to index a given package with both +\fBpkg_mkIndex\fR and \fBauto_mkindex\fR. +If you use \fBpkg_mkIndex\fR to index a package, its commands cannot +be invoked until \fBpackage require\fR has been used to select a +version; in contrast, packages indexed with \fBauto_mkindex\fR +can be used immediately since there is no version control. +.SH "HOW IT WORKS" +.PP +\fBPkg_mkIndex\fR depends on the \fBpackage unknown\fR command, +the \fBpackage ifneeded\fR command, and the auto-loader. +The first time a \fBpackage require\fR command is invoked, +the \fBpackage unknown\fR script is invoked. +This is set by Tcl initialization to a script that +evaluates all of the \fBpkgIndex.tcl\fR files in the +\fBauto_path\fR. +The \fBpkgIndex.tcl\fR files contain \fBpackage ifneeded\fR +commands for each version of each available package; these commands +invoke \fBpackage provide\fR commands to announce the +availability of the package, and they setup auto-loader +information to load the files of the package. +If the \fB\-lazy\fR flag was provided when the \fBpkgIndex.tcl\fR +was generated, +a given file of a given version of a given package is not +actually loaded until the first time one of its commands +is invoked. +Thus, after invoking \fBpackage require\fR you may +not see the package's commands in the interpreter, but you will be able +to invoke the commands and they will be auto-loaded. +.SH "DIRECT LOADING" +.PP +Some packages, for instance packages which use namespaces and export +commands or those which require special initialization, might select +that their package files be loaded immediately upon \fBpackage require\fR +instead of delaying the actual loading to the first use of one of the +package's command. This is the default mode when generating the package +index. It can be overridden by specifying the \fB\-lazy\fR argument. +.SH "COMPLEX CASES" +Most complex cases of dependencies among scripts +and binary files, and packages being split among scripts and +binary files are handled OK. However, you may have to adjust +the order in which files are processed by \fBpkg_mkIndex\fR. +These issues are described in detail below. +.PP +If each script or file contains one package, and packages +are only contained in one file, then things are easy. +You simply specify all files to be indexed in any order +with some glob patterns. +.PP +In general, it is OK for scripts to have dependencies on other +packages. +If scripts contain \fBpackage require\fR commands, these are +stubbed out in the interpreter used to process the scripts, +so these do not cause problems. +If scripts call into other packages in global code, +these calls are handled by a stub \fBunknown\fR command. +However, if scripts make variable references to other package's +variables in global code, these will cause errors. That is +also bad coding style. +.PP +If binary files have dependencies on other packages, things +can become tricky because it is not possible to stub out +C-level APIs such as \fBTcl_PkgRequire\fR API +when loading a binary file. +For example, suppose the BLT package requires Tk, and expresses +this with a call to \fBTcl_PkgRequire\fR in its \fBBlt_Init\fR routine. +To support this, you must run \fBpkg_mkIndex\fR in an interpreter that +has Tk loaded. You can achieve this with the +\fB\-load \fIpkgPat\fR option. If you specify this option, +\fBpkg_mkIndex\fR will load any packages listed by +\fBinfo loaded\fR and that match \fIpkgPat\fR +into the interpreter used to process files. +In most cases this will satisfy the \fBTcl_PkgRequire\fR calls +made by binary files. +.PP +If you are indexing two binary files and one depends on the other, +you should specify the one that has dependencies last. +This way the one without dependencies will get loaded and indexed, +and then the package it provides +will be available when the second file is processed. +You may also need to load the first package into the +temporary interpreter used to create the index by using +the \fB\-load\fR flag; +it will not hurt to specify package patterns that are not yet loaded. +.PP +If you have a package that is split across scripts and a binary file, +then you should avoid the \fB\-load\fR flag. The problem is that +if you load a package before computing the index it masks any +other files that provide part of the same package. +If you must use \fB\-load\fR, +then you must specify the scripts first; otherwise the package loaded from +the binary file may mask the package defined by the scripts. +.SH "SEE ALSO" +package(n) +.SH KEYWORDS +auto-load, index, package, version +'\"Local Variables: +'\"mode: nroff +'\"End: diff --git a/tcl8.6/doc/platform.n b/tcl8.6/doc/platform.n new file mode 100644 index 0000000..6abc289 --- /dev/null +++ b/tcl8.6/doc/platform.n @@ -0,0 +1,86 @@ +'\" +'\" Copyright (c) 2006 ActiveState Software Inc +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH "platform" n 1.0.4 platform "Tcl Bundled Packages" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +platform \- System identification support code and utilities +.SH SYNOPSIS +.nf +\fBpackage require platform ?1.0.10?\fR +.sp +\fBplatform::generic\fR +\fBplatform::identify\fR +\fBplatform::patterns \fIidentifier\fR +.fi +.BE +.SH DESCRIPTION +.PP +The \fBplatform\fR package provides several utility commands useful +for the identification of the architecture of a machine running Tcl. +.PP +Whilst Tcl provides the \fBtcl_platform\fR array for identifying the +current architecture (in particular, the platform and machine +elements) this is not always sufficient. This is because (on Unix +machines) \fBtcl_platform\fR reflects the values returned by the +\fBuname\fR command and these are not standardized across platforms and +architectures. In addition, on at least one platform (AIX) the +\fBtcl_platform(machine)\fR contains the CPU serial number. +.PP +Consequently, individual applications need to manipulate the values in +\fBtcl_platform\fR (along with the output of system specific +utilities) - which is both inconvenient for developers, and introduces +the potential for inconsistencies in identifying architectures and in +naming conventions. +.PP +The \fBplatform\fR package prevents such fragmentation - i.e., it +establishes a standard naming convention for architectures running Tcl +and makes it more convenient for developers to identify the current +architecture a Tcl program is running on. +.SH COMMANDS +.TP +\fBplatform::identify\fR +. +This command returns an identifier describing the platform the Tcl +core is running on. The returned identifier has the general format +\fIOS\fR-\fICPU\fR. The \fIOS\fR part of the identifier may contain +details like kernel version, libc version, etc., and this information +may contain dashes as well. The \fICPU\fR part will not contain +dashes, making the preceding dash the last dash in the result. +.TP +\fBplatform::generic\fR +. +This command returns a simplified identifier describing the platform +the Tcl core is running on. In contrast to \fBplatform::identify\fR it +leaves out details like kernel version, libc version, etc. The +returned identifier has the general format \fIOS\fR-\fICPU\fR. +.TP +\fBplatform::patterns \fIidentifier\fR +. +This command takes an identifier as returned by +\fBplatform::identify\fR and returns a list of identifiers describing +compatible architectures. +.SH EXAMPLE +.PP +This can be used to allow an application to be shipped with multiple builds of +a shared library, so that the same package works on many versions of an +operating system. For example: +.PP +.CS +\fBpackage require platform\fR +# Assume that app script is .../theapp/bin/theapp.tcl +set binDir [file dirname [file normalize [info script]]] +set libDir [file join $binDir .. lib] +set platLibDir [file join $libDir [\fBplatform::identify\fR]] +load [file join $platLibDir support[info sharedlibextension]] +.CE +.SH KEYWORDS +operating system, cpu architecture, platform, architecture +'\" Local Variables: +'\" mode: nroff +'\" End: diff --git a/tcl8.6/doc/platform_shell.n b/tcl8.6/doc/platform_shell.n new file mode 100644 index 0000000..64a2e46 --- /dev/null +++ b/tcl8.6/doc/platform_shell.n @@ -0,0 +1,57 @@ +'\" +'\" Copyright (c) 2006-2008 ActiveState Software Inc +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH "platform::shell" n 1.1.4 platform::shell "Tcl Bundled Packages" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +platform::shell \- System identification support code and utilities +.SH SYNOPSIS +.nf +\fBpackage require platform::shell ?1.1.4?\fR +.sp +\fBplatform::shell::generic \fIshell\fR +\fBplatform::shell::identify \fIshell\fR +\fBplatform::shell::platform \fIshell\fR +.fi +.BE +.SH DESCRIPTION +.PP +The \fBplatform::shell\fR package provides several utility commands useful +for the identification of the architecture of a specific Tcl shell. +.PP +This package allows the identification of the architecture of a +specific Tcl shell different from the shell running the package. The +only requirement is that the other shell (identified by its path), is +actually executable on the current machine. +.PP +While for most platform this means that the architecture of the +interrogated shell is identical to the architecture of the running +shell this is not generally true. A counter example are all platforms +which have 32 and 64 bit variants and where a 64bit system is able to +run 32bit code. For these running and interrogated shell may have +different 32/64 bit settings and thus different identifiers. +.PP +For applications like a code repository it is important to identify +the architecture of the shell which will actually run the installed +packages, versus the architecture of the shell running the repository +software. +.SH COMMANDS +.TP +\fBplatform::shell::identify \fIshell\fR +This command does the same identification as \fBplatform::identify\fR, +for the specified Tcl shell, in contrast to the running shell. +.TP +\fBplatform::shell::generic \fIshell\fR +This command does the same identification as \fBplatform::generic\fR, +for the specified Tcl shell, in contrast to the running shell. +.TP +\fBplatform::shell::platform \fIshell\fR +This command returns the contents of \fBtcl_platform(platform)\fR for +the specified Tcl shell. +.SH KEYWORDS +operating system, cpu architecture, platform, architecture diff --git a/tcl8.6/doc/prefix.n b/tcl8.6/doc/prefix.n new file mode 100644 index 0000000..344ade7 --- /dev/null +++ b/tcl8.6/doc/prefix.n @@ -0,0 +1,116 @@ +'\" +'\" Copyright (c) 2008 Peter Spjuth <pspjuth@users.sourceforge.net> +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH prefix n 8.6 Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +tcl::prefix \- facilities for prefix matching +.SH SYNOPSIS +.nf +\fB::tcl::prefix all\fR \fItable\fR \fIstring\fR +\fB::tcl::prefix longest\fR \fItable\fR \fIstring\fR +\fB::tcl::prefix match\fR \fI?option ...?\fR \fItable\fR \fIstring\fR +.fi +.BE +.SH DESCRIPTION +.PP +This document describes commands looking up a prefix in a list of strings. +The following commands are supported: +.TP +\fB::tcl::prefix all\fR \fItable\fR \fIstring\fR +. +Returns a list of all elements in \fItable\fR that begin with the prefix +\fIstring\fR. +.TP +\fB::tcl::prefix longest\fR \fItable\fR \fIstring\fR +. +Returns the longest common prefix of all elements in \fItable\fR that +begin with the prefix \fIstring\fR. +.TP +\fB::tcl::prefix match\fR ?\fIoptions\fR? \fItable\fR \fIstring\fR +. +If \fIstring\fR equals one element in \fItable\fR or is a prefix to exactly +one element, the matched element is returned. If not, the result depends +on the \fB\-error\fR option. (It is recommended that the \fItable\fR be sorted +before use with this subcommand, so that the list of matches presented in the +error message also becomes sorted, though this is not strictly necessary for +the operation of this subcommand itself.) +.RS +.TP +\fB\-exact\fR\0 +. +Accept only exact matches. +.TP +\fB\-message\0\fIstring\fR +. +Use \fIstring\fR in the error message at a mismatch. Default is +.QW option . +.TP +\fB\-error\0\fIoptions\fR +. +The \fIoptions\fR are used when no match is found. If \fIoptions\fR is empty, +no error is generated and an empty string is returned. Otherwise the +\fIoptions\fR are used as \fBreturn\fR options when generating the error +message. The default corresponds to setting +.QW "\-level 0" . +Example: If +.QW "\fB\-error\fR {\-errorcode MyError \-level 1}" +is used, an error would be generated as: +.RS +.PP +.CS +return \-errorcode MyError \-level 1 \-code error \e + "ambiguous option ..." +.CE +.RE +.RE +.SH "EXAMPLES" +.PP +Basic use: +.PP +.CS +namespace import ::tcl::prefix +\fBprefix match\fR {apa bepa cepa} apa + \fI\(-> apa\fR +\fBprefix match\fR {apa bepa cepa} a + \fI\(-> apa\fR +\fBprefix match\fR \-exact {apa bepa cepa} a + \fI\(-> bad option "a": must be apa, bepa, or cepa\fR +\fBprefix match\fR \-message "switch" {apa ada bepa cepa} a + \fI\(-> ambiguous switch "a": must be apa, ada, bepa, or cepa\fR +\fBprefix longest\fR {fblocked fconfigure fcopy file fileevent flush} fc + \fI\(-> fco\fR +\fBprefix all\fR {fblocked fconfigure fcopy file fileevent flush} fc + \fI\(-> fconfigure fcopy\fR +.CE +.PP +Simplifying option matching: +.PP +.CS +array set opts {\-apa 1 \-bepa "" \-cepa 0} +foreach {arg val} $args { + set opts([\fBprefix match\fR {\-apa \-bepa \-cepa} $arg]) $val +} +.CE +.PP +Creating a \fBswitch\fR that supports prefixes: +.PP +.CS +switch [\fBprefix match\fR {apa bepa cepa} $arg] { + apa { } + bepa { } + cepa { } +} +.CE +.SH "SEE ALSO" +lsearch(n), namespace(n), string(n), Tcl_GetIndexFromObj(3) +.SH "KEYWORDS" +prefix, table lookup +'\" Local Variables: +'\" mode: nroff +'\" End: diff --git a/tcl8.6/doc/proc.n b/tcl8.6/doc/proc.n new file mode 100644 index 0000000..fdccaca --- /dev/null +++ b/tcl8.6/doc/proc.n @@ -0,0 +1,128 @@ +'\" +'\" Copyright (c) 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. +'\" +.TH proc n "" Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +proc \- Create a Tcl procedure +.SH SYNOPSIS +\fBproc \fIname args body\fR +.BE +.SH DESCRIPTION +.PP +The \fBproc\fR command creates a new Tcl procedure named +\fIname\fR, replacing +any existing command or procedure there may have been by that name. +Whenever the new command is invoked, the contents of \fIbody\fR will +be executed by the Tcl interpreter. +Normally, \fIname\fR is unqualified +(does not include the names of any containing namespaces), +and the new procedure is created in the current namespace. +If \fIname\fR includes any namespace qualifiers, +the procedure is created in the specified namespace. +\fIArgs\fR specifies the formal arguments to the +procedure. It consists of a list, possibly empty, each of whose +elements specifies +one argument. Each argument specifier is also a list with either +one or two fields. If there is only a single field in the specifier +then it is the name of the argument; if there are two fields, then +the first is the argument name and the second is its default value. +Arguments with default values that are followed by non-defaulted +arguments become required arguments; enough actual arguments must be +supplied to allow all arguments up to and including the last required +formal argument. +.PP +When \fIname\fR is invoked a local variable +will be created for each of the formal arguments to the procedure; its +value will be the value of corresponding argument in the invoking command +or the argument's default value. +Actual arguments are assigned to formal arguments strictly in order. +Arguments with default values need not be +specified in a procedure invocation. However, there must be enough +actual arguments for all the +formal arguments that do not have defaults, and there must not be any extra +actual arguments. +Arguments with default values that are followed by non-defaulted +arguments become de-facto required arguments, though this may change +in a future version of Tcl; portable code should ensure that all +optional arguments come after all required arguments. +.PP +There is one special case to permit procedures with +variable numbers of arguments. If the last formal argument has the name +.QW \fBargs\fR , +then a call to the procedure may contain more actual arguments +than the procedure has formal arguments. In this case, all of the actual arguments +starting at the one that would be assigned to \fBargs\fR are combined into +a list (as if the \fBlist\fR command had been used); this combined value +is assigned to the local variable \fBargs\fR. +.PP +When \fIbody\fR is being executed, variable names normally refer to +local variables, which are created automatically when referenced and +deleted when the procedure returns. One local variable is automatically +created for each of the procedure's arguments. +Other variables can only be accessed by invoking one of the \fBglobal\fR, +\fBvariable\fR, \fBupvar\fR or \fBnamespace upvar\fR commands. +The current namespace when \fIbody\fR is executed will be the +namespace that the procedure's name exists in, which will be the +namespace that it was created in unless it has been changed with +\fBrename\fR. +'\" We may change this! It makes [variable] unstable when renamed and is +'\" frankly pretty crazy, but doing it right is harder than it looks. +.PP +The \fBproc\fR command returns an empty string. When a procedure is +invoked, the procedure's return value is the value specified in a +\fBreturn\fR command. If the procedure does not execute an explicit +\fBreturn\fR, then its return value is the value of the last command +executed in the procedure's body. +If an error occurs while executing the procedure +body, then the procedure-as-a-whole will return that same error. +.SH EXAMPLES +.PP +This is a procedure that takes two arguments and prints both their sum +and their product. It also returns the string +.QW OK +to the caller as an explicit result. +.PP +.CS +\fBproc\fR printSumProduct {x y} { + set sum [expr {$x + $y}] + set prod [expr {$x * $y}] + puts "sum is $sum, product is $prod" + return "OK" +} +.CE +.PP +This is a procedure that accepts arbitrarily many arguments and prints +them out, one by one. +.PP +.CS +\fBproc\fR printArguments args { + foreach arg $args { + puts $arg + } +} +.CE +.PP +This procedure is a bit like the \fBincr\fR command, except it +multiplies the contents of the named variable by the value, which +defaults to \fB2\fR: +.PP +.CS +\fBproc\fR mult {varName {multiplier 2}} { + upvar 1 $varName var + set var [expr {$var * $multiplier}] +} +.CE +.SH "SEE ALSO" +info(n), unknown(n) +.SH KEYWORDS +argument, procedure +'\" Local Variables: +'\" mode: nroff +'\" End: diff --git a/tcl8.6/doc/puts.n b/tcl8.6/doc/puts.n new file mode 100644 index 0000000..01ca122 --- /dev/null +++ b/tcl8.6/doc/puts.n @@ -0,0 +1,98 @@ +'\" +'\" Copyright (c) 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. +'\" +.TH puts n 7.5 Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +puts \- Write to a channel +.SH SYNOPSIS +\fBputs \fR?\fB\-nonewline\fR? ?\fIchannelId\fR? \fIstring\fR +.BE +.SH DESCRIPTION +.PP +Writes the characters given by \fIstring\fR to the channel given +by \fIchannelId\fR. +.PP +\fIChannelId\fR must be an identifier for an open channel such as a +Tcl standard channel (\fBstdout\fR or \fBstderr\fR), the return +value from an invocation of \fBopen\fR or \fBsocket\fR, or the result +of a channel creation command provided by a Tcl extension. The channel +must have been opened for output. +.PP +If no \fIchannelId\fR is specified then it defaults to +\fBstdout\fR. \fBPuts\fR normally outputs a newline character after +\fIstring\fR, but this feature may be suppressed by specifying the +\fB\-nonewline\fR switch. +.PP +Newline characters in the output are translated by \fBputs\fR to +platform-specific end-of-line sequences according to the current +value of the \fB\-translation\fR option for the channel (for example, +on PCs newlines are normally replaced with carriage-return-linefeed +sequences. +See the \fBfconfigure\fR manual entry for a discussion on ways in +which \fBfconfigure\fR will alter output. +.PP +Tcl buffers output internally, so characters written with \fBputs\fR +may not appear immediately on the output file or device; Tcl will +normally delay output until the buffer is full or the channel is +closed. +You can force output to appear immediately with the \fBflush\fR +command. +.PP +When the output buffer fills up, the \fBputs\fR command will normally +block until all the buffered data has been accepted for output by the +operating system. +If \fIchannelId\fR is in nonblocking mode then the \fBputs\fR command +will not block even if the operating system cannot accept the data. +Instead, Tcl continues to buffer the data and writes it in the +background as fast as the underlying file or device can accept it. +The application must use the Tcl event loop for nonblocking output +to work; otherwise Tcl never finds out that the file or device is +ready for more output data. +It is possible for an arbitrarily large amount of data to be +buffered for a channel in nonblocking mode, which could consume a +large amount of memory. +To avoid wasting memory, nonblocking I/O should normally +be used in an event-driven fashion with the \fBfileevent\fR command +(do not invoke \fBputs\fR unless you have recently been notified +via a file event that the channel is ready for more output data). +.SH EXAMPLES +.PP +Write a short message to the console (or wherever \fBstdout\fR is +directed): +.PP +.CS +\fBputs\fR "Hello, World!" +.CE +.PP +Print a message in several parts: +.PP +.CS +\fBputs\fR -nonewline "Hello, " +\fBputs\fR "World!" +.CE +.PP +Print a message to the standard error channel: +.PP +.CS +\fBputs\fR stderr "Hello, World!" +.CE +.PP +Append a log message to a file: +.PP +.CS +set chan [open my.log a] +set timestamp [clock format [clock seconds]] +\fBputs\fR $chan "$timestamp - Hello, World!" +close $chan +.CE +.SH "SEE ALSO" +file(n), fileevent(n), Tcl_StandardChannels(3) +.SH KEYWORDS +channel, newline, output, write diff --git a/tcl8.6/doc/pwd.n b/tcl8.6/doc/pwd.n new file mode 100644 index 0000000..31d378f --- /dev/null +++ b/tcl8.6/doc/pwd.n @@ -0,0 +1,39 @@ +'\" +'\" Copyright (c) 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. +'\" +.TH pwd n "" Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +pwd \- Return the absolute path of the current working directory +.SH SYNOPSIS +\fBpwd\fR +.BE +.SH DESCRIPTION +.PP +Returns the absolute path name of the current working directory. +.SH EXAMPLE +.PP +Sometimes it is useful to change to a known directory when running +some external command using \fBexec\fR, but it is important to keep +the application usually running in the directory that it was started +in (unless the user specifies otherwise) since that minimizes user +confusion. The way to do this is to save the current directory while +the external command is being run: +.PP +.CS +set tarFile [file normalize somefile.tar] +set savedDir [\fBpwd\fR] +cd /tmp +exec tar -xf $tarFile +cd $savedDir +.CE +.SH "SEE ALSO" +file(n), cd(n), glob(n), filename(n) +.SH KEYWORDS +working directory diff --git a/tcl8.6/doc/re_syntax.n b/tcl8.6/doc/re_syntax.n new file mode 100644 index 0000000..7988071 --- /dev/null +++ b/tcl8.6/doc/re_syntax.n @@ -0,0 +1,858 @@ +'\" +'\" Copyright (c) 1998 Sun Microsystems, Inc. +'\" Copyright (c) 1999 Scriptics Corporation +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.so man.macros +.ie '\w'o''\w'\C'^o''' .ds qo \C'^o' +.el .ds qo u +.TH re_syntax n "8.1" Tcl "Tcl Built-In Commands" +.BS +.SH NAME +re_syntax \- Syntax of Tcl regular expressions +.BE +.SH DESCRIPTION +.PP +A \fIregular expression\fR describes strings of characters. +It's a pattern that matches certain strings and does not match others. +.SH "DIFFERENT FLAVORS OF REs" +Regular expressions +.PQ RE s , +as defined by POSIX, come in two flavors: \fIextended\fR REs +.PQ ERE s +and \fIbasic\fR REs +.PQ BRE s . +EREs are roughly those of the traditional \fIegrep\fR, while BREs are +roughly those of the traditional \fIed\fR. This implementation adds +a third flavor, \fIadvanced\fR REs +.PQ ARE s , +basically EREs with some significant extensions. +.PP +This manual page primarily describes AREs. BREs mostly exist for +backward compatibility in some old programs; they will be discussed at +the end. POSIX EREs are almost an exact subset of AREs. Features of +AREs that are not present in EREs will be indicated. +.SH "REGULAR EXPRESSION SYNTAX" +.PP +Tcl regular expressions are implemented using the package written by +Henry Spencer, based on the 1003.2 spec and some (not quite all) of +the Perl5 extensions (thanks, Henry!). Much of the description of +regular expressions below is copied verbatim from his manual entry. +.PP +An ARE is one or more \fIbranches\fR, +separated by +.QW \fB|\fR , +matching anything that matches any of the branches. +.PP +A branch is zero or more \fIconstraints\fR or \fIquantified atoms\fR, +concatenated. +It matches a match for the first, followed by a match for the second, etc; +an empty branch matches the empty string. +.SS QUANTIFIERS +A quantified atom is an \fIatom\fR possibly followed +by a single \fIquantifier\fR. +Without a quantifier, it matches a single match for the atom. +The quantifiers, +and what a so-quantified atom matches, are: +.RS 2 +.TP 6 +\fB*\fR +. +a sequence of 0 or more matches of the atom +.TP +\fB+\fR +. +a sequence of 1 or more matches of the atom +.TP +\fB?\fR +. +a sequence of 0 or 1 matches of the atom +.TP +\fB{\fIm\fB}\fR +. +a sequence of exactly \fIm\fR matches of the atom +.TP +\fB{\fIm\fB,}\fR +. +a sequence of \fIm\fR or more matches of the atom +.TP +\fB{\fIm\fB,\fIn\fB}\fR +. +a sequence of \fIm\fR through \fIn\fR (inclusive) matches of the atom; +\fIm\fR may not exceed \fIn\fR +.TP +\fB*? +? ?? {\fIm\fB}? {\fIm\fB,}? {\fIm\fB,\fIn\fB}?\fR +. +\fInon-greedy\fR quantifiers, which match the same possibilities, +but prefer the smallest number rather than the largest number +of matches (see \fBMATCHING\fR) +.RE +.PP +The forms using \fB{\fR and \fB}\fR are known as \fIbound\fRs. The +numbers \fIm\fR and \fIn\fR are unsigned decimal integers with +permissible values from 0 to 255 inclusive. +.SS ATOMS +An atom is one of: +.RS 2 +.IP \fB(\fIre\fB)\fR 6 +matches a match for \fIre\fR (\fIre\fR is any regular expression) with +the match noted for possible reporting +.IP \fB(?:\fIre\fB)\fR +as previous, but does no reporting (a +.QW non-capturing +set of parentheses) +.IP \fB()\fR +matches an empty string, noted for possible reporting +.IP \fB(?:)\fR +matches an empty string, without reporting +.IP \fB[\fIchars\fB]\fR +a \fIbracket expression\fR, matching any one of the \fIchars\fR (see +\fBBRACKET EXPRESSIONS\fR for more detail) +.IP \fB.\fR +matches any single character +.IP \fB\e\fIk\fR +matches the non-alphanumeric character \fIk\fR +taken as an ordinary character, e.g. \fB\e\e\fR matches a backslash +character +.IP \fB\e\fIc\fR +where \fIc\fR is alphanumeric (possibly followed by other characters), +an \fIescape\fR (AREs only), see \fBESCAPES\fR below +.IP \fB{\fR +when followed by a character other than a digit, matches the +left-brace character +.QW \fB{\fR ; +when followed by a digit, it is the beginning of a \fIbound\fR (see above) +.IP \fIx\fR +where \fIx\fR is a single character with no other significance, +matches that character. +.RE +.SS CONSTRAINTS +A \fIconstraint\fR matches an empty string when specific conditions +are met. A constraint may not be followed by a quantifier. The +simple constraints are as follows; some more constraints are described +later, under \fBESCAPES\fR. +.RS 2 +.TP 8 +\fB^\fR +. +matches at the beginning of a line +.TP +\fB$\fR +. +matches at the end of a line +.TP +\fB(?=\fIre\fB)\fR +. +\fIpositive lookahead\fR (AREs only), matches at any point where a +substring matching \fIre\fR begins +.TP +\fB(?!\fIre\fB)\fR +. +\fInegative lookahead\fR (AREs only), matches at any point where no +substring matching \fIre\fR begins +.RE +.PP +The lookahead constraints may not contain back references (see later), +and all parentheses within them are considered non-capturing. +.PP +An RE may not end with +.QW \fB\e\fR . +.SH "BRACKET EXPRESSIONS" +A \fIbracket expression\fR is a list of characters enclosed in +.QW \fB[\|]\fR . +It normally matches any single character from the list +(but see below). If the list begins with +.QW \fB^\fR , +it matches any single character (but see below) \fInot\fR from the +rest of the list. +.PP +If two characters in the list are separated by +.QW \fB\-\fR , +this is shorthand for the full \fIrange\fR of characters between those two +(inclusive) in the collating sequence, e.g. +.QW \fB[0\-9]\fR +in Unicode matches any conventional decimal digit. Two ranges may not share an +endpoint, so e.g. +.QW \fBa\-c\-e\fR +is illegal. Ranges in Tcl always use the +Unicode collating sequence, but other programs may use other collating +sequences and this can be a source of incompatibility between programs. +.PP +To include a literal \fB]\fR or \fB\-\fR in the list, the simplest +method is to enclose it in \fB[.\fR and \fB.]\fR to make it a +collating element (see below). Alternatively, make it the first +character (following a possible +.QW \fB^\fR ), +or (AREs only) precede it with +.QW \fB\e\fR . +Alternatively, for +.QW \fB\-\fR , +make it the last character, or the second endpoint of a range. To use +a literal \fB\-\fR as the first endpoint of a range, make it a +collating element or (AREs only) precede it with +.QW \fB\e\fR . +With the exception of +these, some combinations using \fB[\fR (see next paragraphs), and +escapes, all other special characters lose their special significance +within a bracket expression. +.SS "CHARACTER CLASSES" +Within a bracket expression, the name of a \fIcharacter class\fR +enclosed in \fB[:\fR and \fB:]\fR stands for the list of all +characters (not all collating elements!) belonging to that class. +Standard character classes are: +.IP \fBalpha\fR 8 +A letter. +.IP \fBupper\fR 8 +An upper-case letter. +.IP \fBlower\fR 8 +A lower-case letter. +.IP \fBdigit\fR 8 +A decimal digit. +.IP \fBxdigit\fR 8 +A hexadecimal digit. +.IP \fBalnum\fR 8 +An alphanumeric (letter or digit). +.IP \fBprint\fR 8 +A "printable" (same as graph, except also including space). +.IP \fBblank\fR 8 +A space or tab character. +.IP \fBspace\fR 8 +A character producing white space in displayed text. +.IP \fBpunct\fR 8 +A punctuation character. +.IP \fBgraph\fR 8 +A character with a visible representation (includes both \fBalnum\fR +and \fBpunct\fR). +.IP \fBcntrl\fR 8 +A control character. +.PP +A locale may provide others. A character class may not be used as an endpoint +of a range. +.RS +.PP +(\fINote:\fR the current Tcl implementation has only one locale, the Unicode +locale, which supports exactly the above classes.) +.RE +.SS "BRACKETED CONSTRAINTS" +There are two special cases of bracket expressions: the bracket +expressions +.QW \fB[[:<:]]\fR +and +.QW \fB[[:>:]]\fR +are constraints, matching empty strings at the beginning and end of a word +respectively. +.\" note, discussion of escapes below references this definition of word +A word is defined as a sequence of word characters that is neither preceded +nor followed by word characters. A word character is an \fIalnum\fR character +or an underscore +.PQ \fB_\fR "" . +These special bracket expressions are deprecated; users of AREs should use +constraint escapes instead (see below). +.SS "COLLATING ELEMENTS" +Within a bracket expression, a collating element (a character, a +multi-character sequence that collates as if it were a single +character, or a collating-sequence name for either) enclosed in +\fB[.\fR and \fB.]\fR stands for the sequence of characters of that +collating element. The sequence is a single element of the bracket +expression's list. A bracket expression in a locale that has +multi-character collating elements can thus match more than one +character. So (insidiously), a bracket expression that starts with +\fB^\fR can match multi-character collating elements even if none of +them appear in the bracket expression! +.RS +.PP +(\fINote:\fR Tcl has no multi-character collating elements. This information +is only for illustration.) +.RE +.PP +For example, assume the collating sequence includes a \fBch\fR multi-character +collating element. Then the RE +.QW \fB[[.ch.]]*c\fR +(zero or more +.QW \fBch\fRs +followed by +.QW \fBc\fR ) +matches the first five characters of +.QW \fBchchcc\fR . +Also, the RE +.QW \fB[^c]b\fR +matches all of +.QW \fBchb\fR +(because +.QW \fB[^c]\fR +matches the multi-character +.QW \fBch\fR ). +.SS "EQUIVALENCE CLASSES" +Within a bracket expression, a collating element enclosed in \fB[=\fR +and \fB=]\fR is an equivalence class, standing for the sequences of +characters of all collating elements equivalent to that one, including +itself. (If there are no other equivalent collating elements, the +treatment is as if the enclosing delimiters were +.QW \fB[.\fR \& +and +.QW \fB.]\fR .) +For example, if \fBo\fR and \fB\*(qo\fR are the members of an +equivalence class, then +.QW \fB[[=o=]]\fR , +.QW \fB[[=\*(qo=]]\fR , +and +.QW \fB[o\*(qo]\fR \& +are all synonymous. An equivalence class may not be an endpoint of a range. +.RS +.PP +(\fINote:\fR Tcl implements only the Unicode locale. It does not define any +equivalence classes. The examples above are just illustrations.) +.RE +.SH ESCAPES +Escapes (AREs only), which begin with a \fB\e\fR followed by an +alphanumeric character, come in several varieties: character entry, +class shorthands, constraint escapes, and back references. A \fB\e\fR +followed by an alphanumeric character but not constituting a valid +escape is illegal in AREs. In EREs, there are no escapes: outside a +bracket expression, a \fB\e\fR followed by an alphanumeric character +merely stands for that character as an ordinary character, and inside +a bracket expression, \fB\e\fR is an ordinary character. (The latter +is the one actual incompatibility between EREs and AREs.) +.SS "CHARACTER-ENTRY ESCAPES" +Character-entry escapes (AREs only) exist to make it easier to specify +non-printing and otherwise inconvenient characters in REs: +.RS 2 +.TP 5 +\fB\ea\fR +. +alert (bell) character, as in C +.TP +\fB\eb\fR +. +backspace, as in C +.TP +\fB\eB\fR +. +synonym for \fB\e\fR to help reduce backslash doubling in some +applications where there are multiple levels of backslash processing +.TP +\fB\ec\fIX\fR +. +(where \fIX\fR is any character) the character whose low-order 5 bits +are the same as those of \fIX\fR, and whose other bits are all zero +.TP +\fB\ee\fR +. +the character whose collating-sequence name is +.QW \fBESC\fR , +or failing that, the character with octal value 033 +.TP +\fB\ef\fR +. +formfeed, as in C +.TP +\fB\en\fR +. +newline, as in C +.TP +\fB\er\fR +. +carriage return, as in C +.TP +\fB\et\fR +. +horizontal tab, as in C +.TP +\fB\eu\fIwxyz\fR +. +(where \fIwxyz\fR is one up to four hexadecimal digits) the Unicode +character \fBU+\fIwxyz\fR in the local byte ordering +.TP +\fB\eU\fIstuvwxyz\fR +. +(where \fIstuvwxyz\fR is one up to eight hexadecimal digits) reserved +for a Unicode extension up to 21 bits. The digits are parsed until the +first non-hexadecimal character is encountered, the maximun of eight +hexadecimal digits are reached, or an overflow would occur in the maximum +value of \fBU+\fI10ffff\fR. +.TP +\fB\ev\fR +. +vertical tab, as in C are all available. +.TP +\fB\ex\fIhh\fR +. +(where \fIhh\fR is one or two hexadecimal digits) the character +whose hexadecimal value is \fB0x\fIhh\fR. +.TP +\fB\e0\fR +. +the character whose value is \fB0\fR +.TP +\fB\e\fIxyz\fR +. +(where \fIxyz\fR is exactly three octal digits, and is not a \fIback +reference\fR (see below)) the character whose octal value is +\fB0\fIxyz\fR. The first digit must be in the range 0-3, otherwise +the two-digit form is assumed. +.TP +\fB\e\fIxy\fR +. +(where \fIxy\fR is exactly two octal digits, and is not a \fIback +reference\fR (see below)) the character whose octal value is +\fB0\fIxy\fR +.RE +.PP +Hexadecimal digits are +.QR \fB0\fR \fB9\fR , +.QR \fBa\fR \fBf\fR , +and +.QR \fBA\fR \fBF\fR . +Octal digits are +.QR \fB0\fR \fB7\fR . +.PP +The character-entry escapes are always taken as ordinary characters. +For example, \fB\e135\fR is \fB]\fR in Unicode, but \fB\e135\fR does +not terminate a bracket expression. Beware, however, that some +applications (e.g., C compilers and the Tcl interpreter if the regular +expression is not quoted with braces) interpret such sequences +themselves before the regular-expression package gets to see them, +which may require doubling (quadrupling, etc.) the +.QW \fB\e\fR . +.SS "CLASS-SHORTHAND ESCAPES" +Class-shorthand escapes (AREs only) provide shorthands for certain +commonly-used character classes: +.RS 2 +.TP 10 +\fB\ed\fR +. +\fB[[:digit:]]\fR +.TP +\fB\es\fR +. +\fB[[:space:]]\fR +.TP +\fB\ew\fR +. +\fB[[:alnum:]_]\fR (note underscore) +.TP +\fB\eD\fR +. +\fB[^[:digit:]]\fR +.TP +\fB\eS\fR +. +\fB[^[:space:]]\fR +.TP +\fB\eW\fR +. +\fB[^[:alnum:]_]\fR (note underscore) +.RE +.PP +Within bracket expressions, +.QW \fB\ed\fR , +.QW \fB\es\fR , +and +.QW \fB\ew\fR \& +lose their outer brackets, and +.QW \fB\eD\fR , +.QW \fB\eS\fR , +and +.QW \fB\eW\fR \& +are illegal. (So, for example, +.QW \fB[a-c\ed]\fR +is equivalent to +.QW \fB[a-c[:digit:]]\fR . +Also, +.QW \fB[a-c\eD]\fR , +which is equivalent to +.QW \fB[a-c^[:digit:]]\fR , +is illegal.) +.SS "CONSTRAINT ESCAPES" +A constraint escape (AREs only) is a constraint, matching the empty +string if specific conditions are met, written as an escape: +.RS 2 +.TP 6 +\fB\eA\fR +. +matches only at the beginning of the string (see \fBMATCHING\fR, +below, for how this differs from +.QW \fB^\fR ) +.TP +\fB\em\fR +. +matches only at the beginning of a word +.TP +\fB\eM\fR +. +matches only at the end of a word +.TP +\fB\ey\fR +. +matches only at the beginning or end of a word +.TP +\fB\eY\fR +. +matches only at a point that is not the beginning or end of a word +.TP +\fB\eZ\fR +. +matches only at the end of the string (see \fBMATCHING\fR, below, for +how this differs from +.QW \fB$\fR ) +.TP +\fB\e\fIm\fR +. +(where \fIm\fR is a nonzero digit) a \fIback reference\fR, see below +.TP +\fB\e\fImnn\fR +. +(where \fIm\fR is a nonzero digit, and \fInn\fR is some more digits, +and the decimal value \fImnn\fR is not greater than the number of +closing capturing parentheses seen so far) a \fIback reference\fR, see +below +.RE +.PP +A word is defined as in the specification of +.QW \fB[[:<:]]\fR +and +.QW \fB[[:>:]]\fR +above. Constraint escapes are illegal within bracket expressions. +.SS "BACK REFERENCES" +A back reference (AREs only) matches the same string matched by the +parenthesized subexpression specified by the number, so that (e.g.) +.QW \fB([bc])\e1\fR +matches +.QW \fBbb\fR +or +.QW \fBcc\fR +but not +.QW \fBbc\fR . +The subexpression must entirely precede the back reference in the RE. +Subexpressions are numbered in the order of their leading parentheses. +Non-capturing parentheses do not define subexpressions. +.PP +There is an inherent historical ambiguity between octal +character-entry escapes and back references, which is resolved by +heuristics, as hinted at above. A leading zero always indicates an +octal escape. A single non-zero digit, not followed by another digit, +is always taken as a back reference. A multi-digit sequence not +starting with a zero is taken as a back reference if it comes after a +suitable subexpression (i.e. the number is in the legal range for a +back reference), and otherwise is taken as octal. +.SH "METASYNTAX" +In addition to the main syntax described above, there are some special +forms and miscellaneous syntactic facilities available. +.PP +Normally the flavor of RE being used is specified by +application-dependent means. However, this can be overridden by a +\fIdirector\fR. If an RE of any flavor begins with +.QW \fB***:\fR , +the rest of the RE is an ARE. If an RE of any flavor begins with +.QW \fB***=\fR , +the rest of the RE is taken to be a literal string, with +all characters considered ordinary characters. +.PP +An ARE may begin with \fIembedded options\fR: a sequence +\fB(?\fIxyz\fB)\fR (where \fIxyz\fR is one or more alphabetic +characters) specifies options affecting the rest of the RE. These +supplement, and can override, any options specified by the +application. The available option letters are: +.RS 2 +.TP 3 +\fBb\fR +. +rest of RE is a BRE +.TP 3 +\fBc\fR +. +case-sensitive matching (usual default) +.TP 3 +\fBe\fR +. +rest of RE is an ERE +.TP 3 +\fBi\fR +. +case-insensitive matching (see \fBMATCHING\fR, below) +.TP 3 +\fBm\fR +. +historical synonym for \fBn\fR +.TP 3 +\fBn\fR +. +newline-sensitive matching (see \fBMATCHING\fR, below) +.TP 3 +\fBp\fR +. +partial newline-sensitive matching (see \fBMATCHING\fR, below) +.TP 3 +\fBq\fR +. +rest of RE is a literal +.PQ quoted +string, all ordinary characters +.TP 3 +\fBs\fR +. +non-newline-sensitive matching (usual default) +.TP 3 +\fBt\fR +. +tight syntax (usual default; see below) +.TP 3 +\fBw\fR +. +inverse partial newline-sensitive +.PQ weird +matching (see \fBMATCHING\fR, below) +.TP 3 +\fBx\fR +. +expanded syntax (see below) +.RE +.PP +Embedded options take effect at the \fB)\fR terminating the sequence. +They are available only at the start of an ARE, and may not be used +later within it. +.PP +In addition to the usual (\fItight\fR) RE syntax, in which all +characters are significant, there is an \fIexpanded\fR syntax, +available in all flavors of RE with the \fB\-expanded\fR switch, or in +AREs with the embedded x option. In the expanded syntax, white-space +characters are ignored and all characters between a \fB#\fR and the +following newline (or the end of the RE) are ignored, permitting +paragraphing and commenting a complex RE. There are three exceptions +to that basic rule: +.IP \(bu 3 +a white-space character or +.QW \fB#\fR +preceded by +.QW \fB\e\fR +is retained +.IP \(bu 3 +white space or +.QW \fB#\fR +within a bracket expression is retained +.IP \(bu 3 +white space and comments are illegal within multi-character symbols +like the ARE +.QW \fB(?:\fR +or the BRE +.QW \fB\e(\fR +.PP +Expanded-syntax white-space characters are blank, tab, newline, and +any character that belongs to the \fIspace\fR character class. +.PP +Finally, in an ARE, outside bracket expressions, the sequence +.QW \fB(?#\fIttt\fB)\fR +(where \fIttt\fR is any text not containing a +.QW \fB)\fR ) +is a comment, completely ignored. Again, this is not +allowed between the characters of multi-character symbols like +.QW \fB(?:\fR . +Such comments are more a historical artifact than a useful facility, +and their use is deprecated; use the expanded syntax instead. +.PP +\fINone\fR of these metasyntax extensions is available if the +application (or an initial +.QW \fB***=\fR +director) has specified that the +user's input be treated as a literal string rather than as an RE. +.SH MATCHING +In the event that an RE could match more than one substring of a given +string, the RE matches the one starting earliest in the string. If +the RE could match more than one substring starting at that point, its +choice is determined by its \fIpreference\fR: either the longest +substring, or the shortest. +.PP +Most atoms, and all constraints, have no preference. A parenthesized +RE has the same preference (possibly none) as the RE. A quantified +atom with quantifier \fB{\fIm\fB}\fR or \fB{\fIm\fB}?\fR has the same +preference (possibly none) as the atom itself. A quantified atom with +other normal quantifiers (including \fB{\fIm\fB,\fIn\fB}\fR with +\fIm\fR equal to \fIn\fR) prefers longest match. A quantified atom +with other non-greedy quantifiers (including \fB{\fIm\fB,\fIn\fB}?\fR +with \fIm\fR equal to \fIn\fR) prefers shortest match. A branch has +the same preference as the first quantified atom in it which has a +preference. An RE consisting of two or more branches connected by the +\fB|\fR operator prefers longest match. +.PP +Subject to the constraints imposed by the rules for matching the whole +RE, subexpressions also match the longest or shortest possible +substrings, based on their preferences, with subexpressions starting +earlier in the RE taking priority over ones starting later. Note that +outer subexpressions thus take priority over their component +subexpressions. +.PP +The quantifiers \fB{1,1}\fR and \fB{1,1}?\fR can be used to +force longest and shortest preference, respectively, on a +subexpression or a whole RE. +.RS +.PP +\fBNOTE:\fR This means that you can usually make a RE be non-greedy overall by +putting \fB{1,1}?\fR after one of the first non-constraint atoms or +parenthesized sub-expressions in it. \fIIt pays to experiment\fR with the +placing of this non-greediness override on a suitable range of input texts +when you are writing a RE if you are using this level of complexity. +.PP +For example, this regular expression is non-greedy, and will match the +shortest substring possible given that +.QW \fBabc\fR +will be matched as early as possible (the quantifier does not change that): +.PP +.CS +ab{1,1}?c.*x.*cba +.CE +.PP +The atom +.QW \fBa\fR +has no greediness preference, we explicitly give one for +.QW \fBb\fR , +and the remaining quantifiers are overridden to be non-greedy by the preceding +non-greedy quantifier. +.RE +.PP +Match lengths are measured in characters, not collating elements. An +empty string is considered longer than no match at all. For example, +.QW \fBbb*\fR +matches the three middle characters of +.QW \fBabbbc\fR , +.QW \fB(week|wee)(night|knights)\fR +matches all ten characters of +.QW \fBweeknights\fR , +when +.QW \fB(.*).*\fR +is matched against +.QW \fBabc\fR +the parenthesized subexpression matches all three characters, and when +.QW \fB(a*)*\fR +is matched against +.QW \fBbc\fR +both the whole RE and the parenthesized subexpression match an empty string. +.PP +If case-independent matching is specified, the effect is much as if +all case distinctions had vanished from the alphabet. When an +alphabetic that exists in multiple cases appears as an ordinary +character outside a bracket expression, it is effectively transformed +into a bracket expression containing both cases, so that \fBx\fR +becomes +.QW \fB[xX]\fR . +When it appears inside a bracket expression, +all case counterparts of it are added to the bracket expression, so +that +.QW \fB[x]\fR +becomes +.QW \fB[xX]\fR +and +.QW \fB[^x]\fR +becomes +.QW \fB[^xX]\fR . +.PP +If newline-sensitive matching is specified, \fB.\fR and bracket +expressions using \fB^\fR will never match the newline character (so +that matches will never cross newlines unless the RE explicitly +arranges it) and \fB^\fR and \fB$\fR will match the empty string after +and before a newline respectively, in addition to matching at +beginning and end of string respectively. ARE \fB\eA\fR and \fB\eZ\fR +continue to match beginning or end of string \fIonly\fR. +.PP +If partial newline-sensitive matching is specified, this affects +\fB.\fR and bracket expressions as with newline-sensitive matching, +but not \fB^\fR and \fB$\fR. +.PP +If inverse partial newline-sensitive matching is specified, this +affects \fB^\fR and \fB$\fR as with newline-sensitive matching, but +not \fB.\fR and bracket expressions. This is not very useful but is +provided for symmetry. +.SH "LIMITS AND COMPATIBILITY" +No particular limit is imposed on the length of REs. Programs +intended to be highly portable should not employ REs longer than 256 +bytes, as a POSIX-compliant implementation can refuse to accept such +REs. +.PP +The only feature of AREs that is actually incompatible with POSIX EREs +is that \fB\e\fR does not lose its special significance inside bracket +expressions. All other ARE features use syntax which is illegal or +has undefined or unspecified effects in POSIX EREs; the \fB***\fR +syntax of directors likewise is outside the POSIX syntax for both BREs +and EREs. +.PP +Many of the ARE extensions are borrowed from Perl, but some have been +changed to clean them up, and a few Perl extensions are not present. +Incompatibilities of note include +.QW \fB\eb\fR , +.QW \fB\eB\fR , +the lack of special treatment for a trailing newline, the addition of +complemented bracket expressions to the things affected by +newline-sensitive matching, the restrictions on parentheses and back +references in lookahead constraints, and the longest/shortest-match +(rather than first-match) matching semantics. +.PP +The matching rules for REs containing both normal and non-greedy +quantifiers have changed since early beta-test versions of this +package. (The new rules are much simpler and cleaner, but do not work +as hard at guessing the user's real intentions.) +.PP +Henry Spencer's original 1986 \fIregexp\fR package, still in +widespread use (e.g., in pre-8.1 releases of Tcl), implemented an +early version of today's EREs. There are four incompatibilities +between \fIregexp\fR's near-EREs +.PQ RREs " for short" +and AREs. In roughly increasing order of significance: +.IP \(bu 3 +In AREs, \fB\e\fR followed by an alphanumeric character is either an +escape or an error, while in RREs, it was just another way of writing +the alphanumeric. This should not be a problem because there was no +reason to write such a sequence in RREs. +.IP \(bu 3 +\fB{\fR followed by a digit in an ARE is the beginning of a bound, +while in RREs, \fB{\fR was always an ordinary character. Such +sequences should be rare, and will often result in an error because +following characters will not look like a valid bound. +.IP \(bu 3 +In AREs, \fB\e\fR remains a special character within +.QW \fB[\|]\fR , +so a literal \fB\e\fR within \fB[\|]\fR must be written +.QW \fB\e\e\fR . +\fB\e\e\fR also gives a literal \fB\e\fR within \fB[\|]\fR in RREs, +but only truly paranoid programmers routinely doubled the backslash. +.IP \(bu 3 +AREs report the longest/shortest match for the RE, rather than the +first found in a specified search order. This may affect some RREs +which were written in the expectation that the first match would be +reported. (The careful crafting of RREs to optimize the search order +for fast matching is obsolete (AREs examine all possible matches in +parallel, and their performance is largely insensitive to their +complexity) but cases where the search order was exploited to +deliberately find a match which was \fInot\fR the longest/shortest +will need rewriting.) +.SH "BASIC REGULAR EXPRESSIONS" +BREs differ from EREs in several respects. +.QW \fB|\fR , +.QW \fB+\fR , +and \fB?\fR are ordinary characters and there is no equivalent for their +functionality. The delimiters for bounds are \fB\e{\fR and +.QW \fB\e}\fR , +with \fB{\fR and \fB}\fR by themselves ordinary characters. The +parentheses for nested subexpressions are \fB\e(\fR and +.QW \fB\e)\fR , +with \fB(\fR and \fB)\fR by themselves ordinary +characters. \fB^\fR is an ordinary character except at the beginning +of the RE or the beginning of a parenthesized subexpression, \fB$\fR +is an ordinary character except at the end of the RE or the end of a +parenthesized subexpression, and \fB*\fR is an ordinary character if +it appears at the beginning of the RE or the beginning of a +parenthesized subexpression (after a possible leading +.QW \fB^\fR ). +Finally, single-digit back references are available, and \fB\e<\fR and +\fB\e>\fR are synonyms for +.QW \fB[[:<:]]\fR +and +.QW \fB[[:>:]]\fR +respectively; no other escapes are available. +.SH "SEE ALSO" +RegExp(3), regexp(n), regsub(n), lsearch(n), switch(n), text(n) +.SH KEYWORDS +match, regular expression, string +.\" Local Variables: +.\" mode: nroff +.\" End: diff --git a/tcl8.6/doc/read.n b/tcl8.6/doc/read.n new file mode 100644 index 0000000..9a9a7e8 --- /dev/null +++ b/tcl8.6/doc/read.n @@ -0,0 +1,89 @@ +'\" +'\" Copyright (c) 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. +'\" +.TH read n 8.1 Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +read \- Read from a channel +.SH SYNOPSIS +\fBread \fR?\fB\-nonewline\fR? \fIchannelId\fR +.sp +\fBread \fIchannelId numChars\fR +.BE +.SH DESCRIPTION +.PP +In the first form, the \fBread\fR command reads all of the data from +\fIchannelId\fR up to the end of the file. If the \fB\-nonewline\fR +switch is specified then the last character of the file is discarded +if it is a newline. In the second form, the extra argument specifies +how many characters to read. Exactly that many characters will be +read and returned, unless there are fewer than \fInumChars\fR left in +the file; in this case all the remaining characters are returned. If +the channel is configured to use a multi-byte encoding, then the +number of characters read may not be the same as the number of bytes +read. +.PP +\fIChannelId\fR must be an identifier for an open channel such as the +Tcl standard input channel (\fBstdin\fR), the return value from an +invocation of \fBopen\fR or \fBsocket\fR, or the result of a channel +creation command provided by a Tcl extension. The channel must have +been opened for input. +.PP +If \fIchannelId\fR is in nonblocking mode, the command may not read as +many characters as requested: once all available input has been read, +the command will return the data that is available rather than +blocking for more input. If the channel is configured to use a +multi-byte encoding, then there may actually be some bytes remaining +in the internal buffers that do not form a complete character. These +bytes will not be returned until a complete character is available or +end-of-file is reached. The \fB\-nonewline\fR switch is ignored if +the command returns before reaching the end of the file. +.PP +\fBRead\fR translates end-of-line sequences in the input into +newline characters according to the \fB\-translation\fR option +for the channel. +See the \fBfconfigure\fR manual entry for a discussion on ways in +which \fBfconfigure\fR will alter input. +.SH "USE WITH SERIAL PORTS" +'\" Note: this advice actually applies to many versions of Tcl +.PP +For most applications a channel connected to a serial port should be +configured to be nonblocking: \fBfconfigure\fI channelId \fB\-blocking +\fI0\fR. Then \fBread\fR behaves much like described above. Care +must be taken when using \fBread\fR on blocking serial ports: +.TP +\fBread \fIchannelId numChars\fR +. +In this form \fBread\fR blocks until \fInumChars\fR have been received +from the serial port. +.TP +\fBread \fIchannelId\fR +. +In this form \fBread\fR blocks until the reception of the end-of-file +character, see \fBfconfigure\fR \fB\-eofchar\fR. If there no end-of-file +character has been configured for the channel, then \fBread\fR will +block forever. +.SH "EXAMPLE" +.PP +This example code reads a file all at once, and splits it into a list, +with each line in the file corresponding to an element in the list: +.PP +.CS +set fl [open /proc/meminfo] +set data [\fBread\fR $fl] +close $fl +set lines [split $data \en] +.CE +.SH "SEE ALSO" +file(n), eof(n), fblocked(n), fconfigure(n), Tcl_StandardChannels(3) +.SH KEYWORDS +blocking, channel, end of line, end of file, nonblocking, read, translation, encoding +'\"Local Variables: +'\"mode: nroff +'\"End: diff --git a/tcl8.6/doc/refchan.n b/tcl8.6/doc/refchan.n new file mode 100644 index 0000000..2232d50 --- /dev/null +++ b/tcl8.6/doc/refchan.n @@ -0,0 +1,411 @@ +'\" +'\" Copyright (c) 2006 Andreas Kupries <andreas_kupries@users.sourceforge.net> +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH refchan n 8.5 Tcl "Tcl Built-In Commands" +.so man.macros +.BS +.\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +refchan \- command handler API of reflected channels +.SH SYNOPSIS +\fBcmdPrefix \fIoption\fR ?\fIarg arg ...\fR? +.BE +.SH DESCRIPTION +.PP +The Tcl-level handler for a reflected channel has to be a command with +subcommands (termed an \fIensemble\fR, as it is a command such as that +created by \fBnamespace ensemble\fR \fBcreate\fR, though the implementation +of handlers for reflected channel \fIis not\fR tied to \fBnamespace +ensemble\fRs in any way; see \fBEXAMPLE\fR below for how to build an +\fBoo::class\fR that supports the API). Note that \fIcmdPrefix\fR is whatever was +specified in the call to \fBchan create\fR, and may consist of +multiple arguments; this will be expanded to multiple words in place +of the prefix. +.PP +Of all the possible subcommands, the handler \fImust\fR support +\fBinitialize\fR, \fBfinalize\fR, and \fBwatch\fR. Support for the +other subcommands is optional. +.SS "MANDATORY SUBCOMMANDS" +.TP +\fIcmdPrefix \fBinitialize \fIchannelId mode\fR +. +An invocation of this subcommand will be the first call the +\fIcmdPrefix\fR will receive for the specified new \fIchannelId\fR. It +is the responsibility of this subcommand to set up any internal data +structures required to keep track of the channel and its state. +.RS +.PP +The return value of the method has to be a list containing the names +of all subcommands supported by the \fIcmdPrefix\fR. This also tells +the Tcl core which version of the API for reflected channels is used by +this command handler. +.PP +Any error thrown by the method will abort the creation of the channel +and no channel will be created. The thrown error will appear as error +thrown by \fBchan create\fR. Any exception other than an \fBerror\fR +(e.g.,\ \fBbreak\fR, etc.) is treated as (and converted to) an error. +.PP +\fBNote:\fR If the creation of the channel was aborted due to failures +here, then the \fBfinalize\fR subcommand will not be called. +.PP +The \fImode\fR argument tells the handler whether the channel was +opened for reading, writing, or both. It is a list containing any of +the strings \fBread\fR or \fBwrite\fR. The list will always +contain at least one element. +.PP +The subcommand must throw an error if the chosen mode is not +supported by the \fIcmdPrefix\fR. +.RE +.TP +\fIcmdPrefix \fBfinalize \fIchannelId\fR +. +An invocation of this subcommand will be the last call the +\fIcmdPrefix\fR will receive for the specified \fIchannelId\fR. It will +be generated just before the destruction of the data structures of the +channel held by the Tcl core. The command handler \fImust not\fR +access the \fIchannelId\fR anymore in no way. Upon this subcommand being +called, any internal resources allocated to this channel must be +cleaned up. +.RS +.PP +The return value of this subcommand is ignored. +.PP +If the subcommand throws an error the command which caused its +invocation (usually \fBchan close\fR) will appear to have thrown this +error. Any exception beyond \fBerror\fR (e.g.,\ \fBbreak\fR, etc.) is +treated as (and converted to) an error. +.PP +This subcommand is not invoked if the creation of the channel was +aborted during \fBinitialize\fR (See above). +.RE +.TP +\fIcmdPrefix \fBwatch \fIchannelId eventspec\fR +. +This subcommand notifies the \fIcmdPrefix\fR that the specified +\fIchannelId\fR is interested in the events listed in the +\fIeventspec\fR. This argument is a list containing any of \fBread\fR +and \fBwrite\fR. The list may be empty, which signals that the +channel does not wish to be notified of any events. In that situation, +the handler should disable event generation completely. +.RS +.PP +\fBWarning:\fR Any return value of the subcommand is ignored. This +includes all errors thrown by the subcommand, \fBbreak\fR, \fBcontinue\fR, and +custom return codes. +.PP +This subcommand interacts with \fBchan postevent\fR. Trying to post an +event which was not listed in the last call to \fBwatch\fR will cause +\fBchan postevent\fR to throw an error. +.RE +.SS "OPTIONAL SUBCOMMANDS" +.TP +\fIcmdPrefix \fBread \fIchannelId count\fR +. +This \fIoptional\fR subcommand is called when the user requests data from the +channel \fIchannelId\fR. \fIcount\fR specifies how many \fIbytes\fR have been +requested. If the subcommand is not supported then it is not possible to read +from the channel handled by the command. +.RS +.PP +The return value of this subcommand is taken as the requested data +\fIbytes\fR. If the returned data contains more bytes than requested, +an error will be signaled and later thrown by the command which +performed the read (usually \fBgets\fR or \fBread\fR). However, +returning fewer bytes than requested is acceptable. +.PP +Note that returning nothing (0 bytes) is a signal to the higher layers +that \fBEOF\fR has been reached on the channel. To signal that the +channel is out of data right now, but has not yet reached \fBEOF\fR, +it is necessary to throw the error "EAGAIN", i.e. to either +.PP +.CS +return -code error EAGAIN +.CE +or +.CS +error EAGAIN +.CE +.PP +For extensibility any error whose value is a negative integer number +will cause the higher layers to set the C-level variable "\fBerrno\fR" +to the absolute value of this number, signaling a system error. +However, note that the exact mapping between these error numbers and +their meanings is operating system dependent. +.PP +For example, while on Linux both +.PP +.CS +return -code error -11 +.CE +and +.CS +error -11 +.CE +.PP +are equivalent to the examples above, using the more readable string "EAGAIN", +this is not true for BSD, where the equivalent number is -35. +.PP +The symbolic string however is the same across systems, and internally +translated to the correct number. No other error value has such a mapping +to a symbolic string. +.PP +If the subcommand throws any other error, the command which caused its +invocation (usually \fBgets\fR, or \fBread\fR) will appear to have +thrown this error. Any exception beyond \fBerror\fR, (e.g.,\ \fBbreak\fR, +etc.) is treated as and converted to an error. +.RE +.TP +\fIcmdPrefix \fBwrite \fIchannelId data\fR +. +This \fIoptional\fR subcommand is called when the user writes data to +the channel \fIchannelId\fR. The \fIdata\fR argument contains \fIbytes\fR, not +characters. Any type of transformation (EOL, encoding) configured for +the channel has already been applied at this point. If this subcommand +is not supported then it is not possible to write to the channel +handled by the command. +.RS +.PP +The return value of the subcommand is taken as the number of bytes +written by the channel. Anything non-numeric will cause an error to be +signaled and later thrown by the command which performed the write. A +negative value implies that the write failed. Returning a value +greater than the number of bytes given to the handler, or zero, is +forbidden and will cause the Tcl core to throw an error. +.PP +To signal that the channel is not able to accept data for writing +right now, it is necessary to throw the error "EAGAIN", i.e. to either +.PP +.CS +return -code error EAGAIN +.CE +or +.CS +error EAGAIN +.CE +.PP +For extensibility any error whose value is a negative integer number +will cause the higher layers to set the C-level variable "\fBerrno\fR" +to the absolute value of this number, signaling a system error. +However, note that the exact mapping between these error numbers and +their meanings is operating system dependent. +.PP +For example, while on Linux both +.PP +.CS +return -code error -11 +.CE +and +.CS +error -11 +.CE +.PP +are equivalent to the examples above, using the more readable string "EAGAIN", +this is not true for BSD, where the equivalent number is -35. +.PP +The symbolic string however is the same across systems, and internally +translated to the correct number. No other error value has such a mapping +to a symbolic string. +.PP +If the subcommand throws any other error the command which caused its +invocation (usually \fBputs\fR) will appear to have thrown this error. +Any exception beyond \fBerror\fR (e.g.,\ \fBbreak\fR, etc.) is treated +as and converted to an error. +.RE +.TP +\fIcmdPrefix \fBseek \fIchannelId offset base\fR +. +This \fIoptional\fR subcommand is responsible for the handling of +\fBchan seek\fR and \fBchan tell\fR requests on the channel +\fIchannelId\fR. If it is not supported then seeking will not be possible for +the channel. +.RS +.PP +The \fIbase\fR argument is the same as the equivalent argument of the +builtin \fBchan seek\fR, namely: +.TP 10 +\fBstart\fR +. +Seeking is relative to the beginning of the channel. +.TP 10 +\fBcurrent\fR +. +Seeking is relative to the current seek position. +.TP 10 +\fBend\fR +. +Seeking is relative to the end of the channel. +.PP +The \fIoffset\fR is an integer number specifying the amount of +\fBbytes\fR to seek forward or backward. A positive number should seek +forward, and a negative number should seek backward. +A channel may provide only limited seeking. For example sockets can +seek forward, but not backward. +.PP +The return value of the subcommand is taken as the (new) location of +the channel, counted from the start. This has to be an integer number +greater than or equal to zero. +If the subcommand throws an error the command which caused its +invocation (usually \fBchan seek\fR, or \fBchan tell\fR) will appear to have +thrown this error. Any exception beyond \fBerror\fR (e.g.,\ \fBbreak\fR, +etc.) is treated as and converted to an error. +.PP +The offset/base combination of 0/\fBcurrent\fR signals a \fBchan tell\fR +request, i.e.,\ seek nothing relative to the current location, making +the new location identical to the current one, which is then returned. +.RE +.TP +\fIcmdPrefix \fBconfigure \fIchannelId option value\fR +. +This \fIoptional\fR subcommand is for setting the type-specific options of +channel \fIchannelId\fR. The \fIoption\fR argument indicates the option to be +written, and the \fIvalue\fR argument indicates the value to set the option to. +.RS +.PP +This subcommand will never try to update more than one option at a +time; that is behavior implemented in the Tcl channel core. +.PP +The return value of the subcommand is ignored. +.PP +If the subcommand throws an error the command which performed the +(re)configuration or query (usually \fBfconfigure\fR or +\fBchan configure\fR) will appear to have thrown this error. Any exception +beyond \fBerror\fR (e.g.,\ \fBbreak\fR, etc.) is treated as and +converted to an error. +.RE +.TP +\fIcmdPrefix \fBcget \fIchannelId option\fR +. +This \fIoptional\fR subcommand is used when reading a single type-specific +option of channel \fIchannelId\fR. If this subcommand is supported then the +subcommand \fBcgetall\fR must be supported as well. +.RS +.PP +The subcommand should return the value of the specified \fIoption\fR. +.PP +If the subcommand throws an error, the command which performed the +(re)configuration or query (usually \fBfconfigure\fR or \fBchan configure\fR) +will appear to have thrown this error. Any exception beyond \fIerror\fR +(e.g.,\ \fBbreak\fR, etc.) is treated as and converted to an error. +.RE +.TP +\fIcmdPrefix \fBcgetall \fIchannelId\fR +. +This \fIoptional\fR subcommand is used for reading all type-specific options +of channel \fIchannelId\fR. If this subcommand is supported then the +subcommand \fBcget\fR has to be supported as well. +.RS +.PP +The subcommand should return a list of all options and their values. +This list must have an even number of elements. +.PP +If the subcommand throws an error the command which performed the +(re)configuration or query (usually \fBfconfigure\fR or \fBchan configure\fR) +will appear to have thrown this error. Any exception beyond \fBerror\fR +(e.g.,\ \fBbreak\fR, etc.) is treated as and converted to an error. +.RE +.TP +\fIcmdPrefix \fBblocking \fIchannelId mode\fR +. +This \fIoptional\fR subcommand handles changes to the blocking mode of the +channel \fIchannelId\fR. The \fImode\fR is a boolean flag. A true value means +that the channel has to be set to blocking, and a false value means that the +channel should be non-blocking. +.RS +.PP +The return value of the subcommand is ignored. +.PP +If the subcommand throws an error the command which caused its +invocation (usually \fBfconfigure\fR or \fBchan configure\fR) will appear to +have thrown this error. Any exception beyond \fBerror\fR (e.g.,\ \fBbreak\fR, +etc.) is treated as and converted to an error. +.RE +.SH NOTES +Some of the functions supported in channels defined in Tcl's C +interface are not available to channels reflected to the Tcl level. +.PP +The function \fBTcl_DriverGetHandleProc\fR is not supported; +i.e.,\ reflected channels do not have OS specific handles. +.PP +The function \fBTcl_DriverHandlerProc\fR is not supported. This driver +function is relevant only for stacked channels, i.e.,\ transformations. +Reflected channels are always base channels, not transformations. +.PP +The function \fBTcl_DriverFlushProc\fR is not supported. This is +because the current generic I/O layer of Tcl does not use this +function anywhere at all. Therefore support at the Tcl level makes no +sense either. This may be altered in the future (through extending the +API defined here and changing its version number) should the function +be used at some time in the future. +.SH EXAMPLE +.PP +This demonstrates how to make a channel that reads from a string. +.PP +.CS +oo::class create stringchan { + variable data pos + constructor {string {encoding {}}} { + if {$encoding eq ""} {set encoding [encoding system]} + set data [encoding convertto $encoding $string] + set pos 0 + } + + method \fBinitialize\fR {ch mode} { + return "initialize finalize watch read seek" + } + method \fBfinalize\fR {ch} { + my destroy + } + method \fBwatch\fR {ch events} { + # Must be present but we ignore it because we do not + # post any events + } + + # Must be present on a readable channel + method \fBread\fR {ch count} { + set d [string range $data $pos [expr {$pos+$count-1}]] + incr pos [string length $d] + return $d + } + + # This method is optional, but useful for the example below + method \fBseek\fR {ch offset base} { + switch $base { + start { + set pos $offset + } + current { + incr pos $offset + } + end { + set pos [string length $data] + incr pos $offset + } + } + if {$pos < 0} { + set pos 0 + } elseif {$pos > [string length $data]} { + set pos [string length $data] + } + return $pos + } +} + +# Now we create an instance... +set string "The quick brown fox jumps over the lazy dog.\\n" +set ch [\fBchan create\fR read [stringchan new $string]] + +puts [gets $ch]; # Prints the whole string + +seek $ch -5 end; +puts [read $ch]; # Prints just the last word +.CE +.SH "SEE ALSO" +chan(n), transchan(n) +.SH KEYWORDS +API, channel, ensemble, prefix, reflection +'\" Local Variables: +'\" mode: nroff +'\" End: diff --git a/tcl8.6/doc/regexp.n b/tcl8.6/doc/regexp.n new file mode 100644 index 0000000..6f303a4 --- /dev/null +++ b/tcl8.6/doc/regexp.n @@ -0,0 +1,208 @@ +'\" +'\" Copyright (c) 1998 Sun Microsystems, Inc. +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH regexp n 8.3 Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +regexp \- Match a regular expression against a string +.SH SYNOPSIS +\fBregexp \fR?\fIswitches\fR? \fIexp string \fR?\fImatchVar\fR? ?\fIsubMatchVar subMatchVar ...\fR? +.BE +.SH DESCRIPTION +.PP +Determines whether the regular expression \fIexp\fR matches part or +all of \fIstring\fR and returns 1 if it does, 0 if it does not, unless +\fB\-inline\fR is specified (see below). +(Regular expression matching is described in the \fBre_syntax\fR +reference page.) +.PP +If additional arguments are specified after \fIstring\fR then they +are treated as the names of variables in which to return +information about which part(s) of \fIstring\fR matched \fIexp\fR. +\fIMatchVar\fR will be set to the range of \fIstring\fR that +matched all of \fIexp\fR. The first \fIsubMatchVar\fR will contain +the characters in \fIstring\fR that matched the leftmost parenthesized +subexpression within \fIexp\fR, the next \fIsubMatchVar\fR will +contain the characters that matched the next parenthesized +subexpression to the right in \fIexp\fR, and so on. +.PP +If the initial arguments to \fBregexp\fR start with \fB\-\fR then +they are treated as switches. The following switches are +currently supported: +.TP 15 +\fB\-about\fR +. +Instead of attempting to match the regular expression, returns a list +containing information about the regular expression. The first +element of the list is a subexpression count. The second element is a +list of property names that describe various attributes of the regular +expression. This switch is primarily intended for debugging purposes. +.TP 15 +\fB\-expanded\fR +. +Enables use of the expanded regular expression syntax where +whitespace and comments are ignored. This is the same as specifying +the \fB(?x)\fR embedded option (see the \fBre_syntax\fR manual page). +.TP 15 +\fB\-indices\fR +. +Changes what is stored in the \fImatchVar\fR and \fIsubMatchVar\fRs. +Instead of storing the matching characters from \fIstring\fR, +each variable +will contain a list of two decimal strings giving the indices +in \fIstring\fR of the first and last characters in the matching +range of characters. +.TP 15 +\fB\-line\fR +. +Enables newline-sensitive matching. By default, newline is a +completely ordinary character with no special meaning. With this +flag, +.QW [^ +bracket expressions and +.QW . +never match newline, +.QW ^ +matches an empty string after any newline in addition to its normal +function, and +.QW $ +matches an empty string before any newline in +addition to its normal function. This flag is equivalent to +specifying both \fB\-linestop\fR and \fB\-lineanchor\fR, or the +\fB(?n)\fR embedded option (see the \fBre_syntax\fR manual page). +.TP 15 +\fB\-linestop\fR +. +Changes the behavior of +.QW [^ +bracket expressions and +.QW . +so that they +stop at newlines. This is the same as specifying the \fB(?p)\fR +embedded option (see the \fBre_syntax\fR manual page). +.TP 15 +\fB\-lineanchor\fR +. +Changes the behavior of +.QW ^ +and +.QW $ +(the +.QW anchors ) +so they match the +beginning and end of a line respectively. This is the same as +specifying the \fB(?w)\fR embedded option (see the \fBre_syntax\fR +manual page). +.TP 15 +\fB\-nocase\fR +. +Causes upper-case characters in \fIstring\fR to be treated as +lower case during the matching process. +.TP 15 +\fB\-all\fR +. +Causes the regular expression to be matched as many times as possible +in the string, returning the total number of matches found. If this +is specified with match variables, they will contain information for +the last match only. +.TP 15 +\fB\-inline\fR +. +Causes the command to return, as a list, the data that would otherwise +be placed in match variables. When using \fB\-inline\fR, +match variables may not be specified. If used with \fB\-all\fR, the +list will be concatenated at each iteration, such that a flat list is +always returned. For each match iteration, the command will append the +overall match data, plus one element for each subexpression in the +regular expression. Examples are: +.RS +.PP +.CS +\fBregexp\fR -inline -- {\ew(\ew)} " inlined " + \fI\(-> in n\fR +\fBregexp\fR -all -inline -- {\ew(\ew)} " inlined " + \fI\(-> in n li i ne e\fR +.CE +.RE +.TP 15 +\fB\-start\fR \fIindex\fR +. +Specifies a character index offset into the string to start +matching the regular expression at. +The \fIindex\fR value is interpreted in the same manner +as the \fIindex\fR argument to \fBstring index\fR. +When using this switch, +.QW ^ +will not match the beginning of the line, and \eA will still +match the start of the string at \fIindex\fR. If \fB\-indices\fR +is specified, the indices will be indexed starting from the +absolute beginning of the input string. +\fIindex\fR will be constrained to the bounds of the input string. +.TP 15 +\fB\-\|\-\fR +. +Marks the end of switches. The argument following this one will +be treated as \fIexp\fR even if it starts with a \fB\-\fR. +.PP +If there are more \fIsubMatchVar\fRs than parenthesized +subexpressions within \fIexp\fR, or if a particular subexpression +in \fIexp\fR does not match the string (e.g. because it was in a +portion of the expression that was not matched), then the corresponding +\fIsubMatchVar\fR will be set to +.QW "\fB\-1 \-1\fR" +if \fB\-indices\fR has been specified or to an empty string otherwise. +.SH EXAMPLES +.PP +Find the first occurrence of a word starting with \fBfoo\fR in a +string that is not actually an instance of \fBfoobar\fR, and get the +letters following it up to the end of the word into a variable: +.PP +.CS +\fBregexp\fR {\emfoo(?!bar\eM)(\ew*)} $string \-> restOfWord +.CE +.PP +Note that the whole matched substring has been placed in the variable +.QW \fB\->\fR , +which is a name chosen to look nice given that we are not +actually interested in its contents. +.PP +Find the index of the word \fBbadger\fR (in any case) within a string +and store that in the variable \fBlocation\fR: +.PP +.CS +\fBregexp\fR \-indices {(?i)\embadger\eM} $string location +.CE +.PP +This could also be written as a \fIbasic\fR regular expression (as opposed +to using the default syntax of \fIadvanced\fR regular expressions) match by +prefixing the expression with a suitable flag: +.PP +.CS +\fBregexp\fR \-indices {(?ib)\e<badger\e>} $string location +.CE +.PP +This counts the number of octal digits in a string: +.PP +.CS +\fBregexp\fR \-all {[0\-7]} $string +.CE +.PP +This lists all words (consisting of all sequences of non-whitespace +characters) in a string, and is useful as a more powerful version of the +\fBsplit\fR command: +.PP +.CS +\fBregexp\fR \-all \-inline {\eS+} $string +.CE +.SH "SEE ALSO" +re_syntax(n), regsub(n), string(n) +.SH KEYWORDS +match, parsing, pattern, regular expression, splitting, string +'\" Local Variables: +'\" mode: nroff +'\" End: diff --git a/tcl8.6/doc/registry.n b/tcl8.6/doc/registry.n new file mode 100644 index 0000000..001def9 --- /dev/null +++ b/tcl8.6/doc/registry.n @@ -0,0 +1,218 @@ +'\" +'\" Copyright (c) 1997 Sun Microsystems, Inc. +'\" Copyright (c) 2002 ActiveState Corporation. +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH registry n 1.1 registry "Tcl Bundled Packages" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +registry \- Manipulate the Windows registry +.SH SYNOPSIS +.sp +\fBpackage require registry 1.3\fR +.sp +\fBregistry \fR?\fI\-mode\fR? \fIoption\fR \fIkeyName\fR ?\fIarg arg ...\fR? +.BE +.SH DESCRIPTION +.PP +The \fBregistry\fR package provides a general set of operations for +manipulating the Windows registry. The package implements the +\fBregistry\fR Tcl command. This command is only supported on the +Windows platform. Warning: this command should be used with caution +as a corrupted registry can leave your system in an unusable state. +.PP +\fIKeyName\fR is the name of a registry key. Registry keys must be +one of the following forms: +.RS +.PP +\fB\e\e\fIhostname\fB\e\fIrootname\fB\e\fIkeypath\fR +.PP +\fIrootname\fB\e\fIkeypath\fR +.PP +\fIrootname\fR +.RE +.PP +\fIHostname\fR specifies the name of any valid Windows +host that exports its registry. The \fIrootname\fR component must be +one of \fBHKEY_LOCAL_MACHINE\fR, \fBHKEY_USERS\fR, +\fBHKEY_CLASSES_ROOT\fR, \fBHKEY_CURRENT_USER\fR, +\fBHKEY_CURRENT_CONFIG\fR, \fBHKEY_PERFORMANCE_DATA\fR, or +\fBHKEY_DYN_DATA\fR. The \fIkeypath\fR can be one or more +registry key names separated by backslash (\fB\e\fR) characters. +.PP +.VS 8.6 +The optional \fI\-mode\fR argument indicates which registry to work +with; when it is \fB\-32bit\fR the 32-bit registry will be used, and +when it is \fB\-64bit\fR the 64-bit registry will be used. If this +argument is omitted, the system's default registry will be the subject +of the requested operation. +.VE 8.6 +.PP +\fIOption\fR indicates what to do with the registry key name. Any +unique abbreviation for \fIoption\fR is acceptable. The valid options +are: +.TP +\fBregistry broadcast \fIkeyName\fR ?\fB\-timeout \fImilliseconds\fR? +. +Sends a broadcast message to the system and running programs to notify them +of certain updates. This is necessary to propagate changes to key registry +keys like Environment. The timeout specifies the amount of time, in +milliseconds, to wait for applications to respond to the broadcast message. +It defaults to 3000. The following example demonstrates how to add a path +to the global Environment and notify applications of the change without +requiring a logoff/logon step (assumes admin privileges): +.RS +.PP +.CS +set regPath [join { + HKEY_LOCAL_MACHINE + SYSTEM + CurrentControlSet + Control + {Session Manager} + Environment +} "\e\e"] +set curPath [\fBregistry get\fR $regPath "Path"] +\fBregistry set\fR $regPath "Path" "$curPath;$addPath" +\fBregistry broadcast\fR "Environment" +.CE +.RE +.TP +\fBregistry delete \fIkeyName\fR ?\fIvalueName\fR? +. +If the optional \fIvalueName\fR argument is present, the specified +value under \fIkeyName\fR will be deleted from the registry. If the +optional \fIvalueName\fR is omitted, the specified key and any subkeys +or values beneath it in the registry hierarchy will be deleted. If +the key could not be deleted then an error is generated. If the key +did not exist, the command has no effect. +.TP +\fBregistry get \fIkeyName valueName\fR +. +Returns the data associated with the value \fIvalueName\fR under the key +\fIkeyName\fR. If either the key or the value does not exist, then an +error is generated. For more details on the format of the returned +data, see \fBSUPPORTED TYPES\fR, below. +.TP +\fBregistry keys \fIkeyName\fR ?\fIpattern\fR? +. +If \fIpattern\fR is not specified, returns a list of names of all the +subkeys of \fIkeyName\fR. If \fIpattern\fR is specified, only those +names matching \fIpattern\fR are returned. Matching is determined +using the same rules as for \fBstring match\fR. If the +specified \fIkeyName\fR does not exist, then an error is generated. +.TP +\fBregistry set \fIkeyName\fR ?\fIvalueName data \fR?\fItype\fR?? +. +If \fIvalueName\fR is not specified, creates the key \fIkeyName\fR if +it does not already exist. If \fIvalueName\fR is specified, creates +the key \fIkeyName\fR and value \fIvalueName\fR if necessary. The +contents of \fIvalueName\fR are set to \fIdata\fR with the type +indicated by \fItype\fR. If \fItype\fR is not specified, the type +\fBsz\fR is assumed. For more details on the data and type arguments, +see \fBSUPPORTED TYPES\fR below. +.TP +\fBregistry type \fIkeyName valueName\fR +. +Returns the type of the value \fIvalueName\fR in the key +\fIkeyName\fR. For more information on the possible types, see +\fBSUPPORTED TYPES\fR, below. +.TP +\fBregistry values \fIkeyName\fR ?\fIpattern\fR? +. +If \fIpattern\fR is not specified, returns a list of names of all the +values of \fIkeyName\fR. If \fIpattern\fR is specified, only those +names matching \fIpattern\fR are returned. Matching is determined +using the same rules as for \fBstring match\fR. +.SH "SUPPORTED TYPES" +Each value under a key in the registry contains some data of a +particular type in a type-specific representation. The \fBregistry\fR +command converts between this internal representation and one that can +be manipulated by Tcl scripts. In most cases, the data is simply +returned as a Tcl string. The type indicates the intended use for the +data, but does not actually change the representation. For some +types, the \fBregistry\fR command returns the data in a different form to +make it easier to manipulate. The following types are recognized by the +registry command: +.TP 17 +\fBbinary\fR +. +The registry value contains arbitrary binary data. The data is represented +exactly in Tcl, including any embedded nulls. +.TP +\fBnone\fR +. +The registry value contains arbitrary binary data with no defined +type. The data is represented exactly in Tcl, including any embedded +nulls. +.TP +\fBsz\fR +. +The registry value contains a null-terminated string. The data is +represented in Tcl as a string. +.TP +\fBexpand_sz\fR +. +The registry value contains a null-terminated string that contains +unexpanded references to environment variables in the normal Windows +style (for example, +.QW %PATH% ). +The data is represented in Tcl as a string. +.TP +\fBdword\fR +. +The registry value contains a little-endian 32-bit number. The data is +represented in Tcl as a decimal string. +.TP +\fBdword_big_endian\fR +. +The registry value contains a big-endian 32-bit number. The data is +represented in Tcl as a decimal string. +.TP +\fBlink\fR +. +The registry value contains a symbolic link. The data is represented +exactly in Tcl, including any embedded nulls. +.TP +\fBmulti_sz\fR +. +The registry value contains an array of null-terminated strings. The +data is represented in Tcl as a list of strings. +.TP +\fBresource_list\fR +. +The registry value contains a device-driver resource list. The data +is represented exactly in Tcl, including any embedded nulls. +.PP +In addition to the symbolically named types listed above, unknown +types are identified using a 32-bit integer that corresponds to the +type code returned by the system interfaces. In this case, the data +is represented exactly in Tcl, including any embedded nulls. +.SH "PORTABILITY ISSUES" +The registry command is only available on Windows. +.SH EXAMPLE +Print out how double-clicking on a Tcl script file will invoke a Tcl +interpreter: +.PP +.CS +package require registry +set ext .tcl + +# Read the type name +set type [\fBregistry get\fR HKEY_CLASSES_ROOT\e\e$ext {}] +# Work out where to look for the command +set path HKEY_CLASSES_ROOT\e\e$type\e\eShell\e\eOpen\e\ecommand +# Read the command! +set command [\fBregistry get\fR $path {}] + +puts "$ext opens with $command" +.CE +.SH KEYWORDS +registry +'\" Local Variables: +'\" mode: nroff +'\" End: diff --git a/tcl8.6/doc/regsub.n b/tcl8.6/doc/regsub.n new file mode 100644 index 0000000..a5b79de --- /dev/null +++ b/tcl8.6/doc/regsub.n @@ -0,0 +1,192 @@ +'\" +'\" Copyright (c) 1993 The Regents of the University of California. +'\" Copyright (c) 1994-1996 Sun Microsystems, Inc. +'\" Copyright (c) 2000 Scriptics Corporation. +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH regsub n 8.3 Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +regsub \- Perform substitutions based on regular expression pattern matching +.SH SYNOPSIS +\fBregsub \fR?\fIswitches\fR? \fIexp string subSpec \fR?\fIvarName\fR? +.BE +.SH DESCRIPTION +.PP +This command matches the regular expression \fIexp\fR against +\fIstring\fR, +and either copies \fIstring\fR to the variable whose name is +given by \fIvarName\fR or returns \fIstring\fR if \fIvarName\fR is not +present. +(Regular expression matching is described in the \fBre_syntax\fR +reference page.) +If there is a match, then while copying \fIstring\fR to \fIvarName\fR +(or to the result of this command if \fIvarName\fR is not present) +the portion of \fIstring\fR that +matched \fIexp\fR is replaced with \fIsubSpec\fR. +If \fIsubSpec\fR contains a +.QW & +or +.QW \e0 , +then it is replaced in the substitution with the portion of +\fIstring\fR that matched \fIexp\fR. +If \fIsubSpec\fR contains a +.QW \e\fIn\fR , +where \fIn\fR is a digit +between 1 and 9, then it is replaced in the substitution with +the portion of \fIstring\fR that matched the \fIn\fR'th +parenthesized subexpression of \fIexp\fR. +Additional backslashes may be used in \fIsubSpec\fR to prevent special +interpretation of +.QW & , +.QW \e0 , +.QW \e\fIn\fR +and backslashes. +The use of backslashes in \fIsubSpec\fR tends to interact badly +with the Tcl parser's use of backslashes, so it is generally +safest to enclose \fIsubSpec\fR in braces if it includes +backslashes. +.LP +If the initial arguments to \fBregsub\fR start with \fB\-\fR then +they are treated as switches. The following switches are +currently supported: +.TP +\fB\-all\fR +. +All ranges in \fIstring\fR that match \fIexp\fR are found and +substitution is performed for each of these ranges. +Without this switch only the first +matching range is found and substituted. +If \fB\-all\fR is specified, then +.QW & +and +.QW \e\fIn\fR +sequences are handled for each substitution using the information +from the corresponding match. +.TP +\fB\-expanded\fR +. +Enables use of the expanded regular expression syntax where +whitespace and comments are ignored. This is the same as specifying +the \fB(?x)\fR embedded option (see the \fBre_syntax\fR manual page). +.TP +\fB\-line\fR +. +Enables newline-sensitive matching. By default, newline is a +completely ordinary character with no special meaning. With this flag, +.QW [^ +bracket expressions and +.QW . +never match newline, +.QW ^ +matches an empty string after any newline in addition to its normal +function, and +.QW $ +matches an empty string before any newline in +addition to its normal function. This flag is equivalent to +specifying both \fB\-linestop\fR and \fB\-lineanchor\fR, or the +\fB(?n)\fR embedded option (see the \fBre_syntax\fR manual page). +.TP +\fB\-linestop\fR +. +Changes the behavior of +.QW [^ +bracket expressions and +.QW . +so that they +stop at newlines. This is the same as specifying the \fB(?p)\fR +embedded option (see the \fBre_syntax\fR manual page). +.TP +\fB\-lineanchor\fR +. +Changes the behavior of +.QW ^ +and +.QW $ +(the +.QW anchors ) +so they match the +beginning and end of a line respectively. This is the same as +specifying the \fB(?w)\fR embedded option (see the \fBre_syntax\fR +manual page). +.TP +\fB\-nocase\fR +. +Upper-case characters in \fIstring\fR will be converted to lower-case +before matching against \fIexp\fR; however, substitutions specified +by \fIsubSpec\fR use the original unconverted form of \fIstring\fR. +.TP +\fB\-start\fR \fIindex\fR +. +Specifies a character index offset into the string to start +matching the regular expression at. +The \fIindex\fR value is interpreted in the same manner +as the \fIindex\fR argument to \fBstring index\fR. +When using this switch, +.QW ^ +will not match the beginning of the line, and \eA will still +match the start of the string at \fIindex\fR. +\fIindex\fR will be constrained to the bounds of the input string. +.TP +\fB\-\|\-\fR +. +Marks the end of switches. The argument following this one will +be treated as \fIexp\fR even if it starts with a \fB\-\fR. +.PP +If \fIvarName\fR is supplied, the command returns a count of the +number of matching ranges that were found and replaced, otherwise the +string after replacement is returned. +See the manual entry for \fBregexp\fR for details on the interpretation +of regular expressions. +.SH EXAMPLES +.PP +Replace (in the string in variable \fIstring\fR) every instance of +\fBfoo\fR which is a word by itself with \fBbar\fR: +.PP +.CS +\fBregsub\fR -all {\emfoo\eM} $string bar string +.CE +.PP +or (using the +.QW "basic regular expression" +syntax): +.PP +.CS +\fBregsub\fR -all {(?b)\e<foo\e>} $string bar string +.CE +.PP +Insert double-quotes around the first instance of the word +\fBinteresting\fR, however it is capitalized. +.PP +.CS +\fBregsub\fR -nocase {\eyinteresting\ey} $string {"&"} string +.CE +.PP +Convert all non-ASCII and Tcl-significant characters into \eu escape +sequences by using \fBregsub\fR and \fBsubst\fR in combination: +.PP +.CS +# This RE is just a character class for almost everything "bad" +set RE {[][{};#\e\e\e$ \er\et\eu0080-\euffff]} + +# We will substitute with a fragment of Tcl script in brackets +set substitution {[format \e\e\e\eu%04x [scan "\e\e&" %c]]} + +# Now we apply the substitution to get a subst-string that +# will perform the computational parts of the conversion. Note +# that newline is handled specially through \fBstring map\fR since +# backslash-newline is a special sequence. +set quoted [subst [string map {\en {\e\eu000a}} \e + [\fBregsub\fR -all $RE $string $substitution]]] +.CE +.SH "SEE ALSO" +regexp(n), re_syntax(n), subst(n), string(n) +.SH KEYWORDS +match, pattern, quoting, regular expression, substitution +'\" Local Variables: +'\" mode: nroff +'\" End: diff --git a/tcl8.6/doc/rename.n b/tcl8.6/doc/rename.n new file mode 100644 index 0000000..744bf5a --- /dev/null +++ b/tcl8.6/doc/rename.n @@ -0,0 +1,45 @@ +'\" +'\" Copyright (c) 1993 The Regents of the University of California. +'\" Copyright (c) 1994-1997 Sun Microsystems, Inc. +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH rename n "" Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +rename \- Rename or delete a command +.SH SYNOPSIS +\fBrename \fIoldName newName\fR +.BE +.SH DESCRIPTION +.PP +Rename the command that used to be called \fIoldName\fR so that it +is now called \fInewName\fR. +If \fInewName\fR is an empty string then \fIoldName\fR is deleted. +\fIoldName\fR and \fInewName\fR may include namespace qualifiers +(names of containing namespaces). +If a command is renamed into a different namespace, +future invocations of it will execute in the new namespace. +The \fBrename\fR command returns an empty string as result. +.SH EXAMPLE +.PP +The \fBrename\fR command can be used to wrap the standard Tcl commands +with your own monitoring machinery. For example, you might wish to +count how often the \fBsource\fR command is called: +.PP +.CS +\fBrename\fR ::source ::theRealSource +set sourceCount 0 +proc ::source args { + global sourceCount + puts "called source for the [incr sourceCount]'th time" + uplevel 1 ::theRealSource $args +} +.CE +.SH "SEE ALSO" +namespace(n), proc(n) +.SH KEYWORDS +command, delete, namespace, rename diff --git a/tcl8.6/doc/return.n b/tcl8.6/doc/return.n new file mode 100644 index 0000000..ea590ea --- /dev/null +++ b/tcl8.6/doc/return.n @@ -0,0 +1,326 @@ +'\" +'\" Copyright (c) 1993 The Regents of the University of California. +'\" Copyright (c) 1994-1996 Sun Microsystems, Inc. +'\" Contributions from Don Porter, NIST, 2003. (not subject to US copyright) +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH return n 8.5 Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +return \- Return from a procedure, or set return code of a script +.SH SYNOPSIS +\fBreturn \fR?\fIresult\fR? +.sp +\fBreturn \fR?\fB\-code \fIcode\fR? ?\fIresult\fR? +.sp +\fBreturn \fR?\fIoption value \fR...? ?\fIresult\fR? +.BE +.SH DESCRIPTION +.PP +In its simplest usage, the \fBreturn\fR command is used without options +in the body of a procedure to immediately return control to the caller +of the procedure. If a \fIresult\fR argument is provided, its value +becomes the result of the procedure passed back to the caller. +If \fIresult\fR is not specified then an empty string will be returned +to the caller as the result of the procedure. +.PP +The \fBreturn\fR command serves a similar function within script +files that are evaluated by the \fBsource\fR command. When \fBsource\fR +evaluates the contents of a file as a script, an invocation of +the \fBreturn\fR command will cause script evaluation +to immediately cease, and the value \fIresult\fR (or an empty string) +will be returned as the result of the \fBsource\fR command. +.SH "EXCEPTIONAL RETURN CODES" +.PP +In addition to the result of a procedure, the return +code of a procedure may also be set by \fBreturn\fR +through use of the \fB\-code\fR option. +In the usual case where the \fB\-code\fR option is not +specified the procedure will return normally. +However, the \fB\-code\fR option may be used to generate an +exceptional return from the procedure. +\fICode\fR may have any of the following values: +.TP 13 +\fBok\fR (or \fB0\fR) +. +Normal return: same as if the option is omitted. The return code +of the procedure is 0 (\fBTCL_OK\fR). +.TP 13 +\fBerror\fR (or \fB1\fR) +. +Error return: the return code of the procedure is 1 (\fBTCL_ERROR\fR). +The procedure command behaves in its calling context as if it +were the command \fBerror\fR \fIresult\fR. See below for additional +options. +.TP 13 +\fBreturn\fR (or \fB2\fR) +. +The return code of the procedure is 2 (\fBTCL_RETURN\fR). The +procedure command behaves in its calling context as if it +were the command \fBreturn\fR (with no arguments). +.TP 13 +\fBbreak\fR (or \fB3\fR) +. +The return code of the procedure is 3 (\fBTCL_BREAK\fR). The +procedure command behaves in its calling context as if it +were the command \fBbreak\fR. +.TP 13 +\fBcontinue\fR (or \fB4\fR) +. +The return code of the procedure is 4 (\fBTCL_CONTINUE\fR). The +procedure command behaves in its calling context as if it +were the command \fBcontinue\fR. +.TP 13 +\fIvalue\fR +. +\fIValue\fR must be an integer; it will be returned as the +return code for the current procedure. +.LP +When a procedure wants to signal that it has received invalid +arguments from its caller, it may use \fBreturn -code error\fR +with \fIresult\fR set to a suitable error message. Otherwise +usage of the \fBreturn -code\fR option is mostly limited to +procedures that implement a new control structure. +.PP +The \fBreturn \-code\fR command acts similarly within script +files that are evaluated by the \fBsource\fR command. During the +evaluation of the contents of a file as a script by \fBsource\fR, +an invocation of the \fBreturn \-code \fIcode\fR command will cause +the return code of \fBsource\fR to be \fIcode\fR. +.SH "RETURN OPTIONS" +.PP +In addition to a result and a return code, evaluation of a command +in Tcl also produces a dictionary of return options. In general +usage, all \fIoption value\fR pairs given as arguments to \fBreturn\fR +become entries in the return options dictionary, and any values at all +are acceptable except as noted below. The \fBcatch\fR command may be +used to capture all of this information \(em the return code, the result, +and the return options dictionary \(em that arise from evaluation of a +script. +.PP +As documented above, the \fB\-code\fR entry in the return options dictionary +receives special treatment by Tcl. There are other return options also +recognized and treated specially by Tcl. They are: +.TP +\fB\-errorcode \fIlist\fR +. +The \fB\-errorcode\fR option receives special treatment only when the value +of the \fB\-code\fR option is \fBTCL_ERROR\fR. Then the \fIlist\fR value +is meant to be additional information about the error, +presented as a Tcl list for further processing by programs. +If no \fB\-errorcode\fR option is provided to \fBreturn\fR when +the \fB\-code error\fR option is provided, Tcl will set the value +of the \fB\-errorcode\fR entry in the return options dictionary +to the default value of \fBNONE\fR. The \fB\-errorcode\fR return +option will also be stored in the global variable \fBerrorCode\fR. +.TP +\fB\-errorinfo \fIinfo\fR +. +The \fB\-errorinfo\fR option receives special treatment only when the value +of the \fB\-code\fR option is \fBTCL_ERROR\fR. Then \fIinfo\fR is the initial +stack trace, meant to provide to a human reader additional information +about the context in which the error occurred. The stack trace will +also be stored in the global variable \fBerrorInfo\fR. +If no \fB\-errorinfo\fR option is provided to \fBreturn\fR when +the \fB\-code error\fR option is provided, Tcl will provide its own +initial stack trace value in the entry for \fB\-errorinfo\fR. Tcl's +initial stack trace will include only the call to the procedure, and +stack unwinding will append information about higher stack levels, but +there will be no information about the context of the error within +the procedure. Typically the \fIinfo\fR value is supplied from +the value of \fB\-errorinfo\fR in a return options dictionary captured +by the \fBcatch\fR command (or from the copy of that information +stored in the global variable \fBerrorInfo\fR). +.TP +\fB\-errorstack \fIlist\fR +.VS 8.6 +The \fB\-errorstack\fR option receives special treatment only when the value +of the \fB\-code\fR option is \fBTCL_ERROR\fR. Then \fIlist\fR is the initial +error stack, recording actual argument values passed to each proc level. The error stack will +also be reachable through \fBinfo errorstack\fR. +If no \fB\-errorstack\fR option is provided to \fBreturn\fR when +the \fB\-code error\fR option is provided, Tcl will provide its own +initial error stack in the entry for \fB\-errorstack\fR. Tcl's +initial error stack will include only the call to the procedure, and +stack unwinding will append information about higher stack levels, but +there will be no information about the context of the error within +the procedure. Typically the \fIlist\fR value is supplied from +the value of \fB\-errorstack\fR in a return options dictionary captured +by the \fBcatch\fR command (or from the copy of that information from +\fBinfo errorstack\fR). +.VE 8.6 +.TP +\fB\-level \fIlevel\fR +. +The \fB\-level\fR and \fB\-code\fR options work together to set the return +code to be returned by one of the commands currently being evaluated. +The \fIlevel\fR value must be a non-negative integer representing a number +of levels on the call stack. It defines the number of levels up the stack +at which the return code of a command currently being evaluated should +be \fIcode\fR. If no \fB\-level\fR option is provided, the default value +of \fIlevel\fR is 1, so that \fBreturn\fR sets the return code that the +current procedure returns to its caller, 1 level up the call stack. The +mechanism by which these options work is described in more detail below. +.TP +\fB\-options \fIoptions\fR +. +The value \fIoptions\fR must be a valid dictionary. The entries of that +dictionary are treated as additional \fIoption value\fR pairs for the +\fBreturn\fR command. +.SH "RETURN CODE HANDLING MECHANISMS" +.PP +Return codes are used in Tcl to control program flow. A Tcl script +is a sequence of Tcl commands. So long as each command evaluation +returns a return code of \fBTCL_OK\fR, evaluation will continue to the next +command in the script. Any exceptional return code (non-\fBTCL_OK\fR) +returned by a command evaluation causes the flow on to the next +command to be interrupted. Script evaluation ceases, and the +exceptional return code from the command becomes the return code +of the full script evaluation. This is the mechanism by which +errors during script evaluation cause an interruption and unwinding +of the call stack. It is also the mechanism by which commands +like \fBbreak\fR, \fBcontinue\fR, and \fBreturn\fR cause script +evaluation to terminate without evaluating all commands in sequence. +.PP +Some of Tcl's built-in commands evaluate scripts as part of their +functioning. These commands can make use of exceptional return +codes to enable special features. For example, the built-in +Tcl commands that provide loops \(em such as \fBwhile\fR, \fBfor\fR, +and \fBforeach\fR \(em evaluate a script that is the body of the +loop. If evaluation of the loop body returns the return code +of \fBTCL_BREAK\fR or \fBTCL_CONTINUE\fR, the loop command can react in such +a way as to give the \fBbreak\fR and \fBcontinue\fR commands +their documented interpretation in loops. +.PP +Procedure invocation also involves evaluation of a script, the body +of the procedure. Procedure invocation provides special treatment +when evaluation of the procedure body returns the return code +\fBTCL_RETURN\fR. In that circumstance, the \fB\-level\fR entry in the +return options dictionary is decremented. If after decrementing, +the value of the \fB\-level\fR entry is 0, then the value of +the \fB\-code\fR entry becomes the return code of the procedure. +If after decrementing, the value of the \fB\-level\fR entry is +greater than zero, then the return code of the procedure is +\fBTCL_RETURN\fR. If the procedure invocation occurred during the +evaluation of the body of another procedure, the process will +repeat itself up the call stack, decrementing the value of the +\fB\-level\fR entry at each level, so that the \fIcode\fR will +be the return code of the current command \fIlevel\fR levels +up the call stack. The \fBsource\fR command performs the +same handling of the \fBTCL_RETURN\fR return code, which explains +the similarity of \fBreturn\fR invocation during a \fBsource\fR +to \fBreturn\fR invocation within a procedure. +.PP +The return code of the \fBreturn\fR command itself triggers this +special handling by procedure invocation. If \fBreturn\fR +is provided the option \fB\-level 0\fR, then the return code +of the \fBreturn\fR command itself will be the value \fIcode\fR +of the \fB\-code\fR option (or \fBTCL_OK\fR by default). Any other value +for the \fB\-level\fR option (including the default value of 1) +will cause the return code of the \fBreturn\fR command itself +to be \fBTCL_RETURN\fR, triggering a return from the enclosing procedure. +.SH EXAMPLES +.PP +First, a simple example of using \fBreturn\fR to return from a +procedure, interrupting the procedure body. +.PP +.CS +proc printOneLine {} { + puts "line 1" ;# This line will be printed. + \fBreturn\fR + puts "line 2" ;# This line will not be printed. +} +.CE +.PP +Next, an example of using \fBreturn\fR to set the value +returned by the procedure. +.PP +.CS +proc returnX {} {\fBreturn\fR X} +puts [returnX] ;# prints "X" +.CE +.PP +Next, a more complete example, using \fBreturn -code error\fR +to report invalid arguments. +.PP +.CS +proc factorial {n} { + if {![string is integer $n] || ($n < 0)} { + \fBreturn\fR -code error \e + "expected non-negative integer,\e + but got \e"$n\e"" + } + if {$n < 2} { + \fBreturn\fR 1 + } + set m [expr {$n - 1}] + set code [catch {factorial $m} factor] + if {$code != 0} { + \fBreturn\fR -code $code $factor + } + set product [expr {$n * $factor}] + if {$product < 0} { + \fBreturn\fR -code error \e + "overflow computing factorial of $n" + } + \fBreturn\fR $product +} +.CE +.PP +Next, a procedure replacement for \fBbreak\fR. +.PP +.CS +proc myBreak {} { + \fBreturn\fR -code break +} +.CE +.PP +With the \fB\-level 0\fR option, \fBreturn\fR itself can serve +as a replacement for \fBbreak\fR, with the help of \fBinterp alias\fR. +.PP +.CS +interp alias {} Break {} \fBreturn\fR -level 0 -code break +.CE +.PP +An example of using \fBcatch\fR and \fBreturn -options\fR to +re-raise a caught error: +.PP +.CS +proc doSomething {} { + set resource [allocate] + catch { + # Long script of operations + # that might raise an error + } result options + deallocate $resource + \fBreturn\fR -options $options $result +} +.CE +.PP +Finally an example of advanced use of the \fBreturn\fR options +to create a procedure replacement for \fBreturn\fR itself: +.PP +.CS +proc myReturn {args} { + set result "" + if {[llength $args] % 2} { + set result [lindex $args end] + set args [lrange $args 0 end-1] + } + set options [dict merge {-level 1} $args] + dict incr options -level + \fBreturn\fR -options $options $result +} +.CE +.SH "SEE ALSO" +break(n), catch(n), continue(n), dict(n), error(n), errorCode(n), +errorInfo(n), proc(n), source(n), throw(n), try(n) +.SH KEYWORDS +break, catch, continue, error, exception, procedure, result, return +.\" Local Variables: +.\" mode: nroff +.\" End: diff --git a/tcl8.6/doc/safe.n b/tcl8.6/doc/safe.n new file mode 100644 index 0000000..b39f2c2 --- /dev/null +++ b/tcl8.6/doc/safe.n @@ -0,0 +1,359 @@ +'\" +'\" Copyright (c) 1995-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. +'\" +.TH "Safe Tcl" n 8.0 Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +safe \- Creating and manipulating safe interpreters +.SH SYNOPSIS +\fB::safe::interpCreate\fR ?\fIslave\fR? ?\fIoptions...\fR? +.sp +\fB::safe::interpInit\fR \fIslave\fR ?\fIoptions...\fR? +.sp +\fB::safe::interpConfigure\fR \fIslave\fR ?\fIoptions...\fR? +.sp +\fB::safe::interpDelete\fR \fIslave\fR +.sp +\fB::safe::interpAddToAccessPath\fR \fIslave\fR \fIdirectory\fR +.sp +\fB::safe::interpFindInAccessPath\fR \fIslave\fR \fIdirectory\fR +.sp +\fB::safe::setLogCmd\fR ?\fIcmd arg...\fR? +.SS OPTIONS +.PP +?\fB\-accessPath\fR \fIpathList\fR? +?\fB\-statics\fR \fIboolean\fR? ?\fB\-noStatics\fR? +?\fB\-nested\fR \fIboolean\fR? ?\fB\-nestedLoadOk\fR? +?\fB\-deleteHook\fR \fIscript\fR? +.BE +.SH DESCRIPTION +Safe Tcl is a mechanism for executing untrusted Tcl scripts +safely and for providing mediated access by such scripts to +potentially dangerous functionality. +.PP +Safe Tcl ensures that untrusted Tcl scripts cannot harm the +hosting application. +It prevents integrity and privacy attacks. Untrusted Tcl +scripts are prevented from corrupting the state of the hosting +application or computer. Untrusted scripts are also prevented from +disclosing information stored on the hosting computer or in the +hosting application to any party. +.PP +Safe Tcl allows a master interpreter to create safe, restricted +interpreters that contain a set of predefined aliases for the \fBsource\fR, +\fBload\fR, \fBfile\fR, \fBencoding\fR, and \fBexit\fR commands and +are able to use the auto-loading and package mechanisms. +.PP +No knowledge of the file system structure is leaked to the +safe interpreter, because it has access only to a virtualized path +containing tokens. When the safe interpreter requests to source a file, it +uses the token in the virtual path as part of the file name to source; the +master interpreter transparently +translates the token into a real directory name and executes the +requested operation (see the section \fBSECURITY\fR below for details). +Different levels of security can be selected by using the optional flags +of the commands described below. +.PP +All commands provided in the master interpreter by Safe Tcl reside in +the \fBsafe\fR namespace. +.SH COMMANDS +The following commands are provided in the master interpreter: +.TP +\fB::safe::interpCreate\fR ?\fIslave\fR? ?\fIoptions...\fR? +Creates a safe interpreter, installs the aliases described in the section +\fBALIASES\fR and initializes the auto-loading and package mechanism as +specified by the supplied \fIoptions\fR. +See the \fBOPTIONS\fR section below for a description of the +optional arguments. +If the \fIslave\fR argument is omitted, a name will be generated. +\fB::safe::interpCreate\fR always returns the interpreter name. +.TP +\fB::safe::interpInit\fR \fIslave\fR ?\fIoptions...\fR? +This command is similar to \fBinterpCreate\fR except it that does not +create the safe interpreter. \fIslave\fR must have been created by some +other means, like \fBinterp create\fR \fB\-safe\fR. +.TP +\fB::safe::interpConfigure\fR \fIslave\fR ?\fIoptions...\fR? +If no \fIoptions\fR are given, returns the settings for all options for the +named safe interpreter as a list of options and their current values +for that \fIslave\fR. +If a single additional argument is provided, +it will return a list of 2 elements \fIname\fR and \fIvalue\fR where +\fIname\fR is the full name of that option and \fIvalue\fR the current value +for that option and the \fIslave\fR. +If more than two additional arguments are provided, it will reconfigure the +safe interpreter and change each and only the provided options. +See the section on \fBOPTIONS\fR below for options description. +Example of use: +.RS +.PP +.CS +# Create new interp with the same configuration as "$i0": +set i1 [safe::interpCreate {*}[safe::interpConfigure $i0]] + +# Get the current deleteHook +set dh [safe::interpConfigure $i0 \-del] + +# Change (only) the statics loading ok attribute of an +# interp and its deleteHook (leaving the rest unchanged): +safe::interpConfigure $i0 \-delete {foo bar} \-statics 0 +.CE +.RE +.TP +\fB::safe::interpDelete\fR \fIslave\fR +Deletes the safe interpreter and cleans up the corresponding +master interpreter data structures. +If a \fIdeleteHook\fR script was specified for this interpreter it is +evaluated before the interpreter is deleted, with the name of the +interpreter as an additional argument. +.TP +\fB::safe::interpFindInAccessPath\fR \fIslave\fR \fIdirectory\fR +This command finds and returns the token for the real directory +\fIdirectory\fR in the safe interpreter's current virtual access path. +It generates an error if the directory is not found. +Example of use: +.RS +.PP +.CS +$slave eval [list set tk_library \e + [::safe::interpFindInAccessPath $name $tk_library]] +.CE +.RE +.TP +\fB::safe::interpAddToAccessPath\fR \fIslave\fR \fIdirectory\fR +This command adds \fIdirectory\fR to the virtual path maintained for the +safe interpreter in the master, and returns the token that can be used in +the safe interpreter to obtain access to files in that directory. +If the directory is already in the virtual path, it only returns the token +without adding the directory to the virtual path again. +Example of use: +.RS +.PP +.CS +$slave eval [list set tk_library \e + [::safe::interpAddToAccessPath $name $tk_library]] +.CE +.RE +.TP +\fB::safe::setLogCmd\fR ?\fIcmd arg...\fR? +This command installs a script that will be called when interesting +life cycle events occur for a safe interpreter. +When called with no arguments, it returns the currently installed script. +When called with one argument, an empty string, the currently installed +script is removed and logging is turned off. +The script will be invoked with one additional argument, a string +describing the event of interest. +The main purpose is to help in debugging safe interpreters. +Using this facility you can get complete error messages while the safe +interpreter gets only generic error messages. +This prevents a safe interpreter from seeing messages about failures +and other events that might contain sensitive information such as real +directory names. +.RS +.PP +Example of use: +.PP +.CS +::safe::setLogCmd puts stderr +.CE +.PP +Below is the output of a sample session in which a safe interpreter +attempted to source a file not found in its virtual access path. +Note that the safe interpreter only received an error message saying that +the file was not found: +.PP +.CS +NOTICE for slave interp10 : Created +NOTICE for slave interp10 : Setting accessPath=(/foo/bar) staticsok=1 nestedok=0 deletehook=() +NOTICE for slave interp10 : auto_path in interp10 has been set to {$p(:0:)} +ERROR for slave interp10 : /foo/bar/init.tcl: no such file or directory +.CE +.RE +.SS OPTIONS +The following options are common to +\fB::safe::interpCreate\fR, \fB::safe::interpInit\fR, +and \fB::safe::interpConfigure\fR. +Any option name can be abbreviated to its minimal +non-ambiguous name. +Option names are not case sensitive. +.TP +\fB\-accessPath\fR \fIdirectoryList\fR +This option sets the list of directories from which the safe interpreter +can \fBsource\fR and \fBload\fR files. +If this option is not specified, or if it is given as the +empty list, the safe interpreter will use the same directories as its +master for auto-loading. +See the section \fBSECURITY\fR below for more detail about virtual paths, +tokens and access control. +.TP +\fB\-statics\fR \fIboolean\fR +This option specifies if the safe interpreter will be allowed +to load statically linked packages (like \fBload {} Tk\fR). +The default value is \fBtrue\fR : +safe interpreters are allowed to load statically linked packages. +.TP +\fB\-noStatics\fR +This option is a convenience shortcut for \fB\-statics false\fR and +thus specifies that the safe interpreter will not be allowed +to load statically linked packages. +.TP +\fB\-nested\fR \fIboolean\fR +This option specifies if the safe interpreter will be allowed +to load packages into its own sub-interpreters. +The default value is \fBfalse\fR : +safe interpreters are not allowed to load packages into +their own sub-interpreters. +.TP +\fB\-nestedLoadOk\fR +This option is a convenience shortcut for \fB\-nested true\fR and +thus specifies the safe interpreter will be allowed +to load packages into its own sub-interpreters. +.TP +\fB\-deleteHook\fR \fIscript\fR +When this option is given a non-empty \fIscript\fR, it will be +evaluated in the master with the name of +the safe interpreter as an additional argument +just before actually deleting the safe interpreter. +Giving an empty value removes any currently installed deletion hook +script for that safe interpreter. +The default value (\fB{}\fR) is not to have any deletion call back. +.SH ALIASES +The following aliases are provided in a safe interpreter: +.TP +\fBsource\fR \fIfileName\fR +The requested file, a Tcl source file, is sourced into the safe interpreter +if it is found. +The \fBsource\fR alias can only source files from directories in +the virtual path for the safe interpreter. The \fBsource\fR alias requires +the safe interpreter to +use one of the token names in its virtual path to denote the directory in +which the file to be sourced can be found. +See the section on \fBSECURITY\fR for more discussion of restrictions on +valid filenames. +.TP +\fBload\fR \fIfileName\fR +The requested file, a shared object file, is dynamically loaded into the +safe interpreter if it is found. +The filename must contain a token name mentioned in the virtual path for +the safe interpreter for it to be found successfully. +Additionally, the shared object file must contain a safe entry point; see +the manual page for the \fBload\fR command for more details. +.TP +\fBfile\fR ?\fIsubCmd args...\fR? +The \fBfile\fR alias provides access to a safe subset of the subcommands of +the \fBfile\fR command; it allows only \fBdirname\fR, \fBjoin\fR, +\fBextension\fR, \fBroot\fR, \fBtail\fR, \fBpathname\fR and \fBsplit\fR +subcommands. For more details on what these subcommands do see the manual +page for the \fBfile\fR command. +.TP +\fBencoding\fR ?\fIsubCmd args...\fR? +The \fBencoding\fR alias provides access to a safe subset of the +subcommands of the \fBencoding\fR command; it disallows setting of +the system encoding, but allows all other subcommands including +\fBsystem\fR to check the current encoding. +.TP +\fBexit\fR +The calling interpreter is deleted and its computation is stopped, but the +Tcl process in which this interpreter exists is not terminated. +.SH SECURITY +Safe Tcl does not attempt to completely prevent annoyance and +denial of service attacks. These forms of attack prevent the +application or user from temporarily using the computer to perform +useful work, for example by consuming all available CPU time or +all available screen real estate. +These attacks, while aggravating, are deemed to be of lesser importance +in general than integrity and privacy attacks that Safe Tcl +is to prevent. +.PP +The commands available in a safe interpreter, in addition to +the safe set as defined in \fBinterp\fR manual page, are mediated aliases +for \fBsource\fR, \fBload\fR, \fBexit\fR, and safe subsets of +\fBfile\fR and \fBencoding\fR. The safe interpreter can also auto-load +code and it can request that packages be loaded. +.PP +Because some of these commands access the local file system, there is a +potential for information leakage about its directory structure. +To prevent this, commands that take file names as arguments in a safe +interpreter use tokens instead of the real directory names. +These tokens are translated to the real directory name while a request to, +e.g., source a file is mediated by the master interpreter. +This virtual path system is maintained in the master interpreter for each safe +interpreter created by \fB::safe::interpCreate\fR or initialized by +\fB::safe::interpInit\fR and +the path maps tokens accessible in the safe interpreter into real path +names on the local file system thus preventing safe interpreters +from gaining knowledge about the +structure of the file system of the host on which the interpreter is +executing. +The only valid file names arguments +for the \fBsource\fR and \fBload\fR aliases provided to the slave +are path in the form of +\fB[file join \fItoken filename\fB]\fR (i.e. when using the +native file path formats: \fItoken\fB/\fIfilename\fR +on Unix and \fItoken\fB\e\fIfilename\fR on Windows), +where \fItoken\fR is representing one of the directories +of the \fIaccessPath\fR list and \fIfilename\fR is +one file in that directory (no sub directories access are allowed). +.PP +When a token is used in a safe interpreter in a request to source or +load a file, the token is checked and +translated to a real path name and the file to be +sourced or loaded is located on the file system. +The safe interpreter never gains knowledge of the actual path name under +which the file is stored on the file system. +.PP +To further prevent potential information leakage from sensitive files that +are accidentally included in the set of files that can be sourced by a safe +interpreter, the \fBsource\fR alias restricts access to files +meeting the following constraints: the file name must +fourteen characters or shorter, must not contain more than one dot +.PQ \fB.\fR "" , +must end up with the extension +.PQ \fB.tcl\fR +or be called +.PQ \fBtclIndex\fR . +.PP +Each element of the initial access path +list will be assigned a token that will be set in +the slave \fBauto_path\fR and the first element of that list will be set as +the \fBtcl_library\fR for that slave. +.PP +If the access path argument is not given or is the empty list, +the default behavior is to let the slave access the same packages +as the master has access to (Or to be more precise: +only packages written in Tcl (which by definition cannot be dangerous +as they run in the slave interpreter) and C extensions that +provides a _SafeInit entry point). For that purpose, the master's +\fBauto_path\fR will be used to construct the slave access path. +In order that the slave successfully loads the Tcl library files +(which includes the auto-loading mechanism itself) the \fBtcl_library\fR will be +added or moved to the first position if necessary, in the +slave access path, so the slave +\fBtcl_library\fR will be the same as the master's (its real +path will still be invisible to the slave though). +In order that auto-loading works the same for the slave and +the master in this by default case, the first-level +sub directories of each directory in the master \fBauto_path\fR will +also be added (if not already included) to the slave access path. +You can always specify a more +restrictive path for which sub directories will never be searched by +explicitly specifying your directory list with the \fB\-accessPath\fR flag +instead of relying on this default mechanism. +.PP +When the \fIaccessPath\fR is changed after the first creation or +initialization (i.e. through \fBinterpConfigure -accessPath \fR\fIlist\fR), +an \fBauto_reset\fR is automatically evaluated in the safe interpreter +to synchronize its \fBauto_index\fR with the new token list. +.SH "SEE ALSO" +interp(n), library(n), load(n), package(n), source(n), unknown(n) +.SH KEYWORDS +alias, auto\-loading, auto_mkindex, load, master interpreter, safe +interpreter, slave interpreter, source +'\" Local Variables: +'\" mode: nroff +'\" End: diff --git a/tcl8.6/doc/scan.n b/tcl8.6/doc/scan.n new file mode 100644 index 0000000..0c24fea --- /dev/null +++ b/tcl8.6/doc/scan.n @@ -0,0 +1,291 @@ +'\" +'\" Copyright (c) 1993 The Regents of the University of California. +'\" Copyright (c) 1994-1996 Sun Microsystems, Inc. +'\" Copyright (c) 2000 Scriptics Corporation. +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH scan n 8.4 Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +scan \- Parse string using conversion specifiers in the style of sscanf +.SH SYNOPSIS +\fBscan \fIstring format \fR?\fIvarName varName ...\fR? +.BE +.SH INTRODUCTION +.PP +This command parses substrings from an input string in a fashion similar +to the ANSI C \fBsscanf\fR procedure and returns a count of the number of +conversions performed, or -1 if the end of the input string is reached +before any conversions have been performed. \fIString\fR gives the input +to be parsed and \fIformat\fR indicates how to parse it, using \fB%\fR +conversion specifiers as in \fBsscanf\fR. Each \fIvarName\fR gives the +name of a variable; when a substring is scanned from \fIstring\fR that +matches a conversion specifier, the substring is assigned to the +corresponding variable. +If no \fIvarName\fR variables are specified, then \fBscan\fR works in an +inline manner, returning the data that would otherwise be stored in the +variables as a list. In the inline case, an empty string is returned when +the end of the input string is reached before any conversions have been +performed. +.SH "DETAILS ON SCANNING" +.PP +\fBScan\fR operates by scanning \fIstring\fR and \fIformat\fR together. +If the next character in \fIformat\fR is a blank or tab then it +matches any number of white space characters in \fIstring\fR (including +zero). +Otherwise, if it is not a \fB%\fR character then it +must match the next character of \fIstring\fR. +When a \fB%\fR is encountered in \fIformat\fR, it indicates +the start of a conversion specifier. +A conversion specifier contains up to four fields after the \fB%\fR: +a XPG3 position specifier (or a \fB*\fR to indicate the converted +value is to be discarded instead of assigned to any variable); a number +indicating a maximum substring width; a size modifier; and a +conversion character. +All of these fields are optional except for the conversion character. +The fields that are present must appear in the order given above. +.PP +When \fBscan\fR finds a conversion specifier in \fIformat\fR, it +first skips any white-space characters in \fIstring\fR (unless the +conversion character is \fB[\fR or \fBc\fR). +Then it converts the next input characters according to the +conversion specifier and stores the result in the variable given +by the next argument to \fBscan\fR. +.SS "OPTIONAL POSITIONAL SPECIFIER" +.PP +If the \fB%\fR is followed by a decimal number and a \fB$\fR, as in +.QW \fB%2$d\fR , +then the variable to use is not taken from the next +sequential argument. Instead, it is taken from the argument indicated +by the number, where 1 corresponds to the first \fIvarName\fR. If +there are any positional specifiers in \fIformat\fR then all of the +specifiers must be positional. Every \fIvarName\fR on the argument +list must correspond to exactly one conversion specifier or an error +is generated, or in the inline case, any position can be specified +at most once and the empty positions will be filled in with empty strings. +.SS "OPTIONAL SIZE MODIFIER" +.PP +The size modifier field is used only when scanning a substring into +one of Tcl's integer values. The size modifier field dictates the +integer range acceptable to be stored in a variable, or, for the inline +case, in a position in the result list. +The syntactically valid values for the size modifier are \fBh\fR, \fBL\fR, +\fBl\fR, and \fBll\fR. The \fBh\fR size modifier value is equivalent +to the absence of a size modifier in the the conversion specifier. +Either one indicates the integer range to be stored is limited to +the same range produced by the \fBint()\fR function of the \fBexpr\fR +command. The \fBL\fR size modifier is equivalent to the \fBl\fR size +modifier. Either one indicates the integer range to be stored is +limited to the same range produced by the \fBwide()\fR function of +the \fBexpr\fR command. The \fBll\fR size modifier indicates that +the integer range to be stored is unlimited. +.SS "MANDATORY CONVERSION CHARACTER" +.PP +The following conversion characters are supported: +.TP +\fBd\fR +. +The input substring must be a decimal integer. +It is read in and the integer value is stored in the variable, +truncated as required by the size modifier value. +.TP +\fBo\fR +. +The input substring must be an octal integer. It is read in and the +integer value is stored in the variable, +truncated as required by the size modifier value. +.TP +\fBx\fR or \fBX\fR +. +The input substring must be a hexadecimal integer. +It is read in and the integer value is stored in the variable, +truncated as required by the size modifier value. +.TP +\fBb\fR +. +The input substring must be a binary integer. +It is read in and the integer value is stored in the variable, +truncated as required by the size modifier value. +.TP +\fBu\fR +. +The input substring must be a decimal integer. +The integer value is truncated as required by the size modifier +value, and the corresponding unsigned value for that truncated +range is computed and stored in the variable as a decimal string. +The conversion makes no sense without reference to a truncation range, +so the size modifier \fBll\fR is not permitted in combination +with conversion character \fBu\fR. +.TP +\fBi\fR +. +The input substring must be an integer. The base (i.e. decimal, octal, or hexadecimal) is determined by the C convention (leading 0 for octal; prefix 0x for hexadecimal). The integer value is stored in the variable, +truncated as required by the size modifier value. +.TP +\fBc\fR +. +A single character is read in and its Unicode value is stored in +the variable as an integer value. +Initial white space is not skipped in this case, so the input +substring may be a white-space character. +.TP +\fBs\fR +. +The input substring consists of all the characters up to the next +white-space character; the characters are copied to the variable. +.TP +\fBe\fR or \fBf\fR or \fBg\fR or \fBE\fR or \fBG\fR +. +The input substring must be a floating-point number consisting +of an optional sign, a string of decimal digits possibly +containing a decimal point, and an optional exponent consisting +of an \fBe\fR or \fBE\fR followed by an optional sign and a string of +decimal digits. +It is read in and stored in the variable as a floating-point value. +.TP +\fB[\fIchars\fB]\fR +. +The input substring consists of one or more characters in \fIchars\fR. +The matching string is stored in the variable. +If the first character between the brackets is a \fB]\fR then +it is treated as part of \fIchars\fR rather than the closing +bracket for the set. +If \fIchars\fR +contains a sequence of the form \fIa\fB\-\fIb\fR then any +character between \fIa\fR and \fIb\fR (inclusive) will match. +If the first or last character between the brackets is a \fB\-\fR, then +it is treated as part of \fIchars\fR rather than indicating a range. +.TP +\fB[^\fIchars\fB]\fR +. +The input substring consists of one or more characters not in \fIchars\fR. +The matching string is stored in the variable. +If the character immediately following the \fB^\fR is a \fB]\fR then it is +treated as part of the set rather than the closing bracket for +the set. +If \fIchars\fR +contains a sequence of the form \fIa\fB\-\fIb\fR then any +character between \fIa\fR and \fIb\fR (inclusive) will be excluded +from the set. +If the first or last character between the brackets is a \fB\-\fR, then +it is treated as part of \fIchars\fR rather than indicating a range value. +.TP +\fBn\fR +. +No input is consumed from the input string. Instead, the total number +of characters scanned from the input string so far is stored in the variable. +.PP +The number of characters read from the input for a conversion is the +largest number that makes sense for that particular conversion (e.g. +as many decimal digits as possible for \fB%d\fR, as +many octal digits as possible for \fB%o\fR, and so on). +The input substring for a given conversion terminates either when a +white-space character is encountered or when the maximum substring +width has been reached, whichever comes first. +If a \fB*\fR is present in the conversion specifier +then no variable is assigned and the next scan argument is not consumed. +.SH "DIFFERENCES FROM ANSI SSCANF" +.PP +The behavior of the \fBscan\fR command is the same as the behavior of +the ANSI C \fBsscanf\fR procedure except for the following differences: +.IP [1] +\fB%p\fR conversion specifier is not supported. +.IP [2] +For \fB%c\fR conversions a single character value is +converted to a decimal string, which is then assigned to the +corresponding \fIvarName\fR; +no substring width may be specified for this conversion. +.IP [3] +The \fBh\fR modifier is always ignored and the \fBl\fR and \fBL\fR +modifiers are ignored when converting real values (i.e. type +\fBdouble\fR is used for the internal representation). The \fBll\fR +modifier has no \fBsscanf\fR counterpart. +.IP [4] +If the end of the input string is reached before any conversions have been +performed and no variables are given, an empty string is returned. +.SH EXAMPLES +.PP +Convert a UNICODE character to its numeric value: +.PP +.CS +set char "x" +set value [\fBscan\fR $char %c] +.CE +.PP +Parse a simple color specification of the form \fI#RRGGBB\fR using +hexadecimal conversions with substring sizes: +.PP +.CS +set string "#08D03F" +\fBscan\fR $string "#%2x%2x%2x" r g b +.CE +.PP +Parse a \fIHH:MM\fR time string, noting that this avoids problems with +octal numbers by forcing interpretation as decimals (if we did not +care, we would use the \fB%i\fR conversion instead): +.PP +.CS +set string "08:08" ;# *Not* octal! +if {[\fBscan\fR $string "%d:%d" hours minutes] != 2} { + error "not a valid time string" +} +# We have to understand numeric ranges ourselves... +if {$minutes < 0 || $minutes > 59} { + error "invalid number of minutes" +} +.CE +.PP +Break a string up into sequences of non-whitespace characters (note +the use of the \fB%n\fR conversion so that we get skipping over +leading whitespace correct): +.PP +.CS +set string " a string {with braced words} + leading space " +set words {} +while {[\fBscan\fR $string %s%n word length] == 2} { + lappend words $word + set string [string range $string $length end] +} +.CE +.PP +Parse a simple coordinate string, checking that it is complete by +looking for the terminating character explicitly: +.PP +.CS +set string "(5.2,-4e-2)" +# Note that the spaces before the literal parts of +# the scan pattern are significant, and that ")" is +# the Unicode character \eu0029 +if { + [\fBscan\fR $string " (%f ,%f %c" x y last] != 3 + || $last != 0x0029 +} then { + error "invalid coordinate string" +} +puts "X=$x, Y=$y" +.CE +.PP +An interactive session demonstrating the truncation of integer +values determined by size modifiers: +.PP +.CS +\fI%\fR set tcl_platform(wordSize) +4 +\fI%\fR scan 20000000000000000000 %d +2147483647 +\fI%\fR scan 20000000000000000000 %ld +9223372036854775807 +\fI%\fR scan 20000000000000000000 %lld +20000000000000000000 +.CE +.SH "SEE ALSO" +format(n), sscanf(3) +.SH KEYWORDS +conversion specifier, parse, scan +'\" Local Variables: +'\" mode: nroff +'\" End: diff --git a/tcl8.6/doc/seek.n b/tcl8.6/doc/seek.n new file mode 100644 index 0000000..02c5341 --- /dev/null +++ b/tcl8.6/doc/seek.n @@ -0,0 +1,92 @@ +'\" +'\" Copyright (c) 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. +'\" +.TH seek n 8.1 Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +seek \- Change the access position for an open channel +.SH SYNOPSIS +\fBseek \fIchannelId offset \fR?\fIorigin\fR? +.BE +.SH DESCRIPTION +.PP +Changes the current access position for \fIchannelId\fR. +.PP +\fIChannelId\fR must be an identifier for an open channel such as a +Tcl standard channel (\fBstdin\fR, \fBstdout\fR, or \fBstderr\fR), +the return value from an invocation of \fBopen\fR or \fBsocket\fR, or +the result of a channel creation command provided by a Tcl extension. +.PP +The \fIoffset\fR and \fIorigin\fR +arguments specify the position at which the next read or write will occur +for \fIchannelId\fR. \fIOffset\fR must be an integer (which may be +negative) and \fIorigin\fR must be one of the following: +.TP 10 +\fBstart\fR +. +The new access position will be \fIoffset\fR bytes from the start +of the underlying file or device. +.TP 10 +\fBcurrent\fR +. +The new access position will be \fIoffset\fR bytes from the current +access position; a negative \fIoffset\fR moves the access position +backwards in the underlying file or device. +.TP 10 +\fBend\fR +. +The new access position will be \fIoffset\fR bytes from the end of +the file or device. A negative \fIoffset\fR places the access position +before the end of file, and a positive \fIoffset\fR places the access +position after the end of file. +.PP +The \fIorigin\fR argument defaults to \fBstart\fR. +.PP +The command flushes all buffered output for the channel before the command +returns, even if the channel is in non-blocking mode. +It also discards any buffered and unread input. +This command returns an empty string. +An error occurs if this command is applied to channels whose underlying +file or device does not support seeking. +.PP +Note that \fIoffset\fR values are byte offsets, not character +offsets. Both \fBseek\fR and \fBtell\fR operate in terms of bytes, +not characters, unlike \fBread\fR. +.SH EXAMPLES +.PP +Read a file twice: +.PP +.CS +set f [open file.txt] +set data1 [read $f] +\fBseek\fR $f 0 +set data2 [read $f] +close $f +# $data1 eq $data2 if the file wasn't updated +.CE +.PP +Read the last 10 bytes from a file: +.PP +.CS +set f [open file.data] +# This is guaranteed to work with binary data but +# may fail with other encodings... +fconfigure $f -translation binary +\fBseek\fR $f -10 end +set data [read $f 10] +close $f +.CE +.SH "SEE ALSO" +file(n), open(n), close(n), gets(n), tell(n), Tcl_StandardChannels(3) +.SH KEYWORDS +access position, file, seek +'\" Local Variables: +'\" mode: nroff +'\" fill-column: 78 +'\" End: diff --git a/tcl8.6/doc/self.n b/tcl8.6/doc/self.n new file mode 100644 index 0000000..0ad5428 --- /dev/null +++ b/tcl8.6/doc/self.n @@ -0,0 +1,152 @@ +'\" +'\" Copyright (c) 2007 Donal K. Fellows +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH self n 0.1 TclOO "TclOO Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +self \- method call internal introspection +.SH SYNOPSIS +.nf +package require TclOO + +\fBself\fR ?\fIsubcommand\fR? +.fi +.BE +.SH DESCRIPTION +The \fBself\fR command, which should only be used from within the context of a +call to a method (i.e. inside a method, constructor or destructor body) is +used to allow the method to discover information about how it was called. It +takes an argument, \fIsubcommand\fR, that tells it what sort of information is +actually desired; if omitted the result will be the same as if \fBself +object\fR was invoked. The supported subcommands are: +.TP +\fBself call\fR +. +This returns a two-element list describing the method implementations used to +implement the current call chain. The first element is the same as would be +reported by \fBinfo object\fR \fBcall\fR for the current method (except that this +also reports useful values from within constructors and destructors, whose +names are reported as \fB<constructor>\fR and \fB<destructor>\fR +respectively), and the second element is an index into the first element's +list that indicates which actual implementation is currently executing (the +first implementation to execute is always at index 0). +.TP +\fBself caller\fR +. +When the method was invoked from inside another object method, this subcommand +returns a three element list describing the containing object and method. The +first element describes the declaring object or class of the method, the +second element is the name of the object on which the containing method was +invoked, and the third element is the name of the method (with the strings +\fB<constructor>\fR and \fB<destructor>\fR indicating constructors and +destructors respectively). +.TP +\fBself class\fR +. +This returns the name of the class that the current method was defined within. +Note that this will change as the chain of method implementations is traversed +with \fBnext\fR, and that if the method was defined on an object then this +will fail. +.RS +.PP +If you want the class of the current object, you need to use this other +construct: +.PP +.CS +info object class [\fBself object\fR] +.CE +.RE +.TP +\fBself filter\fR +. +When invoked inside a filter, this subcommand returns a three element list +describing the filter. The first element gives the name of the object or class +that declared the filter (note that this may be different from the object or +class that provided the implementation of the filter), the second element is +either \fBobject\fR or \fBclass\fR depending on whether the declaring entity +was an object or class, and the third element is the name of the filter. +.TP +\fBself method\fR +. +This returns the name of the current method (with the strings +\fB<constructor>\fR and \fB<destructor>\fR indicating constructors and +destructors respectively). +.TP +\fBself namespace\fR +. +This returns the name of the unique namespace of the object that the method +was invoked upon. +.TP +\fBself next\fR +. +When invoked from a method that is not at the end of a call chain (i.e. where +the \fBnext\fR command will invoke an actual method implementation), this +subcommand returns a two element list describing the next element in the +method call chain; the first element is the name of the class or object that +declares the next part of the call chain, and the second element is the name +of the method (with the strings \fB<constructor>\fR and \fB<destructor>\fR +indicating constructors and destructors respectively). If invoked from a +method that is at the end of a call chain, this subcommand returns the empty +string. +.TP +\fBself object\fR +. +This returns the name of the object that the method was invoked upon. +.TP +\fBself target\fR +. +When invoked inside a filter implementation, this subcommand returns a two +element list describing the method being filtered. The first element will be +the name of the declarer of the method, and the second element will be the +actual name of the method. +.SH EXAMPLES +.PP +This example shows basic use of \fBself\fR to provide information about the +current object: +.PP +.CS +oo::class create c { + method foo {} { + puts "this is the [\fBself\fR] object" + } +} +c create a +c create b +a foo \fI\(-> prints "this is the ::a object"\fR +b foo \fI\(-> prints "this is the ::b object"\fR +.CE +.PP +This demonstrates what a method call chain looks like, and how traversing +along it changes the index into it: +.PP +.CS +oo::class create c { + method x {} { + puts "Cls: [\fBself call\fR]" + } +} +c create a +oo::objdefine a { + method x {} { + puts "Obj: [\fBself call\fR]" + next + puts "Obj: [\fBself call\fR]" + } +} +a x \fI\(-> Obj: {{method x object method} {method x ::c method}} 0\fR + \fI\(-> Cls: {{method x object method} {method x ::c method}} 1\fR + \fI\(-> Obj: {{method x object method} {method x ::c method}} 0\fR +.CE +.SH "SEE ALSO" +info(n), next(n) +.SH KEYWORDS +call, introspection, object +.\" Local variables: +.\" mode: nroff +.\" fill-column: 78 +.\" End: diff --git a/tcl8.6/doc/set.n b/tcl8.6/doc/set.n new file mode 100644 index 0000000..f065087 --- /dev/null +++ b/tcl8.6/doc/set.n @@ -0,0 +1,75 @@ +'\" +'\" Copyright (c) 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. +'\" +.TH set n "" Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +set \- Read and write variables +.SH SYNOPSIS +\fBset \fIvarName \fR?\fIvalue\fR? +.BE +.SH DESCRIPTION +.PP +Returns the value of variable \fIvarName\fR. +If \fIvalue\fR is specified, then set +the value of \fIvarName\fR to \fIvalue\fR, creating a new variable +if one does not already exist, and return its value. +If \fIvarName\fR contains an open parenthesis and ends with a +close parenthesis, then it refers to an array element: the characters +before the first open parenthesis are the name of the array, +and the characters between the parentheses are the index within the array. +Otherwise \fIvarName\fR refers to a scalar variable. +.PP +If \fIvarName\fR includes namespace qualifiers +(in the array name if it refers to an array element), or if \fIvarName\fR +is unqualified (does not include the names of any containing namespaces) +but no procedure is active, +\fIvarName\fR refers to a namespace variable +resolved according to the rules described under \fBNAME RESOLUTION\fR in +the \fBnamespace\fR manual page. +.PP +If a procedure is active and \fIvarName\fR is unqualified, then +\fIvarName\fR refers to a parameter or local variable of the procedure, +unless \fIvarName\fR was declared to resolve differently through one of the +\fBglobal\fR, \fBvariable\fR or \fBupvar\fR commands. +.SH EXAMPLES +.PP +Store a random number in the variable \fIr\fR: +.PP +.CS +\fBset\fR r [expr {rand()}] +.CE +.PP +Store a short message in an array element: +.PP +.CS +\fBset\fR anAry(msg) "Hello, World!" +.CE +.PP +Store a short message in an array element specified by a variable: +.PP +.CS +\fBset\fR elemName "msg" +\fBset\fR anAry($elemName) "Hello, World!" +.CE +.PP +Copy a value into the variable \fIout\fR from a variable whose name is +stored in the \fIvbl\fR (note that it is often easier to use arrays in +practice instead of doing double-dereferencing): +.PP +.CS +\fBset\fR in0 "small random" +\fBset\fR in1 "large random" +\fBset\fR vbl in[expr {rand() >= 0.5}] +\fBset\fR out [\fBset\fR $vbl] +.CE +.SH "SEE ALSO" +expr(n), global(n), namespace(n), proc(n), trace(n), unset(n), upvar(n), variable(n) +.SH KEYWORDS +read, write, variable diff --git a/tcl8.6/doc/socket.n b/tcl8.6/doc/socket.n new file mode 100644 index 0000000..3efdb37 --- /dev/null +++ b/tcl8.6/doc/socket.n @@ -0,0 +1,235 @@ +'\" +'\" Copyright (c) 1996 Sun Microsystems, Inc. +'\" Copyright (c) 1998-1999 by Scriptics Corporation. +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH socket n 8.6 Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +socket \- Open a TCP network connection +.SH SYNOPSIS +.sp +\fBsocket \fR?\fIoptions\fR? \fIhost port\fR +.sp +\fBsocket\fR \fB\-server \fIcommand\fR ?\fIoptions\fR? \fIport\fR +.BE +.SH DESCRIPTION +.PP +This command opens a network socket and returns a channel identifier +that may be used in future invocations of commands like \fBread\fR, +\fBputs\fR and \fBflush\fR. At present only the TCP network protocol +is supported over IPv4 and IPv6; future releases may include support +for additional protocols. The \fBsocket\fR command may be used to +open either the client or server side of a connection, depending on +whether the \fB\-server\fR switch is specified. +.PP +Note that the default encoding for \fIall\fR sockets is the system +encoding, as returned by \fBencoding system\fR. Most of the time, you +will need to use \fBchan configure\fR to alter this to something else, +such as \fIutf\-8\fR (ideal for communicating with other Tcl +processes) or \fIiso8859\-1\fR (useful for many network protocols, +especially the older ones). +.SH "CLIENT SOCKETS" +.PP +If the \fB\-server\fR option is not specified, then the client side of a +connection is opened and the command returns a channel identifier +that can be used for both reading and writing. +\fIPort\fR and \fIhost\fR specify a port +to connect to; there must be a server accepting connections on +this port. \fIPort\fR is an integer port number +(or service name, where supported and understood by the host operating +system) and \fIhost\fR +is either a domain-style name such as \fBwww.tcl.tk\fR or +a numerical IPv4 or IPv6 address such as \fB127.0.0.1\fR or \fB2001:DB8::1\fR. +Use \fIlocalhost\fR to refer to the host on which the command is invoked. +.PP +The following options may also be present before \fIhost\fR +to specify additional information about the connection: +.TP +\fB\-myaddr\fI addr\fR +. +\fIAddr\fR gives the domain-style name or numerical IP address of +the client-side network interface to use for the connection. +This option may be useful if the client machine has multiple network +interfaces. If the option is omitted then the client-side interface +will be chosen by the system software. +.TP +\fB\-myport\fI port\fR +. +\fIPort\fR specifies an integer port number (or service name, where +supported and understood by the host operating system) to use for the +client's +side of the connection. If this option is omitted, the client's +port number will be chosen at random by the system software. +.TP +\fB\-async\fR +. +This option will cause the client socket to be connected +asynchronously. This means that the socket will be created immediately +but may not yet be connected to the server, when the call to +\fBsocket\fR returns. +.RS +.PP +When a \fBgets\fR or \fBflush\fR is done on the socket before the +connection attempt succeeds or fails, if the socket is in blocking +mode, the operation will wait until the connection is completed or +fails. If the socket is in nonblocking mode and a \fBgets\fR or +\fBflush\fR is done on the socket before the connection attempt +succeeds or fails, the operation returns immediately and +\fBfblocked\fR on the socket returns 1. Synchronous client sockets may +be switched (after they have connected) to operating in asynchronous +mode using: +.PP +.CS +\fBchan configure \fIchan \fB\-blocking 0\fR +.CE +.PP +See the \fBchan configure\fR command for more details. +.PP +The Tcl event loop should be running while an asynchronous connection +is in progress, because it may have to do several connection attempts +in the background. Running the event loop also allows you to set up a +writable channel event on the socket to get notified when the +asynchronous connection has succeeded or failed. See the \fBvwait\fR +and the \fBchan\fR commands for more details on the event loop and +channel events. +.PP +The \fBchan configure\fR option \fB-connecting\fR may be used to check if the connect is still running. To verify a successful connect, the option \fB-error\fR may be checked when \fB-connecting\fR returned 0. +.PP +Operation without the event queue requires at the moment calls to \fBchan configure\fR to advance the internal state machine. +.RE +.SH "SERVER SOCKETS" +.PP +If the \fB\-server\fR option is specified then the new socket will be +a server that listens on the given \fIport\fR (either an integer or a +service name, where supported and understood by the host operating +system; if \fIport\fR is zero, the operating system will allocate a +free port to the server socket which may be discovered by using +\fBchan configure\fR to read the \fB\-sockname\fR option). If the host +supports both, IPv4 and IPv6, the socket will listen on both address +families. Tcl will automatically accept connections to the given port. +For each connection Tcl will create a new channel that may be used to +communicate with the client. Tcl then invokes \fIcommand\fR (properly +a command prefix list, see the \fBEXAMPLES\fR below) with three +additional arguments: the name of the new channel, the address, in +network address notation, of the client's host, and the client's port +number. +.PP +The following additional option may also be specified before \fIport\fR: +.TP +\fB\-myaddr\fI addr\fR +. +\fIAddr\fR gives the domain-style name or numerical IP address of the +server-side network interface to use for the connection. This option +may be useful if the server machine has multiple network interfaces. +If the option is omitted then the server socket is bound to the +wildcard address so that it can accept connections from any +interface. If \fIaddr\fR is a domain name that resolves to multiple IP +addresses that are available on the local machine, the socket will +listen on all of them. +.PP +Server channels cannot be used for input or output; their sole use is to +accept new client connections. The channels created for each incoming +client connection are opened for input and output. Closing the server +channel shuts down the server so that no new connections will be +accepted; however, existing connections will be unaffected. +.PP +Server sockets depend on the Tcl event mechanism to find out when +new connections are opened. If the application does not enter the +event loop, for example by invoking the \fBvwait\fR command or +calling the C procedure \fBTcl_DoOneEvent\fR, then no connections +will be accepted. +.PP +If \fIport\fR is specified as zero, the operating system will allocate +an unused port for use as a server socket. The port number actually +allocated may be retrieved from the created server socket using the +\fBchan configure\fR command to retrieve the \fB\-sockname\fR option as +described below. +.SH "CONFIGURATION OPTIONS" +.PP +The \fBchan configure\fR command can be used to query several readonly +configuration options for socket channels: +.TP +\fB\-error\fR +. +This option gets the current error status of the given socket. This +is useful when you need to determine if an asynchronous connect +operation succeeded. If there was an error, the error message is +returned. If there was no error, an empty string is returned. +.RS +.PP +Note that the error status is reset by the read operation; this mimics +the underlying getsockopt(SO_ERROR) call. +.RE +.TP +\fB\-sockname\fR +. +For client sockets (including the channels that get created when a +client connects to a server socket) this option returns a list of +three elements, the address, the host name and the port number for the +socket. If the host name cannot be computed, the second element is +identical to the address, the first element of the list. +.RS +.PP +For server sockets this option returns a list of a multiple of three +elements each group of which have the same meaning as described +above. The list contains more than one group when the server socket +was created without \fB\-myaddr\fR or with the argument to +\fB\-myaddr\fR being a domain name that resolves multiple IP addresses +that are local to the invoking host. +.RE +.TP +\fB\-peername\fR +. +This option is not supported by server sockets. For client and accepted +sockets, this option returns a list of three elements; these are the +address, the host name and the port to which the peer socket is connected +or bound. If the host name cannot be computed, the second element of the +list is identical to the address, its first element. +.TP +\fB\-connecting\fR +. +This option is not supported by server sockets. For client sockets, this option returns 1 if an asyncroneous connect is still in progress, 0 otherwise. +.PP +.SH "EXAMPLES" +.PP +Here is a very simple time server: +.PP +.CS +proc Server {startTime channel clientaddr clientport} { + puts "Connection from $clientaddr registered" + set now [clock seconds] + puts $channel [clock format $now] + puts $channel "[expr {$now - $startTime}] since start" + close $channel +} + +\fBsocket -server\fR [list Server [clock seconds]] 9900 +vwait forever +.CE +.PP +And here is the corresponding client to talk to the server and extract +some information: +.PP +.CS +set server localhost +set sockChan [\fBsocket\fR $server 9900] +gets $sockChan line1 +gets $sockChan line2 +close $sockChan +puts "The time on $server is $line1" +puts "That is [lindex $line2 0]s since the server started" +.CE +.SH "HISTORY" +Support for IPv6 was added in Tcl 8.6. +.SH "SEE ALSO" +chan(n), flush(n), open(n), read(n) +.SH KEYWORDS +asynchronous I/O, bind, channel, connection, domain name, host, network address, socket, tcp +'\" Local Variables: +'\" mode: nroff +'\" End: diff --git a/tcl8.6/doc/source.n b/tcl8.6/doc/source.n new file mode 100644 index 0000000..67d4b6b --- /dev/null +++ b/tcl8.6/doc/source.n @@ -0,0 +1,71 @@ +'\" +'\" Copyright (c) 1993 The Regents of the University of California. +'\" Copyright (c) 1994-1996 Sun Microsystems, Inc. +'\" Copyright (c) 2000 Scriptics Corporation. +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH source n "" Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +source \- Evaluate a file or resource as a Tcl script +.SH SYNOPSIS +\fBsource \fIfileName\fR +.sp +\fBsource\fR \fB\-encoding \fIencodingName fileName\fR +.BE +.SH DESCRIPTION +.PP +This command takes the contents of the specified file or resource +and passes it to the Tcl interpreter as a text script. The return +value from \fBsource\fR is the return value of the last command +executed in the script. If an error occurs in evaluating the contents +of the script then the \fBsource\fR command will return that error. +If a \fBreturn\fR command is invoked from within the script then the +remainder of the file will be skipped and the \fBsource\fR command +will return normally with the result from the \fBreturn\fR command. +.PP +The end-of-file character for files is +.QW \e32 +(^Z) for all platforms. +The source command will read files up to this character. This +restriction does not exist for the \fBread\fR or \fBgets\fR commands, +allowing for files containing code and data segments (scripted documents). +If you require a +.QW ^Z +in code for string comparison, you can use +.QW \e032 +or +.QW \eu001a , +which will be safely substituted by the Tcl interpreter into +.QW ^Z . +.PP +A leading BOM (Byte order mark) contained in the file is ignored for unicode encodings (utf-8, unicode). +.PP +The \fB\-encoding\fR option is used to specify the encoding of +the data stored in \fIfileName\fR. When the \fB\-encoding\fR option +is omitted, the system encoding is assumed. +.SH EXAMPLE +.PP +Run the script in the file \fBfoo.tcl\fR and then the script in the +file \fBbar.tcl\fR: +.PP +.CS +\fBsource\fR foo.tcl +\fBsource\fR bar.tcl +.CE +.PP +Alternatively: +.PP +.CS +foreach scriptFile {foo.tcl bar.tcl} { + \fBsource\fR $scriptFile +} +.CE +.SH "SEE ALSO" +file(n), cd(n), encoding(n), info(n) +.SH KEYWORDS +file, script diff --git a/tcl8.6/doc/split.n b/tcl8.6/doc/split.n new file mode 100644 index 0000000..f1c66d0 --- /dev/null +++ b/tcl8.6/doc/split.n @@ -0,0 +1,93 @@ +'\" +'\" Copyright (c) 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. +'\" +.TH split n "" Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +split \- Split a string into a proper Tcl list +.SH SYNOPSIS +\fBsplit \fIstring \fR?\fIsplitChars\fR? +.BE +.SH DESCRIPTION +.PP +Returns a list created by splitting \fIstring\fR at each character +that is in the \fIsplitChars\fR argument. +Each element of the result list will consist of the +characters from \fIstring\fR that lie between instances of the +characters in \fIsplitChars\fR. +Empty list elements will be generated if \fIstring\fR contains +adjacent characters in \fIsplitChars\fR, or if the first or last +character of \fIstring\fR is in \fIsplitChars\fR. +If \fIsplitChars\fR is an empty string then each character of +\fIstring\fR becomes a separate element of the result list. +\fISplitChars\fR defaults to the standard white-space characters. +.SH EXAMPLES +.PP +Divide up a USENET group name into its hierarchical components: +.PP +.CS +\fBsplit\fR "comp.lang.tcl" . + \fI\(-> comp lang tcl\fR +.CE +.PP +See how the \fBsplit\fR command splits on \fIevery\fR character in +\fIsplitChars\fR, which can result in information loss if you are not +careful: +.PP +.CS +\fBsplit\fR "alpha beta gamma" "temp" + \fI\(-> al {ha b} {} {a ga} {} a\fR +.CE +.PP +Extract the list words from a string that is not a well-formed list: +.PP +.CS +\fBsplit\fR "Example with {unbalanced brace character" + \fI\(-> Example with \e{unbalanced brace character\fR +.CE +.PP +Split a string into its constituent characters +.PP +.CS +\fBsplit\fR "Hello world" {} + \fI\(-> H e l l o { } w o r l d\fR +.CE +.SS "PARSING RECORD-ORIENTED FILES" +.PP +Parse a Unix /etc/passwd file, which consists of one entry per line, +with each line consisting of a colon-separated list of fields: +.PP +.CS +## Read the file +set fid [open /etc/passwd] +set content [read $fid] +close $fid + +## Split into records on newlines +set records [\fBsplit\fR $content "\en"] + +## Iterate over the records +foreach rec $records { + + ## Split into fields on colons + set fields [\fBsplit\fR $rec ":"] + + ## Assign fields to variables and print some out... + lassign $fields \e + userName password uid grp longName homeDir shell + puts "$longName uses [file tail $shell] for a login shell" +} +.CE +.SH "SEE ALSO" +join(n), list(n), string(n) +.SH KEYWORDS +list, split, string +'\" Local Variables: +'\" mode: nroff +'\" End: diff --git a/tcl8.6/doc/string.n b/tcl8.6/doc/string.n new file mode 100644 index 0000000..00ce85c --- /dev/null +++ b/tcl8.6/doc/string.n @@ -0,0 +1,485 @@ +.\" +.\" Copyright (c) 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. +.\" +.TH string n 8.1 Tcl "Tcl Built-In Commands" +.so man.macros +.BS +.\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +string \- Manipulate strings +.SH SYNOPSIS +\fBstring \fIoption arg \fR?\fIarg ...?\fR +.BE +.SH DESCRIPTION +.PP +Performs one of several string operations, depending on \fIoption\fR. +The legal \fIoption\fRs (which may be abbreviated) are: +.TP +\fBstring cat\fR ?\fIstring1\fR? ?\fIstring2...\fR? +.VS 8.6.2 +Concatenate the given \fIstring\fRs just like placing them directly +next to each other and return the resulting compound string. If no +\fIstring\fRs are present, the result is an empty string. +.RS +.PP +This primitive is occasionally handier than juxtaposition of strings +when mixed quoting is wanted, or when the aim is to return the result +of a concatenation without resorting to \fBreturn\fR \fB\-level 0\fR, +and is more efficient than building a list of arguments and using +\fBjoin\fR with an empty join string. +.RE +.VE +.TP +\fBstring compare\fR ?\fB\-nocase\fR? ?\fB\-length\fI length\fR? \fIstring1 string2\fR +. +Perform a character-by-character comparison of strings \fIstring1\fR +and \fIstring2\fR. Returns \-1, 0, or 1, depending on whether +\fIstring1\fR is lexicographically less than, equal to, or greater +than \fIstring2\fR. If \fB\-length\fR is specified, then only the +first \fIlength\fR characters are used in the comparison. If +\fB\-length\fR is negative, it is ignored. If \fB\-nocase\fR is +specified, then the strings are compared in a case-insensitive manner. +.TP +\fBstring equal\fR ?\fB\-nocase\fR? ?\fB\-length\fI length\fR? \fIstring1 string2\fR +. +Perform a character-by-character comparison of strings \fIstring1\fR +and \fIstring2\fR. Returns 1 if \fIstring1\fR and \fIstring2\fR are +identical, or 0 when not. If \fB\-length\fR is specified, then only +the first \fIlength\fR characters are used in the comparison. If +\fB\-length\fR is negative, it is ignored. If \fB\-nocase\fR is +specified, then the strings are compared in a case-insensitive manner. +.TP +\fBstring first \fIneedleString haystackString\fR ?\fIstartIndex\fR? +. +Search \fIhaystackString\fR for a sequence of characters that exactly match +the characters in \fIneedleString\fR. If found, return the index of the +first character in the first such match within \fIhaystackString\fR. If not +found, return \-1. If \fIstartIndex\fR is specified (in any of the +forms described in \fBSTRING INDICES\fR), then the search is +constrained to start with the character in \fIhaystackString\fR specified by +the index. For example, +.RS +.PP +.CS +\fBstring first a 0a23456789abcdef 5\fR +.CE +.PP +will return \fB10\fR, but +.PP +.CS +\fBstring first a 0123456789abcdef 11\fR +.CE +.PP +will return \fB\-1\fR. +.RE +.TP +\fBstring index \fIstring charIndex\fR +. +Returns the \fIcharIndex\fR'th character of the \fIstring\fR argument. +A \fIcharIndex\fR of 0 corresponds to the first character of the +string. \fIcharIndex\fR may be specified as described in the +\fBSTRING INDICES\fR section. +.RS +.PP +If \fIcharIndex\fR is less than 0 or greater than or equal to the +length of the string then this command returns an empty string. +.RE +.TP +\fBstring is \fIclass\fR ?\fB\-strict\fR? ?\fB\-failindex \fIvarname\fR? \fIstring\fR +. +Returns 1 if \fIstring\fR is a valid member of the specified character +class, otherwise returns 0. If \fB\-strict\fR is specified, then an +empty string returns 0, otherwise an empty string will return 1 on +any class. If \fB\-failindex\fR is specified, then if the function +returns 0, the index in the string where the class was no longer valid +will be stored in the variable named \fIvarname\fR. The \fIvarname\fR +will not be set if \fBstring is\fR returns 1. The following character +classes are recognized (the class name can be abbreviated): +.RS +.IP \fBalnum\fR 12 +Any Unicode alphabet or digit character. +.IP \fBalpha\fR 12 +Any Unicode alphabet character. +.IP \fBascii\fR 12 +Any character with a value less than \eu0080 (those that are in the +7\-bit ascii range). +.IP \fBboolean\fR 12 +Any of the forms allowed to \fBTcl_GetBoolean\fR. +.IP \fBcontrol\fR 12 +Any Unicode control character. +.IP \fBdigit\fR 12 +Any Unicode digit character. Note that this includes characters +outside of the [0\-9] range. +.IP \fBdouble\fR 12 +Any of the valid forms for a double in Tcl, with optional surrounding +whitespace. In case of under/overflow in the value, 0 is returned and +the \fIvarname\fR will contain \-1. +.IP \fBentier\fR 12 +.VS 8.6 +Any of the valid string formats for an integer value of arbitrary size +in Tcl, with optional surrounding whitespace. The formats accepted are +exactly those accepted by the C routine \fBTcl_GetBignumFromObj\fR. +.VE +.IP \fBfalse\fR 12 +Any of the forms allowed to \fBTcl_GetBoolean\fR where the value is +false. +.IP \fBgraph\fR 12 +Any Unicode printing character, except space. +.IP \fBinteger\fR 12 +Any of the valid string formats for a 32-bit integer value in Tcl, +with optional surrounding whitespace. In case of under/overflow in +the value, 0 is returned and the \fIvarname\fR will contain \-1. +.IP \fBlist\fR 12 +Any proper list structure, with optional surrounding whitespace. In +case of improper list structure, 0 is returned and the \fIvarname\fR +will contain the index of the +.QW element +where the list parsing fails, or \-1 if this cannot be determined. +.IP \fBlower\fR 12 +Any Unicode lower case alphabet character. +.IP \fBprint\fR 12 +Any Unicode printing character, including space. +.IP \fBpunct\fR 12 +Any Unicode punctuation character. +.IP \fBspace\fR 12 +Any Unicode whitespace character, mongolian vowel separator +(U+180e), zero width space (U+200b), word joiner (U+2060) or +zero width no-break space (U+feff) (=BOM). +.IP \fBtrue\fR 12 +Any of the forms allowed to \fBTcl_GetBoolean\fR where the value is +true. +.IP \fBupper\fR 12 +Any upper case alphabet character in the Unicode character set. +.IP \fBwideinteger\fR 12 +Any of the valid forms for a wide integer in Tcl, with optional +surrounding whitespace. In case of under/overflow in the value, 0 is +returned and the \fIvarname\fR will contain \-1. +.IP \fBwordchar\fR 12 +Any Unicode word character. That is any alphanumeric character, and +any Unicode connector punctuation characters (e.g. underscore). +.IP \fBxdigit\fR 12 +Any hexadecimal digit character ([0\-9A\-Fa\-f]). +.PP +In the case of \fBboolean\fR, \fBtrue\fR and \fBfalse\fR, if the +function will return 0, then the \fIvarname\fR will always be set to +0, due to the varied nature of a valid boolean value. +.RE +.TP +\fBstring last \fIneedleString haystackString\fR ?\fIlastIndex\fR? +. +Search \fIhaystackString\fR for a sequence of characters that exactly match +the characters in \fIneedleString\fR. If found, return the index of the +first character in the last such match within \fIhaystackString\fR. If there +is no match, then return \-1. If \fIlastIndex\fR is specified (in any +of the forms described in \fBSTRING INDICES\fR), then only the +characters in \fIhaystackString\fR at or before the specified \fIlastIndex\fR +will be considered by the search. For example, +.RS +.PP +.CS +\fBstring last a 0a23456789abcdef 15\fR +.CE +.PP +will return \fB10\fR, but +.PP +.CS +\fBstring last a 0a23456789abcdef 9\fR +.CE +.PP +will return \fB1\fR. +.RE +.TP +\fBstring length \fIstring\fR +. +Returns a decimal string giving the number of characters in +\fIstring\fR. Note that this is not necessarily the same as the +number of bytes used to store the string. If the value is a +byte array value (such as those returned from reading a binary encoded +channel), then this will return the actual byte length of the value. +.TP +\fBstring map\fR ?\fB\-nocase\fR? \fImapping string\fR +. +Replaces substrings in \fIstring\fR based on the key-value pairs in +\fImapping\fR. \fImapping\fR is a list of \fIkey value key value ...\fR +as in the form returned by \fBarray get\fR. Each instance of a +key in the string will be replaced with its corresponding value. If +\fB\-nocase\fR is specified, then matching is done without regard to +case differences. Both \fIkey\fR and \fIvalue\fR may be multiple +characters. Replacement is done in an ordered manner, so the key +appearing first in the list will be checked first, and so on. +\fIstring\fR is only iterated over once, so earlier key replacements +will have no affect for later key matches. For example, +.RS +.PP +.CS +\fBstring map {abc 1 ab 2 a 3 1 0} 1abcaababcabababc\fR +.CE +.PP +will return the string \fB01321221\fR. +.PP +Note that if an earlier \fIkey\fR is a prefix of a later one, it will +completely mask the later one. So if the previous example is +reordered like this, +.PP +.CS +\fBstring map {1 0 ab 2 a 3 abc 1} 1abcaababcabababc\fR +.CE +.PP +it will return the string \fB02c322c222c\fR. +.RE +.TP +\fBstring match\fR ?\fB\-nocase\fR? \fIpattern\fR \fIstring\fR +. +See if \fIpattern\fR matches \fIstring\fR; return 1 if it does, 0 if +it does not. If \fB\-nocase\fR is specified, then the pattern attempts +to match against the string in a case insensitive manner. For the two +strings to match, their contents must be identical except that the +following special sequences may appear in \fIpattern\fR: +.RS +.IP \fB*\fR 10 +Matches any sequence of characters in \fIstring\fR, including a null +string. +.IP \fB?\fR 10 +Matches any single character in \fIstring\fR. +.IP \fB[\fIchars\fB]\fR 10 +Matches any character in the set given by \fIchars\fR. If a sequence +of the form \fIx\fB\-\fIy\fR appears in \fIchars\fR, then any +character between \fIx\fR and \fIy\fR, inclusive, will match. When +used with \fB\-nocase\fR, the end points of the range are converted to +lower case first. Whereas {[A\-z]} matches +.QW _ +when matching case-sensitively (since +.QW _ +falls between the +.QW Z +and +.QW a ), +with \fB\-nocase\fR this is considered like {[A\-Za\-z]} (and +probably what was meant in the first place). +.IP \fB\e\fIx\fR 10 +Matches the single character \fIx\fR. This provides a way of avoiding +the special interpretation of the characters \fB*?[]\e\fR in +\fIpattern\fR. +.RE +.TP +\fBstring range \fIstring first last\fR +. +Returns a range of consecutive characters from \fIstring\fR, starting +with the character whose index is \fIfirst\fR and ending with the +character whose index is \fIlast\fR. An index of 0 refers to the first +character of the string. \fIfirst\fR and \fIlast\fR may be specified +as for the \fBindex\fR method. If \fIfirst\fR is less than zero then +it is treated as if it were zero, and if \fIlast\fR is greater than or +equal to the length of the string then it is treated as if it were +\fBend\fR. If \fIfirst\fR is greater than \fIlast\fR then an empty +string is returned. +.TP +\fBstring repeat \fIstring count\fR +. +Returns \fIstring\fR repeated \fIcount\fR number of times. +.TP +\fBstring replace \fIstring first last\fR ?\fInewstring\fR? +. +Removes a range of consecutive characters from \fIstring\fR, starting +with the character whose index is \fIfirst\fR and ending with the +character whose index is \fIlast\fR. An index of 0 refers to the +first character of the string. \fIFirst\fR and \fIlast\fR may be +specified as for the \fBindex\fR method. If \fInewstring\fR is +specified, then it is placed in the removed character range. If +\fIfirst\fR is less than zero then it is treated as if it were zero, +and if \fIlast\fR is greater than or equal to the length of the string +then it is treated as if it were \fBend\fR. If \fIfirst\fR is greater +than \fIlast\fR or the length of the initial string, or \fIlast\fR is +less than 0, then the initial string is returned untouched. +.TP +\fBstring reverse \fIstring\fR +. +Returns a string that is the same length as \fIstring\fR but with its +characters in the reverse order. +.TP +\fBstring tolower \fIstring\fR ?\fIfirst\fR? ?\fIlast\fR? +. +Returns a value equal to \fIstring\fR except that all upper (or title) +case letters have been converted to lower case. If \fIfirst\fR is +specified, it refers to the first char index in the string to start +modifying. If \fIlast\fR is specified, it refers to the char index in +the string to stop at (inclusive). \fIfirst\fR and \fIlast\fR may be +specified using the forms described in \fBSTRING INDICES\fR. +.TP +\fBstring totitle \fIstring\fR ?\fIfirst\fR? ?\fIlast\fR? +. +Returns a value equal to \fIstring\fR except that the first character +in \fIstring\fR is converted to its Unicode title case variant (or +upper case if there is no title case variant) and the rest of the +string is converted to lower case. If \fIfirst\fR is specified, it +refers to the first char index in the string to start modifying. If +\fIlast\fR is specified, it refers to the char index in the string to +stop at (inclusive). \fIfirst\fR and \fIlast\fR may be specified +using the forms described in \fBSTRING INDICES\fR. +.TP +\fBstring toupper \fIstring\fR ?\fIfirst\fR? ?\fIlast\fR? +. +Returns a value equal to \fIstring\fR except that all lower (or title) +case letters have been converted to upper case. If \fIfirst\fR is +specified, it refers to the first char index in the string to start +modifying. If \fIlast\fR is specified, it refers to the char index in +the string to stop at (inclusive). \fIfirst\fR and \fIlast\fR may be +specified using the forms described in \fBSTRING INDICES\fR. +.TP +\fBstring trim \fIstring\fR ?\fIchars\fR? +. +Returns a value equal to \fIstring\fR except that any leading or +trailing characters present in the string given by \fIchars\fR are removed. If +\fIchars\fR is not specified then white space is removed (any character +for which \fBstring is space\fR returns 1, and "\0"). +.TP +\fBstring trimleft \fIstring\fR ?\fIchars\fR? +. +Returns a value equal to \fIstring\fR except that any leading +characters present in the string given by \fIchars\fR are removed. If +\fIchars\fR is not specified then white space is removed (any character +for which \fBstring is space\fR returns 1, and "\0"). +.TP +\fBstring trimright \fIstring\fR ?\fIchars\fR? +. +Returns a value equal to \fIstring\fR except that any trailing +characters present in the string given by \fIchars\fR are removed. If +\fIchars\fR is not specified then white space is removed (any character +for which \fBstring is space\fR returns 1, and "\0"). +.SS "OBSOLETE SUBCOMMANDS" +.PP +These subcommands are currently supported, but are likely to go away in a +future release as their functionality is either virtually never used or highly +misleading. +.TP +\fBstring bytelength \fIstring\fR +. +Returns a decimal string giving the number of bytes used to represent +\fIstring\fR in memory when encoded as Tcl's internal modified UTF\-8; +Tcl may use other encodings for \fIstring\fR as well, and does not +guarantee to only use a single encoding for a particular \fIstring\fR. +Because UTF\-8 uses a variable number of bytes to represent Unicode +characters, the byte length will not be the same as the character +length in general. The cases where a script cares about the byte +length are rare. +.RS +.PP +In almost all cases, you should use the +\fBstring length\fR operation (including determining the length of a +Tcl byte array value). Refer to the \fBTcl_NumUtfChars\fR manual +entry for more details on the UTF\-8 representation. +.PP +Formally, the \fBstring bytelength\fR operation returns the content of +the \fIlength\fR field of the \fBTcl_Obj\fR structure, after calling +\fBTcl_GetString\fR to ensure that the \fIbytes\fR field is populated. +This is highly unlikely to be useful to Tcl scripts, as Tcl's internal +encoding is not strict UTF\-8, but rather a modified CESU\-8 with a +denormalized NUL (identical to that used in a number of places by +Java's serialization mechanism) to enable basic processing with +non-Unicode-aware C functions. As this representation should only +ever be used by Tcl's implementation, the number of bytes used to +store the representation is of very low value (except to C extension +code, which has direct access for the purpose of memory management, +etc.) +.PP +\fICompatibility note:\fR it is likely that this subcommand will be +withdrawn in a future version of Tcl. It is better to use the +\fBencoding convertto\fR command to convert a string to a known +encoding and then apply \fBstring length\fR to that. +.PP +.CS +\fBstring length\fR [encoding convertto utf-8 $theString] +.CE +.RE +.TP +\fBstring wordend \fIstring charIndex\fR +. +Returns the index of the character just after the last one in the word +containing character \fIcharIndex\fR of \fIstring\fR. \fIcharIndex\fR +may be specified using the forms in \fBSTRING INDICES\fR. A word is +considered to be any contiguous range of alphanumeric (Unicode letters +or decimal digits) or underscore (Unicode connector punctuation) +characters, or any single character other than these. +.TP +\fBstring wordstart \fIstring charIndex\fR +. +Returns the index of the first character in the word containing character +\fIcharIndex\fR of \fIstring\fR. \fIcharIndex\fR may be specified using the +forms in \fBSTRING INDICES\fR. A word is considered to be any contiguous +range of alphanumeric (Unicode letters or decimal digits) or underscore +(Unicode connector punctuation) characters, or any single character other than +these. +.SH "STRING INDICES" +.PP +When referring to indices into a string (e.g., for \fBstring index\fR +or \fBstring range\fR) the following formats are supported: +.IP \fIinteger\fR 10 +For any index value that passes \fBstring is integer \-strict\fR, +the char specified at this integral index (e.g., \fB2\fR would refer to the +.QW c +in +.QW abcd ). +.IP \fBend\fR 10 +The last char of the string (e.g., \fBend\fR would refer to the +.QW d +in +.QW abcd ). +.IP \fBend\-\fIN\fR 10 +The last char of the string minus the specified integer offset \fIN\fR (e.g., +.QW \fBend\-1\fR +would refer to the +.QW c +in +.QW abcd ). +.IP \fBend+\fIN\fR 10 +The last char of the string plus the specified integer offset \fIN\fR (e.g., +.QW \fBend+\-1\fR +would refer to the +.QW c +in +.QW abcd ). +.IP \fIM\fB+\fIN\fR 10 +The char specified at the integral index that is the sum of +integer values \fIM\fR and \fIN\fR (e.g., +.QW \fB1+1\fR +would refer to the +.QW c +in +.QW abcd ). +.IP \fIM\fB\-\fIN\fR 10 +The char specified at the integral index that is the difference of +integer values \fIM\fR and \fIN\fR (e.g., +.QW \fB2\-1\fR +would refer to the +.QW b +in +.QW abcd ). +.PP +In the specifications above, the integer value \fIM\fR contains no +trailing whitespace and the integer value \fIN\fR contains no +leading whitespace. +.SH EXAMPLE +.PP +Test if the string in the variable \fIstring\fR is a proper non-empty +prefix of the string \fBfoobar\fR. +.PP +.CS +set length [\fBstring length\fR $string] +if {$length == 0} { + set isPrefix 0 +} else { + set isPrefix [\fBstring equal\fR \-length $length $string "foobar"] +} +.CE +.SH "SEE ALSO" +expr(n), list(n) +.SH KEYWORDS +case conversion, compare, index, match, pattern, string, word, equal, +ctype, character, reverse +.\" Local Variables: +.\" mode: nroff +.\" End: diff --git a/tcl8.6/doc/subst.n b/tcl8.6/doc/subst.n new file mode 100644 index 0000000..4518140 --- /dev/null +++ b/tcl8.6/doc/subst.n @@ -0,0 +1,164 @@ +'\" +'\" Copyright (c) 1994 The Regents of the University of California. +'\" Copyright (c) 1994-1996 Sun Microsystems, Inc. +'\" Copyright (c) 2001 Donal K. Fellows +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH subst n 7.4 Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +subst \- Perform backslash, command, and variable substitutions +.SH SYNOPSIS +\fBsubst \fR?\fB\-nobackslashes\fR? ?\fB\-nocommands\fR? ?\fB\-novariables\fR? \fIstring\fR +.BE +.SH DESCRIPTION +.PP +This command performs variable substitutions, command substitutions, +and backslash substitutions on its \fIstring\fR argument and +returns the fully-substituted result. +The substitutions are performed in exactly the same way as for +Tcl commands. +As a result, the \fIstring\fR argument is actually substituted twice, +once by the Tcl parser in the usual fashion for Tcl commands, and +again by the \fIsubst\fR command. +.PP +If any of the \fB\-nobackslashes\fR, \fB\-nocommands\fR, or +\fB\-novariables\fR are specified, then the corresponding substitutions +are not performed. +For example, if \fB\-nocommands\fR is specified, command substitution +is not performed: open and close brackets are treated as ordinary characters +with no special interpretation. +.PP +Note that the substitution of one kind can include substitution of +other kinds. For example, even when the \fB\-novariables\fR option +is specified, command substitution is performed without restriction. +This means that any variable substitution necessary to complete the +command substitution will still take place. Likewise, any command +substitution necessary to complete a variable substitution will +take place, even when \fB\-nocommands\fR is specified. See the +\fBEXAMPLES\fR below. +.PP +If an error occurs during substitution, then \fBsubst\fR will return +that error. If a break exception occurs during command or variable +substitution, the result of the whole substitution will be the +string (as substituted) up to the start of the substitution that +raised the exception. If a continue exception occurs during the +evaluation of a command or variable substitution, an empty string +will be substituted for that entire command or variable substitution +(as long as it is well-formed Tcl.) If a return exception occurs, +or any other return code is returned during command or variable +substitution, then the returned value is substituted for that +substitution. See the \fBEXAMPLES\fR below. In this way, all exceptional +return codes are +.QW caught +by \fBsubst\fR. The \fBsubst\fR command +itself will either return an error, or will complete successfully. +.SH EXAMPLES +.PP +When it performs its substitutions, \fIsubst\fR does not give any +special treatment to double quotes or curly braces (except within +command substitutions) so the script +.PP +.CS +set a 44 +\fBsubst\fR {xyz {$a}} +.CE +.PP +returns +.QW "\fBxyz {44}\fR" , +not +.QW "\fBxyz {$a}\fR" +and the script +.PP +.CS +set a "p\e} q \e{r" +\fBsubst\fR {xyz {$a}} +.CE +.PP +returns +.QW "\fBxyz {p} q {r}\fR" , +not +.QW "\fBxyz {p\e} q \e{r}\fR". +.PP +When command substitution is performed, it includes any variable +substitution necessary to evaluate the script. +.PP +.CS +set a 44 +\fBsubst\fR -novariables {$a [format $a]} +.CE +.PP +returns +.QW "\fB$a 44\fR" , +not +.QW "\fB$a $a\fR" . +Similarly, when +variable substitution is performed, it includes any command +substitution necessary to retrieve the value of the variable. +.PP +.CS +proc b {} {return c} +array set a {c c [b] tricky} +\fBsubst\fR -nocommands {[b] $a([b])} +.CE +.PP +returns +.QW "\fB[b] c\fR" , +not +.QW "\fB[b] tricky\fR" . +.PP +The continue and break exceptions allow command substitutions to +prevent substitution of the rest of the command substitution and the +rest of \fIstring\fR respectively, giving script authors more options +when processing text using \fIsubst\fR. For example, the script +.PP +.CS +\fBsubst\fR {abc,[break],def} +.CE +.PP +returns +.QW \fBabc,\fR , +not +.QW \fBabc,,def\fR +and the script +.PP +.CS +\fBsubst\fR {abc,[continue;expr {1+2}],def} +.CE +.PP +returns +.QW \fBabc,,def\fR , +not +.QW \fBabc,3,def\fR . +.PP +Other exceptional return codes substitute the returned value +.PP +.CS +\fBsubst\fR {abc,[return foo;expr {1+2}],def} +.CE +.PP +returns +.QW \fBabc,foo,def\fR , +not +.QW \fBabc,3,def\fR +and +.PP +.CS +\fBsubst\fR {abc,[return -code 10 foo;expr {1+2}],def} +.CE +.PP +also returns +.QW \fBabc,foo,def\fR , +not +.QW \fBabc,3,def\fR . +.SH "SEE ALSO" +Tcl(n), eval(n), break(n), continue(n) +.SH KEYWORDS +backslash substitution, command substitution, quoting, substitution, variable substitution +.\" Local Variables: +.\" mode: nroff +.\" End: diff --git a/tcl8.6/doc/switch.n b/tcl8.6/doc/switch.n new file mode 100644 index 0000000..6e27f56 --- /dev/null +++ b/tcl8.6/doc/switch.n @@ -0,0 +1,186 @@ +'\" +'\" Copyright (c) 1993 The Regents of the University of California. +'\" Copyright (c) 1994-1997 Sun Microsystems, Inc. +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH switch n 8.5 Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +switch \- Evaluate one of several scripts, depending on a given value +.SH SYNOPSIS +\fBswitch \fR?\fIoptions\fR?\fI string pattern body \fR?\fIpattern body \fR...? +.sp +\fBswitch \fR?\fIoptions\fR?\fI string \fR{\fIpattern body \fR?\fIpattern body \fR...?} +.BE +.SH DESCRIPTION +.PP +The \fBswitch\fR command matches its \fIstring\fR argument against each of +the \fIpattern\fR arguments in order. +As soon as it finds a \fIpattern\fR that matches \fIstring\fR it +evaluates the following \fIbody\fR argument by passing it recursively +to the Tcl interpreter and returns the result of that evaluation. +If the last \fIpattern\fR argument is \fBdefault\fR then it matches +anything. +If no \fIpattern\fR argument +matches \fIstring\fR and no default is given, then the \fBswitch\fR +command returns an empty string. +.PP +If the initial arguments to \fBswitch\fR start with \fB\-\fR then +they are treated as options +unless there are exactly two arguments to \fBswitch\fR (in which case the +first must the \fIstring\fR and the second must be the +\fIpattern\fR/\fIbody\fR list). +The following options are currently supported: +.TP 10 +\fB\-exact\fR +. +Use exact matching when comparing \fIstring\fR to a pattern. This +is the default. +.TP 10 +\fB\-glob\fR +. +When matching \fIstring\fR to the patterns, use glob-style matching +(i.e. the same as implemented by the \fBstring match\fR command). +.TP 10 +\fB\-regexp\fR +. +When matching \fIstring\fR to the patterns, use regular +expression matching +(as described in the \fBre_syntax\fR reference page). +.TP 10 +\fB\-nocase\fR +. +Causes comparisons to be handled in a case-insensitive manner. +.TP 10 +\fB\-matchvar\fR \fIvarName\fR +. +This option (only legal when \fB\-regexp\fR is also specified) +specifies the name of a variable into which the list of matches +found by the regular expression engine will be written. The first +element of the list written will be the overall substring of the input +string (i.e. the \fIstring\fR argument to \fBswitch\fR) matched, the +second element of the list will be the substring matched by the first +capturing parenthesis in the regular expression that matched, and so +on. When a \fBdefault\fR branch is taken, the variable will have the +empty list written to it. This option may be specified at the same +time as the \fB\-indexvar\fR option. +.TP 10 +\fB\-indexvar\fR \fIvarName\fR +. +This option (only legal when \fB\-regexp\fR is also specified) +specifies the name of a variable into which the list of indices +referring to matching substrings +found by the regular expression engine will be written. The first +element of the list written will be a two-element list specifying the +index of the start and index of the first character after the end of +the overall substring of the input +string (i.e. the \fIstring\fR argument to \fBswitch\fR) matched, in a +similar way to the \fB\-indices\fR option to the \fBregexp\fR can +obtain. Similarly, the second element of the list refers to the first +capturing parenthesis in the regular expression that matched, and so +on. When a \fBdefault\fR branch is taken, the variable will have the +empty list written to it. This option may be specified at the same +time as the \fB\-matchvar\fR option. +.TP 10 +\fB\-\|\-\fR +. +Marks the end of options. The argument following this one will +be treated as \fIstring\fR even if it starts with a \fB\-\fR. +This is not required when the matching patterns and bodies are grouped +together in a single argument. +.PP +Two syntaxes are provided for the \fIpattern\fR and \fIbody\fR arguments. +The first uses a separate argument for each of the patterns and commands; +this form is convenient if substitutions are desired on some of the +patterns or commands. +The second form places all of the patterns and commands together into +a single argument; the argument must have proper list structure, with +the elements of the list being the patterns and commands. +The second form makes it easy to construct multi-line switch commands, +since the braces around the whole list make it unnecessary to include a +backslash at the end of each line. +Since the \fIpattern\fR arguments are in braces in the second form, +no command or variable substitutions are performed on them; this makes +the behavior of the second form different than the first form in some +cases. +.PP +If a \fIbody\fR is specified as +.QW \fB\-\fR +it means that the \fIbody\fR +for the next pattern should also be used as the body for this +pattern (if the next pattern also has a body of +.QW \fB\-\fR +then the body after that is used, and so on). +This feature makes it possible to share a single \fIbody\fR among +several patterns. +.PP +Beware of how you place comments in \fBswitch\fR commands. Comments +should only be placed \fBinside\fR the execution body of one of the +patterns, and not intermingled with the patterns. +.SH "EXAMPLES" +.PP +The \fBswitch\fR command can match against variables and not just +literals, as shown here (the result is \fI2\fR): +.PP +.CS +set foo "abc" +\fBswitch\fR abc a \- b {expr {1}} $foo {expr {2}} default {expr {3}} +.CE +.PP +Using glob matching and the fall-through body is an alternative to +writing regular expressions with alternations, as can be seen here +(this returns \fI1\fR): +.PP +.CS +\fBswitch\fR \-glob aaab { + a*b \- + b {expr {1}} + a* {expr {2}} + default {expr {3}} +} +.CE +.PP +Whenever nothing matches, the \fBdefault\fR clause (which must be +last) is taken. This example has a result of \fI3\fR: +.PP +.CS +\fBswitch\fR xyz { + a \- + b { + # Correct Comment Placement + expr {1} + } + c { + expr {2} + } + default { + expr {3} + } +} +.CE +.PP +When matching against regular expressions, information about what +exactly matched is easily obtained using the \fB\-matchvar\fR option: +.PP +.CS +\fBswitch\fR \-regexp \-matchvar foo \-\- $bar { + a(b*)c { + puts "Found [string length [lindex $foo 1]] 'b's" + } + d(e*)f(g*)h { + puts "Found [string length [lindex $foo 1]] 'e's and\e + [string length [lindex $foo 2]] 'g's" + } +} +.CE +.SH "SEE ALSO" +for(n), if(n), regexp(n) +.SH KEYWORDS +switch, match, regular expression +.\" Local Variables: +.\" mode: nroff +.\" End: diff --git a/tcl8.6/doc/tailcall.n b/tcl8.6/doc/tailcall.n new file mode 100644 index 0000000..926c608 --- /dev/null +++ b/tcl8.6/doc/tailcall.n @@ -0,0 +1,69 @@ +'\" +'\" Copyright (c) 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. +'\" +.TH tailcall n 8.6 Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +tailcall \- Replace the current procedure with another command +.SH SYNOPSIS +\fBtailcall \fIcommand\fR ?\fIarg ...\fR? +.BE +.SH DESCRIPTION +.PP +The \fBtailcall\fR command replaces the currently executing procedure, lambda +application, or method with another command. The \fIcommand\fR, which will +have \fIarg ...\fR passed as arguments if they are supplied, will be looked up +in the current namespace context, not in the caller's. Apart from that +difference in resolution, it is equivalent to: +.PP +.CS +return [uplevel 1 [list \fIcommand\fR ?\fIarg ...\fR?]] +.CE +.PP +This command may not be invoked from within an \fBuplevel\fR into a procedure +or inside a \fBcatch\fR inside a procedure or lambda. +'\" TODO: sort out the mess with the [try] command! +.SH EXAMPLE +.PP +Compute the factorial of a number. +.PP +.CS +proc factorial {n {accum 1}} { + if {$n < 2} { + return $accum + } + \fBtailcall\fR factorial [expr {$n - 1}] [expr {$accum * $n}] +} +.CE +.PP +Print the elements of a list with alternating lines having different +indentations. +.PP +.CS +proc printList {theList} { + if {[llength $theList]} { + puts "> [lindex $theList 0]" + \fBtailcall\fR printList2 [lrange $theList 1 end] + } +} +proc printList2 {theList} { + if {[llength $theList]} { + puts "< [lindex $theList 0]" + \fBtailcall\fR printList [lrange $theList 1 end] + } +} +.CE +.SH "SEE ALSO" +apply(n), proc(n), uplevel(n) +.SH KEYWORDS +call, recursion, tail recursion +'\" Local Variables: +'\" mode: nroff +'\" fill-column: 78 +'\" End: diff --git a/tcl8.6/doc/tclsh.1 b/tcl8.6/doc/tclsh.1 new file mode 100644 index 0000000..6ed5eb6 --- /dev/null +++ b/tcl8.6/doc/tclsh.1 @@ -0,0 +1,149 @@ +'\" +'\" Copyright (c) 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. +'\" +.TH tclsh 1 "" Tcl "Tcl Applications" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +tclsh \- Simple shell containing Tcl interpreter +.SH SYNOPSIS +\fBtclsh\fR ?\fB\-encoding \fIname\fR? ?\fIfileName arg arg ...\fR? +.BE +.SH DESCRIPTION +.PP +\fBTclsh\fR is a shell-like application that reads Tcl commands +from its standard input or from a file and evaluates them. +If invoked with no arguments then it runs interactively, reading +Tcl commands from standard input and printing command results and +error messages to standard output. +It runs until the \fBexit\fR command is invoked or until it +reaches end-of-file on its standard input. +If there exists a file \fB.tclshrc\fR (or \fBtclshrc.tcl\fR on +the Windows platforms) in the home directory of +the user, interactive \fBtclsh\fR evaluates the file as a Tcl script +just before reading the first command from standard input. +.SH "SCRIPT FILES" +.PP +If \fBtclsh\fR is invoked with arguments then the first few arguments +specify the name of a script file, and, optionally, the encoding of +the text data stored in that script file. Any additional arguments +are made available to the script as variables (see below). +Instead of reading commands from standard input \fBtclsh\fR will +read Tcl commands from the named file; \fBtclsh\fR will exit +when it reaches the end of the file. +The end of the file may be marked either by the physical end of +the medium, or by the character, +.QW \e032 +.PQ \eu001a ", control-Z" . +If this character is present in the file, the \fBtclsh\fR application +will read text up to but not including the character. An application +that requires this character in the file may safely encode it as +.QW \e032 , +.QW \ex1a , +or +.QW \eu001a ; +or may generate it by use of commands such as \fBformat\fR or \fBbinary\fR. +There is no automatic evaluation of \fB.tclshrc\fR when the name +of a script file is presented on the \fBtclsh\fR command +line, but the script file can always \fBsource\fR it if desired. +.PP +If you create a Tcl script in a file whose first line is +.PP +.CS +\fB#!/usr/local/bin/tclsh\fR +.CE +.PP +then you can invoke the script file directly from your shell if +you mark the file as executable. +This assumes that \fBtclsh\fR has been installed in the default +location in /usr/local/bin; if it is installed somewhere else +then you will have to modify the above line to match. +Many UNIX systems do not allow the \fB#!\fR line to exceed about +30 characters in length, so be sure that the \fBtclsh\fR +executable can be accessed with a short file name. +.PP +An even better approach is to start your script files with the +following three lines: +.PP +.CS +\fB#!/bin/sh +# the next line restarts using tclsh \e +exec tclsh "$0" ${1+"$@"}\fR +.CE +.PP +This approach has three advantages over the approach in the previous +paragraph. First, the location of the \fBtclsh\fR binary does not have +to be hard-wired into the script: it can be anywhere in your shell +search path. Second, it gets around the 30-character file name limit +in the previous approach. +Third, this approach will work even if \fBtclsh\fR is +itself a shell script (this is done on some systems in order to +handle multiple architectures or operating systems: the \fBtclsh\fR +script selects one of several binaries to run). The three lines +cause both \fBsh\fR and \fBtclsh\fR to process the script, but the +\fBexec\fR is only executed by \fBsh\fR. +\fBsh\fR processes the script first; it treats the second +line as a comment and executes the third line. +The \fBexec\fR statement cause the shell to stop processing and +instead to start up \fBtclsh\fR to reprocess the entire script. +When \fBtclsh\fR starts up, it treats all three lines as comments, +since the backslash at the end of the second line causes the third +line to be treated as part of the comment on the second line. +.PP +You should note that it is also common practice to install tclsh with +its version number as part of the name. This has the advantage of +allowing multiple versions of Tcl to exist on the same system at once, +but also the disadvantage of making it harder to write scripts that +start up uniformly across different versions of Tcl. +.SH "VARIABLES" +.PP +\fBTclsh\fR sets the following global Tcl variables in addition to those +created by the Tcl library itself (such as \fBenv\fR, which maps +environment variables such as \fBPATH\fR into Tcl): +.TP 15 +\fBargc\fR +. +Contains a count of the number of \fIarg\fR arguments (0 if none), +not including the name of the script file. +.TP 15 +\fBargv\fR +. +Contains a Tcl list whose elements are the \fIarg\fR arguments, +in order, or an empty string if there are no \fIarg\fR arguments. +.TP 15 +\fBargv0\fR +. +Contains \fIfileName\fR if it was specified. +Otherwise, contains the name by which \fBtclsh\fR was invoked. +.TP 15 +\fBtcl_interactive\fR +. +Contains 1 if \fBtclsh\fR is running interactively (no +\fIfileName\fR was specified and standard input is a terminal-like +device), 0 otherwise. +.SH PROMPTS +.PP +When \fBtclsh\fR is invoked interactively it normally prompts for each +command with +.QW "\fB% \fR" . +You can change the prompt by setting the global +variables \fBtcl_prompt1\fR and \fBtcl_prompt2\fR. If variable +\fBtcl_prompt1\fR exists then it must consist of a Tcl script +to output a prompt; instead of outputting a prompt \fBtclsh\fR +will evaluate the script in \fBtcl_prompt1\fR. +The variable \fBtcl_prompt2\fR is used in a similar way when +a newline is typed but the current command is not yet complete; +if \fBtcl_prompt2\fR is not set then no prompt is output for +incomplete commands. +.SH "STANDARD CHANNELS" +.PP +See \fBTcl_StandardChannels\fR for more explanations. +.SH "SEE ALSO" +auto_path(n), encoding(n), env(n), fconfigure(n) +.SH KEYWORDS +application, argument, interpreter, prompt, script file, shell diff --git a/tcl8.6/doc/tcltest.n b/tcl8.6/doc/tcltest.n new file mode 100644 index 0000000..05c1922 --- /dev/null +++ b/tcl8.6/doc/tcltest.n @@ -0,0 +1,1259 @@ +'\" +'\" Copyright (c) 1990-1994 The Regents of the University of California +'\" Copyright (c) 1994-1997 Sun Microsystems, Inc. +'\" Copyright (c) 1998-1999 Scriptics Corporation +'\" Copyright (c) 2000 Ajuba Solutions +'\" Contributions from Don Porter, NIST, 2002. (not subject to US copyright) +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH "tcltest" n 2.3 tcltest "Tcl Bundled Packages" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +tcltest \- Test harness support code and utilities +.SH SYNOPSIS +.nf +\fBpackage require tcltest\fR ?\fB2.3\fR? + +\fBtcltest::test \fIname description\fR ?\fI\-option value ...\fR? +\fBtcltest::test \fIname description\fR ?\fIconstraints\fR? \fIbody result\fR + +\fBtcltest::loadTestedCommands\fR +\fBtcltest::makeDirectory \fIname\fR ?\fIdirectory\fR? +\fBtcltest::removeDirectory \fIname\fR ?\fIdirectory\fR? +\fBtcltest::makeFile \fIcontents name\fR ?\fIdirectory\fR? +\fBtcltest::removeFile \fIname\fR ?\fIdirectory\fR? +\fBtcltest::viewFile \fIname\fR ?\fIdirectory\fR? +\fBtcltest::cleanupTests \fR?\fIrunningMultipleTests\fR? +\fBtcltest::runAllTests\fR + +\fBtcltest::configure\fR +\fBtcltest::configure \fI\-option\fR +\fBtcltest::configure \fI\-option value\fR ?\fI\-option value ...\fR? +\fBtcltest::customMatch \fImode command\fR +\fBtcltest::testConstraint \fIconstraint\fR ?\fIvalue\fR? +\fBtcltest::outputChannel \fR?\fIchannelID\fR? +\fBtcltest::errorChannel \fR?\fIchannelID\fR? +\fBtcltest::interpreter \fR?\fIinterp\fR? + +\fBtcltest::debug \fR?\fIlevel\fR? +\fBtcltest::errorFile \fR?\fIfilename\fR? +\fBtcltest::limitConstraints \fR?\fIboolean\fR? +\fBtcltest::loadFile \fR?\fIfilename\fR? +\fBtcltest::loadScript \fR?\fIscript\fR? +\fBtcltest::match \fR?\fIpatternList\fR? +\fBtcltest::matchDirectories \fR?\fIpatternList\fR? +\fBtcltest::matchFiles \fR?\fIpatternList\fR? +\fBtcltest::outputFile \fR?\fIfilename\fR? +\fBtcltest::preserveCore \fR?\fIlevel\fR? +\fBtcltest::singleProcess \fR?\fIboolean\fR? +\fBtcltest::skip \fR?\fIpatternList\fR? +\fBtcltest::skipDirectories \fR?\fIpatternList\fR? +\fBtcltest::skipFiles \fR?\fIpatternList\fR? +\fBtcltest::temporaryDirectory \fR?\fIdirectory\fR? +\fBtcltest::testsDirectory \fR?\fIdirectory\fR? +\fBtcltest::verbose \fR?\fIlevel\fR? + +\fBtcltest::test \fIname description optionList\fR +\fBtcltest::bytestring \fIstring\fR +\fBtcltest::normalizeMsg \fImsg\fR +\fBtcltest::normalizePath \fIpathVar\fR +\fBtcltest::workingDirectory \fR?\fIdir\fR? +.fi +.BE +.SH DESCRIPTION +.PP +The \fBtcltest\fR package provides several utility commands useful +in the construction of test suites for code instrumented to be +run by evaluation of Tcl commands. Notably the built-in commands +of the Tcl library itself are tested by a test suite using the +tcltest package. +.PP +All the commands provided by the \fBtcltest\fR package are defined +in and exported from the \fB::tcltest\fR namespace, as indicated in +the \fBSYNOPSIS\fR above. In the following sections, all commands +will be described by their simple names, in the interest of brevity. +.PP +The central command of \fBtcltest\fR is \fBtest\fR that defines +and runs a test. Testing with \fBtest\fR involves evaluation +of a Tcl script and comparing the result to an expected result, as +configured and controlled by a number of options. Several other +commands provided by \fBtcltest\fR govern the configuration of +\fBtest\fR and the collection of many \fBtest\fR commands into +test suites. +.PP +See \fBCREATING TEST SUITES WITH TCLTEST\fR below for an extended example +of how to use the commands of \fBtcltest\fR to produce test suites +for your Tcl-enabled code. +.SH COMMANDS +.TP +\fBtest\fR \fIname description\fR ?\fI\-option value ...\fR? +. +Defines and possibly runs a test with the name \fIname\fR and +description \fIdescription\fR. The name and description of a test +are used in messages reported by \fBtest\fR during the +test, as configured by the options of \fBtcltest\fR. The +remaining \fIoption value\fR arguments to \fBtest\fR +define the test, including the scripts to run, the conditions +under which to run them, the expected result, and the means +by which the expected and actual results should be compared. +See \fBTESTS\fR below for a complete description of the valid +options and how they define a test. The \fBtest\fR command +returns an empty string. +.TP +\fBtest\fR \fIname description\fR ?\fIconstraints\fR? \fIbody result\fR +. +This form of \fBtest\fR is provided to support test suites written +for version 1 of the \fBtcltest\fR package, and also a simpler +interface for a common usage. It is the same as +.QW "\fBtest\fR \fIname description\fB \-constraints \fIconstraints\fB \-body \fIbody\fB \-result \fIresult\fR" . +All other options to \fBtest\fR +take their default values. When \fIconstraints\fR is omitted, this +form of \fBtest\fR can be distinguished from the first because +all \fIoption\fRs begin with +.QW \- . +.TP +\fBloadTestedCommands\fR +. +Evaluates in the caller's context the script specified by +\fBconfigure \-load\fR or \fBconfigure \-loadfile\fR. +Returns the result of that script evaluation, including any error +raised by the script. Use this command and the related +configuration options to provide the commands to be tested to +the interpreter running the test suite. +.TP +\fBmakeFile\fR \fIcontents name\fR ?\fIdirectory\fR? +. +Creates a file named \fIname\fR relative to +directory \fIdirectory\fR and write \fIcontents\fR +to that file using the encoding \fBencoding system\fR. +If \fIcontents\fR does not end with a newline, a newline +will be appended so that the file named \fIname\fR +does end with a newline. Because the system encoding is used, +this command is only suitable for making text files. +The file will be removed by the next evaluation +of \fBcleanupTests\fR, unless it is removed by +\fBremoveFile\fR first. The default value of +\fIdirectory\fR is the directory \fBconfigure \-tmpdir\fR. +Returns the full path of the file created. Use this command +to create any text file required by a test with contents as needed. +.TP +\fBremoveFile\fR \fIname\fR ?\fIdirectory\fR? +. +Forces the file referenced by \fIname\fR to be removed. This file name +should be relative to \fIdirectory\fR. The default value of +\fIdirectory\fR is the directory \fBconfigure \-tmpdir\fR. +Returns an empty string. Use this command to delete files +created by \fBmakeFile\fR. +.TP +\fBmakeDirectory\fR \fIname\fR ?\fIdirectory\fR? +. +Creates a directory named \fIname\fR relative to directory \fIdirectory\fR. +The directory will be removed by the next evaluation of \fBcleanupTests\fR, +unless it is removed by \fBremoveDirectory\fR first. +The default value of \fIdirectory\fR is the directory +\fBconfigure \-tmpdir\fR. +Returns the full path of the directory created. Use this command +to create any directories that are required to exist by a test. +.TP +\fBremoveDirectory\fR \fIname\fR ?\fIdirectory\fR? +. +Forces the directory referenced by \fIname\fR to be removed. This +directory should be relative to \fIdirectory\fR. +The default value of \fIdirectory\fR is the directory +\fBconfigure \-tmpdir\fR. +Returns an empty string. Use this command to delete any directories +created by \fBmakeDirectory\fR. +.TP +\fBviewFile\fR \fIfile\fR ?\fIdirectory\fR? +. +Returns the contents of \fIfile\fR, except for any +final newline, just as \fBread \-nonewline\fR would return. +This file name should be relative to \fIdirectory\fR. +The default value of \fIdirectory\fR is the directory +\fBconfigure \-tmpdir\fR. Use this command +as a convenient way to turn the contents of a file generated +by a test into the result of that test for matching against +an expected result. The contents of the file are read using +the system encoding, so its usefulness is limited to text +files. +.TP +\fBcleanupTests\fR +. +Intended to clean up and summarize after several tests have been +run. Typically called once per test file, at the end of the file +after all tests have been completed. For best effectiveness, be +sure that the \fBcleanupTests\fR is evaluated even if an error +occurs earlier in the test file evaluation. +.RS +.PP +Prints statistics about the tests run and removes files that were +created by \fBmakeDirectory\fR and \fBmakeFile\fR since the +last \fBcleanupTests\fR. Names of files and directories +in the directory \fBconfigure \-tmpdir\fR created since +the last \fBcleanupTests\fR, but not created by +\fBmakeFile\fR or \fBmakeDirectory\fR are printed +to \fBoutputChannel\fR. This command also restores the original +shell environment, as described by the global \fBenv\fR +array. Returns an empty string. +.RE +.TP +\fBrunAllTests\fR +. +This is a master command meant to run an entire suite of tests, +spanning multiple files and/or directories, as governed by +the configurable options of \fBtcltest\fR. See \fBRUNNING ALL TESTS\fR +below for a complete description of the many variations possible +with \fBrunAllTests\fR. +.SS "CONFIGURATION COMMANDS" +.TP +\fBconfigure\fR +. +Returns the list of configurable options supported by \fBtcltest\fR. +See \fBCONFIGURABLE OPTIONS\fR below for the full list of options, +their valid values, and their effect on \fBtcltest\fR operations. +.TP +\fBconfigure \fIoption\fR +. +Returns the current value of the supported configurable option \fIoption\fR. +Raises an error if \fIoption\fR is not a supported configurable option. +.TP +\fBconfigure \fIoption value\fR ?\fI\-option value ...\fR? +. +Sets the value of each configurable option \fIoption\fR to the +corresponding value \fIvalue\fR, in order. Raises an error if +an \fIoption\fR is not a supported configurable option, or if +\fIvalue\fR is not a valid value for the corresponding \fIoption\fR, +or if a \fIvalue\fR is not provided. When an error is raised, the +operation of \fBconfigure\fR is halted, and subsequent \fIoption value\fR +arguments are not processed. +.RS +.PP +If the environment variable \fB::env(TCLTEST_OPTIONS)\fR exists when +the \fBtcltest\fR package is loaded (by \fBpackage require\fR \fBtcltest\fR) +then its value is taken as a list of arguments to pass to \fBconfigure\fR. +This allows the default values of the configuration options to be +set by the environment. +.RE +.TP +\fBcustomMatch \fImode script\fR +. +Registers \fImode\fR as a new legal value of the \fB\-match\fR option +to \fBtest\fR. When the \fB\-match \fImode\fR option is +passed to \fBtest\fR, the script \fIscript\fR will be evaluated +to compare the actual result of evaluating the body of the test +to the expected result. +To perform the match, the \fIscript\fR is completed with two additional +words, the expected result, and the actual result, and the completed script +is evaluated in the global namespace. +The completed script is expected to return a boolean value indicating +whether or not the results match. The built-in matching modes of +\fBtest\fR are \fBexact\fR, \fBglob\fR, and \fBregexp\fR. +.TP +\fBtestConstraint \fIconstraint\fR ?\fIboolean\fR? +. +Sets or returns the boolean value associated with the named \fIconstraint\fR. +See \fBTEST CONSTRAINTS\fR below for more information. +.TP +\fBinterpreter\fR ?\fIexecutableName\fR? +. +Sets or returns the name of the executable to be \fBexec\fRed by +\fBrunAllTests\fR to run each test file when +\fBconfigure \-singleproc\fR is false. +The default value for \fBinterpreter\fR is the name of the +currently running program as returned by \fBinfo nameofexecutable\fR. +.TP +\fBoutputChannel\fR ?\fIchannelID\fR? +. +Sets or returns the output channel ID. This defaults to \fBstdout\fR. +Any test that prints test related output should send +that output to \fBoutputChannel\fR rather than letting +that output default to \fBstdout\fR. +.TP +\fBerrorChannel\fR ?\fIchannelID\fR? +. +Sets or returns the error channel ID. This defaults to \fBstderr\fR. +Any test that prints error messages should send +that output to \fBerrorChannel\fR rather than printing +directly to \fBstderr\fR. +.SS "SHORTCUT CONFIGURATION COMMANDS" +.TP +\fBdebug\fR ?\fIlevel\fR? +. +Same as +.QW "\fBconfigure \-debug\fR ?\fIlevel\fR?" . +.TP +\fBerrorFile\fR ?\fIfilename\fR? +. +Same as +.QW "\fBconfigure \-errfile\fR ?\fIfilename\fR?" . +.TP +\fBlimitConstraints\fR ?\fIboolean\fR? +. +Same as +.QW "\fBconfigure \-limitconstraints\fR ?\fIboolean\fR?" . +.TP +\fBloadFile\fR ?\fIfilename\fR? +. +Same as +.QW "\fBconfigure \-loadfile\fR ?\fIfilename\fR?" . +.TP +\fBloadScript\fR ?\fIscript\fR? +. +Same as +.QW "\fBconfigure \-load\fR ?\fIscript\fR?" . +.TP +\fBmatch\fR ?\fIpatternList\fR? +. +Same as +.QW "\fBconfigure \-match\fR ?\fIpatternList\fR?" . +.TP +\fBmatchDirectories\fR ?\fIpatternList\fR? +. +Same as +.QW "\fBconfigure \-relateddir\fR ?\fIpatternList\fR?" . +.TP +\fBmatchFiles\fR ?\fIpatternList\fR? +. +Same as +.QW "\fBconfigure \-file\fR ?\fIpatternList\fR?" . +.TP +\fBoutputFile\fR ?\fIfilename\fR? +. +Same as +.QW "\fBconfigure \-outfile\fR ?\fIfilename\fR?" . +.TP +\fBpreserveCore\fR ?\fIlevel\fR? +. +Same as +.QW "\fBconfigure \-preservecore\fR ?\fIlevel\fR?" . +.TP +\fBsingleProcess\fR ?\fIboolean\fR? +. +Same as +.QW "\fBconfigure \-singleproc\fR ?\fIboolean\fR?" . +.TP +\fBskip\fR ?\fIpatternList\fR? +. +Same as +.QW "\fBconfigure \-skip\fR ?\fIpatternList\fR?" . +.TP +\fBskipDirectories\fR ?\fIpatternList\fR? +. +Same as +.QW "\fBconfigure \-asidefromdir\fR ?\fIpatternList\fR?" . +.TP +\fBskipFiles\fR ?\fIpatternList\fR? +. +Same as +.QW "\fBconfigure \-notfile\fR ?\fIpatternList\fR?" . +.TP +\fBtemporaryDirectory\fR ?\fIdirectory\fR? +. +Same as +.QW "\fBconfigure \-tmpdir\fR ?\fIdirectory\fR?" . +.TP +\fBtestsDirectory\fR ?\fIdirectory\fR? +. +Same as +.QW "\fBconfigure \-testdir\fR ?\fIdirectory\fR?" . +.TP +\fBverbose\fR ?\fIlevel\fR? +. +Same as +.QW "\fBconfigure \-verbose\fR ?\fIlevel\fR?" . +.SS "OTHER COMMANDS" +.PP +The remaining commands provided by \fBtcltest\fR have better +alternatives provided by \fBtcltest\fR or \fBTcl\fR itself. They +are retained to support existing test suites, but should be avoided +in new code. +.TP +\fBtest\fR \fIname description optionList\fR +. +This form of \fBtest\fR was provided to enable passing many +options spanning several lines to \fBtest\fR as a single +argument quoted by braces, rather than needing to backslash quote +the newlines between arguments to \fBtest\fR. The \fIoptionList\fR +argument is expected to be a list with an even number of elements +representing \fIoption\fR and \fIvalue\fR arguments to pass +to \fBtest\fR. However, these values are not passed directly, as +in the alternate forms of \fBswitch\fR. Instead, this form makes +an unfortunate attempt to overthrow Tcl's substitution rules by +performing substitutions on some of the list elements as an attempt to +implement a +.QW "do what I mean" +interpretation of a brace-enclosed +.QW block . +The result is nearly impossible to document clearly, and +for that reason this form is not recommended. See the examples in +\fBCREATING TEST SUITES WITH TCLTEST\fR below to see that this +form is really not necessary to avoid backslash-quoted newlines. +If you insist on using this form, examine +the source code of \fBtcltest\fR if you want to know the substitution +details, or just enclose the third through last argument +to \fBtest\fR in braces and hope for the best. +.TP +\fBworkingDirectory\fR ?\fIdirectoryName\fR? +. +Sets or returns the current working directory when the test suite is +running. The default value for workingDirectory is the directory in +which the test suite was launched. The Tcl commands \fBcd\fR and +\fBpwd\fR are sufficient replacements. +.TP +\fBnormalizeMsg \fImsg\fR +. +Returns the result of removing the +.QW extra +newlines from \fImsg\fR, where +.QW extra +is rather imprecise. Tcl offers plenty of string +processing commands to modify strings as you wish, and +\fBcustomMatch\fR allows flexible matching of actual and expected +results. +.TP +\fBnormalizePath \fIpathVar\fR +. +Resolves symlinks in a path, thus creating a path without internal +redirection. It is assumed that \fIpathVar\fR is absolute. +\fIpathVar\fR is modified in place. The Tcl command \fBfile normalize\fR +is a sufficient replacement. +.TP +\fBbytestring \fIstring\fR +. +Construct a string that consists of the requested sequence of bytes, +as opposed to a string of properly formed UTF-8 characters using the +value supplied in \fIstring\fR. This allows the tester to create +denormalized or improperly formed strings to pass to C procedures that +are supposed to accept strings with embedded NULL types and confirm +that a string result has a certain pattern of bytes. This is +exactly equivalent to the Tcl command \fBencoding convertfrom\fR +\fBidentity\fR. +.SH TESTS +.PP +The \fBtest\fR command is the heart of the \fBtcltest\fR package. +Its essential function is to evaluate a Tcl script and compare +the result with an expected result. The options of \fBtest\fR +define the test script, the environment in which to evaluate it, +the expected result, and how the compare the actual result to +the expected result. Some configuration options of \fBtcltest\fR +also influence how \fBtest\fR operates. +.PP +The valid options for \fBtest\fR are summarized: +.PP +.CS +\fBtest\fR \fIname\fR \fIdescription\fR + ?\fB\-constraints \fIkeywordList|expression\fR? + ?\fB\-setup \fIsetupScript\fR? + ?\fB\-body \fItestScript\fR? + ?\fB\-cleanup \fIcleanupScript\fR? + ?\fB\-result \fIexpectedAnswer\fR? + ?\fB\-output \fIexpectedOutput\fR? + ?\fB\-errorOutput \fIexpectedError\fR? + ?\fB\-returnCodes \fIcodeList\fR? + ?\fB\-match \fImode\fR? +.CE +.PP +The \fIname\fR may be any string. It is conventional to choose +a \fIname\fR according to the pattern: +.PP +.CS +\fItarget\fR-\fImajorNum\fR.\fIminorNum\fR +.CE +.PP +For white-box (regression) tests, the target should be the name of the +C function or Tcl procedure being tested. For black-box tests, the +target should be the name of the feature being tested. Some conventions +call for the names of black-box tests to have the suffix \fB_bb\fR. +Related tests should share a major number. As a test suite evolves, +it is best to have the same test name continue to correspond to the +same test, so that it remains meaningful to say things like +.QW "Test foo-1.3 passed in all releases up to 3.4, but began failing in release 3.5." +.PP +During evaluation of \fBtest\fR, the \fIname\fR will be compared +to the lists of string matching patterns returned by +\fBconfigure \-match\fR, and \fBconfigure \-skip\fR. The test +will be run only if \fIname\fR matches any of the patterns from +\fBconfigure \-match\fR and matches none of the patterns +from \fBconfigure \-skip\fR. +.PP +The \fIdescription\fR should be a short textual description of the +test. The \fIdescription\fR is included in output produced by the +test, typically test failure messages. Good \fIdescription\fR values +should briefly explain the purpose of the test to users of a test suite. +The name of a Tcl or C function being tested should be included in the +description for regression tests. If the test case exists to reproduce +a bug, include the bug ID in the description. +.PP +Valid attributes and associated values are: +.TP +\fB\-constraints \fIkeywordList\fR|\fIexpression\fR +. +The optional \fB\-constraints\fR attribute can be list of one or more +keywords or an expression. If the \fB\-constraints\fR value is a list of +keywords, each of these keywords should be the name of a constraint +defined by a call to \fBtestConstraint\fR. If any of the listed +constraints is false or does not exist, the test is skipped. If the +\fB\-constraints\fR value is an expression, that expression +is evaluated. If the expression evaluates to true, then the test is run. +Note that the expression form of \fB\-constraints\fR may interfere with the +operation of \fBconfigure \-constraints\fR and +\fBconfigure \-limitconstraints\fR, and is not recommended. +Appropriate constraints should be added to any tests that should +not always be run. That is, conditional evaluation of a test +should be accomplished by the \fB\-constraints\fR option, not by +conditional evaluation of \fBtest\fR. In that way, the same +number of tests are always reported by the test suite, though +the number skipped may change based on the testing environment. +The default value is an empty list. +See \fBTEST CONSTRAINTS\fR below for a list of built-in constraints +and information on how to add your own constraints. +.TP +\fB\-setup \fIscript\fR +. +The optional \fB\-setup\fR attribute indicates a \fIscript\fR that will be run +before the script indicated by the \fB\-body\fR attribute. If evaluation +of \fIscript\fR raises an error, the test will fail. The default value +is an empty script. +.TP +\fB\-body \fIscript\fR +. +The \fB\-body\fR attribute indicates the \fIscript\fR to run to carry out the +test, which must return a result that can be checked for correctness. +If evaluation of \fIscript\fR raises an error, the test will fail +(unless the \fB\-returnCodes\fR option is used to state that an error +is expected). +The default value is an empty script. +.TP +\fB\-cleanup \fIscript\fR +. +The optional \fB\-cleanup\fR attribute indicates a \fIscript\fR that will be +run after the script indicated by the \fB\-body\fR attribute. +If evaluation of \fIscript\fR raises an error, the test will fail. +The default value is an empty script. +.TP +\fB\-match \fImode\fR +. +The \fB\-match\fR attribute determines how expected answers supplied by +\fB\-result\fR, \fB\-output\fR, and \fB\-errorOutput\fR are compared. Valid +values for \fImode\fR are \fBregexp\fR, \fBglob\fR, \fBexact\fR, and +any value registered by a prior call to \fBcustomMatch\fR. The default +value is \fBexact\fR. +.TP +\fB\-result \fIexpectedValue\fR +. +The \fB\-result\fR attribute supplies the \fIexpectedValue\fR against which +the return value from script will be compared. The default value is +an empty string. +.TP +\fB\-output \fIexpectedValue\fR +. +The \fB\-output\fR attribute supplies the \fIexpectedValue\fR against which +any output sent to \fBstdout\fR or \fBoutputChannel\fR during evaluation +of the script(s) will be compared. Note that only output printed using +the global \fBputs\fR command is used for comparison. If \fB\-output\fR is +not specified, output sent to \fBstdout\fR and \fBoutputChannel\fR is not +processed for comparison. +.TP +\fB\-errorOutput \fIexpectedValue\fR +. +The \fB\-errorOutput\fR attribute supplies the \fIexpectedValue\fR against +which any output sent to \fBstderr\fR or \fBerrorChannel\fR during +evaluation of the script(s) will be compared. Note that only output +printed using the global \fBputs\fR command is used for comparison. If +\fB\-errorOutput\fR is not specified, output sent to \fBstderr\fR and +\fBerrorChannel\fR is not processed for comparison. +.TP +\fB\-returnCodes \fIexpectedCodeList\fR +. +The optional \fB\-returnCodes\fR attribute supplies \fIexpectedCodeList\fR, +a list of return codes that may be accepted from evaluation of the +\fB\-body\fR script. If evaluation of the \fB\-body\fR script returns +a code not in the \fIexpectedCodeList\fR, the test fails. All +return codes known to \fBreturn\fR, in both numeric and symbolic +form, including extended return codes, are acceptable elements in +the \fIexpectedCodeList\fR. Default value is +.QW "\fBok return\fR" . +.PP +To pass, a test must successfully evaluate its \fB\-setup\fR, \fB\-body\fR, +and \fB\-cleanup\fR scripts. The return code of the \fB\-body\fR script and +its result must match expected values, and if specified, output and error +data from the test must match expected \fB\-output\fR and \fB\-errorOutput\fR +values. If any of these conditions are not met, then the test fails. +Note that all scripts are evaluated in the context of the caller +of \fBtest\fR. +.PP +As long as \fBtest\fR is called with valid syntax and legal +values for all attributes, it will not raise an error. Test +failures are instead reported as output written to \fBoutputChannel\fR. +In default operation, a successful test produces no output. The output +messages produced by \fBtest\fR are controlled by the +\fBconfigure \-verbose\fR option as described in \fBCONFIGURABLE OPTIONS\fR +below. Any output produced by the test scripts themselves should be +produced using \fBputs\fR to \fBoutputChannel\fR or +\fBerrorChannel\fR, so that users of the test suite may +easily capture output with the \fBconfigure \-outfile\fR and +\fBconfigure \-errfile\fR options, and so that the \fB\-output\fR +and \fB\-errorOutput\fR attributes work properly. +.SS "TEST CONSTRAINTS" +.PP +Constraints are used to determine whether or not a test should be skipped. +Each constraint has a name, which may be any string, and a boolean +value. Each \fBtest\fR has a \fB\-constraints\fR value which is a +list of constraint names. There are two modes of constraint control. +Most frequently, the default mode is used, indicated by a setting +of \fBconfigure \-limitconstraints\fR to false. The test will run +only if all constraints in the list are true-valued. Thus, +the \fB\-constraints\fR option of \fBtest\fR is a convenient, symbolic +way to define any conditions required for the test to be possible or +meaningful. For example, a \fBtest\fR with \fB\-constraints unix\fR +will only be run if the constraint \fBunix\fR is true, which indicates +the test suite is being run on a Unix platform. +.PP +Each \fBtest\fR should include whatever \fB\-constraints\fR are +required to constrain it to run only where appropriate. Several +constraints are pre-defined in the \fBtcltest\fR package, listed +below. The registration of user-defined constraints is performed +by the \fBtestConstraint\fR command. User-defined constraints +may appear within a test file, or within the script specified +by the \fBconfigure \-load\fR or \fBconfigure \-loadfile\fR +options. +.PP +The following is a list of constraints pre-defined by the +\fBtcltest\fR package itself: +.TP +\fIsingleTestInterp\fR +. +This test can only be run if all test files are sourced into a single +interpreter. +.TP +\fIunix\fR +. +This test can only be run on any Unix platform. +.TP +\fIwin\fR +. +This test can only be run on any Windows platform. +.TP +\fInt\fR +. +This test can only be run on any Windows NT platform. +.TP +\fImac\fR +. +This test can only be run on any Mac platform. +.TP +\fIunixOrWin\fR +. +This test can only be run on a Unix or Windows platform. +.TP +\fImacOrWin\fR +. +This test can only be run on a Mac or Windows platform. +.TP +\fImacOrUnix\fR +. +This test can only be run on a Mac or Unix platform. +.TP +\fItempNotWin\fR +. +This test can not be run on Windows. This flag is used to temporarily +disable a test. +.TP +\fItempNotMac\fR +. +This test can not be run on a Mac. This flag is used +to temporarily disable a test. +.TP +\fIunixCrash\fR +. +This test crashes if it is run on Unix. This flag is used to temporarily +disable a test. +.TP +\fIwinCrash\fR +. +This test crashes if it is run on Windows. This flag is used to temporarily +disable a test. +.TP +\fImacCrash\fR +. +This test crashes if it is run on a Mac. This flag is used to temporarily +disable a test. +.TP +\fIemptyTest\fR +. +This test is empty, and so not worth running, but it remains as a +place-holder for a test to be written in the future. This constraint +has value false to cause tests to be skipped unless the user specifies +otherwise. +.TP +\fIknownBug\fR +. +This test is known to fail and the bug is not yet fixed. This constraint +has value false to cause tests to be skipped unless the user specifies +otherwise. +.TP +\fInonPortable\fR +. +This test can only be run in some known development environment. +Some tests are inherently non-portable because they depend on things +like word length, file system configuration, window manager, etc. +This constraint has value false to cause tests to be skipped unless +the user specifies otherwise. +.TP +\fIuserInteraction\fR +. +This test requires interaction from the user. This constraint has +value false to causes tests to be skipped unless the user specifies +otherwise. +.TP +\fIinteractive\fR +. +This test can only be run in if the interpreter is in interactive mode +(when the global tcl_interactive variable is set to 1). +.TP +\fInonBlockFiles\fR +. +This test can only be run if platform supports setting files into +nonblocking mode. +.TP +\fIasyncPipeClose\fR +. +This test can only be run if platform supports async flush and async close +on a pipe. +.TP +\fIunixExecs\fR +. +This test can only be run if this machine has Unix-style commands +\fBcat\fR, \fBecho\fR, \fBsh\fR, \fBwc\fR, \fBrm\fR, \fBsleep\fR, +\fBfgrep\fR, \fBps\fR, \fBchmod\fR, and \fBmkdir\fR available. +.TP +\fIhasIsoLocale\fR +. +This test can only be run if can switch to an ISO locale. +.TP +\fIroot\fR +. +This test can only run if Unix user is root. +.TP +\fInotRoot\fR +. +This test can only run if Unix user is not root. +.TP +\fIeformat\fR +. +This test can only run if app has a working version of sprintf with respect +to the +.QW e +format of floating-point numbers. +.TP +\fIstdio\fR +. +This test can only be run if \fBinterpreter\fR can be \fBopen\fRed +as a pipe. +.PP +The alternative mode of constraint control is enabled by setting +\fBconfigure \-limitconstraints\fR to true. With that configuration +setting, all existing constraints other than those in the constraint +list returned by \fBconfigure \-constraints\fR are set to false. +When the value of \fBconfigure \-constraints\fR +is set, all those constraints are set to true. The effect is that +when both options \fBconfigure \-constraints\fR and +\fBconfigure \-limitconstraints\fR are in use, only those tests including +only constraints from the \fBconfigure \-constraints\fR list +are run; all others are skipped. For example, one might set +up a configuration with +.PP +.CS +\fBconfigure\fR -constraints knownBug \e + -limitconstraints true \e + -verbose pass +.CE +.PP +to run exactly those tests that exercise known bugs, and discover +whether any of them pass, indicating the bug had been fixed. +.SS "RUNNING ALL TESTS" +.PP +The single command \fBrunAllTests\fR is evaluated to run an entire +test suite, spanning many files and directories. The configuration +options of \fBtcltest\fR control the precise operations. The +\fBrunAllTests\fR command begins by printing a summary of its +configuration to \fBoutputChannel\fR. +.PP +Test files to be evaluated are sought in the directory +\fBconfigure \-testdir\fR. The list of files in that directory +that match any of the patterns in \fBconfigure \-file\fR and +match none of the patterns in \fBconfigure \-notfile\fR is generated +and sorted. Then each file will be evaluated in turn. If +\fBconfigure \-singleproc\fR is true, then each file will +be \fBsource\fRd in the caller's context. If it is false, +then a copy of \fBinterpreter\fR will be \fBexec\fR'd to +evaluate each file. The multi-process operation is useful +when testing can cause errors so severe that a process +terminates. Although such an error may terminate a child +process evaluating one file, the master process can continue +with the rest of the test suite. In multi-process operation, +the configuration of \fBtcltest\fR in the master process is +passed to the child processes as command line arguments, +with the exception of \fBconfigure \-outfile\fR. The +\fBrunAllTests\fR command in the +master process collects all output from the child processes +and collates their results into one master report. Any +reports of individual test failures, or messages requested +by a \fBconfigure \-verbose\fR setting are passed directly +on to \fBoutputChannel\fR by the master process. +.PP +After evaluating all selected test files, a summary of the +results is printed to \fBoutputChannel\fR. The summary +includes the total number of \fBtest\fRs evaluated, broken +down into those skipped, those passed, and those failed. +The summary also notes the number of files evaluated, and the names +of any files with failing tests or errors. A list of +the constraints that caused tests to be skipped, and the +number of tests skipped for each is also printed. Also, +messages are printed if it appears that evaluation of +a test file has caused any temporary files to be left +behind in \fBconfigure \-tmpdir\fR. +.PP +Having completed and summarized all selected test files, +\fBrunAllTests\fR then recursively acts on subdirectories +of \fBconfigure \-testdir\fR. All subdirectories that +match any of the patterns in \fBconfigure \-relateddir\fR +and do not match any of the patterns in +\fBconfigure \-asidefromdir\fR are examined. If +a file named \fBall.tcl\fR is found in such a directory, +it will be \fBsource\fRd in the caller's context. +Whether or not an examined directory contains an +\fBall.tcl\fR file, its subdirectories are also scanned +against the \fBconfigure \-relateddir\fR and +\fBconfigure \-asidefromdir\fR patterns. In this way, +many directories in a directory tree can have all their +test files evaluated by a single \fBrunAllTests\fR +command. +.SH "CONFIGURABLE OPTIONS" +The \fBconfigure\fR command is used to set and query the configurable +options of \fBtcltest\fR. The valid options are: +.TP +\fB\-singleproc \fIboolean\fR +. +Controls whether or not \fBrunAllTests\fR spawns a child process for +each test file. No spawning when \fIboolean\fR is true. Default +value is false. +.TP +\fB\-debug \fIlevel\fR +. +Sets the debug level to \fIlevel\fR, an integer value indicating how +much debugging information should be printed to \fBstdout\fR. Note that +debug messages always go to \fBstdout\fR, independent of the value of +\fBconfigure \-outfile\fR. Default value is 0. Levels are defined as: +.RS +.IP 0 4 +Do not display any debug information. +.IP 1 +Display information regarding whether a test is skipped because it +does not match any of the tests that were specified using by +\fBconfigure \-match\fR (userSpecifiedNonMatch) or matches any of +the tests specified by \fBconfigure \-skip\fR (userSpecifiedSkip). Also +print warnings about possible lack of cleanup or balance in test files. +Also print warnings about any re-use of test names. +.IP 2 +Display the flag array parsed by the command line processor, the +contents of the global \fBenv\fR array, and all user-defined variables +that exist in the current namespace as they are used. +.IP 3 +Display information regarding what individual procs in the test +harness are doing. +.RE +.TP +\fB\-verbose \fIlevel\fR +. +Sets the type of output verbosity desired to \fIlevel\fR, +a list of zero or more of the elements \fBbody\fR, \fBpass\fR, +\fBskip\fR, \fBstart\fR, \fBerror\fR, \fBline\fR, \fBmsec\fR and \fBusec\fR. +Default value is +.QW "\fBbody error\fR" . +Levels are defined as: +.RS +.IP "body (\fBb\fR)" +Display the body of failed tests +.IP "pass (\fBp\fR)" +Print output when a test passes +.IP "skip (\fBs\fR)" +Print output when a test is skipped +.IP "start (\fBt\fR)" +Print output whenever a test starts +.IP "error (\fBe\fR)" +Print errorInfo and errorCode, if they exist, when a test return code +does not match its expected return code +.IP "line (\fBl\fR)" +Print source file line information of failed tests +.IP "msec (\fBm\fR)" +Print each test's execution time in milliseconds +.IP "usec (\fBu\fR)" +Print each test's execution time in microseconds +.PP +Note that the \fBmsec\fR and \fBusec\fR verbosity levels are provided as +indicative measures only. They do not tackle the problem of repeatibility which +should be considered in performance tests or benchmarks. To use these verbosity +levels to thoroughly track performance degradations, consider wrapping your +test bodies with \fBtime\fR commands. +.PP +The single letter abbreviations noted above are also recognized +so that +.QW "\fBconfigure \-verbose pt\fR" +is the same as +.QW "\fBconfigure \-verbose {pass start}\fR" . +.RE +.TP +\fB\-preservecore \fIlevel\fR +. +Sets the core preservation level to \fIlevel\fR. This level +determines how stringent checks for core files are. Default +value is 0. Levels are defined as: +.RS +.IP 0 +No checking \(em do not check for core files at the end of each test +command, but do check for them in \fBrunAllTests\fR after all +test files have been evaluated. +.IP 1 +Also check for core files at the end of each \fBtest\fR command. +.IP 2 +Check for core files at all times described above, and save a +copy of each core file produced in \fBconfigure \-tmpdir\fR. +.RE +.TP +\fB\-limitconstraints \fIboolean\fR +. +Sets the mode by which \fBtest\fR honors constraints as described +in \fBTESTS\fR above. Default value is false. +.TP +\fB\-constraints \fIlist\fR +. +Sets all the constraints in \fIlist\fR to true. Also used in +combination with \fBconfigure \-limitconstraints true\fR to control an +alternative constraint mode as described in \fBTESTS\fR above. +Default value is an empty list. +.TP +\fB\-tmpdir \fIdirectory\fR +. +Sets the temporary directory to be used by \fBmakeFile\fR, +\fBmakeDirectory\fR, \fBviewFile\fR, \fBremoveFile\fR, +and \fBremoveDirectory\fR as the default directory where +temporary files and directories created by test files should +be created. Default value is \fBworkingDirectory\fR. +.TP +\fB\-testdir \fIdirectory\fR +. +Sets the directory searched by \fBrunAllTests\fR for test files +and subdirectories. Default value is \fBworkingDirectory\fR. +.TP +\fB\-file \fIpatternList\fR +. +Sets the list of patterns used by \fBrunAllTests\fR to determine +what test files to evaluate. Default value is +.QW \fB*.test\fR . +.TP +\fB\-notfile \fIpatternList\fR +. +Sets the list of patterns used by \fBrunAllTests\fR to determine +what test files to skip. Default value is +.QW \fBl.*.test\fR , +so that any SCCS lock files are skipped. +.TP +\fB\-relateddir \fIpatternList\fR +. +Sets the list of patterns used by \fBrunAllTests\fR to determine +what subdirectories to search for an \fBall.tcl\fR file. Default +value is +.QW \fB*\fR . +.TP +\fB\-asidefromdir \fIpatternList\fR +. +Sets the list of patterns used by \fBrunAllTests\fR to determine +what subdirectories to skip when searching for an \fBall.tcl\fR file. +Default value is an empty list. +.TP +\fB\-match \fIpatternList\fR +. +Set the list of patterns used by \fBtest\fR to determine whether +a test should be run. Default value is +.QW \fB*\fR . +.TP +\fB\-skip \fIpatternList\fR +. +Set the list of patterns used by \fBtest\fR to determine whether +a test should be skipped. Default value is an empty list. +.TP +\fB\-load \fIscript\fR +. +Sets a script to be evaluated by \fBloadTestedCommands\fR. +Default value is an empty script. +.TP +\fB\-loadfile \fIfilename\fR +. +Sets the filename from which to read a script to be evaluated +by \fBloadTestedCommands\fR. This is an alternative to +\fB\-load\fR. They cannot be used together. +.TP +\fB\-outfile \fIfilename\fR +. +Sets the file to which all output produced by tcltest should be +written. A file named \fIfilename\fR will be \fBopen\fRed for writing, +and the resulting channel will be set as the value of \fBoutputChannel\fR. +.TP +\fB\-errfile \fIfilename\fR +. +Sets the file to which all error output produced by tcltest +should be written. A file named \fIfilename\fR will be \fBopen\fRed +for writing, and the resulting channel will be set as the value +of \fBerrorChannel\fR. +.SH "CREATING TEST SUITES WITH TCLTEST" +.PP +The fundamental element of a test suite is the individual \fBtest\fR +command. We begin with several examples. +.IP [1] +Test of a script that returns normally. +.RS +.PP +.CS +\fBtest\fR example-1.0 {normal return} { + format %s value +} value +.CE +.RE +.IP [2] +Test of a script that requires context setup and cleanup. Note the +bracing and indenting style that avoids any need for line continuation. +.RS +.PP +.CS +\fBtest\fR example-1.1 {test file existence} -setup { + set file [makeFile {} test] +} -body { + file exists $file +} -cleanup { + removeFile test +} -result 1 +.CE +.RE +.IP [3] +Test of a script that raises an error. +.RS +.PP +.CS +\fBtest\fR example-1.2 {error return} -body { + error message +} -returnCodes error -result message +.CE +.RE +.IP [4] +Test with a constraint. +.RS +.PP +.CS +\fBtest\fR example-1.3 {user owns created files} -constraints { + unix +} -setup { + set file [makeFile {} test] +} -body { + file attributes $file -owner +} -cleanup { + removeFile test +} -result $::tcl_platform(user) +.CE +.RE +.PP +At the next higher layer of organization, several \fBtest\fR commands +are gathered together into a single test file. Test files should have +names with the +.QW \fB.test\fR +extension, because that is the default pattern +used by \fBrunAllTests\fR to find test files. It is a good rule of +thumb to have one test file for each source code file of your project. +It is good practice to edit the test file and the source code file +together, keeping tests synchronized with code changes. +.PP +Most of the code in the test file should be the \fBtest\fR commands. +Use constraints to skip tests, rather than conditional evaluation +of \fBtest\fR. +.IP [5] +Recommended system for writing conditional tests, using constraints to +guard: +.RS +.PP +.CS +\fBtestConstraint\fR X [expr $myRequirement] +\fBtest\fR goodConditionalTest {} X { + # body +} result +.CE +.RE +.IP [6] +Discouraged system for writing conditional tests, using \fBif\fR to +guard: +.RS +.PP +.CS +if $myRequirement { + \fBtest\fR badConditionalTest {} { + #body + } result +} +.CE +.RE +.PP +Use the \fB\-setup\fR and \fB\-cleanup\fR options to establish and release +all context requirements of the test body. Do not make tests depend on +prior tests in the file. Those prior tests might be skipped. If several +consecutive tests require the same context, the appropriate setup +and cleanup scripts may be stored in variable for passing to each tests +\fB\-setup\fR and \fB\-cleanup\fR options. This is a better solution than +performing setup outside of \fBtest\fR commands, because the setup will +only be done if necessary, and any errors during setup will be reported, +and not cause the test file to abort. +.PP +A test file should be able to be combined with other test files and not +interfere with them, even when \fBconfigure \-singleproc 1\fR causes +all files to be evaluated in a common interpreter. A simple way to +achieve this is to have your tests define all their commands and variables +in a namespace that is deleted when the test file evaluation is complete. +A good namespace to use is a child namespace \fBtest\fR of the namespace +of the module you are testing. +.PP +A test file should also be able to be evaluated directly as a script, +not depending on being called by a master \fBrunAllTests\fR. This +means that each test file should process command line arguments to give +the tester all the configuration control that \fBtcltest\fR provides. +.PP +After all \fBtest\fRs in a test file, the command \fBcleanupTests\fR +should be called. +.IP [7] +Here is a sketch of a sample test file illustrating those points: +.RS +.PP +.CS +package require tcltest 2.2 +eval \fB::tcltest::configure\fR $argv +package require example +namespace eval ::example::test { + namespace import ::tcltest::* + \fBtestConstraint\fR X [expr {...}] + variable SETUP {#common setup code} + variable CLEANUP {#common cleanup code} + \fBtest\fR example-1 {} -setup $SETUP -body { + # First test + } -cleanup $CLEANUP -result {...} + \fBtest\fR example-2 {} -constraints X -setup $SETUP -body { + # Second test; constrained + } -cleanup $CLEANUP -result {...} + \fBtest\fR example-3 {} { + # Third test; no context required + } {...} + \fBcleanupTests\fR +} +namespace delete ::example::test +.CE +.RE +.PP +The next level of organization is a full test suite, made up of several +test files. One script is used to control the entire suite. The +basic function of this script is to call \fBrunAllTests\fR after +doing any necessary setup. This script is usually named \fBall.tcl\fR +because that is the default name used by \fBrunAllTests\fR when combining +multiple test suites into one testing run. +.IP [8] +Here is a sketch of a sample test suite master script: +.RS +.PP +.CS +package require Tcl 8.4 +package require tcltest 2.2 +package require example +\fB::tcltest::configure\fR -testdir \e + [file dirname [file normalize [info script]]] +eval \fB::tcltest::configure\fR $argv +\fB::tcltest::runAllTests\fR +.CE +.RE +.SH COMPATIBILITY +.PP +A number of commands and variables in the \fB::tcltest\fR namespace +provided by earlier releases of \fBtcltest\fR have not been documented +here. They are no longer part of the supported public interface of +\fBtcltest\fR and should not be used in new test suites. However, +to continue to support existing test suites written to the older +interface specifications, many of those deprecated commands and +variables still work as before. For example, in many circumstances, +\fBconfigure\fR will be automatically called shortly after +\fBpackage require\fR \fBtcltest 2.1\fR succeeds with arguments +from the variable \fB::argv\fR. This is to support test suites +that depend on the old behavior that \fBtcltest\fR was automatically +configured from command line arguments. New test files should not +depend on this, but should explicitly include +.PP +.CS +eval \fB::tcltest::configure\fR $::argv +.CE +.PP +or +.PP +.CS +\fB::tcltest::configure\fR {*}$::argv +.CE +.PP +to establish a configuration from command line arguments. +.SH "KNOWN ISSUES" +There are two known issues related to nested evaluations of \fBtest\fR. +The first issue relates to the stack level in which test scripts are +executed. Tests nested within other tests may be executed at the same +stack level as the outermost test. For example, in the following code: +.PP +.CS +\fBtest\fR level-1.1 {level 1} { + -body { + \fBtest\fR level-2.1 {level 2} { + } + } +} +.CE +.PP +any script executed in level-2.1 may be executed at the same stack +level as the script defined for level-1.1. +.PP +In addition, while two \fBtest\fRs have been run, results will only +be reported by \fBcleanupTests\fR for tests at the same level as +test level-1.1. However, test results for all tests run prior to +level-1.1 will be available when test level-2.1 runs. What this +means is that if you try to access the test results for test level-2.1, +it will may say that +.QW m +tests have run, +.QW n +tests have been skipped, +.QW o +tests have passed and +.QW p +tests have failed, where +.QW m , +.QW n , +.QW o , +and +.QW p +refer to tests that were run at the same test level as test level-1.1. +.PP +Implementation of output and error comparison in the test command +depends on usage of \fBputs\fR in your application code. Output is +intercepted by redefining the global \fBputs\fR command while the defined test +script is being run. Errors thrown by C procedures or printed +directly from C applications will not be caught by the \fBtest\fR command. +Therefore, usage of the \fB\-output\fR and \fB\-errorOutput\fR +options to \fBtest\fR is useful only for pure Tcl applications +that use \fBputs\fR to produce output. +.SH KEYWORDS +test, test harness, test suite +.\" Local Variables: +.\" mode: nroff +.\" End: diff --git a/tcl8.6/doc/tclvars.n b/tcl8.6/doc/tclvars.n new file mode 100644 index 0000000..adefe40 --- /dev/null +++ b/tcl8.6/doc/tclvars.n @@ -0,0 +1,566 @@ +'\" +'\" Copyright (c) 1993 The Regents of the University of California. +'\" Copyright (c) 1994-1997 Sun Microsystems, Inc. +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH tclvars n 8.0 Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +argc, argv, argv0, auto_path, env, errorCode, errorInfo, tcl_interactive, tcl_library, tcl_nonwordchars, tcl_patchLevel, tcl_pkgPath, tcl_platform, tcl_precision, tcl_rcFileName, tcl_traceCompile, tcl_traceExec, tcl_wordchars, tcl_version \- Variables used by Tcl +.BE +.SH DESCRIPTION +.PP +The following global variables are created and managed automatically +by the Tcl library. Except where noted below, these variables should +normally be treated as read-only by application-specific code and by users. +.TP +\fBauto_path\fR +. +If set, then it must contain a valid Tcl list giving directories to +search during auto-load operations (including for package index +files when using the default \fBpackage unknown\fR handler). +This variable is initialized during startup to contain, in order: +the directories listed in the \fBTCLLIBPATH\fR environment variable, +the directory named by the \fBtcl_library\fR global variable, +the parent directory of \fBtcl_library\fR, +the directories listed in the \fBtcl_pkgPath\fR variable. +Additional locations to look for files and package indices should +normally be added to this variable using \fBlappend\fR. +.RS +.PP +Additional variables relating to package management exist. More +details are listed in the \fBVARIABLES\fR section of the \fBlibrary\fR +manual page. +.RE +.TP +\fBenv\fR +. +This variable is maintained by Tcl as an array +whose elements are the environment variables for the process. +Reading an element will return the value of the corresponding +environment variable. +Setting an element of the array will modify the corresponding +environment variable or create a new one if it does not already +exist. +Unsetting an element of \fBenv\fR will remove the corresponding +environment variable. +Changes to the \fBenv\fR array will affect the environment +passed to children by commands like \fBexec\fR. +If the entire \fBenv\fR array is unset then Tcl will stop +monitoring \fBenv\fR accesses and will not update environment +variables. +.RS +.PP +Under Windows, the environment variables PATH and COMSPEC in any +capitalization are converted automatically to upper case. For instance, the +PATH variable could be exported by the operating system as +.QW path , +.QW Path , +.QW PaTh , +etc., causing otherwise simple Tcl code to have to +support many special cases. All other environment variables inherited by +Tcl are left unmodified. Setting an env array variable to blank is the +same as unsetting it as this is the behavior of the underlying Windows OS. +It should be noted that relying on an existing and empty environment variable +will not work on Windows and is discouraged for cross-platform usage. +.PP +The following elements of \fBenv\fR are special to Tcl: +.TP +\fBenv(HOME)\fR +. +This environment variable, if set, gives the location of the directory +considered to be the current user's home directory, and to which a +call of \fBcd\fR without arguments or with just +.QW ~ +as an argument will change into. Most platforms set this correctly by +default; it does not normally need to be set by user code. +.TP +\fBenv(TCL_LIBRARY)\fR +. +If set, then it specifies the location of the directory containing +library scripts (the value of this variable will be +assigned to the \fBtcl_library\fR variable and therefore returned by +the command \fBinfo library\fR). If this variable is not set then +a default value is used. +.RS +.PP +Note that this environment variable should \fInot\fR normally be set. +.RE +.TP +\fBenv(TCLLIBPATH)\fR +. +If set, then it must contain a valid Tcl list giving directories to +search during auto-load operations. Directories must be specified in +Tcl format, using +.QW / +as the path separator, regardless of platform. +This variable is only used when initializing the \fBauto_path\fR variable. +.TP +\fBenv(TCL_TZ)\fR, \fBenv(TZ)\fR +. +These specify the default timezone used for parsing and formatting times and +dates in the \fBclock\fR command. On many platforms, the TZ environment +variable is set up by the operating system. +.TP +\fBenv(LC_ALL)\fR, \fBenv(LC_MESSAGES)\fR, \fBenv(LANG)\fR +. +These environment variables are used by the \fBmsgcat\fR package to +determine what locale to format messages using. +.TP +\fBenv(TCL_INTERP_DEBUG_FRAME)\fR +. +If existing, it has the same effect as running \fBinterp debug\fR +\fB{} -frame 1\fR +as the very first command of each new Tcl interpreter. +.RE +.TP +\fBerrorCode\fR +. +This variable holds the value of the \fB\-errorcode\fR return option +set by the most recent error that occurred in this interpreter. +This list value represents additional information about the error +in a form that is easy to process with programs. +The first element of the list identifies a general class of +errors, and determines the format of the rest of the list. +The following formats for \fB\-errorcode\fR return options +are used by the Tcl core; individual applications may define +additional formats. +.RS +.TP +\fBARITH\fI code msg\fR +. +This format is used when an arithmetic error occurs (e.g. an attempt +to divide zero by zero in the \fBexpr\fR command). +\fICode\fR identifies the precise error and \fImsg\fR provides a +human-readable description of the error. \fICode\fR will be either +DIVZERO (for an attempt to divide by zero), +DOMAIN (if an argument is outside the domain of a function, such as acos(\-3)), +IOVERFLOW (for integer overflow), +OVERFLOW (for a floating-point overflow), +or UNKNOWN (if the cause of the error cannot be determined). +.RS +.PP +Detection of these errors depends in part on the underlying hardware +and system libraries. +.RE +.TP +\fBCHILDKILLED\fI pid sigName msg\fR +. +This format is used when a child process has been killed because of +a signal. The \fIpid\fR element will be the process's identifier (in decimal). +The \fIsigName\fR element will be the symbolic name of the signal that caused +the process to terminate; it will be one of the names from the +include file signal.h, such as \fBSIGPIPE\fR. +The \fImsg\fR element will be a short human-readable message +describing the signal, such as +.QW "write on pipe with no readers" +for \fBSIGPIPE\fR. +.TP +\fBCHILDSTATUS\fI pid code\fR +. +This format is used when a child process has exited with a non-zero +exit status. The \fIpid\fR element will be the +process's identifier (in decimal) and the \fIcode\fR element will be the exit +code returned by the process (also in decimal). +.TP +\fBCHILDSUSP\fI pid sigName msg\fR +. +This format is used when a child process has been suspended because +of a signal. +The \fIpid\fR element will be the process's identifier, in decimal. +The \fIsigName\fR element will be the symbolic name of the signal that caused +the process to suspend; this will be one of the names from the +include file signal.h, such as \fBSIGTTIN\fR. +The \fImsg\fR element will be a short human-readable message +describing the signal, such as +.QW "background tty read" +for \fBSIGTTIN\fR. +.TP +\fBNONE\fR +. +This format is used for errors where no additional information is +available for an error besides the message returned with the +error. In these cases the \fB\-errorcode\fR return option +will consist of a list containing a single element whose +contents are \fBNONE\fR. +.TP +\fBPOSIX \fIerrName msg\fR +. +If the first element is \fBPOSIX\fR, then +the error occurred during a POSIX kernel call. +The \fIerrName\fR element will contain the symbolic name +of the error that occurred, such as \fBENOENT\fR; this will +be one of the values defined in the include file errno.h. +The \fImsg\fR element will be a human-readable +message corresponding to \fIerrName\fR, such as +.QW "no such file or directory" +for the \fBENOENT\fR case. +.TP +\fBTCL\fR ... +. +Indicates some sort of problem generated in relation to Tcl itself, e.g. a +failure to look up a channel or variable. +.PP +To set the \fB\-errorcode\fR return option, applications should use library +procedures such as \fBTcl_SetObjErrorCode\fR, \fBTcl_SetReturnOptions\fR, +and \fBTcl_PosixError\fR, or they may invoke the \fB\-errorcode\fR +option of the \fBreturn\fR command. +If none of these methods for setting the error code has been used, +the Tcl interpreter will reset the variable to \fBNONE\fR after +the next error. +.RE +.TP +\fBerrorInfo\fR +. +This variable holds the value of the \fB\-errorinfo\fR return option +set by the most recent error that occurred in this interpreter. +This string value will contain one or more lines +identifying the Tcl commands and procedures that were being executed +when the most recent error occurred. +Its contents take the form of a stack trace showing the various +nested Tcl commands that had been invoked at the time of the error. +.TP +\fBtcl_library\fR +. +This variable holds the name of a directory containing the +system library of Tcl scripts, such as those used for auto-loading. +The value of this variable is returned by the \fBinfo library\fR command. +See the \fBlibrary\fR manual entry for details of the facilities +provided by the Tcl script library. +Normally each application or package will have its own application-specific +script library in addition to the Tcl script library; +each application should set a global variable with a name like +\fB$\fIapp\fB_library\fR (where \fIapp\fR is the application's name) +to hold the network file name for that application's library directory. +The initial value of \fBtcl_library\fR is set when an interpreter +is created by searching several different directories until one is +found that contains an appropriate Tcl startup script. +If the \fBTCL_LIBRARY\fR environment variable exists, then +the directory it names is checked first. +If \fBTCL_LIBRARY\fR is not set or doesn't refer to an appropriate +directory, then Tcl checks several other directories based on a +compiled-in default location, the location of the binary containing +the application, and the current working directory. +.TP +\fBtcl_patchLevel\fR +. +When an interpreter is created Tcl initializes this variable to +hold a string giving the current patch level for Tcl, such as +\fB8.4.16\fR for Tcl 8.4 with the first sixteen official patches, or +\fB8.5b3\fR for the third beta release of Tcl 8.5. +The value of this variable is returned by the \fBinfo patchlevel\fR +command. +.TP +\fBtcl_pkgPath\fR +. +This variable holds a list of directories indicating where packages are +normally installed. It is not used on Windows. It typically contains +either one or two entries; if it contains two entries, the first is +normally a directory for platform-dependent packages (e.g., shared library +binaries) and the second is normally a directory for platform-independent +packages (e.g., script files). Typically a package is installed as a +subdirectory of one of the entries in the \fBtcl_pkgPath\fR +variable. The directories in the \fBtcl_pkgPath\fR variable are +included by default in the \fBauto_path\fR +variable, so they and their immediate subdirectories are automatically +searched for packages during \fBpackage require\fR commands. Note: +\fBtcl_pkgPath\fR is not intended to be modified by the application. Its +value is added to \fBauto_path\fR at startup; changes to \fBtcl_pkgPath\fR +are not reflected in \fBauto_path\fR. If you want Tcl to search additional +directories for packages you should add the names of those directories to +\fBauto_path\fR, not \fBtcl_pkgPath\fR. +.TP +\fBtcl_platform\fR +. +This is an associative array whose elements contain information about +the platform on which the application is running, such as the name of +the operating system, its current release number, and the machine's +instruction set. The elements listed below will always +be defined, but they may have empty strings as values if Tcl could not +retrieve any relevant information. In addition, extensions +and applications may add additional values to the array. The +predefined elements are: +.RS +.TP +\fBbyteOrder\fR +. +The native byte order of this machine: either \fBlittleEndian\fR or +\fBbigEndian\fR. +.TP +\fBdebug\fR +. +If this variable exists, then the interpreter was compiled with and linked +to a debug-enabled C run-time. This variable will only exist on Windows, +so extension writers can specify which package to load depending on the +C run-time library that is in use. This is not an indication that this core +contains symbols. +.TP +\fBengine\fR +. +The name of the Tcl language implementation. When the interpreter is first +created, this is always set to the string \fBTcl\fR. +.TP +\fBmachine\fR +. +The instruction set executed by this machine, such as +\fBintel\fR, \fBPPC\fR, \fB68k\fR, or \fBsun4m\fR. On UNIX machines, this +is the value returned by \fBuname -m\fR. +.TP +\fBos\fR +. +The name of the operating system running on this machine, +such as \fBWindows NT\fR or \fBSunOS\fR. +On UNIX machines, this is the value returned by \fBuname -s\fR. +.TP +\fBosVersion\fR +. +The version number for the operating system running on this machine. +On UNIX machines, this is the value returned by \fBuname -r\fR. +.TP +\fBpathSeparator\fR +.VS 8.6 +'\" Defined by TIP #315 +The character that should be used to \fBsplit\fR PATH-like environment +variables into their corresponding list of directory names. +.VE 8.6 +.TP +\fBplatform\fR +. +Either \fBwindows\fR, or \fBunix\fR. This identifies the +general operating environment of the machine. +.TP +\fBpointerSize\fR +. +This gives the size of the native-machine pointer in bytes (strictly, it +is same as the result of evaluating \fIsizeof(void*)\fR in C.) +.TP +\fBthreaded\fR +. +If this variable exists, then the interpreter +was compiled with threads enabled. +.TP +\fBuser\fR +. +This identifies the +current user based on the login information available on the platform. +This value comes from the getuid() and getpwuid() system calls on Unix, +and the value from the GetUserName() system call on Windows. +.TP +\fBwordSize\fR +. +This gives the size of the native-machine word in bytes (strictly, it +is same as the result of evaluating \fIsizeof(long)\fR in C.) +.RE +.TP +\fBtcl_precision\fR +. +This variable controls the number of digits to generate +when converting floating-point values to strings. It defaults +to 0. \fIApplications should not change this value;\fR it is +provided for compatibility with legacy code. +.PP +.RS +The default value of 0 is special, meaning that Tcl should +convert numbers using as few digits as possible while still +distinguishing any floating point number from its nearest +neighbours. It differs from using an arbitrarily high value +for \fItcl_precision\fR in that an inexact number like \fI1.4\fR +will convert as \fI1.4\fR rather than \fI1.3999999999999999\fR +even though the latter is nearer to the exact value of the +binary number. +.RE +.PP +.RS +If \fBtcl_precision\fR is not zero, then when Tcl converts a floating +point number, it creates a decimal representation of at most +\fBtcl_precision\fR significant digits; the result may be shorter if +the shorter result represents the original number exactly. If no +result of at most \fBtcl_precision\fR digits is an exact representation +of the original number, the one that is closest to the original +number is chosen. +If the original number lies precisely between two equally accurate +decimal representations, then the one with an even value for the least +significant digit is chosen; for instance, if \fBtcl_precision\fR is 3, then +0.3125 will convert to 0.312, not 0.313, while 0.6875 will convert to +0.688, not 0.687. Any string of trailing zeroes that remains is trimmed. +.RE +.PP +.RS +a \fBtcl_precision\fR value of 17 digits is +.QW perfect +for IEEE floating-point in that it allows +double-precision values to be converted to strings and back to +binary with no loss of information. For this reason, you will often +see it as a value in legacy code that must run on Tcl versions before +8.5. It is no longer recommended; as noted above, a zero value is the +preferred method. +.RE +.PP +.RS +All interpreters in a thread share a single \fBtcl_precision\fR value: +changing it in one interpreter will affect all other interpreters as +well. Safe interpreters are not allowed to modify the +variable. +.RE +.PP +.RS +Valid values for \fBtcl_precision\fR range from 0 to 17. +.RE +.TP +\fBtcl_rcFileName\fR +. +This variable is used during initialization to indicate the name of a +user-specific startup file. If it is set by application-specific +initialization, then the Tcl startup code will check for the existence +of this file and \fBsource\fR it if it exists. For example, for \fBwish\fR +the variable is set to \fB~/.wishrc\fR for Unix and \fB~/wishrc.tcl\fR +for Windows. +.TP +\fBtcl_traceCompile\fR +. +The value of this variable can be set to control +how much tracing information +is displayed during bytecode compilation. +By default, \fBtcl_traceCompile\fR is zero and no information is displayed. +Setting \fBtcl_traceCompile\fR to 1 generates a one-line summary in \fBstdout\fR +whenever a procedure or top-level command is compiled. +Setting it to 2 generates a detailed listing in \fBstdout\fR of the +bytecode instructions emitted during every compilation. +This variable is useful in +tracking down suspected problems with the Tcl compiler. +.PP +.RS +This variable and functionality only exist if +\fBTCL_COMPILE_DEBUG\fR was defined during Tcl's compilation. +.RE +.TP +\fBtcl_traceExec\fR +. +The value of this variable can be set to control +how much tracing information +is displayed during bytecode execution. +By default, \fBtcl_traceExec\fR is zero and no information is displayed. +Setting \fBtcl_traceExec\fR to 1 generates a one-line trace in \fBstdout\fR +on each call to a Tcl procedure. +Setting it to 2 generates a line of output +whenever any Tcl command is invoked +that contains the name of the command and its arguments. +Setting it to 3 produces a detailed trace showing the result of +executing each bytecode instruction. +Note that when \fBtcl_traceExec\fR is 2 or 3, +commands such as \fBset\fR and \fBincr\fR +that have been entirely replaced by a sequence +of bytecode instructions are not shown. +Setting this variable is useful in +tracking down suspected problems with the bytecode compiler +and interpreter. +.PP +.RS +This variable and functionality only exist if +\fBTCL_COMPILE_DEBUG\fR was defined during Tcl's compilation. +.RE +.TP +\fBtcl_wordchars\fR +. +The value of this variable is a regular expression that can be set to +control what are considered +.QW word +characters, for instances like +selecting a word by double-clicking in text in Tk. It is platform +dependent. On Windows, it defaults to \fB\eS\fR, meaning anything +but a Unicode space character. Otherwise it defaults to \fB\ew\fR, +which is any Unicode word character (number, letter, or underscore). +.TP +\fBtcl_nonwordchars\fR +. +The value of this variable is a regular expression that can be set to +control what are considered +.QW non-word +characters, for instances like +selecting a word by double-clicking in text in Tk. It is platform +dependent. On Windows, it defaults to \fB\es\fR, meaning any Unicode space +character. Otherwise it defaults to \fB\eW\fR, which is anything but a +Unicode word character (number, letter, or underscore). +.TP +\fBtcl_version\fR +. +When an interpreter is created Tcl initializes this variable to +hold the version number for this version of Tcl in the form \fIx.y\fR. +Changes to \fIx\fR represent major changes with probable +incompatibilities and changes to \fIy\fR represent small enhancements and +bug fixes that retain backward compatibility. +The value of this variable is returned by the \fBinfo tclversion\fR +command. +.SH "OTHER GLOBAL VARIABLES" +.PP +The following variables are only guaranteed to exist in \fBtclsh\fR +and \fBwish\fR executables; the Tcl library does not define them +itself but many Tcl environments do. +.TP 6 +\fBargc\fR +. +The number of arguments to \fBtclsh\fR or \fBwish\fR. +.TP 6 +\fBargv\fR +. +Tcl list of arguments to \fBtclsh\fR or \fBwish\fR. +.TP 6 +\fBargv0\fR +. +The script that \fBtclsh\fR or \fBwish\fR started executing (if it was +specified) or otherwise the name by which \fBtclsh\fR or \fBwish\fR +was invoked. +.TP 6 +\fBtcl_interactive\fR +. +Contains 1 if \fBtclsh\fR or \fBwish\fR is running interactively (no +script was specified and standard input is a terminal-like device), 0 +otherwise. +.SH EXAMPLES +.PP +To add a directory to the collection of locations searched by +\fBpackage require\fR, e.g., because of some application-specific +packages that are used, the \fBauto_path\fR variable needs to be +updated: +.PP +.CS +lappend ::\fBauto_path\fR [file join [pwd] "theLibDir"] +.CE +.PP +A simple though not very robust way to handle command line arguments +of the form +.QW "\-foo 1 \-bar 2" +is to load them into an array having first loaded in the default settings: +.CS +array set arguments {-foo 0 -bar 0 -grill 0} +array set arguments $::\fBargv\fR +puts "foo is $arguments(-foo)" +puts "bar is $arguments(-bar)" +puts "grill is $arguments(-grill)" +.CE +.PP +The \fBargv0\fR global variable can be used (in conjunction with the +\fBinfo script\fR command) to determine whether the current script is +being executed as the main script or loaded as a library. This is +useful because it allows a single script to be used as both a library +and a demonstration of that library: +.PP +.CS +if {$::\fBargv0\fR eq [info script]} { + # running as: tclsh example.tcl +} else { + package provide Example 1.0 +} +.CE +.SH "SEE ALSO" +eval(n), library(n), tclsh(1), tkvars(n), wish(1) +.SH KEYWORDS +arithmetic, bytecode, compiler, error, environment, POSIX, precision, +subprocess, user, variables +'\" Local Variables: +'\" mode: nroff +'\" End: diff --git a/tcl8.6/doc/tell.n b/tcl8.6/doc/tell.n new file mode 100644 index 0000000..e8bf3af --- /dev/null +++ b/tcl8.6/doc/tell.n @@ -0,0 +1,48 @@ +'\" +'\" Copyright (c) 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. +'\" +.TH tell n 8.1 Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +tell \- Return current access position for an open channel +.SH SYNOPSIS +\fBtell \fIchannelId\fR +.BE +.SH DESCRIPTION +.PP +Returns an integer string giving the current access position in +\fIchannelId\fR. This value returned is a byte offset that can be passed to +\fBseek\fR in order to set the channel to a particular position. Note +that this value is in terms of bytes, not characters like \fBread\fR. +The value returned is -1 for channels that do not support +seeking. +.PP +\fIChannelId\fR must be an identifier for an open channel such as a +Tcl standard channel (\fBstdin\fR, \fBstdout\fR, or \fBstderr\fR), +the return value from an invocation of \fBopen\fR or \fBsocket\fR, or +the result of a channel creation command provided by a Tcl extension. +.SH EXAMPLE +.PP +Read a line from a file channel only if it starts with \fBfoobar\fR: +.PP +.CS +# Save the offset in case we need to undo the read... +set offset [\fBtell\fR $chan] +if {[read $chan 6] eq "foobar"} { + gets $chan line +} else { + set line {} + # Undo the read... + seek $chan $offset +} +.CE +.SH "SEE ALSO" +file(n), open(n), close(n), gets(n), seek(n), Tcl_StandardChannels(3) +.SH KEYWORDS +access position, channel, seeking diff --git a/tcl8.6/doc/throw.n b/tcl8.6/doc/throw.n new file mode 100644 index 0000000..0d1df78 --- /dev/null +++ b/tcl8.6/doc/throw.n @@ -0,0 +1,48 @@ +'\" +'\" Copyright (c) 2008 Donal K. Fellows +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH throw n 8.6 Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +throw \- Generate a machine-readable error +.SH SYNOPSIS +\fBthrow\fI type message\fR +.BE +.SH DESCRIPTION +.PP +This command causes the current evaluation to be unwound with an error. The +error created is described by the \fItype\fR and \fImessage\fR arguments: +\fItype\fR must contain a list of words describing the error in a form that is +machine-readable (and which will form the error-code part of the result +dictionary), and \fImessage\fR should contain text that is intended for +display to a human being. +.PP +The stack will be unwound until the error is trapped by a suitable \fBcatch\fR +or \fBtry\fR command. If it reaches the event loop without being trapped, it +will be reported through the \fBbgerror\fR mechanism. If it reaches the top +level of script evaluation in \fBtclsh\fR, it will be printed on the console +before, in the non-interactive case, causing an exit (the behavior in other +programs will depend on the details of how Tcl is embedded and used). +.PP +By convention, the words in the \fItype\fR argument should go from most +general to most specific. +.SH EXAMPLES +.PP +The following produces an error that is identical to that produced by +\fBexpr\fR when trying to divide a value by zero. +.PP +.CS +\fBthrow\fR {ARITH DIVZERO {divide by zero}} {divide by zero} +.CE +.SH "SEE ALSO" +catch(n), error(n), errorCode(n), errorInfo(n), return(n), try(n) +.SH "KEYWORDS" +error, exception +'\" Local Variables: +'\" mode: nroff +'\" End: diff --git a/tcl8.6/doc/time.n b/tcl8.6/doc/time.n new file mode 100644 index 0000000..35b41c4 --- /dev/null +++ b/tcl8.6/doc/time.n @@ -0,0 +1,47 @@ +'\" +'\" Copyright (c) 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. +'\" +.TH time n "" Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +time \- Time the execution of a script +.SH SYNOPSIS +\fBtime \fIscript\fR ?\fIcount\fR? +.BE +.SH DESCRIPTION +.PP +This command will call the Tcl interpreter \fIcount\fR +times to evaluate \fIscript\fR (or once if \fIcount\fR is not +specified). It will then return a string of the form +.PP +.CS +\fB503.2 microseconds per iteration\fR +.CE +.PP +which indicates the average amount of time required per iteration, +in microseconds. +Time is measured in elapsed time, not CPU time. +.SH EXAMPLE +Estimate how long it takes for a simple Tcl \fBfor\fR loop to count to +a thousand: +.PP +.CS +time { + for {set i 0} {$i<1000} {incr i} { + # empty body + } +} +.CE +.SH "SEE ALSO" +clock(n) +.SH KEYWORDS +script, time +.\" Local Variables: +.\" mode: nroff +.\" End: diff --git a/tcl8.6/doc/tm.n b/tcl8.6/doc/tm.n new file mode 100644 index 0000000..5602686 --- /dev/null +++ b/tcl8.6/doc/tm.n @@ -0,0 +1,308 @@ +'\" +'\" Copyright (c) 2004-2010 Andreas Kupries <andreas_kupries@users.sourceforge.net> +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH tm n 8.5 Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +tm \- Facilities for locating and loading of Tcl Modules +.SH SYNOPSIS +.nf +\fB::tcl::tm::path add \fR?\fIpath\fR...? +\fB::tcl::tm::path remove \fR?\fIpath\fR...? +\fB::tcl::tm::path list\fR +\fB::tcl::tm::roots \fR?\fIpath\fR...? +.fi +.BE +.SH DESCRIPTION +.PP +This document describes the facilities for locating and loading Tcl +Modules (see \fBMODULE DEFINITION\fR for the definition of a Tcl Module). +The following commands are supported: +.TP +\fB::tcl::tm::path add \fR?\fIpath\fR...? +. +The paths are added at the head to the list of module paths, in order +of appearance. This means that the last argument ends up as the new +head of the list. +.RS +.PP +The command enforces the restriction that no path may be an ancestor +directory of any other path on the list. If any of the new paths +violates this restriction an error will be raised, before any of the +paths have been added. In other words, if only one path argument +violates the restriction then none will be added. +.PP +If a path is already present as is, no error will be raised and no +action will be taken. +.PP +Paths are searched later in the order of their appearance in the +list. As they are added to the front of the list they are searched in +reverse order of addition. In other words, the paths added last are +looked at first. +.RE +.TP +\fB::tcl::tm::path remove \fR?\fIpath\fR...? +. +Removes the paths from the list of module paths. The command silently +ignores all paths which are not on the list. +.TP +\fB::tcl::tm::path list\fR +. +Returns a list containing all registered module paths, in the order +that they are searched for modules. +.TP +\fB::tcl::tm::roots \fR?\fIpath\fR...? +. +Similar to \fBpath add\fR, and layered on top of it. This command +takes a list of paths, extends each with +.QW "\fBtcl\fIX\fB/site-tcl\fR" , +and +.QW "\fBtcl\fIX\fB/\fIX\fB.\fIy\fR" , +for major version \fIX\fR of the +Tcl interpreter and minor version \fIy\fR less than or equal to the +minor version of the interpreter, and adds the resulting set of paths +to the list of paths to search. +.RS +.PP +This command is used internally by the system to set up the +system-specific default paths. +.PP +The command has been exposed to allow a build system to define +additional root paths beyond those described by this document. +.RE +.SH "MODULE DEFINITION" +.PP +A Tcl Module is a Tcl Package contained in a single file, and no other +files required by it. This file has to be \fBsource\fRable. In other +words, a Tcl Module is always imported via: +.PP +.CS +source module_file +.CE +.PP +The \fBload\fR command is not directly used. This restriction is not +an actual limitation, as some may believe. +Ever since 8.4 the Tcl \fBsource\fR command reads only until the first +^Z character. This allows us to combine an arbitrary Tcl script with +arbitrary binary data into one file, where the script processes the +attached data in any it chooses to fully import and activate the +package. +.PP +The name of a module file has to match the regular expression: +.PP +.CS +([_[:alpha:]][:_[:alnum:]]*)-([[:digit:]].*)\e.tm +.CE +.PP +The first capturing parentheses provides the name of the package, the +second clause its version. In addition to matching the pattern, the +extracted version number must not raise an error when used in the +command: +.PP +.CS +package vcompare $version 0 +.CE +.SH "FINDING MODULES" +.PP +The directory tree for storing Tcl modules is separate from other +parts of the filesystem and independent of \fBauto_path\fR. +.PP +Tcl Modules are searched for in all directories listed in the result +of the command \fB::tcl::tm::path list\fR. +This is called the \fIModule path\fR. Neither the \fBauto_path\fR nor +the \fBtcl_pkgPath\fR variables are used. +All directories on the module path have to obey one restriction: +.RS +.PP +For any two directories, neither is an ancestor directory of the +other. +.RE +.PP +This is required to avoid ambiguities in package naming. If for +example the two directories +.QW "\fIfoo/\fR" +and +.QW "\fIfoo/cool\fR" +were on +the path a package named \fBcool::ice\fR could be found via the +names \fBcool::ice\fR or \fBice\fR, the latter potentially +obscuring a package named \fBice\fR, unqualified. +.PP +Before the search is started, the name of the requested package is +translated into a partial path, using the following algorithm: +.RS +.PP +All occurrences of +.QW "\fB::\fR" +in the package name are replaced by +the appropriate directory separator character for the platform we are +on. On Unix, for example, this is +.QW "\fB/\fR" . +.RE +.PP +Example: +.RS +.PP +The requested package is \fBencoding::base64\fR. The generated +partial path is +.QW "\fIencoding/base64\fR" . +.RE +.PP +After this translation the package is looked for in all module paths, +by combining them one-by-one, first to last with the partial path to +form a complete search pattern. Note that the search algorithm rejects +all files where the filename does not match the regular expression +given in the section \fBMODULE DEFINITION\fR. For the remaining +files \fIprovide scripts\fR are generated and added to the package +ifneeded database. +.PP +The algorithm falls back to the previous unknown handler when none of +the found module files satisfy the request. If the request was +satisfied the fall-back is ignored. +.PP +Note that packages in module form have \fIno\fR control over the +\fIindex\fR and \fIprovide script\fRs entered into the package +database for them. +For a module file \fBMF\fR the \fIindex script\fR is always: +.PP +.CS +package ifneeded \fBPNAME PVERSION\fR [list source \fBMF\fR] +.CE +.PP +and the \fIprovide script\fR embedded in the above is: +.PP +.CS +source \fBMF\fR +.CE +.PP +Both package name \fBPNAME\fR and package version \fBPVERSION\fR are +extracted from the filename \fBMF\fR according to the definition +below: +.PP +.CS +\fBMF\fR = /module_path/\fBPNAME\(fm\fR-\fBPVERSION\fR.tm +.CE +.PP +Where \fBPNAME\(fm\fR is the partial path of the module as defined in +section \fBFINDING MODULES\fR, and translated into \fBPNAME\fR by +changing all directory separators to +.QW "\fB::\fR" , +and \fBmodule_path\fR is the path (from the list of paths to search) +that we found the module file under. +.PP +Note also that we are here creating a connection between package names +and paths. Tcl is case-sensitive when it comes to comparing package +names, but there are filesystems which are not, like NTFS. Luckily +these filesystems do store the case of the name, despite not using the +information when comparing. +.PP +Given the above we allow the names for packages in Tcl modules to have +mixed-case, but also require that there are no collisions when +comparing names in a case-insensitive manner. In other words, if a +package \fBFoo\fR is deployed in the form of a Tcl Module, +packages like \fBfoo\fR, \fBfOo\fR, etc. are not allowed +anymore. +.SH "DEFAULT PATHS" +.PP +The default list of paths on the module path is computed by a +\fBtclsh\fR as follows, where \fIX\fR is the major version of the Tcl +interpreter and \fIy\fR is less than or equal to the minor version of +the Tcl interpreter. +.PP +All the default paths are added to the module path, even those paths +which do not exist. Non-existent paths are filtered out during actual +searches. This enables a user to create one of the paths searched when +needed and all running applications will automatically pick up any +modules placed in them. +.PP +The paths are added in the order as they are listed below, and for +lists of paths defined by an environment variable in the order they +are found in the variable. +.SS "SYSTEM SPECIFIC PATHS" +.TP +\fBfile normalize [info library]/../tcl\fIX\fB/\fIX\fB.\fIy\fR +. +In other words, the interpreter will look into a directory specified +by its major version and whose minor versions are less than or equal +to the minor version of the interpreter. +.RS +.PP +For example for Tcl 8.4 the paths searched are: +.PP +.CS +\fB[info library]/../tcl8/8.4\fR +\fB[info library]/../tcl8/8.3\fR +\fB[info library]/../tcl8/8.2\fR +\fB[info library]/../tcl8/8.1\fR +\fB[info library]/../tcl8/8.0\fR +.CE +.PP +This definition assumes that a package defined for Tcl \fIX\fB.\fIy\fR +can also be used by all interpreters which have the same major number +\fIX\fR and a minor number greater than \fIy\fR. +.RE +.TP +\fBfile normalize EXEC/tcl\fIX\fB/\fIX\fB.\fIy\fR +. +Where \fBEXEC\fR is \fBfile normalize [info nameofexecutable]/../lib\fR +or \fBfile normalize [::tcl::pkgconfig get libdir,runtime]\fR +.RS +.PP +This sets of paths is handled equivalently to the set coming before, +except that it is anchored in \fBEXEC_PREFIX\fR. +For a build with \fBPREFIX\fR = \fBEXEC_PREFIX\fR the two sets are +identical. +.RE +.SS "SITE SPECIFIC PATHS" +.TP +\fBfile normalize [info library]/../tcl\fIX\fB/site-tcl\fR +. +Note that this is always a single entry because \fIX\fR is always a +specific value (the current major version of Tcl). +.SS "USER SPECIFIC PATHS" +.TP +\fB$::env(TCL\fIX\fB_\fIy\fB_TM_PATH)\fR +. +A list of paths, separated by either \fB:\fR (Unix) or \fB;\fR +(Windows). This is user and site specific as this environment variable +can be set not only by the user's profile, but by system configuration +scripts as well. +.TP +\fB$::env(TCL\fIX\fB.\fIy\fB_TM_PATH)\fR +. +Same meaning and content as the previous variable. However the use of +dot '.' to separate major and minor version number makes this name +less to non-portable and its use is discouraged. Support of this +variable has been kept only for backward compatibility with the +original specification, i.e. TIP 189. +.PP +These paths are seen and therefore shared by all Tcl shells in the +\fB$::env(PATH)\fR of the user. +.PP +Note that \fIX\fR and \fIy\fR follow the general rules set out +above. In other words, Tcl 8.4, for example, will look at these 10 +environment variables: +.PP +.CS +\fB$::env(TCL8.4_TM_PATH)\fR \fB$::env(TCL8_4_TM_PATH)\fR +\fB$::env(TCL8.3_TM_PATH)\fR \fB$::env(TCL8_3_TM_PATH)\fR +\fB$::env(TCL8.2_TM_PATH)\fR \fB$::env(TCL8_2_TM_PATH)\fR +\fB$::env(TCL8.1_TM_PATH)\fR \fB$::env(TCL8_1_TM_PATH)\fR +\fB$::env(TCL8.0_TM_PATH)\fR \fB$::env(TCL8_0_TM_PATH)\fR +.CE +.SH "SEE ALSO" +package(n), Tcl Improvement Proposal #189 +.QW "\fITcl Modules\fR" +(online at http://tip.tcl.tk/189.html), Tcl Improvement Proposal #190 +.QW "\fIImplementation Choices for Tcl Modules\fR" +(online at http://tip.tcl.tk/190.html) +.SH "KEYWORDS" +modules, package +.\" Local Variables: +.\" mode: nroff +.\" End: diff --git a/tcl8.6/doc/trace.n b/tcl8.6/doc/trace.n new file mode 100644 index 0000000..5482e59 --- /dev/null +++ b/tcl8.6/doc/trace.n @@ -0,0 +1,426 @@ +'\" +'\" Copyright (c) 1993 The Regents of the University of California. +'\" Copyright (c) 1994-1996 Sun Microsystems, Inc. +'\" Copyright (c) 2000 Ajuba Solutions. +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH trace n "8.4" Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +trace \- Monitor variable accesses, command usages and command executions +.SH SYNOPSIS +\fBtrace \fIoption\fR ?\fIarg arg ...\fR? +.BE +.SH DESCRIPTION +.PP +This command causes Tcl commands to be executed whenever certain operations are +invoked. The legal \fIoption\fRs (which may be abbreviated) are: +.TP +\fBtrace add \fItype name ops ?args?\fR +Where \fItype\fR is \fBcommand\fR, \fBexecution\fR, or \fBvariable\fR. +.RS +.TP +\fBtrace add command\fR \fIname ops commandPrefix\fR +. +Arrange for \fIcommandPrefix\fR to be executed (with additional arguments) +whenever command \fIname\fR is modified in one of the ways given by the list +\fIops\fR. \fIName\fR will be resolved using the usual namespace resolution +rules used by commands. If the command does not exist, an error will be +thrown. +.RS +.PP +\fIOps\fR indicates which operations are of interest, and is a list of +one or more of the following items: +.TP +\fBrename\fR +. +Invoke \fIcommandPrefix\fR whenever the traced command is renamed. Note that +renaming to the empty string is considered deletion, and will not be traced +with +.QW \fBrename\fR . +.TP +\fBdelete\fR +. +Invoke \fIcommandPrefix\fR when the traced command is deleted. Commands can be +deleted explicitly by using the \fBrename\fR command to rename the command to +an empty string. Commands are also deleted when the interpreter is deleted, +but traces will not be invoked because there is no interpreter in which to +execute them. +.PP +When the trace triggers, depending on the operations being traced, a number of +arguments are appended to \fIcommandPrefix\fR so that the actual command is as +follows: +.PP +.CS +\fIcommandPrefix oldName newName op\fR +.CE +.PP +\fIOldName\fR and \fInewName\fR give the traced command's current (old) name, +and the name to which it is being renamed (the empty string if this is a +.QW delete +operation). +\fIOp\fR indicates what operation is being performed on the +command, and is one of \fBrename\fR or \fBdelete\fR as +defined above. The trace operation cannot be used to stop a command +from being deleted. Tcl will always remove the command once the trace +is complete. Recursive renaming or deleting will not cause further traces +of the same type to be evaluated, so a delete trace which itself +deletes the command, or a rename trace which itself renames the +command will not cause further trace evaluations to occur. +Both \fIoldName\fR and \fInewName\fR are fully qualified with any namespace(s) +in which they appear. +.RE +.TP +\fBtrace add execution\fR \fIname ops commandPrefix\fR +. +Arrange for \fIcommandPrefix\fR to be executed (with additional arguments) +whenever command \fIname\fR is executed, with traces occurring at the points +indicated by the list \fIops\fR. \fIName\fR will be resolved using the usual +namespace resolution rules used by commands. If the command does not exist, +an error will be thrown. +.RS +.PP +\fIOps\fR indicates which operations are of interest, and is a list of +one or more of the following items: +.TP +\fBenter\fR +Invoke \fIcommandPrefix\fR whenever the command \fIname\fR is executed, +just before the actual execution takes place. +.TP +\fBleave\fR +Invoke \fIcommandPrefix\fR whenever the command \fIname\fR is executed, +just after the actual execution takes place. +.TP +\fBenterstep\fR +. +Invoke \fIcommandPrefix\fR for every Tcl command which is executed from the +start of the execution of the procedure \fIname\fR until that +procedure finishes. \fICommandPrefix\fR is invoked just before the actual +execution of the Tcl command being reported takes place. For example +if we have +.QW "proc foo {} { puts \N'34'hello\N'34' }" , +then an \fIenterstep\fR trace would be invoked just before +.QW "\fIputs \N'34'hello\N'34'\fR" +is executed. +Setting an \fIenterstep\fR trace on a command \fIname\fR that does not refer +to a procedure will not result in an error and is simply ignored. +.TP +\fBleavestep\fR +. +Invoke \fIcommandPrefix\fR for every Tcl command which is executed from the +start of the execution of the procedure \fIname\fR until that +procedure finishes. \fICommandPrefix\fR is invoked just after the actual +execution of the Tcl command being reported takes place. +Setting a \fIleavestep\fR trace on a command \fIname\fR that does not refer to +a procedure will not result in an error and is simply ignored. +.PP +When the trace triggers, depending on the operations being traced, a +number of arguments are appended to \fIcommandPrefix\fR so that the actual +command is as follows: +.PP +For \fBenter\fR and \fBenterstep\fR operations: +.PP +.CS +\fIcommandPrefix command-string op\fR +.CE +.PP +\fICommand-string\fR gives the complete current command being +executed (the traced command for a \fBenter\fR operation, an +arbitrary command for a \fBenterstep\fR operation), including +all arguments in their fully expanded form. +\fIOp\fR indicates what operation is being performed on the +command execution, and is one of \fBenter\fR or \fBenterstep\fR as +defined above. The trace operation can be used to stop the +command from executing, by deleting the command in question. Of +course when the command is subsequently executed, an +.QW "invalid command" +error will occur. +.PP +For \fBleave\fR and \fBleavestep\fR operations: +.PP +.CS +\fIcommandPrefix command-string code result op\fR +.CE +.PP +\fICommand-string\fR gives the complete current command being +executed (the traced command for a \fBenter\fR operation, an +arbitrary command for a \fBenterstep\fR operation), including +all arguments in their fully expanded form. +\fICode\fR gives the result code of that execution, and \fIresult\fR +the result string. +\fIOp\fR indicates what operation is being performed on the +command execution, and is one of \fBleave\fR or \fBleavestep\fR as +defined above. +Note that the creation of many \fBenterstep\fR or +\fBleavestep\fR traces can lead to unintuitive results, since the +invoked commands from one trace can themselves lead to further +command invocations for other traces. +.PP +\fICommandPrefix\fR executes in the same context as the code that invoked +the traced operation: thus the \fIcommandPrefix\fR, if invoked from a +procedure, will have access to the same local variables as code in the +procedure. This context may be different than the context in which the trace +was created. If \fIcommandPrefix\fR invokes a procedure (which it normally +does) then the procedure will have to use \fBupvar\fR or \fBuplevel\fR +commands if it wishes to access the local variables of the code which invoked +the trace operation. +.PP +While \fIcommandPrefix\fR is executing during an execution trace, traces +on \fIname\fR are temporarily disabled. This allows the \fIcommandPrefix\fR +to execute \fIname\fR in its body without invoking any other traces again. +If an error occurs while executing the \fIcommandPrefix\fR, then the +command \fIname\fR as a whole will return that same error. +.PP +When multiple traces are set on \fIname\fR, then for \fIenter\fR +and \fIenterstep\fR operations, the traced commands are invoked +in the reverse order of how the traces were originally created; +and for \fIleave\fR and \fIleavestep\fR operations, the traced +commands are invoked in the original order of creation. +.PP +The behavior of execution traces is currently undefined for a command +\fIname\fR imported into another namespace. +.RE +.TP +\fBtrace add variable\fI name ops commandPrefix\fR +Arrange for \fIcommandPrefix\fR to be executed whenever variable \fIname\fR +is accessed in one of the ways given by the list \fIops\fR. \fIName\fR may +refer to a normal variable, an element of an array, or to an array +as a whole (i.e. \fIname\fR may be just the name of an array, with no +parenthesized index). If \fIname\fR refers to a whole array, then +\fIcommandPrefix\fR is invoked whenever any element of the array is +manipulated. If the variable does not exist, it will be created but +will not be given a value, so it will be visible to \fBnamespace which\fR +queries, but not to \fBinfo exists\fR queries. +.RS +.PP +\fIOps\fR indicates which operations are of interest, and is a list of +one or more of the following items: +.TP +\fBarray\fR +Invoke \fIcommandPrefix\fR whenever the variable is accessed or modified via +the \fBarray\fR command, provided that \fIname\fR is not a scalar +variable at the time that the \fBarray\fR command is invoked. If +\fIname\fR is a scalar variable, the access via the \fBarray\fR +command will not trigger the trace. +.TP +\fBread\fR +Invoke \fIcommandPrefix\fR whenever the variable is read. +.TP +\fBwrite\fR +Invoke \fIcommandPrefix\fR whenever the variable is written. +.TP +\fBunset\fR +Invoke \fIcommandPrefix\fR whenever the variable is unset. Variables +can be unset explicitly with the \fBunset\fR command, or +implicitly when procedures return (all of their local variables +are unset). Variables are also unset when interpreters are +deleted, but traces will not be invoked because there is no +interpreter in which to execute them. +.PP +When the trace triggers, three arguments are appended to +\fIcommandPrefix\fR so that the actual command is as follows: +.PP +.CS +\fIcommandPrefix name1 name2 op\fR +.CE +.PP +\fIName1\fR and \fIname2\fR give the name(s) for the variable +being accessed: if the variable is a scalar then \fIname1\fR +gives the variable's name and \fIname2\fR is an empty string; +if the variable is an array element then \fIname1\fR gives the +name of the array and name2 gives the index into the array; +if an entire array is being deleted and the trace was registered +on the overall array, rather than a single element, then \fIname1\fR +gives the array name and \fIname2\fR is an empty string. +\fIName1\fR and \fIname2\fR are not necessarily the same as the +name used in the \fBtrace variable\fR command: the \fBupvar\fR +command allows a procedure to reference a variable under a +different name. +\fIOp\fR indicates what operation is being performed on the +variable, and is one of \fBread\fR, \fBwrite\fR, or \fBunset\fR as +defined above. +.PP +\fICommandPrefix\fR executes in the same context as the code that invoked +the traced operation: if the variable was accessed as part of a Tcl +procedure, then \fIcommandPrefix\fR will have access to the same local +variables as code in the procedure. This context may be different +than the context in which the trace was created. If \fIcommandPrefix\fR +invokes a procedure (which it normally does) then the procedure will +have to use \fBupvar\fR or \fBuplevel\fR if it wishes to access the +traced variable. Note also that \fIname1\fR may not necessarily be +the same as the name used to set the trace on the variable; +differences can occur if the access is made through a variable defined +with the \fBupvar\fR command. +.PP +For read and write traces, \fIcommandPrefix\fR can modify the variable to +affect the result of the traced operation. If \fIcommandPrefix\fR modifies +the value of a variable during a read or write trace, then the new +value will be returned as the result of the traced operation. The +return value from \fIcommandPrefix\fR is ignored except that if it returns +an error of any sort then the traced operation also returns an error +with the same error message returned by the trace command (this +mechanism can be used to implement read-only variables, for example). +For write traces, \fIcommandPrefix\fR is invoked after the variable's value +has been changed; it can write a new value into the variable to +override the original value specified in the write operation. To +implement read-only variables, \fIcommandPrefix\fR will have to restore the +old value of the variable. +.PP +While \fIcommandPrefix\fR is executing during a read or write trace, traces +on the variable are temporarily disabled. This means that reads and +writes invoked by \fIcommandPrefix\fR will occur directly, without invoking +\fIcommandPrefix\fR (or any other traces) again. However, if +\fIcommandPrefix\fR unsets the variable then unset traces will be invoked. +.PP +When an unset trace is invoked, the variable has already been deleted: +it will appear to be undefined with no traces. If an unset occurs +because of a procedure return, then the trace will be invoked in the +variable context of the procedure being returned to: the stack frame +of the returning procedure will no longer exist. Traces are not +disabled during unset traces, so if an unset trace command creates a +new trace and accesses the variable, the trace will be invoked. Any +errors in unset traces are ignored. +.PP +If there are multiple traces on a variable they are invoked in order +of creation, most-recent first. If one trace returns an error, then +no further traces are invoked for the variable. If an array element +has a trace set, and there is also a trace set on the array as a +whole, the trace on the overall array is invoked before the one on the +element. +.PP +Once created, the trace remains in effect either until the trace is +removed with the \fBtrace remove variable\fR command described below, +until the variable is unset, or until the interpreter is deleted. +Unsetting an element of array will remove any traces on that element, +but will not remove traces on the overall array. +.PP +This command returns an empty string. +.RE +.RE +.TP +\fBtrace remove \fItype name opList commandPrefix\fR +Where \fItype\fR is either \fBcommand\fR, \fBexecution\fR or \fBvariable\fR. +.RS +.TP +\fBtrace remove command\fI name opList commandPrefix\fR +If there is a trace set on command \fIname\fR with the operations and +command given by \fIopList\fR and \fIcommandPrefix\fR, then the trace is +removed, so that \fIcommandPrefix\fR will never again be invoked. Returns +an empty string. If \fIname\fR does not exist, the command will throw +an error. +.TP +\fBtrace remove execution\fI name opList commandPrefix\fR +If there is a trace set on command \fIname\fR with the operations and +command given by \fIopList\fR and \fIcommandPrefix\fR, then the trace is +removed, so that \fIcommandPrefix\fR will never again be invoked. Returns +an empty string. If \fIname\fR does not exist, the command will throw +an error. +.TP +\fBtrace remove variable\fI name opList commandPrefix\fR +If there is a trace set on variable \fIname\fR with the operations and +command given by \fIopList\fR and \fIcommandPrefix\fR, then the trace is +removed, so that \fIcommandPrefix\fR will never again be invoked. Returns +an empty string. +.RE +.TP +\fBtrace info \fItype name\fR +Where \fItype\fR is either \fBcommand\fR, \fBexecution\fR or \fBvariable\fR. +.RS +.TP +\fBtrace info command\fI name\fR +Returns a list containing one element for each trace currently set on +command \fIname\fR. Each element of the list is itself a list +containing two elements, which are the \fIopList\fR and \fIcommandPrefix\fR +associated with the trace. If \fIname\fR does not have any traces set, +then the result of the command will be an empty string. If \fIname\fR +does not exist, the command will throw an error. +.TP +\fBtrace info execution\fI name\fR +Returns a list containing one element for each trace currently set on +command \fIname\fR. Each element of the list is itself a list +containing two elements, which are the \fIopList\fR and \fIcommandPrefix\fR +associated with the trace. If \fIname\fR does not have any traces set, +then the result of the command will be an empty string. If \fIname\fR +does not exist, the command will throw an error. +.TP +\fBtrace info variable\fI name\fR +Returns a list containing one element for each trace currently set on +variable \fIname\fR. Each element of the list is itself a list +containing two elements, which are the \fIopList\fR and \fIcommandPrefix\fR +associated with the trace. If \fIname\fR does not exist or does not +have any traces set, then the result of the command will be an empty +string. +.RE +.PP +For backwards compatibility, three other subcommands are available: +.RS +.TP +\fBtrace variable \fIname ops command\fR +This is equivalent to \fBtrace add variable \fIname ops command\fR. +.TP +\fBtrace vdelete \fIname ops command\fR +This is equivalent to \fBtrace remove variable \fIname ops command\fR +.TP +\fBtrace vinfo \fIname\fR +This is equivalent to \fBtrace info variable \fIname\fR +.RE +.PP +These subcommands are deprecated and will likely be removed in a +future version of Tcl. They use an older syntax in which \fBarray\fR, +\fBread\fR, \fBwrite\fR, \fBunset\fR are replaced by \fBa\fR, \fBr\fR, +\fBw\fR and \fBu\fR respectively, and the \fIops\fR argument is not a +list, but simply a string concatenation of the operations, such as +\fBrwua\fR. +.SH EXAMPLES +.PP +Print a message whenever either of the global variables \fBfoo\fR and +\fBbar\fR are updated, even if they have a different local name at the +time (which can be done with the \fBupvar\fR command): +.PP +.CS +proc tracer {varname args} { + upvar #0 $varname var + puts "$varname was updated to be \e"$var\e"" +} +\fBtrace add\fR variable foo write "tracer foo" +\fBtrace add\fR variable bar write "tracer bar" +.CE +.PP +Ensure that the global variable \fBfoobar\fR always contains the +product of the global variables \fBfoo\fR and \fBbar\fR: +.PP +.CS +proc doMult args { + global foo bar foobar + set foobar [expr {$foo * $bar}] +} +\fBtrace add\fR variable foo write doMult +\fBtrace add\fR variable bar write doMult +.CE +.PP +Print a trace of what commands are executed during the processing of a Tcl +procedure: +.PP +.CS +proc x {} { y } +proc y {} { z } +proc z {} { puts hello } +proc report args {puts [info level 0]} +\fBtrace add\fR execution x enterstep report +x + \(-> \fIreport y enterstep\fR + \fIreport z enterstep\fR + \fIreport {puts hello} enterstep\fR + \fIhello\fR +.CE +.SH "SEE ALSO" +set(n), unset(n) +.SH KEYWORDS +read, command, rename, variable, write, trace, unset +.\" Local Variables: +.\" mode: nroff +.\" End: diff --git a/tcl8.6/doc/transchan.n b/tcl8.6/doc/transchan.n new file mode 100644 index 0000000..4da74f2 --- /dev/null +++ b/tcl8.6/doc/transchan.n @@ -0,0 +1,160 @@ +'\" +'\" Copyright (c) 2008 Donal K. Fellows +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH transchan n 8.6 Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +transchan \- command handler API of channel transforms +.SH SYNOPSIS +\fBcmdPrefix \fIoption\fR ?\fIarg arg ...\fR? +.BE +.SH DESCRIPTION +.PP +The Tcl-level handler for a channel transformation has to be a command with +subcommands (termed an \fIensemble\fR despite not implying that it must be +created with \fBnamespace ensemble create\fR; this mechanism is not tied to +\fBnamespace ensemble\fR in any way). Note that \fIcmdPrefix\fR is whatever +was specified in the call to \fBchan push\fR, and may consist of multiple +arguments; this will be expanded to multiple words in place of the prefix. +.PP +Of all the possible subcommands, the handler \fImust\fR support +\fBinitialize\fR and \fBfinalize\fR. Transformations for writable channels +must also support \fBwrite\fR, and transformations for readable channels must +also support \fBread\fR. +.PP +Note that in the descriptions below \fIcmdPrefix\fR may be more than one word, +and \fIhandle\fR is the value returned by the \fBchan push\fR call used to +create the transformation. +.SS "GENERIC SUBCOMMANDS" +.PP +The following subcommands are relevant to all types of channel. +.TP +\fIcmdPrefix \fBclear \fIhandle\fR +. +This optional subcommand is called to signify to the transformation that any +data stored in internal buffers (either incoming or outgoing) must be +cleared. It is called when a \fBchan seek\fR is performed on the channel being +transformed. +.TP +\fIcmdPrefix \fBfinalize \fIhandle\fR +. +This mandatory subcommand is called last for the given \fIhandle\fR, and then +never again, and it exists to allow for cleaning up any Tcl-level data +structures associated with the transformation. \fIWarning!\fR Any errors +thrown by this subcommand will be ignored. It is not guaranteed to be called +if the interpreter is deleted. +.TP +\fIcmdPrefix \fBinitialize \fIhandle mode\fR +. +This mandatory subcommand is called first, and then never again (for the given +\fIhandle\fR). Its responsibility is to initialize all parts of the +transformation at the Tcl level. The \fImode\fR is a list containing any of +\fBread \fRand \fBwrite\fR. +.RS +.TP +\fBwrite\fR +. +implies that the channel is writable. +.TP +\fBread\fR +. +implies that the channel is readable. +.PP +The return value of the subcommand should be a list containing the names of +all subcommands supported by this handler. Any error thrown by the subcommand +will prevent the creation of the transformation. The thrown error will appear +as error thrown by \fBchan push\fR. +.RE +.SS "READ-RELATED SUBCOMMANDS" +.PP +These subcommands are used for handling transformations applied to readable +channels; though strictly \fBread \fRis optional, it must be supported if any +of the others is or the channel will be made non-readable. +.TP +\fIcmdPrefix \fBdrain \fIhandle\fR +. +This optional subcommand is called whenever data in the transformation input +(i.e. read) buffer has to be forced upward, i.e. towards the user or script. +The result returned by the method is taken as the \fIbinary\fR data to push +upward to the level above this transformation (the reader or a higher-level +transformation). +.RS +.PP +In other words, when this method is called the transformation cannot defer the +actual transformation operation anymore and has to transform all data waiting +in its internal read buffers and return the result of that action. +.RE +.TP +\fIcmdPrefix \fBlimit? \fIhandle\fR +. +This optional subcommand is called to allow the Tcl I/O engine to determine +how far ahead it should read. If present, it should return an integer number +greater than zero which indicates how many bytes ahead should be read, or an +integer less than zero to indicate that the I/O engine may read as far ahead +as it likes. +.TP +\fIcmdPrefix \fBread \fIhandle buffer\fR +. +This subcommand, which must be present if the transformation is to work with +readable channels, is called whenever the base channel, or a transformation +below this transformation, pushes data upward. The \fIbuffer\fR contains the +binary data which has been given to us from below. It is the responsibility of +this subcommand to actually transform the data. The result returned by the +subcommand is taken as the binary data to push further upward to the +transformation above this transformation. This can also be the user or script +that originally read from the channel. +.RS +.PP +Note that the result is allowed to be empty, or even less than the data we +received; the transformation is not required to transform everything given to +it right now. It is allowed to store incoming data in internal buffers and to +defer the actual transformation until it has more data. +.RE +.SS "WRITE-RELATED SUBCOMMANDS" +.PP +These subcommands are used for handling transformations applied to writable +channels; though strictly \fBwrite\fR is optional, it must be supported if any +of the others is or the channel will be made non-writable. +.TP +\fIcmdPrefix \fBflush \fIhandle\fR +. +This optional subcommand is called whenever data in the transformation 'write' +buffer has to be forced downward, i.e. towards the base channel. The result +returned by the subcommand is taken as the binary data to write to the +transformation below the current transformation. This can be the base channel +as well. +.RS +.PP +In other words, when this subcommand is called the transformation cannot defer +the actual transformation operation anymore and has to transform all data +waiting in its internal write buffers and return the result of that action. +.RE +.TP +\fIcmdPrefix \fBwrite \fIhandle buffer\fR +. +This subcommand, which must be present if the transformation is to work with +writable channels, is called whenever the user, or a transformation above this +transformation, writes data downward. The \fIbuffer\fR contains the binary +data which has been written to us. It is the responsibility of this subcommand +to actually transform the data. +.RS +.PP +The result returned by the subcommand is taken as the binary data to write to +the transformation below this transformation. This can be the base channel as +well. Note that the result is allowed to be empty, or less than the data we +got; the transformation is not required to transform everything which was +written to it right now. It is allowed to store this data in internal buffers +and to defer the actual transformation until it has more data. +.RE +.SH "SEE ALSO" +chan(n), refchan(n) +.SH KEYWORDS +API, channel, ensemble, prefix, transformation +'\" Local Variables: +'\" mode: nroff +'\" End: diff --git a/tcl8.6/doc/try.n b/tcl8.6/doc/try.n new file mode 100644 index 0000000..eae4dc7 --- /dev/null +++ b/tcl8.6/doc/try.n @@ -0,0 +1,103 @@ +'\" +'\" Copyright (c) 2008 Donal K. Fellows +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH try n 8.6 Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +try \- Trap and process errors and exceptions +.SH SYNOPSIS +\fBtry\fI body\fR ?\fIhandler...\fR? ?\fBfinally\fI script\fR? +.BE +.SH DESCRIPTION +.PP +This command executes the script \fIbody\fR and, depending on what the outcome +of that script is (normal exit, error, or some other exceptional result), runs +a handler script to deal with the case. Once that has all happened, if the +\fBfinally\fR clause is present, the \fIscript\fR it includes will be run and +the result of the handler (or the \fIbody\fR if no handler matched) is allowed +to continue to propagate. Note that the \fBfinally\fR clause is processed even +if an error occurs and irrespective of which, if any, \fIhandler\fR is used. +.PP +The \fIhandler\fR clauses are each expressed as several words, and must have +one of the following forms: +.TP +\fBon \fIcode variableList script\fR +. +This clause matches if the evaluation of \fIbody\fR completed with the +exception code \fIcode\fR. The \fIcode\fR may be expressed as an integer or +one of the following literal words: \fBok\fR, \fBerror\fR, \fBreturn\fR, +\fBbreak\fR, or \fBcontinue\fR. Those literals correspond to the integers 0 +through 4 respectively. +.TP +\fBtrap \fIpattern variableList script\fR +. +This clause matches if the evaluation of \fIbody\fR resulted in an error and +the prefix of the \fB\-errorcode\fR from the interpreter's status dictionary +is equal to the \fIpattern\fR. The number of prefix words taken from the +\fB\-errorcode\fR is equal to the list-length of \fIpattern\fR, and inter-word +spaces are normalized in both the \fB\-errorcode\fR and \fIpattern\fR before +comparison. +.PP +The \fIvariableList\fR word in each \fIhandler\fR is always interpreted as a +list of variable names. If the first word of the list is present and +non-empty, it names a variable into which the result of the evaluation of +\fIbody\fR (from the main \fBtry\fR) will be placed; this will contain the +human-readable form of any errors. If the second word of the list is present +and non-empty, it names a variable into which the options dictionary of the +interpreter at the moment of completion of execution of \fIbody\fR +will be placed. +.PP +The \fIscript\fR word of each \fIhandler\fR is also always interpreted the +same: as a Tcl script to evaluate if the clause is matched. If \fIscript\fR is +a literal +.QW \- +and the \fIhandler\fR is not the last one, the \fIscript\fR of the following +\fIhandler\fR is invoked instead (just like with the \fBswitch\fR command). +.PP +Note that \fIhandler\fR clauses are matched against in order, and that the +first matching one is always selected. At most one \fIhandler\fR clause will +selected. As a consequence, an \fBon error\fR will mask any subsequent +\fBtrap\fR in the \fBtry\fR. Also note that \fBon error\fR is equivalent to +\fBtrap {}\fR. +.PP +If an exception (i.e. any non-\fBok\fR result) occurs during the evaluation of +either the \fIhandler\fR or the \fBfinally\fR clause, the original exception's +status dictionary will be added to the new exception's status dictionary under +the \fB\-during\fR key. +.SH EXAMPLES +.PP +Ensure that a file is closed no matter what: +.PP +.CS +set f [open /some/file/name a] +\fBtry\fR { + puts $f "some message" + # ... +} \fBfinally\fR { + close $f +} +.CE +.PP +Handle different reasons for a file to not be openable for reading: +.PP +.CS +\fBtry\fR { + set f [open /some/file/name w] +} \fBtrap\fR {POSIX EISDIR} {} { + puts "failed to open /some/file/name: it's a directory" +} \fBtrap\fR {POSIX ENOENT} {} { + puts "failed to open /some/file/name: it doesn't exist" +} +.CE +.SH "SEE ALSO" +catch(n), error(n), return(n), throw(n) +.SH "KEYWORDS" +cleanup, error, exception, final, resource management +'\" Local Variables: +'\" mode: nroff +'\" End: diff --git a/tcl8.6/doc/unknown.n b/tcl8.6/doc/unknown.n new file mode 100644 index 0000000..82dcefc --- /dev/null +++ b/tcl8.6/doc/unknown.n @@ -0,0 +1,91 @@ +'\" +'\" Copyright (c) 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. +'\" +.TH unknown n "" Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +unknown \- Handle attempts to use non-existent commands +.SH SYNOPSIS +\fBunknown \fIcmdName \fR?\fIarg arg ...\fR? +.BE +.SH DESCRIPTION +.PP +This command is invoked by the Tcl interpreter whenever a script +tries to invoke a command that does not exist. The default implementation +of \fBunknown\fR is a library procedure defined when Tcl initializes an +interpreter. You can override the default \fBunknown\fR to change its +functionality, or you can register a new handler for individual namespaces +using the \fBnamespace unknown\fR command. Note that there is no default +implementation of \fBunknown\fR in a safe interpreter. +.PP +If the Tcl interpreter encounters a command name for which there +is not a defined command (in either the current namespace, or the +global namespace), then Tcl checks for the existence of +an unknown handler for the current namespace. By default, this +handler is a command named \fB::unknown\fR. If there is no such +command, then the interpreter returns an error. +If the \fBunknown\fR command exists (or a new handler has been +registered for the current namespace), then it is invoked with +arguments consisting of the fully-substituted name and arguments +for the original non-existent command. +The \fBunknown\fR command typically does things like searching +through library directories for a command procedure with the name +\fIcmdName\fR, or expanding abbreviated command names to full-length, +or automatically executing unknown commands as sub-processes. +In some cases (such as expanding abbreviations) \fBunknown\fR will +change the original command slightly and then (re-)execute it. +The result of the \fBunknown\fR command is used as the result for +the original non-existent command. +.PP +The default implementation of \fBunknown\fR behaves as follows. +It first calls the \fBauto_load\fR library procedure to load the command. +If this succeeds, then it executes the original command with its +original arguments. +If the auto-load fails then \fBunknown\fR calls \fBauto_execok\fR +to see if there is an executable file by the name \fIcmd\fR. +If so, it invokes the Tcl \fBexec\fR command +with \fIcmd\fR and all the \fIargs\fR as arguments. +If \fIcmd\fR cannot be auto-executed, \fBunknown\fR checks to +see if the command was invoked at top-level and outside of any +script. If so, then \fBunknown\fR takes two additional steps. +First, it sees if \fIcmd\fR has one of the following three forms: +\fB!!\fR, \fB!\fIevent\fR, or \fB^\fIold\fB^\fInew\fR?\fB^\fR?. +If so, then \fBunknown\fR carries out history substitution +in the same way that \fBcsh\fR would for these constructs. +Finally, \fBunknown\fR checks to see if \fIcmd\fR is +a unique abbreviation for an existing Tcl command. +If so, it expands the command name and executes the command with +the original arguments. +If none of the above efforts has been able to execute +the command, \fBunknown\fR generates an error return. +If the global variable \fBauto_noload\fR is defined, then the auto-load +step is skipped. +If the global variable \fBauto_noexec\fR is defined then the +auto-exec step is skipped. +Under normal circumstances the return value from \fBunknown\fR +is the return value from the command that was eventually +executed. +.SH EXAMPLE +Arrange for the \fBunknown\fR command to have its standard behavior +except for first logging the fact that a command was not found: +.PP +.CS +# Save the original one so we can chain to it +rename \fBunknown\fR _original_unknown + +# Provide our own implementation +proc \fBunknown\fR args { + puts stderr "WARNING: unknown command: $args" + uplevel 1 [list _original_unknown {*}$args] +} +.CE +.SH "SEE ALSO" +info(n), proc(n), interp(n), library(n), namespace(n) +.SH KEYWORDS +error, non-existent command, unknown diff --git a/tcl8.6/doc/unload.n b/tcl8.6/doc/unload.n new file mode 100644 index 0000000..0a8e99b --- /dev/null +++ b/tcl8.6/doc/unload.n @@ -0,0 +1,172 @@ +'\" +'\" Copyright (c) 2003 George Petasis <petasis@iit.demokritos.gr>. +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH unload n 8.5 Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +unload \- Unload machine code +.SH SYNOPSIS +\fBunload \fR?\fIswitches\fR? \fIfileName\fR +.br +\fBunload \fR?\fIswitches\fR? \fIfileName packageName\fR +.br +\fBunload \fR?\fIswitches\fR? \fIfileName packageName interp\fR +.BE +.SH DESCRIPTION +.PP +This command tries to unload shared libraries previously loaded +with \fBload\fR from the application's address space. \fIfileName\fR +is the name of the file containing the library file to be unload; it +must be the same as the filename provided to \fBload\fR for +loading the library. +The \fIpackageName\fR argument is the name of the package (as +determined by or passed to \fBload\fR), and is used to +compute the name of the unload procedure; if not supplied, it is +computed from \fIfileName\fR in the same manner as \fBload\fR. +The \fIinterp\fR argument is the path name of the interpreter from +which to unload the package (see the \fBinterp\fR manual entry for +details); if \fIinterp\fR is omitted, it defaults to the +interpreter in which the \fBunload\fR command was invoked. +.PP +If the initial arguments to \fBunload\fR start with \fB\-\fR then +they are treated as switches. The following switches are +currently supported: +.TP +\fB\-nocomplain\fR +. +Suppresses all error messages. If this switch is given, \fBunload\fR will +never report an error. +.TP +\fB\-keeplibrary\fR +. +This switch will prevent \fBunload\fR from issuing the operating system call +that will unload the library from the process. +.TP +\fB\-\|\-\fR +. +Marks the end of switches. The argument following this one will +be treated as a \fIfileName\fR even if it starts with a \fB\-\fR. +.SS "UNLOAD OPERATION" +.PP +When a file containing a shared library is loaded through the +\fBload\fR command, Tcl associates two reference counts to the library +file. The first counter shows how many times the library has been +loaded into normal (trusted) interpreters while the second describes how many +times the library has been loaded into safe interpreters. As a file containing +a shared library can be loaded only once by Tcl (with the first \fBload\fR +call on the file), these counters track how many interpreters use the library. +Each subsequent call to \fBload\fR after the first simply increments the +proper reference count. +.PP +\fBunload\fR works in the opposite direction. As a first step, \fBunload\fR +will check whether the library is unloadable: an unloadable library exports +a special unload procedure. The name of the unload procedure is determined by +\fIpackageName\fR and whether or not the target interpreter +is a safe one. For normal interpreters the name of the initialization +procedure will have the form \fIpkg\fB_Unload\fR, where \fIpkg\fR +is the same as \fIpackageName\fR except that the first letter is +converted to upper case and all other letters +are converted to lower case. For example, if \fIpackageName\fR is +\fBfoo\fR or \fBFOo\fR, the initialization procedure's name will +be \fBFoo_Unload\fR. +If the target interpreter is a safe interpreter, then the name +of the initialization procedure will be \fIpkg\fB_SafeUnload\fR +instead of \fIpkg\fB_Unload\fR. +.PP +If \fBunload\fR determines that a library is not unloadable (or unload +functionality has been disabled during compilation), an error will be returned. +If the library is unloadable, then \fBunload\fR will call the unload +procedure. If the unload procedure returns \fBTCL_OK\fR, \fBunload\fR will proceed +and decrease the proper reference count (depending on the target interpreter +type). When both reference counts have reached 0, the library will be +detached from the process. +.SS "UNLOAD HOOK PROTOTYPE" +.PP +The unload procedure must match the following prototype: +.PP +.CS +typedef int \fBTcl_PackageUnloadProc\fR( + Tcl_Interp *\fIinterp\fR, + int \fIflags\fR); +.CE +.PP +The \fIinterp\fR argument identifies the interpreter from which the +library is to be unloaded. The unload procedure must return +\fBTCL_OK\fR or \fBTCL_ERROR\fR to indicate whether or not it completed +successfully; in the event of an error it should set the interpreter's result +to point to an error message. In this case, the result of the +\fBunload\fR command will be the result returned by the unload procedure. +.PP +The \fIflags\fR argument can be either \fBTCL_UNLOAD_DETACH_FROM_INTERPRETER\fR +or \fBTCL_UNLOAD_DETACH_FROM_PROCESS\fR. In case the library will remain +attached to the process after the unload procedure returns (i.e. because +the library is used by other interpreters), +\fBTCL_UNLOAD_DETACH_FROM_INTERPRETER\fR will be defined. However, if the +library is used only by the target interpreter and the library will be +detached from the application as soon as the unload procedure returns, +the \fIflags\fR argument will be set to \fBTCL_UNLOAD_DETACH_FROM_PROCESS\fR. +.SS NOTES +.PP +The \fBunload\fR command cannot unload libraries that are statically +linked with the application. +If \fIfileName\fR is an empty string, then the \fIpackageName\fR argument must +be specified. +.PP +If \fIpackageName\fR is omitted or specified as an empty string, +Tcl tries to guess the name of the package. +This may be done differently on different platforms. +The default guess, which is used on most UNIX platforms, is to +take the last element of \fIfileName\fR, strip off the first +three characters if they are \fBlib\fR, and use any following +alphabetic and underline characters as the module name. +For example, the command \fBunload libxyz4.2.so\fR uses the module +name \fBxyz\fR and the command \fBunload bin/last.so {}\fR uses the +module name \fBlast\fR. +.SH "PORTABILITY ISSUES" +.TP +\fBUnix\fR\0\0\0\0\0 +. +Not all unix operating systems support library unloading. Under such +an operating system \fBunload\fR returns an error (unless \fB\-nocomplain\fR +has been specified). +.SH BUGS +.PP +If the same file is \fBload\fRed by different \fIfileName\fRs, it will +be loaded into the process's address space multiple times. The +behavior of this varies from system to system (some systems may +detect the redundant loads, others may not). In case a library has been +silently detached by the operating system (and as a result Tcl thinks the +library is still loaded), it may be dangerous to use +\fBunload\fR on such a library (as the library will be completely detached +from the application while some interpreters will continue to use it). +.SH EXAMPLE +.PP +If an unloadable module in the file \fBfoobar.dll\fR had been loaded +using the \fBload\fR command like this (on Windows): +.PP +.CS +load c:/some/dir/foobar.dll +.CE +.PP +then it would be unloaded like this: +.PP +.CS +\fBunload\fR c:/some/dir/foobar.dll +.CE +.PP +This allows a C code module to be installed temporarily into a +long-running Tcl program and then removed again (either because it is +no longer needed or because it is being updated with a new version) +without having to shut down the overall Tcl process. +.SH "SEE ALSO" +info sharedlibextension, load(n), safe(n) +.SH KEYWORDS +binary code, unloading, safe interpreter, shared library +.\" Local Variables: +.\" mode: nroff +.\" End: diff --git a/tcl8.6/doc/unset.n b/tcl8.6/doc/unset.n new file mode 100644 index 0000000..2cfc63e --- /dev/null +++ b/tcl8.6/doc/unset.n @@ -0,0 +1,68 @@ +'\" +'\" Copyright (c) 1993 The Regents of the University of California. +'\" Copyright (c) 1994-1996 Sun Microsystems, Inc. +'\" Copyright (c) 2000 Ajuba Solutions. +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH unset n 8.4 Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +unset \- Delete variables +.SH SYNOPSIS +\fBunset \fR?\fB\-nocomplain\fR? ?\fB\-\-\fR? ?\fIname name name ...\fR? +.BE +.SH DESCRIPTION +.PP +This command removes one or more variables. +Each \fIname\fR is a variable name, specified in any of the +ways acceptable to the \fBset\fR command. +If a \fIname\fR refers to an element of an array then that +element is removed without affecting the rest of the array. +If a \fIname\fR consists of an array name with no parenthesized +index, then the entire array is deleted. +The \fBunset\fR command returns an empty string as result. +If \fB\-nocomplain\fR is specified as the first argument, any possible +errors are suppressed. The option may not be abbreviated, in order to +disambiguate it from possible variable names. The option \fB\-\-\fR +indicates the end of the options, and should be used if you wish to +remove a variable with the same name as any of the options. +If an error occurs during variable deletion, any variables after the named one +causing the error are not +deleted. An error can occur when the named variable does not exist, or the +name refers to an array element but the variable is a scalar, or the name +refers to a variable in a non-existent namespace. +.SH EXAMPLE +.PP +Create an array containing a mapping from some numbers to their +squares and remove the array elements for non-prime numbers: +.PP +.CS +array set squares { + 1 1 6 36 + 2 4 7 49 + 3 9 8 64 + 4 16 9 81 + 5 25 10 100 +} + +puts "The squares are:" +parray squares + +\fBunset\fR squares(1) squares(4) squares(6) +\fBunset\fR squares(8) squares(9) squares(10) + +puts "The prime squares are:" +parray squares +.CE +.SH "SEE ALSO" +set(n), trace(n), upvar(n) +.SH KEYWORDS +remove, variable +'\" Local Variables: +'\" mode: nroff +'\" fill-column: 78 +'\" End: diff --git a/tcl8.6/doc/update.n b/tcl8.6/doc/update.n new file mode 100644 index 0000000..ce0fb25 --- /dev/null +++ b/tcl8.6/doc/update.n @@ -0,0 +1,65 @@ +'\" +'\" Copyright (c) 1990-1992 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. +'\" +.TH update n 7.5 Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +update \- Process pending events and idle callbacks +.SH SYNOPSIS +\fBupdate\fR ?\fBidletasks\fR? +.BE +.SH DESCRIPTION +.PP +This command is used to bring the application +.QW "up to date" +by entering the event loop repeatedly until all pending events +(including idle callbacks) have been processed. +.PP +If the \fBidletasks\fR keyword is specified as an argument to the +command, then no new events or errors are processed; only idle +callbacks are invoked. +This causes operations that are normally deferred, such as display +updates and window layout calculations, to be performed immediately. +.PP +The \fBupdate idletasks\fR command is useful in scripts where +changes have been made to the application's state and you want those +changes to appear on the display immediately, rather than waiting +for the script to complete. Most display updates are performed as +idle callbacks, so \fBupdate idletasks\fR will cause them to run. +However, there are some kinds of updates that only happen in +response to events, such as those triggered by window size changes; +these updates will not occur in \fBupdate idletasks\fR. +.PP +The \fBupdate\fR command with no options is useful in scripts where +you are performing a long-running computation but you still want +the application to respond to events such as user interactions; if +you occasionally call \fBupdate\fR then user input will be processed +during the next call to \fBupdate\fR. +.SH EXAMPLE +.PP +Run computations for about a second and then finish: +.PP +.CS +set x 1000 +set done 0 +after 1000 set done 1 +while {!$done} { + # A very silly example! + set x [expr {log($x) ** 2.8}] + + # Test to see if our time-limit has been hit. This would + # also give a chance for serving network sockets and, if + # the Tk package is loaded, updating a user interface. + \fBupdate\fR +} +.CE +.SH "SEE ALSO" +after(n), interp(n) +.SH KEYWORDS +asynchronous I/O, event, flush, handler, idle, update diff --git a/tcl8.6/doc/uplevel.n b/tcl8.6/doc/uplevel.n new file mode 100644 index 0000000..4decc6d --- /dev/null +++ b/tcl8.6/doc/uplevel.n @@ -0,0 +1,103 @@ +'\" +'\" Copyright (c) 1993 The Regents of the University of California. +'\" Copyright (c) 1994-1997 Sun Microsystems, Inc. +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH uplevel n "" Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +uplevel \- Execute a script in a different stack frame +.SH SYNOPSIS +\fBuplevel \fR?\fIlevel\fR?\fI arg \fR?\fIarg ...\fR? +.BE +.SH DESCRIPTION +.PP +All of the \fIarg\fR arguments are concatenated as if they had +been passed to \fBconcat\fR; the result is then evaluated in the +variable context indicated by \fIlevel\fR. \fBUplevel\fR returns +the result of that evaluation. +.PP +If \fIlevel\fR is an integer then +it gives a distance (up the procedure calling stack) to move before +executing the command. If \fIlevel\fR consists of \fB#\fR followed by +a number then the number gives an absolute level number. If \fIlevel\fR +is omitted then it defaults to \fB1\fR. \fILevel\fR cannot be +defaulted if the first \fIcommand\fR argument starts with a digit or \fB#\fR. +.PP +For example, suppose that procedure \fBa\fR was invoked +from top-level, and that it called \fBb\fR, and that \fBb\fR called \fBc\fR. +Suppose that \fBc\fR invokes the \fBuplevel\fR command. If \fIlevel\fR +is \fB1\fR or \fB#2\fR or omitted, then the command will be executed +in the variable context of \fBb\fR. If \fIlevel\fR is \fB2\fR or \fB#1\fR +then the command will be executed in the variable context of \fBa\fR. +If \fIlevel\fR is \fB3\fR or \fB#0\fR then the command will be executed +at top-level (only global variables will be visible). +.PP +The \fBuplevel\fR command causes the invoking procedure to disappear +from the procedure calling stack while the command is being executed. +In the above example, suppose \fBc\fR invokes the command +.PP +.CS +\fBuplevel\fR 1 {set x 43; d} +.CE +.PP +where \fBd\fR is another Tcl procedure. The \fBset\fR command will +modify the variable \fBx\fR in \fBb\fR's context, and \fBd\fR will execute +at level 3, as if called from \fBb\fR. If it in turn executes +the command +.PP +.CS +\fBuplevel\fR {set x 42} +.CE +.PP +then the \fBset\fR command will modify the same variable \fBx\fR in \fBb\fR's +context: the procedure \fBc\fR does not appear to be on the call stack +when \fBd\fR is executing. The \fBinfo level\fR command may +be used to obtain the level of the current procedure. +.PP +\fBUplevel\fR makes it possible to implement new control +constructs as Tcl procedures (for example, \fBuplevel\fR could +be used to implement the \fBwhile\fR construct as a Tcl procedure). +.PP +The \fBnamespace eval\fR and \fBapply\fR commands offer other ways +(besides procedure calls) that the Tcl naming context can change. +They add a call frame to the stack to represent the namespace context. +This means each \fBnamespace eval\fR command +counts as another call level for \fBuplevel\fR and \fBupvar\fR commands. +For example, \fBinfo level 1\fR will return a list +describing a command that is either +the outermost procedure call or the outermost \fBnamespace eval\fR command. +Also, \fBuplevel #0\fR evaluates a script +at top-level in the outermost namespace (the global namespace). +.SH EXAMPLE +As stated above, the \fBuplevel\fR command is useful for creating new +control constructs. This example shows how (without error handling) +it can be used to create a \fBdo\fR command that is the counterpart of +\fBwhile\fR except for always performing the test after running the +loop body: +.PP +.CS +proc do {body while condition} { + if {$while ne "while"} { + error "required word missing" + } + set conditionCmd [list expr $condition] + while {1} { + \fBuplevel\fR 1 $body + if {![\fBuplevel\fR 1 $conditionCmd]} { + break + } + } +} +.CE +.SH "SEE ALSO" +apply(n), namespace(n), upvar(n) +.SH KEYWORDS +context, level, namespace, stack frame, variable +.\" Local Variables: +.\" mode: nroff +.\" End: diff --git a/tcl8.6/doc/upvar.n b/tcl8.6/doc/upvar.n new file mode 100644 index 0000000..91defe6 --- /dev/null +++ b/tcl8.6/doc/upvar.n @@ -0,0 +1,122 @@ +'\" +'\" Copyright (c) 1993 The Regents of the University of California. +'\" Copyright (c) 1994-1997 Sun Microsystems, Inc. +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH upvar n "" Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +upvar \- Create link to variable in a different stack frame +.SH SYNOPSIS +\fBupvar \fR?\fIlevel\fR? \fIotherVar myVar \fR?\fIotherVar myVar \fR...? +.BE + +.SH DESCRIPTION +.PP +This command arranges for one or more local variables in the current +procedure to refer to variables in an enclosing procedure call or +to global variables. +\fILevel\fR may have any of the forms permitted for the \fBuplevel\fR +command, and may be omitted (it defaults to \fB1\fR). +For each \fIotherVar\fR argument, \fBupvar\fR makes the variable +by that name in the procedure frame given by \fIlevel\fR (or at +global level, if \fIlevel\fR is \fB#0\fR) accessible +in the current procedure by the name given in the corresponding +\fImyVar\fR argument. +The variable named by \fIotherVar\fR need not exist at the time of the +call; it will be created the first time \fImyVar\fR is referenced, just like +an ordinary variable. There must not exist a variable by the +name \fImyVar\fR at the time \fBupvar\fR is invoked. +\fIMyVar\fR is always treated as the name of a variable, not an +array element. An error is returned if the name looks like an array element, +such as \fBa(b)\fR. +\fIOtherVar\fR may refer to a scalar variable, an array, +or an array element. +\fBUpvar\fR returns an empty string. +.PP +The \fBupvar\fR command simplifies the implementation of call-by-name +procedure calling and also makes it easier to build new control constructs +as Tcl procedures. +For example, consider the following procedure: +.PP +.CS +proc \fIadd2\fR name { + \fBupvar\fR $name x + set x [expr {$x + 2}] +} +.CE +.PP +If \fIadd2\fR is invoked with an argument giving the name of a variable, +it adds two to the value of that variable. +Although \fIadd2\fR could have been implemented using \fBuplevel\fR +instead of \fBupvar\fR, \fBupvar\fR makes it simpler for \fIadd2\fR +to access the variable in the caller's procedure frame. +.PP +\fBnamespace eval\fR is another way (besides procedure calls) +that the Tcl naming context can change. +It adds a call frame to the stack to represent the namespace context. +This means each \fBnamespace eval\fR command +counts as another call level for \fBuplevel\fR and \fBupvar\fR commands. +For example, \fBinfo level\fR \fB1\fR will return a list +describing a command that is either +the outermost procedure call or the outermost \fBnamespace eval\fR command. +Also, \fBuplevel #0\fR evaluates a script +at top-level in the outermost namespace (the global namespace). +.PP +If an upvar variable is unset (e.g. \fBx\fR in \fBadd2\fR above), the +\fBunset\fR operation affects the variable it is linked to, not the +upvar variable. There is no way to unset an upvar variable except +by exiting the procedure in which it is defined. However, it is +possible to retarget an upvar variable by executing another \fBupvar\fR +command. +.SH "TRACES AND UPVAR" +.PP +Upvar interacts with traces in a straightforward but possibly +unexpected manner. If a variable trace is defined on \fIotherVar\fR, that +trace will be triggered by actions involving \fImyVar\fR. However, +the trace procedure will be passed the name of \fImyVar\fR, rather +than the name of \fIotherVar\fR. Thus, the output of the following code +will be +.QW "\fIlocalVar\fR" +rather than +.QW "\fIoriginalVar\fR" : +.PP +.CS +proc \fItraceproc\fR { name index op } { + puts $name +} +proc \fIsetByUpvar\fR { name value } { + \fBupvar\fR $name localVar + set localVar $value +} +set originalVar 1 +trace variable originalVar w \fItraceproc\fR +\fIsetByUpvar\fR originalVar 2 +.CE +.PP +If \fIotherVar\fR refers to an element of an array, then variable +traces set for the entire array will not be invoked when \fImyVar\fR +is accessed (but traces on the particular element will still be +invoked). In particular, if the array is \fBenv\fR, then changes +made to \fImyVar\fR will not be passed to subprocesses correctly. +.SH EXAMPLE +A \fBdecr\fR command that works like \fBincr\fR except it subtracts +the value from the variable instead of adding it: +.PP +.CS +proc decr {varName {decrement 1}} { + \fBupvar\fR 1 $varName var + incr var [expr {-$decrement}] +} +.CE +.SH "SEE ALSO" +global(n), namespace(n), uplevel(n), variable(n) +.SH KEYWORDS +context, frame, global, level, namespace, procedure, upvar, variable +.\" Local Variables: +.\" mode: nroff +.\" End: diff --git a/tcl8.6/doc/variable.n b/tcl8.6/doc/variable.n new file mode 100644 index 0000000..8228859 --- /dev/null +++ b/tcl8.6/doc/variable.n @@ -0,0 +1,105 @@ +'\" +'\" Copyright (c) 1993-1997 Bell Labs Innovations for Lucent Technologies +'\" Copyright (c) 1997 Sun Microsystems, Inc. +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH variable n 8.0 Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +variable \- create and initialize a namespace variable +.SH SYNOPSIS +\fBvariable \fR\fIname\fR +.sp +\fBvariable \fR?\fIname value...\fR? +.BE +.SH DESCRIPTION +.PP +This command is normally used within a +\fBnamespace eval\fR command to create one or more variables +within a namespace. +Each variable \fIname\fR is initialized with \fIvalue\fR. +The \fIvalue\fR for the last variable is optional. +.PP +If a variable \fIname\fR does not exist, it is created. +In this case, if \fIvalue\fR is specified, +it is assigned to the newly created variable. +If no \fIvalue\fR is specified, the new variable is left undefined. +If the variable already exists, +it is set to \fIvalue\fR if \fIvalue\fR is specified +or left unchanged if no \fIvalue\fR is given. +Normally, \fIname\fR is unqualified +(does not include the names of any containing namespaces), +and the variable is created in the current namespace. +If \fIname\fR includes any namespace qualifiers, +the variable is created in the specified namespace. If the variable +is not defined, it will be visible to the \fBnamespace which\fR +command, but not to the \fBinfo exists\fR command. +.PP +If the \fBvariable\fR command is executed inside a Tcl procedure, +it creates local variables +linked to the corresponding namespace variables (and therefore these +variables are listed by \fBinfo vars\fR.) +In this way the \fBvariable\fR command resembles the \fBglobal\fR command, +although the \fBglobal\fR command +resolves variable names with respect to the global namespace instead +of the current namespace of the procedure. +If any \fIvalue\fRs are given, +they are used to modify the values of the associated namespace variables. +If a namespace variable does not exist, +it is created and optionally initialized. +.PP +A \fIname\fR argument cannot reference an element within an array. +Instead, \fIname\fR should reference the entire array, +and the initialization \fIvalue\fR should be left off. +After the variable has been declared, +elements within the array can be set using ordinary +\fBset\fR or \fBarray\fR commands. +.SH EXAMPLES +.PP +Create a variable in a namespace: +.PP +.CS +namespace eval foo { + \fBvariable\fR bar 12345 +} +.CE +.PP +Create an array in a namespace: +.PP +.CS +namespace eval someNS { + \fBvariable\fR someAry + array set someAry { + someName someValue + otherName otherValue + } +} +.CE +.PP +Access variables in namespaces from a procedure: +.PP +.CS +namespace eval foo { + proc spong {} { + # Variable in this namespace + \fBvariable\fR bar + puts "bar is $bar" + + # Variable in another namespace + \fBvariable\fR ::someNS::someAry + parray someAry + } +} +.CE +.SH "SEE ALSO" +global(n), namespace(n), upvar(n) +.SH KEYWORDS +global, namespace, procedure, variable +.\" Local variables: +.\" mode: nroff +.\" fill-column: 78 +.\" End: diff --git a/tcl8.6/doc/vwait.n b/tcl8.6/doc/vwait.n new file mode 100644 index 0000000..f64d39c --- /dev/null +++ b/tcl8.6/doc/vwait.n @@ -0,0 +1,246 @@ +'\" +'\" Copyright (c) 1995-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. +'\" +.TH vwait n 8.0 Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +vwait \- Process events until a variable is written +.SH SYNOPSIS +\fBvwait\fR \fIvarName\fR +.BE +.SH DESCRIPTION +.PP +This command enters the Tcl event loop to process events, blocking +the application if no events are ready. It continues processing +events until some event handler sets the value of the global variable +\fIvarName\fR. Once \fIvarName\fR has been set, the \fBvwait\fR +command will return as soon as the event handler that modified +\fIvarName\fR completes. The \fIvarName\fR argument is always interpreted as +a variable name with respect to the global namespace, but can refer to any +namespace's variables if the fully-qualified name is given. +.PP +In some cases the \fBvwait\fR command may not return immediately +after \fIvarName\fR is set. This happens if the event handler +that sets \fIvarName\fR does not complete immediately. For example, +if an event handler sets \fIvarName\fR and then itself calls +\fBvwait\fR to wait for a different variable, then it may not return +for a long time. During this time the top-level \fBvwait\fR is +blocked waiting for the event handler to complete, so it cannot +return either. (See the \fBNESTED VWAITS BY EXAMPLE\fR below.) +.PP +To be clear, \fImultiple \fBvwait\fI calls will nest and will not happen in +parallel\fR. The outermost call to \fBvwait\fR will not return until all the +inner ones do. It is recommended that code should never nest \fBvwait\fR +calls (by avoiding putting them in event callbacks) but when that is not +possible, care should be taken to add interlock variables to the code to +prevent all reentrant calls to \fBvwait\fR that are not \fIstrictly\fR +necessary. Be aware that the synchronous modes of operation of some Tcl +packages (e.g.,\ \fBhttp\fR) use \fBvwait\fR internally; if using the event +loop, it is best to use the asynchronous callback-based modes of operation of +those packages where available. +.SH EXAMPLES +.PP +Run the event-loop continually until some event calls \fBexit\fR. +(You can use any variable not mentioned elsewhere, but the name +\fIforever\fR reminds you at a glance of the intent.) +.PP +.CS +\fBvwait\fR forever +.CE +.PP +Wait five seconds for a connection to a server socket, otherwise +close the socket and continue running the script: +.PP +.CS +# Initialise the state +after 5000 set state timeout +set server [socket -server accept 12345] +proc accept {args} { + global state connectionInfo + set state accepted + set connectionInfo $args +} + +# Wait for something to happen +\fBvwait\fR state + +# Clean up events that could have happened +close $server +after cancel set state timeout + +# Do something based on how the vwait finished... +switch $state { + timeout { + puts "no connection on port 12345" + } + accepted { + puts "connection: $connectionInfo" + puts [lindex $connectionInfo 0] "Hello there!" + } +} +.CE +.PP +A command that will wait for some time delay by waiting for a namespace +variable to be set. Includes an interlock to prevent nested waits. +.PP +.CS +namespace eval example { + variable v done + proc wait {delay} { + variable v + if {$v ne "waiting"} { + set v waiting + after $delay [namespace code {set v done}] + \fBvwait\fR [namespace which -variable v] + } + return $v + } +} +.CE +.PP +When running inside a \fBcoroutine\fR, an alternative to using \fBvwait\fR is +to \fByield\fR to an outer event loop and to get recommenced when the variable +is set, or at an idle moment after that. +.PP +.CS +coroutine task apply {{} { + # simulate [after 1000] + after 1000 [info coroutine] + yield + + # schedule the setting of a global variable, as normal + after 2000 {set var 1} + + # simulate [\fBvwait\fR var] + proc updatedVar {task args} { + after idle $task + trace remove variable ::var write "updatedVar $task" + } + trace add variable ::var write "updatedVar [info coroutine]" + yield +}} +.CE +.SS "NESTED VWAITS BY EXAMPLE" +.PP +This example demonstrates what can happen when the \fBvwait\fR command is +nested. The script will never finish because the waiting for the \fIa\fR +variable never finishes; that \fBvwait\fR command is still waiting for a +script scheduled with \fBafter\fR to complete, which just happens to be +running an inner \fBvwait\fR (for \fIb\fR) even though the event that the +outer \fBvwait\fR was waiting for (the setting of \fIa\fR) has occurred. +.PP +.CS +after 500 { + puts "waiting for b" + \fBvwait\fR b + puts "b was set" +} +after 1000 { + puts "setting a" + set a 10 +} +puts "waiting for a" +\fBvwait\fR a +puts "a was set" +puts "setting b" +set b 42 +.CE +.PP +If you run the above code, you get this output: +.PP +.CS +waiting for a +waiting for b +setting a +.CE +.PP +The script will never print +.QW "a was set" +until after it has printed +.QW "b was set" +because of the nesting of \fBvwait\fR commands, and yet \fIb\fR will not be +set until after the outer \fBvwait\fR returns, so the script has deadlocked. +The only ways to avoid this are to either structure the overall program in +continuation-passing style or to use \fBcoroutine\fR to make the continuations +implicit. The first of these options would be written as: +.PP +.CS +after 500 { + puts "waiting for b" + trace add variable b write {apply {args { + global a b + trace remove variable ::b write \e + [lrange [info level 0] 0 1] + puts "b was set" + set ::done ok + }}} +} +after 1000 { + puts "setting a" + set a 10 +} +puts "waiting for a" +trace add variable a write {apply {args { + global a b + trace remove variable a write [lrange [info level 0] 0 1] + puts "a was set" + puts "setting b" + set b 42 +}}} +\fBvwait\fR done +.CE +.PP +The second option, with \fBcoroutine\fR and some helper procedures, is done +like this: +.PP +.CS +# A coroutine-based wait-for-variable command +proc waitvar globalVar { + trace add variable ::$globalVar write \e + [list apply {{v c args} { + trace remove variable $v write \e + [lrange [info level 0] 0 3] + after 0 $c + }} ::$globalVar [info coroutine]] + yield +} +# A coroutine-based wait-for-some-time command +proc waittime ms { + after $ms [info coroutine] + yield +} + +coroutine task-1 eval { + puts "waiting for a" + waitvar a + puts "a was set" + puts "setting b" + set b 42 +} +coroutine task-2 eval { + waittime 500 + puts "waiting for b" + waitvar b + puts "b was set" + set done ok +} +coroutine task-3 eval { + waittime 1000 + puts "setting a" + set a 10 +} +\fBvwait\fR done +.CE +.SH "SEE ALSO" +global(n), update(n) +.SH KEYWORDS +asynchronous I/O, event, variable, wait +'\" Local Variables: +'\" mode: nroff +'\" fill-column: 78 +'\" End: diff --git a/tcl8.6/doc/while.n b/tcl8.6/doc/while.n new file mode 100644 index 0000000..961260c --- /dev/null +++ b/tcl8.6/doc/while.n @@ -0,0 +1,65 @@ +'\" +'\" Copyright (c) 1993 The Regents of the University of California. +'\" Copyright (c) 1994-1997 Sun Microsystems, Inc. +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH while n "" Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +while \- Execute script repeatedly as long as a condition is met +.SH SYNOPSIS +\fBwhile \fItest body\fR +.BE +.SH DESCRIPTION +.PP +The \fBwhile\fR command evaluates \fItest\fR as an expression +(in the same way that \fBexpr\fR evaluates its argument). +The value of the expression must a proper boolean +value; if it is a true value +then \fIbody\fR is executed by passing it to the Tcl interpreter. +Once \fIbody\fR has been executed then \fItest\fR is evaluated +again, and the process repeats until eventually \fItest\fR +evaluates to a false boolean value. \fBContinue\fR +commands may be executed inside \fIbody\fR to terminate the current +iteration of the loop, and \fBbreak\fR +commands may be executed inside \fIbody\fR to cause immediate +termination of the \fBwhile\fR command. The \fBwhile\fR command +always returns an empty string. +.PP +Note: \fItest\fR should almost always be enclosed in braces. If not, +variable substitutions will be made before the \fBwhile\fR +command starts executing, which means that variable changes +made by the loop body will not be considered in the expression. +This is likely to result in an infinite loop. If \fItest\fR is +enclosed in braces, variable substitutions are delayed until the +expression is evaluated (before +each loop iteration), so changes in the variables will be visible. +For an example, try the following script with and without the braces +around \fB$x<10\fR: +.PP +.CS +set x 0 +\fBwhile\fR {$x<10} { + puts "x is $x" + incr x +} +.CE +.SH EXAMPLE +.PP +Read lines from a channel until we get to the end of the stream, and +print them out with a line-number prepended: +.PP +.CS +set lineCount 0 +\fBwhile\fR {[gets $chan line] >= 0} { + puts "[incr lineCount]: $line" +} +.CE +.SH "SEE ALSO" +break(n), continue(n), for(n), foreach(n) +.SH KEYWORDS +boolean, loop, test, while diff --git a/tcl8.6/doc/zlib.n b/tcl8.6/doc/zlib.n new file mode 100644 index 0000000..fd29e0d --- /dev/null +++ b/tcl8.6/doc/zlib.n @@ -0,0 +1,466 @@ +'\" +'\" Copyright (c) 2008-2012 Donal K. Fellows +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH zlib n 8.6 Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +zlib \- compression and decompression operations +.SH SYNOPSIS +.nf +\fBzlib \fIsubcommand arg ...\fR +.fi +.BE +.SH DESCRIPTION +.PP +The \fBzlib\fR command provides access to the compression and check-summing +facilities of the Zlib library by Jean-loup Gailly and Mark Adler. It has the +following subcommands. +.SS "COMPRESSION SUBCOMMANDS" +.TP +\fBzlib compress\fI string\fR ?\fIlevel\fR? +. +Returns the zlib-format compressed binary data of the binary string in +\fIstring\fR. If present, \fIlevel\fR gives the compression level to use (from +0, which is uncompressed, to 9, maximally compressed). +.TP +\fBzlib decompress\fI string\fR ?\fIbufferSize\fR? +. +Returns the uncompressed version of the raw compressed binary data in +\fIstring\fR. If present, \fIbufferSize\fR is a hint as to what size of buffer +is to be used to receive the data. +.TP +\fBzlib deflate\fI string\fR ?\fIlevel\fR? +. +Returns the raw compressed binary data of the binary string in \fIstring\fR. +If present, \fIlevel\fR gives the compression level to use (from 0, which is +uncompressed, to 9, maximally compressed). +.TP +\fBzlib gunzip\fI string\fR ?\fB\-headerVar \fIvarName\fR? +. +Return the uncompressed contents of binary string \fIstring\fR, which must +have been in gzip format. If \fB\-headerVar\fR is given, store a dictionary +describing the contents of the gzip header in the variable called +\fIvarName\fR. The keys of the dictionary that may be present are: +.RS +.TP +\fBcomment\fR +. +The comment field from the header, if present. +.TP +\fBcrc\fR +. +A boolean value describing whether a CRC of the header is computed. +.TP +\fBfilename\fR +. +The filename field from the header, if present. +.TP +\fBos\fR +. +The operating system type code field from the header (if not the +QW unknown +value). See RFC 1952 for the meaning of these codes. +.TP +\fBsize\fR +. +The size of the uncompressed data. +.TP +\fBtime\fR +. +The time field from the header if non-zero, expected to be time that the file +named by the \fBfilename\fR field was modified. Suitable for use with +\fBclock format\fR. +.TP +\fBtype\fR +. +The type of the uncompressed data (\fBbinary\fR or \fBtext\fR) if known. +.RE +.TP +\fBzlib gzip\fI string\fR ?\fB\-level \fIlevel\fR? ?\fB\-header \fIdict\fR? +. +Return the compressed contents of binary string \fIstring\fR in gzip format. +If \fB\-level\fR is given, \fIlevel\fR gives the compression level to use +(from 0, which is uncompressed, to 9, maximally compressed). If \fB\-header\fR +is given, \fIdict\fR is a dictionary containing values used for the gzip +header. The following keys may be defined: +.RS +.TP +\fBcomment\fR +. +Add the given comment to the header of the gzip-format data. +.TP +\fBcrc\fR +. +A boolean saying whether to compute a CRC of the header. Note that if the data +is to be interchanged with the \fBgzip\fR program, a header CRC should +\fInot\fR be computed. +.TP +\fBfilename\fR +. +The name of the file that the data to be compressed came from. +.TP +\fBos\fR +. +The operating system type code, which should be one of the values described in +RFC 1952. +.TP +\fBtime\fR +. +The time that the file named in the \fBfilename\fR key was last modified. This +will be in the same as is returned by \fBclock seconds\fR or \fBfile mtime\fR. +.TP +\fBtype\fR +. +The type of the data being compressed, being \fBbinary\fR or \fBtext\fR. +.RE +.TP +\fBzlib inflate\fI string\fR ?\fIbufferSize\fR? +. +Returns the uncompressed version of the raw compressed binary data in +\fIstring\fR. If present, \fIbufferSize\fR is a hint as to what size of buffer +is to be used to receive the data. +.SS "CHANNEL SUBCOMMAND" +.TP +\fBzlib push\fI mode channel\fR ?\fIoptions ...\fR? +. +Pushes a compressing or decompressing transformation onto the channel +\fIchannel\fR. +The transformation can be removed again with \fBchan pop\fR. +The \fImode\fR argument determines what type of transformation +is pushed; the following are supported: +.RS +.TP +\fBcompress\fR +. +The transformation will be a compressing transformation that produces +zlib-format data on \fIchannel\fR, which must be writable. +.TP +\fBdecompress\fR +. +The transformation will be a decompressing transformation that reads +zlib-format data from \fIchannel\fR, which must be readable. +.TP +\fBdeflate\fR +. +The transformation will be a compressing transformation that produces raw +compressed data on \fIchannel\fR, which must be writable. +.TP +\fBgunzip\fR +. +The transformation will be a decompressing transformation that reads +gzip-format data from \fIchannel\fR, which must be readable. +.TP +\fBgzip\fR +. +The transformation will be a compressing transformation that produces +gzip-format data on \fIchannel\fR, which must be writable. +.TP +\fBinflate\fR +. +The transformation will be a decompressing transformation that reads raw +compressed data from \fIchannel\fR, which must be readable. +.PP +The following options may be set when creating a transformation via +the +.QW "\fIoptions ...\fR" +to the \fBzlib push\fR command: +.TP +\fB\-dictionary\fI binData\fR +.VS "TIP 400" +Sets the compression dictionary to use when working with compressing or +decompressing the data to be \fIbinData\fR. Not valid for transformations that +work with gzip-format data. The dictionary should consist of strings (byte +sequences) that are likely to be encountered later in the data to be compressed, +with the most commonly used strings preferably put towards the end of the +dictionary. Tcl provides no mechanism for choosing a good such dictionary for +a particular data sequence. +.VE +.TP +\fB\-header\fI dictionary\fR +. +Passes a description of the gzip header to create, in the same format that +\fBzlib gzip\fR understands. +.TP +\fB\-level\fI compressionLevel\fR +. +How hard to compress the data. Must be an integer from 0 (uncompressed) to 9 +(maximally compressed). +.TP +\fB\-limit\fI readaheadLimit\fR +. +The maximum number of bytes ahead to read when decompressing. This defaults to +1, which ensures that data is always decompressed correctly, but may be +increased to improve performance. This is more useful when the channel is +non-blocking. +.PP +Both compressing and decompressing channel transformations add extra +configuration options that may be accessed through \fBchan configure\fR. The +options are: +.TP +\fB\-checksum\fI checksum\fR +. +This read-only option gets the current checksum for the uncompressed data that +the compression engine has seen so far. It is valid for both compressing and +decompressing transforms, but not for the raw inflate and deflate formats. The +compression algorithm depends on what format is being produced or consumed. +.TP +\fB\-dictionary\fI binData\fR +.VS "TIP 400" +This read-write options gets or sets the initial compression dictionary to use +when working with compressing or decompressing the data to be \fIbinData\fR. +It is not valid for transformations that work with gzip-format data, and should +not normally be set on compressing transformations other than at the point where +the transformation is stacked. Note that this cannot be used to get the +current active compression dictionary mid-stream, as that information is not +exposed by the underlying library. +.VE +.TP +\fB\-flush\fI type\fR +. +This write-only operation flushes the current state of the compressor to the +underlying channel. It is only valid for compressing transformations. The +\fItype\fR must be either \fBsync\fR or \fBfull\fR for a normal flush or an +expensive flush respectively. Flushing degrades the compression ratio, but +makes it easier for a decompressor to recover more of the file in the case of +data corruption. +.TP +\fB\-header\fI dictionary\fR +. +This read-only option, only valid for decompressing transforms that are +processing gzip-format data, returns the dictionary describing the header read +off the data stream. +.TP +\fB\-limit\fI readaheadLimit\fR +. +This read-write option is used by decompressing channels to control the +maximum number of bytes ahead to read from the underlying data source. This +defaults to 1, which ensures that data is always decompressed correctly, but +may be increased to improve performance. This is more useful when the channel +is non-blocking. +.RE +.SS "STREAMING SUBCOMMAND" +.TP +\fBzlib stream\fI mode\fR ?\fIoptions\fR? +. +Creates a streaming compression or decompression command based on the +\fImode\fR, and return the name of the command. For a description of how that +command works, see \fBSTREAMING INSTANCE COMMAND\fR below. The following modes +and \fIoptions\fR are supported: +.RS +.TP +\fBzlib stream compress\fR ?\fB\-dictionary \fIbindata\fR? ?\fB\-level \fIlevel\fR? +. +The stream will be a compressing stream that produces zlib-format output, +using compression level \fIlevel\fR (if specified) which will be an integer +from 0 to 9, +.VS "TIP 400" +and the compression dictionary \fIbindata\fR (if specified). +.VE +.TP +\fBzlib stream decompress\fR ?\fB\-dictionary \fIbindata\fR? +. +The stream will be a decompressing stream that takes zlib-format input and +produces uncompressed output. +.VS "TIP 400" +If \fIbindata\fR is supplied, it is a compression dictionary to use if +required. +.VE +.TP +\fBzlib stream deflate\fR ?\fB\-dictionary \fIbindata\fR? ?\fB\-level \fIlevel\fR? +. +The stream will be a compressing stream that produces raw output, using +compression level \fIlevel\fR (if specified) which will be an integer from 0 +to 9, +.VS "TIP 400" +and the compression dictionary \fIbindata\fR (if specified). Note that +the raw compressed data includes no metadata about what compression +dictionary was used, if any; that is a feature of the zlib-format data. +.VE +.TP +\fBzlib stream gunzip\fR +. +The stream will be a decompressing stream that takes gzip-format input and +produces uncompressed output. +.TP +\fBzlib stream gzip\fR ?\fB\-header \fIheader\fR? ?\fB\-level \fIlevel\fR? +. +The stream will be a compressing stream that produces gzip-format output, +using compression level \fIlevel\fR (if specified) which will be an integer +from 0 to 9, and the header descriptor dictionary \fIheader\fR (if specified; +for keys see \fBzlib gzip\fR). +.TP +\fBzlib stream inflate\fR ?\fB\-dictionary \fIbindata\fR? +. +The stream will be a decompressing stream that takes raw compressed input and +produces uncompressed output. +.VS "TIP 400" +If \fIbindata\fR is supplied, it is a compression dictionary to use. Note that +there are no checks in place to determine whether the compression dictionary +is correct. +.VE +.RE +.SS "CHECKSUMMING SUBCOMMANDS" +.TP +\fBzlib adler32\fI string\fR ?\fIinitValue\fR? +. +Compute a checksum of binary string \fIstring\fR using the Adler-32 algorithm. +If given, \fIinitValue\fR is used to initialize the checksum engine. +.TP +\fBzlib crc32\fI string\fR ?\fIinitValue\fR? +. +Compute a checksum of binary string \fIstring\fR using the CRC-32 algorithm. +If given, \fIinitValue\fR is used to initialize the checksum engine. +.SH "STREAMING INSTANCE COMMAND" +.PP +Streaming compression instance commands are produced by the \fBzlib stream\fR +command. They are used by calling their \fBput\fR subcommand one or more times +to load data in, and their \fBget\fR subcommand one or more times to extract +the transformed data. +.PP +The full set of subcommands supported by a streaming instance command, +\fIstream\fR, is as follows: +.TP +\fIstream \fBadd\fR ?\fIoption...\fR? \fIdata\fR +. +A short-cut for +.QW "\fIstream \fBput \fR?\fIoption...\fR? \fIdata\fR" +followed by +.QW "\fIstream \fBget\fR" . +.TP +\fIstream \fBchecksum\fR +. +Returns the checksum of the uncompressed data seen so far by this stream. +.TP +\fIstream \fBclose\fR +. +Deletes this stream and frees up all resources associated with it. +.TP +\fIstream \fBeof\fR +. +Returns a boolean indicating whether the end of the stream (as determined by +the compressed data itself) has been reached. Not all formats support +detection of the end of the stream. +.TP +\fIstream \fBfinalize\fR +. +A short-cut for +.QW "\fIstream \fBput \-finalize {}\fR" . +.TP +\fIstream \fBflush\fR +. +A short-cut for +.QW "\fIstream \fBput \-flush {}\fR" . +.TP +\fIstream \fBfullflush\fR +. +A short-cut for +.QW "\fIstream \fBput \-fullflush {}\fR" . +.TP +\fIstream \fBget \fR?\fIcount\fR? +. +Return up to \fIcount\fR bytes from \fIstream\fR's internal buffers with the +transformation applied. If \fIcount\fR is omitted, the entire contents of the +buffers are returned. +. +\fIstream \fBheader\fR +. +Return the gzip header description dictionary extracted from the stream. Only +supported for streams created with their \fImode\fR parameter set to +\fBgunzip\fR. +.TP +\fIstream \fBput\fR ?\fIoption...\fR? \fIdata\fR +. +Append the contents of the binary string \fIdata\fR to \fIstream\fR's internal +buffers while applying the transformation. The following \fIoption\fRs are +supported (or an unambiguous prefix of them), which are used to modify the +way in which the transformation is applied: +.RS +.TP +\fB\-dictionary\fI binData\fR +.VS "TIP 400" +Sets the compression dictionary to use when working with compressing or +decompressing the data to be \fIbinData\fR. +.VE +.TP +\fB\-finalize\fR +. +Mark the stream as finished, ensuring that all bytes have been wholly +compressed or decompressed. For gzip streams, this also ensures that the +footer is written to the stream. The stream will need to be reset before +having more data written to it after this, though data can still be read out +of the stream with the \fBget\fR subcommand. +.RS +.PP +This option is mutually exclusive with the \fB\-flush\fR and \fB\-fullflush\fR +options. +.RE +.TP +\fB\-flush\fR +. +Ensure that a decompressor consuming the bytes that the current (compressing) +stream is producing will be able to produce all the bytes that have been +compressed so far, at some performance penalty. +.RS +.PP +This option is mutually exclusive with the \fB\-finalize\fR and +\fB\-fullflush\fR options. +.RE +.TP +\fB\-fullflush\fR +. +Ensure that not only can a decompressor handle all the bytes produced so far +(as with \fB\-flush\fR above) but also that it can restart from this point if +it detects that the stream is partially corrupt. This incurs a substantial +performance penalty. +.RS +.PP +This option is mutually exclusive with the \fB\-finalize\fR and \fB\-flush\fR +options. +.RE +.RE +.TP +\fIstream \fBreset\fR +. +Puts any stream, including those that have been finalized or that have reached +eof, back into a state where it can process more data. Throws away all +internally buffered data. +.SH EXAMPLES +.PP +To compress a Tcl string, it should be first converted to a particular charset +encoding since the \fBzlib\fR command always operates on binary strings. +.PP +.CS +set binData [encoding convertto utf-8 $string] +set compData [\fBzlib compress\fR $binData] +.CE +.PP +When converting back, it is also important to reverse the charset encoding: +.PP +.CS +set binData [\fBzlib decompress\fR $compData] +set string [encoding convertfrom utf-8 $binData] +.CE +.PP +The compression operation from above can also be done with streams, which is +especially helpful when you want to accumulate the data by stages: +.PP +.CS +set strm [\fBzlib stream\fR compress] +$\fIstrm \fBput\fR [encoding convertto utf-8 $string] +# ... +$\fIstrm \fBfinalize\fR +set compData [$\fIstrm \fBget\fR] +$\fIstrm \fBclose\fR +.CE +.SH "SEE ALSO" +binary(n), chan(n), encoding(n), Tcl_ZlibDeflate(3), RFC1950 \- RFC1952 +.SH "KEYWORDS" +compress, decompress, deflate, gzip, inflate, zlib +'\" Local Variables: +'\" mode: nroff +'\" End: |