OSDN Git Service

Please enter the commit message for your changes. Lines starting
[eos/hostdependX86LINUX64.git] / util / X86LINUX64 / man / man3 / Tcl_AppendResult.3
1 '\"
2 '\" Copyright (c) 1989-1993 The Regents of the University of California.
3 '\" Copyright (c) 1994-1997 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 .TH Tcl_SetResult 3 8.0 Tcl "Tcl Library Procedures"
9 .\" The -*- nroff -*- definitions below are for supplemental macros used
10 .\" in Tcl/Tk manual entries.
11 .\"
12 .\" .AP type name in/out ?indent?
13 .\"     Start paragraph describing an argument to a library procedure.
14 .\"     type is type of argument (int, etc.), in/out is either "in", "out",
15 .\"     or "in/out" to describe whether procedure reads or modifies arg,
16 .\"     and indent is equivalent to second arg of .IP (shouldn't ever be
17 .\"     needed;  use .AS below instead)
18 .\"
19 .\" .AS ?type? ?name?
20 .\"     Give maximum sizes of arguments for setting tab stops.  Type and
21 .\"     name are examples of largest possible arguments that will be passed
22 .\"     to .AP later.  If args are omitted, default tab stops are used.
23 .\"
24 .\" .BS
25 .\"     Start box enclosure.  From here until next .BE, everything will be
26 .\"     enclosed in one large box.
27 .\"
28 .\" .BE
29 .\"     End of box enclosure.
30 .\"
31 .\" .CS
32 .\"     Begin code excerpt.
33 .\"
34 .\" .CE
35 .\"     End code excerpt.
36 .\"
37 .\" .VS ?version? ?br?
38 .\"     Begin vertical sidebar, for use in marking newly-changed parts
39 .\"     of man pages.  The first argument is ignored and used for recording
40 .\"     the version when the .VS was added, so that the sidebars can be
41 .\"     found and removed when they reach a certain age.  If another argument
42 .\"     is present, then a line break is forced before starting the sidebar.
43 .\"
44 .\" .VE
45 .\"     End of vertical sidebar.
46 .\"
47 .\" .DS
48 .\"     Begin an indented unfilled display.
49 .\"
50 .\" .DE
51 .\"     End of indented unfilled display.
52 .\"
53 .\" .SO ?manpage?
54 .\"     Start of list of standard options for a Tk widget. The manpage
55 .\"     argument defines where to look up the standard options; if
56 .\"     omitted, defaults to "options". The options follow on successive
57 .\"     lines, in three columns separated 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 .\" .QW arg1 ?arg2?
72 .\"     Print arg1 in quotes, then arg2 normally (for trailing punctuation).
73 .\"
74 .\" .PQ arg1 ?arg2?
75 .\"     Print an open parenthesis, arg1 in quotes, then arg2 normally
76 .\"     (for trailing punctuation) and then a closing parenthesis.
77 .\"
78 .\"     # Set up traps and other miscellaneous stuff for Tcl/Tk man pages.
79 .if t .wh -1.3i ^B
80 .nr ^l \n(.l
81 .ad b
82 .\"     # Start an argument description
83 .de AP
84 .ie !"\\$4"" .TP \\$4
85 .el \{\
86 .   ie !"\\$2"" .TP \\n()Cu
87 .   el          .TP 15
88 .\}
89 .ta \\n()Au \\n()Bu
90 .ie !"\\$3"" \{\
91 \&\\$1 \\fI\\$2\\fP (\\$3)
92 .\".b
93 .\}
94 .el \{\
95 .br
96 .ie !"\\$2"" \{\
97 \&\\$1  \\fI\\$2\\fP
98 .\}
99 .el \{\
100 \&\\fI\\$1\\fP
101 .\}
102 .\}
103 ..
104 .\"     # define tabbing values for .AP
105 .de AS
106 .nr )A 10n
107 .if !"\\$1"" .nr )A \\w'\\$1'u+3n
108 .nr )B \\n()Au+15n
109 .\"
110 .if !"\\$2"" .nr )B \\w'\\$2'u+\\n()Au+3n
111 .nr )C \\n()Bu+\\w'(in/out)'u+2n
112 ..
113 .AS Tcl_Interp Tcl_CreateInterp in/out
114 .\"     # BS - start boxed text
115 .\"     # ^y = starting y location
116 .\"     # ^b = 1
117 .de BS
118 .br
119 .mk ^y
120 .nr ^b 1u
121 .if n .nf
122 .if n .ti 0
123 .if n \l'\\n(.lu\(ul'
124 .if n .fi
125 ..
126 .\"     # BE - end boxed text (draw box now)
127 .de BE
128 .nf
129 .ti 0
130 .mk ^t
131 .ie n \l'\\n(^lu\(ul'
132 .el \{\
133 .\"     Draw four-sided box normally, but don't draw top of
134 .\"     box if the box started on an earlier page.
135 .ie !\\n(^b-1 \{\
136 \h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul'
137 .\}
138 .el \}\
139 \h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul'
140 .\}
141 .\}
142 .fi
143 .br
144 .nr ^b 0
145 ..
146 .\"     # VS - start vertical sidebar
147 .\"     # ^Y = starting y location
148 .\"     # ^v = 1 (for troff;  for nroff this doesn't matter)
149 .de VS
150 .if !"\\$2"" .br
151 .mk ^Y
152 .ie n 'mc \s12\(br\s0
153 .el .nr ^v 1u
154 ..
155 .\"     # VE - end of vertical sidebar
156 .de VE
157 .ie n 'mc
158 .el \{\
159 .ev 2
160 .nf
161 .ti 0
162 .mk ^t
163 \h'|\\n(^lu+3n'\L'|\\n(^Yu-1v\(bv'\v'\\n(^tu+1v-\\n(^Yu'\h'-|\\n(^lu+3n'
164 .sp -1
165 .fi
166 .ev
167 .\}
168 .nr ^v 0
169 ..
170 .\"     # Special macro to handle page bottom:  finish off current
171 .\"     # box/sidebar if in box/sidebar mode, then invoked standard
172 .\"     # page bottom macro.
173 .de ^B
174 .ev 2
175 'ti 0
176 'nf
177 .mk ^t
178 .if \\n(^b \{\
179 .\"     Draw three-sided box if this is the box's first page,
180 .\"     draw two sides but no top otherwise.
181 .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
182 .el \h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\h'|0u'\c
183 .\}
184 .if \\n(^v \{\
185 .nr ^x \\n(^tu+1v-\\n(^Yu
186 \kx\h'-\\nxu'\h'|\\n(^lu+3n'\ky\L'-\\n(^xu'\v'\\n(^xu'\h'|0u'\c
187 .\}
188 .bp
189 'fi
190 .ev
191 .if \\n(^b \{\
192 .mk ^y
193 .nr ^b 2
194 .\}
195 .if \\n(^v \{\
196 .mk ^Y
197 .\}
198 ..
199 .\"     # DS - begin display
200 .de DS
201 .RS
202 .nf
203 .sp
204 ..
205 .\"     # DE - end display
206 .de DE
207 .fi
208 .RE
209 .sp
210 ..
211 .\"     # SO - start of list of standard options
212 .de SO
213 'ie '\\$1'' .ds So \\fBoptions\\fR
214 'el .ds So \\fB\\$1\\fR
215 .SH "STANDARD OPTIONS"
216 .LP
217 .nf
218 .ta 5.5c 11c
219 .ft B
220 ..
221 .\"     # SE - end of list of standard options
222 .de SE
223 .fi
224 .ft R
225 .LP
226 See the \\*(So manual entry for details on the standard options.
227 ..
228 .\"     # OP - start of full description for a single option
229 .de OP
230 .LP
231 .nf
232 .ta 4c
233 Command-Line Name:      \\fB\\$1\\fR
234 Database Name:  \\fB\\$2\\fR
235 Database Class: \\fB\\$3\\fR
236 .fi
237 .IP
238 ..
239 .\"     # CS - begin code excerpt
240 .de CS
241 .RS
242 .nf
243 .ta .25i .5i .75i 1i
244 ..
245 .\"     # CE - end code excerpt
246 .de CE
247 .fi
248 .RE
249 ..
250 .\"     # UL - underline word
251 .de UL
252 \\$1\l'|0\(ul'\\$2
253 ..
254 .\"     # QW - apply quotation marks to word
255 .de QW
256 .ie '\\*(lq'"' ``\\$1''\\$2
257 .\"" fix emacs highlighting
258 .el \\*(lq\\$1\\*(rq\\$2
259 ..
260 .\"     # PQ - apply parens and quotation marks to word
261 .de PQ
262 .ie '\\*(lq'"' (``\\$1''\\$2)\\$3
263 .\"" fix emacs highlighting
264 .el (\\*(lq\\$1\\*(rq\\$2)\\$3
265 ..
266 .\"     # QR - quoted range
267 .de QR
268 .ie '\\*(lq'"' ``\\$1''\\-``\\$2''\\$3
269 .\"" fix emacs highlighting
270 .el \\*(lq\\$1\\*(rq\\-\\*(lq\\$2\\*(rq\\$3
271 ..
272 .\"     # MT - "empty" string
273 .de MT
274 .QW ""
275 ..
276 .BS
277 .SH NAME
278 Tcl_SetObjResult, Tcl_GetObjResult, Tcl_SetResult, Tcl_GetStringResult, Tcl_AppendResult, Tcl_AppendResultVA, Tcl_AppendElement, Tcl_ResetResult, Tcl_TransferResult, Tcl_FreeResult \- manipulate Tcl result
279 .SH SYNOPSIS
280 .nf
281 \fB#include <tcl.h>\fR
282 .sp
283 \fBTcl_SetObjResult\fR(\fIinterp, objPtr\fR)
284 .sp
285 Tcl_Obj *
286 \fBTcl_GetObjResult\fR(\fIinterp\fR)
287 .sp
288 \fBTcl_SetResult\fR(\fIinterp, result, freeProc\fR)
289 .sp
290 const char *
291 \fBTcl_GetStringResult\fR(\fIinterp\fR)
292 .sp
293 \fBTcl_AppendResult\fR(\fIinterp, result, result, ... , \fB(char *) NULL\fR)
294 .sp
295 \fBTcl_AppendResultVA\fR(\fIinterp, argList\fR)
296 .sp
297 \fBTcl_ResetResult\fR(\fIinterp\fR)
298 .sp
299 .VS 8.6
300 \fBTcl_TransferResult\fR(\fIsourceInterp, result, targetInterp\fR)
301 .VE 8.6
302 .sp
303 \fBTcl_AppendElement\fR(\fIinterp, element\fR)
304 .sp
305 \fBTcl_FreeResult\fR(\fIinterp\fR)
306 .SH ARGUMENTS
307 .AS Tcl_FreeProc sourceInterp out
308 .AP Tcl_Interp *interp out
309 Interpreter whose result is to be modified or read.
310 .AP Tcl_Obj *objPtr in
311 Tcl value to become result for \fIinterp\fR.
312 .AP char *result in
313 String value to become result for \fIinterp\fR or to be
314 appended to the existing result.
315 .AP "const char" *element in
316 String value to append as a list element
317 to the existing result of \fIinterp\fR.
318 .AP Tcl_FreeProc *freeProc in
319 Address of procedure to call to release storage at
320 \fIresult\fR, or \fBTCL_STATIC\fR, \fBTCL_DYNAMIC\fR, or
321 \fBTCL_VOLATILE\fR.
322 .AP va_list argList in
323 An argument list which must have been initialized using
324 \fBva_start\fR, and cleared using \fBva_end\fR.
325 .AP Tcl_Interp *sourceInterp in
326 .VS 8.6
327 Interpreter that the result and error information should be copied from.
328 .VE 8.6
329 .AP Tcl_Interp *targetInterp in
330 .VS 8.6
331 Interpreter that the result and error information should be copied to.
332 .VE 8.6
333 .AP int result in
334 .VS 8.6
335 If \fBTCL_OK\fR, only copy the result. If \fBTCL_ERROR\fR, copy the error
336 information as well.
337 .VE 8.6
338 .BE
339 .SH DESCRIPTION
340 .PP
341 The procedures described here are utilities for manipulating the
342 result value in a Tcl interpreter.
343 The interpreter result may be either a Tcl value or a string.
344 For example, \fBTcl_SetObjResult\fR and \fBTcl_SetResult\fR
345 set the interpreter result to, respectively, a value and a string.
346 Similarly, \fBTcl_GetObjResult\fR and \fBTcl_GetStringResult\fR
347 return the interpreter result as a value and as a string.
348 The procedures always keep the string and value forms
349 of the interpreter result consistent.
350 For example, if \fBTcl_SetObjResult\fR is called to set
351 the result to a value,
352 then \fBTcl_GetStringResult\fR is called,
353 it will return the value's string representation.
354 .PP
355 \fBTcl_SetObjResult\fR
356 arranges for \fIobjPtr\fR to be the result for \fIinterp\fR,
357 replacing any existing result.
358 The result is left pointing to the value
359 referenced by \fIobjPtr\fR.
360 \fIobjPtr\fR's reference count is incremented
361 since there is now a new reference to it from \fIinterp\fR.
362 The reference count for any old result value
363 is decremented and the old result value is freed if no
364 references to it remain.
365 .PP
366 \fBTcl_GetObjResult\fR returns the result for \fIinterp\fR as a value.
367 The value's reference count is not incremented;
368 if the caller needs to retain a long-term pointer to the value
369 they should use \fBTcl_IncrRefCount\fR to increment its reference count
370 in order to keep it from being freed too early or accidentally changed.
371 .PP
372 \fBTcl_SetResult\fR
373 arranges for \fIresult\fR to be the result for the current Tcl
374 command in \fIinterp\fR, replacing any existing result.
375 The \fIfreeProc\fR argument specifies how to manage the storage
376 for the \fIresult\fR argument;
377 it is discussed in the section
378 \fBTHE TCL_FREEPROC ARGUMENT TO TCL_SETRESULT\fR below.
379 If \fIresult\fR is \fBNULL\fR, then \fIfreeProc\fR is ignored
380 and \fBTcl_SetResult\fR
381 re-initializes \fIinterp\fR's result to point to an empty string.
382 .PP
383 \fBTcl_GetStringResult\fR returns the result for \fIinterp\fR as a string.
384 If the result was set to a value by a \fBTcl_SetObjResult\fR call,
385 the value form will be converted to a string and returned.
386 If the value's string representation contains null bytes,
387 this conversion will lose information.
388 For this reason, programmers are encouraged to
389 write their code to use the new value API procedures
390 and to call \fBTcl_GetObjResult\fR instead.
391 .PP
392 \fBTcl_ResetResult\fR clears the result for \fIinterp\fR
393 and leaves the result in its normal empty initialized state.
394 If the result is a value,
395 its reference count is decremented and the result is left
396 pointing to an unshared value representing an empty string.
397 If the result is a dynamically allocated string, its memory is free*d
398 and the result is left as a empty string.
399 \fBTcl_ResetResult\fR also clears the error state managed by
400 \fBTcl_AddErrorInfo\fR, \fBTcl_AddObjErrorInfo\fR,
401 and \fBTcl_SetErrorCode\fR.
402 .PP
403 \fBTcl_AppendResult\fR makes it easy to build up Tcl results in pieces.
404 It takes each of its \fIresult\fR arguments and appends them in order
405 to the current result associated with \fIinterp\fR.
406 If the result is in its initialized empty state (e.g. a command procedure
407 was just invoked or \fBTcl_ResetResult\fR was just called),
408 then \fBTcl_AppendResult\fR sets the result to the concatenation of
409 its \fIresult\fR arguments.
410 \fBTcl_AppendResult\fR may be called repeatedly as additional pieces
411 of the result are produced.
412 \fBTcl_AppendResult\fR takes care of all the
413 storage management issues associated with managing \fIinterp\fR's
414 result, such as allocating a larger result area if necessary.
415 It also manages conversion to and from the \fIresult\fR field of the
416 \fIinterp\fR so as to handle backward-compatibility with old-style
417 extensions.
418 Any number of \fIresult\fR arguments may be passed in a single
419 call; the last argument in the list must be a NULL pointer.
420 .PP
421 \fBTcl_AppendResultVA\fR is the same as \fBTcl_AppendResult\fR except that
422 instead of taking a variable number of arguments it takes an argument list.
423 .PP
424 .VS 8.6
425 \fBTcl_TransferResult\fR moves a result from one interpreter to another,
426 optionally (dependent on the \fIresult\fR parameter) including the error
427 information dictionary as well. The interpreters must be in the same thread.
428 The source interpreter will have its result reset by this operation.
429 .VE 8.6
430 .SH "DEPRECATED INTERFACES"
431 .SS "OLD STRING PROCEDURES"
432 .PP
433 Use of the following procedures (is deprecated
434 since they manipulate the Tcl result as a string.
435 Procedures such as \fBTcl_SetObjResult\fR
436 that manipulate the result as a value
437 can be significantly more efficient.
438 .PP
439 \fBTcl_AppendElement\fR is similar to \fBTcl_AppendResult\fR in
440 that it allows results to be built up in pieces.
441 However, \fBTcl_AppendElement\fR takes only a single \fIelement\fR
442 argument and it appends that argument to the current result
443 as a proper Tcl list element.
444 \fBTcl_AppendElement\fR adds backslashes or braces if necessary
445 to ensure that \fIinterp\fR's result can be parsed as a list and that
446 \fIelement\fR will be extracted as a single element.
447 Under normal conditions, \fBTcl_AppendElement\fR will add a space
448 character to \fIinterp\fR's result just before adding the new
449 list element, so that the list elements in the result are properly
450 separated.
451 However if the new list element is the first in a list or sub-list
452 (i.e. \fIinterp\fR's current result is empty, or consists of the
453 single character
454 .QW { ,
455 or ends in the characters
456 .QW " {" )
457 then no space is added.
458 .PP
459 \fBTcl_FreeResult\fR performs part of the work
460 of \fBTcl_ResetResult\fR.
461 It frees up the memory associated with \fIinterp\fR's result.
462 It also sets \fIinterp->freeProc\fR to zero, but does not
463 change \fIinterp->result\fR or clear error state.
464 \fBTcl_FreeResult\fR is most commonly used when a procedure
465 is about to replace one result value with another.
466 .SS "DIRECT ACCESS TO INTERP->RESULT"
467 .PP
468 It used to be legal for programs to
469 directly read and write \fIinterp->result\fR
470 to manipulate the interpreter result.  The Tcl headers no longer
471 permit this access by default, and C code still doing this must
472 be updated to use supported routines \fBTcl_GetObjResult\fR,
473 \fBTcl_GetStringResult\fR, \fBTcl_SetObjResult\fR, and \fBTcl_SetResult\fR.
474 As a migration aid, access can be restored with the compiler directive
475 .CS
476 #define USE_INTERP_RESULT
477 .CE
478 but this is meant only to offer life support to otherwise dead code.
479 .SH "THE TCL_FREEPROC ARGUMENT TO TCL_SETRESULT"
480 .PP
481 \fBTcl_SetResult\fR's \fIfreeProc\fR argument specifies how 
482 the Tcl system is to manage the storage for the \fIresult\fR argument.
483 If \fBTcl_SetResult\fR or \fBTcl_SetObjResult\fR are called
484 at a time when \fIinterp\fR holds a string result,
485 they do whatever is necessary to dispose of the old string result
486 (see the \fBTcl_Interp\fR manual entry for details on this).
487 .PP
488 If \fIfreeProc\fR is \fBTCL_STATIC\fR it means that \fIresult\fR
489 refers to an area of static storage that is guaranteed not to be
490 modified until at least the next call to \fBTcl_Eval\fR.
491 If \fIfreeProc\fR
492 is \fBTCL_DYNAMIC\fR it means that \fIresult\fR was allocated with a call
493 to \fBTcl_Alloc\fR and is now the property of the Tcl system.
494 \fBTcl_SetResult\fR will arrange for the string's storage to be
495 released by calling \fBTcl_Free\fR when it is no longer needed.
496 If \fIfreeProc\fR is \fBTCL_VOLATILE\fR it means that \fIresult\fR
497 points to an area of memory that is likely to be overwritten when
498 \fBTcl_SetResult\fR returns (e.g. it points to something in a stack frame).
499 In this case \fBTcl_SetResult\fR will make a copy of the string in
500 dynamically allocated storage and arrange for the copy to be the
501 result for the current Tcl command.
502 .PP
503 If \fIfreeProc\fR is not one of the values \fBTCL_STATIC\fR,
504 \fBTCL_DYNAMIC\fR, and \fBTCL_VOLATILE\fR, then it is the address
505 of a procedure that Tcl should call to free the string.
506 This allows applications to use non-standard storage allocators.
507 When Tcl no longer needs the storage for the string, it will
508 call \fIfreeProc\fR. \fIFreeProc\fR should have arguments and
509 result that match the type \fBTcl_FreeProc\fR:
510 .PP
511 .CS
512 typedef void \fBTcl_FreeProc\fR(
513         char *\fIblockPtr\fR);
514 .CE
515 .PP
516 When \fIfreeProc\fR is called, its \fIblockPtr\fR will be set to
517 the value of \fIresult\fR passed to \fBTcl_SetResult\fR.
518 .SH "SEE ALSO"
519 Tcl_AddErrorInfo, Tcl_CreateObjCommand, Tcl_SetErrorCode, Tcl_Interp
520 .SH KEYWORDS
521 append, command, element, list, value, result, return value, interpreter