2 '\" Copyright (c) 1989-1993 The Regents of the University of California.
3 '\" Copyright (c) 1994-1996 Sun Microsystems, Inc.
5 '\" See the file "license.terms" for information on usage and redistribution
6 '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
8 '\" RCS: @(#) $Id: SplitList.3,v 1.3 2000/04/14 23:01:53 hobbs Exp $
10 '\" The definitions below are for supplemental macros used in Tcl/Tk
13 '\" .AP type name in/out ?indent?
14 '\" Start paragraph describing an argument to a library procedure.
15 '\" type is type of argument (int, etc.), in/out is either "in", "out",
16 '\" or "in/out" to describe whether procedure reads or modifies arg,
17 '\" and indent is equivalent to second arg of .IP (shouldn't ever be
18 '\" needed; use .AS below instead)
21 '\" Give maximum sizes of arguments for setting tab stops. Type and
22 '\" name are examples of largest possible arguments that will be passed
23 '\" to .AP later. If args are omitted, default tab stops are used.
26 '\" Start box enclosure. From here until next .BE, everything will be
27 '\" enclosed in one large box.
30 '\" End of box enclosure.
33 '\" Begin code excerpt.
38 '\" .VS ?version? ?br?
39 '\" Begin vertical sidebar, for use in marking newly-changed parts
40 '\" of man pages. The first argument is ignored and used for recording
41 '\" the version when the .VS was added, so that the sidebars can be
42 '\" found and removed when they reach a certain age. If another argument
43 '\" is present, then a line break is forced before starting the sidebar.
46 '\" End of vertical sidebar.
49 '\" Begin an indented unfilled display.
52 '\" End of indented unfilled display.
55 '\" Start of list of standard options for a Tk widget. The
56 '\" options follow on successive lines, in four columns separated
60 '\" End of list of standard options for a Tk widget.
62 '\" .OP cmdName dbName dbClass
63 '\" Start of description of a specific option. cmdName gives the
64 '\" option's name as specified in the class command, dbName gives
65 '\" the option's name in the option database, and dbClass gives
66 '\" the option's class in the option database.
69 '\" Print arg1 underlined, then print arg2 normally.
71 '\" RCS: @(#) $Id: man.macros,v 1.3 1999/04/16 00:46:35 stanton Exp $
73 '\" # Set up traps and other miscellaneous stuff for Tcl/Tk man pages.
77 '\" # Start an argument description
81 . ie !"\\$2"" .TP \\n()Cu
86 \&\\$1 \\fI\\$2\\fP (\\$3)
99 '\" # define tabbing values for .AP
102 .if !"\\$1"" .nr )A \\w'\\$1'u+3n
105 .if !"\\$2"" .nr )B \\w'\\$2'u+\\n()Au+3n
106 .nr )C \\n()Bu+\\w'(in/out)'u+2n
108 .AS Tcl_Interp Tcl_CreateInterp in/out
109 '\" # BS - start boxed text
110 '\" # ^y = starting y location
118 .if n \l'\\n(.lu\(ul'
121 '\" # BE - end boxed text (draw box now)
126 .ie n \l'\\n(^lu\(ul'
128 .\" Draw four-sided box normally, but don't draw top of
129 .\" box if the box started on an earlier page.
131 \h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul'
134 \h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul'
141 '\" # VS - start vertical sidebar
142 '\" # ^Y = starting y location
143 '\" # ^v = 1 (for troff; for nroff this doesn't matter)
147 .ie n 'mc \s12\(br\s0
150 '\" # VE - end of vertical sidebar
158 \h'|\\n(^lu+3n'\L'|\\n(^Yu-1v\(bv'\v'\\n(^tu+1v-\\n(^Yu'\h'-|\\n(^lu+3n'
165 '\" # Special macro to handle page bottom: finish off current
166 '\" # box/sidebar if in box/sidebar mode, then invoked standard
167 '\" # page bottom macro.
174 .\" Draw three-sided box if this is the box's first page,
175 .\" draw two sides but no top otherwise.
176 .ie !\\n(^b-1 \h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\h'|0u'\c
177 .el \h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\h'|0u'\c
180 .nr ^x \\n(^tu+1v-\\n(^Yu
181 \kx\h'-\\nxu'\h'|\\n(^lu+3n'\ky\L'-\\n(^xu'\v'\\n(^xu'\h'|0u'\c
194 '\" # DS - begin display
200 '\" # DE - end display
206 '\" # SO - start of list of standard options
208 .SH "STANDARD OPTIONS"
214 '\" # SE - end of list of standard options
219 See the \\fBoptions\\fR manual entry for details on the standard options.
221 '\" # OP - start of full description for a single option
226 Command-Line Name: \\fB\\$1\\fR
227 Database Name: \\fB\\$2\\fR
228 Database Class: \\fB\\$3\\fR
232 '\" # CS - begin code excerpt
238 '\" # CE - end code excerpt
246 .TH Tcl_SplitList 3 8.0 Tcl "Tcl Library Procedures"
249 Tcl_SplitList, Tcl_Merge, Tcl_ScanElement, Tcl_ConvertElement \- manipulate Tcl lists
252 \fB#include <tcl.h>\fR
255 \fBTcl_SplitList\fR(\fIinterp, list, argcPtr, argvPtr\fR)
258 \fBTcl_Merge\fR(\fIargc, argv\fR)
261 \fBTcl_ScanElement\fR(\fIsrc, flagsPtr\fR)
264 \fBTcl_ScanCountedElement\fR(\fIsrc, length, flagsPtr\fR)
267 \fBTcl_ConvertElement\fR(\fIsrc, dst, flags\fR)
270 \fBTcl_ConvertCountedElement\fR(\fIsrc, length, dst, flags\fR)
272 .AS Tcl_Interp ***argvPtr
273 .AP Tcl_Interp *interp out
274 Interpreter to use for error reporting. If NULL, then no error message
277 Pointer to a string with proper list structure.
279 Filled in with number of elements in \fIlist\fR.
280 .AP char ***argvPtr out
281 \fI*argvPtr\fR will be filled in with the address of an array of
282 pointers to the strings that are the extracted elements of \fIlist\fR.
283 There will be \fI*argcPtr\fR valid entries in the array, followed by
286 Number of elements in \fIargv\fR.
288 Array of strings to merge together into a single list.
289 Each string will become a separate element of the list.
291 String that is to become an element of a list.
293 Pointer to word to fill in with information about \fIsrc\fR.
294 The value of *\fIflagsPtr\fR must be passed to \fBTcl_ConvertElement\fR.
296 Number of bytes in string \fIsrc\fR.
298 Place to copy converted list element. Must contain enough characters
299 to hold converted string.
301 Information about \fIsrc\fR. Must be value returned by previous
302 call to \fBTcl_ScanElement\fR, possibly OR-ed
303 with \fBTCL_DONT_USE_BRACES\fR.
308 These procedures may be used to disassemble and reassemble Tcl lists.
309 \fBTcl_SplitList\fR breaks a list up into its constituent elements,
310 returning an array of pointers to the elements using
311 \fIargcPtr\fR and \fIargvPtr\fR.
312 While extracting the arguments, \fBTcl_SplitList\fR obeys the usual
313 rules for backslash substitutions and braces. The area of
314 memory pointed to by \fI*argvPtr\fR is dynamically allocated; in
315 addition to the array of pointers, it
316 also holds copies of all the list elements. It is the caller's
317 responsibility to free up all of this storage.
318 For example, suppose that you have called \fBTcl_SplitList\fR with
325 code = Tcl_SplitList(interp, string, &argc, &argv);
327 Then you should eventually free the storage with a call like the
330 Tcl_Free((char *) argv);
333 \fBTcl_SplitList\fR normally returns \fBTCL_OK\fR, which means the list was
335 If there was a syntax error in \fIlist\fR, then \fBTCL_ERROR\fR is returned
336 and the interpreter's result will point to an error message describing the
337 problem (if \fIinterp\fR was not NULL).
338 If \fBTCL_ERROR\fR is returned then no memory is allocated and \fI*argvPtr\fR
341 \fBTcl_Merge\fR is the inverse of \fBTcl_SplitList\fR: it
342 takes a collection of strings given by \fIargc\fR
343 and \fIargv\fR and generates a result string
344 that has proper list structure.
345 This means that commands like \fBindex\fR may be used to
346 extract the original elements again.
347 In addition, if the result of \fBTcl_Merge\fR is passed to \fBTcl_Eval\fR,
348 it will be parsed into \fIargc\fR words whose values will
349 be the same as the \fIargv\fR strings passed to \fBTcl_Merge\fR.
350 \fBTcl_Merge\fR will modify the list elements with braces and/or
351 backslashes in order to produce proper Tcl list structure.
352 The result string is dynamically allocated
353 using \fBTcl_Alloc\fR; the caller must eventually release the space
354 using \fBTcl_Free\fR.
356 If the result of \fBTcl_Merge\fR is passed to \fBTcl_SplitList\fR,
357 the elements returned by \fBTcl_SplitList\fR will be identical to
358 those passed into \fBTcl_Merge\fR.
359 However, the converse is not true: if \fBTcl_SplitList\fR
360 is passed a given string, and the resulting \fIargc\fR and
361 \fIargv\fR are passed to \fBTcl_Merge\fR, the resulting string
362 may not be the same as the original string passed to \fBTcl_SplitList\fR.
363 This is because \fBTcl_Merge\fR may use backslashes and braces
364 differently than the original string.
366 \fBTcl_ScanElement\fR and \fBTcl_ConvertElement\fR are the
367 procedures that do all of the real work of \fBTcl_Merge\fR.
368 \fBTcl_ScanElement\fR scans its \fIsrc\fR argument
369 and determines how to use backslashes and braces
370 when converting it to a list element.
371 It returns an overestimate of the number of characters
372 required to represent \fIsrc\fR as a list element, and
373 it stores information in \fI*flagsPtr\fR that is needed
374 by \fBTcl_ConvertElement\fR.
376 \fBTcl_ConvertElement\fR is a companion procedure to \fBTcl_ScanElement\fR.
377 It does the actual work of converting a string to a list element.
378 Its \fIflags\fR argument must be the same as the value returned
379 by \fBTcl_ScanElement\fR.
380 \fBTcl_ConvertElement\fR writes a proper list element to memory
381 starting at *\fIdst\fR and returns a count of the total number
382 of characters written, which will be no more than the result
383 returned by \fBTcl_ScanElement\fR.
384 \fBTcl_ConvertElement\fR writes out only the actual list element
385 without any leading or trailing spaces: it is up to the caller to
386 include spaces between adjacent list elements.
388 \fBTcl_ConvertElement\fR uses one of two different approaches to
389 handle the special characters in \fIsrc\fR. Wherever possible, it
390 handles special characters by surrounding the string with braces.
391 This produces clean-looking output, but can't be used in some situations,
392 such as when \fIsrc\fR contains unmatched braces.
393 In these situations, \fBTcl_ConvertElement\fR handles special
394 characters by generating backslash sequences for them.
395 The caller may insist on the second approach by OR-ing the
396 flag value returned by \fBTcl_ScanElement\fR with
397 \fBTCL_DONT_USE_BRACES\fR.
398 Although this will produce an uglier result, it is useful in some
399 special situations, such as when \fBTcl_ConvertElement\fR is being
400 used to generate a portion of an argument for a Tcl command.
401 In this case, surrounding \fIsrc\fR with curly braces would cause
402 the command not to be parsed correctly.
404 \fBTcl_ScanCountedElement\fR and \fBTcl_ConvertCountedElement\fR are
405 the same as \fBTcl_ScanElement\fR and \fBTcl_ConvertElement\fR, except
406 the length of string \fIsrc\fR is specified by the \fIlength\fR
407 argument, and the string may contain embedded nulls.
410 backslash, convert, element, list, merge, split, strings