diff options
author | dgp <dgp@users.sourceforge.net> | 2011-05-02 20:17:50 (GMT) |
---|---|---|
committer | dgp <dgp@users.sourceforge.net> | 2011-05-02 20:17:50 (GMT) |
commit | b670c3cc9cd25e3c0bfcb9dc0025c79558b78d90 (patch) | |
tree | ef3b5e015a4811a57a9eb36926e198d8d5545c88 /generic/tclUtil.c | |
parent | 1658668d010de46f70b608c5c2edfba8f0b87b7c (diff) | |
parent | 4f558942fb97b0dd3652ee2a257fe94b1dc3a8db (diff) | |
download | tcl-b670c3cc9cd25e3c0bfcb9dc0025c79558b78d90.zip tcl-b670c3cc9cd25e3c0bfcb9dc0025c79558b78d90.tar.gz tcl-b670c3cc9cd25e3c0bfcb9dc0025c79558b78d90.tar.bz2 |
Revised TclFindElement() interface.
The final argument had been bracePtr, the address of a boolean var, where
the caller can be told whether or not the parsed list element was enclosed
in braces. In practice, no callers really care about that. What the callers
really want to know is whether the list element value exists as a literal
substring of the string being parsed, or whether a call to
TclCopyAndCollpase() is needed to produce the list element value. Now the
final argument is changed to do what callers actually need. This is a
better fit for the calls in tclParse.c, where now a good deal of
post-processing checking for "naked backslashes" is no longer necessary.
***POTENTIAL INCOMPATIBILITY***
For any callers calling in via the internal stubs table who really do use
the final argument explicitly to check for the enclosing brace scenario.
Simply looking for the braces where they must be is the revision available
to those callers, and it will backport cleanly.
Tests for expanded literals quoting detection.
Diffstat (limited to 'generic/tclUtil.c')
-rw-r--r-- | generic/tclUtil.c | 40 |
1 files changed, 30 insertions, 10 deletions
diff --git a/generic/tclUtil.c b/generic/tclUtil.c index d4630af..7baadff 100644 --- a/generic/tclUtil.c +++ b/generic/tclUtil.c @@ -180,8 +180,13 @@ TclMaxListLength( * after the opening brace and *sizePtr will not include either of the * braces. If there isn't an element in the list, *sizePtr will be zero, * and both *elementPtr and *termPtr will point just after the last - * character in the list. Note: this function does NOT collapse backslash - * sequences. + * character in the list. If literalPtr is non-NULL, *literalPtr is set + * to a boolean value indicating whether the substring returned as + * the values of **elementPtr and *sizePtr is the literal value of + * a list element. If not, a call to TclCopyAndCollapse() is needed + * to produce the actual value of the list element. Note: this function + * does NOT collapse backslash sequences, but uses *literalPtr to tell + * callers when it is required for them to do so. * * Side effects: * None. @@ -205,8 +210,12 @@ TclFindElement( * argument (next arg or end of list). */ int *sizePtr, /* If non-zero, fill in with size of * element. */ - int *bracePtr) /* If non-zero, fill in with non-zero/zero to - * indicate that arg was/wasn't in braces. */ + int *literalPtr) /* If non-zero, fill in with non-zero/zero to + * indicate that the substring of *sizePtr + * bytes starting at **elementPtr is/is not + * the literal list element and therefore + * does not/does require a call to + * TclCopyAndCollapse() by the caller. */ { const char *p = list; const char *elemStart; /* Points to first byte of first element. */ @@ -215,6 +224,7 @@ TclFindElement( int inQuotes = 0; int size = 0; /* lint. */ int numChars; + int literal = 1; const char *p2; /* @@ -240,9 +250,6 @@ TclFindElement( p++; } elemStart = p; - if (bracePtr != 0) { - *bracePtr = openBraces; - } /* * Find element's end (a space, close brace, or the end of the string). @@ -302,6 +309,15 @@ TclFindElement( */ case '\\': + if (openBraces == 0) { + /* + * A backslash sequence not within a brace quoted element + * means the value of the element is different from the + * substring we are parsing. A call to TclCopyAndCollapse() + * is needed to produce the element value. Inform the caller. + */ + literal = 0; + } TclParseBackslash(p, limit - p, &numChars, NULL); p += (numChars - 1); break; @@ -392,6 +408,9 @@ TclFindElement( if (sizePtr != 0) { *sizePtr = size; } + if (literalPtr != 0) { + *literalPtr = literal; + } return TCL_OK; } @@ -484,7 +503,7 @@ Tcl_SplitList( { const char **argv, *end, *element; char *p; - int length, size, i, result, elSize, brace; + int length, size, i, result, elSize; /* * Allocate enough space to work in. A (CONST char *) for each @@ -502,9 +521,10 @@ Tcl_SplitList( for (i = 0, p = ((char *) argv) + size*sizeof(char *); *list != 0; i++) { const char *prevList = list; + int literal; result = TclFindElement(interp, list, length, &element, &list, - &elSize, &brace); + &elSize, &literal); length -= (list - prevList); if (result != TCL_OK) { ckfree(argv); @@ -524,7 +544,7 @@ Tcl_SplitList( return TCL_ERROR; } argv[i] = p; - if (brace) { + if (literal) { memcpy(p, element, (size_t) elSize); p += elSize; *p = 0; |