- Replace 'while(' with 'while ('.
[openocd.git] / src / helper / jim.c
index f4336ae244b2a15283f2fd716476ad04babf6155..28c651233d2b21eab1bd239b74b278108846b42f 100644 (file)
  * are those of the authors and should not be interpreted as representing
  * official policies, either expressed or implied, of the Jim Tcl Project.
  **/
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
 #define __JIM_CORE__
 #define JIM_OPTIMIZATION /* comment to avoid optimizations and reduce size */
 
 #ifdef __ECOS
 #include <pkgconf/jimtcl.h>
-#endif
-#ifndef JIM_ANSIC
-#define JIM_DYNLIB      /* Dynamic library support for UNIX and WIN32 */
-#endif /* JIM_ANSIC */
-
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <assert.h>
 #include <errno.h>
 #include <time.h>
-#if defined(WIN32)
-/* sys/time - need is different */
-#else
-#include <sys/time.h> // for gettimeofday()
 #endif
+#ifndef JIM_ANSIC
+#define JIM_DYNLIB      /* Dynamic library support for UNIX and WIN32 */
+#endif /* JIM_ANSIC */
 
-#include "replacements.h"
+#include <stdarg.h>
+#include <limits.h>
 
 /* Include the platform dependent libraries for
  * dynamic loading of libraries. */
 #endif /* WIN32 */
 #endif /* JIM_DYNLIB */
 
-#ifndef WIN32
-#include <unistd.h>
-#endif
-
 #ifdef __ECOS
 #include <cyg/jimtcl/jim.h>
 #else
@@ -115,7 +110,7 @@ static void JimChangeCallFrameId(Jim_Interp *interp, Jim_CallFrame *cf);
 static void JimFreeCallFrame(Jim_Interp *interp, Jim_CallFrame *cf, int flags);
 static void JimRegisterCoreApi(Jim_Interp *interp);
 
-static Jim_HashTableType JimVariablesHashTableType;
+static Jim_HashTableType *getJimVariablesHashTableType(void);
 
 /* -----------------------------------------------------------------------------
  * Utility functions
@@ -132,7 +127,9 @@ static char buf[2048];
        buf[sizeof(buf)-1] = 0;
 #else
        char *buf;
-       vasprintf( &buf, fmt, ap );
+       int result;
+       result = vasprintf( &buf, fmt, ap );
+       if (result < 0) exit(-1);
 #endif
        return buf;
 }
@@ -155,7 +152,7 @@ jim_vasprintf_done( void *buf )
  * Ignores `locale' stuff.  Assumes that the upper and lower case
  * alphabets and digits are each contiguous.
  */
