*
* Copyright 2005 Salvatore Sanfilippo <antirez@invece.org>
* Copyright 2005 Clemens Hintze <c.hintze@gmx.net>
- * Copyright 2005 patthoyts - Pat Thoyts <patthoyts@users.sf.net>
- * Copyright 2008 oharboe - Øyvind Harboe - oyvind.harboe@zylin.com
+ * Copyright 2005 patthoyts - Pat Thoyts <patthoyts@users.sf.net>
+ * Copyright 2008,2009 oharboe - Øyvind Harboe - oyvind.harboe@zylin.com
* Copyright 2008 Andrew Lunn <andrew@lunn.ch>
* Copyright 2008 Duane Ellis <openocd@duaneellis.com>
* Copyright 2008 Uwe Klein <uklein@klein-messgeraete.de>
* Copyright 2008 Steve Bennett <steveb@workware.net.au>
- *
+ * Copyright 2009 Nico Coesel <ncoesel@dealogic.nl>
+ * Copyright 2009 Zachary T Welch zw@superlucidity.net
+ * Copyright 2009 David Brownell
+ *
* The FreeBSD license
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
- *
+ *
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials
* provided with the distribution.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE JIM TCL PROJECT ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
+ *
* The views and conclusions contained in the software and documentation
* are those of the authors and should not be interpreted as representing
* official policies, either expressed or implied, of the Jim Tcl Project.
#include <pkgconf/jimtcl.h>
#include <stdio.h>
#include <stdlib.h>
+
+typedef CYG_ADDRWORD intptr_t;
+
#include <string.h>
#include <stdarg.h>
#include <ctype.h>
* ---------------------------------------------------------------------------*/
static char *
-jim_vasprintf(const char *fmt, va_list ap )
+jim_vasprintf(const char *fmt, va_list ap)
{
#ifndef HAVE_VASPRINTF
/* yucky way */
static char buf[2048];
- vsnprintf(buf, sizeof(buf), fmt, ap );
+ vsnprintf(buf, sizeof(buf), fmt, ap);
/* garentee termination */
buf[sizeof(buf)-1] = 0;
#else
char *buf;
int result;
- result = vasprintf(&buf, fmt, ap );
+ result = vasprintf(&buf, fmt, ap);
if (result < 0) exit(-1);
#endif
return buf;
}
static void
-jim_vasprintf_done(void *buf )
+jim_vasprintf_done(void *buf)
{
#ifndef HAVE_VASPRINTF
(void)(buf);
free(buf);
#endif
}
-
+
/*
* Convert a string to a jim_wide INTEGER.
}
/* Search 's1' inside 's2', starting to search from char 'index' of 's2'.
- * The index of the first occurrence of s1 in s2 is returned.
+ * The index of the first occurrence of s1 in s2 is returned.
* If s1 is not found inside s2, -1 is returned. */
int JimStringFirst(const char *s1, int l1, const char *s2, int l2, int index)
{
#else
*widePtr = strtol(str, &endptr, base);
#endif
- if ((str[0] == '\0') || (str == endptr) )
+ if ((str[0] == '\0') || (str == endptr))
return JIM_ERR;
if (endptr[0] != '\0') {
while (*endptr) {
char *endptr;
*intPtr = strtol(str, &endptr, 10);
- if ((str[0] == '\0') || (str == endptr) )
+ if ((str[0] == '\0') || (str == endptr))
return JIM_ERR;
if (endptr[0] != '\0') {
while (*endptr) {
char *endptr;
*doublePtr = strtod(str, &endptr);
- if (str[0] == '\0' || endptr[0] != '\0' || (str == endptr) )
+ if (str[0] == '\0' || endptr[0] != '\0' || (str == endptr))
return JIM_ERR;
return JIM_OK;
}
va_list ap;
va_start(ap, fmt);
- /*
+ /*
* Send it here first.. Assuming STDIO still works
*/
fprintf(stderr, JIM_NL "JIM INTERPRETER PANIC: ");
fprintf(fp,"[backtrace] of 'nm <executable>' in the bug report." JIM_NL);
}
#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 );
+ Jim_vfprintf(interp, interp->cookie_stderr, fmt, ap);
+ Jim_fprintf(interp, interp->cookie_stderr, JIM_NL JIM_NL);
}
abort();
}
char *Jim_StrDupLen(const char *s, int l)
{
char *copy = Jim_Alloc(l + 1);
-
+
memcpy(copy, s, l + 1);
copy[l] = 0; /* Just to be sure, original could be substring */
return copy;
Jim_HashEntry *he, *nextHe;
if (ht->table[i] == NULL) continue;
-
+
/* For each hash entry on this slot... */
he = ht->table[i];
while (he) {
/* Initialize a parser context.
* 'prg' is a pointer to the program text, linenr is the line
* number of the first line contained in the program. */
-void JimParserInit(struct JimParserCtx *pc, const char *prg,
+void JimParserInit(struct JimParserCtx *pc, const char *prg,
int len, int linenr)
{
pc->prg = prg;
{
char *p = dest;
int i, len;
-
+
if (slen == -1)
slen = strlen(s);
* For exmple the string:
*
* {expand}$a
- *
+ *
* will return as first token "expand", of type JIM_TT_STR
*
* While the string:
StringAppendString(objPtr, str, len);
}
-void Jim_AppendString_sprintf(Jim_Interp *interp, Jim_Obj *objPtr, const char *fmt, ... )
+void Jim_AppendString_sprintf(Jim_Interp *interp, Jim_Obj *objPtr, const char *fmt, ...)
{
char *buf;
va_list ap;
- va_start(ap, fmt );
- buf = jim_vasprintf(fmt, ap );
+ va_start(ap, fmt);
+ buf = jim_vasprintf(fmt, ap);
va_end(ap);
- if (buf ){
- Jim_AppendString(interp, objPtr, buf, -1 );
+ if (buf) {
+ Jim_AppendString(interp, objPtr, buf, -1);
jim_vasprintf_done(buf);
}
}
memcpy(buf, strObjPtr->bytes, strObjPtr->length + 1);
for (i = 0; i < strObjPtr->length; i++)
- buf[i] = tolower(buf[i]);
+ buf[i] = tolower((unsigned)buf[i]);
return Jim_NewStringObjNoAlloc(interp, buf, strObjPtr->length);
}
memcpy(buf, strObjPtr->bytes, strObjPtr->length + 1);
for (i = 0; i < strObjPtr->length; i++)
- buf[i] = toupper(buf[i]);
+ buf[i] = toupper((unsigned)buf[i]);
return Jim_NewStringObjNoAlloc(interp, buf, strObjPtr->length);
}
/* This is the core of the [format] command.
* TODO: Lots of things work - via a hack
- * However, no format item can be >= JIM_MAX_FMT
+ * However, no format item can be >= JIM_MAX_FMT
*/
#define JIM_MAX_FMT 2048
static Jim_Obj *Jim_FormatString_Inner(Jim_Interp *interp, Jim_Obj *fmtObjPtr,
const char *fmt, *_fmt;
int fmtLen;
Jim_Obj *resObjPtr;
-
+
fmt = Jim_GetString(fmtObjPtr, &fmtLen);
_fmt = fmt;
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 'u': /* unsigned */
case 'f': /* float */
break;
-
+
/* non-terminals */
case '0': /* zero pad */
zpad = 1;
altfm = 1;
fmt++; fmtLen--;
goto next_fmt;
-
+
case '.':
inprec = 1;
fmt++; fmtLen--;
case '8':
case '9':
accum = 0;
- while (isdigit(*fmt) && (fmtLen > 0) ){
+ while (isdigit((unsigned)*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 ){
- Jim_FreeNewObj(interp, resObjPtr );
+ 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;
}
goto next_fmt;
break;
}
-
-
+
+
if (*fmt != '%') {
if (objc == 0) {
not_enough_args:
objc--;
}
}
-
+
/*
* Create the formatter
* cause we cheat and use sprintf()
*/
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 ){
- sprintf(cp, "%d", width );
+ 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 ){
- sprintf(cp, "%d", prec );
+ if (haveprec) {
+ sprintf(cp, "%d", prec);
}
cp = strchr(cp,0);
}
*cp++ = 's';
*cp = 0;
/* BUG: we do not handled embeded NULLs */
- snprintf(sprintf_buf, JIM_MAX_FMT, fmt_str, Jim_GetString(objv[0], NULL ));
+ snprintf(sprintf_buf, JIM_MAX_FMT, fmt_str, Jim_GetString(objv[0], NULL));
break;
case 'c':
*cp++ = 'c';
return NULL;
}
c = (char) wideValue;
- snprintf(sprintf_buf, JIM_MAX_FMT, fmt_str, c );
+ snprintf(sprintf_buf, JIM_MAX_FMT, fmt_str, c);
break;
case 'f':
case 'F':
case 'E':
*cp++ = *fmt;
*cp = 0;
- if (Jim_GetDouble(interp, objv[0], &doubleValue ) == JIM_ERR ){
- Jim_FreeNewObj(interp, resObjPtr );
+ if (Jim_GetDouble(interp, objv[0], &doubleValue) == JIM_ERR) {
+ Jim_FreeNewObj(interp, resObjPtr);
return NULL;
}
- snprintf(sprintf_buf, JIM_MAX_FMT, fmt_str, doubleValue );
+ snprintf(sprintf_buf, JIM_MAX_FMT, fmt_str, doubleValue);
break;
case 'b':
case 'd':
case 'x':
case 'X':
/* jim widevaluse are 64bit */
- if (sizeof(jim_wide) == sizeof(long long) ){
- *cp++ = 'l';
+ if (sizeof(jim_wide) == sizeof(long long)) {
+ *cp++ = 'l';
*cp++ = 'l';
} else {
*cp++ = 'l';
Jim_FreeNewObj(interp, resObjPtr);
return NULL;
}
- snprintf(sprintf_buf, JIM_MAX_FMT, fmt_str, wideValue );
+ snprintf(sprintf_buf, JIM_MAX_FMT, fmt_str, wideValue);
break;
case '%':
sprintf_buf[0] = '%';
}
/* force terminate */
#if 0
- printf("FMT was: %s\n", fmt_str );
- printf("RES was: |%s|\n", sprintf_buf );
+ printf("FMT was: %s\n", fmt_str);
+ printf("RES was: |%s|\n", sprintf_buf);
#endif
-
+
sprintf_buf[ JIM_MAX_FMT - 1] = 0;
- Jim_AppendString(interp, resObjPtr, sprintf_buf, strlen(sprintf_buf) );
+ Jim_AppendString(interp, resObjPtr, sprintf_buf, strlen(sprintf_buf));
/* next obj */
objv++;
fmt++;
char *sprintf_buf = malloc(JIM_MAX_FMT);
Jim_Obj *t = Jim_FormatString_Inner(interp, fmtObjPtr, objc, objv, sprintf_buf);
free(sprintf_buf);
- return t;
+ return t;
}
/* -----------------------------------------------------------------------------
return JIM_ERR;
}
-int Jim_GetNvp(Jim_Interp *interp,
+int Jim_GetNvp(Jim_Interp *interp,
Jim_Obj *objPtr,
- const Jim_Nvp *nvp_table,
+ const Jim_Nvp *nvp_table,
const Jim_Nvp ** result)
{
Jim_Nvp *n;
int e;
- e = Jim_Nvp_name2value_obj(interp, nvp_table, objPtr, &n );
- if (e == JIM_ERR ){
+ e = Jim_Nvp_name2value_obj(interp, nvp_table, objPtr, &n);
+ if (e == JIM_ERR) {
return e;
}
/* Success? found? */
- if (n->name ){
+ if (n->name) {
/* remove const */
*result = (Jim_Nvp *)n;
return JIM_OK;
* The command structure is a pre-computed representation of the
* command length and arguments structure as a simple liner array
* of integers.
- *
+ *
* For example the script:
*
* puts hello
int i;
struct ScriptObj *script = (void*) objPtr->internalRep.ptr;
+ if (!script)
+ return;
+
script->inUse--;
if (script->inUse != 0) return;
for (i = 0; i < script->len; i++) {
cmdPtr->arityMin = arityMin;
cmdPtr->arityMax = arityMax;
cmdPtr->staticVars = NULL;
-
+
/* Create the statics hash table. */
if (staticsListObjPtr) {
int len, i;
Jim_InitHashTable(cmdPtr->staticVars, getJimVariablesHashTableType(),
interp);
for (i = 0; i < len; i++) {
- Jim_Obj *objPtr, *initObjPtr, *nameObjPtr;
+ Jim_Obj *objPtr=NULL, *initObjPtr=NULL, *nameObjPtr=NULL;
Jim_Var *varPtr;
int subLen;
return JIM_OK;
}
-int Jim_RenameCommand(Jim_Interp *interp, const char *oldName,
+int Jim_RenameCommand(Jim_Interp *interp, const char *oldName,
const char *newName)
{
Jim_Cmd *cmdPtr;
const char *name;
Jim_Var *varPtr;
int err;
-
+
if ((err = SetVariableFromAny(interp, nameObjPtr)) != JIM_OK) {
/* Check for [dict] syntax sugar. */
if (err == JIM_DICT_SUGAR)
return copy;
}
-int JimReferencesHTKeyCompare(void *privdata, const void *key1,
+int JimReferencesHTKeyCompare(void *privdata, const void *key1,
const void *key2)
{
JIM_NOTUSED(privdata);
&objPtr->internalRep.refValue.id, NULL);
#ifdef JIM_DEBUG_GC
Jim_fprintf(interp,interp->cookie_stdout,
- "MARK (reference): %d refcount: %d" JIM_NL,
+ "MARK (reference): %d refcount: %d" JIM_NL,
(int) objPtr->internalRep.refValue.id,
objPtr->refCount);
#endif
{
jim_wide elapsedId;
int elapsedTime;
-
+
elapsedId = interp->referenceNextId - interp->lastCollectId;
elapsedTime = time(NULL) - interp->lastCollectTime;
i->cookie_stderr = stderr;
i->cb_fwrite = ((size_t (*)(const void *, size_t, size_t, void *))(fwrite));
i->cb_fread = ((size_t (*)(void *, size_t, size_t, void *))(fread));
- i->cb_vfprintf = ((int (*)(void *, const char *fmt, va_list ))(vfprintf));
+ i->cb_vfprintf = ((int (*)(void *, const char *fmt, va_list))(vfprintf));
i->cb_fflush = ((int (*)(void *))(fflush));
i->cb_fgets = ((char * (*)(char *, int, void *))(fgets));
* there is a memory leak. */
if (i->liveList != NULL) {
Jim_Obj *objPtr = i->liveList;
-
+
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) {
Jim_AddHashEntry(&interp->sharedStrings, strCopy, (void*)1);
return strCopy;
} else {
- long refCount = (long) he->val;
+ intptr_t refCount = (intptr_t) he->val;
refCount++;
he->val = (void*) refCount;
void Jim_ReleaseSharedString(Jim_Interp *interp, const char *str)
{
- long refCount;
+ intptr_t refCount;
Jim_HashEntry *he = Jim_FindHashEntry(&interp->sharedStrings, str);
if (he == NULL)
Jim_Panic(interp,"Jim_ReleaseSharedString called with "
"unknown shared string '%s'", str);
- refCount = (long) he->val;
+ refCount = (intptr_t) he->val;
refCount--;
if (refCount == 0) {
Jim_DeleteHashEntry(&interp->sharedStrings, str);
return JIM_OK;
}
-Jim_Obj *Jim_NewListObj(Jim_Interp *interp, Jim_Obj *const *elements,
+Jim_Obj *Jim_NewListObj(Jim_Interp *interp, Jim_Obj *const *elements,
int len)
{
Jim_Obj *objPtr;
SetListFromAny(interp, listPtr);
if (index >= 0 && index > listPtr->internalRep.listValue.len)
index = listPtr->internalRep.listValue.len;
- else if (index < 0 )
+ else if (index < 0)
index = 0;
Jim_InvalidateStringRep(listPtr);
ListInsertElements(listPtr, index, objc, objVec);
index = INT_MAX;
else
index = -(index + 1);
- } else if (!end && index < 0)
+ } else if (index < 0)
index = -INT_MAX;
/* Free the old internal repr and set the new one. */
Jim_FreeIntRep(interp, objPtr);
if (*pc->p == '-') {
pc->p++; pc->len--;
}
- while (isdigit((int)*pc->p)
- || (allowhex && isxdigit((int)*pc->p) )
- || (allowdot && *pc->p == '.')
+ while (isdigit((int)*pc->p)
+ || (allowhex && isxdigit((int)*pc->p))
+ || (allowdot && *pc->p == '.')
|| (pc->p-pc->tstart == 1 && *pc->tstart == '0' &&
(*pc->p == 'x' || *pc->p == 'X'))
- )
+)
{
if ((*pc->p == 'x') || (*pc->p == 'X')) {
allowhex = 1;
"Got floating-point value where integer was expected", -1);
error = 1;
goto err;
- break;
case JIM_EXPROP_ADD: dC = dA + dB; break;
case JIM_EXPROP_SUB: dC = dA-dB; break;
case JIM_EXPROP_MUL: 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;
+ /* FIXME comparing floats for equality/inequality is bad juju */
case JIM_EXPROP_NUMEQ: dC = dA == dB; break;
case JIM_EXPROP_NUMNE: dC = dA != dB; break;
case JIM_EXPROP_LOGICAND_LEFT:
* to be parsed in its entirely first and then, if correct, can be used for
* scanning. To avoid endless re-parsing, the parsed representation will be
* stored in an internal representation and re-used for performance reason. */
-
+
/* A ScanFmtPartDescr will held the information of /one/ part of the whole
* scanformat string. This part will later be used to extract information
* out from the string to be parsed by Jim_ScanString */
-
+
typedef struct ScanFmtPartDescr {
char type; /* Type of conversion (e.g. c, d, f) */
char modifier; /* Modify type (e.g. l - long, h - short */
size_t width; /* Maximal width of input to be converted */
- int pos; /* -1 - no assign, 0 - natural pos, >0 - XPG3 pos */
+ int pos; /* -1 - no assign, 0 - natural pos, >0 - XPG3 pos */
char *arg; /* Specification of a CHARSET conversion */
char *prefix; /* Prefix to be scanned literally before conversion */
} ScanFmtPartDescr;
int width = 0, skip;
ScanFmtPartDescr *descr = &fmtObj->descr[curr];
fmtObj->count++;
- descr->width = 0; /* Assume width unspecified */
+ descr->width = 0; /* Assume width unspecified */
/* Overread and store any "literal" prefix */
if (*fmt != '%' || fmt[1] == '%') {
descr->type = 0;
buffer[i++] = *fmt;
}
buffer[i++] = 0;
- }
+ }
/* Skip the conversion introducing '%' sign */
- ++fmt;
+ ++fmt;
/* End reached due to non-conversion literal only? */
if (fmt >= fmtEnd)
goto done;
if (*fmt != ']') {
fmtObj->error = "unmatched [ in format string";
return JIM_ERR;
- }
+ }
end = i;
buffer[i++] = 0;
/* In case a range fence was given "backwards", swap it */
/* Remember any valid modifier if given */
if (strchr("hlL", *fmt) != 0)
descr->modifier = tolower((int)*fmt++);
-
+
descr->type = *fmt;
if (strchr("efgcsndoxui", *fmt) == 0) {
fmtObj->error = "bad scan conversion character";
((ScanFmtStringObj*)((_fo_)->internalRep.ptr))->error
/* Some Bit testing/setting/cleaning routines. For now only used in handling
- * charsets ([a-z123]) within scanning. Later on perhaps a base for a
- * bitvector implementation in Jim? */
+ * charsets ([a-z123]) within scanning. Later on perhaps a base for a
+ * bitvector implementation in Jim? */
static int JimTestBit(const char *bitvec, char ch)
{
memset(charset, (sdescr ? 0 : 255), sizeof(charset));
if (sdescr) {
/* There was a set description given, that means we are parsing
- * a specified string. So we have to build a corresponding
+ * a specified string. So we have to build a corresponding
* charset reflecting the description */
int notFlag = 0;
/* Should the set be negated at the end? */
/* Negate the charset if there was a NOT given */
for (i = 0; notFlag && i < sizeof(charset); ++i)
charset[i] = ~charset[i];
- }
+ }
/* And after all the mess above, the real work begin ... */
while (str && *str) {
if (!sdescr && isspace((int)*str))
/* If prefix require, skip WS */
if (isspace((int)descr->prefix[i]))
while (str[pos] && isspace((int)str[pos])) ++pos;
- else if (descr->prefix[i] != str[pos])
+ else if (descr->prefix[i] != str[pos])
break; /* Prefix do not match here, leave the loop */
else
++pos; /* Prefix matched so far, next round */
: descr->type == 'x' ? 16
: descr->type == 'i' ? 0
: 10;
-
+
do {
/* Try to scan a number with the given base */
if (descr->modifier == 'l')
}
/* 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.
+ * case where %i begin to parse a number prefix (e.g.
* '0x' but no further digits follows. This will be
* handled as a ZERO followed by a char 'x' by Tcl */
if (endp == tok && base == 0) base = 10;
int scanned = 1;
const char *str = Jim_GetString(strObjPtr, 0);
Jim_Obj *resultList = 0;
- Jim_Obj **resultVec;
+ Jim_Obj **resultVec =NULL;
int resultc;
Jim_Obj *emptyStr = 0;
ScanFmtStringObj *fmtObj;
#ifdef JIM_DYNLIB
#ifdef WIN32
#define RTLD_LAZY 0
-void * dlopen(const char *path, int mode)
+void * dlopen(const char *path, int mode)
{
JIM_NOTUSED(mode);
const char *prefix;
int prefixlen;
Jim_Obj *prefixObjPtr;
-
+
buf[0] = '\0';
if (Jim_ListIndex(interp, libPathObjPtr, i,
&prefixObjPtr, JIM_NONE) != JIM_OK)
continue;
if (*pathName == '/') {
strcpy(buf, pathName);
- }
+ }
else if (prefixlen && prefix[prefixlen-1] == '/')
sprintf(buf, "%s%s", prefix, pathName);
else
#define JIM_PKG_ANY_VERSION -1
/* Convert a string of the type "1.2" into an integer.
- * MAJOR.MINOR is converted as MAJOR*100 + MINOR, so "1.2" is converted
+ * MAJOR.MINOR is converted as MAJOR*100 + MINOR, so "1.2" is converted
* to the integer with value 102 */
static int JimPackageVersionToInt(Jim_Interp *interp, const char *v,
int *intPtr, int flags)
}
for (i = 0; i < num_args; i++) {
- Jim_Obj *argObjPtr;
- Jim_Obj *nameObjPtr;
- Jim_Obj *valueObjPtr;
+ Jim_Obj *argObjPtr=NULL;
+ Jim_Obj *nameObjPtr=NULL;
+ Jim_Obj *valueObjPtr=NULL;
Jim_ListIndex(interp, cmd->argListObjPtr, i, &argObjPtr, JIM_NONE);
if (i + 1 >= cmd->arityMin) {
}
/* Set optional arguments */
if (cmd->arityMax == -1) {
- Jim_Obj *listObjPtr, *objPtr;
+ Jim_Obj *listObjPtr=NULL, *objPtr=NULL;
i++;
listObjPtr = Jim_NewListObj(interp, argv + i, argc-i);
Jim_IncrRefCount(scriptObjPtr);
- if (filename ){
- JimSetSourceInfo(interp, scriptObjPtr, filename, lineno );
+ if (filename) {
+ JimSetSourceInfo(interp, scriptObjPtr, filename, lineno);
}
retval = Jim_EvalObj(interp, scriptObjPtr);
int Jim_Eval(Jim_Interp *interp, const char *script)
{
- return Jim_Eval_Named(interp, script, NULL, 0 );
+ return Jim_Eval_Named(interp, script, NULL, 0);
}
int nread, totread, maxlen, buflen;
int retval;
Jim_Obj *scriptObjPtr;
-
+
if ((fp = fopen(filename, "r")) == NULL) {
const int cwd_len = 2048;
char *cwd = malloc(cwd_len);
Jim_SetResult(interp, Jim_NewEmptyStringObj(interp));
- if (!getcwd(cwd, cwd_len )) strcpy(cwd, "unknown");
+ if (!getcwd(cwd, cwd_len)) strcpy(cwd, "unknown");
Jim_AppendStrings(interp, Jim_GetResult(interp),
"Error loading script \"", filename, "\"",
" cwd: ", cwd,
* that's: $foo($bar) */
if (script->len == 1 && script->token[0].type == JIM_TT_VAR) {
Jim_Obj *varObjPtr = script->token[0].objPtr;
-
+
Jim_IncrRefCount(varObjPtr);
resObjPtr = Jim_GetVariable(interp, varObjPtr, JIM_ERRMSG);
if (resObjPtr == NULL) {
* to return. */
savedResultObjPtr = interp->result;
Jim_IncrRefCount(savedResultObjPtr);
-
+
/* Perform the substitution. Starts with an empty object
* and adds every token (performing the appropriate
* var/command/escape substitution). */
JIM_REGISTER_API(StackPop);
JIM_REGISTER_API(StackPeek);
JIM_REGISTER_API(FreeStackElements);
- JIM_REGISTER_API(fprintf );
- JIM_REGISTER_API(vfprintf );
- JIM_REGISTER_API(fwrite );
- JIM_REGISTER_API(fread );
- JIM_REGISTER_API(fflush );
- JIM_REGISTER_API(fgets );
+ JIM_REGISTER_API(fprintf);
+ JIM_REGISTER_API(vfprintf);
+ JIM_REGISTER_API(fwrite);
+ JIM_REGISTER_API(fread);
+ JIM_REGISTER_API(fflush);
+ JIM_REGISTER_API(fgets);
JIM_REGISTER_API(GetNvp);
JIM_REGISTER_API(Nvp_name2value);
JIM_REGISTER_API(Nvp_name2value_simple);
JIM_REGISTER_API(GetOpt_Nvp);
JIM_REGISTER_API(GetOpt_NvpUnknown);
JIM_REGISTER_API(GetOpt_Enum);
-
+
JIM_REGISTER_API(Debug_ArgvString);
JIM_REGISTER_API(SetResult_sprintf);
JIM_REGISTER_API(SetResult_NvpUnknown);
/* -----------------------------------------------------------------------------
* Core commands utility functions
* ---------------------------------------------------------------------------*/
-void Jim_WrongNumArgs(Jim_Interp *interp, int argc, Jim_Obj *const *argv,
+void Jim_WrongNumArgs(Jim_Interp *interp, int argc, Jim_Obj *const *argv,
const char *msg)
{
int i;
Jim_HashEntry *he;
Jim_Obj *listObjPtr = Jim_NewListObj(interp, NULL, 0);
const char *pattern;
- int patternLen;
-
+ int patternLen=0;
+
pattern = patternObjPtr ? Jim_GetString(patternObjPtr, &patternLen) : NULL;
htiter = Jim_GetHashTableIterator(&interp->commands);
while ((he = Jim_NextHashEntry(htiter)) != NULL) {
- if (pattern && !JimStringMatch(pattern, patternLen, he->key,
+ if (pattern && !JimStringMatch(pattern, patternLen, he->key,
strlen((const char*)he->key), 0))
continue;
Jim_ListAppendElement(interp, listObjPtr,
Jim_HashEntry *he;
Jim_Obj *listObjPtr = Jim_NewListObj(interp, NULL, 0);
const char *pattern;
- int patternLen;
-
+ int patternLen=0;
+
pattern = patternObjPtr ? Jim_GetString(patternObjPtr, &patternLen) : NULL;
if (mode == JIM_VARLIST_GLOBALS) {
htiter = Jim_GetHashTableIterator(&interp->topFramePtr->vars);
if (varPtr->linkFramePtr != NULL)
continue;
}
- if (pattern && !JimStringMatch(pattern, patternLen, he->key,
+ if (pattern && !JimStringMatch(pattern, patternLen, he->key,
strlen((const char*)he->key), 0))
continue;
Jim_ListAppendElement(interp, listObjPtr,
{
const char *str;
int len, nonewline = 0;
-
+
if (argc != 2 && argc != 3) {
Jim_WrongNumArgs(interp, 1, argv, "-nonewline string");
return JIM_ERR;
}
/* Helper for [+] and [*] */
-static int Jim_AddMulHelper(Jim_Interp *interp, int argc,
+static int Jim_AddMulHelper(Jim_Interp *interp, int argc,
Jim_Obj *const *argv, int op)
{
jim_wide wideValue, res;
int i;
res = (op == JIM_EXPROP_ADD) ? 0 : 1;
-
+
for (i = 1; i < argc; i++) {
if (Jim_GetWide(interp, argv[i], &wideValue) != JIM_OK)
goto trydouble;
}
/* Helper for [-] and [/] */
-static int Jim_SubDivHelper(Jim_Interp *interp, int argc,
+static int Jim_SubDivHelper(Jim_Interp *interp, int argc,
Jim_Obj *const *argv, int op)
{
jim_wide wideValue, res = 0;
}
/* [unset] */
-static int Jim_UnsetCoreCommand(Jim_Interp *interp, int argc,
+static int Jim_UnsetCoreCommand(Jim_Interp *interp, int argc,
Jim_Obj *const *argv)
{
int i;
}
/* [incr] */
-static int Jim_IncrCoreCommand(Jim_Interp *interp, int argc,
+static int Jim_IncrCoreCommand(Jim_Interp *interp, int argc,
Jim_Obj *const *argv)
{
jim_wide wideValue, increment = 1;
}
/* [while] */
-static int Jim_WhileCoreCommand(Jim_Interp *interp, int argc,
+static int Jim_WhileCoreCommand(Jim_Interp *interp, int argc,
Jim_Obj *const *argv)
{
if (argc != 3) {
/* STEP 1 -- Check if there are the conditions to run the specialized
* version of while */
-
+
if ((expr = Jim_GetExpression(interp, argv[1])) == NULL) goto noopt;
if (expr->len <= 0 || expr->len > 3) goto noopt;
switch (expr->len) {
exprLen = expr->len;
if (exprLen == 1) {
- jim_wide wideValue;
+ jim_wide wideValue=0;
if (expr->opcode[0] == JIM_EXPROP_VARIABLE) {
varAObjPtr = expr->obj[0];
if (varAObjPtr)
Jim_DecrRefCount(interp, varAObjPtr);
} else if (exprLen == 3) {
- jim_wide wideValueA, wideValueB, cmpRes = 0;
+ jim_wide wideValueA, wideValueB=0, cmpRes = 0;
int cmpType = expr->opcode[2];
varAObjPtr = expr->obj[0];
Jim_GetWide(interp, objPtr, &wideValueB) != JIM_OK)
{
Jim_DecrRefCount(interp, varAObjPtr);
- if (varBObjPtr)
- Jim_DecrRefCount(interp, varBObjPtr);
+ Jim_DecrRefCount(interp, varBObjPtr);
goto noopt;
}
}
}
/* [for] */
-static int Jim_ForCoreCommand(Jim_Interp *interp, int argc,
+static int Jim_ForCoreCommand(Jim_Interp *interp, int argc,
Jim_Obj *const *argv)
{
int retval;
{
ScriptObj *initScript, *incrScript;
ExprByteCode *expr;
- jim_wide start, stop, currentVal;
+ jim_wide start, stop=0, currentVal;
unsigned jim_wide procEpoch = interp->procEpoch;
Jim_Obj *varNamePtr, *stopVarNamePtr = NULL, *objPtr;
int cmpType;
}
/* foreach + lmap implementation. */
-static int JimForeachMapHelper(Jim_Interp *interp, int argc,
+static int JimForeachMapHelper(Jim_Interp *interp, int argc,
Jim_Obj *const *argv, int doMap)
{
int result = JIM_ERR, i, nbrOfLists, *listsIdx, *listsEnd;
if (count > nbrOfLoops)
nbrOfLoops = count;
}
- for (; nbrOfLoops-- > 0; ) {
+ for (; nbrOfLoops-- > 0;) {
for (i = 0; i < nbrOfLists; ++i) {
int varIdx = 0, var = i * 2;
while (varIdx < listsEnd[var]) {
Jim_SetResultString(interp, "couldn't set loop variable: ", -1);
goto err;
}
- ++listsIdx[i]; /* Remember next iterator of current list */
+ ++listsIdx[i]; /* Remember next iterator of current list */
} else if (Jim_SetVariable(interp, varName, emptyStr) != JIM_OK) {
Jim_SetResultString(interp, "couldn't set loop variable: ", -1);
goto err;
}
/* [foreach] */
-static int Jim_ForeachCoreCommand(Jim_Interp *interp, int argc,
+static int Jim_ForeachCoreCommand(Jim_Interp *interp, int argc,
Jim_Obj *const *argv)
{
return JimForeachMapHelper(interp, argc, argv, 0);
}
/* [lmap] */
-static int Jim_LmapCoreCommand(Jim_Interp *interp, int argc,
+static int Jim_LmapCoreCommand(Jim_Interp *interp, int argc,
Jim_Obj *const *argv)
{
return JimForeachMapHelper(interp, argc, argv, 1);
}
/* [if] */
-static int Jim_IfCoreCommand(Jim_Interp *interp, int argc,
+static int Jim_IfCoreCommand(Jim_Interp *interp, int argc,
Jim_Obj *const *argv)
{
int boolean, retval, current = 1, falsebody = 0;
return Jim_EvalObj(interp, argv[current]);
/* Ok: no else-clause follows */
if (++current >= argc) {
- Jim_SetResult(interp, Jim_NewEmptyStringObj(interp));
+ Jim_SetResult(interp, Jim_NewEmptyStringObj(interp));
return JIM_OK;
}
falsebody = current++;
enum {SWITCH_EXACT, SWITCH_GLOB, SWITCH_RE, SWITCH_CMD, SWITCH_UNKNOWN};
/* [switch] */
-static int Jim_SwitchCoreCommand(Jim_Interp *interp, int argc,
+static int Jim_SwitchCoreCommand(Jim_Interp *interp, int argc,
Jim_Obj *const *argv)
{
int retcode = JIM_ERR, matchOpt = SWITCH_EXACT, opt = 1, patCount, i;
else if (strncmp(option, "-regexp", 2) == 0) matchOpt = SWITCH_RE;
else if (strncmp(option, "-command", 2) == 0) { matchOpt = SWITCH_CMD;
if ((argc - opt) < 2) goto wrongnumargs;
- command = argv[++opt];
+ command = argv[++opt];
} else {
Jim_SetResult(interp, Jim_NewEmptyStringObj(interp));
Jim_AppendStrings(interp, Jim_GetResult(interp),
"bad option \"", option, "\": must be -exact, -glob, "
"-regexp, -command procname or --", 0);
- goto err;
+ goto err;
}
if ((argc - opt) < 2) goto wrongnumargs;
}
"pattern body ... ?default body? or "
"{pattern body ?pattern body ...?}");
err:
- return retcode;
+ return retcode;
}
/* [list] */
-static int Jim_ListCoreCommand(Jim_Interp *interp, int argc,
+static int Jim_ListCoreCommand(Jim_Interp *interp, int argc,
Jim_Obj *const *argv)
{
Jim_Obj *listObjPtr;
}
/* [lindex] */
-static int Jim_LindexCoreCommand(Jim_Interp *interp, int argc,
+static int Jim_LindexCoreCommand(Jim_Interp *interp, int argc,
Jim_Obj *const *argv)
{
Jim_Obj *objPtr, *listObjPtr;
}
/* [llength] */
-static int Jim_LlengthCoreCommand(Jim_Interp *interp, int argc,
+static int Jim_LlengthCoreCommand(Jim_Interp *interp, int argc,
Jim_Obj *const *argv)
{
int len;
}
/* [lappend] */
-static int Jim_LappendCoreCommand(Jim_Interp *interp, int argc,
+static int Jim_LappendCoreCommand(Jim_Interp *interp, int argc,
Jim_Obj *const *argv)
{
Jim_Obj *listObjPtr;
}
/* [linsert] */
-static int Jim_LinsertCoreCommand(Jim_Interp *interp, int argc,
+static int Jim_LinsertCoreCommand(Jim_Interp *interp, int argc,
Jim_Obj *const *argv)
{
int index, len;
}
/* [lset] */
-static int Jim_LsetCoreCommand(Jim_Interp *interp, int argc,
+static int Jim_LsetCoreCommand(Jim_Interp *interp, int argc,
Jim_Obj *const *argv)
{
if (argc < 3) {
}
/* [append] */
-static int Jim_AppendCoreCommand(Jim_Interp *interp, int argc,
+static int Jim_AppendCoreCommand(Jim_Interp *interp, int argc,
Jim_Obj *const *argv)
{
Jim_Obj *stringObjPtr;
}
/* [debug] */
-static int Jim_DebugCoreCommand(Jim_Interp *interp, int argc,
+static int Jim_DebugCoreCommand(Jim_Interp *interp, int argc,
Jim_Obj *const *argv)
{
const char *options[] = {
}
/* [eval] */
-static int Jim_EvalCoreCommand(Jim_Interp *interp, int argc,
+static int Jim_EvalCoreCommand(Jim_Interp *interp, int argc,
Jim_Obj *const *argv)
{
if (argc == 2) {
}
/* [uplevel] */
-static int Jim_UplevelCoreCommand(Jim_Interp *interp, int argc,
+static int Jim_UplevelCoreCommand(Jim_Interp *interp, int argc,
Jim_Obj *const *argv)
{
if (argc >= 2) {
}
/* [expr] */
-static int Jim_ExprCoreCommand(Jim_Interp *interp, int argc,
+static int Jim_ExprCoreCommand(Jim_Interp *interp, int argc,
Jim_Obj *const *argv)
{
Jim_Obj *exprResultPtr;
}
/* [break] */
-static int Jim_BreakCoreCommand(Jim_Interp *interp, int argc,
+static int Jim_BreakCoreCommand(Jim_Interp *interp, int argc,
Jim_Obj *const *argv)
{
if (argc != 1) {
}
/* [return] */
-static int Jim_ReturnCoreCommand(Jim_Interp *interp, int argc,
+static int Jim_ReturnCoreCommand(Jim_Interp *interp, int argc,
Jim_Obj *const *argv)
{
if (argc == 1) {
}
/* [proc] */
-static int Jim_ProcCoreCommand(Jim_Interp *interp, int argc,
+static int Jim_ProcCoreCommand(Jim_Interp *interp, int argc,
Jim_Obj *const *argv)
{
int argListLen;
if (argListLen) {
const char *str;
int len;
- Jim_Obj *argPtr;
-
+ Jim_Obj *argPtr=NULL;
+
/* Check for 'args' and adjust arityMin and arityMax if necessary */
Jim_ListIndex(interp, argv[2], argListLen-1, &argPtr, JIM_NONE);
str = Jim_GetString(argPtr, &len);
}
/* [concat] */
-static int Jim_ConcatCoreCommand(Jim_Interp *interp, int argc,
+static int Jim_ConcatCoreCommand(Jim_Interp *interp, int argc,
Jim_Obj *const *argv)
{
Jim_SetResult(interp, Jim_ConcatObj(interp, argc-1, argv + 1));
}
/* [upvar] */
-static int Jim_UpvarCoreCommand(Jim_Interp *interp, int argc,
+static int Jim_UpvarCoreCommand(Jim_Interp *interp, int argc,
Jim_Obj *const *argv)
{
const char *str;
/* Lookup the target frame pointer */
str = Jim_GetString(argv[1], NULL);
- if (argc > 3 &&
+ if (argc > 3 &&
((str[0] >= '0' && str[0] <= '9') || str[0] == '#'))
{
if (Jim_GetCallFrameByLevel(interp, argv[1],
}
/* [global] */
-static int Jim_GlobalCoreCommand(Jim_Interp *interp, int argc,
+static int Jim_GlobalCoreCommand(Jim_Interp *interp, int argc,
Jim_Obj *const *argv)
{
int i;
Jim_Obj **value;
int *keyLen, strLen, i;
Jim_Obj *resultObjPtr;
-
+
Jim_ListLength(interp, mapListObjPtr, &numMaps);
if (numMaps % 2) {
Jim_SetResultString(interp,
value = Jim_Alloc(sizeof(Jim_Obj*)*numMaps);
resultObjPtr = Jim_NewStringObj(interp, "", 0);
for (i = 0; i < numMaps; i++) {
- Jim_Obj *eleObjPtr;
+ Jim_Obj *eleObjPtr=NULL;
Jim_ListIndex(interp, mapListObjPtr, i*2, &eleObjPtr, JIM_NONE);
key[i] = Jim_GetString(eleObjPtr, &keyLen[i]);
}
/* [string] */
-static int Jim_StringCoreCommand(Jim_Interp *interp, int argc,
+static int Jim_StringCoreCommand(Jim_Interp *interp, int argc,
Jim_Obj *const *argv)
{
int option;
}
/* [time] */
-static int Jim_TimeCoreCommand(Jim_Interp *interp, int argc,
+static int Jim_TimeCoreCommand(Jim_Interp *interp, int argc,
Jim_Obj *const *argv)
{
long i, count = 1;
}
/* [exit] */
-static int Jim_ExitCoreCommand(Jim_Interp *interp, int argc,
+static int Jim_ExitCoreCommand(Jim_Interp *interp, int argc,
Jim_Obj *const *argv)
{
long exitCode = 0;
}
/* [catch] */
-static int Jim_CatchCoreCommand(Jim_Interp *interp, int argc,
+static int Jim_CatchCoreCommand(Jim_Interp *interp, int argc,
Jim_Obj *const *argv)
{
int exitCode = 0;
}
/* [ref] */
-static int Jim_RefCoreCommand(Jim_Interp *interp, int argc,
+static int Jim_RefCoreCommand(Jim_Interp *interp, int argc,
Jim_Obj *const *argv)
{
if (argc != 3 && argc != 4) {
}
/* [getref] */
-static int Jim_GetrefCoreCommand(Jim_Interp *interp, int argc,
+static int Jim_GetrefCoreCommand(Jim_Interp *interp, int argc,
Jim_Obj *const *argv)
{
Jim_Reference *refPtr;
}
/* [setref] */
-static int Jim_SetrefCoreCommand(Jim_Interp *interp, int argc,
+static int Jim_SetrefCoreCommand(Jim_Interp *interp, int argc,
Jim_Obj *const *argv)
{
Jim_Reference *refPtr;
}
/* [collect] */
-static int Jim_CollectCoreCommand(Jim_Interp *interp, int argc,
+static int Jim_CollectCoreCommand(Jim_Interp *interp, int argc,
Jim_Obj *const *argv)
{
if (argc != 1) {
}
/* [finalize] reference ?newValue? */
-static int Jim_FinalizeCoreCommand(Jim_Interp *interp, int argc,
+static int Jim_FinalizeCoreCommand(Jim_Interp *interp, int argc,
Jim_Obj *const *argv)
{
if (argc != 2 && argc != 3) {
/* [info references] (list of all the references/finalizers) */
/* [rename] */
-static int Jim_RenameCoreCommand(Jim_Interp *interp, int argc,
+static int Jim_RenameCoreCommand(Jim_Interp *interp, int argc,
Jim_Obj *const *argv)
{
const char *oldName, *newName;
}
/* [dict] */
-static int Jim_DictCoreCommand(Jim_Interp *interp, int argc,
+static int Jim_DictCoreCommand(Jim_Interp *interp, int argc,
Jim_Obj *const *argv)
{
int option;
}
/* [load] */
-static int Jim_LoadCoreCommand(Jim_Interp *interp, int argc,
+static int Jim_LoadCoreCommand(Jim_Interp *interp, int argc,
Jim_Obj *const *argv)
{
if (argc < 2) {
}
/* [subst] */
-static int Jim_SubstCoreCommand(Jim_Interp *interp, int argc,
+static int Jim_SubstCoreCommand(Jim_Interp *interp, int argc,
Jim_Obj *const *argv)
{
int i, flags = 0;
}
/* [info] */
-static int Jim_InfoCoreCommand(Jim_Interp *interp, int argc,
+static int Jim_InfoCoreCommand(Jim_Interp *interp, int argc,
Jim_Obj *const *argv)
{
int cmd, result = JIM_OK;
};
enum {INFO_BODY, INFO_COMMANDS, INFO_EXISTS, INFO_GLOBALS, INFO_LEVEL,
INFO_LOCALS, INFO_VARS, INFO_VERSION, INFO_COMPLETE, INFO_ARGS, INFO_HOSTNAME};
-
+
if (argc < 2) {
Jim_WrongNumArgs(interp, 1, argv, "command ?args ...?");
return JIM_ERR;
!= JIM_OK) {
return JIM_ERR;
}
-
+
if (cmd == INFO_COMMANDS) {
if (argc != 2 && argc != 3) {
Jim_WrongNumArgs(interp, 2, argv, "?pattern?");
Jim_SetResult(interp, cmdPtr->argListObjPtr);
} else if (cmd == INFO_VERSION) {
char buf[(JIM_INTEGER_SPACE * 2) + 1];
- sprintf(buf, "%d.%d",
+ sprintf(buf, "%d.%d",
JIM_VERSION / 100, JIM_VERSION % 100);
Jim_SetResultString(interp, buf, -1);
} else if (cmd == INFO_COMPLETE) {
}
/* [split] */
-static int Jim_SplitCoreCommand(Jim_Interp *interp, int argc,
+static int Jim_SplitCoreCommand(Jim_Interp *interp, int argc,
Jim_Obj *const *argv)
{
const char *str, *splitChars, *noMatchStart;
memset(objCache, 0, sizeof(objCache));
for (i = 0; i < strLen; i++) {
int c = u[i];
-
+
if (objCache[c] == NULL)
objCache[c] = Jim_NewStringObj(interp, (char*)u + i, 1);
Jim_ListAppendElement(interp, resObjPtr, objCache[c]);
}
/* [join] */
-static int Jim_JoinCoreCommand(Jim_Interp *interp, int argc,
+static int Jim_JoinCoreCommand(Jim_Interp *interp, int argc,
Jim_Obj *const *argv)
{
const char *joinStr;
resObjPtr = Jim_NewStringObj(interp, NULL, 0);
/* Split */
for (i = 0; i < listLen; i++) {
- Jim_Obj *objPtr;
+ Jim_Obj *objPtr=NULL;
Jim_ListIndex(interp, argv[1], i, &objPtr, JIM_NONE);
Jim_AppendObj(interp, resObjPtr, objPtr);
if (argc < 3) {
Jim_WrongNumArgs(interp, 1, argv, "string formatString ?varName ...?");
return JIM_ERR;
- }
+ }
if (argv[2]->typePtr != &scanFmtStringObjType)
SetScanFmtFromAny(interp, argv[2]);
if (FormatGetError(argv[2]) != 0) {
"field specifiers", -1);
return JIM_ERR;
}
- }
+ }
listPtr = Jim_ScanString(interp, argv[1], argv[2], JIM_ERRMSG);
if (listPtr == 0)
return JIM_ERR;
static int Jim_RandCoreCommand(Jim_Interp *interp, int argc,
Jim_Obj *const *argv)
{
- jim_wide min = 0, max, len, maxMul;
+ jim_wide min = 0, max =0, len, maxMul;
if (argc < 1 || argc > 3) {
Jim_WrongNumArgs(interp, 1, argv, "?min? max");
}
/* [package] */
-static int Jim_PackageCoreCommand(Jim_Interp *interp, int argc,
+static int Jim_PackageCoreCommand(Jim_Interp *interp, int argc,
Jim_Obj *const *argv)
{
int option;
"proc lambdaFinalizer {name val} {\n"
" rename $name {}\n"
"}\n"
- );
+);
}
void Jim_RegisterCoreCommands(Jim_Interp *interp)
int i = 0;
while (Jim_CoreCommandsTable[i].name != NULL) {
- Jim_CreateCommand(interp,
+ Jim_CreateCommand(interp,
Jim_CoreCommandsTable[i].name,
Jim_CoreCommandsTable[i].cmdProc,
NULL, NULL);
Jim_GetString(interp->result, NULL));
Jim_ListLength(interp, interp->stackTrace, &len);
for (i = len-3; i >= 0; i-= 3) {
- Jim_Obj *objPtr;
+ Jim_Obj *objPtr=NULL;
const char *proc, *file, *line;
Jim_ListIndex(interp, interp->stackTrace, i, &objPtr, JIM_NONE);
* Jim's idea of STDIO..
* ---------------------------------------------------------------------------*/
-int Jim_fprintf(Jim_Interp *interp, void *cookie, const char *fmt, ... )
+int Jim_fprintf(Jim_Interp *interp, void *cookie, const char *fmt, ...)
{
int r;
va_list ap;
va_start(ap,fmt);
- r = Jim_vfprintf(interp, cookie, fmt,ap );
+ r = Jim_vfprintf(interp, cookie, fmt,ap);
va_end(ap);
return r;
}
-int Jim_vfprintf(Jim_Interp *interp, void *cookie, const char *fmt, va_list ap )
+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;
}
- return (*(interp->cb_vfprintf))(cookie, fmt, ap );
+ return (*(interp->cb_vfprintf))(cookie, fmt, ap);
}
-size_t Jim_fwrite(Jim_Interp *interp, const void *ptr, size_t size, size_t n, void *cookie )
+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;
}
return (*(interp->cb_fwrite))(ptr, size, n, cookie);
}
-size_t Jim_fread(Jim_Interp *interp, void *ptr, size_t size, size_t n, void *cookie )
+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;
}
return (*(interp->cb_fread))(ptr, size, n, cookie);
}
-int Jim_fflush(Jim_Interp *interp, void *cookie )
+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;
}
- return (*(interp->cb_fflush))(cookie );
+ return (*(interp->cb_fflush))(cookie);
}
-char* Jim_fgets(Jim_Interp *interp, char *s, int size, 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;
}
- return (*(interp->cb_fgets))(s, size, cookie );
+ return (*(interp->cb_fgets))(s, size, cookie);
}
Jim_Nvp *
-Jim_Nvp_name2value_simple(const Jim_Nvp *p, const char *name )
+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 )
+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++;
}
int
-Jim_Nvp_name2value_obj(Jim_Interp *interp,
- const Jim_Nvp *p,
- Jim_Obj *o,
- Jim_Nvp **result )
+Jim_Nvp_name2value_obj(Jim_Interp *interp,
+ const Jim_Nvp *p,
+ Jim_Obj *o,
+ Jim_Nvp **result)
{
- return Jim_Nvp_name2value(interp, p, Jim_GetString(o, NULL ), result );
+ return Jim_Nvp_name2value(interp, p, Jim_GetString(o, NULL), result);
}
-
-int
-Jim_Nvp_name2value(Jim_Interp *interp,
- const Jim_Nvp *_p,
- const char *name,
+
+int
+Jim_Nvp_name2value(Jim_Interp *interp,
+ const Jim_Nvp *_p,
+ const char *name,
Jim_Nvp **result)
{
const Jim_Nvp *p;
- p = Jim_Nvp_name2value_simple(_p, name );
+ 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;
}
int
-Jim_Nvp_name2value_obj_nocase(Jim_Interp *interp, const Jim_Nvp *p, Jim_Obj *o, Jim_Nvp **puthere )
+Jim_Nvp_name2value_obj_nocase(Jim_Interp *interp, const Jim_Nvp *p, Jim_Obj *o, Jim_Nvp **puthere)
{
- return Jim_Nvp_name2value_nocase(interp, p, Jim_GetString(o, NULL ), puthere );
+ return Jim_Nvp_name2value_nocase(interp, p, Jim_GetString(o, NULL), puthere);
}
int
-Jim_Nvp_name2value_nocase(Jim_Interp *interp, const Jim_Nvp *_p, const char *name, Jim_Nvp **puthere )
+Jim_Nvp_name2value_nocase(Jim_Interp *interp, const Jim_Nvp *_p, const char *name, Jim_Nvp **puthere)
{
const Jim_Nvp *p;
- p = Jim_Nvp_name2value_nocase_simple(_p, name );
+ 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;
}
-int
-Jim_Nvp_value2name_obj(Jim_Interp *interp, const Jim_Nvp *p, Jim_Obj *o, Jim_Nvp **result )
+int
+Jim_Nvp_value2name_obj(Jim_Interp *interp, const Jim_Nvp *p, Jim_Obj *o, Jim_Nvp **result)
{
int e;;
jim_wide w;
- e = Jim_GetWide(interp, o, &w );
- if (e != JIM_OK ){
+ e = Jim_GetWide(interp, o, &w);
+ if (e != JIM_OK) {
return e;
}
- return Jim_Nvp_value2name(interp, p, w, result );
+ return Jim_Nvp_value2name(interp, p, w, result);
}
Jim_Nvp *
-Jim_Nvp_value2name_simple(const Jim_Nvp *p, int value )
+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++;
}
-int
-Jim_Nvp_value2name(Jim_Interp *interp, const Jim_Nvp *_p, int value, Jim_Nvp **result )
+int
+Jim_Nvp_value2name(Jim_Interp *interp, const Jim_Nvp *_p, int value, Jim_Nvp **result)
{
const Jim_Nvp *p;
- p = Jim_Nvp_value2name_simple(_p, value );
+ 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
Jim_GetOpt_Setup(Jim_GetOptInfo *p, Jim_Interp *interp, int argc, Jim_Obj * const * argv)
{
- memset(p, 0, sizeof(*p) );
+ memset(p, 0, sizeof(*p));
p->interp = interp;
p->argc = argc;
p->argv = argv;
}
void
-Jim_GetOpt_Debug(Jim_GetOptInfo *p )
+Jim_GetOpt_Debug(Jim_GetOptInfo *p)
{
int x;
Jim_fprintf(p->interp, p->interp->cookie_stderr, "---args---\n");
- for (x = 0 ; x < p->argc ; x++ ){
- Jim_fprintf(p->interp, p->interp->cookie_stderr,
- "%2d) %s\n",
- x,
- Jim_GetString(p->argv[x], NULL ) );
+ for (x = 0 ; x < p->argc ; x++) {
+ Jim_fprintf(p->interp, p->interp->cookie_stderr,
+ "%2d) %s\n",
+ x,
+ Jim_GetString(p->argv[x], NULL));
}
Jim_fprintf(p->interp, p->interp->cookie_stderr, "-------\n");
}
int
-Jim_GetOpt_Obj(Jim_GetOptInfo *goi, Jim_Obj **puthere )
+Jim_GetOpt_Obj(Jim_GetOptInfo *goi, Jim_Obj **puthere)
{
Jim_Obj *o;
-
- o = NULL; // failure
- if (goi->argc ){
- // success
+
+ o = NULL; // failure
+ 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;
}
int
-Jim_GetOpt_String(Jim_GetOptInfo *goi, char **puthere, int *len )
+Jim_GetOpt_String(Jim_GetOptInfo *goi, char **puthere, int *len)
{
int r;
Jim_Obj *o;
const char *cp;
- r = Jim_GetOpt_Obj(goi, &o );
- if (r == JIM_OK ){
- cp = Jim_GetString(o, len );
- if (puthere ){
+ r = Jim_GetOpt_Obj(goi, &o);
+ if (r == JIM_OK) {
+ cp = Jim_GetString(o, len);
+ if (puthere) {
/* remove const */
*puthere = (char *)(cp);
}
}
int
-Jim_GetOpt_Double(Jim_GetOptInfo *goi, double *puthere )
+Jim_GetOpt_Double(Jim_GetOptInfo *goi, double *puthere)
{
int r;
Jim_Obj *o;
double _safe;
-
- if (puthere == NULL ){
+
+ if (puthere == NULL) {
puthere = &_safe;
}
- r = Jim_GetOpt_Obj(goi, &o );
- if (r == JIM_OK ){
- r = Jim_GetDouble(goi->interp, o, puthere );
- if (r != JIM_OK ){
+ r = Jim_GetOpt_Obj(goi, &o);
+ if (r == JIM_OK) {
+ r = Jim_GetDouble(goi->interp, o, puthere);
+ if (r != JIM_OK) {
Jim_SetResult_sprintf(goi->interp,
- "not a number: %s",
- Jim_GetString(o, NULL ) );
+ "not a number: %s",
+ Jim_GetString(o, NULL));
}
}
return r;
}
int
-Jim_GetOpt_Wide(Jim_GetOptInfo *goi, jim_wide *puthere )
+Jim_GetOpt_Wide(Jim_GetOptInfo *goi, jim_wide *puthere)
{
int r;
Jim_Obj *o;
jim_wide _safe;
- if (puthere == NULL ){
+ if (puthere == NULL) {
puthere = &_safe;
}
- r = Jim_GetOpt_Obj(goi, &o );
- if (r == JIM_OK ){
- r = Jim_GetWide(goi->interp, o, puthere );
+ r = Jim_GetOpt_Obj(goi, &o);
+ if (r == JIM_OK) {
+ r = Jim_GetWide(goi->interp, o, puthere);
}
return r;
}
-int Jim_GetOpt_Nvp(Jim_GetOptInfo *goi,
- const Jim_Nvp *nvp,
+int Jim_GetOpt_Nvp(Jim_GetOptInfo *goi,
+ const Jim_Nvp *nvp,
Jim_Nvp **puthere)
{
Jim_Nvp *_safe;
Jim_Obj *o;
int e;
- if (puthere == NULL ){
+ if (puthere == NULL) {
puthere = &_safe;
}
- e = Jim_GetOpt_Obj(goi, &o );
- if (e == JIM_OK ){
+ e = Jim_GetOpt_Obj(goi, &o);
+ if (e == JIM_OK) {
e = Jim_Nvp_name2value_obj(goi->interp,
- nvp,
+ nvp,
o,
- puthere );
+ puthere);
}
return e;
void
Jim_GetOpt_NvpUnknown(Jim_GetOptInfo *goi,
const Jim_Nvp *nvptable,
- int hadprefix )
+ int hadprefix)
{
- if (hadprefix ){
+ if (hadprefix) {
Jim_SetResult_NvpUnknown(goi->interp,
goi->argv[-2],
goi->argv[-1],
- nvptable );
+ nvptable);
} else {
Jim_SetResult_NvpUnknown(goi->interp,
NULL,
goi->argv[-1],
- nvptable );
+ nvptable);
}
}
-
-int
+
+int
Jim_GetOpt_Enum(Jim_GetOptInfo *goi,
const char * const * lookup,
int *puthere)
Jim_Obj *o;
int e;
- if (puthere == NULL ){
+ if (puthere == NULL) {
puthere = &_safe;
}
- e = Jim_GetOpt_Obj(goi, &o );
- if (e == JIM_OK ){
+ e = Jim_GetOpt_Obj(goi, &o);
+ if (e == JIM_OK) {
e = Jim_GetEnum(goi->interp,
o,
lookup,
puthere,
"option",
- JIM_ERRMSG );
+ JIM_ERRMSG);
}
return e;
}
-
+
int
-Jim_SetResult_sprintf(Jim_Interp *interp, const char *fmt,... )
+Jim_SetResult_sprintf(Jim_Interp *interp, const char *fmt,...)
{
va_list ap;
char *buf;
va_start(ap,fmt);
- buf = jim_vasprintf(fmt, ap );
+ buf = jim_vasprintf(fmt, ap);
va_end(ap);
- if (buf ){
- Jim_SetResultString(interp, buf, -1 );
+ if (buf) {
+ Jim_SetResultString(interp, buf, -1);
jim_vasprintf_done(buf);
}
return JIM_OK;
}
-
+
void
-Jim_SetResult_NvpUnknown(Jim_Interp *interp,
+Jim_SetResult_NvpUnknown(Jim_Interp *interp,
Jim_Obj *param_name,
Jim_Obj *param_value,
- const Jim_Nvp *nvp )
+ 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 ),
- Jim_GetString(param_value, NULL ) );
+ Jim_GetString(param_name, NULL),
+ Jim_GetString(param_value, NULL));
} else {
Jim_SetResult_sprintf(interp,
"Unknown param: %s, try one of: ",
- Jim_GetString(param_value, NULL ) );
+ 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 {
}
Jim_AppendStrings(interp,
Jim_GetResult(interp),
- a, b, NULL );
+ a, b, NULL);
nvp++;
}
}
-
+
static Jim_Obj *debug_string_obj;
const char *
-Jim_Debug_ArgvString(Jim_Interp *interp, int argc, Jim_Obj *const *argv )
+Jim_Debug_ArgvString(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
int x;
- if (debug_string_obj ){
- Jim_FreeObj(interp, 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++ ){
+ debug_string_obj = Jim_NewEmptyStringObj(interp);
+ for (x = 0 ; x < argc ; x++) {
Jim_AppendStrings(interp,
debug_string_obj,
- Jim_GetString(argv[x], NULL ),
+ Jim_GetString(argv[x], NULL),
" ",
- NULL );
+ NULL);
}
- return Jim_GetString(debug_string_obj, NULL );
+ return Jim_GetString(debug_string_obj, NULL);
}