summaryrefslogtreecommitdiffstats
path: root/generic/tclCmdAH.c
diff options
context:
space:
mode:
authordgp <dgp@users.sourceforge.net>2005-09-09 15:44:26 (GMT)
committerdgp <dgp@users.sourceforge.net>2005-09-09 15:44:26 (GMT)
commit9d73340679f7c5a710e47d19fe4cdfc41461afe3 (patch)
tree1ebbce67249a6ad57eb32c616b35a98b89eaf09e /generic/tclCmdAH.c
parent8edbe2e47e1209c5af81525c10cf38d303a796c5 (diff)
downloadtcl-9d73340679f7c5a710e47d19fe4cdfc41461afe3.zip
tcl-9d73340679f7c5a710e47d19fe4cdfc41461afe3.tar.gz
tcl-9d73340679f7c5a710e47d19fe4cdfc41461afe3.tar.bz2
* generic/tclInt.h: New internal routines TclFormatObj()
* generic/tclStringObj.c: and TclAppendFormattedObjs() to offer sprintf()-like means to append to Tcl_Obj. Work in progress toward [RFE 572392]. * generic/tclCmdAH.c: Compiler directive NEW_FORMAT when #define'd directs the [format] command to be implemented in terms of the new TclAppendFormattedObjs() routine.
Diffstat (limited to 'generic/tclCmdAH.c')
-rw-r--r--generic/tclCmdAH.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/generic/tclCmdAH.c b/generic/tclCmdAH.c
index 9e9ab9c..9d84adf 100644
--- a/generic/tclCmdAH.c
+++ b/generic/tclCmdAH.c
@@ -10,7 +10,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclCmdAH.c,v 1.66 2005/08/26 13:26:55 dkf Exp $
+ * RCS: @(#) $Id: tclCmdAH.c,v 1.67 2005/09/09 15:44:27 dgp Exp $
*/
#include "tclInt.h"
@@ -1900,6 +1900,7 @@ Tcl_FormatObjCmd(dummy, interp, objc, objv)
int objc; /* Number of arguments. */
Tcl_Obj *CONST objv[]; /* Argument objects. */
{
+#ifndef NEW_FORMAT
char *format; /* Used to read characters from the format
* string. */
int formatLen; /* The length of the format string */
@@ -1932,7 +1933,9 @@ Tcl_FormatObjCmd(dummy, interp, objc, objv)
#define WIDE_VALUE 5
#define MAX_FLOAT_SIZE 320
+#endif
Tcl_Obj *resultPtr; /* Where result is stored finally. */
+#ifndef NEW_FORMAT
char staticBuf[MAX_FLOAT_SIZE + 1];
/* A static buffer to copy the format results
* into */
@@ -1974,12 +1977,25 @@ Tcl_FormatObjCmd(dummy, interp, objc, objv)
* So, what happens here is to scan the format string one % group at a
* time, making many individual calls to sprintf.
*/
+#endif
if (objc < 2) {
Tcl_WrongNumArgs(interp, 1, objv, "formatString ?arg arg ...?");
return TCL_ERROR;
}
+#ifdef NEW_FORMAT
+ resultPtr = Tcl_NewObj();
+ Tcl_IncrRefCount(resultPtr);
+ if (TclAppendFormattedObjs(interp, resultPtr, Tcl_GetString(objv[1]),
+ objc-2, objv+2) != TCL_OK) {
+ Tcl_DecrRefCount(resultPtr);
+ return TCL_ERROR;
+ }
+ Tcl_SetObjResult(interp, resultPtr);
+ Tcl_DecrRefCount(resultPtr);
+ return TCL_OK;
+#else
format = Tcl_GetStringFromObj(objv[1], &formatLen);
endPtr = format + formatLen;
resultPtr = Tcl_NewObj();
@@ -2381,6 +2397,7 @@ Tcl_FormatObjCmd(dummy, interp, objc, objv)
}
Tcl_DecrRefCount(resultPtr);
return TCL_ERROR;
+#endif
}
/*