[njs] Improved help desrcription of njs shell.

Dmitry Volyntsev xeioex at nginx.com
Fri Jul 20 17:11:25 UTC 2018


details:   http://hg.nginx.org/njs/rev/d4697241f506
branches:  
changeset: 564:d4697241f506
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Fri Jul 20 20:11:02 2018 +0300
description:
Improved help desrcription of njs shell.

diffstat:

 njs/njs_core.h  |   1 +
 njs/njs_shell.c |  26 +++++++++++++++++---------
 nxt/auto/os     |   1 +
 nxt/nxt_unix.h  |  23 +++++++++++++++++++++++
 4 files changed, 42 insertions(+), 9 deletions(-)

diffs (101 lines):

diff -r 552da720e6e6 -r d4697241f506 njs/njs_core.h
--- a/njs/njs_core.h	Fri Jul 20 16:09:50 2018 +0300
+++ b/njs/njs_core.h	Fri Jul 20 20:11:02 2018 +0300
@@ -9,6 +9,7 @@
 
 #include <nxt_auto_config.h>
 
+#include <nxt_unix.h>
 #include <nxt_types.h>
 #include <nxt_clang.h>
 #include <nxt_alignment.h>
diff -r 552da720e6e6 -r d4697241f506 njs/njs_shell.c
--- a/njs/njs_shell.c	Fri Jul 20 16:09:50 2018 +0300
+++ b/njs/njs_shell.c	Fri Jul 20 20:11:02 2018 +0300
@@ -150,6 +150,14 @@ njs_get_options(njs_opts_t *opts, int ar
     char     *p;
     nxt_int_t  i, ret;
 
+    static const char  help[] =
+        "Interactive njs shell.\n"
+        "\n"
+        "Options:\n"
+        "  -v              print njs version and exit.\n"
+        "  -d              print disassembled code.\n"
+        "  <filename> | -  run code from a file or stdin.\n";
+
     ret = NXT_DONE;
 
     for (i = 1; i < argc; i++) {
@@ -165,24 +173,24 @@ njs_get_options(njs_opts_t *opts, int ar
         p++;
 
         switch (*p) {
+        case '?':
+        case 'h':
+            (void) write(STDIN_FILENO, help, nxt_length(help));
+            return ret;
+
         case 'd':
             opts->disassemble = 1;
             break;
 
+        case 'v':
         case 'V':
             opts->version = 1;
             break;
 
         default:
-            fprintf(stderr, "Unknown argument: \"%s\"\n", argv[i]);
-            ret = NXT_ERROR;
-
-            /* Fall through. */
-
-        case 'h':
-        case '?':
-            printf("Usage: %s [<file>|-] [-dV]\n", argv[0]);
-            return ret;
+            fprintf(stderr, "Unknown argument: \"%s\" "
+                    "try \"%s -h\" for available options\n", argv[i], argv[0]);
+            return NXT_ERROR;
         }
     }
 
diff -r 552da720e6e6 -r d4697241f506 nxt/auto/os
--- a/nxt/auto/os	Fri Jul 20 16:09:50 2018 +0300
+++ b/nxt/auto/os	Fri Jul 20 20:11:02 2018 +0300
@@ -9,6 +9,7 @@ NXT_SYSTEM=`uname -s 2>/dev/null`
 case "$NXT_SYSTEM" in
 
     Linux)
+        nxt_define=NXT_LINUX . ${NXT_AUTO}define
         NXT_SYSTEM_VERSION=`uname -r 2>/dev/null`
         # Linux uname -p can return "unknown".
         NXT_SYSTEM_PLATFORM=`uname -m 2>/dev/null`
diff -r 552da720e6e6 -r d4697241f506 nxt/nxt_unix.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nxt/nxt_unix.h	Fri Jul 20 20:11:02 2018 +0300
@@ -0,0 +1,23 @@
+
+/*
+ * Copyright (C) Dmitry Volyntsev
+ * Copyright (C) NGINX, Inc.
+ */
+
+
+#ifndef _NXT_UNIX_H_INCLUDED_
+#define _NXT_UNIX_H_INCLUDED_
+
+#if (NXT_LINUX)
+
+#ifdef _FORTIFY_SOURCE
+/*
+ * _FORTIFY_SOURCE
+ *     does not allow to use "(void) write()";
+ */
+#undef _FORTIFY_SOURCE
+#endif
+
+#endif /* NXT_LINUX */
+
+#endif /* _NXT_UNIX_H_INCLUDED_ */


More information about the nginx-devel mailing list