summaryrefslogtreecommitdiffstats
path: root/generic/tclUtil.c
diff options
context:
space:
mode:
authordgp <dgp@users.sourceforge.net>2003-09-04 16:44:11 (GMT)
committerdgp <dgp@users.sourceforge.net>2003-09-04 16:44:11 (GMT)
commit50a76c2d9e2b751c9ca040cbb8308ca088f3d034 (patch)
treee4dab2e65e57de3f104811a01c704395859cc326 /generic/tclUtil.c
parentdbcc5e83bdefe43d400134dba999965c93892c73 (diff)
downloadtcl-50a76c2d9e2b751c9ca040cbb8308ca088f3d034.zip
tcl-50a76c2d9e2b751c9ca040cbb8308ca088f3d034.tar.gz
tcl-50a76c2d9e2b751c9ca040cbb8308ca088f3d034.tar.bz2
* doc/SplitList.3: Implementation of TIP 148. Fixes [Bug 489537].
* generic/tcl.h: Updated Tcl_ConvertCountedElement() to quote * generic/tclUtil.c: the leading "#" character of all list elements unless the TCL_DONT_QUOTE_HASH flag is passed in. * generic/tclDictObj.c: Updated Tcl_ConvertCountedElement() callers * generic/tclListObj.c: to pass in the TCL_DONT_QUOTE_HASH flags * generic/tclResult.c: when appropriate.
Diffstat (limited to 'generic/tclUtil.c')
-rw-r--r--generic/tclUtil.c37
1 files changed, 32 insertions, 5 deletions
diff --git a/generic/tclUtil.c b/generic/tclUtil.c
index 4321833..10cddf2 100644
--- a/generic/tclUtil.c
+++ b/generic/tclUtil.c
@@ -11,7 +11,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclUtil.c,v 1.42 2003/08/27 21:31:05 dgp Exp $
+ * RCS: @(#) $Id: tclUtil.c,v 1.43 2003/09/04 16:44:12 dgp Exp $
*/
#include "tclInt.h"
@@ -29,9 +29,9 @@ char *tclNativeExecutableName = NULL;
/*
* The following values are used in the flags returned by Tcl_ScanElement
- * and used by Tcl_ConvertElement. The value TCL_DONT_USE_BRACES is also
- * defined in tcl.h; make sure its value doesn't overlap with any of the
- * values below.
+ * and used by Tcl_ConvertElement. The values TCL_DONT_USE_BRACES and
+ * TCL_DONT_QUOTE_HASH are defined in tcl.h; make sure neither value
+ * overlaps with any of the values below.
*
* TCL_DONT_USE_BRACES - 1 means the string mustn't be enclosed in
* braces (e.g. it contains unmatched braces,
@@ -43,6 +43,12 @@ char *tclNativeExecutableName = NULL;
* enclosing the entire argument in braces.
* BRACES_UNMATCHED - 1 means that braces aren't properly matched
* in the argument.
+ * TCL_DONT_QUOTE_HASH - 1 means the caller insists that a leading
+ * hash character ('#') should *not* be quoted.
+ * This is appropriate when the caller can
+ * guarantee the element is not the first element
+ * of a list, so [eval] cannot mis-parse the
+ * element as a comment.
*/
#define USE_BRACES 2
@@ -733,6 +739,9 @@ Tcl_ConvertCountedElement(src, length, dst, flags)
return 2;
}
lastChar = src + length;
+ if ((*src == '#') && !(flags & TCL_DONT_QUOTE_HASH)) {
+ flags |= USE_BRACES;
+ }
if ((flags & USE_BRACES) && !(flags & TCL_DONT_USE_BRACES)) {
*p = '{';
p++;
@@ -755,6 +764,17 @@ Tcl_ConvertCountedElement(src, length, dst, flags)
p += 2;
src++;
flags |= BRACES_UNMATCHED;
+ } else if ((*src == '#') && !(flags & TCL_DONT_QUOTE_HASH)) {
+ /*
+ * Leading '#' could be seen by [eval] as the start of
+ * a comment, if on the first element of a list, so
+ * quote it.
+ */
+
+ p[0] = '\\';
+ p[1] = '#';
+ p += 2;
+ src++;
}
for (; src != lastChar; src++) {
switch (*src) {
@@ -877,7 +897,8 @@ Tcl_Merge(argc, argv)
result = (char *) ckalloc((unsigned) numChars);
dst = result;
for (i = 0; i < argc; i++) {
- numChars = Tcl_ConvertElement(argv[i], dst, flagPtr[i]);
+ numChars = Tcl_ConvertElement(argv[i], dst,
+ flagPtr[i] | (i==0 ? 0 : TCL_DONT_QUOTE_HASH) );
dst += numChars;
*dst = ' ';
dst++;
@@ -1556,6 +1577,12 @@ Tcl_DStringAppendElement(dsPtr, string)
*dst = ' ';
dst++;
dsPtr->length++;
+ /*
+ * If we need a space to separate this element from preceding
+ * stuff, then this element will not lead a list, and need not
+ * have it's leading '#' quoted.
+ */
+ flags |= TCL_DONT_QUOTE_HASH;
}
dsPtr->length += Tcl_ConvertCountedElement(string, strSize, dst, flags);
return dsPtr->string;