| | @@ -2597,11 +2597,11 @@ |
| 2597 | 2597 | |
| 2598 | 2598 | static int aio_cmd_buffering(Jim_Interp *interp, int argc, Jim_Obj *const *argv) |
| 2599 | 2599 | { |
| 2600 | 2600 | AioFile *af = Jim_CmdPrivData(interp); |
| 2601 | 2601 | |
| 2602 | | - static const char *options[] = { |
| 2602 | + static const char * const options[] = { |
| 2603 | 2603 | "none", |
| 2604 | 2604 | "line", |
| 2605 | 2605 | "full", |
| 2606 | 2606 | NULL |
| 2607 | 2607 | }; |
| | @@ -5156,17 +5156,17 @@ |
| 5156 | 5156 | return result; |
| 5157 | 5157 | } |
| 5158 | 5158 | |
| 5159 | 5159 | void Jim_ReapDetachedPids(struct WaitInfoTable *table) |
| 5160 | 5160 | { |
| 5161 | + struct WaitInfo *waitPtr; |
| 5162 | + int count; |
| 5163 | + |
| 5161 | 5164 | if (!table) { |
| 5162 | 5165 | return; |
| 5163 | 5166 | } |
| 5164 | 5167 | |
| 5165 | | - struct WaitInfo *waitPtr; |
| 5166 | | - int count; |
| 5167 | | - |
| 5168 | 5168 | for (waitPtr = table->info, count = table->used; count > 0; waitPtr++, count--) { |
| 5169 | 5169 | if (waitPtr->flags & WI_DETACHED) { |
| 5170 | 5170 | int status; |
| 5171 | 5171 | int pid = waitpid(waitPtr->pid, &status, WNOHANG); |
| 5172 | 5172 | if (pid > 0) { |
| | @@ -6365,30 +6365,30 @@ |
| 6365 | 6365 | return JIM_OK; |
| 6366 | 6366 | } |
| 6367 | 6367 | int Jim_InitStaticExtensions(Jim_Interp *interp) |
| 6368 | 6368 | { |
| 6369 | 6369 | extern int Jim_bootstrapInit(Jim_Interp *); |
| 6370 | | -Jim_bootstrapInit(interp); |
| 6371 | 6370 | extern int Jim_aioInit(Jim_Interp *); |
| 6372 | | -Jim_aioInit(interp); |
| 6373 | 6371 | extern int Jim_readdirInit(Jim_Interp *); |
| 6374 | | -Jim_readdirInit(interp); |
| 6375 | 6372 | extern int Jim_globInit(Jim_Interp *); |
| 6376 | | -Jim_globInit(interp); |
| 6377 | 6373 | extern int Jim_regexpInit(Jim_Interp *); |
| 6378 | | -Jim_regexpInit(interp); |
| 6379 | 6374 | extern int Jim_fileInit(Jim_Interp *); |
| 6375 | +extern int Jim_execInit(Jim_Interp *); |
| 6376 | +extern int Jim_clockInit(Jim_Interp *); |
| 6377 | +extern int Jim_arrayInit(Jim_Interp *); |
| 6378 | +extern int Jim_stdlibInit(Jim_Interp *); |
| 6379 | +extern int Jim_tclcompatInit(Jim_Interp *); |
| 6380 | +Jim_bootstrapInit(interp); |
| 6381 | +Jim_aioInit(interp); |
| 6382 | +Jim_readdirInit(interp); |
| 6383 | +Jim_globInit(interp); |
| 6384 | +Jim_regexpInit(interp); |
| 6380 | 6385 | Jim_fileInit(interp); |
| 6381 | | -extern int Jim_execInit(Jim_Interp *); |
| 6382 | 6386 | Jim_execInit(interp); |
| 6383 | | -extern int Jim_clockInit(Jim_Interp *); |
| 6384 | 6387 | Jim_clockInit(interp); |
| 6385 | | -extern int Jim_arrayInit(Jim_Interp *); |
| 6386 | 6388 | Jim_arrayInit(interp); |
| 6387 | | -extern int Jim_stdlibInit(Jim_Interp *); |
| 6388 | 6389 | Jim_stdlibInit(interp); |
| 6389 | | -extern int Jim_tclcompatInit(Jim_Interp *); |
| 6390 | 6390 | Jim_tclcompatInit(interp); |
| 6391 | 6391 | return JIM_OK; |
| 6392 | 6392 | } |
| 6393 | 6393 | |
| 6394 | 6394 | /* Jim - A small embeddable Tcl interpreter |
| | @@ -16669,15 +16669,16 @@ |
| 16669 | 16669 | i = 1; |
| 16670 | 16670 | for (d = 0; d < cmd->u.proc.argListLen; d++) { |
| 16671 | 16671 | Jim_Obj *nameObjPtr = cmd->u.proc.arglist[d].nameObjPtr; |
| 16672 | 16672 | if (d == cmd->u.proc.argsPos) { |
| 16673 | 16673 | /* assign $args */ |
| 16674 | + Jim_Obj *listObjPtr; |
| 16674 | 16675 | int argsLen = 0; |
| 16675 | 16676 | if (cmd->u.proc.reqArity + cmd->u.proc.optArity < argc - 1) { |
| 16676 | 16677 | argsLen = argc - 1 - (cmd->u.proc.reqArity + cmd->u.proc.optArity); |
| 16677 | 16678 | } |
| 16678 | | - Jim_Obj *listObjPtr = Jim_NewListObj(interp, &argv[i], argsLen); |
| 16679 | + listObjPtr = Jim_NewListObj(interp, &argv[i], argsLen); |
| 16679 | 16680 | |
| 16680 | 16681 | /* It is possible to rename args. */ |
| 16681 | 16682 | if (cmd->u.proc.arglist[d].defaultObjPtr) { |
| 16682 | 16683 | nameObjPtr =cmd->u.proc.arglist[d].defaultObjPtr; |
| 16683 | 16684 | } |
| | @@ -16813,11 +16814,10 @@ |
| 16813 | 16814 | { |
| 16814 | 16815 | FILE *fp; |
| 16815 | 16816 | char *buf; |
| 16816 | 16817 | Jim_Obj *scriptObjPtr; |
| 16817 | 16818 | Jim_Obj *prevScriptObj; |
| 16818 | | - Jim_Stack *prevLocalProcs; |
| 16819 | 16819 | struct stat sb; |
| 16820 | 16820 | int retcode; |
| 16821 | 16821 | int readlen; |
| 16822 | 16822 | struct JimParseResult result; |
| 16823 | 16823 | |
| | @@ -16872,20 +16872,12 @@ |
| 16872 | 16872 | } |
| 16873 | 16873 | |
| 16874 | 16874 | prevScriptObj = interp->currentScriptObj; |
| 16875 | 16875 | interp->currentScriptObj = scriptObjPtr; |
| 16876 | 16876 | |
| 16877 | | - /* Install a new stack for local procs */ |
| 16878 | | - prevLocalProcs = interp->localProcs; |
| 16879 | | - interp->localProcs = NULL; |
| 16880 | | - |
| 16881 | 16877 | retcode = Jim_EvalObj(interp, scriptObjPtr); |
| 16882 | 16878 | |
| 16883 | | - /* Delete any local procs */ |
| 16884 | | - JimDeleteLocalProcs(interp); |
| 16885 | | - interp->localProcs = prevLocalProcs; |
| 16886 | | - |
| 16887 | 16879 | /* Handle the JIM_RETURN return code */ |
| 16888 | 16880 | if (retcode == JIM_RETURN) { |
| 16889 | 16881 | if (--interp->returnLevel <= 0) { |
| 16890 | 16882 | retcode = interp->returnCode; |
| 16891 | 16883 | interp->returnCode = JIM_OK; |
| | @@ -18366,11 +18358,11 @@ |
| 18366 | 18358 | } |
| 18367 | 18359 | |
| 18368 | 18360 | /* [lsort] */ |
| 18369 | 18361 | static int Jim_LsortCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const argv[]) |
| 18370 | 18362 | { |
| 18371 | | - const char *options[] = { |
| 18363 | + static const char * const options[] = { |
| 18372 | 18364 | "-ascii", "-nocase", "-increasing", "-decreasing", "-command", "-integer", "-index", NULL |
| 18373 | 18365 | }; |
| 18374 | 18366 | enum |
| 18375 | 18367 | { OPT_ASCII, OPT_NOCASE, OPT_INCREASING, OPT_DECREASING, OPT_COMMAND, OPT_INTEGER, OPT_INDEX }; |
| 18376 | 18368 | Jim_Obj *resObj; |
| | @@ -18488,11 +18480,11 @@ |
| 18488 | 18480 | |
| 18489 | 18481 | /* [debug] */ |
| 18490 | 18482 | static int Jim_DebugCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv) |
| 18491 | 18483 | { |
| 18492 | 18484 | #ifdef JIM_DEBUG_COMMAND |
| 18493 | | - const char *options[] = { |
| 18485 | + static const char * const options[] = { |
| 18494 | 18486 | "refcount", "objcount", "objects", "invstr", "scriptlen", "exprlen", |
| 18495 | 18487 | "exprbc", "show", |
| 18496 | 18488 | NULL |
| 18497 | 18489 | }; |
| 18498 | 18490 | enum |
| | @@ -18693,32 +18685,23 @@ |
| 18693 | 18685 | |
| 18694 | 18686 | /* [eval] */ |
| 18695 | 18687 | static int Jim_EvalCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv) |
| 18696 | 18688 | { |
| 18697 | 18689 | int rc; |
| 18698 | | - Jim_Stack *prevLocalProcs; |
| 18699 | 18690 | |
| 18700 | 18691 | if (argc < 2) { |
| 18701 | 18692 | Jim_WrongNumArgs(interp, 1, argv, "script ?...?"); |
| 18702 | 18693 | return JIM_ERR; |
| 18703 | 18694 | } |
| 18704 | 18695 | |
| 18705 | | - /* Install a new stack for local procs */ |
| 18706 | | - prevLocalProcs = interp->localProcs; |
| 18707 | | - interp->localProcs = NULL; |
| 18708 | | - |
| 18709 | 18696 | if (argc == 2) { |
| 18710 | 18697 | rc = Jim_EvalObj(interp, argv[1]); |
| 18711 | 18698 | } |
| 18712 | 18699 | else { |
| 18713 | 18700 | rc = Jim_EvalObj(interp, Jim_ConcatObj(interp, argc - 1, argv + 1)); |
| 18714 | 18701 | } |
| 18715 | 18702 | |
| 18716 | | - /* Delete any local procs */ |
| 18717 | | - JimDeleteLocalProcs(interp); |
| 18718 | | - interp->localProcs = prevLocalProcs; |
| 18719 | | - |
| 18720 | 18703 | if (rc == JIM_ERR) { |
| 18721 | 18704 | /* eval is "interesting", so add a stack frame here */ |
| 18722 | 18705 | interp->addStackTrace++; |
| 18723 | 18706 | } |
| 18724 | 18707 | return rc; |
| | @@ -19504,12 +19487,12 @@ |
| 19504 | 19487 | else { |
| 19505 | 19488 | exitCode = Jim_EvalObj(interp, argv[0]); |
| 19506 | 19489 | } |
| 19507 | 19490 | interp->signal_level -= sig; |
| 19508 | 19491 | |
| 19509 | | - /* Catch or pass through? Only the first 64 codes can be passed through */ |
| 19510 | | - if (exitCode >= 0 && exitCode < (int)sizeof(mask) && ((1 << exitCode) & mask) == 0) { |
| 19492 | + /* Catch or pass through? Only the first 32/64 codes can be passed through */ |
| 19493 | + if (exitCode >= 0 && exitCode < (int)sizeof(mask) * 8 && ((1 << exitCode) & mask) == 0) { |
| 19511 | 19494 | /* Not caught, pass it up */ |
| 19512 | 19495 | return exitCode; |
| 19513 | 19496 | } |
| 19514 | 19497 | |
| 19515 | 19498 | if (sig && exitCode == JIM_SIGNAL) { |
| | @@ -19736,11 +19719,11 @@ |
| 19736 | 19719 | /* [dict] */ |
| 19737 | 19720 | static int Jim_DictCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv) |
| 19738 | 19721 | { |
| 19739 | 19722 | Jim_Obj *objPtr; |
| 19740 | 19723 | int option; |
| 19741 | | - const char *options[] = { |
| 19724 | + static const char * const options[] = { |
| 19742 | 19725 | "create", "get", "set", "unset", "exists", "keys", "merge", "size", "with", NULL |
| 19743 | 19726 | }; |
| 19744 | 19727 | enum |
| 19745 | 19728 | { |
| 19746 | 19729 | OPT_CREATE, OPT_GET, OPT_SET, OPT_UNSET, OPT_EXIST, OPT_KEYS, OPT_MERGE, OPT_SIZE, OPT_WITH, |
| | @@ -19852,11 +19835,11 @@ |
| 19852 | 19835 | } |
| 19853 | 19836 | |
| 19854 | 19837 | /* [subst] */ |
| 19855 | 19838 | static int Jim_SubstCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv) |
| 19856 | 19839 | { |
| 19857 | | - const char *options[] = { |
| 19840 | + static const char * const options[] = { |
| 19858 | 19841 | "-nobackslashes", "-nocommands", "-novariables", NULL |
| 19859 | 19842 | }; |
| 19860 | 19843 | enum |
| 19861 | 19844 | { OPT_NOBACKSLASHES, OPT_NOCOMMANDS, OPT_NOVARIABLES }; |
| 19862 | 19845 | int i; |
| | @@ -21399,10 +21382,11 @@ |
| 21399 | 21382 | #endif |
| 21400 | 21383 | #include <errno.h> |
| 21401 | 21384 | #include <string.h> |
| 21402 | 21385 | |
| 21403 | 21386 | #ifdef USE_LINENOISE |
| 21387 | +#include <unistd.h> |
| 21404 | 21388 | #include "linenoise.h" |
| 21405 | 21389 | #else |
| 21406 | 21390 | |
| 21407 | 21391 | #define MAX_LINE_LEN 512 |
| 21408 | 21392 | |
| | @@ -21427,11 +21411,11 @@ |
| 21427 | 21411 | char *history_file = NULL; |
| 21428 | 21412 | #ifdef USE_LINENOISE |
| 21429 | 21413 | const char *home; |
| 21430 | 21414 | |
| 21431 | 21415 | home = getenv("HOME"); |
| 21432 | | - if (home) { |
| 21416 | + if (home && isatty(STDIN_FILENO)) { |
| 21433 | 21417 | int history_len = strlen(home) + sizeof("/.jim_history"); |
| 21434 | 21418 | history_file = Jim_Alloc(history_len); |
| 21435 | 21419 | snprintf(history_file, history_len, "%s/.jim_history", home); |
| 21436 | 21420 | linenoiseHistoryLoad(history_file); |
| 21437 | 21421 | } |
| | @@ -21504,11 +21488,13 @@ |
| 21504 | 21488 | Jim_DecrRefCount(interp, scriptObjPtr); |
| 21505 | 21489 | continue; |
| 21506 | 21490 | } |
| 21507 | 21491 | |
| 21508 | 21492 | linenoiseHistoryAdd(Jim_String(scriptObjPtr)); |
| 21509 | | - linenoiseHistorySave(history_file); |
| 21493 | + if (history_file) { |
| 21494 | + linenoiseHistorySave(history_file); |
| 21495 | + } |
| 21510 | 21496 | #endif |
| 21511 | 21497 | retcode = Jim_EvalObj(interp, scriptObjPtr); |
| 21512 | 21498 | Jim_DecrRefCount(interp, scriptObjPtr); |
| 21513 | 21499 | |
| 21514 | 21500 | |
| 21515 | 21501 | |