home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tcl2-73c.zip / tcl7.3 / doc / SetResult.3 < prev    next >
Text File  |  1993-04-03  |  7KB  |  163 lines

  1. '\"
  2. '\" Copyright (c) 1989-1993 The Regents of the University of California.
  3. '\" All rights reserved.
  4. '\"
  5. '\" Permission is hereby granted, without written agreement and without
  6. '\" license or royalty fees, to use, copy, modify, and distribute this
  7. '\" documentation for any purpose, provided that the above copyright
  8. '\" notice and the following two paragraphs appear in all copies.
  9. '\"
  10. '\" IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY
  11. '\" FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
  12. '\" ARISING OUT OF THE USE OF THIS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
  13. '\" CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  14. '\"
  15. '\" THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
  16. '\" INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
  17. '\" AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
  18. '\" ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
  19. '\" PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  20. '\" 
  21. '\" $Header: /user6/ouster/tcl/man/RCS/SetResult.3,v 1.12 93/04/03 15:05:59 ouster Exp $ SPRITE (Berkeley)
  22. '\" 
  23. .so man.macros
  24. .HS Tcl_SetResult tclc 7.0
  25. .BS
  26. .SH NAME
  27. Tcl_SetResult, Tcl_AppendResult, Tcl_AppendElement, Tcl_ResetResult \- manipulate Tcl result string
  28. .SH SYNOPSIS
  29. .nf
  30. \fB#include <tcl.h>\fR
  31. .sp
  32. \fBTcl_SetResult\fR(\fIinterp, string, freeProc\fR)
  33. .sp
  34. \fBTcl_AppendResult(\fIinterp, string, string, ... , \fB(char *) NULL\fR)
  35. .sp
  36. .VS
  37. \fBTcl_AppendElement\fR(\fIinterp, string\fR)
  38. .VE
  39. .sp
  40. \fBTcl_ResetResult\fR(\fIinterp\fR)
  41. .sp
  42. \fBTcl_FreeResult\fR(\fIinterp\fR)
  43. .SH ARGUMENTS
  44. .AS Tcl_FreeProc freeProc
  45. .AP Tcl_Interp *interp out
  46. Interpreter whose result is to be modified.
  47. .AP char *string in
  48. String value to become result for \fIinterp\fR or to be
  49. appended to existing result.
  50. .AP Tcl_FreeProc freeProc in
  51. Address of procedure to call to release storage at
  52. \fIstring\fR, or \fBTCL_STATIC\fR, \fBTCL_DYNAMIC\fR, or
  53. \fBTCL_VOLATILE\fR.
  54. .BE
  55.  
  56. .SH DESCRIPTION
  57. .PP
  58. The procedures described here are utilities for setting the
  59. result/error string in a Tcl interpreter.
  60. .PP
  61. \fBTcl_SetResult\fR
  62. arranges for \fIstring\fR to be the return string for the current Tcl
  63. command in \fIinterp\fR, replacing any existing result.
  64. If \fIfreeProc\fR is \fBTCL_STATIC\fR it means that \fIstring\fR
  65. refers to an area of static storage that is guaranteed not to be
  66. modified until at least the next call to \fBTcl_Eval\fR.
  67. If \fIfreeProc\fR
  68. is \fBTCL_DYNAMIC\fR it means that \fIstring\fR was allocated with a call
  69. to \fBmalloc()\fR and is now the property of the Tcl system.
  70. \fBTcl_SetResult\fR will arrange for the string's storage to be
  71. released by calling \fBfree()\fR when it is no longer needed.
  72. If \fIfreeProc\fR is \fBTCL_VOLATILE\fR it means that \fIstring\fR
  73. points to an area of memory that is likely to be overwritten when
  74. \fBTcl_SetResult\fR returns (e.g. it points to something in a stack frame).
  75. In this case \fBTcl_SetResult\fR will make a copy of the string in
  76. dynamically allocated storage and arrange for the copy to be the
  77. return string for the current Tcl command.
  78. .PP
  79. If \fIfreeProc\fR isn't one of the values \fBTCL_STATIC\fR,
  80. \fBTCL_DYNAMIC\fR, and \fBTCL_VOLATILE\fR, then it is the address
  81. of a procedure that Tcl should call to free the string.
  82. This allows applications to use non-standard storage allocators.
  83. When Tcl no longer needs the storage for the string, it will
  84. call \fIfreeProc\fR.  \fIFreeProc\fR should have arguments and
  85. result that match the type \fBTcl_FreeProc\fR:
  86. .nf
  87. .RS
  88.  
  89. typedef void Tcl_FreeProc(char *\fIblockPtr\fR);
  90.  
  91. .RE
  92. .fi
  93. When \fIfreeProc\fR is called, its \fIblockPtr\fR will be set to
  94. the value of \fIstring\fR passed to \fBTcl_SetResult\fR.
  95. .PP
  96. If \fIstring\fR is \fBNULL\fR, then \fIfreeProc\fR is ignored
  97. and \fBTcl_SetResult\fR
  98. re-initializes \fIinterp\fR's result to point to the pre-allocated result
  99. area, with an empty string in the result area.
  100. .PP
  101. If \fBTcl_SetResult\fR is called at a time when \fIinterp\fR holds a
  102. result, \fBTcl_SetResult\fR does whatever is necessary to dispose
  103. of the old result (see the \fBTcl_Interp\fR manual entry for details
  104. on this).
  105. .PP
  106. \fBTcl_AppendResult\fR makes it easy to build up Tcl results in pieces.
  107. It takes each of its \fIstring\fR arguments and appends them in order
  108. to the current result associated with \fIinterp\fR.
  109. If the result is in its initialized empty state (e.g. a command procedure
  110. was just invoked or \fBTcl_ResetResult\fR was just called),
  111. then \fBTcl_AppendResult\fR sets the result to the concatenation of
  112. its \fIstring\fR arguments.
  113. \fBTcl_AppendResult\fR may be called repeatedly as additional pieces
  114. of the result are produced.
  115. \fBTcl_AppendResult\fR takes care of all the
  116. storage management issues associated with managing \fIinterp\fR's
  117. result, such as allocating a larger result area if necessary.
  118. Any number of \fIstring\fR arguments may be passed in a single
  119. call;  the last argument in the list must be a NULL pointer.
  120. .PP
  121. \fBTcl_AppendElement\fR is similar to \fBTcl_AppendResult\fR in
  122. that it allows results to be built up in pieces.
  123. However, \fBTcl_AppendElement\fR takes only a single \fIstring\fR
  124. argument and it appends that argument to the current result
  125. as a proper Tcl list element.
  126. \fBTcl_AppendElement\fR adds backslashes or braces if necessary
  127. to ensure that \fIinterp\fR's result can be parsed as a list and that
  128. \fIstring\fR will be extracted as a single element.
  129. Under normal conditions, \fBTcl_AppendElement\fR will add a space
  130. character to \fIinterp\fR's result just before adding the new
  131. list element, so that the list elements in the result are properly
  132. separated.
  133. .VS
  134. However if the new list element is the first in a list or sub-list
  135. (i.e. \fIinterp\fR's current result is empty, or consists of the
  136. single character ``{'', or ends in the characters `` {'') then no
  137. space is added.
  138. .VE
  139. .PP
  140. \fBTcl_ResetResult\fR clears the result for \fIinterp\fR,
  141. freeing the memory associated with it if the current result was
  142. dynamically allocated.
  143. It leaves the result in its normal initialized state with
  144. \fIinterp->result\fR pointing to a static buffer containing
  145. \fBTCL_RESULT_SIZE\fR characters, of which the first character
  146. is zero.
  147. \fBTcl_ResetResult\fR also clears the error state managed by
  148. \fBTcl_AddErrorInfo\fR and \fBTcl_SetErrorCode\fR.
  149. .PP
  150. \fBTcl_FreeResult\fR is a macro that performs part of the work
  151. of \fBTcl_ResetResult\fR.
  152. It frees up the memory associated with \fIinterp\fR's result
  153. and sets \fIinterp->freeProc\fR to zero, but it doesn't
  154. change \fIinterp->result\fR or clear error state.
  155. \fBTcl_FreeResult\fR is most commonly used when a procedure
  156. is about to replace one result value with another.
  157.  
  158. .SH "SEE ALSO"
  159. Tcl_AddErrorInfo, Tcl_SetErrorCode, Tcl_Interp
  160.  
  161. .SH KEYWORDS
  162. append, command, element, list, result, return value, interpreter
  163.