diff options
-rw-r--r-- | jim-aio.c | 101 | ||||
-rw-r--r-- | jim-array.c | 5 | ||||
-rw-r--r-- | jim-exec.c | 2 | ||||
-rw-r--r-- | jim-format.c | 750 | ||||
-rw-r--r-- | jim-interactive.c | 10 | ||||
-rw-r--r-- | jim-namespace.c | 4 | ||||
-rw-r--r-- | jim.c | 233 |
7 files changed, 551 insertions, 554 deletions
@@ -1,4 +1,3 @@ - /* Jim - A small embeddable Tcl interpreter * * Copyright 2005 Salvatore Sanfilippo <antirez@invece.org> @@ -670,25 +669,25 @@ static int aio_cmd_eof(Jim_Interp *interp, int argc, Jim_Obj *const *argv) static int aio_cmd_close(Jim_Interp *interp, int argc, Jim_Obj *const *argv) { - if (argc == 3) { + if (argc == 3) { #ifdef HAVE_SHUTDOWN - static const char * const options[] = { "r", "w", NULL }; - enum { OPT_R, OPT_W, }; - int option; - AioFile *af = Jim_CmdPrivData(interp); - - if (Jim_GetEnum(interp, argv[2], options, &option, NULL, JIM_ERRMSG) != JIM_OK) { - return JIM_ERR; - } - if (shutdown(af->fd, option == OPT_R ? SHUT_RD : SHUT_WR) == 0) { - return JIM_OK; - } - JimAioSetError(interp, NULL); + static const char * const options[] = { "r", "w", NULL }; + enum { OPT_R, OPT_W, }; + int option; + AioFile *af = Jim_CmdPrivData(interp); + + if (Jim_GetEnum(interp, argv[2], options, &option, NULL, JIM_ERRMSG) != JIM_OK) { + return JIM_ERR; + } + if (shutdown(af->fd, option == OPT_R ? SHUT_RD : SHUT_WR) == 0) { + return JIM_OK; + } + JimAioSetError(interp, NULL); #else - Jim_SetResultString(interp, "async close not supported", -1); + Jim_SetResultString(interp, "async close not supported", -1); #endif - return JIM_ERR; - } + return JIM_ERR; + } return Jim_DeleteCommand(interp, Jim_String(argv[0])); } @@ -1120,9 +1119,9 @@ static int JimMakeChannel(Jim_Interp *interp, FILE *fh, int fd, Jim_Obj *filenam snprintf(buf, sizeof(buf), hdlfmt, Jim_GetId(interp)); Jim_CreateCommand(interp, buf, JimAioSubCmdProc, af, JimAioDelProc); - /* Note that the command must use the global namespace, even if - * the current namespace is something different - */ + /* Note that the command must use the global namespace, even if + * the current namespace is something different + */ Jim_SetResult(interp, Jim_MakeGlobalNamespaceName(interp, Jim_NewStringObj(interp, buf, -1))); return JIM_OK; @@ -1131,22 +1130,22 @@ static int JimMakeChannel(Jim_Interp *interp, FILE *fh, int fd, Jim_Obj *filenam static int JimMakeChannelPair(Jim_Interp *interp, int p[2], Jim_Obj *filename, const char *hdlfmt, int family, const char *mode[2]) { - if (JimMakeChannel(interp, NULL, p[0], filename, hdlfmt, family, mode[0]) == JIM_OK) { - Jim_Obj *objPtr = Jim_NewListObj(interp, NULL, 0); - Jim_ListAppendElement(interp, objPtr, Jim_GetResult(interp)); - - if (JimMakeChannel(interp, NULL, p[1], filename, hdlfmt, family, mode[1]) == JIM_OK) { - Jim_ListAppendElement(interp, objPtr, Jim_GetResult(interp)); - Jim_SetResult(interp, objPtr); - return JIM_OK; - } - } - - /* Can only be here if fdopen() failed */ - close(p[0]); - close(p[1]); - JimAioSetError(interp, NULL); - return JIM_ERR; + if (JimMakeChannel(interp, NULL, p[0], filename, hdlfmt, family, mode[0]) == JIM_OK) { + Jim_Obj *objPtr = Jim_NewListObj(interp, NULL, 0); + Jim_ListAppendElement(interp, objPtr, Jim_GetResult(interp)); + + if (JimMakeChannel(interp, NULL, p[1], filename, hdlfmt, family, mode[1]) == JIM_OK) { + Jim_ListAppendElement(interp, objPtr, Jim_GetResult(interp)); + Jim_SetResult(interp, objPtr); + return JIM_OK; + } + } + + /* Can only be here if fdopen() failed */ + close(p[0]); + close(p[1]); + JimAioSetError(interp, NULL); + return JIM_ERR; } #if !defined(JIM_ANSIC) && !defined(JIM_BOOTSTRAP) @@ -1372,20 +1371,20 @@ static int JimAioSockCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv) #if defined(HAVE_SOCKETPAIR) && defined(HAVE_SYS_UN_H) case SOCK_STREAM_SOCKETPAIR: - { + { int p[2]; - static const char *mode[2] = { "r+", "r+" }; + static const char *mode[2] = { "r+", "r+" }; if (argc != 2 || ipv6) { goto wrongargs; } - if (socketpair(PF_UNIX, SOCK_STREAM, 0, p) < 0) { - JimAioSetError(interp, NULL); - return JIM_ERR; - } - return JimMakeChannelPair(interp, p, argv[1], "aio.sockpair%ld", PF_UNIX, mode); - } + if (socketpair(PF_UNIX, SOCK_STREAM, 0, p) < 0) { + JimAioSetError(interp, NULL); + return JIM_ERR; + } + return JimMakeChannelPair(interp, p, argv[1], "aio.sockpair%ld", PF_UNIX, mode); + } break; #endif @@ -1393,19 +1392,19 @@ static int JimAioSockCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv) case SOCK_STREAM_PIPE: { int p[2]; - static const char *mode[2] = { "r", "w" }; + static const char *mode[2] = { "r", "w" }; if (argc != 2 || ipv6) { goto wrongargs; } - if (pipe(p) < 0) { - JimAioSetError(interp, NULL); - return JIM_ERR; - } + if (pipe(p) < 0) { + JimAioSetError(interp, NULL); + return JIM_ERR; + } - return JimMakeChannelPair(interp, p, argv[1], "aio.pipe%ld", 0, mode); - } + return JimMakeChannelPair(interp, p, argv[1], "aio.pipe%ld", 0, mode); + } break; #endif diff --git a/jim-array.c b/jim-array.c index d4f9449..179e110 100644 --- a/jim-array.c +++ b/jim-array.c @@ -1,4 +1,3 @@ - /* * Implements the array command for jim * @@ -157,8 +156,8 @@ static int array_cmd_stat(Jim_Interp *interp, int argc, Jim_Obj *const *argv) if (objPtr) { return Jim_DictInfo(interp, objPtr); } - Jim_SetResultFormatted(interp, "\"%#s\" isn't an array", argv[0], NULL); - return JIM_ERR; + Jim_SetResultFormatted(interp, "\"%#s\" isn't an array", argv[0], NULL); + return JIM_ERR; } static int array_cmd_set(Jim_Interp *interp, int argc, Jim_Obj *const *argv) @@ -1500,7 +1500,7 @@ JimStartWinProcess(Jim_Interp *interp, char **argv, char *env, fdtype inputId, f ZeroMemory(&startInfo, sizeof(startInfo)); startInfo.cb = sizeof(startInfo); startInfo.dwFlags = STARTF_USESTDHANDLES; - startInfo.hStdInput = INVALID_HANDLE_VALUE; + startInfo.hStdInput = INVALID_HANDLE_VALUE; startInfo.hStdOutput= INVALID_HANDLE_VALUE; startInfo.hStdError = INVALID_HANDLE_VALUE; diff --git a/jim-format.c b/jim-format.c index 7876d3e..b923456 100644 --- a/jim-format.c +++ b/jim-format.c @@ -59,10 +59,10 @@ Jim_Obj *Jim_FormatString(Jim_Interp *interp, Jim_Obj *fmtObjPtr, int objc, Jim_ const char *span, *format, *formatEnd, *msg; int numBytes = 0, objIndex = 0, gotXpg = 0, gotSequential = 0; static const char * const mixedXPG = - "cannot mix \"%\" and \"%n$\" conversion specifiers"; + "cannot mix \"%\" and \"%n$\" conversion specifiers"; static const char * const badIndex[2] = { - "not enough arguments for all format specifiers", - "\"%n$\" argument index out of range" + "not enough arguments for all format specifiers", + "\"%n$\" argument index out of range" }; int formatLen; Jim_Obj *resultPtr; @@ -78,382 +78,382 @@ Jim_Obj *Jim_FormatString(Jim_Interp *interp, Jim_Obj *fmtObjPtr, int objc, Jim_ resultPtr = Jim_NewEmptyStringObj(interp); while (format != formatEnd) { - char *end; - int gotMinus, sawFlag; - int gotPrecision, useShort; - long width, precision; - int newXpg; - int ch; - int step; - int doubleType; - char pad = ' '; - char spec[2*JIM_INTEGER_SPACE + 12]; - char *p; - - int formatted_chars; - int formatted_bytes; - const char *formatted_buf; - - step = utf8_tounicode(format, &ch); - format += step; - if (ch != '%') { - numBytes += step; - continue; - } - if (numBytes) { - Jim_AppendString(interp, resultPtr, span, numBytes); - numBytes = 0; - } - - /* - * Saw a % : process the format specifier. - * - * Step 0. Handle special case of escaped format marker (i.e., %%). - */ - - step = utf8_tounicode(format, &ch); - if (ch == '%') { - span = format; - numBytes = step; - format += step; - continue; - } - - /* - * Step 1. XPG3 position specifier - */ - - newXpg = 0; - if (isdigit(ch)) { - int position = strtoul(format, &end, 10); - if (*end == '$') { - newXpg = 1; - objIndex = position - 1; - format = end + 1; - step = utf8_tounicode(format, &ch); - } - } - if (newXpg) { - if (gotSequential) { - msg = mixedXPG; - goto errorMsg; - } - gotXpg = 1; - } else { - if (gotXpg) { - msg = mixedXPG; - goto errorMsg; - } - gotSequential = 1; - } - if ((objIndex < 0) || (objIndex >= objc)) { - msg = badIndex[gotXpg]; - goto errorMsg; - } - - /* - * Step 2. Set of flags. Also build up the sprintf spec. - */ - p = spec; - *p++ = '%'; - - gotMinus = 0; - sawFlag = 1; - do { - switch (ch) { - case '-': - gotMinus = 1; - break; - case '0': - pad = ch; - break; - case ' ': - case '+': - case '#': - break; - default: - sawFlag = 0; - continue; - } - *p++ = ch; - format += step; - step = utf8_tounicode(format, &ch); - } while (sawFlag); - - /* - * Step 3. Minimum field width. - */ - - width = 0; - if (isdigit(ch)) { - width = strtoul(format, &end, 10); - format = end; - step = utf8_tounicode(format, &ch); - } else if (ch == '*') { - if (objIndex >= objc - 1) { - msg = badIndex[gotXpg]; - goto errorMsg; - } - if (Jim_GetLong(interp, objv[objIndex], &width) != JIM_OK) { - goto error; - } - if (width < 0) { - width = -width; - if (!gotMinus) { - *p++ = '-'; - gotMinus = 1; - } - } - objIndex++; - format += step; - step = utf8_tounicode(format, &ch); - } - - /* - * Step 4. Precision. - */ - - gotPrecision = precision = 0; - if (ch == '.') { - gotPrecision = 1; - format += step; - step = utf8_tounicode(format, &ch); - } - if (isdigit(ch)) { - precision = strtoul(format, &end, 10); - format = end; - step = utf8_tounicode(format, &ch); - } else if (ch == '*') { - if (objIndex >= objc - 1) { - msg = badIndex[gotXpg]; - goto errorMsg; - } - if (Jim_GetLong(interp, objv[objIndex], &precision) != JIM_OK) { - goto error; - } - - /* - * TODO: Check this truncation logic. - */ - - if (precision < 0) { - precision = 0; - } - objIndex++; - format += step; - step = utf8_tounicode(format, &ch); - } - - /* - * Step 5. Length modifier. - */ - - useShort = 0; - if (ch == 'h') { - useShort = 1; - format += step; - step = utf8_tounicode(format, &ch); - } else if (ch == 'l') { - /* Just for compatibility. All non-short integers are wide. */ - format += step; - step = utf8_tounicode(format, &ch); - if (ch == 'l') { - format += step; - step = utf8_tounicode(format, &ch); - } - } - - format += step; - span = format; - - /* - * Step 6. The actual conversion character. - */ - - if (ch == 'i') { - ch = 'd'; - } - - doubleType = 0; - - /* Each valid conversion will set: - * formatted_buf - the result to be added - * formatted_chars - the length of formatted_buf in characters - * formatted_bytes - the length of formatted_buf in bytes - */ - switch (ch) { - case '\0': - msg = "format string ended in middle of field specifier"; - goto errorMsg; - case 's': { - formatted_buf = Jim_GetString(objv[objIndex], &formatted_bytes); - formatted_chars = Jim_Utf8Length(interp, objv[objIndex]); - if (gotPrecision && (precision < formatted_chars)) { - /* Need to build a (null terminated) truncated string */ - formatted_chars = precision; - formatted_bytes = utf8_index(formatted_buf, precision); - } - break; - } - case 'c': { - jim_wide code; - - if (Jim_GetWide(interp, objv[objIndex], &code) != JIM_OK) { - goto error; - } - /* Just store the value in the 'spec' buffer */ - formatted_bytes = utf8_getchars(spec, code); - formatted_buf = spec; - formatted_chars = 1; - break; - } - case 'b': { - unsigned jim_wide w; - int length; - int i; - int j; - - if (Jim_GetWide(interp, objv[objIndex], (jim_wide *)&w) != JIM_OK) { - goto error; - } - length = sizeof(w) * 8; - - /* XXX: width and precision not yet implemented for binary - * also flags in 'spec', e.g. #, 0, - - */ - - /* Increase the size of the buffer if needed */ - if (num_buffer_size < length + 1) { - num_buffer_size = length + 1; - num_buffer = Jim_Realloc(num_buffer, num_buffer_size); - } - - j = 0; - for (i = length; i > 0; ) { - i--; - if (w & ((unsigned jim_wide)1 << i)) { - num_buffer[j++] = '1'; - } - else if (j || i == 0) { - num_buffer[j++] = '0'; - } - } - num_buffer[j] = 0; - formatted_chars = formatted_bytes = j; - formatted_buf = num_buffer; - break; - } - - case 'e': - case 'E': - case 'f': - case 'g': - case 'G': - doubleType = 1; - /* fall through */ - case 'd': - case 'u': - case 'o': - case 'x': - case 'X': { - jim_wide w; - double d; - int length; - - /* Fill in the width and precision */ - if (width) { - p += sprintf(p, "%ld", width); - } - if (gotPrecision) { - p += sprintf(p, ".%ld", precision); - } - - /* Now the modifier, and get the actual value here */ - if (doubleType) { - if (Jim_GetDouble(interp, objv[objIndex], &d) != JIM_OK) { - goto error; - } - length = MAX_FLOAT_WIDTH; - } - else { - if (Jim_GetWide(interp, objv[objIndex], &w) != JIM_OK) { - goto error; - } - length = JIM_INTEGER_SPACE; - if (useShort) { - *p++ = 'h'; - if (ch == 'd') { - w = (short)w; - } - else { - w = (unsigned short)w; - } - } - else { - *p++ = 'l'; + char *end; + int gotMinus, sawFlag; + int gotPrecision, useShort; + long width, precision; + int newXpg; + int ch; + int step; + int doubleType; + char pad = ' '; + char spec[2*JIM_INTEGER_SPACE + 12]; + char *p; + + int formatted_chars; + int formatted_bytes; + const char *formatted_buf; + + step = utf8_tounicode(format, &ch); + format += step; + if (ch != '%') { + numBytes += step; + continue; + } + if (numBytes) { + Jim_AppendString(interp, resultPtr, span, numBytes); + numBytes = 0; + } + + /* + * Saw a % : process the format specifier. + * + * Step 0. Handle special case of escaped format marker (i.e., %%). + */ + + step = utf8_tounicode(format, &ch); + if (ch == '%') { + span = format; + numBytes = step; + format += step; + continue; + } + + /* + * Step 1. XPG3 position specifier + */ + + newXpg = 0; + if (isdigit(ch)) { + int position = strtoul(format, &end, 10); + if (*end == '$') { + newXpg = 1; + objIndex = position - 1; + format = end + 1; + step = utf8_tounicode(format, &ch); + } + } + if (newXpg) { + if (gotSequential) { + msg = mixedXPG; + goto errorMsg; + } + gotXpg = 1; + } else { + if (gotXpg) { + msg = mixedXPG; + goto errorMsg; + } + gotSequential = 1; + } + if ((objIndex < 0) || (objIndex >= objc)) { + msg = badIndex[gotXpg]; + goto errorMsg; + } + + /* + * Step 2. Set of flags. Also build up the sprintf spec. + */ + p = spec; + *p++ = '%'; + + gotMinus = 0; + sawFlag = 1; + do { + switch (ch) { + case '-': + gotMinus = 1; + break; + case '0': + pad = ch; + break; + case ' ': + case '+': + case '#': + break; + default: + sawFlag = 0; + continue; + } + *p++ = ch; + format += step; + step = utf8_tounicode(format, &ch); + } while (sawFlag); + + /* + * Step 3. Minimum field width. + */ + + width = 0; + if (isdigit(ch)) { + width = strtoul(format, &end, 10); + format = end; + step = utf8_tounicode(format, &ch); + } else if (ch == '*') { + if (objIndex >= objc - 1) { + msg = badIndex[gotXpg]; + goto errorMsg; + } + if (Jim_GetLong(interp, objv[objIndex], &width) != JIM_OK) { + goto error; + } + if (width < 0) { + width = -width; + if (!gotMinus) { + *p++ = '-'; + gotMinus = 1; + } + } + objIndex++; + format += step; + step = utf8_tounicode(format, &ch); + } + + /* + * Step 4. Precision. + */ + + gotPrecision = precision = 0; + if (ch == '.') { + gotPrecision = 1; + format += step; + step = utf8_tounicode(format, &ch); + } + if (isdigit(ch)) { + precision = strtoul(format, &end, 10); + format = end; + step = utf8_tounicode(format, &ch); + } else if (ch == '*') { + if (objIndex >= objc - 1) { + msg = badIndex[gotXpg]; + goto errorMsg; + } + if (Jim_GetLong(interp, objv[objIndex], &precision) != JIM_OK) { + goto error; + } + + /* + * TODO: Check this truncation logic. + */ + + if (precision < 0) { + precision = 0; + } + objIndex++; + format += step; + step = utf8_tounicode(format, &ch); + } + + /* + * Step 5. Length modifier. + */ + + useShort = 0; + if (ch == 'h') { + useShort = 1; + format += step; + step = utf8_tounicode(format, &ch); + } else if (ch == 'l') { + /* Just for compatibility. All non-short integers are wide. */ + format += step; + step = utf8_tounicode(format, &ch); + if (ch == 'l') { + format += step; + step = utf8_tounicode(format, &ch); + } + } + + format += step; + span = format; + + /* + * Step 6. The actual conversion character. + */ + + if (ch == 'i') { + ch = 'd'; + } + + doubleType = 0; + + /* Each valid conversion will set: + * formatted_buf - the result to be added + * formatted_chars - the length of formatted_buf in characters + * formatted_bytes - the length of formatted_buf in bytes + */ + switch (ch) { + case '\0': + msg = "format string ended in middle of field specifier"; + goto errorMsg; + case 's': { + formatted_buf = Jim_GetString(objv[objIndex], &formatted_bytes); + formatted_chars = Jim_Utf8Length(interp, objv[objIndex]); + if (gotPrecision && (precision < formatted_chars)) { + /* Need to build a (null terminated) truncated string */ + formatted_chars = precision; + formatted_bytes = utf8_index(formatted_buf, precision); + } + break; + } + case 'c': { + jim_wide code; + + if (Jim_GetWide(interp, objv[objIndex], &code) != JIM_OK) { + goto error; + } + /* Just store the value in the 'spec' buffer */ + formatted_bytes = utf8_getchars(spec, code); + formatted_buf = spec; + formatted_chars = 1; + break; + } + case 'b': { + unsigned jim_wide w; + int length; + int i; + int j; + + if (Jim_GetWide(interp, objv[objIndex], (jim_wide *)&w) != JIM_OK) { + goto error; + } + length = sizeof(w) * 8; + + /* XXX: width and precision not yet implemented for binary + * also flags in 'spec', e.g. #, 0, - + */ + + /* Increase the size of the buffer if needed */ + if (num_buffer_size < length + 1) { + num_buffer_size = length + 1; + num_buffer = Jim_Realloc(num_buffer, num_buffer_size); + } + + j = 0; + for (i = length; i > 0; ) { + i--; + if (w & ((unsigned jim_wide)1 << i)) { + num_buffer[j++] = '1'; + } + else if (j || i == 0) { + num_buffer[j++] = '0'; + } + } + num_buffer[j] = 0; + formatted_chars = formatted_bytes = j; + formatted_buf = num_buffer; + break; + } + + case 'e': + case 'E': + case 'f': + case 'g': + case 'G': + doubleType = 1; + /* fall through */ + case 'd': + case 'u': + case 'o': + case 'x': + case 'X': { + jim_wide w; + double d; + int length; + + /* Fill in the width and precision */ + if (width) { + p += sprintf(p, "%ld", width); + } + if (gotPrecision) { + p += sprintf(p, ".%ld", precision); + } + + /* Now the modifier, and get the actual value here */ + if (doubleType) { + if (Jim_GetDouble(interp, objv[objIndex], &d) != JIM_OK) { + goto error; + } + length = MAX_FLOAT_WIDTH; + } + else { + if (Jim_GetWide(interp, objv[objIndex], &w) != JIM_OK) { + goto error; + } + length = JIM_INTEGER_SPACE; + if (useShort) { + *p++ = 'h'; + if (ch == 'd') { + w = (short)w; + } + else { + w = (unsigned short)w; + } + } + else { + *p++ = 'l'; #ifdef HAVE_LONG_LONG - if (sizeof(long long) == sizeof(jim_wide)) { - *p++ = 'l'; - } + if (sizeof(long long) == sizeof(jim_wide)) { + *p++ = 'l'; + } #endif - } - } - - *p++ = (char) ch; - *p = '\0'; - - /* Adjust length for width and precision */ - if (width > length) { - length = width; - } - if (gotPrecision) { - length += precision; - } - - /* Increase the size of the buffer if needed */ - if (num_buffer_size < length + 1) { - num_buffer_size = length + 1; - num_buffer = Jim_Realloc(num_buffer, num_buffer_size); - } - - if (doubleType) { - snprintf(num_buffer, length + 1, spec, d); - } - else { - formatted_bytes = snprintf(num_buffer, length + 1, spec, w); - } - formatted_chars = formatted_bytes = strlen(num_buffer); - formatted_buf = num_buffer; - break; - } - - default: { - /* Just reuse the 'spec' buffer */ - spec[0] = ch; - spec[1] = '\0'; - Jim_SetResultFormatted(interp, "bad field specifier \"%s\"", spec); - goto error; - } - } - - if (!gotMinus) { - while (formatted_chars < width) { - Jim_AppendString(interp, resultPtr, &pad, 1); - formatted_chars++; - } - } - - Jim_AppendString(interp, resultPtr, formatted_buf, formatted_bytes); - - while (formatted_chars < width) { - Jim_AppendString(interp, resultPtr, &pad, 1); - formatted_chars++; - } - - objIndex += gotSequential; + } + } + + *p++ = (char) ch; + *p = '\0'; + + /* Adjust length for width and precision */ + if (width > length) { + length = width; + } + if (gotPrecision) { + length += precision; + } + + /* Increase the size of the buffer if needed */ + if (num_buffer_size < length + 1) { + num_buffer_size = length + 1; + num_buffer = Jim_Realloc(num_buffer, num_buffer_size); + } + + if (doubleType) { + snprintf(num_buffer, length + 1, spec, d); + } + else { + formatted_bytes = snprintf(num_buffer, length + 1, spec, w); + } + formatted_chars = formatted_bytes = strlen(num_buffer); + formatted_buf = num_buffer; + break; + } + + default: { + /* Just reuse the 'spec' buffer */ + spec[0] = ch; + spec[1] = '\0'; + Jim_SetResultFormatted(interp, "bad field specifier \"%s\"", spec); + goto error; + } + } + + if (!gotMinus) { + while (formatted_chars < width) { + Jim_AppendString(interp, resultPtr, &pad, 1); + formatted_chars++; + } + } + + Jim_AppendString(interp, resultPtr, formatted_buf, formatted_bytes); + + while (formatted_chars < width) { + Jim_AppendString(interp, resultPtr, &pad, 1); + formatted_chars++; + } + + objIndex += gotSequential; } if (numBytes) { - Jim_AppendString(interp, resultPtr, span, numBytes); + Jim_AppendString(interp, resultPtr, span, numBytes); } Jim_Free(num_buffer); diff --git a/jim-interactive.c b/jim-interactive.c index 60a5edc..17e43d2 100644 --- a/jim-interactive.c +++ b/jim-interactive.c @@ -19,7 +19,7 @@ char *Jim_HistoryGetline(const char *prompt) #ifdef USE_LINENOISE return linenoise(prompt); #else - int len; + int len; char *line = malloc(MAX_LINE_LEN); fputs(prompt, stdout); @@ -29,10 +29,10 @@ char *Jim_HistoryGetline(const char *prompt) free(line); return NULL; } - len = strlen(line); - if (len && line[len - 1] == '\n') { - line[len - 1] = '\0'; - } + len = strlen(line); + if (len && line[len - 1] == '\n') { + line[len - 1] = '\0'; + } return line; #endif } diff --git a/jim-namespace.c b/jim-namespace.c index fa2db54..61f608c 100644 --- a/jim-namespace.c +++ b/jim-namespace.c @@ -269,8 +269,8 @@ static int JimNamespaceCmd(Jim_Interp *interp, int argc, Jim_Obj *const *argv) Jim_SetResult(interp, Jim_NamespaceQualifiers(interp, argv[2])); return JIM_OK; - case OPT_IMPORT: - case OPT_EXPORT: + case OPT_IMPORT: + case OPT_EXPORT: return JIM_OK; case OPT_TAIL: @@ -1,4 +1,3 @@ - /* Jim - A small embeddable Tcl interpreter * * Copyright 2005 Salvatore Sanfilippo <antirez@invece.org> @@ -1662,10 +1661,10 @@ static int JimParseStr(struct JimParserCtx *pc) pc->p++; pc->len--; } - else if (pc->len == 1) { - /* End of script with trailing backslash */ - pc->missing = '\\'; - } + else if (pc->len == 1) { + /* End of script with trailing backslash */ + pc->missing = '\\'; + } break; case '(': /* If the following token is not '$' just keep going */ @@ -1727,21 +1726,21 @@ static int JimParseComment(struct JimParserCtx *pc) { while (*pc->p) { if (*pc->p == '\\') { - pc->p++; - pc->len--; - if (pc->len == 0) { - pc->missing = '\\'; - return JIM_OK; - } - if (*pc->p == '\n') { - pc->linenr++; - } - } - else if (*pc->p == '\n') { + pc->p++; + pc->len--; + if (pc->len == 0) { + pc->missing = '\\'; + return JIM_OK; + } + if (*pc->p == '\n') { + pc->linenr++; + } + } + else if (*pc->p == '\n') { pc->p++; pc->len--; pc->linenr++; - break; + break; } pc->p++; pc->len--; @@ -3566,7 +3565,7 @@ static int SetScriptFromAny(Jim_Interp *interp, struct Jim_Obj *objPtr, struct J ScriptAddToken(&tokenlist, parser.tstart, parser.tend - parser.tstart + 1, parser.tt, parser.tline); } - /* Note that we accept a trailing backslash without error */ + /* Note that we accept a trailing backslash without error */ if (result && parser.missing != ' ' && parser.missing != '\\') { ScriptTokenListFree(&tokenlist); result->missing = parser.missing; @@ -3716,18 +3715,18 @@ static Jim_Obj *JimQualifyNameObj(Jim_Interp *interp, Jim_Obj *nsObj) Jim_Obj *Jim_MakeGlobalNamespaceName(Jim_Interp *interp, Jim_Obj *nameObjPtr) { - Jim_Obj *resultObj; + Jim_Obj *resultObj; const char *name = Jim_String(nameObjPtr); if (name[0] == ':' && name[1] == ':') { - return nameObjPtr; - } - Jim_IncrRefCount(nameObjPtr); - resultObj = Jim_NewStringObj(interp, "::", -1); - Jim_AppendObj(interp, resultObj, nameObjPtr); - Jim_DecrRefCount(interp, nameObjPtr); + return nameObjPtr; + } + Jim_IncrRefCount(nameObjPtr); + resultObj = Jim_NewStringObj(interp, "::", -1); + Jim_AppendObj(interp, resultObj, nameObjPtr); + Jim_DecrRefCount(interp, nameObjPtr); - return resultObj; + return resultObj; } /** @@ -3765,7 +3764,7 @@ static const char *JimQualifyName(Jim_Interp *interp, const char *name, Jim_Obj Jim_Obj *Jim_MakeGlobalNamespaceName(Jim_Interp *interp, Jim_Obj *nameObjPtr) { - return nameObjPtr; + return nameObjPtr; } #endif @@ -4092,17 +4091,17 @@ static const Jim_ObjType commandObjType = { Jim_Cmd *Jim_GetCommand(Jim_Interp *interp, Jim_Obj *objPtr, int flags) { Jim_Cmd *cmd; - Jim_Obj *nsObj; - - /* one-off special name resolution */ - if (interp->resolveNsObj) { - nsObj = interp->resolveNsObj; - interp->resolveNsObj = NULL; - } - else { - nsObj = interp->framePtr->nsObj; - } - Jim_IncrRefCount(nsObj); + Jim_Obj *nsObj; + + /* one-off special name resolution */ + if (interp->resolveNsObj) { + nsObj = interp->resolveNsObj; + interp->resolveNsObj = NULL; + } + else { + nsObj = interp->framePtr->nsObj; + } + Jim_IncrRefCount(nsObj); /* In order to be valid, the proc epoch must match and * the lookup must have occurred in the same namespace @@ -4142,8 +4141,8 @@ Jim_Cmd *Jim_GetCommand(Jim_Interp *interp, Jim_Obj *objPtr, int flags) if (flags & JIM_ERRMSG) { Jim_SetResultFormatted(interp, "invalid command name \"%#s\"", objPtr); } - cmd = NULL; - goto out; + cmd = NULL; + goto out; } #ifdef jim_ext_namespace found: @@ -4165,7 +4164,7 @@ found: cmd = cmd->prevCmd; } out: - Jim_DecrRefCount(interp, nsObj); + Jim_DecrRefCount(interp, nsObj); return cmd; } @@ -6422,7 +6421,7 @@ struct lsort_info { int order; int index; int indexed; - int unique; + int unique; int (*subfn)(Jim_Obj **, Jim_Obj **); }; @@ -6470,13 +6469,13 @@ static int ListSortReal(Jim_Obj **lhsObj, Jim_Obj **rhsObj) Jim_GetDouble(sort_info->interp, *rhsObj, &rhs) != JIM_OK) { longjmp(sort_info->jmpbuf, JIM_ERR); } - if (lhs == rhs) { - return 0; - } - if (lhs > rhs) { - return sort_info->order; - } - return -sort_info->order; + if (lhs == rhs) { + return 0; + } + if (lhs > rhs) { + return sort_info->order; + } + return -sort_info->order; } static int ListSortCommand(Jim_Obj **lhsObj, Jim_Obj **rhsObj) @@ -6507,26 +6506,26 @@ static int ListSortCommand(Jim_Obj **lhsObj, Jim_Obj **rhsObj) */ static void ListRemoveDuplicates(Jim_Obj *listObjPtr, int (*comp)(Jim_Obj **lhs, Jim_Obj **rhs)) { - int src; - int dst = 0; - Jim_Obj **ele = listObjPtr->internalRep.listValue.ele; + int src; + int dst = 0; + Jim_Obj **ele = listObjPtr->internalRep.listValue.ele; - for (src = 1; src < listObjPtr->internalRep.listValue.len; src++) { - if (comp(&ele[dst], &ele[src]) == 0) { - /* Match, so replace the dest with the current source */ - Jim_DecrRefCount(sort_info->interp, ele[dst]); - } - else { - /* No match, so keep the current source and move to the next destination */ - dst++; - } - ele[dst] = ele[src]; - } - /* At end of list, keep the final element */ - ele[++dst] = ele[src]; + for (src = 1; src < listObjPtr->internalRep.listValue.len; src++) { + if (comp(&ele[dst], &ele[src]) == 0) { + /* Match, so replace the dest with the current source */ + Jim_DecrRefCount(sort_info->interp, ele[dst]); + } + else { + /* No match, so keep the current source and move to the next destination */ + dst++; + } + ele[dst] = ele[src]; + } + /* At end of list, keep the final element */ + ele[++dst] = ele[src]; - /* Set the new length */ - listObjPtr->internalRep.listValue.len = dst; + /* Set the new length */ + listObjPtr->internalRep.listValue.len = dst; } /* Sort a list *in place*. MUST be called with non-shared objects. */ @@ -6579,12 +6578,12 @@ static int ListSortElements(Jim_Interp *interp, Jim_Obj *listObjPtr, struct lsor if ((rc = setjmp(info->jmpbuf)) == 0) { qsort(vector, len, sizeof(Jim_Obj *), (qsort_comparator *) fn); - if (info->unique && len > 1) { - ListRemoveDuplicates(listObjPtr, fn); - } + if (info->unique && len > 1) { + ListRemoveDuplicates(listObjPtr, fn); + } - Jim_InvalidateStringRep(listObjPtr); - } + Jim_InvalidateStringRep(listObjPtr); + } sort_info = prev_info; return rc; @@ -10866,36 +10865,36 @@ static int JimCallProcedure(Jim_Interp *interp, Jim_Cmd *cmd, int argc, Jim_Obj badargset: - interp->framePtr = interp->framePtr->parent; + interp->framePtr = interp->framePtr->parent; - /* Handle the JIM_EVAL return code */ + /* Handle the JIM_EVAL return code */ if (retcode == JIM_EVAL) { - /* We need to do resolution of the tailcall command - * (i.e. the very next command resolution) - * in the current namespace, but everything after that needs - * to be done in the normal namespace. - */ - interp->resolveNsObj = callFramePtr->nsObj; - - do { - Jim_Obj *resultScriptObjPtr = Jim_GetResult(interp); - - Jim_IncrRefCount(resultScriptObjPtr); - /* Result must be a list */ - JimPanic((!Jim_IsList(resultScriptObjPtr), "tailcall (JIM_EVAL) returned non-list")); - - retcode = JimEvalObjList(interp, resultScriptObjPtr); - if (retcode == JIM_RETURN) { - /* If the result of the tailcall invokes 'return', push - * it up to the caller - */ - interp->returnLevel++; - } - Jim_DecrRefCount(interp, resultScriptObjPtr); - } while (retcode == JIM_EVAL); - } - - /* Need to do this after tailcall in case of tailcall to a local proc */ + /* We need to do resolution of the tailcall command + * (i.e. the very next command resolution) + * in the current namespace, but everything after that needs + * to be done in the normal namespace. + */ + interp->resolveNsObj = callFramePtr->nsObj; + + do { + Jim_Obj *resultScriptObjPtr = Jim_GetResult(interp); + + Jim_IncrRefCount(resultScriptObjPtr); + /* Result must be a list */ + JimPanic((!Jim_IsList(resultScriptObjPtr), "tailcall (JIM_EVAL) returned non-list")); + + retcode = JimEvalObjList(interp, resultScriptObjPtr); + if (retcode == JIM_RETURN) { + /* If the result of the tailcall invokes 'return', push + * it up to the caller + */ + interp->returnLevel++; + } + Jim_DecrRefCount(interp, resultScriptObjPtr); + } while (retcode == JIM_EVAL); + } + + /* Need to do this after tailcall in case of tailcall to a local proc */ if (callFramePtr->vars.size != JIM_HT_INITIAL_SIZE) { JimFreeCallFrame(interp, callFramePtr, JIM_FCF_NONE); } @@ -11225,7 +11224,7 @@ void Jim_WrongNumArgs(Jim_Interp *interp, int argc, Jim_Obj *const *argv, const typedef void JimHashtableIteratorCallbackType(Jim_Interp *interp, Jim_Obj *listObjPtr, Jim_HashEntry *he, int type); -#define JimTrivialMatch(pattern) (strpbrk((pattern), "*[?\\") == NULL) +#define JimTrivialMatch(pattern) (strpbrk((pattern), "*[?\\") == NULL) /** * For each key of the hash table 'ht' (with string keys) which matches the glob pattern (all if NULL), @@ -13876,8 +13875,8 @@ static int Jim_CatchCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *ar } else { exitCode = Jim_EvalObj(interp, argv[0]); - /* Don't want any caught error included in a later stack trace */ - interp->errorFlag = 0; + /* Don't want any caught error included in a later stack trace */ + interp->errorFlag = 0; } interp->signal_level -= sig; @@ -14124,32 +14123,32 @@ int Jim_DictSize(Jim_Interp *interp, Jim_Obj *objPtr) int Jim_DictInfo(Jim_Interp *interp, Jim_Obj *objPtr) { - Jim_HashTable *ht; + Jim_HashTable *ht; unsigned int i; if (SetDictFromAny(interp, objPtr) != JIM_OK) { return JIM_ERR; } - ht = (Jim_HashTable *)objPtr->internalRep.ptr; + ht = (Jim_HashTable *)objPtr->internalRep.ptr; - /* Note that this uses internal knowledge of the hash table */ - printf("%d entries in table, %d buckets\n", ht->used, ht->size); + /* Note that this uses internal knowledge of the hash table */ + printf("%d entries in table, %d buckets\n", ht->used, ht->size); for (i = 0; i < ht->size; i++) { Jim_HashEntry *he = he = ht->table[i]; - if (he) { - printf("%d: ", i); + if (he) { + printf("%d: ", i); - while (he) { - printf(" %s", Jim_String(he->key)); - he = he->next; - } - printf("\n"); - } + while (he) { + printf(" %s", Jim_String(he->key)); + he = he->next; + } + printf("\n"); + } } - return JIM_OK; + return JIM_OK; } static int Jim_EvalEnsemble(Jim_Interp *interp, const char *basecmd, const char *subcmd, int argc, Jim_Obj *const *argv) @@ -14281,7 +14280,7 @@ static int Jim_DictCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *arg Jim_WrongNumArgs(interp, 2, argv, "dictionary"); return JIM_ERR; } - return Jim_DictInfo(interp, argv[2]); + return Jim_DictInfo(interp, argv[2]); } /* Handle command as an ensemble */ return Jim_EvalEnsemble(interp, "dict", options[option], argc - 2, argv + 2); |