SplitList.3
上传用户:rrhhcc
上传日期:2015-12-11
资源大小:54129k
文件大小:7k
- '"
- '" Copyright (c) 1989-1993 The Regents of the University of California.
- '" Copyright (c) 1994-1996 Sun Microsystems, Inc.
- '"
- '" See the file "license.terms" for information on usage and redistribution
- '" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
- '"
- '" RCS: @(#) $Id: SplitList.3,v 1.6 2002/01/25 20:40:55 dgp Exp $
- '"
- .so man.macros
- .TH Tcl_SplitList 3 8.0 Tcl "Tcl Library Procedures"
- .BS
- .SH NAME
- Tcl_SplitList, Tcl_Merge, Tcl_ScanElement, Tcl_ConvertElement, Tcl_ScanCountedElement, Tcl_ConvertCountedElement - manipulate Tcl lists
- .SH SYNOPSIS
- .nf
- fB#include <tcl.h>fR
- .sp
- int
- fBTcl_SplitListfR(fIinterp, list, argcPtr, argvPtrfR)
- .sp
- char *
- fBTcl_MergefR(fIargc, argvfR)
- .sp
- int
- fBTcl_ScanElementfR(fIsrc, flagsPtrfR)
- .sp
- int
- fBTcl_ScanCountedElementfR(fIsrc, length, flagsPtrfR)
- .sp
- int
- fBTcl_ConvertElementfR(fIsrc, dst, flagsfR)
- .sp
- int
- fBTcl_ConvertCountedElementfR(fIsrc, length, dst, flagsfR)
- .SH ARGUMENTS
- .AS "CONST char * CONST" ***argvPtr
- .AP Tcl_Interp *interp out
- Interpreter to use for error reporting. If NULL, then no error message
- is left.
- .AP char *list in
- Pointer to a string with proper list structure.
- .AP int *argcPtr out
- Filled in with number of elements in fIlistfR.
- .AP "CONST char" ***argvPtr out
- fI*argvPtrfR will be filled in with the address of an array of
- pointers to the strings that are the extracted elements of fIlistfR.
- There will be fI*argcPtrfR valid entries in the array, followed by
- a NULL entry.
- .AP int argc in
- Number of elements in fIargvfR.
- .AP "CONST char * CONST" *argv in
- Array of strings to merge together into a single list.
- Each string will become a separate element of the list.
- .AP "CONST char" *src in
- String that is to become an element of a list.
- .AP int *flagsPtr in
- Pointer to word to fill in with information about fIsrcfR.
- The value of *fIflagsPtrfR must be passed to fBTcl_ConvertElementfR.
- .AP int length in
- Number of bytes in string fIsrcfR.
- .AP char *dst in
- Place to copy converted list element. Must contain enough characters
- to hold converted string.
- .AP int flags in
- Information about fIsrcfR. Must be value returned by previous
- call to fBTcl_ScanElementfR, possibly OR-ed
- with fBTCL_DONT_USE_BRACESfR.
- .BE
- .SH DESCRIPTION
- .PP
- These procedures may be used to disassemble and reassemble Tcl lists.
- fBTcl_SplitListfR breaks a list up into its constituent elements,
- returning an array of pointers to the elements using
- fIargcPtrfR and fIargvPtrfR.
- While extracting the arguments, fBTcl_SplitListfR obeys the usual
- rules for backslash substitutions and braces. The area of
- memory pointed to by fI*argvPtrfR is dynamically allocated; in
- addition to the array of pointers, it
- also holds copies of all the list elements. It is the caller's
- responsibility to free up all of this storage.
- For example, suppose that you have called fBTcl_SplitListfR with
- the following code:
- .CS
- int argc, code;
- char *string;
- char **argv;
- &...
- code = Tcl_SplitList(interp, string, &argc, &argv);
- .CE
- Then you should eventually free the storage with a call like the
- following:
- .CS
- Tcl_Free((char *) argv);
- .CE
- .PP
- fBTcl_SplitListfR normally returns fBTCL_OKfR, which means the list was
- successfully parsed.
- If there was a syntax error in fIlistfR, then fBTCL_ERRORfR is returned
- and the interpreter's result will point to an error message describing the
- problem (if fIinterpfR was not NULL).
- If fBTCL_ERRORfR is returned then no memory is allocated and fI*argvPtrfR
- is not modified.
- .PP
- fBTcl_MergefR is the inverse of fBTcl_SplitListfR: it
- takes a collection of strings given by fIargcfR
- and fIargvfR and generates a result string
- that has proper list structure.
- This means that commands like fBindexfR may be used to
- extract the original elements again.
- In addition, if the result of fBTcl_MergefR is passed to fBTcl_EvalfR,
- it will be parsed into fIargcfR words whose values will
- be the same as the fIargvfR strings passed to fBTcl_MergefR.
- fBTcl_MergefR will modify the list elements with braces and/or
- backslashes in order to produce proper Tcl list structure.
- The result string is dynamically allocated
- using fBTcl_AllocfR; the caller must eventually release the space
- using fBTcl_FreefR.
- .PP
- If the result of fBTcl_MergefR is passed to fBTcl_SplitListfR,
- the elements returned by fBTcl_SplitListfR will be identical to
- those passed into fBTcl_MergefR.
- However, the converse is not true: if fBTcl_SplitListfR
- is passed a given string, and the resulting fIargcfR and
- fIargvfR are passed to fBTcl_MergefR, the resulting string
- may not be the same as the original string passed to fBTcl_SplitListfR.
- This is because fBTcl_MergefR may use backslashes and braces
- differently than the original string.
- .PP
- fBTcl_ScanElementfR and fBTcl_ConvertElementfR are the
- procedures that do all of the real work of fBTcl_MergefR.
- fBTcl_ScanElementfR scans its fIsrcfR argument
- and determines how to use backslashes and braces
- when converting it to a list element.
- It returns an overestimate of the number of characters
- required to represent fIsrcfR as a list element, and
- it stores information in fI*flagsPtrfR that is needed
- by fBTcl_ConvertElementfR.
- .PP
- fBTcl_ConvertElementfR is a companion procedure to fBTcl_ScanElementfR.
- It does the actual work of converting a string to a list element.
- Its fIflagsfR argument must be the same as the value returned
- by fBTcl_ScanElementfR.
- fBTcl_ConvertElementfR writes a proper list element to memory
- starting at *fIdstfR and returns a count of the total number
- of characters written, which will be no more than the result
- returned by fBTcl_ScanElementfR.
- fBTcl_ConvertElementfR writes out only the actual list element
- without any leading or trailing spaces: it is up to the caller to
- include spaces between adjacent list elements.
- .PP
- fBTcl_ConvertElementfR uses one of two different approaches to
- handle the special characters in fIsrcfR. Wherever possible, it
- handles special characters by surrounding the string with braces.
- This produces clean-looking output, but can't be used in some situations,
- such as when fIsrcfR contains unmatched braces.
- In these situations, fBTcl_ConvertElementfR handles special
- characters by generating backslash sequences for them.
- The caller may insist on the second approach by OR-ing the
- flag value returned by fBTcl_ScanElementfR with
- fBTCL_DONT_USE_BRACESfR.
- Although this will produce an uglier result, it is useful in some
- special situations, such as when fBTcl_ConvertElementfR is being
- used to generate a portion of an argument for a Tcl command.
- In this case, surrounding fIsrcfR with curly braces would cause
- the command not to be parsed correctly.
- .PP
- fBTcl_ScanCountedElementfR and fBTcl_ConvertCountedElementfR are
- the same as fBTcl_ScanElementfR and fBTcl_ConvertElementfR, except
- the length of string fIsrcfR is specified by the fIlengthfR
- argument, and the string may contain embedded nulls.
- .SH KEYWORDS
- backslash, convert, element, list, merge, split, strings