diff options
author | dgp <dgp@users.sourceforge.net> | 2011-05-02 17:36:27 (GMT) |
---|---|---|
committer | dgp <dgp@users.sourceforge.net> | 2011-05-02 17:36:27 (GMT) |
commit | 58a04d6f1325fc9905ccac80234f9fc0d92b0318 (patch) | |
tree | 6f65c0c47bdc92c47d2ef7ec544c6961aca11467 /generic/tclUtil.c | |
parent | caea13f2776c1d71043747539553c566d4186553 (diff) | |
download | tcl-58a04d6f1325fc9905ccac80234f9fc0d92b0318.zip tcl-58a04d6f1325fc9905ccac80234f9fc0d92b0318.tar.gz tcl-58a04d6f1325fc9905ccac80234f9fc0d92b0318.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.
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 76676a1..fd3d935 100644 --- a/generic/tclUtil.c +++ b/generic/tclUtil.c @@ -181,8 +181,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. @@ -206,8 +211,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. */ @@ -216,6 +225,7 @@ TclFindElement( int inQuotes = 0; int size = 0; /* lint. */ int numChars; + int literal = 1; CONST char *p2; /* @@ -241,9 +251,6 @@ TclFindElement( p++; } elemStart = p; - if (bracePtr != 0) { - *bracePtr = openBraces; - } /* * Find element's end (a space, close brace, or the end of the string). @@ -301,6 +308,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; @@ -385,6 +401,9 @@ TclFindElement( if (sizePtr != 0) { *sizePtr = size; } + if (literalPtr != 0) { + *literalPtr = literal; + } return TCL_OK; } @@ -477,7 +496,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 @@ -496,9 +515,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((char *) argv); @@ -516,7 +536,7 @@ Tcl_SplitList( return TCL_ERROR; } argv[i] = p; - if (brace) { + if (literal) { memcpy(p, element, (size_t) elSize); p += elSize; *p = 0; |