Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/tcl8.5.2/doc/SplitList.3 @ 43

Last change on this file since 43 was 25, checked in by landauf, 17 years ago

added tcl to libs

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