OSDN Git Service

FIRST REPOSITORY
[eos/hostdependOTHERS.git] / SGI / util / SGI / man / man3 / Tcl_UntraceVar.3
1 '\"
2 '\" Copyright (c) 1989-1993 The Regents of the University of California.
3 '\" Copyright (c) 1994-1996 Sun Microsystems, Inc.
4 '\"
5 '\" See the file "license.terms" for information on usage and redistribution
6 '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
7 '\" 
8 '\" SCCS: @(#) TraceVar.3 1.27 97/10/10 15:05:37
9 '\" 
10 '\" The definitions below are for supplemental macros used in Tcl/Tk
11 '\" manual entries.
12 '\"
13 '\" .AP type name in/out ?indent?
14 '\"     Start paragraph describing an argument to a library procedure.
15 '\"     type is type of argument (int, etc.), in/out is either "in", "out",
16 '\"     or "in/out" to describe whether procedure reads or modifies arg,
17 '\"     and indent is equivalent to second arg of .IP (shouldn't ever be
18 '\"     needed;  use .AS below instead)
19 '\"
20 '\" .AS ?type? ?name?
21 '\"     Give maximum sizes of arguments for setting tab stops.  Type and
22 '\"     name are examples of largest possible arguments that will be passed
23 '\"     to .AP later.  If args are omitted, default tab stops are used.
24 '\"
25 '\" .BS
26 '\"     Start box enclosure.  From here until next .BE, everything will be
27 '\"     enclosed in one large box.
28 '\"
29 '\" .BE
30 '\"     End of box enclosure.
31 '\"
32 '\" .CS
33 '\"     Begin code excerpt.
34 '\"
35 '\" .CE
36 '\"     End code excerpt.
37 '\"
38 '\" .VS ?version? ?br?
39 '\"     Begin vertical sidebar, for use in marking newly-changed parts
40 '\"     of man pages.  The first argument is ignored and used for recording
41 '\"     the version when the .VS was added, so that the sidebars can be
42 '\"     found and removed when they reach a certain age.  If another argument
43 '\"     is present, then a line break is forced before starting the sidebar.
44 '\"
45 '\" .VE
46 '\"     End of vertical sidebar.
47 '\"
48 '\" .DS
49 '\"     Begin an indented unfilled display.
50 '\"
51 '\" .DE
52 '\"     End of indented unfilled display.
53 '\"
54 '\" .SO
55 '\"     Start of list of standard options for a Tk widget.  The
56 '\"     options follow on successive lines, in four columns separated
57 '\"     by tabs.
58 '\"
59 '\" .SE
60 '\"     End of list of standard options for a Tk widget.
61 '\"
62 '\" .OP cmdName dbName dbClass
63 '\"     Start of description of a specific option.  cmdName gives the
64 '\"     option's name as specified in the class command, dbName gives
65 '\"     the option's name in the option database, and dbClass gives
66 '\"     the option's class in the option database.
67 '\"
68 '\" .UL arg1 arg2
69 '\"     Print arg1 underlined, then print arg2 normally.
70 '\"
71 '\" SCCS: @(#) man.macros 1.9 97/08/22 18:50:59
72 '\"
73 '\"     # Set up traps and other miscellaneous stuff for Tcl/Tk man pages.
74 .if t .wh -1.3i ^B
75 .nr ^l \n(.l
76 .ad b
77 '\"     # Start an argument description
78 .de AP
79 .ie !"\\$4"" .TP \\$4
80 .el \{\
81 .   ie !"\\$2"" .TP \\n()Cu
82 .   el          .TP 15
83 .\}
84 .ie !"\\$3"" \{\
85 .ta \\n()Au \\n()Bu
86 \&\\$1  \\fI\\$2\\fP    (\\$3)
87 .\".b
88 .\}
89 .el \{\
90 .br
91 .ie !"\\$2"" \{\
92 \&\\$1  \\fI\\$2\\fP
93 .\}
94 .el \{\
95 \&\\fI\\$1\\fP
96 .\}
97 .\}
98 ..
99 '\"     # define tabbing values for .AP
100 .de AS
101 .nr )A 10n
102 .if !"\\$1"" .nr )A \\w'\\$1'u+3n
103 .nr )B \\n()Au+15n
104 .\"
105 .if !"\\$2"" .nr )B \\w'\\$2'u+\\n()Au+3n
106 .nr )C \\n()Bu+\\w'(in/out)'u+2n
107 ..
108 .AS Tcl_Interp Tcl_CreateInterp in/out
109 '\"     # BS - start boxed text
110 '\"     # ^y = starting y location
111 '\"     # ^b = 1
112 .de BS
113 .br
114 .mk ^y
115 .nr ^b 1u
116 .if n .nf
117 .if n .ti 0
118 .if n \l'\\n(.lu\(ul'
119 .if n .fi
120 ..
121 '\"     # BE - end boxed text (draw box now)
122 .de BE
123 .nf
124 .ti 0
125 .mk ^t
126 .ie n \l'\\n(^lu\(ul'
127 .el \{\
128 .\"     Draw four-sided box normally, but don't draw top of
129 .\"     box if the box started on an earlier page.
130 .ie !\\n(^b-1 \{\
131 \h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul'
132 .\}
133 .el \}\
134 \h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul'
135 .\}
136 .\}
137 .fi
138 .br
139 .nr ^b 0
140 ..
141 '\"     # VS - start vertical sidebar
142 '\"     # ^Y = starting y location
143 '\"     # ^v = 1 (for troff;  for nroff this doesn't matter)
144 .de VS
145 .if !"\\$2"" .br
146 .mk ^Y
147 .ie n 'mc \s12\(br\s0
148 .el .nr ^v 1u
149 ..
150 '\"     # VE - end of vertical sidebar
151 .de VE
152 .ie n 'mc
153 .el \{\
154 .ev 2
155 .nf
156 .ti 0
157 .mk ^t
158 \h'|\\n(^lu+3n'\L'|\\n(^Yu-1v\(bv'\v'\\n(^tu+1v-\\n(^Yu'\h'-|\\n(^lu+3n'
159 .sp -1
160 .fi
161 .ev
162 .\}
163 .nr ^v 0
164 ..
165 '\"     # Special macro to handle page bottom:  finish off current
166 '\"     # box/sidebar if in box/sidebar mode, then invoked standard
167 '\"     # page bottom macro.
168 .de ^B
169 .ev 2
170 'ti 0
171 'nf
172 .mk ^t
173 .if \\n(^b \{\
174 .\"     Draw three-sided box if this is the box's first page,
175 .\"     draw two sides but no top otherwise.
176 .ie !\\n(^b-1 \h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\h'|0u'\c
177 .el \h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\h'|0u'\c
178 .\}
179 .if \\n(^v \{\
180 .nr ^x \\n(^tu+1v-\\n(^Yu
181 \kx\h'-\\nxu'\h'|\\n(^lu+3n'\ky\L'-\\n(^xu'\v'\\n(^xu'\h'|0u'\c
182 .\}
183 .bp
184 'fi
185 .ev
186 .if \\n(^b \{\
187 .mk ^y
188 .nr ^b 2
189 .\}
190 .if \\n(^v \{\
191 .mk ^Y
192 .\}
193 ..
194 '\"     # DS - begin display
195 .de DS
196 .RS
197 .nf
198 .sp
199 ..
200 '\"     # DE - end display
201 .de DE
202 .fi
203 .RE
204 .sp
205 ..
206 '\"     # SO - start of list of standard options
207 .de SO
208 .SH "STANDARD OPTIONS"
209 .LP
210 .nf
211 .ta 4c 8c 12c
212 .ft B
213 ..
214 '\"     # SE - end of list of standard options
215 .de SE
216 .fi
217 .ft R
218 .LP
219 See the \\fBoptions\\fR manual entry for details on the standard options.
220 ..
221 '\"     # OP - start of full description for a single option
222 .de OP
223 .LP
224 .nf
225 .ta 4c
226 Command-Line Name:      \\fB\\$1\\fR
227 Database Name:  \\fB\\$2\\fR
228 Database Class: \\fB\\$3\\fR
229 .fi
230 .IP
231 ..
232 '\"     # CS - begin code excerpt
233 .de CS
234 .RS
235 .nf
236 .ta .25i .5i .75i 1i
237 ..
238 '\"     # CE - end code excerpt
239 .de CE
240 .fi
241 .RE
242 ..
243 .de UL
244 \\$1\l'|0\(ul'\\$2
245 ..
246 .TH Tcl_TraceVar 3 7.4 Tcl "Tcl Library Procedures"
247 .BS
248 .SH NAME
249 Tcl_TraceVar, Tcl_TraceVar2, Tcl_UntraceVar, Tcl_UntraceVar2, Tcl_VarTraceInfo, Tcl_VarTraceInfo2 \- monitor accesses to a variable
250 .SH SYNOPSIS
251 .nf
252 \fB#include <tcl.h>\fR
253 .sp
254 int
255 \fBTcl_TraceVar(\fIinterp, varName, flags, proc, clientData\fB)\fR
256 .sp
257 int
258 \fBTcl_TraceVar2(\fIinterp, name1, name2, flags, proc, clientData\fB)\fR
259 .sp
260 \fBTcl_UntraceVar(\fIinterp, varName, flags, proc, clientData\fB)\fR
261 .sp
262 \fBTcl_UntraceVar2(\fIinterp, name1, name2, flags, proc, clientData\fB)\fR
263 .sp
264 ClientData
265 \fBTcl_VarTraceInfo(\fIinterp, varName, flags, proc, prevClientData\fB)\fR
266 .sp
267 ClientData
268 \fBTcl_VarTraceInfo2(\fIinterp, name1, name2, flags, proc, prevClientData\fB)\fR
269 .SH ARGUMENTS
270 .AS Tcl_VarTraceProc prevClientData
271 .AP Tcl_Interp *interp in
272 Interpreter containing variable.
273 .AP char *varName in
274 Name of variable.  May refer to a scalar variable, to
275 an array variable with no index, or to an array variable
276 with a parenthesized index.
277 If the name references an element of an array, then it
278 must be in writable memory:  Tcl will make temporary modifications 
279 to it while looking up the name.
280 .AP int flags in
281 OR-ed combination of the values TCL_TRACE_READS, TCL_TRACE_WRITES, and
282 TCL_TRACE_UNSETS, TCL_PARSE_PART1, and TCL_GLOBAL_ONLY.  
283 Not all flags are used by all
284 procedures.  See below for more information.
285 .AP Tcl_VarTraceProc *proc in
286 Procedure to invoke whenever one of the traced operations occurs.
287 .AP ClientData clientData in
288 Arbitrary one-word value to pass to \fIproc\fR.
289 .AP char *name1 in
290 Name of scalar or array variable (without array index).
291 .AP char *name2 in
292 For a trace on an element of an array, gives the index of the
293 element.  For traces on scalar variables or on whole arrays,
294 is NULL.
295 .AP ClientData prevClientData in
296 If non-NULL, gives last value returned by \fBTcl_VarTraceInfo\fR or
297 \fBTcl_VarTraceInfo2\fR, so this call will return information about
298 next trace.  If NULL, this call will return information about first
299 trace.
300 .BE
301
302 .SH DESCRIPTION
303 .PP
304 \fBTcl_TraceVar\fR allows a C procedure to monitor and control
305 access to a Tcl variable, so that the C procedure is invoked
306 whenever the variable is read or written or unset.
307 If the trace is created successfully then \fBTcl_TraceVar\fR returns
308 TCL_OK.  If an error occurred (e.g. \fIvarName\fR specifies an element
309 of an array, but the actual variable isn't an array) then TCL_ERROR
310 is returned and an error message is left in \fIinterp->result\fR.
311 .PP
312 The \fIflags\fR argument to \fBTcl_TraceVar\fR indicates when the
313 trace procedure is to be invoked and provides information
314 for setting up the trace.  It consists of an OR-ed combination
315 of any of the following values:
316 .TP
317 \fBTCL_GLOBAL_ONLY\fR
318 Normally, the variable will be looked up at the current level of
319 procedure call;  if this bit is set then the variable will be looked
320 up at global level, ignoring any active procedures.
321 .TP
322 \fBTCL_TRACE_READS\fR
323 Invoke \fIproc\fR whenever an attempt is made to read the variable.
324 .TP
325 \fBTCL_TRACE_WRITES\fR
326 Invoke \fIproc\fR whenever an attempt is made to modify the variable.
327 .TP
328 \fBTCL_TRACE_UNSETS\fR
329 Invoke \fIproc\fR whenever the variable is unset.
330 A variable may be unset either explicitly by an \fBunset\fR command,
331 or implicitly when a procedure returns (its local variables are
332 automatically unset) or when the interpreter is deleted (all
333 variables are automatically unset).
334 .PP
335 Whenever one of the specified operations occurs on the variable,
336 \fIproc\fR will be invoked.
337 It should have arguments and result that match the type
338 \fBTcl_VarTraceProc\fR:
339 .CS
340 typedef char *Tcl_VarTraceProc(
341         ClientData \fIclientData\fR,
342         Tcl_Interp *\fIinterp\fR,
343         char *\fIname1\fR,
344         char *\fIname2\fR,
345         int \fIflags\fR);
346 .CE
347 The \fIclientData\fR and \fIinterp\fR parameters will
348 have the same values as those passed to \fBTcl_TraceVar\fR when the
349 trace was created.
350 \fIClientData\fR typically points to an application-specific
351 data structure that describes what to do when \fIproc\fR
352 is invoked.
353 \fIName1\fR and \fIname2\fR give the name of the traced variable
354 in the normal two-part form (see the description of \fBTcl_TraceVar2\fR
355 below for details).
356 \fIFlags\fR is an OR-ed combination of bits providing several
357 pieces of information.
358 One of the bits TCL_TRACE_READS, TCL_TRACE_WRITES, or TCL_TRACE_UNSETS
359 will be set in \fIflags\fR to indicate which operation is being performed
360 on the variable.
361 The bit TCL_GLOBAL_ONLY will be set whenever the variable being
362 accessed is a global one not accessible from the current level of
363 procedure call:  the trace procedure will need to pass this flag
364 back to variable-related procedures like \fBTcl_GetVar\fR if it
365 attempts to access the variable.
366 The bit TCL_TRACE_DESTROYED will be set in \fIflags\fR if the trace is
367 about to be destroyed;  this information may be useful to \fIproc\fR
368 so that it can clean up its own internal data structures (see
369 the section TCL_TRACE_DESTROYED below for more details).
370 Lastly, the bit TCL_INTERP_DESTROYED will be set if the entire
371 interpreter is being destroyed.
372 When this bit is set, \fIproc\fR must be especially careful in
373 the things it does (see the section TCL_INTERP_DESTROYED below).
374 The trace procedure's return value should normally be NULL;  see
375 ERROR RETURNS below for information on other possibilities.
376 .PP
377 \fBTcl_UntraceVar\fR may be used to remove a trace.
378 If the variable specified by \fIinterp\fR, \fIvarName\fR, and \fIflags\fR
379 has a trace set with \fIflags\fR, \fIproc\fR, and
380 \fIclientData\fR, then the corresponding trace is removed.
381 If no such trace exists, then the call to \fBTcl_UntraceVar\fR
382 has no effect.
383 The same bits are valid for \fIflags\fR as for calls to \fBTcl_TraceVar\fR.
384 .PP
385 \fBTcl_VarTraceInfo\fR may be used to retrieve information about
386 traces set on a given variable.
387 The return value from \fBTcl_VarTraceInfo\fR is the \fIclientData\fR
388 associated with a particular trace.
389 The trace must be on the variable specified by the \fIinterp\fR,
390 \fIvarName\fR, and \fIflags\fR arguments (only the TCL_GLOBAL_ONLY
391 bit from \fIflags\fR is used;  other bits are ignored) and its trace procedure
392 must the same as the \fIproc\fR argument.
393 If the \fIprevClientData\fR argument is NULL then the return
394 value corresponds to the first (most recently created) matching
395 trace, or NULL if there are no matching traces.
396 If the \fIprevClientData\fR argument isn't NULL, then it should
397 be the return value from a previous call to \fBTcl_VarTraceInfo\fR.
398 In this case, the new return value will correspond to the next
399 matching trace after the one whose \fIclientData\fR matches
400 \fIprevClientData\fR, or NULL if no trace matches \fIprevClientData\fR
401 or if there are no more matching traces after it.
402 This mechanism makes it possible to step through all of the
403 traces for a given variable that have the same \fIproc\fR.
404
405 .SH "TWO-PART NAMES"
406 .PP
407 The procedures \fBTcl_TraceVar2\fR, \fBTcl_UntraceVar2\fR, and
408 \fBTcl_VarTraceInfo2\fR are identical to \fBTcl_TraceVar\fR,
409 \fBTcl_UntraceVar\fR, and \fBTcl_VarTraceInfo\fR, respectively,
410 except that the name of the variable consists of two parts.
411 \fIName1\fR gives the name of a scalar variable or array,
412 and \fIname2\fR gives the name of an element within an array.
413 If \fIname2\fR is NULL it means that either the variable is
414 a scalar or the trace is to be set on the entire array rather
415 than an individual element (see WHOLE-ARRAY TRACES below for
416 more information).
417 As a special case, if the flag TCL_PARSE_PART1 is specified,
418 \fIname1\fR may contain both an array and an element name:
419 if the name contains an open parenthesis and ends with a
420 close parenthesis, then the value between the parentheses is
421 treated as an element name (which can have any string value) and
422 the characters before the first open
423 parenthesis are treated as the name of an array variable.
424 If the flag TCL_PARSE_PART1 is given,
425 \fIname2\fR should be NULL since the array and element names
426 are taken from \fIname1\fR.
427
428 .SH "ACCESSING VARIABLES DURING TRACES"
429 .PP
430 During read and write traces, the
431 trace procedure can read, write, or unset the traced
432 variable using \fBTcl_GetVar2\fR, \fBTcl_SetVar2\fR, and
433 other procedures.
434 While \fIproc\fR is executing, traces are temporarily disabled
435 for the variable, so that calls to \fBTcl_GetVar2\fR and
436 \fBTcl_SetVar2\fR will not cause \fIproc\fR or other trace procedures
437 to be invoked again.
438 Disabling only occurs for the variable whose trace procedure
439 is active;  accesses to other variables will still be traced.
440 However, if a variable is unset during a read or write trace then unset
441 traces will be invoked.
442 .PP
443 During unset traces the variable has already been completely
444 expunged.
445 It is possible for the trace procedure to read or write the
446 variable, but this will be a new version of the variable.
447 Traces are not disabled during unset traces as they are for
448 read and write traces, but existing traces have been removed
449 from the variable before any trace procedures are invoked.
450 If new traces are set by unset trace procedures, these traces
451 will be invoked on accesses to the variable by the trace
452 procedures.
453
454 .SH "CALLBACK TIMING"
455 .PP
456 When read tracing has been specified for a variable, the trace
457 procedure will be invoked whenever the variable's value is
458 read.  This includes \fBset\fR Tcl commands, \fB$\fR-notation
459 in Tcl commands, and invocations of the \fBTcl_GetVar\fR
460 and \fBTcl_GetVar2\fR procedures.
461 \fIProc\fR is invoked just before the variable's value is
462 returned.
463 It may modify the value of the variable to affect what
464 is returned by the traced access.
465 If it unsets the variable then the access will return an error
466 just as if the variable never existed.
467 .PP
468 When write tracing has been specified for a variable, the
469 trace procedure will be invoked whenever the variable's value
470 is modified.  This includes \fBset\fR commands,
471 commands that modify variables as side effects (such as
472 \fBcatch\fR and \fBscan\fR), and calls to the \fBTcl_SetVar\fR
473 and \fBTcl_SetVar2\fR procedures).
474 \fIProc\fR will be invoked after the variable's value has been
475 modified, but before the new value of the variable has been
476 returned.
477 It may modify the value of the variable to override the change
478 and to determine the value actually returned by the traced
479 access.
480 If it deletes the variable then the traced access will return
481 an empty string.
482 .PP
483 When unset tracing has been specified, the trace procedure
484 will be invoked whenever the variable is destroyed.
485 The traces will be called after the variable has been
486 completely unset.
487
488 .SH "WHOLE-ARRAY TRACES"
489 .PP
490 If a call to \fBTcl_TraceVar\fR or \fBTcl_TraceVar2\fR specifies
491 the name of an array variable without an index into the array,
492 then the trace will be set on the array as a whole.
493 This means that \fIproc\fR will be invoked whenever any
494 element of the array is accessed in the ways specified by
495 \fIflags\fR.
496 When an array is unset, a whole-array trace will be invoked
497 just once, with \fIname1\fR equal to the name of the array
498 and \fIname2\fR NULL;  it will not be invoked once for each
499 element.
500
501 .SH "MULTIPLE TRACES"
502 .PP
503 It is possible for multiple traces to exist on the same variable.
504 When this happens, all of the trace procedures will be invoked on each
505 access, in order from most-recently-created to least-recently-created.
506 When there exist whole-array traces for an array as well as
507 traces on individual elements, the whole-array traces are invoked
508 before the individual-element traces.
509 If a read or write trace unsets the variable then all of the unset
510 traces will be invoked but the remainder of the read and write traces
511 will be skipped.
512
513 .SH "ERROR RETURNS"
514 .PP
515 Under normal conditions trace procedures should return NULL, indicating
516 successful completion.
517 If \fIproc\fR returns a non-NULL value it signifies that an
518 error occurred.
519 The return value must be a pointer to a static character string
520 containing an error message.
521 If a trace procedure returns an error, no further traces are
522 invoked for the access and the traced access aborts with the
523 given message.
524 Trace procedures can use this facility to make variables
525 read-only, for example (but note that the value of the variable
526 will already have been modified before the trace procedure is
527 called, so the trace procedure will have to restore the correct
528 value).
529 .PP
530 The return value from \fIproc\fR is only used during read and
531 write tracing.
532 During unset traces, the return value is ignored and all relevant
533 trace procedures will always be invoked.
534
535 .SH "RESTRICTIONS"
536 .PP
537 A trace procedure can be called at any time, even when there
538 is a partially-formed result in the interpreter's result area.  If
539 the trace procedure does anything that could damage this result (such
540 as calling \fBTcl_Eval\fR) then it must save the original values of
541 the interpreter's \fBresult\fR and \fBfreeProc\fR fields and restore
542 them before it returns.
543
544 .SH "UNDEFINED VARIABLES"
545 .PP
546 It is legal to set a trace on an undefined variable.
547 The variable will still appear to be undefined until the
548 first time its value is set.
549 If an undefined variable is traced and then unset, the unset will fail
550 with an error (``no such variable''), but the trace
551 procedure will still be invoked.
552
553 .SH "TCL_TRACE_DESTROYED FLAG"
554 .PP
555 In an unset callback to \fIproc\fR, the TCL_TRACE_DESTROYED bit
556 is set in \fIflags\fR if the trace is being removed as part
557 of the deletion.
558 Traces on a variable are always removed whenever the variable
559 is deleted;  the only time TCL_TRACE_DESTROYED isn't set is for
560 a whole-array trace invoked when only a single element of an
561 array is unset.
562
563 .SH "TCL_INTERP_DESTROYED"
564 .PP
565 When an interpreter is destroyed, unset traces are called for
566 all of its variables.
567 The TCL_INTERP_DESTROYED bit will be set in the \fIflags\fR
568 argument passed to the trace procedures.
569 Trace procedures must be extremely careful in what they do if
570 the TCL_INTERP_DESTROYED bit is set.
571 It is not safe for the procedures to invoke any Tcl procedures
572 on the interpreter, since its state is partially deleted.
573 All that trace procedures should do under these circumstances is
574 to clean up and free their own internal data structures.
575
576 .SH BUGS
577 .PP
578 Tcl doesn't do any error checking to prevent trace procedures
579 from misusing the interpreter during traces with TCL_INTERP_DESTROYED
580 set.
581
582 .SH KEYWORDS
583 clientData, trace, variable