From 33b89bc394f561268e414d71b64e920110a0f2b8 Mon Sep 17 00:00:00 2001 From: Dmitry Volyntsev Date: Thu, 28 Feb 2019 15:32:15 +0300 Subject: [PATCH] Shell: passing original filename to parser. --- njs/njs_shell.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/njs/njs_shell.c b/njs/njs_shell.c index ea9f8cf1..e23bdfb9 100644 --- a/njs/njs_shell.c +++ b/njs/njs_shell.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -195,6 +196,7 @@ static njs_console_t njs_console; int main(int argc, char **argv) { + char path[MAXPATHLEN], *p; nxt_int_t ret; njs_opts_t opts; njs_vm_opt_t vm_options; @@ -215,14 +217,19 @@ main(int argc, char **argv) nxt_memzero(&vm_options, sizeof(njs_vm_opt_t)); if (!opts.quiet) { - if (opts.file != NULL) { - vm_options.file.start = (u_char *) opts.file; - vm_options.file.length = strlen(opts.file); - nxt_file_basename(&vm_options.file, &vm_options.file); + if (opts.file == NULL) { + p = getcwd(path, sizeof(path)); + if (p == NULL) { + fprintf(stderr, "getcwd() failed:%s\n", strerror(errno)); + return EXIT_FAILURE; + } - } else { - vm_options.file = nxt_string_value("shell"); + memcpy(path + strlen(path), "/shell", sizeof("/shell")); + opts.file = path; } + + vm_options.file.start = (u_char *) opts.file; + vm_options.file.length = strlen(opts.file); } vm_options.init = !opts.interactive; -- 2.47.3