[njs] Shell: sorting arguments in alphabetic order.
Dmitry Volyntsev
xeioex at nginx.com
Tue May 7 16:50:59 UTC 2019
details: https://hg.nginx.org/njs/rev/6adf4063e1bb
branches:
changeset: 955:6adf4063e1bb
user: Dmitry Volyntsev <xeioex at nginx.com>
date: Tue May 07 19:50:38 2019 +0300
description:
Shell: sorting arguments in alphabetic order.
diffstat:
njs/njs_shell.c | 50 +++++++++++++++++-----------------
njs/test/njs_expect_test.exp | 63 +++++++++++++++++++++++--------------------
2 files changed, 58 insertions(+), 55 deletions(-)
diffs (171 lines):
diff -r a7a632e7d686 -r 6adf4063e1bb njs/njs_shell.c
--- a/njs/njs_shell.c Tue May 07 19:50:35 2019 +0300
+++ b/njs/njs_shell.c Tue May 07 19:50:38 2019 +0300
@@ -30,15 +30,16 @@
typedef struct {
+ uint8_t disassemble;
+ uint8_t interactive;
+ uint8_t module;
+ uint8_t quiet;
+ uint8_t sandbox;
+ uint8_t version;
+
char *file;
size_t n_paths;
char **paths;
- nxt_int_t version;
- nxt_int_t disassemble;
- nxt_int_t interactive;
- nxt_int_t sandbox;
- nxt_int_t quiet;
- nxt_int_t module;
} njs_opts_t;
@@ -284,10 +285,10 @@ njs_get_options(njs_opts_t *opts, int ar
"\n"
"Options:\n"
" -d print disassembled code.\n"
+ " -p set path prefix for modules.\n"
" -q disable interactive introduction prompt.\n"
" -s sandbox mode.\n"
" -t script|module source code type (script is default).\n"
- " -p set path prefix for modules.\n"
" -v print njs version and exit.\n"
" <filename> | - run code from a file or stdin.\n";
@@ -315,6 +316,23 @@ njs_get_options(njs_opts_t *opts, int ar
opts->disassemble = 1;
break;
+ case 'p':
+ if (++i < argc) {
+ opts->n_paths++;
+ paths = realloc(opts->paths, opts->n_paths * sizeof(char *));
+ if (paths == NULL) {
+ nxt_error("failed to add path\n");
+ return NXT_ERROR;
+ }
+
+ opts->paths = paths;
+ opts->paths[opts->n_paths - 1] = argv[i];
+ break;
+ }
+
+ nxt_error("option \"-p\" requires directory name\n");
+ return NXT_ERROR;
+
case 'q':
opts->quiet = 1;
break;
@@ -339,24 +357,6 @@ njs_get_options(njs_opts_t *opts, int ar
nxt_error("option \"-t\" requires source type\n");
return NXT_ERROR;
-
- case 'p':
- if (++i < argc) {
- opts->n_paths++;
- paths = realloc(opts->paths, opts->n_paths * sizeof(char *));
- if (paths == NULL) {
- nxt_error("failed to add path\n");
- return NXT_ERROR;
- }
-
- opts->paths = paths;
- opts->paths[opts->n_paths - 1] = argv[i];
- break;
- }
-
- nxt_error("option \"-p\" requires directory name\n");
- return NXT_ERROR;
-
case 'v':
case 'V':
opts->version = 1;
diff -r a7a632e7d686 -r 6adf4063e1bb njs/test/njs_expect_test.exp
--- a/njs/test/njs_expect_test.exp Tue May 07 19:50:35 2019 +0300
+++ b/njs/test/njs_expect_test.exp Tue May 07 19:50:38 2019 +0300
@@ -649,10 +649,6 @@ njs_run "-p njs/test/module ./njs/test/m
njs_run "-h" "Interactive njs shell.\r\n\r\nOptions:"
-# version
-
-njs_run "-v" "\\d+\.\\d+\.\\d+"
-
# disassemble
njs_test {
@@ -664,32 +660,6 @@ njs_test {
"00000 TRY START*\r\n*TRY RETURN*STOP*\r\n\r\nundefined"}
} "-d"
-# sandboxing
-
-njs_test {
- {"var fs = require('fs')\r\n"
- "Error: Cannot find module \"fs\"\r\n"}
-} "-s"
-
-njs_test {
- {"var crypto = require('crypto')\r\n"
- "undefined\r\n"}
-} "-s"
-
-# source type
-
-njs_test {
- {"this\r\n"
- "this\r\nundefined"}
- {"(() => this)()\r\n"
- "(() => this)()\r\nundefined"}
-} "-t module"
-
-njs_test {
- {"this.NaN\r\n"
- "this.NaN\r\nNaN"}
-} "-t script"
-
# modules
njs_test {
@@ -740,3 +710,36 @@ njs_run "-q ./njs/test/module/normal.js"
njs_run "-p njs/test/module/libs/ -d ./njs/test/module/normal.js" \
"passed!"
+
+# sandboxing
+
+njs_test {
+ {"var fs = require('fs')\r\n"
+ "Error: Cannot find module \"fs\"\r\n"}
+} "-s"
+
+njs_test {
+ {"var crypto = require('crypto')\r\n"
+ "undefined\r\n"}
+} "-s"
+
+
+# source type
+
+njs_test {
+ {"this\r\n"
+ "this\r\nundefined"}
+ {"(() => this)()\r\n"
+ "(() => this)()\r\nundefined"}
+} "-t module"
+
+njs_test {
+ {"this.NaN\r\n"
+ "this.NaN\r\nNaN"}
+} "-t script"
+
+
+# version
+
+njs_run "-v" "\\d+\.\\d+\.\\d+"
+
More information about the nginx-devel
mailing list