From 2b7bbc93323cc1ef9d67625e48b0435e1af4efbd Mon Sep 17 00:00:00 2001 From: Steve Bennett Date: Wed, 14 Sep 2016 13:21:09 +1000 Subject: jimsh: add support for "jimsh -" A convenience for evaluating a script on stdin without interactive mode Signed-off-by: Steve Bennett --- jimsh.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'jimsh.c') diff --git a/jimsh.c b/jimsh.c index afcd7dd..1a334a2 100644 --- a/jimsh.c +++ b/jimsh.c @@ -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); -- cgit v1.1