📄 splitlist.3
字号:
'\"'\" 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.'\" '\" SCCS: @(#) SplitList.3 1.21 97/04/29 14:07:10'\" .so man.macros.TH Tcl_SplitList 3 7.5 Tcl "Tcl Library Procedures".BS.SH NAMETcl_SplitList, Tcl_Merge, Tcl_ScanElement, Tcl_ConvertElement \- manipulate Tcl lists.SH SYNOPSIS.nf\fB#include <tcl.h>\fR.spint\fBTcl_SplitList\fR(\fIinterp, list, argcPtr, argvPtr\fR).spchar *\fBTcl_Merge\fR(\fIargc, argv\fR).spint\fBTcl_ScanElement\fR(\fIsrc, flagsPtr\fR).VS.spint\fBTcl_ScanCountedElement\fR(\fIsrc, length, flagsPtr\fR).VE.spint\fBTcl_ConvertElement\fR(\fIsrc, dst, flags\fR).VS.spint\fBTcl_ConvertCountedElement\fR(\fIsrc, length, dst, flags\fR).VE.SH ARGUMENTS.AS Tcl_Interp ***argvPtr.AP Tcl_Interp *interp out.VSInterpreter to use for error reporting. If NULL, then no error messageis left..VE.AP char *list inPointer to a string with proper list structure..AP int *argcPtr outFilled in with number of elements in \fIlist\fR..AP char ***argvPtr out\fI*argvPtr\fR will be filled in with the address of an array ofpointers to the strings that are the extracted elements of \fIlist\fR.There will be \fI*argcPtr\fR valid entries in the array, followed bya NULL entry..AP int argc inNumber of elements in \fIargv\fR..AP char **argv inArray of strings to merge together into a single list.Each string will become a separate element of the list..AP char *src inString that is to become an element of a list..AP int *flagsPtr inPointer to word to fill in with information about \fIsrc\fR.The value of *\fIflagsPtr\fR must be passed to \fBTcl_ConvertElement\fR..VS.AP int length inNumber of bytes in string \fIsrc\fR..VE.AP char *dst inPlace to copy converted list element. Must contain enough charactersto hold converted string..AP int flags inInformation about \fIsrc\fR. Must be value returned by previouscall to \fBTcl_ScanElement\fR, possibly OR-edwith \fBTCL_DONT_USE_BRACES\fR..BE.SH DESCRIPTION.PPThese procedures may be used to disassemble and reassemble Tcl lists.\fBTcl_SplitList\fR breaks a list up into its constituent elements,returning an array of pointers to the elements using\fIargcPtr\fR and \fIargvPtr\fR.While extracting the arguments, \fBTcl_SplitList\fR obeys the usualrules for backslash substitutions and braces. The area ofmemory pointed to by \fI*argvPtr\fR is dynamically allocated; inaddition to the array of pointers, italso holds copies of all the list elements. It is the caller'sresponsibility to free up all of this storage.For example, suppose that you have called \fBTcl_SplitList\fR withthe following code:.CSint argc, code;char *string;char **argv;\&...code = Tcl_SplitList(interp, string, &argc, &argv);.CEThen you should eventually free the storage with a call like thefollowing:.VS.CSTcl_Free((char *) argv);.CE.VE.PP\fBTcl_SplitList\fR normally returns \fBTCL_OK\fR, which means the list wassuccessfully parsed.If there was a syntax error in \fIlist\fR, then \fBTCL_ERROR\fR is returnedand \fIinterp->result\fR will point to an error message describing the.VSproblem (if \fIinterp\fR was not NULL)..VEIf \fBTCL_ERROR\fR is returned then no memory is allocated and \fI*argvPtr\fRis not modified..PP\fBTcl_Merge\fR is the inverse of \fBTcl_SplitList\fR: ittakes a collection of strings given by \fIargc\fRand \fIargv\fR and generates a result stringthat has proper list structure.This means that commands like \fBindex\fR may be used toextract the original elements again.In addition, if the result of \fBTcl_Merge\fR is passed to \fBTcl_Eval\fR,it will be parsed into \fIargc\fR words whose values willbe the same as the \fIargv\fR strings passed to \fBTcl_Merge\fR.\fBTcl_Merge\fR will modify the list elements with braces and/orbackslashes in order to produce proper Tcl list structure..VSThe result string is dynamically allocatedusing \fBTcl_Alloc\fR; the caller must eventually release the spaceusing \fBTcl_Free\fR..VE.PPIf the result of \fBTcl_Merge\fR is passed to \fBTcl_SplitList\fR,the elements returned by \fBTcl_SplitList\fR will be identical tothose passed into \fBTcl_Merge\fR.However, the converse is not true: if \fBTcl_SplitList\fRis passed a given string, and the resulting \fIargc\fR and\fIargv\fR are passed to \fBTcl_Merge\fR, the resulting stringmay not be the same as the original string passed to \fBTcl_SplitList\fR.This is because \fBTcl_Merge\fR may use backslashes and bracesdifferently than the original string..PP\fBTcl_ScanElement\fR and \fBTcl_ConvertElement\fR are theprocedures that do all of the real work of \fBTcl_Merge\fR.\fBTcl_ScanElement\fR scans its \fIsrc\fR argumentand determines how to use backslashes and braceswhen converting it to a list element.It returns an overestimate of the number of charactersrequired to represent \fIsrc\fR as a list element, andit stores information in \fI*flagsPtr\fR that is neededby \fBTcl_ConvertElement\fR..PP\fBTcl_ConvertElement\fR is a companion procedure to \fBTcl_ScanElement\fR.It does the actual work of converting a string to a list element.Its \fIflags\fR argument must be the same as the value returnedby \fBTcl_ScanElement\fR.\fBTcl_ConvertElement\fR writes a proper list element to memorystarting at *\fIdst\fR and returns a count of the total numberof characters written, which will be no more than the resultreturned by \fBTcl_ScanElement\fR.\fBTcl_ConvertElement\fR writes out only the actual list elementwithout any leading or trailing spaces: it is up to the caller toinclude spaces between adjacent list elements..PP\fBTcl_ConvertElement\fR uses one of two different approaches tohandle the special characters in \fIsrc\fR. Wherever possible, ithandles special characters by surrounding the string with braces.This produces clean-looking output, but can't be used in some situations,such as when \fIsrc\fR contains unmatched braces.In these situations, \fBTcl_ConvertElement\fR handles specialcharacters by generating backslash sequences for them.The caller may insist on the second approach by OR-ing theflag value returned by \fBTcl_ScanElement\fR with\fBTCL_DONT_USE_BRACES\fR.Although this will produce an uglier result, it is useful in somespecial situations, such as when \fBTcl_ConvertElement\fR is beingused to generate a portion of an argument for a Tcl command.In this case, surrounding \fIsrc\fR with curly braces would causethe command not to be parsed correctly..PP.VS\fBTcl_ScanCountedElement\fR and \fBTcl_ConvertCountedElement\fR arethe same as \fBTcl_ScanElement\fR and \fBTcl_ConvertElement\fR, exceptthe length of string \fIsrc\fR is specified by the \fIlength\fRargument, and the string may contain embedded nulls..VE.SH KEYWORDSbackslash, convert, element, list, merge, split, strings
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -