testing/*.tcl sample & test code
[openocd.git] / src / jim.c
index e9eb588223568dbb61bb7422ac458cc0315b9e67..be53233c16524a10ec9af069e4fc3027d8fbcbcb 100644 (file)
--- a/src/jim.c
+++ b/src/jim.c
@@ -2180,6 +2180,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--;
@@ -2194,6 +2198,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;
@@ -2237,7 +2244,12 @@ Jim_Obj *Jim_FormatString(Jim_Interp *interp, Jim_Obj *fmtObjPtr,
                        altfm = 1;
                        *fmt++; fmtLen--;
                        goto next_fmt;
-                       
+
+               case '.':
+                       inprec = 1;
+                       *fmt++; fmtLen--;
+                       goto next_fmt;
+                       break;
                case '1':
                case '2':
                case '3':
@@ -2247,11 +2259,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 */
@@ -2264,10 +2282,20 @@ Jim_Obj *Jim_FormatString(Jim_Interp *interp, Jim_Obj *fmtObjPtr,
                                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;
@@ -2313,6 +2341,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 */
@@ -8207,10 +8245,10 @@ int Jim_EvalObjVector(Jim_Interp *interp, int objc, Jim_Obj *const *objv)
             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 */
@@ -8502,6 +8540,11 @@ int Jim_EvalObj(Jim_Interp *interp, Jim_Obj *scriptObjPtr)
         } 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. */
@@ -9995,7 +10038,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")) {

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)