diff options
author | Steve Bennett <steveb@workware.net.au> | 2016-09-14 13:21:09 +1000 |
---|---|---|
committer | Steve Bennett <steveb@workware.net.au> | 2016-09-29 08:13:24 +1000 |
commit | 2b7bbc93323cc1ef9d67625e48b0435e1af4efbd (patch) | |
tree | 5aec44b2e6e7018b65f086835a59fa079c090da0 /jimsh.c | |
parent | d69d5e6674fd2e9b7d16ba2ca77cd1bb0109a223 (diff) | |
download | jimtcl-2b7bbc93323cc1ef9d67625e48b0435e1af4efbd.zip jimtcl-2b7bbc93323cc1ef9d67625e48b0435e1af4efbd.tar.gz jimtcl-2b7bbc93323cc1ef9d67625e48b0435e1af4efbd.tar.bz2 |
jimsh: add support for "jimsh -"
A convenience for evaluating a script on stdin without interactive mode
Signed-off-by: Steve Bennett <steveb@workware.net.au>
Diffstat (limited to 'jimsh.c')
-rw-r--r-- | jimsh.c | 18 |
1 files changed, 11 insertions, 7 deletions
@@ -74,12 +74,12 @@ void usage(const char* executable_name) printf("Without options: Interactive mode\n"); printf("\n"); printf("Options:\n"); - printf(" --version : prints the version string\n"); - printf(" --help : prints this text\n"); - printf(" -e CMD : executes command CMD\n"); - printf(" NOTE: all subsequent options will be passed as arguments to the command\n"); - printf(" [filename] : executes the script contained in the named file\n"); - printf(" NOTE: all subsequent options will be passed to the script\n\n"); + printf(" --version : prints the version string\n"); + printf(" --help : prints this text\n"); + printf(" -e CMD : executes command CMD\n"); + printf(" NOTE: all subsequent options will be passed as arguments to the command\n"); + printf(" [filename|-] : executes the script contained in the named file, or from stdin if \"-\"\n"); + printf(" NOTE: all subsequent options will be passed to the script\n\n"); } int main(int argc, char *const argv[]) @@ -134,7 +134,11 @@ int main(int argc, char *const argv[]) else { Jim_SetVariableStr(interp, "argv0", Jim_NewStringObj(interp, argv[1], -1)); JimSetArgv(interp, argc - 2, argv + 2); - retcode = Jim_EvalFile(interp, argv[1]); + if (strcmp(argv[1], "-") == 0) { + retcode = Jim_Eval(interp, "eval [info source [stdin read] stdin 1]"); + } else { + retcode = Jim_EvalFile(interp, argv[1]); + } } if (retcode == JIM_ERR) { JimPrintErrorMessage(interp); |