* 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
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
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;
}
* 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)
{
static int JimStringMatch(const char *pattern, int patternLen,
const char *string, int stringLen, int nocase)
{
- while(patternLen) {
- switch(pattern[0]) {
+ while (patternLen) {
+ switch (pattern[0]) {
case '*':
while (pattern[1] == '*') {
pattern++;
}
if (patternLen == 1)
return 1; /* match */
- while(stringLen) {
+ while (stringLen) {
if (JimStringMatch(pattern+1, patternLen-1,
string, stringLen, nocase))
return 1; /* match */
patternLen--;
}
match = 0;
- while(1) {
+ while (1) {
if (pattern[0] == '\\') {
pattern++;
patternLen--;
pattern++;
patternLen--;
if (stringLen == 0) {
- while(*pattern == '*') {
+ while (*pattern == '*') {
pattern++;
patternLen--;
}
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--;
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--;
{
char *endptr;
-#ifdef HAVE_LONG_LONG
+#ifdef HAVE_LONG_LONG_INT
*widePtr = JimStrtoll(str, &endptr, base);
#else
*widePtr = strtol(str, &endptr, 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++;
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++;
len = sprintf(buf, "%.17g", doubleValue);
s = buf;
- while(*s) {
+ while (*s) {
if (*s == '.') return len;
s++;
}
static jim_wide JimPowWide(jim_wide b, jim_wide e)
{
jim_wide i, res = 1;
- if ((b==0 && e!=0) || (e<0)) return 0;
- for(i=0; i<e; i++) {res *= b;}
+ if ((b==0 && e != 0) || (e<0)) return 0;
+ for (i=0; i<e; i++) {res *= b;}
return res;
}
#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 );
unsigned int Jim_GenHashFunction(const unsigned char *buf, int len)
{
unsigned int h = 0;
- while(len--)
+ while (len--)
h += (h<<3)+*buf++;
return h;
}
/* For each hash entry on this slot... */
he = ht->table[i];
- while(he) {
+ while (he) {
unsigned int h;
nextHe = he->next;
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)
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);
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;
if (size >= 2147483648U)
return 2147483648U;
- while(1) {
+ while (1) {
if (i >= size)
return i;
i *= 2;
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;
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;
pc->eof = 1;
return JIM_OK;
}
- switch(*(pc->p)) {
+ switch (*(pc->p)) {
case '\\':
if (*(pc->p+1) == '\n')
return JimParseSep(pc);
pc->tt = JIM_TT_ESC;
return JIM_OK;
}
- switch(*pc->p) {
+ switch (*pc->p) {
case '\\':
if (pc->state == JIM_PS_DEF &&
*(pc->p+1) == '\n') {
slen = strlen(s);
for (i = 0; i < slen; i++) {
- switch(s[i]) {
+ switch (s[i]) {
case '\\':
- switch(s[i+1]) {
+ switch (s[i+1]) {
case 'a': *p++ = 0x7; i++; break;
case 'b': *p++ = 0x8; i++; break;
case 'f': *p++ = 0xc; i++; break;
int level = 0;
int state = ' ';
- while(len) {
+ while (len) {
switch (*s) {
case '\\':
if (len > 1)
pc->eof = 1;
return JIM_OK;
}
- switch(*pc->p) {
+ switch (*pc->p) {
case ' ':
case '\n':
case '\t':
pc->tt = JIM_TT_ESC;
return JIM_OK;
}
- switch(*pc->p) {
+ switch (*pc->p) {
case '\\':
pc->p++; pc->len--;
break;
buf = jim_vasprintf( fmt, ap );
va_end(ap);
- if( buf ){
+ if ( buf ){
Jim_AppendString( interp, objPtr, buf, -1 );
jim_vasprintf_done(buf);
}
haveprec = 0;
prec = -1; /* not found yet */
next_fmt:
- if( fmtLen <= 0 ){
+ if ( fmtLen <= 0 ){
break;
}
- switch( *fmt ){
+ switch ( *fmt ){
/* terminals */
case 'b': /* binary - not all printfs() do this */
case 's': /* string */
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 {
/* 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;
}
*/
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);
/* here we do the work */
/* actually - we make sprintf() do it for us */
- switch(*fmt) {
+ switch (*fmt) {
case 's':
*cp++ = 's';
*cp = 0;
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;
}
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 {
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;
}
JimParserInit(&parser, scriptText, scriptTextLen, initialLineNumber);
- while(!JimParserEof(&parser)) {
+ while (!JimParserEof(&parser)) {
char *token;
int len, type, linenr;
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;
JimVariablesHTValDestructor /* val destructor */
};
+static Jim_HashTableType *getJimVariablesHashTableType(void)
+{
+ return &JimVariablesHashTableType;
+}
+
/* -----------------------------------------------------------------------------
* Variable object
* ---------------------------------------------------------------------------*/
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);
* 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;
continue;
}
/* Extract references from the object string repr. */
- while(1) {
+ while (1) {
int i;
jim_wide id;
char buf[21];
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;
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,
}
/* Free cached CallFrame structures */
cf = i->freeFramesList;
- while(cf) {
+ while (cf) {
nextcf = cf->nextFramePtr;
if (cf->vars.table != NULL)
Jim_Free(cf->vars.table);
goto testbrace;
}
for (i = 0; i < len; i++) {
- switch(s[i]) {
+ switch (s[i]) {
case ' ':
case '$':
case '"':
s[len-1] == ']') return JIM_ELESTR_QUOTE;
level = 0;
for (i = 0; i < len; i++) {
- switch(s[i]) {
+ switch (s[i]) {
case '{': level++; break;
case '}': level--;
if (level < 0) return JIM_ELESTR_QUOTE;
if (level == 0) {
if (!trySimple) return JIM_ELESTR_BRACE;
for (i = 0; i < len; i++) {
- switch(s[i]) {
+ switch (s[i]) {
case ' ':
case '$':
case '"':
char *q = Jim_Alloc(len*2+1), *p;
p = q;
- while(*s) {
+ while (*s) {
switch (*s) {
case ' ':
case '$':
const char *strRep = Jim_GetString(ele[i], &len);
char *q;
- switch(quotingType[i]) {
+ switch (quotingType[i]) {
case JIM_ELESTR_SIMPLE:
memcpy(p, strRep, len);
p += len;
/* Convert into a list */
JimParserInit(&parser, str, strLen, 1);
- while(!JimParserEof(&parser)) {
+ while (!JimParserEof(&parser)) {
char *token;
int tokenLen, type;
Jim_Obj *elementPtr;
const char *strRep = Jim_GetString(objv[i], &len);
char *q;
- switch(quotingType[i]) {
+ switch (quotingType[i]) {
case JIM_ELESTR_SIMPLE:
memcpy(p, strRep, len);
p += len;
/* Convert into a dict */
JimParserInit(&parser, str, strLen, 1);
i = 0;
- while(!JimParserEof(&parser)) {
+ while (!JimParserEof(&parser)) {
char *token;
int tokenLen, type;
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) {
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' ||
pc->eof = 1;
return JIM_OK;
}
- switch(*(pc->p)) {
+ switch (*(pc->p)) {
case '(':
pc->tstart = pc->tend = pc->p;
pc->tline = pc->linenr;
* and make sure at the end of the program there is
* a single result on the stack. */
for (i = 0; i < expr->len; i++) {
- switch(expr->opcode[i]) {
+ switch (expr->opcode[i]) {
case JIM_EXPROP_NUMBER:
case JIM_EXPROP_STRING:
case JIM_EXPROP_SUBST:
/* Search for the end of the first operator */
leftindex = index-1;
arity = 1;
- while(arity) {
- switch(expr->opcode[leftindex]) {
+ while (arity) {
+ switch (expr->opcode[leftindex]) {
case JIM_EXPROP_NUMBER:
case JIM_EXPROP_COMMAND:
case JIM_EXPROP_VARIABLE:
Jim_InitStack(&stack);
JimParserInit(&parser, exprText, exprTextLen, 1);
- while(!JimParserEof(&parser)) {
+ while (!JimParserEof(&parser)) {
char *token;
int len, type;
Jim_Free(token);
break;
}
- switch(type) {
+ switch (type) {
case JIM_TT_STR:
ExprObjAddInstr(interp, expr, JIM_EXPROP_STRING, token, len);
break;
break;
case JIM_TT_EXPR_OPERATOR:
op = JimExprOperatorInfo(token);
- while(1) {
+ while (1) {
Jim_ExprOperator *stackTopOp;
if (Jim_StackPeek(&stack) != NULL) {
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);
}
Jim_DecrRefCount(interp, A);
Jim_DecrRefCount(interp, B);
- switch(expr->opcode[i]) {
+ switch (expr->opcode[i]) {
case JIM_EXPROP_ADD: wC = wA+wB; break;
case JIM_EXPROP_SUB: wC = wA-wB; break;
case JIM_EXPROP_MUL: wC = wA*wB; break;
case JIM_EXPROP_LSHIFT: wC = wA<<wB; break;
case JIM_EXPROP_RSHIFT: wC = wA>>wB; break;
case JIM_EXPROP_NUMEQ: wC = wA==wB; break;
- case JIM_EXPROP_NUMNE: wC = wA!=wB; break;
+ case JIM_EXPROP_NUMNE: wC = wA != wB; break;
case JIM_EXPROP_BITAND: wC = wA&wB; break;
case JIM_EXPROP_BITXOR: wC = wA^wB; break;
case JIM_EXPROP_BITOR: wC = wA|wB; break;
}
Jim_DecrRefCount(interp, A);
Jim_DecrRefCount(interp, B);
- switch(expr->opcode[i]) {
+ switch (expr->opcode[i]) {
case JIM_EXPROP_ROTL:
case JIM_EXPROP_ROTR:
case JIM_EXPROP_LSHIFT:
case JIM_EXPROP_LTE: dC = dA<=dB; break;
case JIM_EXPROP_GTE: dC = dA>=dB; break;
case JIM_EXPROP_NUMEQ: dC = dA==dB; break;
- case JIM_EXPROP_NUMNE: dC = dA!=dB; break;
+ case JIM_EXPROP_NUMNE: dC = dA != dB; break;
case JIM_EXPROP_LOGICAND_LEFT:
if (dA == 0) {
i += (int)dB;
retry_as_string:
sA = Jim_GetString(A, &Alen);
sB = Jim_GetString(B, &Blen);
- switch(opcode) {
+ switch (opcode) {
case JIM_EXPROP_STREQ:
if (Alen == Blen && memcmp(sA, sB, Alen) ==0)
wC = 1;
goto trydouble_unary;
}
Jim_DecrRefCount(interp, A);
- switch(expr->opcode[i]) {
+ switch (expr->opcode[i]) {
case JIM_EXPROP_NOT: wC = !wA; break;
case JIM_EXPROP_BITNOT: wC = ~wA; break;
case JIM_EXPROP_LOGICAND_RIGHT:
goto err;
}
Jim_DecrRefCount(interp, A);
- switch(expr->opcode[i]) {
+ switch (expr->opcode[i]) {
case JIM_EXPROP_NOT: dC = !dA; break;
case JIM_EXPROP_LOGICAND_RIGHT:
case JIM_EXPROP_LOGICOR_RIGHT: dC = (dA != 0); break;
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
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.
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 {
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 {
{
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);
{
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;
}
{
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;
}
/* Compute every token forming the argument
* in the intv objects vector. */
for (i = 0; i < tokens; i++) {
- switch(token[i].type) {
+ switch (token[i].type) {
case JIM_TT_ESC:
case JIM_TT_STR:
intv[i] = token[i].objPtr;
if (tokens == 1) {
/* Fast path if the token does not
* need interpolation */
- switch(token[i].type) {
+ switch (token[i].type) {
case JIM_TT_ESC:
case JIM_TT_STR:
argv[j] = token[i].objPtr;
if (cmd->cmdProc) {
interp->cmdPrivData = cmd->privData;
retcode = cmd->cmdProc(interp, argc, argv);
- if (retcode == JIM_ERR_ADDSTACK) {
+ if ((retcode == JIM_ERR)||(retcode == JIM_ERR_ADDSTACK)) {
JimAppendStackTrace(interp, "", script->fileName, token[i-argc*2].linenr);
retcode = JIM_ERR;
}
Jim_IncrRefCount(scriptObjPtr);
- if( filename ){
+ if ( filename ){
JimSetSourceInfo( interp, scriptObjPtr, filename, lineno );
}
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,
pc->eof = 1;
return JIM_OK;
}
- switch(*pc->p) {
+ switch (*pc->p) {
case '[':
retval = JimParseCmd(pc);
if (flags & JIM_SUBST_NOCMD) {
script->fileName = NULL;
JimParserInit(&parser, scriptText, scriptTextLen, 1);
- while(1) {
+ while (1) {
char *token;
int len, type, linenr;
for (i = 0; i < len; i++) {
Jim_Obj *objPtr;
- switch(token[i].type) {
+ switch (token[i].type) {
case JIM_TT_STR:
case JIM_TT_ESC:
Jim_AppendObj(interp, resObjPtr, token[i].objPtr);
if ((expr = Jim_GetExpression(interp, argv[1])) == NULL) goto noopt;
if (expr->len <= 0 || expr->len > 3) goto noopt;
- switch(expr->len) {
+ switch (expr->len) {
case 1:
if (expr->opcode[0] != JIM_EXPROP_VARIABLE &&
expr->opcode[0] != JIM_EXPROP_NUMBER)
(expr->opcode[1] != JIM_EXPROP_NUMBER &&
expr->opcode[1] != JIM_EXPROP_VARIABLE))
goto noopt;
- switch(expr->opcode[2]) {
+ switch (expr->opcode[2]) {
case JIM_EXPROP_LT:
case JIM_EXPROP_LTE:
case JIM_EXPROP_GT:
}
if (!wideValue) break;
if ((retval = Jim_EvalObj(interp, argv[2])) != JIM_OK) {
- switch(retval) {
+ switch (retval) {
case JIM_BREAK:
if (varAObjPtr)
Jim_DecrRefCount(interp, varAObjPtr);
goto noopt;
}
}
- switch(cmpType) {
+ switch (cmpType) {
case JIM_EXPROP_LT:
cmpRes = wideValueA < wideValueB; break;
case JIM_EXPROP_LTE:
}
if (!cmpRes) break;
if ((retval = Jim_EvalObj(interp, argv[2])) != JIM_OK) {
- switch(retval) {
+ switch (retval) {
case JIM_BREAK:
Jim_DecrRefCount(interp, varAObjPtr);
if (varBObjPtr)
return retval;
if (!boolean) break;
if ((retval = Jim_EvalObj(interp, argv[2])) != JIM_OK) {
- switch(retval) {
+ switch (retval) {
case JIM_BREAK:
goto out;
break;
}
/* Eval body */
if ((retval = Jim_EvalObj(interp, argv[4])) != JIM_OK) {
- switch(retval) {
+ switch (retval) {
case JIM_BREAK:
if (stopVarNamePtr)
Jim_DecrRefCount(interp, stopVarNamePtr);
if (!boolean) break;
/* Eval body */
if ((retval = Jim_EvalObj(interp, argv[4])) != JIM_OK) {
- switch(retval) {
+ switch (retval) {
case JIM_BREAK:
goto out;
break;
evalnext:
/* Eval next */
if ((retval = Jim_EvalObj(interp, argv[3])) != JIM_OK) {
- switch(retval) {
+ switch (retval) {
case JIM_BREAK:
goto out;
break;
script = caseList[i+1];
}
}
- for(; i < patCount && Jim_CompareStringImmediate(interp, script, "-");
+ for (; i < patCount && Jim_CompareStringImmediate(interp, script, "-");
i += 2)
script = caseList[i+1];
if (script && Jim_CompareStringImmediate(interp, script, "-")) {
if (Jim_GetEnum(interp, argv[i], options, &option, "option", JIM_ERRMSG)
!= JIM_OK)
return JIM_ERR;
- switch(option) {
+ switch (option) {
case OPT_ASCII: lsortType = JIM_LSORT_ASCII; break;
case OPT_NOCASE: lsortType = JIM_LSORT_NOCASE; break;
case OPT_INCREASING: decreasing = 0; break;
}
}
if (decreasing) {
- switch(lsortType) {
+ switch (lsortType) {
case JIM_LSORT_ASCII: lsortType = JIM_LSORT_ASCII_DECR; break;
case JIM_LSORT_NOCASE: lsortType = JIM_LSORT_NOCASE_DECR; break;
}
const char *type;
Jim_ExprOperator *op;
- switch(expr->opcode[i]) {
+ switch (expr->opcode[i]) {
case JIM_EXPROP_NUMBER: type = "number"; break;
case JIM_EXPROP_COMMAND: type = "command"; break;
case JIM_EXPROP_VARIABLE: type = "variable"; break;
}
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],
return JIM_ERR;
}
i = argc-2;
- while(i--) {
+ while (i--) {
if (Jim_CompareStringImmediate(interp, argv[i+1],
"-nobackslashes"))
flags |= JIM_SUBST_NOESC;
char *val;
if (argc == 1) {
+
+#ifdef NEED_ENVIRON_EXTERN
extern char **environ;
+#endif
int i;
Jim_Obj *listObjPtr = Jim_NewListObj(interp, NULL, 0);
{
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,
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;
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;
}
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;
}
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;
}
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;
}
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;
}
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++;
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++;
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;
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;
jim_wide w;
e = Jim_GetWide( interp, o, &w );
- if( e != JIM_OK ){
+ if ( e != JIM_OK ){
return e;
}
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++;
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;
int x;
Jim_fprintf( p->interp, p->interp->cookie_stderr, "---args---\n");
- for( x = 0 ; x < p->argc ; x++ ){
+ for ( x = 0 ; x < p->argc ; x++ ){
Jim_fprintf( p->interp, p->interp->cookie_stderr,
"%2d) %s\n",
x,
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;
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);
}
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 ) );
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;
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,
const Jim_Nvp *nvptable,
int hadprefix )
{
- if( hadprefix ){
+ if ( hadprefix ){
Jim_SetResult_NvpUnknown( goi->interp,
goi->argv[-2],
goi->argv[-1],
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,
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);
}
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 ),
"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 {
{
int x;
- if( debug_string_obj ){
+ if ( debug_string_obj ){
Jim_FreeObj( interp, debug_string_obj );
}
debug_string_obj = Jim_NewEmptyStringObj( interp );
- for( x = 0 ; x < argc ; x++ ){
+ for ( x = 0 ; x < argc ; x++ ){
Jim_AppendStrings( interp,
debug_string_obj,
Jim_GetString( argv[x], NULL ),
return Jim_GetString( debug_string_obj, NULL );
}
-
-
-
-/*
- * Local Variables: ***
- * c-basic-offset: 4 ***
- * tab-width: 4 ***
- * End: ***
- */