OSDN Git Service

FIRST REPOSITORY
[eos/hostdependOTHERS.git] / SGI / util / SGI / man / man3 / Tcl_SetResult.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 '\" SCCS: @(#) SetResult.3 1.23 97/06/26 14:05:57
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_SetResult 3 7.5 Tcl "Tcl Library Procedures"
247 .BS
248 .SH NAME
249 Tcl_SetObjResult, Tcl_GetObjResult, Tcl_SetResult, Tcl_GetStringResult, Tcl_AppendResult, Tcl_AppendElement, Tcl_ResetResult \- manipulate Tcl result
250 .SH SYNOPSIS
251 .nf
252 \fB#include <tcl.h>\fR
253 .sp
254 \fBTcl_SetObjResult\fR(\fIinterp, objPtr\fR)
255 .sp
256 Tcl_Obj *
257 \fBTcl_GetObjResult\fR(\fIinterp\fR)
258 .sp
259 \fBTcl_SetResult\fR(\fIinterp, string, freeProc\fR)
260 .sp
261 char *
262 \fBTcl_GetStringResult\fR(\fIinterp\fR)
263 .sp
264 \fBTcl_AppendResult\fR(\fIinterp, string, string, ... , \fB(char *) NULL\fR)
265 .sp
266 \fBTcl_AppendElement\fR(\fIinterp, string\fR)
267 .sp
268 \fBTcl_ResetResult\fR(\fIinterp\fR)
269 .sp
270 \fBTcl_FreeResult\fR(\fIinterp\fR)
271 .SH ARGUMENTS
272 .AS Tcl_FreeProc freeProc
273 .AP Tcl_Interp *interp out
274 Interpreter whose result is to be modified or read.
275 .AP Tcl_Obj *objPtr in
276 Object value to become result for \fIinterp\fR.
277 .AP char *string in
278 String value to become result for \fIinterp\fR or to be
279 appended to the existing result.
280 .AP Tcl_FreeProc *freeProc in
281 Address of procedure to call to release storage at
282 \fIstring\fR, or \fBTCL_STATIC\fR, \fBTCL_DYNAMIC\fR, or
283 \fBTCL_VOLATILE\fR.
284 .BE
285
286 .SH DESCRIPTION
287 .PP
288 The procedures described here are utilities for manipulating the
289 result value in a Tcl interpreter.
290 The interpreter result may be either a Tcl object or a string.
291 For example, \fBTcl_SetObjResult\fR and \fBTcl_SetResult\fR
292 set the interpreter result to, respectively, an object and a string.
293 Similarly, \fBTcl_GetObjResult\fR and \fBTcl_GetStringResult\fR
294 return the interpreter result as an object and as a string.
295 The procedures always keep the string and object forms
296 of the interpreter result consistent.
297 For example, if \fBTcl_SetObjResult\fR is called to set
298 the result to an object,
299 then \fBTcl_GetStringResult\fR is called,
300 it will return the object's string value.
301 .PP
302 \fBTcl_SetObjResult\fR
303 arranges for \fIobjPtr\fR to be the result for \fIinterp\fR,
304 replacing any existing result.
305 The result is left pointing to the object
306 referenced by \fIobjPtr\fR.
307 \fIobjPtr\fR's reference count is incremented
308 since there is now a new reference to it from \fIinterp\fR.
309 The reference count for any old result object
310 is decremented and the old result object is freed if no
311 references to it remain.
312 .PP
313 \fBTcl_GetObjResult\fR returns the result for \fIinterp\fR as an object.
314 The object's reference count is not incremented;
315 if the caller needs to retain a long-term pointer to the object
316 they should use \fBTcl_IncrRefCount\fR to increment its reference count
317 in order to keep it from being freed too early or accidently changed.
318 .PP
319 \fBTcl_SetResult\fR
320 arranges for \fIstring\fR to be the result for the current Tcl
321 command in \fIinterp\fR, replacing any existing result.
322 The \fIfreeProc\fR argument specifies how to manage the storage
323 for the \fIstring\fR argument;
324 it is discussed in the section
325 \fBTHE TCL_FREEPROC ARGUMENT TO TCL_SETRESULT\fR below.
326 If \fIstring\fR is \fBNULL\fR, then \fIfreeProc\fR is ignored
327 and \fBTcl_SetResult\fR
328 re-initializes \fIinterp\fR's result to point to an empty string.
329 .PP
330 \fBTcl_GetStringResult\fR returns the result for \fIinterp\fR as an string.
331 If the result was set to an object by a \fBTcl_SetObjResult\fR call,
332 the object form will be converted to a string and returned.
333 If the object's string representation contains null bytes,
334 this conversion will lose information.
335 For this reason, programmers are encouraged to
336 write their code to use the new object API procedures
337 and to call \fBTcl_GetObjResult\fR instead.
338 .PP
339 \fBTcl_ResetResult\fR clears the result for \fIinterp\fR
340 and leaves the result in its normal empty initialized state.
341 If the result is an object,
342 its reference count is decremented and the result is left
343 pointing to an unshared object representing an empty string.
344 If the result is a dynamically allocated string, its memory is free*d
345 and the result is left as a empty string.
346 \fBTcl_ResetResult\fR also clears the error state managed by
347 \fBTcl_AddErrorInfo\fR, \fBTcl_AddObjErrorInfo\fR,
348 and \fBTcl_SetErrorCode\fR.
349
350 .SH OLD STRING PROCEDURES
351 .PP
352 Use of the following procedures is deprecated
353 since they manipulate the Tcl result as a string.
354 Procedures such as \fBTcl_SetObjResult\fR
355 that manipulate the result as an object
356 can be significantly more efficient.
357 .PP
358 \fBTcl_AppendResult\fR makes it easy to build up Tcl results in pieces.
359 It takes each of its \fIstring\fR arguments and appends them in order
360 to the current result associated with \fIinterp\fR.
361 If the result is in its initialized empty state (e.g. a command procedure
362 was just invoked or \fBTcl_ResetResult\fR was just called),
363 then \fBTcl_AppendResult\fR sets the result to the concatenation of
364 its \fIstring\fR arguments.
365 \fBTcl_AppendResult\fR may be called repeatedly as additional pieces
366 of the result are produced.
367 \fBTcl_AppendResult\fR takes care of all the
368 storage management issues associated with managing \fIinterp\fR's
369 result, such as allocating a larger result area if necessary.
370 It also converts the current interpreter result from an object
371 to a string, if necessary, before appending the argument strings.
372 Any number of \fIstring\fR arguments may be passed in a single
373 call; the last argument in the list must be a NULL pointer.
374 .PP
375 \fBTcl_AppendElement\fR is similar to \fBTcl_AppendResult\fR in
376 that it allows results to be built up in pieces.
377 However, \fBTcl_AppendElement\fR takes only a single \fIstring\fR
378 argument and it appends that argument to the current result
379 as a proper Tcl list element.
380 \fBTcl_AppendElement\fR adds backslashes or braces if necessary
381 to ensure that \fIinterp\fR's result can be parsed as a list and that
382 \fIstring\fR will be extracted as a single element.
383 Under normal conditions, \fBTcl_AppendElement\fR will add a space
384 character to \fIinterp\fR's result just before adding the new
385 list element, so that the list elements in the result are properly
386 separated.
387 However if the new list element is the first in a list or sub-list
388 (i.e. \fIinterp\fR's current result is empty, or consists of the
389 single character ``{'', or ends in the characters `` {'') then no
390 space is added.
391 .PP
392 \fBTcl_FreeResult\fR performs part of the work
393 of \fBTcl_ResetResult\fR.
394 It frees up the memory associated with \fIinterp\fR's result.
395 It also sets \fIinterp->freeProc\fR to zero, but doesn't
396 change \fIinterp->result\fR or clear error state.
397 \fBTcl_FreeResult\fR is most commonly used when a procedure
398 is about to replace one result value with another.
399
400 .SH DIRECT ACCESS TO INTERP->RESULT IS DEPRECATED
401 .PP
402 It used to be legal for programs to
403 directly read and write \fIinterp->result\fR
404 to manipulate the interpreter result.
405 Direct access to \fIinterp->result\fR is now strongly deprecated
406 because it can make the result's string and object forms inconsistent.
407 Programs should always read the result
408 using the procedures \fBTcl_GetObjResult\fR or \fBTcl_GetStringResult\fR,
409 and write the result using \fBTcl_SetObjResult\fR or \fBTcl_SetResult\fR.
410
411 .SH THE TCL_FREEPROC ARGUMENT TO TCL_SETRESULT
412 .PP
413 \fBTcl_SetResult\fR's \fIfreeProc\fR argument specifies how 
414 the Tcl system is to manage the storage for the \fIstring\fR argument.
415 If \fBTcl_SetResult\fR or \fBTcl_SetObjResult\fR are called
416 at a time when \fIinterp\fR holds a string result,
417 they do whatever is necessary to dispose of the old string result
418 (see the \fBTcl_Interp\fR manual entry for details on this).
419 .PP
420 If \fIfreeProc\fR is \fBTCL_STATIC\fR it means that \fIstring\fR
421 refers to an area of static storage that is guaranteed not to be
422 modified until at least the next call to \fBTcl_Eval\fR.
423 If \fIfreeProc\fR
424 is \fBTCL_DYNAMIC\fR it means that \fIstring\fR was allocated with a call
425 to \fBTcl_Alloc\fR and is now the property of the Tcl system.
426 \fBTcl_SetResult\fR will arrange for the string's storage to be
427 released by calling \fBTcl_Free\fR when it is no longer needed.
428 If \fIfreeProc\fR is \fBTCL_VOLATILE\fR it means that \fIstring\fR
429 points to an area of memory that is likely to be overwritten when
430 \fBTcl_SetResult\fR returns (e.g. it points to something in a stack frame).
431 In this case \fBTcl_SetResult\fR will make a copy of the string in
432 dynamically allocated storage and arrange for the copy to be the
433 result for the current Tcl command.
434 .PP
435 If \fIfreeProc\fR isn't one of the values \fBTCL_STATIC\fR,
436 \fBTCL_DYNAMIC\fR, and \fBTCL_VOLATILE\fR, then it is the address
437 of a procedure that Tcl should call to free the string.
438 This allows applications to use non-standard storage allocators.
439 When Tcl no longer needs the storage for the string, it will
440 call \fIfreeProc\fR. \fIFreeProc\fR should have arguments and
441 result that match the type \fBTcl_FreeProc\fR:
442 .CS
443 typedef void Tcl_FreeProc(char *\fIblockPtr\fR);
444 .CE
445 When \fIfreeProc\fR is called, its \fIblockPtr\fR will be set to
446 the value of \fIstring\fR passed to \fBTcl_SetResult\fR.
447
448 .SH "SEE ALSO"
449 Tcl_AddErrorInfo, Tcl_CreateObjCommand, Tcl_SetErrorCode, Tcl_Interp
450
451 .SH KEYWORDS
452 append, command, element, list, object, result, return value, interpreter