-#ifdef HAVE_LONG_LONG
+#ifdef HAVE_LONG_LONG_INT
 #define JimIsAscii(c) (((c) & ~0x7f) == 0)
 static jim_wide JimStrtoll(const char *nptr, char **endptr, register int base)
 {
@@ -248,7 +245,7 @@ static jim_wide JimStrtoll(const char *nptr, char **endptr, register int base)
 static int JimStringMatch(const char *pattern, int patternLen,
         const char *string, int stringLen, int nocase)
 {
-    while(patternLen) {
+    while (patternLen) {
         switch(pattern[0]) {
         case '*':
             while (pattern[1] == '*') {
@@ -257,7 +254,7 @@ static int JimStringMatch(const char *pattern, int patternLen,
             }
             if (patternLen == 1)
                 return 1; /* match */
-            while(stringLen) {
+            while (stringLen) {
                 if (JimStringMatch(pattern+1, patternLen-1,
                             string, stringLen, nocase))
                     return 1; /* match */
@@ -284,7 +281,7 @@ static int JimStringMatch(const char *pattern, int patternLen,
                 patternLen--;
             }
             match = 0;
-            while(1) {
+            while (1) {
                 if (pattern[0] == '\\') {
                     pattern++;
                     patternLen--;
@@ -355,7 +352,7 @@ static int JimStringMatch(const char *pattern, int patternLen,
         pattern++;
         patternLen--;
         if (stringLen == 0) {
-            while(*pattern == '*') {
+            while (*pattern == '*') {
                 pattern++;
                 patternLen--;
             }
@@ -373,7 +370,7 @@ int JimStringCompare(const char *s1, int l1, const char *s2, int l2,
     unsigned char *u1 = (unsigned char*) s1, *u2 = (unsigned char*) s2;
 
     if (nocase == 0) {
-        while(l1 && l2) {
+        while (l1 && l2) {
             if (*u1 != *u2)
                 return (int)*u1-*u2;
             u1++; u2++; l1--; l2--;
@@ -381,7 +378,7 @@ int JimStringCompare(const char *s1, int l1, const char *s2, int l2,
         if (!l1 && !l2) return 0;
         return l1-l2;
     } else {
-        while(l1 && l2) {
+        while (l1 && l2) {
             if (tolower((int)*u1) != tolower((int)*u2))
                 return tolower((int)*u1)-tolower((int)*u2);
             u1++; u2++; l1--; l2--;
@@ -419,7 +416,7 @@ int Jim_StringToWide(const char *str, jim_wide *widePtr, int base)
 {
     char *endptr;
 
-#ifdef HAVE_LONG_LONG
+#ifdef HAVE_LONG_LONG_INT
     *widePtr = JimStrtoll(str, &endptr, base);
 #else
     *widePtr = strtol(str, &endptr, base);
@@ -427,7 +424,7 @@ int Jim_StringToWide(const char *str, jim_wide *widePtr, int base)
     if ((str[0] == '\0') || (str == endptr) )
         return JIM_ERR;
     if (endptr[0] != '\0') {
-        while(*endptr) {
+        while (*endptr) {
             if (!isspace((int)*endptr))
                 return JIM_ERR;
             endptr++;
@@ -444,7 +441,7 @@ int Jim_StringToIndex(const char *str, int *intPtr)
     if ( (str[0] == '\0') || (str == endptr) )
         return JIM_ERR;
     if (endptr[0] != '\0') {
-        while(*endptr) {
+        while (*endptr) {
             if (!isspace((int)*endptr))
                 return JIM_ERR;
             endptr++;
@@ -476,7 +473,7 @@ int Jim_DoubleToString(char *buf, double doubleValue)
 
     len = sprintf(buf, "%.17g", doubleValue);
     s = buf;
-    while(*s) {
+    while (*s) {
         if (*s == '.') return len;
         s++;
     }
@@ -547,7 +544,7 @@ void Jim_Panic(Jim_Interp *interp, const char *fmt, ...)
 #endif
        
        /* This may actually crash... we do it last */
-       if( interp && interp->cookie_stderr ){
+       if ( interp && interp->cookie_stderr ){
                Jim_fprintf(  interp, interp->cookie_stderr, JIM_NL "JIM INTERPRETER PANIC: ");
                Jim_vfprintf( interp, interp->cookie_stderr, fmt, ap );
                Jim_fprintf(  interp, interp->cookie_stderr, JIM_NL JIM_NL );
@@ -664,7 +661,7 @@ unsigned int Jim_IdentityHashFunction(unsigned int key)
 unsigned int Jim_GenHashFunction(const unsigned char *buf, int len)
 {
     unsigned int h = 0;
-    while(len--)
+    while (len--)
         h += (h<<3)+*buf++;
     return h;
 }
@@ -732,7 +729,7 @@ int Jim_ExpandHashTable(Jim_HashTable *ht, unsigned int size)
         
         /* For each hash entry on this slot... */
         he = ht->table[i];
-        while(he) {
+        while (he) {
             unsigned int h;
 
             nextHe = he->next;
@@ -805,7 +802,7 @@ int Jim_DeleteHashEntry(Jim_HashTable *ht, const void *key)
     he = ht->table[h];
 
     prevHe = NULL;
-    while(he) {
+    while (he) {
         if (Jim_CompareHashKeys(ht, key, he->key)) {
             /* Unlink the element from the list */
             if (prevHe)
@@ -834,7 +831,7 @@ int Jim_FreeHashTable(Jim_HashTable *ht)
         Jim_HashEntry *he, *nextHe;
 
         if ((he = ht->table[i]) == NULL) continue;
-        while(he) {
+        while (he) {
             nextHe = he->next;
             Jim_FreeEntryKey(ht, he);
             Jim_FreeEntryVal(ht, he);
@@ -858,7 +855,7 @@ Jim_HashEntry *Jim_FindHashEntry(Jim_HashTable *ht, const void *key)
     if (ht->size == 0) return NULL;
     h = Jim_HashKey(ht, key) & ht->sizemask;
     he = ht->table[h];
-    while(he) {
+    while (he) {
         if (Jim_CompareHashKeys(ht, key, he->key))
             return he;
         he = he->next;
@@ -919,7 +916,7 @@ static unsigned int JimHashTableNextPower(unsigned int size)
 
     if (size >= 2147483648U)
         return 2147483648U;
-    while(1) {
+    while (1) {
         if (i >= size)
             return i;
         i *= 2;
@@ -941,7 +938,7 @@ static int JimInsertHashEntry(Jim_HashTable *ht, const void *key)
     h = Jim_HashKey(ht, key) & ht->sizemask;
     /* Search if this slot does not already contain the given key */
     he = ht->table[h];
-    while(he) {
+    while (he) {
         if (Jim_CompareHashKeys(ht, key, he->key))
             return -1;
         he = he->next;
@@ -1183,7 +1180,7 @@ void JimParserInit(struct JimParserCtx *pc, const char *prg,
 
 int JimParseScript(struct JimParserCtx *pc)
 {
-    while(1) { /* the while is used to reiterate with continue if needed */
+    while (1) { /* the while is used to reiterate with continue if needed */
         if (!pc->len) {
             pc->tstart = pc->p;
             pc->tend = pc->p-1;
@@ -1660,7 +1657,7 @@ int Jim_ScriptIsComplete(const char *s, int len, char *stateCharPtr)
     int level = 0;
     int state = ' ';
 
-    while(len) {
+    while (len) {
         switch (*s) {
             case '\\':
                 if (len > 1)
@@ -2067,7 +2064,7 @@ void Jim_AppendString_sprintf( Jim_Interp *interp, Jim_Obj *objPtr, const char *
        buf = jim_vasprintf( fmt, ap );
        va_end(ap);
 
-       if( buf ){
+       if ( buf ){
                Jim_AppendString( interp, objPtr, buf, -1 );
                jim_vasprintf_done(buf);
        }
@@ -2286,7 +2283,7 @@ static Jim_Obj *Jim_FormatString_Inner(Jim_Interp *interp, Jim_Obj *fmtObjPtr,
                haveprec = 0;
                prec = -1; /* not found yet */
     next_fmt:
-               if( fmtLen <= 0 ){
+               if ( fmtLen <= 0 ){
                        break;
                }
                switch( *fmt ){
@@ -2344,11 +2341,11 @@ static Jim_Obj *Jim_FormatString_Inner(Jim_Interp *interp, Jim_Obj *fmtObjPtr,
                case '8':
                case '9':
                        accum = 0;
-                       while( isdigit(*fmt) && (fmtLen > 0) ){
+                       while ( isdigit(*fmt) && (fmtLen > 0) ){
                                accum = (accum * 10) + (*fmt - '0');
                                fmt++;  fmtLen--;
                        }
-                       if( inprec ){
+                       if ( inprec ){
                                haveprec = 1;
                                prec = accum;
                        } else {
@@ -2359,24 +2356,24 @@ static Jim_Obj *Jim_FormatString_Inner(Jim_Interp *interp, Jim_Obj *fmtObjPtr,
                        /* suck up the next item as an integer */
                        fmt++;  fmtLen--;
                        objc--;
-                       if( objc <= 0 ){
+                       if ( objc <= 0 ){
                                goto not_enough_args;
                        }
-                       if( Jim_GetWide(interp,objv[0],&wideValue )== JIM_ERR ){
+                       if ( Jim_GetWide(interp,objv[0],&wideValue )== JIM_ERR ){
                                Jim_FreeNewObj(interp, resObjPtr );
                                return NULL;
                        }
-                       if( inprec ){
+                       if ( inprec ){
                                haveprec = 1;
                                prec = wideValue;
-                               if( prec < 0 ){
+                               if ( prec < 0 ){
                                        /* man 3 printf says */
                                        /* if prec is negative, it is zero */
                                        prec = 0;
                                }
                        } else {
                        width = wideValue;
-                       if( width < 0 ){
+                       if ( width < 0 ){
                                ljust = 1;
                                width = -width;
                        }
@@ -2405,32 +2402,32 @@ static Jim_Obj *Jim_FormatString_Inner(Jim_Interp *interp, Jim_Obj *fmtObjPtr,
                 */
                cp = fmt_str;
                *cp++ = '%';
-               if( altfm ){
+               if ( altfm ){
                        *cp++ = '#';
                }
-               if( forceplus ){
+               if ( forceplus ){
                        *cp++ = '+';
-               } else if( spad ){
+               } else if ( spad ){
                        /* PLUS overrides */
                        *cp++ = ' ';
                }
-               if( ljust ){
+               if ( ljust ){
                        *cp++ = '-';
                }
-               if( zpad  ){
+               if ( zpad  ){
                        *cp++ = '0';
                }
-               if( width > 0 ){
+               if ( width > 0 ){
                        sprintf( cp, "%d", width );
                        /* skip ahead */
                        cp = strchr(cp,0);
                }
                /* did we find a period? */
-               if( inprec ){
+               if ( inprec ){
                        /* then add it */
                        *cp++ = '.';
                        /* did something occur after the period? */
-                       if( haveprec ){
+                       if ( haveprec ){
                                sprintf( cp, "%d", prec );
                        }
                        cp = strchr(cp,0);
@@ -2464,7 +2461,7 @@ static Jim_Obj *Jim_FormatString_Inner(Jim_Interp *interp, Jim_Obj *fmtObjPtr,
                case 'E':
                        *cp++ = *fmt;
                        *cp   = 0;
-                       if( Jim_GetDouble( interp, objv[0], &doubleValue ) == JIM_ERR ){
+                       if ( Jim_GetDouble( interp, objv[0], &doubleValue ) == JIM_ERR ){
                                Jim_FreeNewObj( interp, resObjPtr );
                                return NULL;
                        }
@@ -2478,7 +2475,7 @@ static Jim_Obj *Jim_FormatString_Inner(Jim_Interp *interp, Jim_Obj *fmtObjPtr,
                case 'x':
                case 'X':
                        /* jim widevaluse are 64bit */
-                       if( sizeof(jim_wide) == sizeof(long long) ){
+                       if ( sizeof(jim_wide) == sizeof(long long) ){
                                *cp++ = 'l'; 
                                *cp++ = 'l';
                        } else {
@@ -2630,12 +2627,12 @@ int Jim_GetNvp(Jim_Interp *interp,
        int e;
 
        e = Jim_Nvp_name2value_obj( interp, nvp_table, objPtr, &n );
-       if( e == JIM_ERR ){
+       if ( e == JIM_ERR ){
                return e;
        }
 
        /* Success? found? */
-       if( n->name ){
+       if ( n->name ){
                /* remove const */
                *result = (Jim_Nvp *)n;
                return JIM_OK;
@@ -3032,7 +3029,7 @@ int SetScriptFromAny(Jim_Interp *interp, struct Jim_Obj *objPtr)
     }
 
     JimParserInit(&parser, scriptText, scriptTextLen, initialLineNumber);
-    while(!JimParserEof(&parser)) {
+    while (!JimParserEof(&parser)) {
         char *token;
         int len, type, linenr;
 
@@ -3232,7 +3229,7 @@ int Jim_CreateProcedure(Jim_Interp *interp, const char *cmdName,
         Jim_ListLength(interp, staticsListObjPtr, &len);
         if (len != 0) {
             cmdPtr->staticVars = Jim_Alloc(sizeof(Jim_HashTable));
-            Jim_InitHashTable(cmdPtr->staticVars, &JimVariablesHashTableType,
+            Jim_InitHashTable(cmdPtr->staticVars, getJimVariablesHashTableType(),
                     interp);
             for (i = 0; i < len; i++) {
                 Jim_Obj *objPtr, *initObjPtr, *nameObjPtr;
@@ -3435,6 +3432,11 @@ static Jim_HashTableType JimVariablesHashTableType = {
     JimVariablesHTValDestructor       /* val destructor */
 };
 
+static Jim_HashTableType *getJimVariablesHashTableType(void)
+{
+       return &JimVariablesHashTableType;
+}
+
 /* -----------------------------------------------------------------------------
  * Variable object
  * ---------------------------------------------------------------------------*/
@@ -3619,7 +3621,7 @@ int Jim_SetVariableLink(Jim_Interp *interp, Jim_Obj *nameObjPtr,
         Jim_Obj *objPtr = targetNameObjPtr;
         Jim_Var *varPtr;
         /* Cycles are only possible with 'uplevel 0' */
-        while(1) {
+        while (1) {
             if (Jim_StringEqObj(objPtr, nameObjPtr, 0)) {
                 Jim_SetResultString(interp,
                     "can't upvar from variable to itself", -1);
@@ -4260,7 +4262,7 @@ int Jim_Collect(Jim_Interp *interp)
      * is of a type that can contain references. */
     Jim_InitHashTable(&marks, &JimRefMarkHashTableType, NULL);
     objPtr = interp->liveList;
-    while(objPtr) {
+    while (objPtr) {
         if (objPtr->typePtr == NULL ||
             objPtr->typePtr->flags & JIM_TYPE_REFERENCES) {
             const char *str, *p;
@@ -4289,7 +4291,7 @@ int Jim_Collect(Jim_Interp *interp)
                 continue;
             }
             /* Extract references from the object string repr. */
-            while(1) {
+            while (1) {
                 int i;
                 jim_wide id;
                 char buf[21];
@@ -4486,7 +4488,7 @@ void Jim_FreeInterp(Jim_Interp *i)
     Jim_FreeHashTable(&i->packages);
     Jim_Free(i->prngState);
     /* Free the call frames list */
-    while(cf) {
+    while (cf) {
         prevcf = cf->parentCallFrame;
         JimFreeCallFrame(i, cf, JIM_FCF_NONE);
         cf = prevcf;
@@ -4498,7 +4500,7 @@ void Jim_FreeInterp(Jim_Interp *i)
     
         Jim_fprintf( i, i->cookie_stdout,JIM_NL "-------------------------------------" JIM_NL);
         Jim_fprintf( i, i->cookie_stdout,"Objects still in the free list:" JIM_NL);
-        while(objPtr) {
+        while (objPtr) {
             const char *type = objPtr->typePtr ?
                 objPtr->typePtr->name : "";
             Jim_fprintf( i, i->cookie_stdout,"%p \"%-10s\": '%.20s' (refCount: %d)" JIM_NL,
@@ -4524,7 +4526,7 @@ void Jim_FreeInterp(Jim_Interp *i)
     }
     /* Free cached CallFrame structures */
     cf = i->freeFramesList;
-    while(cf) {
+    while (cf) {
         nextcf = cf->nextFramePtr;
         if (cf->vars.table != NULL)
             Jim_Free(cf->vars.table);
@@ -5100,7 +5102,7 @@ char *BackslashQuoteString(const char *s, int len, int *qlenPtr)
     char *q = Jim_Alloc(len*2+1), *p;
 
     p = q;
-    while(*s) {
+    while (*s) {
         switch (*s) {
         case ' ':
         case '$':
@@ -5213,7 +5215,7 @@ int SetListFromAny(Jim_Interp *interp, struct Jim_Obj *objPtr)
 
     /* Convert into a list */
     JimParserInit(&parser, str, strLen, 1);
-    while(!JimParserEof(&parser)) {
+    while (!JimParserEof(&parser)) {
         char *token;
         int tokenLen, type;
         Jim_Obj *elementPtr;
@@ -5792,7 +5794,7 @@ int SetDictFromAny(Jim_Interp *interp, struct Jim_Obj *objPtr)
     /* Convert into a dict */
     JimParserInit(&parser, str, strLen, 1);
     i = 0;
-    while(!JimParserEof(&parser)) {
+    while (!JimParserEof(&parser)) {
         char *token;
         int tokenLen, type;
 
@@ -5917,7 +5919,7 @@ int Jim_DictKey(Jim_Interp *interp, Jim_Obj *dictPtr, Jim_Obj *keyPtr,
 int Jim_DictKeysVector(Jim_Interp *interp, Jim_Obj *dictPtr,
         Jim_Obj *const *keyv, int keyc, Jim_Obj **objPtrPtr, int flags)
 {
-    Jim_Obj *objPtr;
+    Jim_Obj *objPtr = NULL;
     int i;
 
     if (keyc == 0) {
@@ -6274,7 +6276,7 @@ static struct Jim_ExprOperator Jim_ExprOperators[] = {
 int JimParseExpression(struct JimParserCtx *pc)
 {
     /* Discard spaces and quoted newline */
-    while(*(pc->p) == ' ' ||
+    while (*(pc->p) == ' ' ||
           *(pc->p) == '\t' ||
           *(pc->p) == '\r' ||
           *(pc->p) == '\n' ||
@@ -6621,7 +6623,7 @@ static void ExprMakeLazy(Jim_Interp *interp, ExprByteCode *expr)
         /* Search for the end of the first operator */
         leftindex = index-1;
         arity = 1;
-        while(arity) {
+        while (arity) {
             switch(expr->opcode[leftindex]) {
             case JIM_EXPROP_NUMBER:
             case JIM_EXPROP_COMMAND:
@@ -6695,7 +6697,7 @@ int SetExprFromAny(Jim_Interp *interp, struct Jim_Obj *objPtr)
 
     Jim_InitStack(&stack);
     JimParserInit(&parser, exprText, exprTextLen, 1);
-    while(!JimParserEof(&parser)) {
+    while (!JimParserEof(&parser)) {
         char *token;
         int len, type;
 
@@ -6729,7 +6731,7 @@ int SetExprFromAny(Jim_Interp *interp, struct Jim_Obj *objPtr)
             break;
         case JIM_TT_EXPR_OPERATOR:
             op = JimExprOperatorInfo(token);
-            while(1) {
+            while (1) {
                 Jim_ExprOperator *stackTopOp;
 
                 if (Jim_StackPeek(&stack) != NULL) {
@@ -6756,7 +6758,7 @@ int SetExprFromAny(Jim_Interp *interp, struct Jim_Obj *objPtr)
         case JIM_TT_SUBEXPR_END:
             {
                 int found = 0;
-                while(Jim_StackLen(&stack)) {
+                while (Jim_StackLen(&stack)) {
                     char *opstr = Jim_StackPop(&stack);
                     if (!strcmp(opstr, "(")) {
                         Jim_Free(opstr);
@@ -7640,6 +7642,8 @@ static int ScanOneEntry(Jim_Interp *interp, const char *str, long pos,
                 scanned += 1;
                 break;
             case 'd': case 'o': case 'x': case 'u': case 'i': {
+                jim_wide jwvalue = 0;
+                long lvalue = 0;
                 char *endp;  /* Position where the number finished */
                 int base = descr->type == 'o' ? 8
                     : descr->type == 'x' ? 16
@@ -7649,16 +7653,22 @@ static int ScanOneEntry(Jim_Interp *interp, const char *str, long pos,
                 do {
                     /* Try to scan a number with the given base */
                     if (descr->modifier == 'l')
-#ifdef HAVE_LONG_LONG
-                      *(jim_wide*)value = JimStrtoll(tok, &endp, base);
+                    {
+#ifdef HAVE_LONG_LONG_INT
+                        jwvalue = JimStrtoll(tok, &endp, base),
 #else
-                      *(jim_wide*)value = strtol(tok, &endp, base);
+                        jwvalue = strtol(tok, &endp, base),
 #endif
+                        memcpy(value, &jwvalue, sizeof(jim_wide));
+                    }
                     else
+                    {
                       if (descr->type == 'u')
-                        *(long*)value = strtoul(tok, &endp, base);
+                        lvalue = strtoul(tok, &endp, base);
                       else
-                        *(long*)value = strtol(tok, &endp, base);
+                        lvalue = strtol(tok, &endp, base);
+                      memcpy(value, &lvalue, sizeof(lvalue));
+                    }
                     /* If scanning failed, and base was undetermined, simply
                      * put it to 10 and try once more. This should catch the
                      * case where %i begin to parse a number prefix (e.g. 
@@ -7670,9 +7680,9 @@ static int ScanOneEntry(Jim_Interp *interp, const char *str, long pos,
                 if (endp != tok) {
                     /* There was some number sucessfully scanned! */
                     if (descr->modifier == 'l')
-                        *valObjPtr = Jim_NewIntObj(interp, *(jim_wide*)value);
+                        *valObjPtr = Jim_NewIntObj(interp, jwvalue);
                     else
-                        *valObjPtr = Jim_NewIntObj(interp, *(long*)value);
+                        *valObjPtr = Jim_NewIntObj(interp, lvalue);
                     /* Adjust the number-of-chars scanned so far */
                     scanned += endp - tok;
                 } else {
@@ -7691,10 +7701,11 @@ static int ScanOneEntry(Jim_Interp *interp, const char *str, long pos,
             case 'e': case 'f': case 'g': {
                 char *endp;
 
-                *(double*)value = strtod(tok, &endp);
+                double dvalue = strtod(tok, &endp);
+                memcpy(value, &dvalue, sizeof(double));
                 if (endp != tok) {
                     /* There was some number sucessfully scanned! */
-                    *valObjPtr = Jim_NewDoubleObj(interp, *(double*)value);
+                    *valObjPtr = Jim_NewDoubleObj(interp, dvalue);
                     /* Adjust the number-of-chars scanned so far */
                     scanned += endp - tok;
                 } else {
@@ -8093,17 +8104,17 @@ DIR *opendir(const char *name)
 {
     DIR *dir = 0;
 
-    if(name && name[0]) {
+    if (name && name[0]) {
         size_t base_length = strlen(name);
         const char *all = /* search pattern must end with suitable wildcard */
             strchr("/\\", name[base_length - 1]) ? "*" : "/*";
 
-        if((dir = (DIR *) Jim_Alloc(sizeof *dir)) != 0 &&
+        if ((dir = (DIR *) Jim_Alloc(sizeof *dir)) != 0 &&
            (dir->name = (char *) Jim_Alloc(base_length + strlen(all) + 1)) != 0)
         {
             strcat(strcpy(dir->name, name), all);
 
-            if((dir->handle = (long) _findfirst(dir->name, &dir->info)) != -1)
+            if ((dir->handle = (long) _findfirst(dir->name, &dir->info)) != -1)
                 dir->result.d_name = 0;
             else { /* rollback */
                 Jim_Free(dir->name);
@@ -8125,13 +8136,13 @@ int closedir(DIR *dir)
 {
     int result = -1;
 
-    if(dir) {
-        if(dir->handle != -1)
+    if (dir) {
+        if (dir->handle != -1)
             result = _findclose(dir->handle);
         Jim_Free(dir->name);
         Jim_Free(dir);
     }
-    if(result == -1) /* map all errors to EBADF */
+    if (result == -1) /* map all errors to EBADF */
         errno = EBADF;
     return result;
 }
@@ -8140,8 +8151,8 @@ struct dirent *readdir(DIR *dir)
 {
     struct dirent *result = 0;
 
-    if(dir && dir->handle != -1) {
-        if(!dir->result.d_name || _findnext(dir->handle, &dir->info) != -1) {
+    if (dir && dir->handle != -1) {
+        if (!dir->result.d_name || _findnext(dir->handle, &dir->info) != -1) {
             result         = &dir->result;
             result->d_name = dir->info.name;
         }
@@ -8883,7 +8894,7 @@ int Jim_Eval_Named(Jim_Interp *interp, const char *script, const char *filename,
     Jim_IncrRefCount(scriptObjPtr);
 
 
-       if( filename ){
+       if ( filename ){
                JimSetSourceInfo( interp, scriptObjPtr, filename, lineno );
        }
 
@@ -8952,7 +8963,7 @@ int Jim_EvalFile(Jim_Interp *interp, const char *filename)
        const int cwd_len=2048;
                char *cwd=malloc(cwd_len);
         Jim_SetResult(interp, Jim_NewEmptyStringObj(interp));
-       getcwd( cwd, cwd_len );
+       if (!getcwd( cwd, cwd_len )) strcpy(cwd, "unknown");
         Jim_AppendStrings(interp, Jim_GetResult(interp),
        "Error loading script \"", filename, "\"",
            " cwd: ", cwd,
@@ -9083,7 +9094,7 @@ int SetSubstFromAny(Jim_Interp *interp, struct Jim_Obj *objPtr, int flags)
     script->fileName = NULL;
 
     JimParserInit(&parser, scriptText, scriptTextLen, 1);
-    while(1) {
+    while (1) {
         char *token;
         int len, type, linenr;
 
@@ -11127,7 +11138,7 @@ static Jim_Obj *JimStringMap(Jim_Interp *interp, Jim_Obj *mapListObjPtr,
     }
     str = Jim_GetString(objPtr, &strLen);
     /* Map it */
-    while(strLen) {
+    while (strLen) {
         for (i = 0; i < numMaps; i++) {
             if (strLen >= keyLen[i] && keyLen[i]) {
                 if (!JimStringCompare(str, keyLen[i], key[i], keyLen[i],
@@ -11619,7 +11630,7 @@ static int Jim_SubstCoreCommand(Jim_Interp *interp, int argc,
         return JIM_ERR;
     }
     i = argc-2;
-    while(i--) {
+    while (i--) {
         if (Jim_CompareStringImmediate(interp, argv[i+1],
                     "-nobackslashes"))
             flags |= JIM_SUBST_NOESC;
@@ -11973,7 +11984,10 @@ static int Jim_EnvCoreCommand(Jim_Interp *interp, int argc,
     char *val;
 
     if (argc == 1) {
+
+#ifdef NEED_ENVIRON_EXTERN
         extern char **environ;
+#endif
 
         int i;
         Jim_Obj *listObjPtr = Jim_NewListObj(interp, NULL, 0);
@@ -12269,7 +12283,7 @@ void Jim_RegisterCoreCommands(Jim_Interp *interp)
 {
     int i = 0;
 
-    while(Jim_CoreCommandsTable[i].name != NULL) {
+    while (Jim_CoreCommandsTable[i].name != NULL) {
         Jim_CreateCommand(interp, 
                 Jim_CoreCommandsTable[i].name,
                 Jim_CoreCommandsTable[i].cmdProc,
@@ -12347,7 +12361,7 @@ int Jim_InteractivePrompt(Jim_Interp *interp)
         Jim_fflush( interp, interp->cookie_stdout);
         scriptObjPtr = Jim_NewStringObj(interp, "", 0);
         Jim_IncrRefCount(scriptObjPtr);
-        while(1) {
+        while (1) {
             const char *str;
             char state;
             int len;
@@ -12398,7 +12412,7 @@ int Jim_fprintf( Jim_Interp *interp, void *cookie, const char *fmt, ... )
 
 int Jim_vfprintf( Jim_Interp *interp, void *cookie, const char *fmt, va_list ap )
 {
-       if( (interp == NULL) || (interp->cb_vfprintf == NULL) ){
+       if ( (interp == NULL) || (interp->cb_vfprintf == NULL) ){
                errno = ENOTSUP;
                return -1;
        }
@@ -12407,7 +12421,7 @@ int Jim_vfprintf( Jim_Interp *interp, void *cookie, const char *fmt, va_list ap
 
 size_t Jim_fwrite( Jim_Interp *interp, const void *ptr, size_t size, size_t n, void *cookie )
 {
-       if( (interp == NULL) || (interp->cb_fwrite == NULL) ){
+       if ( (interp == NULL) || (interp->cb_fwrite == NULL) ){
                errno = ENOTSUP;
                return 0;
        }
@@ -12416,7 +12430,7 @@ size_t Jim_fwrite( Jim_Interp *interp, const void *ptr, size_t size, size_t n, v
 
 size_t Jim_fread( Jim_Interp *interp, void *ptr, size_t size, size_t n, void *cookie )
 {
-       if( (interp == NULL) || (interp->cb_fread == NULL) ){
+       if ( (interp == NULL) || (interp->cb_fread == NULL) ){
                errno = ENOTSUP;
                return 0;
        }
@@ -12425,7 +12439,7 @@ size_t Jim_fread( Jim_Interp *interp, void *ptr, size_t size, size_t n, void *co
 
 int Jim_fflush( Jim_Interp *interp, void *cookie )
 {
-       if( (interp == NULL) || (interp->cb_fflush == NULL) ){
+       if ( (interp == NULL) || (interp->cb_fflush == NULL) ){
                /* pretend all is well */
                return 0;
        }
@@ -12434,7 +12448,7 @@ int Jim_fflush( Jim_Interp *interp, void *cookie )
 
 char* Jim_fgets( Jim_Interp *interp, char *s, int size, void *cookie )
 {
-       if( (interp == NULL) || (interp->cb_fgets == NULL) ){
+       if ( (interp == NULL) || (interp->cb_fgets == NULL) ){
                errno = ENOTSUP;
                return NULL;
        }
@@ -12443,8 +12457,8 @@ char* Jim_fgets( Jim_Interp *interp, char *s, int size, void *cookie )
 Jim_Nvp *
 Jim_Nvp_name2value_simple( const Jim_Nvp *p, const char *name )
 {
-       while( p->name ){
-               if( 0 == strcmp( name, p->name ) ){
+       while ( p->name ){
+               if ( 0 == strcmp( name, p->name ) ){
                        break;
                }
                p++;
@@ -12455,8 +12469,8 @@ Jim_Nvp_name2value_simple( const Jim_Nvp *p, const char *name )
 Jim_Nvp *
 Jim_Nvp_name2value_nocase_simple( const Jim_Nvp *p, const char *name )
 {
-       while( p->name ){
-               if( 0 == strcasecmp( name, p->name ) ){
+       while ( p->name ){
+               if ( 0 == strcasecmp( name, p->name ) ){
                        break;
                }
                p++;
@@ -12485,12 +12499,12 @@ Jim_Nvp_name2value( Jim_Interp *interp,
        p = Jim_Nvp_name2value_simple( _p, name );
 
        /* result */
-       if( result ){
+       if ( result ){
                *result = (Jim_Nvp *)(p);
        }
        
        /* found? */
-       if( p->name ){
+       if ( p->name ){
                return JIM_OK;
        } else {
                return JIM_ERR;
@@ -12510,11 +12524,11 @@ Jim_Nvp_name2value_nocase( Jim_Interp *interp, const Jim_Nvp *_p, const char *na
 
        p = Jim_Nvp_name2value_nocase_simple( _p, name );
 
-       if( puthere ){
+       if ( puthere ){
                *puthere = (Jim_Nvp *)(p);
        }
        /* found */
-       if( p->name ){
+       if ( p->name ){
                return JIM_OK;
        } else {
                return JIM_ERR;
@@ -12529,7 +12543,7 @@ Jim_Nvp_value2name_obj( Jim_Interp *interp, const Jim_Nvp *p, Jim_Obj *o, Jim_Nv
        jim_wide w;
 
        e = Jim_GetWide( interp, o, &w );
-       if( e != JIM_OK ){
+       if ( e != JIM_OK ){
                return e;
        }
 
@@ -12539,8 +12553,8 @@ Jim_Nvp_value2name_obj( Jim_Interp *interp, const Jim_Nvp *p, Jim_Obj *o, Jim_Nv
 Jim_Nvp *
 Jim_Nvp_value2name_simple( const Jim_Nvp *p, int value )
 {
-       while( p->name ){
-               if( value == p->value ){
+       while ( p->name ){
+               if ( value == p->value ){
                        break;
                }
                p++;
@@ -12556,11 +12570,11 @@ Jim_Nvp_value2name( Jim_Interp *interp, const Jim_Nvp *_p, int value, Jim_Nvp **
 
        p = Jim_Nvp_value2name_simple( _p, value );
 
-       if( result ){
+       if ( result ){
                *result = (Jim_Nvp *)(p);
        }
 
-       if( p->name ){
+       if ( p->name ){
                return JIM_OK;
        } else {
                return JIM_ERR;
@@ -12601,16 +12615,16 @@ Jim_GetOpt_Obj( Jim_GetOptInfo *goi, Jim_Obj **puthere )
        Jim_Obj *o;
        
        o = NULL; // failure 
-       if( goi->argc ){
+       if ( goi->argc ){
                // success 
                o = goi->argv[0];
                goi->argc -= 1;
                goi->argv += 1;
        }
-       if( puthere ){
+       if ( puthere ){
                *puthere = o;
        }
-       if( o != NULL ){
+       if ( o != NULL ){
                return JIM_OK;
        } else {
                return JIM_ERR;
@@ -12626,9 +12640,9 @@ Jim_GetOpt_String( Jim_GetOptInfo *goi, char **puthere, int *len )
 
 
        r = Jim_GetOpt_Obj( goi, &o );
-       if( r == JIM_OK ){
+       if ( r == JIM_OK ){
                cp = Jim_GetString( o, len );
-               if( puthere ){
+               if ( puthere ){
                        /* remove const */
                        *puthere = (char *)(cp);
                }
@@ -12643,14 +12657,14 @@ Jim_GetOpt_Double( Jim_GetOptInfo *goi, double *puthere )
        Jim_Obj *o;
        double _safe;
        
-       if( puthere == NULL ){
+       if ( puthere == NULL ){
                puthere = &_safe;
        }
 
        r = Jim_GetOpt_Obj( goi, &o );
-       if( r == JIM_OK ){
+       if ( r == JIM_OK ){
                r = Jim_GetDouble( goi->interp, o, puthere );
-               if( r != JIM_OK ){
+               if ( r != JIM_OK ){
                        Jim_SetResult_sprintf( goi->interp,
                                                                   "not a number: %s", 
                                                                   Jim_GetString( o, NULL ) );
@@ -12666,12 +12680,12 @@ Jim_GetOpt_Wide( Jim_GetOptInfo *goi, jim_wide *puthere )
        Jim_Obj *o;
        jim_wide _safe;
 
-       if( puthere == NULL ){
+       if ( puthere == NULL ){
                puthere = &_safe;
        }
 
        r = Jim_GetOpt_Obj( goi, &o );
-       if( r == JIM_OK ){
+       if ( r == JIM_OK ){
                r = Jim_GetWide( goi->interp, o, puthere );
        }
        return r;
@@ -12685,12 +12699,12 @@ int Jim_GetOpt_Nvp( Jim_GetOptInfo *goi,
        Jim_Obj *o;
        int e;
 
-       if( puthere == NULL ){
+       if ( puthere == NULL ){
                puthere = &_safe;
        }
 
        e = Jim_GetOpt_Obj( goi, &o );
-       if( e == JIM_OK ){
+       if ( e == JIM_OK ){
                e = Jim_Nvp_name2value_obj( goi->interp,
                                                                        nvp, 
                                                                        o,
@@ -12705,7 +12719,7 @@ Jim_GetOpt_NvpUnknown( Jim_GetOptInfo *goi,
                                           const Jim_Nvp *nvptable,
                                           int hadprefix )
 {
-       if( hadprefix ){
+       if ( hadprefix ){
                Jim_SetResult_NvpUnknown( goi->interp,
                                                                  goi->argv[-2],
                                                                  goi->argv[-1],
@@ -12728,11 +12742,11 @@ Jim_GetOpt_Enum( Jim_GetOptInfo *goi,
        Jim_Obj *o;
        int e;
 
-       if( puthere == NULL ){
+       if ( puthere == NULL ){
                puthere = &_safe;
        }
        e = Jim_GetOpt_Obj( goi, &o );
-       if( e == JIM_OK ){
+       if ( e == JIM_OK ){
                e = Jim_GetEnum( goi->interp,
                                                 o,
                                                 lookup,
@@ -12754,7 +12768,7 @@ Jim_SetResult_sprintf( Jim_Interp *interp, const char *fmt,... )
        va_start(ap,fmt);
        buf = jim_vasprintf( fmt, ap );
        va_end(ap);
-       if( buf ){
+       if ( buf ){
                Jim_SetResultString( interp, buf, -1 );
                jim_vasprintf_done(buf);
        }
@@ -12768,7 +12782,7 @@ Jim_SetResult_NvpUnknown( Jim_Interp *interp,
                                                  Jim_Obj *param_value,
                                                  const Jim_Nvp *nvp )
 {
-       if( param_name ){
+       if ( param_name ){
                Jim_SetResult_sprintf( interp,
                                                           "%s: Unknown: %s, try one of: ",
                                                           Jim_GetString( param_name, NULL ),
@@ -12778,11 +12792,11 @@ Jim_SetResult_NvpUnknown( Jim_Interp *interp,
                                                           "Unknown param: %s, try one of: ",
                                                           Jim_GetString( param_value, NULL ) );
        }
-       while( nvp->name ){
+       while ( nvp->name ){
                const char *a;
                const char *b;
 
-               if( (nvp+1)->name ){
+               if ( (nvp+1)->name ){
                        a = nvp->name;
                        b = ", ";
                } else {
@@ -12804,7 +12818,7 @@ Jim_Debug_ArgvString( Jim_Interp *interp, int argc, Jim_Obj *const *argv )
 {
        int x;
 
-       if( debug_string_obj ){
+       if ( debug_string_obj ){
                Jim_FreeObj( interp, debug_string_obj );
        }
 
@@ -12819,12 +12833,3 @@ Jim_Debug_ArgvString( Jim_Interp *interp, int argc, Jim_Obj *const *argv )
 
        return Jim_GetString( debug_string_obj, NULL );
 }
-
-       
-
-/*
- * Local Variables: ***
- * c-basic-offset: 4 ***
- * tab-width: 4 ***
- * End: ***
- */

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)