home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tcl2-73c.zip / tcl7.3 / doc / SplitList.3 < prev    next >
Text File  |  1993-04-01  |  7KB  |  165 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/SplitList.3,v 1.11 93/04/01 09:25:34 ouster Exp $ SPRITE (Berkeley)
  22. '\" 
  23. .so man.macros
  24. .HS Tcl_SplitList tclc
  25. .BS
  26. .SH NAME
  27. Tcl_SplitList, Tcl_Merge, Tcl_ScanElement, Tcl_ConvertElement \- manipulate Tcl lists
  28. .SH SYNOPSIS
  29. .nf
  30. \fB#include <tcl.h>\fR
  31. .sp
  32. int
  33. \fBTcl_SplitList\fR(\fIinterp, list, argcPtr, argvPtr\fR)
  34. .sp
  35. char *
  36. \fBTcl_Merge\fR(\fIargc, argv\fR)
  37. .sp
  38. int
  39. \fBTcl_ScanElement\fR(\fIsrc, flagsPtr\fR)
  40. .sp
  41. int
  42. \fBTcl_ConvertElement\fR(\fIsrc, dst, flags\fR)
  43. .SH ARGUMENTS
  44. .AS Tcl_Interp ***argvPtr
  45. .AP Tcl_Interp *interp out
  46. Interpreter to use for error reporting.
  47. .AP char *list in
  48. Pointer to a string with proper list structure.
  49. .AP int *argcPtr out
  50. Filled in with number of elements in \fIlist\fR.
  51. .AP char ***argvPtr out
  52. \fI*argvPtr\fR will be filled in with the address of an array of
  53. pointers to the strings that are the extracted elements of \fIlist\fR.
  54. There will be \fI*argcPtr\fR valid entries in the array, followed by
  55. a NULL entry.
  56. .AP int argc in
  57. Number of elements in \fIargv\fR.
  58. .AP char **argv in
  59. Array of strings to merge together into a single list.
  60. Each string will become a separate element of the list.
  61. .AP char *src in
  62. String that is to become an element of a list.
  63. .AP int *flagsPtr in
  64. Pointer to word to fill in with information about \fIsrc\fR.
  65. The value of *\fIflagsPtr\fR must be passed to \fBTcl_ConvertElement\fR.
  66. .AP char *dst in
  67. Place to copy converted list element.  Must contain enough characters
  68. to hold converted string.
  69. .AP int flags in
  70. Information about \fIsrc\fR. Must be value returned by previous
  71. call to \fBTcl_ScanElement\fR, possibly OR-ed
  72. with \fBTCL_DONT_USE_BRACES\fR.
  73. .BE
  74.  
  75. .SH DESCRIPTION
  76. .PP
  77. These procedures may be used to disassemble and reassemble Tcl lists.
  78. \fBTcl_SplitList\fR breaks a list up into its constituent elements,
  79. returning an array of pointers to the elements using
  80. \fIargcPtr\fR and \fIargvPtr\fR.
  81. While extracting the arguments, \fBTcl_SplitList\fR obeys the usual
  82. rules for backslash substitutions and braces.  The area of
  83. memory pointed to by \fI*argvPtr\fR is dynamically allocated;  in
  84. addition to the array of pointers, it
  85. also holds copies of all the list elements.  It is the caller's
  86. responsibility to free up all of this storage by calling
  87. .DS
  88. \fBfree\fR((char *) \fI*argvPtr\fR)
  89. .DE
  90. when the list elements are no longer needed.
  91. .PP
  92. \fBTcl_SplitList\fR normally returns \fBTCL_OK\fR, which means the list was
  93. successfully parsed.
  94. If there was a syntax error in \fIlist\fR, then \fBTCL_ERROR\fR is returned
  95. and \fIinterp->result\fR will point to an error message describing the
  96. problem.
  97. If \fBTCL_ERROR\fR is returned then no memory is allocated and \fI*argvPtr\fR
  98. is not modified.
  99. .PP
  100. \fBTcl_Merge\fR is the inverse of \fBTcl_SplitList\fR:  it
  101. takes a collection of strings given by \fIargc\fR
  102. and \fIargv\fR and generates a result string
  103. that has proper list structure.
  104. This means that commands like \fBindex\fR may be used to
  105. extract the original elements again.
  106. In addition, if the result of \fBTcl_Merge\fR is passed to \fBTcl_Eval\fR,
  107. it will be parsed into \fIargc\fR words whose values will
  108. be the same as the \fIargv\fR strings passed to \fBTcl_Merge\fR.
  109. \fBTcl_Merge\fR will modify the list elements with braces and/or
  110. backslashes in order to produce proper Tcl list structure.
  111. The result string is dynamically allocated
  112. using \fBmalloc()\fR;  the caller must eventually release the space
  113. using \fBfree()\fR.
  114. .PP
  115. If the result of \fBTcl_Merge\fR is passed to \fBTcl_SplitList\fR,
  116. the elements returned by \fBTcl_SplitList\fR will be identical to
  117. those passed into \fBTcl_Merge\fR.
  118. However, the converse is not true:  if \fBTcl_SplitList\fR
  119. is passed a given string, and the resulting \fIargc\fR and
  120. \fIargv\fR are passed to \fBTcl_Merge\fR, the resulting string
  121. may not be the same as the original string passed to \fBTcl_SplitList\fR.
  122. This is because \fBTcl_Merge\fR may use backslashes and braces
  123. differently than the original string.
  124. .PP
  125. \fBTcl_ScanElement\fR and \fBTcl_ConvertElement\fR are the
  126. procedures that do all of the real work of \fBTcl_Merge\fR.
  127. \fBTcl_ScanElement\fR scans its \fIsrc\fR argument
  128. and determines how to use backslashes and braces
  129. when converting it to a list element.
  130. It returns an overestimate of the number of characters
  131. required to represent \fIsrc\fR as a list element, and
  132. it stores information in \fI*flagsPtr\fR that is needed
  133. by \fBTcl_ConvertElement\fR.
  134. .PP
  135. \fBTcl_ConvertElement\fR is a companion procedure to \fBTcl_ScanElement\fR.
  136. It does the actual work of converting a string to a list element.
  137. Its \fIflags\fR argument must be the same as the value returned
  138. by \fBTcl_ScanElement\fR.
  139. \fBTcl_ConvertElement\fR writes a proper list element to memory
  140. starting at *\fIdst\fR and returns a count of the total number
  141. of characters written, which will be no more than the result
  142. returned by \fBTcl_ScanElement\fR.
  143. \fBTcl_ConvertElement\fR writes out only the actual list element
  144. without any leading or trailing spaces: it is up to the caller to
  145. include spaces between adjacent list elements.
  146. .PP
  147. \fBTcl_ConvertElement\fR uses one of two different approaches to
  148. handle the special characters in \fIsrc\fR.  Wherever possible, it
  149. handles special characters by surrounding the string with braces.
  150. This produces clean-looking output, but can't be used in some situations,
  151. such as when \fIsrc\fR contains unmatched braces.
  152. In these situations, \fBTcl_ConvertElement\fR handles special
  153. characters by generating backslash sequences for them.
  154. The caller may insist on the second approach by OR-ing the
  155. flag value returned by \fBTcl_ScanElement\fR with
  156. \fBTCL_DONT_USE_BRACES\fR.
  157. Although this will produce an uglier result, it is useful in some
  158. special situations, such as when \fBTcl_ConvertElement\fR is being
  159. used to generate a portion of an argument for a Tcl command.
  160. In this case, surrounding \fIsrc\fR with curly braces would cause
  161. the command not to be parsed correctly.
  162.  
  163. .SH KEYWORDS
  164. backslash, convert, element, list, merge, split, strings
  165.