diff options
author | oharboe <oharboe> | 2008-07-08 12:04:25 +0000 |
---|---|---|
committer | oharboe <oharboe> | 2008-07-08 12:04:25 +0000 |
commit | a305962f04110d6ff252bf6ff531eeba342138ba (patch) | |
tree | 3d33576d1a6143cff181416edc200113f7582283 /ecos | |
parent | dfb095e05ea89d2be7db296ea25c73fb9ac5ba1c (diff) | |
download | jimtcl-a305962f04110d6ff252bf6ff531eeba342138ba.zip jimtcl-a305962f04110d6ff252bf6ff531eeba342138ba.tar.gz jimtcl-a305962f04110d6ff252bf6ff531eeba342138ba.tar.bz2 |
* src/jim.c: remove bogus return value from if {[expr]} {xx} when
{xx} is not run.
Diffstat (limited to 'ecos')
-rw-r--r-- | ecos/language/tcl/jim/current/src/jim.c | 47 |
1 files changed, 44 insertions, 3 deletions
diff --git a/ecos/language/tcl/jim/current/src/jim.c b/ecos/language/tcl/jim/current/src/jim.c index fdbdf18..4ec8dc9 100644 --- a/ecos/language/tcl/jim/current/src/jim.c +++ b/ecos/language/tcl/jim/current/src/jim.c @@ -2178,6 +2178,10 @@ Jim_Obj *Jim_FormatString(Jim_Interp *interp, Jim_Obj *fmtObjPtr, int spad;
int altfm;
int forceplus;
+ int prec;
+ int inprec;
+ int haveprec;
+ int accum;
while (*fmt != '%' && fmtLen) {
fmt++; fmtLen--;
@@ -2192,6 +2196,9 @@ Jim_Obj *Jim_FormatString(Jim_Interp *interp, Jim_Obj *fmtObjPtr, ljust = 0;
altfm = 0;
forceplus = 0;
+ inprec = 0;
+ haveprec = 0;
+ prec = -1; /* not found yet */
next_fmt:
if( fmtLen <= 0 ){
break;
@@ -2236,6 +2243,11 @@ Jim_Obj *Jim_FormatString(Jim_Interp *interp, Jim_Obj *fmtObjPtr, *fmt++; fmtLen--;
goto next_fmt;
+ case '.':
+ inprec = 1;
+ *fmt++; fmtLen--;
+ goto next_fmt;
+ break;
case '1':
case '2':
case '3':
@@ -2245,11 +2257,17 @@ Jim_Obj *Jim_FormatString(Jim_Interp *interp, Jim_Obj *fmtObjPtr, case '7':
case '8':
case '9':
- width = 0;
+ accum = 0;
while( isdigit(*fmt) && (fmtLen > 0) ){
- width = (width * 10) + (*fmt - '0');
+ accum = (accum * 10) + (*fmt - '0');
fmt++; fmtLen--;
}
+ if( inprec ){
+ haveprec = 1;
+ prec = accum;
+ } else {
+ width = accum;
+ }
goto next_fmt;
case '*':
/* suck up the next item as an integer */
@@ -2262,11 +2280,21 @@ Jim_Obj *Jim_FormatString(Jim_Interp *interp, Jim_Obj *fmtObjPtr, Jim_FreeNewObj(interp, resObjPtr );
return NULL;
}
+ if( inprec ){
+ haveprec = 1;
+ prec = wideValue;
+ if( prec < 0 ){
+ /* man 3 printf says */
+ /* if prec is negative, it is zero */
+ prec = 0;
+ }
+ } else {
width = wideValue;
if( width < 0 ){
ljust = 1;
width = -width;
}
+ }
objv++;
goto next_fmt;
break;
@@ -2311,6 +2339,16 @@ Jim_Obj *Jim_FormatString(Jim_Interp *interp, Jim_Obj *fmtObjPtr, /* skip ahead */
cp = strchr(cp,0);
}
+ /* did we find a period? */
+ if( inprec ){
+ /* then add it */
+ *cp++ = '.';
+ /* did something occur after the period? */
+ if( haveprec ){
+ sprintf( cp, "%d", prec );
+ }
+ cp = strchr(cp,0);
+ }
*cp = 0;
/* here we do the work */
@@ -9993,7 +10031,10 @@ static int Jim_IfCoreCommand(Jim_Interp *interp, int argc, if (boolean)
return Jim_EvalObj(interp, argv[current]);
/* Ok: no else-clause follows */
- if (++current >= argc) return JIM_OK;
+ if (++current >= argc) {
+ Jim_SetResult(interp, Jim_NewEmptyStringObj(interp));
+ return JIM_OK;
+ }
falsebody = current++;
if (Jim_CompareStringImmediate(interp, argv[falsebody],
"else")) {
|