diff options
author | dgp <dgp@users.sourceforge.net> | 2005-09-14 17:13:18 (GMT) |
---|---|---|
committer | dgp <dgp@users.sourceforge.net> | 2005-09-14 17:13:18 (GMT) |
commit | 9e5a076c152f19abbf9f1b67392bd2072bac77c7 (patch) | |
tree | 6faa8807c6893dae4bd8cd9d5668a911697e0dfe /generic/tclStringObj.c | |
parent | d6a5a988b1a1360a77a043ec10d175c8a6c0fd36 (diff) | |
download | tcl-9e5a076c152f19abbf9f1b67392bd2072bac77c7.zip tcl-9e5a076c152f19abbf9f1b67392bd2072bac77c7.tar.gz tcl-9e5a076c152f19abbf9f1b67392bd2072bac77c7.tar.bz2 |
* generic/tclStringObj.c: Bug fixes: ObjPrintfVA needed to
support "*" fields and needed to interpret precision limits on
%s conversions as a number of bytes, not Tcl_UniChars, to take
from the (char *) argument.
* generic/tclBasic.c: Updated several callers to use
* generic/tclCmdMZ.c: TclFormatToErrorInfo().
* generic/tclIOUtil.c:
* library/init.tcl: Keep [unknown] in sync with errorInfo
formatting rules.
Diffstat (limited to 'generic/tclStringObj.c')
-rw-r--r-- | generic/tclStringObj.c | 36 |
1 files changed, 31 insertions, 5 deletions
diff --git a/generic/tclStringObj.c b/generic/tclStringObj.c index 802e94a..a2bce94 100644 --- a/generic/tclStringObj.c +++ b/generic/tclStringObj.c @@ -33,7 +33,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclStringObj.c,v 1.45 2005/09/14 03:46:50 dgp Exp $ */ + * RCS: @(#) $Id: tclStringObj.c,v 1.46 2005/09/14 17:13:18 dgp Exp $ */ #include "tclInt.h" @@ -2284,12 +2284,14 @@ ObjPrintfVA( int code, objc; Tcl_Obj **objv, *list = Tcl_NewObj(); CONST char *p; + char *end; p = format; Tcl_IncrRefCount(list); while (*p != '\0') { - int size = 0; - int seekingConversion = 1; + int size = 0, seekingConversion = 1, gotPrecision = 0; + int lastNum = -1, numBytes = -1; + if (*p++ != '%') { continue; } @@ -2304,9 +2306,18 @@ ObjPrintfVA( seekingConversion = 0; break; case 's': - Tcl_ListObjAppendElement(NULL, list, Tcl_NewStringObj( - va_arg(argList, char *), -1)); seekingConversion = 0; + if (gotPrecision) { + numBytes = lastNum; + } + Tcl_ListObjAppendElement(NULL, list, Tcl_NewStringObj( + va_arg(argList, char *), numBytes)); + /* We took no more than numBytes bytes from the (char *). + * In turn, [format] will take no more than numBytes + * characters from the Tcl_Obj. Since numBytes characters + * must be no less than numBytes bytes, the character limit + * will have no effect and we can just pass it through. + */ break; case 'c': case 'i': @@ -2337,6 +2348,21 @@ ObjPrintfVA( va_arg(argList, double))); seekingConversion = 0; break; + case '*': + lastNum = (int)va_arg(argList, int); + Tcl_ListObjAppendElement(NULL, list, Tcl_NewIntObj(lastNum)); + p++; + break; + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + lastNum = (int) strtoul(p, &end, 10); + p = end; + break; + case '.': + gotPrecision = 1; + p++; + break; + /* TODO: support for wide (and bignum?) arguments */ case 'l': size = 1; p++; |