OSDN Git Service

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