home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tcl2-73c.zip / tcl7.3 / doc / DString.3 < prev    next >
Text File  |  1993-08-16  |  6KB  |  142 lines

  1. '\"
  2. '\" Copyright (c) 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/DString.3,v 1.10 93/08/16 13:24:52 ouster Exp $ SPRITE (Berkeley)
  22. '\" 
  23. .so man.macros
  24. .HS Tcl_DStringInit tclc 7.0
  25. .BS
  26. .SH NAME
  27. .na
  28. Tcl_DStringInit, Tcl_DStringAppend, Tcl_DStringAppendElement, Tcl_DStringStartSublist, Tcl_DStringEndSublist, Tcl_DStringLength, Tcl_DStringValue, Tcl_DStringTrunc, Tcl_DStringFree, Tcl_DStringResult \- manipulate dynamic strings
  29. .ad
  30. .SH SYNOPSIS
  31. .nf
  32. \fB#include <tcl.h>\fR
  33. .sp
  34. \fBTcl_DStringInit\fR(\fIdsPtr\fR)
  35. .sp
  36. char *
  37. \fBTcl_DStringAppend\fR(\fIdsPtr, string, length\fR)
  38. .sp
  39. char *
  40. \fBTcl_DStringAppendElement\fR(\fIdsPtr, string\fR)
  41. .sp
  42. \fBTcl_DStringStartSublist\fR(\fIdsPtr\fR)
  43. .sp
  44. \fBTcl_DStringEndSublist\fR(\fIdsPtr\fR)
  45. .sp
  46. int
  47. \fBTcl_DStringLength\fR(\fIdsPtr\fR)
  48. .sp
  49. char *
  50. \fBTcl_DStringValue\fR(\fIdsPtr\fR)
  51. .sp
  52. \fBTcl_DStringTrunc\fR(\fIdsPtr, newLength\fR)
  53. .sp
  54. \fBTcl_DStringFree\fR(\fIdsPtr\fR)
  55. .sp
  56. \fBTcl_DStringResult\fR(\fIinterp, dsPtr\fR)
  57. .SH ARGUMENTS
  58. .AS Tcl_DString newLength
  59. .AP Tcl_DString *dsPtr in/out
  60. Pointer to structure that is used to manage a dynamic string.
  61. .AP char *string in
  62. Pointer to characters to add to dynamic string.
  63. .AP int length in
  64. Number of characters from string to add to dynamic string.  If -1,
  65. add all characters up to null terminating character.
  66. .AP int newLength in
  67. New length for dynamic string, not including null terminating
  68. character.
  69. .BE
  70.  
  71. .SH DESCRIPTION
  72. .PP
  73. Dynamic strings provide a mechanism for building up arbitrarily long
  74. strings by gradually appending information.  If the dynamic string is
  75. short then there will be no memory allocation overhead;  as the string
  76. gets larger, additional space will be allocated as needed.
  77. .PP
  78. \fBTcl_DStringInit\fR initializes a dynamic string to zero length.
  79. The Tcl_DString structure must have been allocated by the caller.
  80. No assumptions are made about the current state of the structure;
  81. anything already in it is discarded.
  82. If the structure has been used previously, \fBTcl_DStringFree\fR should
  83. be called first to free up any memory allocated for the old
  84. string.
  85. .PP
  86. \fBTcl_DStringAppend\fR adds new information to a dynamic string,
  87. allocating more memory for the string if needed.
  88. If \fIlength\fR is less than zero then everything in \fIstring\fR
  89. is appended to the dynamic string;  otherwise \fIlength\fR
  90. specifies the number of bytes to append.
  91. \fBTcl_DStringAppend\fR returns a pointer to the characters of
  92. the new string.  The string can also be retrieved from the
  93. \fIstring\fR field of the Tcl_DString structure.
  94. .PP
  95. \fBTcl_DStringAppendElement\fR is similar to \fBTcl_DStringAppend\fR
  96. except that it doesn't take a \fIlength\fR argument (it appends
  97. all of \fIstring\fR) and it converts the string to a proper list element
  98. before appending.
  99. \fBTcl_DStringAppendElement\fR adds a separator space before the
  100. new list element unless the new list element is the first in a
  101. list or sub-list (i.e. either the current string is empty, or it
  102. contains the single character ``{'', or the last two characters of
  103. the current string are `` {'').
  104. \fBTcl_DStringAppendElement\fR returns a pointer to the
  105. characters of the new string.
  106. .PP
  107. \fBTcl_DStringStartSublist\fR and \fBTcl_DStringEndSublist\fR can be
  108. used to create nested lists.
  109. To append a list element that is itself a sublist, first
  110. call \fBTcl_DStringStartSublist\fR, then call \fBTcl_DStringAppendElement\fR
  111. for each of the elements in the sublist, then call
  112. \fBTcl_DStringEndSublist\fR to end the sublist.
  113. \fBTcl_DStringStartSublist\fR appends a space character if needed,
  114. followed by an open brace;  \fBTcl_DStringAppendElement\fR appends
  115. a close brace.
  116. Lists can be nested to any depth.
  117. .PP
  118. \fBTcl_DStringLength\fR is a macro that returns the current length
  119. of a dynamic string (not including the terminating null character).
  120. \fBTcl_DStringValue\fR is a  macro that returns a pointer to the
  121. current contents of a dynamic string.
  122. .PP
  123. \fBTcl_DStringTrunc\fR truncates a dynamic string to a given length.
  124. It has no effect if the string was already smaller than \fInewLength\fR.
  125. This procedure does not free up the string's storage space, even
  126. if the string is truncated to zero length, so \fBTcl_DStringFree\fR
  127. will still need to be called.
  128. .PP
  129. \fBTcl_DStringFree\fR should be called when you're finished using
  130. the string.  It frees up any memory that was allocated for the string
  131. and reinitializes the string's value to an empty string.
  132. .PP
  133. \fBTcl_DStringResult\fR sets the result of \fIinterp\fR to the value of
  134. the dynamic string given by \fIdsPtr\fR.  It does this by moving
  135. a pointer from \fIdsPtr\fR to \fIinterp->result\fR.
  136. This saves the cost of allocating new memory and copying the string.
  137. \fBTcl_DStringResult\fR also reinitializes the dynamic string to
  138. an empty string.
  139.  
  140. .SH KEYWORDS
  141. append, dynamic string, free, result
  142.