summaryrefslogtreecommitdiffstats
path: root/generic/tclCmdAH.c
diff options
context:
space:
mode:
Diffstat (limited to 'generic/tclCmdAH.c')
-rw-r--r--generic/tclCmdAH.c23
1 files changed, 17 insertions, 6 deletions
diff --git a/generic/tclCmdAH.c b/generic/tclCmdAH.c
index 14ac7f6..b86ea42 100644
--- a/generic/tclCmdAH.c
+++ b/generic/tclCmdAH.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: tclCmdAH.c,v 1.8 1999/08/19 02:59:08 hobbs Exp $
+ * RCS: @(#) $Id: tclCmdAH.c,v 1.9 1999/09/21 04:20:39 hobbs Exp $
*/
#include "tclInt.h"
@@ -1917,6 +1917,8 @@ Tcl_FormatObjCmd(dummy, interp, objc, objv)
* been seen in the current field. */
int gotPrecision; /* Non-zero indicates that a precision has
* been set for the current field. */
+ int gotZero; /* Non-zero indicates that a zero flag has
+ * been seen in the current field. */
/*
* This procedure is a bit nasty. The goal is to use sprintf to
@@ -1945,7 +1947,7 @@ Tcl_FormatObjCmd(dummy, interp, objc, objv)
register char *newPtr = newFormat;
width = precision = noPercent = useShort = 0;
- gotMinus = gotPrecision = 0;
+ gotZero = gotMinus = gotPrecision = 0;
whichValue = PTR_VALUE;
/*
@@ -2014,6 +2016,13 @@ Tcl_FormatObjCmd(dummy, interp, objc, objv)
if (*format == '-') {
gotMinus = 1;
}
+ if (*format == '0') {
+ /*
+ * This will be handled by sprintf for numbers, but we
+ * need to do the char/string ones ourselves
+ */
+ gotZero = 1;
+ }
*newPtr = *format;
newPtr++;
format++;
@@ -2201,21 +2210,23 @@ Tcl_FormatObjCmd(dummy, interp, objc, objv)
}
case CHAR_VALUE: {
char *ptr;
+ char padChar = (gotZero ? '0' : ' ');
ptr = dst;
if (!gotMinus) {
for ( ; --width > 0; ptr++) {
- *ptr = ' ';
+ *ptr = padChar;
}
}
ptr += Tcl_UniCharToUtf(intValue, ptr);
for ( ; --width > 0; ptr++) {
- *ptr = ' ';
+ *ptr = padChar;
}
*ptr = '\0';
break;
}
case STRING_VALUE: {
char *ptr;
+ char padChar = (gotZero ? '0' : ' ');
int pad;
ptr = dst;
@@ -2227,7 +2238,7 @@ Tcl_FormatObjCmd(dummy, interp, objc, objv)
if (!gotMinus) {
while (pad > 0) {
- *ptr++ = ' ';
+ *ptr++ = padChar;
pad--;
}
}
@@ -2238,7 +2249,7 @@ Tcl_FormatObjCmd(dummy, interp, objc, objv)
ptr += size;
}
while (pad > 0) {
- *ptr++ = ' ';
+ *ptr++ = padChar;
pad--;
}
*ptr = '\0';