Welcome! Log In Create A New Profile

Advanced

[njs] Shell: sorting arguments in alphabetic order.

Dmitry Volyntsev
May 07, 2019 12:52PM
details: https://hg.nginx.org/njs/rev/6adf4063e1bb
branches:
changeset: 955:6adf4063e1bb
user: Dmitry Volyntsev <xeioex@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+"
+
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[njs] Shell: sorting arguments in alphabetic order.

Dmitry Volyntsev 146 May 07, 2019 12:52PM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 75
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready