int spad;
int altfm;
int forceplus;
+ int prec;
+ int inprec;
+ int haveprec;
+ int accum;
while (*fmt != '%' && fmtLen) {
fmt++; fmtLen--;
ljust = 0;
altfm = 0;
forceplus = 0;
+ inprec = 0;
+ haveprec = 0;
+ prec = -1; /* not found yet */
next_fmt:
if( fmtLen <= 0 ){
break;
altfm = 1;
*fmt++; fmtLen--;
goto next_fmt;
-
+
+ case '.':
+ inprec = 1;
+ *fmt++; fmtLen--;
+ goto next_fmt;
+ break;
case '1':
case '2':
case '3':
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 */
Jim_FreeNewObj(interp, resObjPtr );
return NULL;
}
- width = wideValue;
- if( width < 0 ){
- ljust = 1;
- width = -width;
+ 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;
/* 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 */
retcode = cmdPtr->cmdProc(interp, objc, objv);
} else {
retcode = JimCallProcedure(interp, cmdPtr, objc, objv);
- if (retcode == JIM_ERR) {
- JimAppendStackTrace(interp,
- Jim_GetString(objv[0], NULL), "?", 1);
- }
+ if (retcode == JIM_ERR) {
+ JimAppendStackTrace(interp,
+ Jim_GetString(objv[0], NULL), "?", 1);
+ }
}
}
/* Decr refcount of arguments and return the retcode */
} else {
/* Call [unknown] */
retcode = JimUnknown(interp, argc, argv);
+ if (retcode == JIM_ERR) {
+ JimAppendStackTrace(interp,
+ Jim_GetString(argv[0], NULL), script->fileName,
+ token[i-argc*2].linenr);
+ }
}
if (retcode != JIM_OK) {
i -= argc*2; /* point to the command name. */
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")) {