* digit. For instance, if the range for quads is
* [-9223372036854775808..9223372036854775807] and the input base
* is 10, cutoff will be set to 922337203685477580 and cutlim to
- * either 7 (neg==0) or 8 (neg==1), meaning that if we have
+ * either 7 (neg == 0) or 8 (neg == 1), meaning that if we have
* accumulated a value > 922337203685477580, or equal but the
* next digit is > 7 (or 8), the number is too big, and we will
* return a range error.
const char *string, int stringLen, int nocase)
{
while (patternLen) {
- switch(pattern[0]) {
+ switch (pattern[0]) {
case '*':
while (pattern[1] == '*') {
pattern++;
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;
}
void *Jim_Alloc(int size)
{
/* We allocate zero length arrayes, etc. to use a single orthogonal codepath */
- if (size==0)
- size=1;
+ if (size == 0)
+ size = 1;
void *p = malloc(size);
if (p == NULL)
Jim_Panic(NULL,"malloc: Out of memory");
void *Jim_Realloc(void *ptr, int size)
{
/* We allocate zero length arrayes, etc. to use a single orthogonal codepath */
- if (size==0)
- size=1;
+ if (size == 0)
+ size = 1;
void *p = realloc(ptr, size);
if (p == NULL)
Jim_Panic(NULL,"realloc: Out of memory");
{
unsigned int h = 0;
while (len--)
- h += (h<<3)+*buf++;
+ h += (h << 3)+*buf++;
return h;
}
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;
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;
if ( fmtLen <= 0 ){
break;
}
- switch( *fmt ){
+ switch ( *fmt ){
/* terminals */
case 'b': /* binary - not all printfs() do this */
case 's': /* string */
/* here we do the work */
/* actually - we make sprintf() do it for us */
- switch(*fmt) {
+ switch (*fmt) {
case 's':
*cp++ = 's';
*cp = 0;
Jim_Obj *Jim_FormatString(Jim_Interp *interp, Jim_Obj *fmtObjPtr,
int objc, Jim_Obj *const *objv)
{
- char *sprintf_buf=malloc(JIM_MAX_FMT);
- Jim_Obj *t=Jim_FormatString_Inner(interp, fmtObjPtr, objc, objv, sprintf_buf);
+ char *sprintf_buf = malloc(JIM_MAX_FMT);
+ Jim_Obj *t = Jim_FormatString_Inner(interp, fmtObjPtr, objc, objv, sprintf_buf);
free(sprintf_buf);
return t;
}
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 '"':
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;
}
point = listPtr->internalRep.listValue.ele + index;
memmove(point+elemc, point, (currentLen-index) * sizeof(Jim_Obj*));
- for (i=0; i < elemc; ++i) {
+ for (i = 0; i < elemc; ++i) {
point[i] = elemVec[i];
Jim_IncrRefCount(point[i]);
}
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;
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:
leftindex = index-1;
arity = 1;
while (arity) {
- switch(expr->opcode[leftindex]) {
+ switch (expr->opcode[leftindex]) {
case JIM_EXPROP_NUMBER:
case JIM_EXPROP_COMMAND:
case JIM_EXPROP_VARIABLE:
Jim_Free(token);
break;
}
- switch(type) {
+ switch (type) {
case JIM_TT_STR:
ExprObjAddInstr(interp, expr, JIM_EXPROP_STRING, token, len);
break;
}
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_LT: wC = wA<wB; break;
case JIM_EXPROP_GT: wC = wA>wB; break;
- case JIM_EXPROP_LTE: wC = wA<=wB; break;
- case JIM_EXPROP_GTE: 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_LTE: wC = wA <= wB; break;
+ case JIM_EXPROP_GTE: 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_BITAND: wC = wA&wB; break;
case JIM_EXPROP_BITXOR: wC = wA^wB; break;
case JIM_EXPROP_BITOR: wC = wA|wB; break;
wC = _rotl(uA,(unsigned long)wB);
#else
const unsigned int S = sizeof(unsigned long) * 8;
- wC = (unsigned long)((uA<<wB)|(uA>>(S-wB)));
+ wC = (unsigned long)((uA << wB)|(uA >> (S-wB)));
#endif
break;
}
wC = _rotr(uA,(unsigned long)wB);
#else
const unsigned int S = sizeof(unsigned long) * 8;
- wC = (unsigned long)((uA>>wB)|(uA<<(S-wB)));
+ wC = (unsigned long)((uA >> wB)|(uA << (S-wB)));
#endif
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_MUL: dC = dA*dB; break;
case JIM_EXPROP_LT: dC = dA<dB; break;
case JIM_EXPROP_GT: dC = dA>dB; break;
- 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_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_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;
Jim_FreeIntRep(interp, objPtr);
/* Count how many conversions could take place maximally */
- for (i=0, maxCount=0; i < maxFmtLen; ++i)
+ for (i = 0, maxCount = 0; i < maxFmtLen; ++i)
if (fmt[i] == '%')
++maxCount;
/* Calculate an approximation of the memory necessary */
buffer = fmtObj->stringRep + maxFmtLen + 1;
objPtr->internalRep.ptr = fmtObj;
objPtr->typePtr = &scanFmtStringObjType;
- for (i=0, curr=0; fmt < fmtEnd; ++fmt) {
- int width=0, skip;
+ for (i = 0, curr = 0; fmt < fmtEnd; ++fmt) {
+ int width = 0, skip;
ScanFmtPartDescr *descr = &fmtObj->descr[curr];
fmtObj->count++;
descr->width = 0; /* Assume width unspecified */
return JIM_ERR;
}
/* Look if this position was already used */
- for (prev=0; prev < curr; ++prev) {
+ for (prev = 0; prev < curr; ++prev) {
if (fmtObj->descr[prev].pos == -1) continue;
if (fmtObj->descr[prev].pos == descr->pos) {
fmtObj->error = "same \"%n$\" conversion specifier "
/* In case a range fence was given "backwards", swap it */
while (swapped) {
swapped = 0;
- for (j=beg+1; j < end-1; ++j) {
+ for (j = beg+1; j < end-1; ++j) {
if (buffer[j] == '-' && buffer[j-1] > buffer[j+1]) {
char tmp = buffer[j-1];
buffer[j-1] = buffer[j+1];
if (sdescr[1] == '-' && sdescr[2] != 0) {
/* Handle range definitions */
int i;
- for (i=sdescr[0]; i <= sdescr[2]; ++i)
+ for (i = sdescr[0]; i <= sdescr[2]; ++i)
JimSetBit(charset, (char)i);
sdescr += 3;
} else {
}
}
/* Negate the charset if there was a NOT given */
- for (i=0; notFlag && i < sizeof(charset); ++i)
+ for (i = 0; notFlag && i < sizeof(charset); ++i)
charset[i] = ~charset[i];
}
/* And after all the mess above, the real work begin ... */
if (descr->prefix) {
/* There was a prefix given before the conversion, skip it and adjust
* the string-to-be-parsed accordingly */
- for (i=0; str[pos] && descr->prefix[i]; ++i) {
+ for (i = 0; str[pos] && descr->prefix[i]; ++i) {
/* If prefix require, skip WS */
if (isspace((int)descr->prefix[i]))
while (str[pos] && isspace((int)str[pos])) ++pos;
/* Create a list and fill it with empty strings up to max specified XPG3 */
resultList = Jim_NewListObj(interp, 0, 0);
if (fmtObj->maxPos > 0) {
- for (i=0; i < fmtObj->maxPos; ++i)
+ for (i = 0; i < fmtObj->maxPos; ++i)
Jim_ListAppendElement(interp, resultList, emptyStr);
JimListGetElements(interp, resultList, &resultc, &resultVec);
}
/* Now handle every partial format description */
- for (i=0, pos=0; i < fmtObj->count; ++i) {
+ for (i = 0, pos = 0; i < fmtObj->count; ++i) {
ScanFmtPartDescr *descr = &(fmtObj->descr[i]);
Jim_Obj *value = 0;
/* Only last type may be "literal" w/o conversion - skip it! */
return JIM_ERR;
}
-#define JIM_MATCHVER_EXACT (1<<JIM_PRIV_FLAG_SHIFT)
+#define JIM_MATCHVER_EXACT (1 << JIM_PRIV_FLAG_SHIFT)
static int JimPackageMatchVersion(int needed, int actual, int flags)
{
if (needed == JIM_PKG_ANY_VERSION) return 1;
/* 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;
Jim_Obj *scriptObjPtr;
if ((fp = fopen(filename, "r")) == NULL) {
- const int cwd_len=2048;
- char *cwd=malloc(cwd_len);
+ const int cwd_len = 2048;
+ char *cwd = malloc(cwd_len);
Jim_SetResult(interp, Jim_NewEmptyStringObj(interp));
if (!getcwd( cwd, cwd_len )) strcpy(cwd, "unknown");
Jim_AppendStrings(interp, Jim_GetResult(interp),
pc->eof = 1;
return JIM_OK;
}
- switch(*pc->p) {
+ switch (*pc->p) {
case '[':
retval = JimParseCmd(pc);
if (flags & JIM_SUBST_NOCMD) {
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;
/* Initialize iterators and remember max nbr elements each list */
memset(listsIdx, 0, nbrOfLists * sizeof(int));
/* Remember lengths of all lists and calculate how much rounds to loop */
- for (i=0; i < nbrOfLists*2; i += 2) {
+ for (i = 0; i < nbrOfLists*2; i += 2) {
div_t cnt;
int count;
Jim_ListLength(interp, argv[i+1], &listsEnd[i]);
nbrOfLoops = count;
}
for (; nbrOfLoops-- > 0; ) {
- for (i=0; i < nbrOfLists; ++i) {
+ for (i = 0; i < nbrOfLists; ++i) {
int varIdx = 0, var = i * 2;
while (varIdx < listsEnd[var]) {
Jim_Obj *varName, *ele;
static int Jim_SwitchCoreCommand(Jim_Interp *interp, int argc,
Jim_Obj *const *argv)
{
- int retcode = JIM_ERR, matchOpt = SWITCH_EXACT, opt=1, patCount, i;
+ int retcode = JIM_ERR, matchOpt = SWITCH_EXACT, opt = 1, patCount, i;
Jim_Obj *command = 0, *const *caseList = 0, *strObj;
Jim_Obj *script = 0;
if (argc < 3) goto wrongnumargs;
- for (opt=1; opt < argc; ++opt) {
+ for (opt = 1; opt < argc; ++opt) {
const char *option = Jim_GetString(argv[opt], 0);
if (*option != '-') break;
else if (strncmp(option, "--", 2) == 0) { ++opt; break; }
} else
caseList = &argv[opt];
if (patCount == 0 || patCount % 2 != 0) goto wrongnumargs;
- for (i=0; script == 0 && i < patCount; i += 2) {
+ for (i = 0; script == 0 && i < patCount; i += 2) {
Jim_Obj *patObj = caseList[i];
if (!Jim_CompareStringImmediate(interp, patObj, "default")
|| i < (patCount-2)) {
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;
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,
}
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 ),