Import Tcl-core 8.6.6 (as of svn r86089)
This commit is contained in:
71
doc/Access.3
Normal file
71
doc/Access.3
Normal file
@@ -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)
|
||||
312
doc/AddErrInfo.3
Normal file
312
doc/AddErrInfo.3
Normal file
@@ -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
|
||||
92
doc/Alloc.3
Normal file
92
doc/Alloc.3
Normal file
@@ -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
|
||||
44
doc/AllowExc.3
Normal file
44
doc/AllowExc.3
Normal file
@@ -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
|
||||
83
doc/AppInit.3
Normal file
83
doc/AppInit.3
Normal file
@@ -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
|
||||
87
doc/AssocData.3
Normal file
87
doc/AssocData.3
Normal file
@@ -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
|
||||
161
doc/Async.3
Normal file
161
doc/Async.3
Normal file
@@ -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
|
||||
78
doc/BackgdErr.3
Normal file
78
doc/BackgdErr.3
Normal file
@@ -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
|
||||
47
doc/Backslash.3
Normal file
47
doc/Backslash.3
Normal file
@@ -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
|
||||
95
doc/BoolObj.3
Normal file
95
doc/BoolObj.3
Normal file
@@ -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
|
||||
91
doc/ByteArrObj.3
Normal file
91
doc/ByteArrObj.3
Normal file
@@ -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
|
||||
67
doc/CallDel.3
Normal file
67
doc/CallDel.3
Normal file
@@ -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
|
||||
74
doc/Cancel.3
Normal file
74
doc/Cancel.3
Normal file
@@ -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
|
||||
97
doc/ChnlStack.3
Normal file
97
doc/ChnlStack.3
Normal file
@@ -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
|
||||
237
doc/Class.3
Normal file
237
doc/Class.3
Normal file
@@ -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:
|
||||
34
doc/CmdCmplt.3
Normal file
34
doc/CmdCmplt.3
Normal file
@@ -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
|
||||
51
doc/Concat.3
Normal file
51
doc/Concat.3
Normal file
@@ -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
|
||||
928
doc/CrtChannel.3
Normal file
928
doc/CrtChannel.3
Normal file
@@ -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
|
||||
89
doc/CrtChnlHdlr.3
Normal file
89
doc/CrtChnlHdlr.3
Normal file
@@ -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.
|
||||
55
doc/CrtCloseHdlr.3
Normal file
55
doc/CrtCloseHdlr.3
Normal file
@@ -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
|
||||
143
doc/CrtCommand.3
Normal file
143
doc/CrtCommand.3
Normal file
@@ -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
|
||||
91
doc/CrtFileHdlr.3
Normal file
91
doc/CrtFileHdlr.3
Normal file
@@ -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
|
||||
150
doc/CrtInterp.3
Normal file
150
doc/CrtInterp.3
Normal file
@@ -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
|
||||
162
doc/CrtMathFnc.3
Normal file
162
doc/CrtMathFnc.3
Normal file
@@ -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
|
||||
302
doc/CrtObjCmd.3
Normal file
302
doc/CrtObjCmd.3
Normal file
@@ -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
|
||||
236
doc/CrtSlave.3
Normal file
236
doc/CrtSlave.3
Normal file
@@ -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
|
||||
76
doc/CrtTimerHdlr.3
Normal file
76
doc/CrtTimerHdlr.3
Normal file
@@ -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
|
||||
191
doc/CrtTrace.3
Normal file
191
doc/CrtTrace.3
Normal file
@@ -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
|
||||
153
doc/DString.3
Normal file
153
doc/DString.3
Normal file
@@ -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
|
||||
75
doc/DetachPids.3
Normal file
75
doc/DetachPids.3
Normal file
@@ -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
|
||||
234
doc/DictObj.3
Normal file
234
doc/DictObj.3
Normal file
@@ -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
|
||||
106
doc/DoOneEvent.3
Normal file
106
doc/DoOneEvent.3
Normal file
@@ -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
|
||||
87
doc/DoWhenIdle.3
Normal file
87
doc/DoWhenIdle.3
Normal file
@@ -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
|
||||
64
doc/DoubleObj.3
Normal file
64
doc/DoubleObj.3
Normal file
@@ -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
|
||||
68
doc/DumpActiveMemory.3
Normal file
68
doc/DumpActiveMemory.3
Normal file
@@ -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
|
||||
|
||||
|
||||
558
doc/Encoding.3
Normal file
558
doc/Encoding.3
Normal file
@@ -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
|
||||
219
doc/Ensemble.3
Normal file
219
doc/Ensemble.3
Normal file
@@ -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
|
||||
38
doc/Environment.3
Normal file
38
doc/Environment.3
Normal file
@@ -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
|
||||
211
doc/Eval.3
Normal file
211
doc/Eval.3
Normal file
@@ -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 then \fBTCL_OK\fR or \fBTCL_ERROR\fR.
|
||||
|
||||
.SH KEYWORDS
|
||||
execute, file, global, result, script, value
|
||||
140
doc/Exit.3
Normal file
140
doc/Exit.3
Normal file
@@ -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
|
||||
106
doc/ExprLong.3
Normal file
106
doc/ExprLong.3
Normal file
@@ -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
|
||||
106
doc/ExprLongObj.3
Normal file
106
doc/ExprLongObj.3
Normal file
@@ -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
|
||||
1644
doc/FileSystem.3
Normal file
1644
doc/FileSystem.3
Normal file
File diff suppressed because it is too large
Load Diff
63
doc/FindExec.3
Normal file
63
doc/FindExec.3
Normal file
@@ -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
|
||||
52
doc/GetCwd.3
Normal file
52
doc/GetCwd.3
Normal file
@@ -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
|
||||
27
doc/GetHostName.3
Normal file
27
doc/GetHostName.3
Normal file
@@ -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
|
||||
104
doc/GetIndex.3
Normal file
104
doc/GetIndex.3
Normal file
@@ -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
|
||||
86
doc/GetInt.3
Normal file
86
doc/GetInt.3
Normal file
@@ -0,0 +1,86 @@
|
||||
'\"
|
||||
'\" 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 by
|
||||
white space. If the first two characters of \fIsrc\fR
|
||||
after the optional white space and sign are
|
||||
.QW 0x
|
||||
then \fIsrc\fR is expected to be in hexadecimal form; otherwise,
|
||||
if the first such character is
|
||||
.QW 0
|
||||
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; a sequence of digits; the letter
|
||||
.QW e ;
|
||||
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 e
|
||||
is present then it must be followed by the exponent number.
|
||||
.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
|
||||
58
doc/GetOpnFl.3
Normal file
58
doc/GetOpnFl.3
Normal file
@@ -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
|
||||
86
doc/GetStdChan.3
Normal file
86
doc/GetStdChan.3
Normal file
@@ -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
|
||||
109
doc/GetTime.3
Normal file
109
doc/GetTime.3
Normal file
@@ -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
|
||||
48
doc/GetVersion.3
Normal file
48
doc/GetVersion.3
Normal file
@@ -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
|
||||
|
||||
334
doc/Hash.3
Normal file
334
doc/Hash.3
Normal file
@@ -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
|
||||
34
doc/Init.3
Normal file
34
doc/Init.3
Normal file
@@ -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
|
||||
89
doc/InitStubs.3
Normal file
89
doc/InitStubs.3
Normal file
@@ -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
|
||||
152
doc/IntObj.3
Normal file
152
doc/IntObj.3
Normal file
@@ -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, \fBint64\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
|
||||
134
doc/Interp.3
Normal file
134
doc/Interp.3
Normal file
@@ -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
|
||||
192
doc/Limit.3
Normal file
192
doc/Limit.3
Normal file
@@ -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
|
||||
207
doc/LinkVar.3
Normal file
207
doc/LinkVar.3
Normal file
@@ -0,0 +1,207 @@
|
||||
'\"
|
||||
'\" 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.
|
||||
.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.
|
||||
.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.
|
||||
.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.
|
||||
.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.
|
||||
.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.
|
||||
.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.
|
||||
.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.
|
||||
.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.
|
||||
.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.
|
||||
.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.
|
||||
.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.
|
||||
.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
|
||||
251
doc/ListObj.3
Normal file
251
doc/ListObj.3
Normal file
@@ -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
|
||||
70
doc/Load.3
Normal file
70
doc/Load.3
Normal file
@@ -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:
|
||||
251
doc/Method.3
Normal file
251
doc/Method.3
Normal file
@@ -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:
|
||||
328
doc/NRE.3
Normal file
328
doc/NRE.3
Normal file
@@ -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
|
||||
165
doc/Namespace.3
Normal file
165
doc/Namespace.3
Normal file
@@ -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
|
||||
635
doc/Notifier.3
Normal file
635
doc/Notifier.3
Normal file
@@ -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
|
||||
54
doc/OOInitStubs.3
Normal file
54
doc/OOInitStubs.3
Normal file
@@ -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:
|
||||
352
doc/Object.3
Normal file
352
doc/Object.3
Normal file
@@ -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 \fIinternalRep.longValue\fR member
|
||||
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
|
||||
256
doc/ObjectType.3
Normal file
256
doc/ObjectType.3
Normal file
@@ -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
|
||||
648
doc/OpenFileChnl.3
Normal file
648
doc/OpenFileChnl.3
Normal file
@@ -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
|
||||
169
doc/OpenTcp.3
Normal file
169
doc/OpenTcp.3
Normal file
@@ -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
|
||||
89
doc/Panic.3
Normal file
89
doc/Panic.3
Normal file
@@ -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
|
||||
198
doc/ParseArgs.3
Normal file
198
doc/ParseArgs.3
Normal file
@@ -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:
|
||||
467
doc/ParseCmd.3
Normal file
467
doc/ParseCmd.3
Normal file
@@ -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
|
||||
97
doc/PkgRequire.3
Normal file
97
doc/PkgRequire.3
Normal file
@@ -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)
|
||||
110
doc/Preserve.3
Normal file
110
doc/Preserve.3
Normal file
@@ -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
|
||||
51
doc/PrintDbl.3
Normal file
51
doc/PrintDbl.3
Normal file
@@ -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
|
||||
53
doc/RecEvalObj.3
Normal file
53
doc/RecEvalObj.3
Normal file
@@ -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
|
||||
55
doc/RecordEval.3
Normal file
55
doc/RecordEval.3
Normal file
@@ -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
|
||||
111
doc/RegConfig.3
Normal file
111
doc/RegConfig.3
Normal file
@@ -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
|
||||
383
doc/RegExp.3
Normal file
383
doc/RegExp.3
Normal file
@@ -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
|
||||
120
doc/SaveResult.3
Normal file
120
doc/SaveResult.3
Normal file
@@ -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 a \fBTcl_SavedResult\fR structure
|
||||
that is used to store enough information to restore the interpreter result.
|
||||
This structure 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
|
||||
140
doc/SetChanErr.3
Normal file
140
doc/SetChanErr.3
Normal file
@@ -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
|
||||
66
doc/SetErrno.3
Normal file
66
doc/SetErrno.3
Normal file
@@ -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
|
||||
53
doc/SetRecLmt.3
Normal file
53
doc/SetRecLmt.3
Normal file
@@ -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
|
||||
255
doc/SetResult.3
Normal file
255
doc/SetResult.3
Normal file
@@ -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
|
||||
249
doc/SetVar.3
Normal file
249
doc/SetVar.3
Normal file
@@ -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
|
||||
41
doc/Signal.3
Normal file
41
doc/Signal.3
Normal file
@@ -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
|
||||
34
doc/Sleep.3
Normal file
34
doc/Sleep.3
Normal file
@@ -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
|
||||
32
doc/SourceRCFile.3
Normal file
32
doc/SourceRCFile.3
Normal file
@@ -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
|
||||
188
doc/SplitList.3
Normal file
188
doc/SplitList.3
Normal file
@@ -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
|
||||
97
doc/SplitPath.3
Normal file
97
doc/SplitPath.3
Normal file
@@ -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
|
||||
70
doc/StaticPkg.3
Normal file
70
doc/StaticPkg.3
Normal file
@@ -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)
|
||||
120
doc/StdChannels.3
Normal file
120
doc/StdChannels.3
Normal file
@@ -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
|
||||
49
doc/StrMatch.3
Normal file
49
doc/StrMatch.3
Normal file
@@ -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
|
||||
387
doc/StringObj.3
Normal file
387
doc/StringObj.3
Normal file
@@ -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
|
||||
68
doc/SubstObj.3
Normal file
68
doc/SubstObj.3
Normal file
@@ -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
|
||||
80
doc/TCL_MEM_DEBUG.3
Normal file
80
doc/TCL_MEM_DEBUG.3
Normal file
@@ -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
|
||||
275
doc/Tcl.n
Normal file
275
doc/Tcl.n
Normal file
@@ -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:
|
||||
276
doc/TclZlib.3
Normal file
276
doc/TclZlib.3
Normal file
@@ -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:
|
||||
196
doc/Tcl_Main.3
Normal file
196
doc/Tcl_Main.3
Normal file
@@ -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
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user