1Tcl_TraceCommand(3)         Tcl Library Procedures         Tcl_TraceCommand(3)
2
3
4
5______________________________________________________________________________
6

NAME

8       Tcl_CommandTraceInfo,  Tcl_TraceCommand,  Tcl_UntraceCommand  - monitor
9       renames and deletes of a command
10

SYNOPSIS

12       #include <tcl.h>
13
14       ClientData
15       Tcl_CommandTraceInfo(interp, cmdName, flags, proc, prevClientData)
16
17       int
18       Tcl_TraceCommand(interp, cmdName, flags, proc, clientData)
19
20       void
21       Tcl_UntraceCommand(interp, cmdName, flags, proc, clientData)
22

ARGUMENTS

24       Tcl_Interp *interp (in)                           Interpreter  contain‐
25                                                         ing the command.
26
27       const char *cmdName (in)                          Name of command.
28
29       int flags (in)                                    OR'ed  collection  of
30                                                         the            values
31                                                         TCL_TRACE_RENAME  and
32                                                         TCL_TRACE_DELETE.
33
34       Tcl_CommandTraceProc *proc (in)                   Procedure   to   call
35                                                         when specified opera‐
36                                                         tions occur  to  cmd‐
37                                                         Name.
38
39       ClientData clientData (in)                        Arbitrary argument to
40                                                         pass to proc.
41
42       ClientData prevClientData (in)                    If  non-NULL,   gives
43                                                         last  value  returned
44                                                         by  Tcl_CommandTrace‐
45                                                         Info,  so  this  call
46                                                         will return  informa‐
47                                                         tion    about    next
48                                                         trace.  If NULL, this
49                                                         call    will   return
50                                                         information     about
51                                                         first trace.
52_________________________________________________________________
53

DESCRIPTION

55       Tcl_TraceCommand  allows  a C procedure to monitor operations performed
56       on a Tcl command, so that the C procedure is invoked whenever the  com‐
57       mand  is renamed or deleted.  If the trace is created successfully then
58       Tcl_TraceCommand returns TCL_OK. If an  error  occurred  (e.g.  cmdName
59       specifies  a  non-existent  command)  then TCL_ERROR is returned and an
60       error message is left in the interpreter's result.
61
62       The flags argument to Tcl_TraceCommand indicates when the trace  proce‐
63       dure  is  to be invoked.  It consists of an OR'ed combination of any of
64       the following values:
65
66       TCL_TRACE_RENAME
67              Invoke proc whenever the command is renamed.
68
69       TCL_TRACE_DELETE
70              Invoke proc when the command is deleted.
71
72       Whenever one of the specified operations occurs to  the  command,  proc
73       will  be  invoked.   It should have arguments and result that match the
74       type Tcl_CommandTraceProc:
75              typedef void Tcl_CommandTraceProc(
76                      ClientData clientData,
77                      Tcl_Interp *interp,
78                      const char *oldName,
79                      const char *newName,
80                      int flags);
81       The clientData and interp parameters will have the same values as those
82       passed to Tcl_TraceCommand when the trace was created.  ClientData typ‐
83       ically points to an application-specific data structure that  describes
84       what to do when proc is invoked.  OldName gives the name of the command
85       being renamed, and newName gives the name that  the  command  is  being
86       renamed  to  (or  an  empty  string  or  NULL when the command is being
87       deleted.)  Flags is an OR'ed combination of bits potentially  providing
88       several  pieces  of  information.  One of the bits TCL_TRACE_RENAME and
89       TCL_TRACE_DELETE will be set in flags to indicate  which  operation  is
90       being  performed  on  the command.  The bit TCL_TRACE_DESTROYED will be
91       set in flags if the trace is about to be  destroyed;  this  information
92       may  be  useful  to  proc so that it can clean up its own internal data
93       structures  (see  the  section  TCL_TRACE_DESTROYED  below   for   more
94       details).   Lastly,  the  bit  TCL_INTERP_DESTROYED  will be set if the
95       entire interpreter is being destroyed.  When this bit is set, proc must
96       be   especially  careful  in  the  things  it  does  (see  the  section
97       TCL_INTERP_DESTROYED below).
98
99       Tcl_UntraceCommand may be used to remove a trace.  If the command spec‐
100       ified  by  interp, cmdName, and flags has a trace set with flags, proc,
101       and clientData, then the corresponding trace is removed.   If  no  such
102       trace  exists,  then the call to Tcl_UntraceCommand has no effect.  The
103       same bits are valid for flags as for calls to Tcl_TraceCommand.
104
105       Tcl_CommandTraceInfo may be used to retrieve information  about  traces
106       set  on a given command.  The return value from Tcl_CommandTraceInfo is
107       the clientData associated with a particular trace.  The trace  must  be
108       on  the  command  specified by the interp, cmdName, and flags arguments
109       (note that currently the flags are ignored; flags should be  set  to  0
110       for  future compatibility) and its trace procedure must the same as the
111       proc argument.  If the prevClientData argument is NULL then the  return
112       value  corresponds to the first (most recently created) matching trace,
113       or NULL if there are no matching traces.  If the  prevClientData  argu‐
114       ment  is  not  NULL, then it should be the return value from a previous
115       call to Tcl_CommandTraceInfo.  In this case, the new return value  will
116       correspond  to  the  next matching trace after the one whose clientData
117       matches prevClientData, or NULL if no trace matches  prevClientData  or
118       if there are no more matching traces after it.  This mechanism makes it
119       possible to step through all of the traces for  a  given  command  that
120       have the same proc.
121

CALLING COMMANDS DURING TRACES

123       During  rename  traces,  the command being renamed is visible with both
124       names simultaneously, and the command still exists during delete traces
125       (if  TCL_INTERP_DESTROYED  is not set).  However, there is no mechanism
126       for signaling that an error occurred in a  trace  procedure,  so  great
127       care should be taken that errors do not get silently lost.
128

MULTIPLE TRACES

130       It  is possible for multiple traces to exist on the same command.  When
131       this happens, all of the trace  procedures  will  be  invoked  on  each
132       access,  in order from most-recently-created to least-recently-created.
133       Attempts to  delete  the  command  during  a  delete  trace  will  fail
134       silently,  since  the command is already scheduled for deletion anyway.
135       If the command being renamed is renamed by one of  its  rename  traces,
136       that  renaming  takes  precedence over the one that triggered the trace
137       and the collection of traces will not be reexecuted; if several  traces
138       rename the command, the last renaming takes precedence.
139

TCL_TRACE_DESTROYED FLAG

141       In  a  delete  callback  to proc, the TCL_TRACE_DESTROYED bit is set in
142       flags.
143

TCL_INTERP_DESTROYED

145       When an interpreter is destroyed, unset traces are called  for  all  of
146       its  commands.   The  TCL_INTERP_DESTROYED bit will be set in the flags
147       argument passed to the trace  procedures.   Trace  procedures  must  be
148       extremely  careful  in  what they do if the TCL_INTERP_DESTROYED bit is
149       set.  It is not safe for the procedures to invoke any Tcl procedures on
150       the  interpreter, since its state is partially deleted.  All that trace
151       procedures should do under these circumstances is to clean up and  free
152       their own internal data structures.
153

BUGS

155       Tcl  does  not  do  any error checking to prevent trace procedures from
156       misusing the interpreter during traces with TCL_INTERP_DESTROYED set.
157

KEYWORDS

159       clientData, trace, command
160
161
162
163Tcl                                   7.4                  Tcl_TraceCommand(3)
Impressum